GetSuitItemVIew.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using UI.CommonGame;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using static UnityEditor.Progress;
  5. namespace GFGGame
  6. {
  7. public class GetSuitItemVIew : BaseWindow
  8. {
  9. private UI_GetSuitItemUI _ui;
  10. private GameObject _scenePrefab;
  11. private GameObject _sceneObject;
  12. private GoWrapper _wrapper;
  13. private GameObject _gameObject1;
  14. private GoWrapper _wrapper1;
  15. //正在显示的套装id
  16. private int _suitIdShowing;
  17. private int guideId = 0;//0:没有引导 1:首次获得套装2:首次获得套装部件
  18. public override void Dispose()
  19. {
  20. if (_scenePrefab != null)
  21. {
  22. GameObject.Destroy(_scenePrefab);
  23. _scenePrefab = null;
  24. }
  25. SceneController.DestroyObjectFromView(_gameObject1);
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. _ui = UI_GetSuitItemUI.Create();
  32. this.viewCom = _ui.target;
  33. isfullScreen = true;
  34. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  35. _ui.m_bg.onClick.Add(OnClickBg);
  36. string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_tz");
  37. SceneController.AddObjectToView(null, null, _ui.m_holderEffect, resPath, out _gameObject1, out _wrapper1);
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. GRoot.inst.touchable = true;
  43. int itemId = (int)viewData;
  44. guideId = 0;
  45. UpdateView(itemId);
  46. }
  47. protected override void OnHide()
  48. {
  49. base.OnHide();
  50. _suitIdShowing = 0;
  51. if (_sceneObject != null)
  52. {
  53. GameObject.Destroy(_sceneObject);
  54. _sceneObject = null;
  55. }
  56. if (_wrapper != null)
  57. {
  58. _wrapper.wrapTarget = null;
  59. }
  60. if (this.viewCom == null || this.viewCom.root == null)
  61. {
  62. Timers.inst.CallLater((object param) =>
  63. {
  64. GetSuitItemController.TryShow(0);
  65. });
  66. }
  67. TryCompleteGuide();
  68. }
  69. public override void Refresh()
  70. {
  71. int itemId = (int)viewData;
  72. guideId = 0;
  73. UpdateView(itemId);
  74. }
  75. private void OnClickBg()
  76. {
  77. int itemId = GetSuitItemController.TryShow(0);
  78. if (itemId > 0)
  79. {
  80. UpdateView(itemId);
  81. }
  82. else
  83. {
  84. Hide();
  85. }
  86. }
  87. private void UpdateItem(int itemdId)
  88. {
  89. UI_LuckyBoxBonusItem itemUI = _ui.m_item;
  90. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdId);
  91. itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  92. string itemName = itemCfg.name;
  93. itemUI.m_comIcon.m_txtName.text = itemName;
  94. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemdId, false);
  95. itemUI.target.data = itemdId;
  96. itemUI.target.onClick.Clear();
  97. itemUI.target.onClick.Add(OnClickItemUI);
  98. }
  99. private void OnClickItemUI(EventContext context)
  100. {
  101. GComponent item = context.sender as GComponent;
  102. int itemID = (int)item.data;
  103. GoodsItemTipsController.ShowItemTips(itemID);
  104. }
  105. private void UpdateView(int itemId)
  106. {
  107. _ui.m_holderEffect.visible = true;
  108. int count = 0;
  109. int totalCount = 1;
  110. int suitId = 0;
  111. int[] itemIds = null;
  112. DressUpMenuSuitDataManager.GetSuitProgressByItemId(itemId, out suitId, out count);
  113. totalCount = SuitCfgManager.Instance.GetTotalCountOfOneSuit(suitId);
  114. itemIds = SuitCfgManager.Instance.GetSuitItems(suitId);
  115. if (suitId > 0)
  116. {
  117. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  118. _ui.m_txtName.text = "套装·" + suitCfg.name;
  119. int targetY = (int)(_ui.m_item.target.y + _ui.m_item.target.height + 50);
  120. if (count == totalCount)
  121. {
  122. guideId = 1;
  123. }
  124. else
  125. {
  126. guideId = 2;
  127. }
  128. }
  129. _ui.m_probar.max = totalCount;
  130. _ui.m_probar.value = count;
  131. UpdateItem(itemId);
  132. if(_suitIdShowing == 0 || _suitIdShowing != suitId)
  133. {
  134. if (_sceneObject != null)
  135. {
  136. GameObject.Destroy(_sceneObject);
  137. _sceneObject = null;
  138. }
  139. _sceneObject = GameObject.Instantiate(_scenePrefab);
  140. int scale = 70;
  141. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  142. SceneController.UpdateRole(itemIds, _sceneObject);
  143. if (_wrapper == null)
  144. {
  145. _wrapper = new GoWrapper(_sceneObject);
  146. _ui.m_holder.SetNativeObject(_wrapper);
  147. }
  148. else
  149. {
  150. _wrapper.wrapTarget = _sceneObject;
  151. }
  152. _suitIdShowing = suitId;
  153. }
  154. }
  155. protected override void UpdateToCheckGuide(object param)
  156. {
  157. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  158. if (guideId == 1) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FULL, 1, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", -1, true, (int)(this.viewCom.height - 150));
  159. if (guideId == 2) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FIRST, 1, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", -1, true, (int)(this.viewCom.height - 150));
  160. }
  161. protected override void TryCompleteGuide()
  162. {
  163. GuideCfg cfg;
  164. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FULL);
  165. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  166. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FULL, 1);
  167. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FIRST);
  168. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  169. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FIRST, 1);
  170. }
  171. }
  172. }