ClothingDecomposeView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ET;
  5. using FairyGUI;
  6. using UI.ClothingDecompose;
  7. namespace GFGGame
  8. {
  9. public class ClothingDecomposeView : BaseWindow
  10. {
  11. private UI_ClothingDecomposeUI _ui;
  12. private ValueBarController _valueBarController;
  13. private List<int> _clothingDatas = new List<int>();
  14. private Dictionary<int, int> _decomposeData = new Dictionary<int, int>();
  15. private int _decomposeCount = 0;//要分解物品的数量
  16. private int _curRarity = 0;
  17. public override void Dispose()
  18. {
  19. _valueBarController.Dispose();
  20. _valueBarController = null;
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_ClothingDecomposeUI.PACKAGE_NAME;
  27. _ui = UI_ClothingDecomposeUI.Create();
  28. this.viewCom = _ui.target;
  29. isfullScreen = true;
  30. this.clickBlankToClose = false;
  31. _valueBarController = new ValueBarController(_ui.m_valueBar);
  32. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  33. _ui.m_listTab.onClickItem.Add((EventContext context) =>
  34. {
  35. int index = _ui.m_listTab.GetChildIndex(context.data as GObject);
  36. OnClickBtnRarity(index + 1);
  37. });
  38. _ui.m_btnSelect.onClick.Add(OnClickBtnSelect);
  39. _ui.m_btnRule.onClick.Add(OnClickBtnRule);
  40. _ui.m_btnDecompose.onClick.Add(OnClickBtnDecompose);
  41. _ui.m_list.itemRenderer = ListItemRander;
  42. _ui.m_list.SetVirtual();
  43. _ui.m_listReward.itemRenderer = ListRewardItemRander;
  44. _ui.m_listReward.onClickItem.Add(OnClickListRewardItem);
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. _ui.m_c1.selectedIndex = 0;
  50. _ui.m_listTab.selectedIndex = 0;
  51. _valueBarController.OnShown();
  52. _valueBarController.Controller(6);
  53. OnClickBtnRarity(ConstDressRarity.Rarity_FANPIN);
  54. if (GuideDataManager.currentGuideId == GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_DECOMPOSE).id)
  55. {
  56. _ui.m_listTab.selectedIndex = 1;
  57. OnClickBtnRarity(ConstDressRarity.Rarity_ZHENXI);
  58. }
  59. }
  60. protected override void OnHide()
  61. {
  62. base.OnHide();
  63. _valueBarController.OnHide();
  64. }
  65. private void OnClickBtnRarity(int rarity)
  66. {
  67. _curRarity = rarity;
  68. _clothingDatas = DecomposeDataManager.Instance.GetDecomposeDataByRarity(rarity);
  69. _ui.m_list.visible = _clothingDatas != null && _clothingDatas.Count > 0;
  70. _ui.m_txtNone.visible = _clothingDatas == null || _clothingDatas.Count == 0;
  71. if (_clothingDatas == null) return;
  72. _ui.m_list.numItems = _clothingDatas.Count;
  73. _ui.m_btnSelect.selected = false;
  74. CancleAll();
  75. UpdateConsume();
  76. }
  77. private void ListItemRander(int index, GObject obj)
  78. {
  79. UI_ListItem item = UI_ListItem.Proxy(obj);
  80. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_clothingDatas[index]);
  81. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  82. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
  83. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  84. item.m_txtName.text = itemCfg.name;
  85. item.m_imgSelect.visible = false;
  86. int itemHasCount = DecomposeDataManager.Instance.ItemCanDecomposeCount(itemCfg.id);
  87. item.m_txtHasCount.text = itemHasCount.ToString();
  88. int itemCount = _decomposeData.ContainsKey(_clothingDatas[index]) ? _decomposeData[_clothingDatas[index]] : 0;
  89. item.m_txtCount.text = itemCount.ToString();
  90. item.m_imgSelect.visible = itemCount > 0;
  91. item.m_btnMinus.visible = itemCount > 0;
  92. if (item.m_btnMinus.data == null)
  93. {
  94. item.m_btnMinus.onClick.Add(OnClickBtnMinus);
  95. }
  96. item.m_btnMinus.data = index;
  97. if (item.m_loaItem.data == null)
  98. {
  99. item.m_loaItem.onClick.Add(OnListItemClick);
  100. }
  101. item.m_loaItem.data = index;
  102. item.target.data = itemCfg;
  103. }
  104. private void OnListItemClick(EventContext context)
  105. {
  106. int index = (int)((context.sender as GLoader).data);
  107. int childIndex = _ui.m_list.ItemIndexToChildIndex(index);
  108. GComponent com = _ui.m_list.GetChildAt(childIndex).asCom;
  109. int itemId = (com.data as ItemCfg).id;
  110. if (!_decomposeData.ContainsKey(itemId)) _decomposeData[itemId] = 0;
  111. if (_decomposeData[itemId] == DecomposeDataManager.Instance.ItemCanDecomposeCount(itemId)) return;
  112. if (_decomposeCount == DecomposeDataManager.MaxCount)
  113. {
  114. PromptController.Instance.ShowFloatTextPrompt("已达到单次可分解上限,请分批操作");
  115. return;
  116. }
  117. UI_ListItem item = UI_ListItem.Proxy(com);
  118. item.m_btnMinus.visible = true;
  119. item.m_imgSelect.visible = true;
  120. _decomposeData[itemId] = _decomposeData[itemId] + 1;
  121. _decomposeCount += 1;
  122. item.m_txtCount.text = _decomposeData[itemId].ToString();
  123. UpdateConsume();
  124. }
  125. private void OnClickBtnMinus(EventContext context)
  126. {
  127. int index = (int)((context.sender as GButton).data);
  128. int childIndex = _ui.m_list.ItemIndexToChildIndex(index);
  129. GComponent com = _ui.m_list.GetChildAt(childIndex).asCom;
  130. UI_ListItem item = UI_ListItem.Proxy(com);
  131. int itemId = (com.data as ItemCfg).id;
  132. _decomposeData[itemId] = _decomposeData[itemId] - 1;
  133. _decomposeCount -= 1;
  134. item.m_txtCount.text = _decomposeData[itemId].ToString();
  135. if (_decomposeData[itemId] == 0)
  136. {
  137. _decomposeData.Remove(itemId);
  138. item.m_imgSelect.visible = false;
  139. item.m_btnMinus.visible = false;
  140. }
  141. UpdateConsume();
  142. }
  143. private void OnClickBtnSelect()
  144. {
  145. if (_ui.m_btnSelect.selected)
  146. {
  147. SelectAll();
  148. }
  149. else
  150. {
  151. CancleAll();
  152. }
  153. UpdateConsume();
  154. }
  155. private void SelectAll()
  156. {
  157. int lastCount = DecomposeDataManager.MaxCount - _decomposeCount;
  158. for (int i = 0; i < _clothingDatas.Count; i++)
  159. {
  160. int itemId = _clothingDatas[i];
  161. int itemHasCount = DecomposeDataManager.Instance.ItemCanDecomposeCount(itemId);
  162. int itemLastCount = _decomposeData.ContainsKey(itemId) ? itemHasCount - _decomposeData[itemId] : itemHasCount;
  163. int count = Math.Min(lastCount, itemLastCount);
  164. lastCount -= count;
  165. if (!_decomposeData.ContainsKey(itemId)) _decomposeData[itemId] = 0;
  166. _decomposeData[itemId] = _decomposeData[itemId] + count;
  167. _decomposeCount += count;
  168. if (lastCount == 0) break;
  169. }
  170. _ui.m_list.numItems = _clothingDatas.Count;
  171. }
  172. private void CancleAll()
  173. {
  174. _decomposeData.Clear();
  175. _ui.m_list.numItems = _clothingDatas.Count;
  176. _decomposeCount = 0;
  177. }
  178. private void UpdateConsume()
  179. {
  180. DecomposeCfg cfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);
  181. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.consumeId);
  182. _ui.m_listReward.numItems = _decomposeCount > 0 ? cfg.itemsArr.Length : 0;
  183. _ui.m_txtShow.text = string.Format("* 分解{0}件{1}可获得 *", StringUtil.GetColorText(_decomposeCount.ToString(), "#DA826E"), ConstDressRarity.DressRarityList()[_curRarity]);
  184. _ui.m_txtConsume.text = string.Format("消耗{0}X{1}", itemCfg.name, (_decomposeCount * cfg.consumeCount));
  185. }
  186. private void ListRewardItemRander(int index, GObject obj)
  187. {
  188. UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj);
  189. DecomposeCfg decomposeCfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);
  190. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(decomposeCfg.itemsArr[index][0]);
  191. item.m_txtCount.text = (decomposeCfg.itemsArr[index][1] * _decomposeCount).ToString();
  192. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
  193. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  194. item.target.data = itemCfg;
  195. }
  196. private void OnClickListRewardItem(EventContext context)
  197. {
  198. UI_ListRewardItem item = UI_ListRewardItem.Proxy((context.data as GObject));
  199. GoodsItemTipsController.ShowItemTips((item.target.data as ItemCfg).id);
  200. }
  201. private void OnClickBtnDecompose()
  202. {
  203. if (_curRarity > ConstDressRarity.Rarity_ZHENXI)
  204. {
  205. Alert.Show(string.Format("当前选择的稀有度为{0},是否确定分解?", ConstDressRarity.DressRarityList()[_curRarity])).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { DecomposeItem(); });
  206. }
  207. else
  208. {
  209. DecomposeItem();
  210. }
  211. }
  212. private async void DecomposeItem()
  213. {
  214. DecomposeCfg cfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);
  215. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.consumeId);
  216. if (_decomposeCount <= 0)
  217. {
  218. PromptController.Instance.ShowFloatTextPrompt("未选择分解服装");
  219. return;
  220. }
  221. int consumeCount = cfg.consumeCount * _decomposeCount;
  222. if (consumeCount > ItemDataManager.GetItemNum(cfg.consumeId))
  223. {
  224. PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足", itemCfg.name));
  225. return;
  226. }
  227. List<int> itemIds = _decomposeData.Keys.ToList<int>();
  228. List<int> itemNums = _decomposeData.Values.ToList<int>();
  229. bool result = await ClothingDecomposeSProxy.ClothingDecompose(itemIds, itemNums);
  230. if (result)
  231. {
  232. OnClickBtnRarity(_curRarity);
  233. LogServerHelper.SendNodeLog((int)PlayParticipationEnum.FU_ZHUANG_FEN_JIE, 2);
  234. }
  235. }
  236. private void OnClickBtnRule()
  237. {
  238. ViewManager.Show<ClothingDecomposeRuleView>();
  239. }
  240. private void OnClickBtnBack()
  241. {
  242. ViewManager.GoBackFrom(typeof(ClothingDecomposeView).FullName);
  243. }
  244. protected override void UpdateToCheckGuide(object param)
  245. {
  246. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  247. GuideController.TryGuide(_ui.m_list, ConstGuideId.CLOTHING_DECOMPOSE, 4, "选择重复获得的服饰部件", 0);
  248. GuideController.TryGuide(_ui.m_btnDecompose, ConstGuideId.CLOTHING_DECOMPOSE, 5, "分解获得的材料可用于新服饰合成");
  249. GuideController.TryCompleteGuide(ConstGuideId.CLOTHING_DECOMPOSE, 5);
  250. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.CLOTHING_SYNTHETIC, 1, "回到绣坊界面");
  251. }
  252. }
  253. }