GoodsItemTipsView.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. _ui.m_comBg.m_btnClose.onClick.Add(Hide);
  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. int itemID = (int)(viewData as object[])[0];
  50. object[] sourceDatas = (viewData as object[])[1] as object[];
  51. itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
  52. UpdateBase();
  53. UpdateScore();
  54. UpdateTags();
  55. UpdateItems();
  56. UpdateSourec(sourceDatas);
  57. // this.viewCom.height = _ui.m_grpTips.height;
  58. // this.viewCom.Center();
  59. Timers.inst.AddUpdate(CheckGuide);
  60. }
  61. protected override void OnHide()
  62. {
  63. if (approachView != null)
  64. {
  65. approachView.OnHide();
  66. }
  67. Timers.inst.Remove(CheckGuide);
  68. base.OnHide();
  69. }
  70. protected override void RemoveEventListener()
  71. {
  72. base.RemoveEventListener();
  73. EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
  74. }
  75. private void UpdateBase()
  76. {
  77. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  78. {
  79. _ui.m_comBg.m_txtTitle.text = string.Format("{0} _{1}", itemCfg.name, itemCfg.id);
  80. }
  81. else
  82. {
  83. _ui.m_comBg.m_txtTitle.text = itemCfg.name;
  84. }
  85. _ui.m_comTipsBase.m_txtOwned.SetVar("count", "" + ItemDataManager.GetItemNum(itemCfg.id)).FlushVars();
  86. _ui.m_comTipsBase.m_txtDesc.text = string.IsNullOrEmpty(itemCfg.desc) ? "暂无描述" : itemCfg.desc;
  87. _ui.m_comTipsBase.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  88. RarityIconController.UpdateRarityIcon(_ui.m_comTipsBase.m_loaRarity, itemCfg.id, false);
  89. ET.Log.Debug(itemCfg.name + " itemId:" + itemCfg.id);
  90. }
  91. private void UpdateScore()
  92. {
  93. bool isDressUp = itemCfg.itemType == ConstItemType.DRESS_UP;
  94. _ui.m_comTipsBase.m_loaRarity.visible = isDressUp;
  95. _ui.m_comTipsBase.m_grpScore.visible = isDressUp;
  96. if (!isDressUp) return;
  97. _ui.m_comTipsBase.m_txtGong.text = "" + itemCfg.score1;
  98. _ui.m_comTipsBase.m_txtShang.text = "" + itemCfg.score2;
  99. _ui.m_comTipsBase.m_txtJue.text = "" + itemCfg.score3;
  100. _ui.m_comTipsBase.m_txtZhi.text = "" + itemCfg.score4;
  101. }
  102. private void UpdateTags()
  103. {
  104. _ui.m_comTipsBase.m_listTag.visible = itemCfg.tagsArr.Length > 0;
  105. _ui.m_comTipsBase.m_listTag.numItems = itemCfg.tagsArr.Length;
  106. }
  107. private void RenderListTagItem(int index, GObject obj)
  108. {
  109. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  110. ItemUtil.UpdateTag(item.m_comTag.target, itemCfg.tagsArr[index][0]);
  111. item.m_txtTagScore.text = itemCfg.tagsArr[index][1].ToString();
  112. UI_ListTagItem.ProxyEnd();
  113. }
  114. private void UpdateItems()
  115. {
  116. _ui.m_comTipsBase.m_listItem.visible = itemCfg.itemsArr.Length > 0;
  117. _ui.m_comTipsBase.m_listItem.numItems = itemCfg.itemsArr.Length;
  118. }
  119. private void ListItemRenderer(int index, GObject obj)
  120. {
  121. ItemData itemData = ItemUtil.createItemData(itemCfg.itemsArr[index]);
  122. if (obj.data == null)
  123. {
  124. obj.data = new ItemView(obj as GComponent);
  125. }
  126. (obj.data as ItemView).SetData(itemData);
  127. (obj.data as ItemView).ChangeTxtCountStyle();
  128. }
  129. private void UpdateSourec(object[] sourceDatas)
  130. {
  131. _ui.m_comTipsApproach.target.visible = sourceDatas != null;
  132. if (sourceDatas == null) return;
  133. approachView.OnShow(sourceDatas);
  134. }
  135. private void CheckGuide(object param)
  136. {
  137. if (_ui.m_comTipsApproach.m_list.numItems > 0 && GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  138. {
  139. UpdateToCheckGuide(null);
  140. }
  141. else
  142. {
  143. Timers.inst.Remove(CheckGuide);
  144. }
  145. }
  146. protected override void UpdateToCheckGuide(object param)
  147. {
  148. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  149. List<string[]> _approachDatas = _ui.m_comTipsApproach.m_list.data as List<string[]>;
  150. if (_approachDatas == null) return;
  151. GComponent obj = null;
  152. for (int i = 0; i < _approachDatas.Count; i++)
  153. {
  154. if (_approachDatas[i][0] == ConstFunctionId.FU_ZHUANG_DIAN)
  155. {
  156. _ui.m_comTipsApproach.m_list.ScrollToView(i);
  157. UI_ListSourceItem item = UI_ListSourceItem.Proxy(_ui.m_comTipsApproach.m_list.GetChildAt(i));
  158. obj = item.m_btnGo.target;
  159. UI_ListSourceItem.ProxyEnd();
  160. break;
  161. }
  162. }
  163. GuideController.TryGuide(obj, ConstGuideId.BUY_CLOTHING, 4, "该物品可以在服装店购买,点开服装店看看。");
  164. }
  165. }
  166. }