SuitFosterView.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 SuitFosterView : BaseWindow
  9. {
  10. private UI_SuitFosterUI _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. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. packageName = UI_SuitFosterUI.PACKAGE_NAME;
  24. _ui = UI_SuitFosterUI.Create();
  25. this.viewCom = _ui.target;
  26. this.viewCom.Center();
  27. this.modal = true;
  28. // viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  29. _ui.m_listMaterials.itemRenderer = ListMaterialItemRender;
  30. _ui.m_listMaterials.onClickItem.Add(OnListMaterialsItem);
  31. _ui.m_listPropertyAdd.itemRenderer = ListPropertyItemRender;
  32. _ui.m_btnFoster.onClick.Add(OnClickBtnFoster);
  33. }
  34. protected override void OnShown()
  35. {
  36. base.OnShown();
  37. _suitId = (int)(this.viewData as object[])[0];
  38. _index = (int)(this.viewData as object[])[1];
  39. _propertyList = (this.viewData as object[])[2] as SortedList;
  40. _addPropertyList = (this.viewData as object[])[3] as SortedList;
  41. _canFoster = true;
  42. SuitFosterCfg cfg = SuitFosterCfgArray.Instance.GetCfgs(_suitId)[_index];
  43. _ui.m_listMaterials.numItems = cfg.materialsArr.Length;
  44. int has = ItemDataManager.GetItemNum(cfg.costId);
  45. int need = cfg.costNum;
  46. UI_ComConsumeCurrency comConsume = UI_ComConsumeCurrency.Proxy(_ui.m_ComConsume);
  47. comConsume.m_txtHas.text = has.ToString();
  48. comConsume.m_txtNeed.text = need.ToString();
  49. if (_canFoster && has < need) _canFoster = false;
  50. _ui.m_listPropertyAdd.numItems = _propertyList.Count;
  51. }
  52. protected override void OnHide()
  53. {
  54. base.OnHide();
  55. }
  56. private void ListMaterialItemRender(int index, GObject obj)
  57. {
  58. UI_ListMaterialsItem item = UI_ListMaterialsItem.Proxy(obj);
  59. int[][] materialsArr = SuitFosterCfgArray.Instance.GetCfgs(_suitId)[_index].materialsArr;
  60. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(materialsArr[index][0]);
  61. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  62. int has = ItemDataManager.GetItemNum(itemCfg.id);
  63. item.m_txtHas.text = has.ToString();
  64. int need = materialsArr[index][1];
  65. item.m_txtNeed.text = StringUtil.GetColorText(need.ToString(), has >= need ? "#DD994A" : "#DD994A");
  66. if (_canFoster && has < need) _canFoster = false;
  67. item.target.data = materialsArr[index][0];
  68. }
  69. private void OnListMaterialsItem(EventContext context)
  70. {
  71. int itemId = (int)(context.data as GComponent).data;
  72. GoodsItemTipsController.ShowItemTips(itemId);
  73. }
  74. private void ListPropertyItemRender(int index, GObject obj)
  75. {
  76. UI_ListPropertyAddItem item = UI_ListPropertyAddItem.Proxy(obj);
  77. UI_ListPropertyItem comProperty = UI_ListPropertyItem.Proxy(item.m_comProperty);
  78. int score = (int)_propertyList.GetKey(index);
  79. comProperty.m_txtProperty.text = _propertyList[score].ToString();
  80. comProperty.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (score));
  81. item.m_txtAdd.text = _addPropertyList.GetByIndex(index).ToString();
  82. }
  83. private void OnClickBtnFoster()
  84. {
  85. if (!_canFoster)
  86. {
  87. PromptController.Instance.ShowFloatTextPrompt("材料不足");
  88. return;
  89. }
  90. SuitFosterHelper.SendMaintainSuit(_suitId, _index + 1).Coroutine();
  91. }
  92. }
  93. }