GoodsItemTipsView.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using FairyGUI;
  2. using UI.CommonGame;
  3. using System.Collections;
  4. namespace GFGGame
  5. {
  6. public class GoodsItemTipsView : BaseWindow
  7. {
  8. private UI_GoodsItemTips _ui;
  9. private ItemView itemView;
  10. private ApproachView approachView;
  11. private ItemCfg itemCfg;
  12. public override void Dispose()
  13. {
  14. base.Dispose();
  15. itemView.Dispose();
  16. if (approachView != null)
  17. {
  18. approachView.Dispose();
  19. approachView = null;
  20. }
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. }
  27. protected override void OnInit()
  28. {
  29. base.OnInit();
  30. _ui = UI_GoodsItemTips.Create();
  31. this.viewCom = _ui.target;
  32. this.viewCom.Center();
  33. this.modal = true;
  34. }
  35. protected override void AddEventListener()
  36. {
  37. base.AddEventListener();
  38. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  39. }
  40. protected override void OnShown()
  41. {
  42. base.OnShown();
  43. int itemID = (int)(viewData as object[])[0];
  44. object[] sourceDatas = (viewData as object[])[1] as object[];
  45. itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
  46. UpdateBase();
  47. UpdateScore();
  48. _ui.m_comTipsDesc.m_txtDesc.text = string.IsNullOrEmpty(itemCfg.desc) ? "暂无描述" : itemCfg.desc;
  49. UpdateSourec(sourceDatas);
  50. }
  51. protected override void OnHide()
  52. {
  53. if (approachView != null)
  54. {
  55. approachView.OnHide();
  56. }
  57. base.OnHide();
  58. }
  59. protected override void RemoveEventListener()
  60. {
  61. base.RemoveEventListener();
  62. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  63. }
  64. private void UpdateBase()
  65. {
  66. _ui.m_comTipsBase.m_txtOwned.SetVar("count", "" + ItemDataManager.GetItemNum(itemCfg.id)).FlushVars();
  67. _ui.m_comTipsBase.m_txtName.text = itemCfg.name;
  68. if (itemView == null)
  69. {
  70. itemView = new ItemView(_ui.m_comTipsBase.m_goodsItem.target);
  71. }
  72. ItemData itemData = ItemUtil.createItemData(new int[] { itemCfg.id, 1 });
  73. itemView.SetData(itemData);
  74. itemView.ShowCount = false;
  75. itemView.ShowTips = false;
  76. itemView.ShowRarity = false;
  77. }
  78. private void UpdateScore()
  79. {
  80. bool isDressUp = itemCfg.itemType == ConstItemType.DRESS_UP;
  81. _ui.m_comTipsBase.m_rarity.visible = isDressUp;
  82. _ui.m_comTipsScores.target.visible = isDressUp;
  83. if (!isDressUp) return;
  84. _ui.m_comTipsScores.m_txtGong.text = "" + itemCfg.score1;
  85. _ui.m_comTipsScores.m_txtShang.text = "" + itemCfg.score2;
  86. _ui.m_comTipsScores.m_txtJue.text = "" + itemCfg.score3;
  87. _ui.m_comTipsScores.m_txtZhi.text = "" + itemCfg.score4;
  88. }
  89. private void UpdateSourec(object[] sourceDatas)
  90. {
  91. _ui.m_comTipsApproach.target.visible = sourceDatas != null;
  92. if (sourceDatas == null) return;
  93. if (approachView == null)
  94. {
  95. approachView = new ApproachView();
  96. }
  97. approachView.OnShow(_ui.m_comTipsApproach.target, sourceDatas);
  98. }
  99. }
  100. }