ClothingDecomposeView.cs 18 KB

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