ClothingFosterView.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 int _suitId;
  14. private int _index;
  15. private SortedList _propertyList;
  16. // private Dictionary<int, int> _addPropertyList;
  17. private bool _canFoster;
  18. public override void Dispose()
  19. {
  20. if (_ui != null)
  21. {
  22. _ui.Dispose();
  23. _ui = null;
  24. }
  25. base.Dispose();
  26. }
  27. protected override void OnInit()
  28. {
  29. base.OnInit();
  30. packageName = UI_ClothingFosterUI.PACKAGE_NAME;
  31. _ui = UI_ClothingFosterUI.Create();
  32. this.viewCom = _ui.target;
  33. this.viewCom.Center();
  34. this.modal = true;
  35. // viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  36. _ui.m_listMaterials.itemRenderer = ListMaterialItemRender;
  37. _ui.m_listMaterials.onClickItem.Add(OnListMaterialsItem);
  38. _ui.m_listPropertyAdd.itemRenderer = ListPropertyItemRender;
  39. _ui.m_btnFoster.onClick.Add(OnClickBtnFoster);
  40. }
  41. protected override void AddEventListener()
  42. {
  43. base.AddEventListener();
  44. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. _suitId = (int)(this.viewData as object[])[0];
  50. _index = (int)(this.viewData as object[])[1];
  51. _propertyList = (this.viewData as object[])[2] as SortedList;
  52. // _addPropertyList = SuitFosterDataManager.Instance.GetAdditionPropertyData(_suitId, _index);
  53. _canFoster = true;
  54. cfg = SuitFosterCfgArray.Instance.GetCfgsBysuitId(_suitId)[_index];
  55. _ui.m_listMaterials.numItems = cfg.materialsArr.Length;
  56. long has = ItemDataManager.GetItemNum(cfg.costId);
  57. int need = cfg.costNum;
  58. // UI_ComCostCurrency comConsume = UI_ComCostCurrency.Proxy(_ui.m_ComConsume);
  59. // comConsume.m_txtNeed.text = need.ToString();
  60. // UI_ComCostCurrency.ProxyEnd();
  61. ItemUtil.UpdateItemNeedNum(_ui.m_ComConsume, cfg.costId, cfg.costNum);
  62. if (_canFoster && has < need) _canFoster = false;
  63. _ui.m_listPropertyAdd.numItems = _propertyList.Count;
  64. }
  65. protected override void OnHide()
  66. {
  67. base.OnHide();
  68. }
  69. protected override void RemoveEventListener()
  70. {
  71. base.RemoveEventListener();
  72. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  73. }
  74. private void ListMaterialItemRender(int index, GObject obj)
  75. {
  76. UI_ListMaterialsItem item = UI_ListMaterialsItem.Proxy(obj);
  77. int[][] materialsArr = SuitFosterCfgArray.Instance.GetCfgsBysuitId(_suitId)[_index].materialsArr;
  78. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(materialsArr[index][0]);
  79. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  80. long has = ItemDataManager.GetItemNum(itemCfg.id);
  81. item.m_txtHas.text = has.ToString();
  82. int need = materialsArr[index][1];
  83. item.m_txtNeed.text = need.ToString();
  84. item.m_txtHas.text = StringUtil.GetColorText(has.ToString(), has >= need ? "#F2DB96" : "#C9F1A5");
  85. if (_canFoster && has < need) _canFoster = false;
  86. item.target.data = materialsArr[index];
  87. UI_ListMaterialsItem.ProxyEnd();
  88. }
  89. private void OnListMaterialsItem(EventContext context)
  90. {
  91. int[] itemData = (int[])(context.data as GComponent).data;
  92. // ViewManager.Show(ViewName.APPROACH_OF_ITEM_VIEW, new object[] { itemData[0], new object[] { typeof(ClothingView).FullName, (this.viewData as object[])[4] }, itemData[1] });
  93. object[] sourceDatas = new object[] { itemData[0], new object[] { typeof(ClothingView).FullName, (this.viewData as object[])[3] }, itemData[1] };
  94. GoodsItemTipsController.ShowItemTips(itemData[0], sourceDatas);
  95. }
  96. private void ListPropertyItemRender(int index, GObject obj)
  97. {
  98. UI_ListPropertyAddItem item = UI_ListPropertyAddItem.Proxy(obj);
  99. UI_ListScoreItem comProperty = UI_ListScoreItem.Proxy(item.m_comProperty);
  100. int score = (int)_propertyList.GetKey(index);
  101. comProperty.m_txtProperty.text = _propertyList[score].ToString();
  102. comProperty.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (score));
  103. // double addition = _addPropertyList[score] * 100 / 10000;
  104. double addition = cfg.addition * 100 / 10000;
  105. item.m_txtAdd.text = string.Format("+{0}%", addition);
  106. UI_ListPropertyAddItem.ProxyEnd();
  107. UI_ListScoreItem.ProxyEnd();
  108. }
  109. private async void OnClickBtnFoster()
  110. {
  111. SuitFosterCfg cfg = SuitFosterCfgArray.Instance.GetCfgsBysuitId(_suitId)[_index];
  112. if (!ItemUtil.CheckItemEnough(cfg.costId, cfg.costNum))
  113. {
  114. long has = ItemDataManager.GetItemNum(cfg.costId);
  115. ItemUtil.BuyCurrency(cfg.costId, cfg.costNum - has);
  116. return;
  117. }
  118. for (int i = 0; i < cfg.materialsArr.Length; i++)
  119. {
  120. if (!ItemUtil.CheckItemEnough(cfg.materialsArr[i][0], cfg.materialsArr[i][1], true)) return;
  121. }
  122. int result = await SuitFosterProxy.SendMaintainSuit(_suitId, _index + 1);
  123. if (result == ErrorCode.ERR_Success)
  124. {
  125. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_YANG_CHENG, 2);
  126. this.Hide();
  127. }
  128. }
  129. }
  130. }