ClothingFosterView.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.ClothingFoster;
  6. using UI.CommonGame;
  7. namespace GFGGame
  8. {
  9. public class ClothingFosterView : BaseWindow
  10. {
  11. private UI_ClothingFosterUI _ui;
  12. private SuitFosterCfg cfg;
  13. private ItemCfg cardItemCfg;
  14. private int _suitId;
  15. private int _index;
  16. private SortedList _propertyList;
  17. // private Dictionary<int, int> _addPropertyList;
  18. private bool _canFoster;
  19. public override void Dispose()
  20. {
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI_ClothingFosterUI.PACKAGE_NAME;
  32. _ui = UI_ClothingFosterUI.Create();
  33. this.viewCom = _ui.target;
  34. this.viewCom.Center();
  35. this.modal = true;
  36. // viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  37. _ui.m_listMaterials.itemRenderer = ListMaterialItemRender;
  38. _ui.m_listMaterials.onClickItem.Add(OnListMaterialsItem);
  39. _ui.m_listPropertyAdd.itemRenderer = ListPropertyItemRender;
  40. _ui.m_btnFoster.onClick.Add(OnClickBtnFoster);
  41. }
  42. protected override void AddEventListener()
  43. {
  44. base.AddEventListener();
  45. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  46. }
  47. protected override void OnShown()
  48. {
  49. base.OnShown();
  50. _suitId = (int)(this.viewData as object[])[0];
  51. _index = (int)(this.viewData as object[])[1];
  52. _propertyList = (this.viewData as object[])[2] as SortedList;
  53. // _addPropertyList = SuitFosterDataManager.Instance.GetAdditionPropertyData(_suitId, _index);
  54. _canFoster = true;
  55. cfg = SuitFosterCfgArray.Instance.GetCfgsBysuitId(_suitId)[_index];
  56. List<ItemCfg> itemCfgs = ItemCfgArray.Instance.GetCfgsBysuitId(_suitId);
  57. for (int i = 0; i < itemCfgs.Count; i++)
  58. {
  59. if (itemCfgs[i].itemType == ConstItemType.CARD)
  60. {
  61. cardItemCfg = itemCfgs[i];
  62. break;
  63. }
  64. }
  65. _ui.m_txtLock.text = cardItemCfg == null || cfg.cardStar == 0 ? "" : string.Format("词牌【{0}】达到{1}星可养护", cardItemCfg.name, cfg.cardStar / 5);
  66. _ui.m_txtLock.visible = cardItemCfg != null && cfg.cardStar > 0;
  67. _ui.m_listMaterials.numItems = cfg.materialsArr.Length;
  68. long has = ItemDataManager.GetItemNum(cfg.costId);
  69. int need = cfg.costNum;
  70. ItemUtil.UpdateItemNeedNum(_ui.m_ComConsume, cfg.costId, cfg.costNum);
  71. if (_canFoster && has < need) _canFoster = false;
  72. _ui.m_txtDiscribe.text = string.Format("完成套装{0}", SuitFosterDataManager.Instance.stepNames[_index]);
  73. _ui.m_listPropertyAdd.numItems = _propertyList.Count;
  74. }
  75. protected override void OnHide()
  76. {
  77. base.OnHide();
  78. }
  79. protected override void RemoveEventListener()
  80. {
  81. base.RemoveEventListener();
  82. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  83. }
  84. private void ListMaterialItemRender(int index, GObject obj)
  85. {
  86. UI_ListMaterialsItem item = UI_ListMaterialsItem.Proxy(obj);
  87. int[][] materialsArr = SuitFosterCfgArray.Instance.GetCfgsBysuitId(_suitId)[_index].materialsArr;
  88. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(materialsArr[index][0]);
  89. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  90. long has = ItemDataManager.GetItemNum(itemCfg.id);
  91. item.m_txtHas.text = has.ToString();
  92. int need = materialsArr[index][1];
  93. item.m_txtNeed.text = need.ToString();
  94. item.m_txtHas.text = StringUtil.GetColorText(has.ToString(), has >= need ? "#F2DB96" : "#C9F1A5");
  95. if (_canFoster && has < need) _canFoster = false;
  96. item.target.data = materialsArr[index];
  97. UI_ListMaterialsItem.ProxyEnd();
  98. }
  99. private void OnListMaterialsItem(EventContext context)
  100. {
  101. int[] itemData = (int[])(context.data as GComponent).data;
  102. //ViewManager.Show<ApproachOfItemView>(new object[] { itemData[0], new object[] { typeof(ClothingView).FullName, (this.viewData as object[])[4] }, itemData[1] });
  103. object[] sourceDatas = new object[] { itemData[0], new object[] { typeof(ClothingView).FullName, (this.viewData as object[])[3] }, itemData[1] };
  104. GoodsItemTipsController.ShowItemTips(itemData[0], sourceDatas);
  105. }
  106. private void ListPropertyItemRender(int index, GObject obj)
  107. {
  108. UI_ListPropertyAddItem item = UI_ListPropertyAddItem.Proxy(obj);
  109. UI_ListScoreItem comProperty = UI_ListScoreItem.Proxy(item.m_comProperty);
  110. int score = (int)_propertyList.GetKey(index);
  111. comProperty.m_txtProperty.text = _propertyList[score].ToString();
  112. comProperty.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (score));
  113. // double addition = _addPropertyList[score] * 100 / 10000;
  114. double addition = cfg.addition * 100 / 10000;
  115. item.m_txtAdd.text = string.Format("+{0}%", addition);
  116. UI_ListPropertyAddItem.ProxyEnd();
  117. UI_ListScoreItem.ProxyEnd();
  118. }
  119. private async void OnClickBtnFoster()
  120. {
  121. if (cfg.cardStar > 0)
  122. {
  123. CardData cardData = CardDataManager.GetCardDataById(cardItemCfg.id);
  124. if (cardData == null)
  125. {
  126. PromptController.Instance.ShowFloatTextPrompt(string.Format("暂未获得词牌【{0}】", cardItemCfg.name));
  127. return;
  128. }
  129. if (cardData.star < cfg.cardStar)
  130. {
  131. PromptController.Instance.ShowFloatTextPrompt(string.Format("词牌【{0}】星级不足", cardItemCfg.name));
  132. return;
  133. }
  134. }
  135. if (!ItemUtil.CheckItemEnough(cfg.costId, cfg.costNum))
  136. {
  137. long has = ItemDataManager.GetItemNum(cfg.costId);
  138. ItemUtil.BuyCurrency(cfg.costId, cfg.costNum - has);
  139. return;
  140. }
  141. for (int i = 0; i < cfg.materialsArr.Length; i++)
  142. {
  143. if (!ItemUtil.CheckItemEnough(cfg.materialsArr[i][0], cfg.materialsArr[i][1], true)) return;
  144. }
  145. int result = await SuitFosterProxy.SendMaintainSuit(_suitId, _index + 1);
  146. if (result == ErrorCode.ERR_Success)
  147. {
  148. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_YANG_CHENG, 2);
  149. this.Hide();
  150. }
  151. }
  152. }
  153. }