少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-19 2fb0f9761ef9789ce068fbe26d2e4c7af1148ec0
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
using System;
using UnityEngine;
using UnityEngine.UI;
 
using System.Collections.Generic;
using System.Text;
using System.Collections;
 
namespace Snxxz.UI
{
    public class MakeDrugCell : MonoBehaviour
    {
        [SerializeField] Image icon;
        [SerializeField] Button iconBtn;
        [SerializeField] Image iconBGIcon;
        [SerializeField] Text itemCntText;
        [SerializeField] Slider numSlider;
        [SerializeField] Text useCntText;
        [SerializeField] Text attrDesText;
        [SerializeField] Text nameText;
        [SerializeField] Button useBtn;
        [SerializeField] Image useBtnBG;
        [SerializeField] Text useBtnText;
        [SerializeField] GameObject reachMaxUse;
 
        Dictionary<int, int> attrDict = new Dictionary<int, int>();
        StringBuilder attrSB = new StringBuilder();
        PlayerPackModel _playerPack;
        PlayerPackModel playerPack
        {
            get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
        }
        BlastFurnaceModel furnaceModel { get { return ModelCenter.Instance.GetModel<BlastFurnaceModel>(); } }
 
        ItemTipsModel _itemTipsModel;
        ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>()); } }
        int itemId = 0;
 
        Color32 brightColor = new Color32(64,28,6,255);
        Color32 greyColor = new Color32(247, 247, 247, 255);
        AttrFruitConfig fruitConfig;
 
        private void OnEnable()
        {
            attrDesText.gameObject.SetActive(false);
            iconBtn.AddListener(ClickIconBtn);
            playerPack.RefreshItemSumUseCntAct += RefreshItemUsce;
            playerPack.RefreshItemCountAct += RefreshItemCnt;
            StartCoroutine(SetAttrDesUI());
        }
 
        private void OnDisable()
        {
            playerPack.RefreshItemSumUseCntAct -= RefreshItemUsce;
            playerPack.RefreshItemCountAct -= RefreshItemCnt;
            iconBtn.RemoveAllListeners();
            useBtn.RemoveAllListeners();
        }
 
        IEnumerator SetAttrDesUI()
        {
            yield return null;
            attrDesText.gameObject.SetActive(true);
        }
 
        public void InitModel(int id)
        {
            attrDict.Clear();
            this.itemId = id ;
            ItemConfig itemConfig = ItemConfig.Get(itemId);
            if (itemConfig == null) return;
 
            fruitConfig = AttrFruitConfig.Get(itemId);
            icon.SetSprite(itemConfig.IconKey);
            iconBGIcon.SetItemBackGround(itemConfig.ItemColor);
            nameText.text = itemConfig.ItemName;
            nameText.color = UIHelper.GetUIColor(itemConfig.ItemColor,true);
            numSlider.minValue = 0;
            numSlider.maxValue = fruitConfig.MaxUseCnt;
            if(itemConfig.Effect1 != 0)
            {
                attrDict.Add(itemConfig.Effect1,itemConfig.EffectValueA1);
            }
 
            if (itemConfig.Effect2 != 0)
            {
                attrDict.Add(itemConfig.Effect2, itemConfig.EffectValueA2);
            }
 
            if (itemConfig.Effect3 != 0)
            {
                attrDict.Add(itemConfig.Effect3, itemConfig.EffectValueA3);
            }
            if (itemConfig.Effect4 != 0)
            {
                attrDict.Add(itemConfig.Effect4, itemConfig.EffectValueA4);
            }
            if (itemConfig.Effect5 != 0)
            {
                attrDict.Add(itemConfig.Effect5, itemConfig.EffectValueA5);
            }
            RefreshUI();
        }
 
        private void RefreshUI()
        {
            int haveCnt = playerPack.GetItemCountByID(PackType.Item, itemId);
            itemCntText.text = StringUtility.Contact(haveCnt,"/",1);
            int useNum = playerPack.GetSumUseCntByID(itemId);
            numSlider.value = useNum;
            useCntText.text = StringUtility.Contact(useNum,"/",numSlider.maxValue);
            attrSB.Length = 0;
            foreach(var id in attrDict.Keys)
            {
                PlayerPropertyConfig attrConfig = PlayerPropertyConfig.Get(id);
                if(attrConfig != null)
                {
                    int value = attrDict[id] * useNum;
                    string valueStr = StringUtility.Contact("+", UIHelper.AppendStringColor(TextColType.Green, GetProValueTypeStr(attrConfig, value), true));
                    string attrStr = StringUtility.Contact(attrConfig.Name, valueStr);
                    if(attrSB.Length != 0)
                    {
                        attrSB.Append("  " + attrStr);
                    }
                    else
                    {
                        attrSB.Append(attrStr);
                    }
                   
                }
                else
                {
                    DebugEx.Log("属性表中不存在此属性:" + id + "丹药Id" + this.itemId);
                }
              
            }
            attrDesText.text = attrSB.ToString();
            useBtn.RemoveAllListeners();
            if (useNum < fruitConfig.MaxUseCnt)
            {
                reachMaxUse.SetActive(false);
                useBtnText.text = Language.Get("KnapS103");
                useBtn.AddListener(ClickMakeUseBtn);
                useBtn.gameObject.SetActive(true);
                if (haveCnt > 0)
                {
                    useBtnBG.material = MaterialUtility.GetUIDefaultGraphicMaterial();
                    useBtnText.color = brightColor;
                }
                else
                {
                    useBtnBG.material = MaterialUtility.GetInstantiatedSpriteGrayMaterial();
                    useBtnText.color = greyColor;
                }
            }
            else
            {
                useBtn.gameObject.SetActive(false);
                reachMaxUse.SetActive(true);
            }
            
          
        }
 
        private void RefreshItemUsce(int id)
        {
            if (id != itemId) return;
 
             RefreshUI();
        }
        private void RefreshItemCnt(PackType type, int index, int id)
        {
            if (type != PackType.Item || id != itemId) return;
            RefreshUI();
        }
 
        public string GetProValueTypeStr(PlayerPropertyConfig playerproModel, int value)
        {
            string s = "";
            if (playerproModel.ISPercentage == 0)
            {
                s = value.ToString();
            }
            else if (playerproModel.ISPercentage == 1)
            {
                s = (float)Math.Round(value / 100f, 1) + "%";
            }
            else if (playerproModel.ISPercentage == 2)
            {
                s = ((float)Math.Round(value / 100f, 1)).ToString();
            }
            return s;
        }
 
        private void ClickMakeUseBtn()
        {
            SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.Item);
            if (singlePack == null) return;
 
            List<ItemModel> list = null;
            singlePack.GetItemCountByID(itemId,out list);
            if(list.Count > 0)
            {
                if(ItemLogicUtility.Instance.CheckItemUselimit(itemId))
                {
                    ItemLogicUtility.Instance.SendMakeUseQuest(list[0].itemPlace);
                }
            }
        }
 
        private void ClickRecycle()
        {
            furnaceModel.RecycleDrug(itemId, fruitConfig.RecycleExp);
        }
 
        private void ClickIconBtn()
        {
            ItemAttrData attrData = new ItemAttrData(itemId);
            itemTipsModel.SetItemTipsModel(attrData);
        }
    }
}