ClothingDecomposeView.cs 18 KB

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