ClothingDecomposeView.cs 18 KB

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