ClothingFosterView.cs 7.8 KB

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