ClothingDecomposeView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. UI_ListItem.ProxyEnd();
  104. }
  105. private void OnListItemClick(EventContext context)
  106. {
  107. int index = (int)((context.sender as GLoader).data);
  108. int childIndex = _ui.m_list.ItemIndexToChildIndex(index);
  109. GComponent com = _ui.m_list.GetChildAt(childIndex).asCom;
  110. int itemId = (com.data as ItemCfg).id;
  111. if (!_decomposeData.ContainsKey(itemId)) _decomposeData[itemId] = 0;
  112. if (_decomposeData[itemId] == DecomposeDataManager.Instance.ItemCanDecomposeCount(itemId)) return;
  113. if (_decomposeCount == DecomposeDataManager.MaxCount)
  114. {
  115. PromptController.Instance.ShowFloatTextPrompt("已达到单次可分解上限,请分批操作");
  116. return;
  117. }
  118. UI_ListItem item = UI_ListItem.Proxy(com);
  119. item.m_btnMinus.visible = true;
  120. item.m_imgSelect.visible = true;
  121. _decomposeData[itemId] = _decomposeData[itemId] + 1;
  122. _decomposeCount += 1;
  123. item.m_txtCount.text = _decomposeData[itemId].ToString();
  124. UI_ListItem.ProxyEnd();
  125. UpdateConsume();
  126. }
  127. private void OnClickBtnMinus(EventContext context)
  128. {
  129. int index = (int)((context.sender as GButton).data);
  130. int childIndex = _ui.m_list.ItemIndexToChildIndex(index);
  131. GComponent com = _ui.m_list.GetChildAt(childIndex).asCom;
  132. UI_ListItem item = UI_ListItem.Proxy(com);
  133. int itemId = (com.data as ItemCfg).id;
  134. _decomposeData[itemId] = _decomposeData[itemId] - 1;
  135. _decomposeCount -= 1;
  136. item.m_txtCount.text = _decomposeData[itemId].ToString();
  137. if (_decomposeData[itemId] == 0)
  138. {
  139. _decomposeData.Remove(itemId);
  140. item.m_imgSelect.visible = false;
  141. item.m_btnMinus.visible = false;
  142. }
  143. UI_ListItem.ProxyEnd();
  144. UpdateConsume();
  145. }
  146. private void OnClickBtnSelect()
  147. {
  148. if (_ui.m_btnSelect.selected)
  149. {
  150. SelectAll();
  151. }
  152. else
  153. {
  154. CancleAll();
  155. }
  156. UpdateConsume();
  157. }
  158. private void SelectAll()
  159. {
  160. int lastCount = DecomposeDataManager.MaxCount - _decomposeCount;
  161. for (int i = 0; i < _clothingDatas.Count; i++)
  162. {
  163. int itemId = _clothingDatas[i];
  164. int itemHasCount = DecomposeDataManager.Instance.ItemCanDecomposeCount(itemId);
  165. int itemLastCount = _decomposeData.ContainsKey(itemId) ? itemHasCount - _decomposeData[itemId] : itemHasCount;
  166. int count = Math.Min(lastCount, itemLastCount);
  167. lastCount -= count;
  168. if (!_decomposeData.ContainsKey(itemId)) _decomposeData[itemId] = 0;
  169. _decomposeData[itemId] = _decomposeData[itemId] + count;
  170. _decomposeCount += count;
  171. if (lastCount == 0) break;
  172. }
  173. _ui.m_list.numItems = _clothingDatas.Count;
  174. }
  175. private void CancleAll()
  176. {
  177. _decomposeData.Clear();
  178. _ui.m_list.numItems = _clothingDatas.Count;
  179. _decomposeCount = 0;
  180. }
  181. private void UpdateConsume()
  182. {
  183. DecomposeCfg cfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);
  184. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.consumeId);
  185. _ui.m_listReward.numItems = _decomposeCount > 0 ? cfg.itemsArr.Length : 0;
  186. _ui.m_txtShow.text = string.Format("* 分解{0}件{1}可获得 *", StringUtil.GetColorText(_decomposeCount.ToString(), "#DA826E"), ConstDressRarity.DressRarityList()[_curRarity]);
  187. _ui.m_txtConsume.text = string.Format("消耗{0}X{1}", itemCfg.name, (_decomposeCount * cfg.consumeCount));
  188. }
  189. private void ListRewardItemRander(int index, GObject obj)
  190. {
  191. UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj);
  192. DecomposeCfg decomposeCfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);
  193. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(decomposeCfg.itemsArr[index][0]);
  194. item.m_txtCount.text = (decomposeCfg.itemsArr[index][1] * _decomposeCount).ToString();
  195. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
  196. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext);
  197. item.target.data = itemCfg;
  198. UI_ListRewardItem.ProxyEnd();
  199. }
  200. private void OnClickListRewardItem(EventContext context)
  201. {
  202. UI_ListRewardItem item = UI_ListRewardItem.Proxy((context.data as GObject));
  203. GoodsItemTipsController.ShowItemTips((item.target.data as ItemCfg).id);
  204. UI_ListRewardItem.ProxyEnd();
  205. }
  206. private void OnClickBtnDecompose()
  207. {
  208. if (_curRarity > ConstDressRarity.Rarity_ZHENXI)
  209. {
  210. Alert.Show(string.Format("当前选择的稀有度为{0},是否确定分解?", ConstDressRarity.DressRarityList()[_curRarity])).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { DecomposeItem(); });
  211. }
  212. else
  213. {
  214. DecomposeItem();
  215. }
  216. }
  217. private async void DecomposeItem()
  218. {
  219. DecomposeCfg cfg = DecomposeCfgArray.Instance.GetCfg(_curRarity);
  220. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.consumeId);
  221. if (_decomposeCount <= 0)
  222. {
  223. PromptController.Instance.ShowFloatTextPrompt("未选择分解服装");
  224. return;
  225. }
  226. int consumeCount = cfg.consumeCount * _decomposeCount;
  227. if (consumeCount > ItemDataManager.GetItemNum(cfg.consumeId))
  228. {
  229. PromptController.Instance.ShowFloatTextPrompt(string.Format("{0}不足", itemCfg.name));
  230. return;
  231. }
  232. List<int> itemIds = _decomposeData.Keys.ToList<int>();
  233. List<int> itemNums = _decomposeData.Values.ToList<int>();
  234. bool result = await ClothingDecomposeSProxy.ClothingDecompose(itemIds, itemNums);
  235. if (result)
  236. {
  237. OnClickBtnRarity(_curRarity);
  238. LogServerHelper.SendNodeLog((int)PlayParticipationEnum.FU_ZHUANG_FEN_JIE, 2);
  239. }
  240. }
  241. private void OnClickBtnRule()
  242. {
  243. ViewManager.Show<ClothingDecomposeRuleView>();
  244. }
  245. private void OnClickBtnBack()
  246. {
  247. ViewManager.GoBackFrom(typeof(ClothingDecomposeView).FullName);
  248. }
  249. protected override void UpdateToCheckGuide(object param)
  250. {
  251. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  252. GuideController.TryGuide(_ui.m_list, ConstGuideId.CLOTHING_DECOMPOSE, 4, "选择重复获得的服饰部件", 0);
  253. GuideController.TryGuide(_ui.m_btnDecompose, ConstGuideId.CLOTHING_DECOMPOSE, 5, "分解获得的材料可用于新服饰合成");
  254. GuideController.TryCompleteGuide(ConstGuideId.CLOTHING_DECOMPOSE, 5);
  255. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.CLOTHING_SYNTHETIC, 1, "回到绣坊界面");
  256. }
  257. }
  258. }