GoodsItemTipsView.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using FairyGUI;
  2. using UI.CommonGame;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace GFGGame
  6. {
  7. public class GoodsItemTipsView : BaseWindow
  8. {
  9. private UI_GoodsItemTips _ui;
  10. // private ItemView itemView;
  11. private ApproachView approachView;
  12. private ItemCfg itemCfg;
  13. public override void Dispose()
  14. {
  15. base.Dispose();
  16. // itemView.Dispose();
  17. if (approachView != null)
  18. {
  19. approachView.Dispose();
  20. approachView = null;
  21. }
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. _ui = null;
  26. }
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. _ui = UI_GoodsItemTips.Create();
  32. this.viewCom = _ui.target;
  33. this.viewCom.Center();
  34. this.modal = true;
  35. approachView = new ApproachView();
  36. approachView.OnInit(_ui.m_comTipsApproach.target);
  37. _ui.m_comTipsBase.m_listTag.itemRenderer = RenderListTagItem;
  38. _ui.m_comTipsBase.m_listItem.itemRenderer = ListItemRenderer;
  39. }
  40. protected override void AddEventListener()
  41. {
  42. base.AddEventListener();
  43. EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. int itemID = (int)(viewData as object[])[0];
  49. object[] sourceDatas = (viewData as object[])[1] as object[];
  50. itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
  51. UpdateBase();
  52. UpdateScore();
  53. UpdateTags();
  54. UpdateItems();
  55. UpdateSourec(sourceDatas);
  56. // this.viewCom.height = _ui.m_grpTips.height;
  57. // this.viewCom.Center();
  58. Timers.inst.AddUpdate(CheckGuide);
  59. }
  60. protected override void OnHide()
  61. {
  62. if (approachView != null)
  63. {
  64. approachView.OnHide();
  65. }
  66. Timers.inst.Remove(CheckGuide);
  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 UpdateBase()
  75. {
  76. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  77. {
  78. _ui.m_comTipsBase.m_txtName.text = string.Format("{0} _{1}", itemCfg.name, itemCfg.id);
  79. }
  80. else
  81. {
  82. _ui.m_comTipsBase.m_txtName.text = itemCfg.name;
  83. }
  84. _ui.m_comTipsBase.m_txtOwned.SetVar("count", "" + ItemDataManager.GetItemNum(itemCfg.id)).FlushVars();
  85. _ui.m_comTipsBase.m_txtDesc.text = string.IsNullOrEmpty(itemCfg.desc) ? "暂无描述" : itemCfg.desc;
  86. _ui.m_comTipsBase.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  87. RarityIconController.UpdateRarityIcon(_ui.m_comTipsBase.m_loaRarity, itemCfg.id, false);
  88. ET.Log.Debug(itemCfg.name + " itemId:" + itemCfg.id);
  89. }
  90. private void UpdateScore()
  91. {
  92. bool isDressUp = itemCfg.itemType == ConstItemType.DRESS_UP;
  93. _ui.m_comTipsBase.m_loaRarity.visible = isDressUp;
  94. _ui.m_comTipsBase.m_grpScore.visible = isDressUp;
  95. if (!isDressUp) return;
  96. _ui.m_comTipsBase.m_txtGong.text = "" + itemCfg.score1;
  97. _ui.m_comTipsBase.m_txtShang.text = "" + itemCfg.score2;
  98. _ui.m_comTipsBase.m_txtJue.text = "" + itemCfg.score3;
  99. _ui.m_comTipsBase.m_txtZhi.text = "" + itemCfg.score4;
  100. }
  101. private void UpdateTags()
  102. {
  103. _ui.m_comTipsBase.m_listTag.visible = itemCfg.tagsArr.Length > 0;
  104. _ui.m_comTipsBase.m_listTag.numItems = itemCfg.tagsArr.Length;
  105. }
  106. private void RenderListTagItem(int index, GObject obj)
  107. {
  108. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  109. ItemUtil.UpdateTag(item.m_comTag.target, itemCfg.tagsArr[index][0]);
  110. item.m_txtTagScore.text = itemCfg.tagsArr[index][1].ToString();
  111. UI_ListTagItem.ProxyEnd();
  112. }
  113. private void UpdateItems()
  114. {
  115. _ui.m_comTipsBase.m_listItem.visible = itemCfg.itemsArr.Length > 0;
  116. _ui.m_comTipsBase.m_listItem.numItems = itemCfg.itemsArr.Length;
  117. }
  118. private void ListItemRenderer(int index, GObject obj)
  119. {
  120. ItemData itemData = ItemUtil.createItemData(itemCfg.itemsArr[index]);
  121. if (obj.data == null)
  122. {
  123. obj.data = new ItemView(obj as GComponent);
  124. }
  125. (obj.data as ItemView).SetData(itemData);
  126. (obj.data as ItemView).ChangeTxtCountStyle();
  127. }
  128. private void UpdateSourec(object[] sourceDatas)
  129. {
  130. _ui.m_comTipsApproach.target.visible = sourceDatas != null;
  131. if (sourceDatas == null) return;
  132. approachView.OnShow(sourceDatas);
  133. }
  134. private void CheckGuide(object param)
  135. {
  136. if (_ui.m_comTipsApproach.m_list.numItems > 0 && GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  137. {
  138. UpdateToCheckGuide(null);
  139. }
  140. else
  141. {
  142. Timers.inst.Remove(CheckGuide);
  143. }
  144. }
  145. protected override void UpdateToCheckGuide(object param)
  146. {
  147. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  148. List<string[]> _approachDatas = _ui.m_comTipsApproach.m_list.data as List<string[]>;
  149. if (_approachDatas == null) return;
  150. GComponent obj = null;
  151. for (int i = 0; i < _approachDatas.Count; i++)
  152. {
  153. if (_approachDatas[i][0] == ConstFunctionId.FU_ZHUANG_DIAN)
  154. {
  155. _ui.m_comTipsApproach.m_list.ScrollToView(i);
  156. UI_ListSourceItem item = UI_ListSourceItem.Proxy(_ui.m_comTipsApproach.m_list.GetChildAt(i));
  157. obj = item.m_btnGo.target;
  158. UI_ListSourceItem.ProxyEnd();
  159. break;
  160. }
  161. }
  162. GuideController.TryGuide(obj, ConstGuideId.BUY_CLOTHING, 4, "该物品可以在服装店购买,点开服装店看看。");
  163. }
  164. }
  165. }