SuitView.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using FairyGUI;
  4. using UI.ClothingFoster;
  5. using UI.CommonGame;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class SuitView : BaseWindow
  10. {
  11. private UI_SuitUI _ui;
  12. private GameObject _scenePrefab;
  13. private GameObject _sceneObject;
  14. private GoWrapper _wrapper;
  15. private DressUpObjDataCache _dressUpObjDataCache;
  16. private bool _actionIsPic;
  17. private List<int> _suitIds;//已解锁套装列表
  18. private SortedList _propertyList;
  19. private int _suitId;
  20. private int _index;
  21. public override void Dispose()
  22. {
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. packageName = UI_SuitUI.PACKAGE_NAME;
  29. _ui = UI_SuitUI.Create();
  30. this.viewCom = _ui.target;
  31. this.viewCom.Center();
  32. isfullScreen = true;
  33. this.clickBlankToClose = false;
  34. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  35. _dressUpObjDataCache = new DressUpObjDataCache();
  36. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  37. _ui.m_btnLeft.onClick.Add(() => { OnClickBtnDirection(-1); });
  38. _ui.m_btnRight.onClick.Add(() => { OnClickBtnDirection(1); });
  39. _ui.m_btnReward.target.onClick.Add(OnClickBtnReward);
  40. _ui.m_btnPropertyShow.onClick.Add(OnClickBtnPropertyShow);
  41. _ui.m_listFoster.itemRenderer = ListFosterItemRender;
  42. _ui.m_listFoster.onClickItem.Add(OnClickListFosterItem);
  43. _ui.m_listProperty.itemRenderer = ListPropertyItemRender;
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. object[] datas = this.viewData as object[];
  49. _suitId = (int)datas[0];
  50. List<int> suitIds = datas[1] as List<int>;
  51. _suitIds = new List<int>();
  52. foreach (int suitId in suitIds)
  53. {
  54. if (DressUpMenuSuitDataManager.CheckHaveSuit(suitId))
  55. {
  56. _suitIds.Add(suitId);
  57. }
  58. }
  59. UpdateView();
  60. }
  61. protected override void OnHide()
  62. {
  63. base.OnHide();
  64. }
  65. private void OnClickBtnBack()
  66. {
  67. ViewManager.GoBackFrom(typeof(SuitView).FullName);
  68. }
  69. private void UpdateView()
  70. {
  71. UpdateArrows();
  72. UpdateSuitView();
  73. _ui.m_listFoster.numItems = SuitFosterCfgArray.Instance.GetCfgs(_suitId).Length;
  74. _propertyList = SuitFosterDataManager.Instance.GetPropertyData(_suitId, _index);
  75. _ui.m_listProperty.numItems = _propertyList.Count;
  76. }
  77. private void UpdateArrows()
  78. {
  79. int index = _suitIds.IndexOf(_suitId);
  80. int count = _suitIds.Count;
  81. _ui.m_btnRight.visible = (index + 1 < count);
  82. _ui.m_btnLeft.visible = (index - 1 >= 0);
  83. }
  84. private void OnClickBtnDirection(int direction)
  85. {
  86. int index = _suitIds.IndexOf(_suitId);
  87. int targetIndex = index + direction;
  88. if (targetIndex >= 0 && direction == -1 || targetIndex < _suitIds.Count && direction == 1)
  89. {
  90. _suitId = _suitIds[targetIndex];
  91. UpdateView();
  92. }
  93. }
  94. private void UpdateSuitView(bool isPic = true)
  95. {
  96. _actionIsPic = isPic;
  97. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  98. _ui.m_txtName.text = suitCfg.name;
  99. if (_sceneObject != null)
  100. {
  101. GameObject.Destroy(_sceneObject);
  102. _sceneObject = null;
  103. }
  104. _sceneObject = GameObject.Instantiate(_scenePrefab);
  105. int scale = 100;
  106. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  107. _dressUpObjDataCache.setSceneObj(_sceneObject);
  108. _dressUpObjDataCache.PutOnDefaultSuitSaved(false);
  109. _dressUpObjDataCache.PutOnSuitCfg(_suitId, isPic, false, new int[] { ConstDressUpItemType.BEI_JING });
  110. if (_wrapper == null)
  111. {
  112. _wrapper = new GoWrapper(_sceneObject);
  113. _ui.m_holder.SetNativeObject(_wrapper);
  114. }
  115. else
  116. {
  117. _wrapper.wrapTarget = _sceneObject;
  118. }
  119. }
  120. private void ListFosterItemRender(int index, GObject obj)
  121. {
  122. UI_ListFosterItem item = UI_ListFosterItem.Proxy(obj);
  123. item.target.data = index;
  124. item.m_finish.selectedIndex = SuitFosterDataManager.Instance.GetFosterState(_suitId, index);
  125. if (SuitFosterDataManager.Instance.GetSuitFosterData(_suitId).maintainStep == index)
  126. {
  127. _index = index;
  128. }
  129. }
  130. private void ListPropertyItemRender(int index, GObject obj)
  131. {
  132. UI_ListPropertyItem item = UI_ListPropertyItem.Proxy(obj);
  133. int score = index + 1;
  134. item.m_txtProperty.text = _propertyList[score].ToString();
  135. item.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (score));
  136. }
  137. private void OnClickListFosterItem(EventContext context)
  138. {
  139. int index = (int)(context.data as GObject).data;
  140. if (index == _index)
  141. {
  142. ViewManager.Show<SuitFosterView>(new object[] { _suitId, index });
  143. }
  144. }
  145. private void OnClickBtnReward()
  146. {
  147. ViewManager.Show<SuitRewardView>(_suitId);
  148. }
  149. private void OnClickBtnPropertyShow()
  150. {
  151. ViewManager.Show<SuitPropertyShowView>(new object[] { _suitId, _index });
  152. }
  153. }
  154. }