ClothingDecomposeView.cs 12 KB

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