ClothingDecomposeView.cs 13 KB

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