ClothingDecomposeView.cs 14 KB

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