hch
3 天以前 e3e4ed259b23b433a3d6f0dc8c1a50282ad80e2a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using UnityEngine;
 
public class BuffInfoWin : UIBase
{
    [SerializeField] BuffInfoCell buffInfoCell;
    [SerializeField] ImageEx teamImage;
    [SerializeField] ImageEx heroImage;
    [SerializeField] TextEx heroNameText;
    [SerializeField] ScrollerController buffScroller;
    ViewBuffManager manager => ViewBuffManager.Instance;
    BattleClickBuffData data;
    protected override void OnPreOpen()
    {
        buffScroller.OnRefreshCell += OnRefreshCell;
        buffScroller.OnGetDynamicSize += OnGetWorldChatDynamicSize;
 
        data = manager.currentBuffData;
 
        var heroConfig = HeroConfig.Get(data.heroID);
        if (heroConfig == null) return;
 
        var heroSkinConfig = HeroSkinConfig.Get(data.skinID);
        if (heroSkinConfig == null) return;
 
        teamImage.SetSprite(data.isMySide ? "OtherHeroDetailBGBlue" : "OtherHeroDetailBGRed");
         var sprite = UILoader.LoadSprite("HeroHead", HeroSkinConfig.Get(data.skinID).SquareIcon);
        if (sprite == null)
        {
            // 内网未配置时
            heroImage.SetSprite("herohead_default");
        }
        else
        {
            heroImage.overrideSprite = sprite;
        }
        heroNameText.text = heroConfig.Name;
 
        CreateScroller();
    }
 
    protected override void OnPreClose()
    {
        buffScroller.OnRefreshCell -= OnRefreshCell;
        buffScroller.OnGetDynamicSize -= OnGetWorldChatDynamicSize;
    }
 
    public bool TryGetSkillConfig(int index, out SkillConfig config)
    {
        config = null;
        if (data.datas?.Count <= index)
            return false;
        config = SkillConfig.Get((int)data.datas[index].SkillID);
        return config != null;
    }
 
    private bool OnGetWorldChatDynamicSize(ScrollerDataType type, int index, out float height)
    {
        height = 0;
        if (!TryGetSkillConfig(index, out SkillConfig config))
            return false;
        height = buffInfoCell.GetTextHeight(config.Description);
        return true;
    }
 
    private void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell.GetComponent<BuffInfoCell>();
        _cell?.Display(cell.index, data);
    }
 
    private void CreateScroller()
    {
        buffScroller.Refresh();
        for (int i = 0; i < data.datas.Count; i++)
        {
            buffScroller.AddCell(ScrollerDataType.Header, i);
        }
        buffScroller.Restart();
    }
 
 
}