ClothingFosterView.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System.Collections;
  2. using ET;
  3. using FairyGUI;
  4. using UI.ClothingFoster;
  5. using UI.CommonGame;
  6. namespace GFGGame
  7. {
  8. public class ClothingFosterView : BaseWindow
  9. {
  10. private UI_ClothingFosterUI _ui;
  11. private int _suitId;
  12. private int _index;
  13. private SortedList _propertyList;
  14. private SortedList _addPropertyList;
  15. private bool _canFoster;
  16. public override void Dispose()
  17. {
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. packageName = UI_ClothingFosterUI.PACKAGE_NAME;
  29. _ui = UI_ClothingFosterUI.Create();
  30. this.viewCom = _ui.target;
  31. this.viewCom.Center();
  32. this.modal = true;
  33. // viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  34. _ui.m_listMaterials.itemRenderer = ListMaterialItemRender;
  35. _ui.m_listMaterials.onClickItem.Add(OnListMaterialsItem);
  36. _ui.m_listPropertyAdd.itemRenderer = ListPropertyItemRender;
  37. _ui.m_btnFoster.onClick.Add(OnClickBtnFoster);
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  43. }
  44. protected override void OnShown()
  45. {
  46. base.OnShown();
  47. _suitId = (int)(this.viewData as object[])[0];
  48. _index = (int)(this.viewData as object[])[1];
  49. _propertyList = (this.viewData as object[])[2] as SortedList;
  50. _addPropertyList = (this.viewData as object[])[3] as SortedList;
  51. _canFoster = true;
  52. SuitFosterCfg cfg = SuitFosterCfgArray.Instance.GetCfgs(_suitId)[_index];
  53. _ui.m_listMaterials.numItems = cfg.materialsArr.Length;
  54. int has = ItemDataManager.GetItemNum(cfg.costId);
  55. int need = cfg.costNum;
  56. UI_ComCostCurrency comConsume = UI_ComCostCurrency.Proxy(_ui.m_ComConsume);
  57. comConsume.m_txtNeed.text = StringUtil.GetColorText(need.ToString(), has >= need ? "#FFF8EA" : "#C9F1A5");
  58. UI_ComCostCurrency.ProxyEnd();
  59. if (_canFoster && has < need) _canFoster = false;
  60. _ui.m_listPropertyAdd.numItems = _propertyList.Count;
  61. }
  62. protected override void OnHide()
  63. {
  64. base.OnHide();
  65. }
  66. protected override void RemoveEventListener()
  67. {
  68. base.RemoveEventListener();
  69. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  70. }
  71. private void ListMaterialItemRender(int index, GObject obj)
  72. {
  73. UI_ListMaterialsItem item = UI_ListMaterialsItem.Proxy(obj);
  74. int[][] materialsArr = SuitFosterCfgArray.Instance.GetCfgs(_suitId)[_index].materialsArr;
  75. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(materialsArr[index][0]);
  76. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  77. int has = ItemDataManager.GetItemNum(itemCfg.id);
  78. item.m_txtHas.text = has.ToString();
  79. int need = materialsArr[index][1];
  80. item.m_txtNeed.text = need.ToString();
  81. item.m_txtHas.text = StringUtil.GetColorText(has.ToString(), has >= need ? "#F2DB96" : "#C9F1A5");
  82. if (_canFoster && has < need) _canFoster = false;
  83. item.target.data = materialsArr[index][0];
  84. UI_ListMaterialsItem.ProxyEnd();
  85. }
  86. private void OnListMaterialsItem(EventContext context)
  87. {
  88. int itemId = (int)(context.data as GComponent).data;
  89. ViewManager.Show(ViewName.APPROACH_OF_ITEM_VIEW, new object[] { itemId, new object[] { typeof(ClothingView).FullName, ( this.viewData as object[])[4] }
  90. });
  91. }
  92. private void ListPropertyItemRender(int index, GObject obj)
  93. {
  94. UI_ListPropertyAddItem item = UI_ListPropertyAddItem.Proxy(obj);
  95. UI_ListPropertyItem comProperty = UI_ListPropertyItem.Proxy(item.m_comProperty);
  96. int score = (int)_propertyList.GetKey(index);
  97. comProperty.m_txtProperty.text = _propertyList[score].ToString();
  98. comProperty.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (score));
  99. item.m_txtAdd.text = "+" + _addPropertyList.GetByIndex(index);
  100. UI_ListPropertyAddItem.ProxyEnd();
  101. UI_ListPropertyItem.ProxyEnd();
  102. }
  103. private async void OnClickBtnFoster()
  104. {
  105. if (!_canFoster)
  106. {
  107. PromptController.Instance.ShowFloatTextPrompt("材料不足");
  108. return;
  109. }
  110. int result = await SuitFosterProxy.SendMaintainSuit(_suitId, _index + 1);
  111. if (result == ErrorCode.ERR_Success)
  112. {
  113. LogServerHelper.SendNodeLog((int)PlayParticipationEnum.FU_ZHUANG_YANG_CHENG, 2);
  114. this.Hide();
  115. }
  116. }
  117. }
  118. }