ClothingDecomposeView.cs 16 KB

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