ArenaDressInfoView.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using FairyGUI;
  5. using UI.Arena;
  6. // using UI.DressUp;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class ArenaDressInfoView : BaseWindow
  11. {
  12. private UI_ArenaDressInfoUI _ui;
  13. private GameObject _scenePrefab;
  14. private GameObject _sceneObject;
  15. private List<LongPressGesture> _listLongPress = new List<LongPressGesture>();
  16. private List<FightData> _roleDatas;//可能是自己的搭配,也可能是对方玩家的搭配
  17. private int _themeIndex = 0;
  18. private List<int> _itemList;
  19. private string[] _tags;
  20. private int _roleType = 0;//FightRoleType
  21. public override void Dispose()
  22. {
  23. if (_sceneObject != null)
  24. {
  25. GameObject.Destroy(_sceneObject);
  26. _sceneObject = null;
  27. }
  28. // _dressUpObj.Dispose();
  29. for (int i = 0; i < _listLongPress.Count; i++)
  30. {
  31. _listLongPress[i].Dispose();
  32. }
  33. _listLongPress.Clear();
  34. if (_ui != null)
  35. {
  36. _ui.Dispose();
  37. _ui = null;
  38. }
  39. base.Dispose();
  40. }
  41. protected override void OnInit()
  42. {
  43. base.OnInit();
  44. packageName = UI_ArenaUI.PACKAGE_NAME;
  45. _ui = UI_ArenaDressInfoUI.Create();
  46. this.viewCom = _ui.target;
  47. isfullScreen = true;
  48. _ui.m_c2.onChanged.Add(OnThemeChange);
  49. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  50. _ui.m_btnDress.onClick.Add(OnBtnDressClick);
  51. _ui.m_btnRecommend.onClick.Add(OnBtnRecommendClick);
  52. _ui.m_list.itemRenderer = RenderListItem;
  53. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneArenaDressUp"));
  54. }
  55. protected override void AddEventListener()
  56. {
  57. base.AddEventListener();
  58. }
  59. protected override void OnShown()
  60. {
  61. base.OnShown();
  62. _roleType = (int)(this.viewData as object[])[0];
  63. _themeIndex = (int)(this.viewData as object[])[1];
  64. _roleDatas = (this.viewData as object[])[2] as List<FightData>;
  65. _ui.m_c1.selectedIndex = _roleType;
  66. if (_sceneObject == null)
  67. {
  68. _sceneObject = GameObject.Instantiate(_scenePrefab);
  69. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  70. }
  71. UpdateView();
  72. }
  73. protected override void OnHide()
  74. {
  75. base.OnHide();
  76. if (_sceneObject != null)
  77. {
  78. GameObject.Destroy(_sceneObject);
  79. _sceneObject = null;
  80. }
  81. }
  82. protected override void RemoveEventListener()
  83. {
  84. base.RemoveEventListener();
  85. }
  86. private void OnClickBtnBack()
  87. {
  88. ViewManager.GoBackFrom(typeof(ArenaDressInfoView).FullName);
  89. }
  90. private void OnThemeChange()
  91. {
  92. _themeIndex = _ui.m_c2.selectedIndex;
  93. if (_roleType == FightRoleType.MINE)
  94. {
  95. ArenaDataManager.Instance.SelectThemeIndex = _themeIndex;
  96. }
  97. UpdateView();
  98. }
  99. private void OnBtnDressClick()
  100. {
  101. ViewManager.Show<ArenaDressUpFightView>(null, new object[] { typeof(ArenaDressInfoView).FullName, new object[] { _roleType, _themeIndex, _roleDatas } }, true);
  102. }
  103. private async void OnBtnRecommendClick()
  104. {
  105. for (int i = 0; i < ArenaDataManager.Instance.ThemeList.Count; i++)
  106. {
  107. int scoreType = ArenaDataManager.Instance.ThemeList[i];
  108. FightData roleData = ArenaDataManager.Instance.DressupList[i];
  109. roleData.scoreType = scoreType;
  110. roleData.itemList = ArenaDataManager.Instance.GetRecommentItemList(scoreType, roleData.tags);
  111. roleData.cardId = ArenaDataManager.Instance.GetRecommentCardId(scoreType, roleData.itemList);
  112. roleData.cardScore = ItemDataManager.GetItemAdditionScore(roleData.cardId, roleData.scoreType, roleData.tags);
  113. roleData.skillLvs = SkillDataManager.Instance.GetSkillLvs(roleData.cardId);
  114. FightDataManager.Instance.SetItemScoreList(roleData);
  115. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  116. _roleDatas = ArenaDataManager.Instance.DressupList;
  117. bool result = await ArenaSproxy.ReqChangeArenaDressup(i, roleData.cardId, roleData.itemList);
  118. if (!result)
  119. {
  120. PromptController.Instance.ShowFloatTextPrompt("保存失败");
  121. return;
  122. }
  123. }
  124. PromptController.Instance.ShowFloatTextPrompt("保存成功");
  125. UpdateView();
  126. }
  127. private void UpdateView()
  128. {
  129. _itemList = _roleDatas[_themeIndex].itemList;
  130. _tags = _roleDatas[_themeIndex].tags;
  131. UpdateCardInfo(_roleDatas[_themeIndex].cardId);
  132. ArenaViewManager.Instance.UpdateValue(_ui.m_comValueInfo.target, _themeIndex, _roleDatas);
  133. MyDressUpHelper.dressUpObj.PutOnItemList(_itemList);
  134. _ui.m_list.numItems = _itemList.Count;
  135. }
  136. private void UpdateCardInfo(int cardId)
  137. {
  138. if (cardId == 0)
  139. {
  140. _ui.m_comCard.m_c1.selectedIndex = 0;
  141. return;
  142. }
  143. _ui.m_comCard.m_c1.selectedIndex = 1;
  144. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cardId);
  145. _ui.m_comCard.m_txtCardName.text = itemCfg.name;
  146. _ui.m_comCard.m_comCard.m_loaCard.url = ResPathUtil.GetCardSmallPath(itemCfg.res);
  147. _ui.m_comCard.m_loaScore.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  148. RarityIconController.UpdateRarityIcon(_ui.m_comCard.m_loaRarity, cardId, false);
  149. }
  150. private void RenderListItem(int index, GObject obj)
  151. {
  152. UI_ListPartsItem item = UI_ListPartsItem.Proxy(obj);
  153. item.m_iconSelected.visible = true;
  154. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemList[index]);
  155. item.m_txtTitle.text = itemCfg.name;
  156. item.m_ScoreType.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  157. item.m_icon.url = ResPathUtil.GetIconPath(itemCfg.res, "png");
  158. item.m_txtScore.text = _roleDatas[_themeIndex].itemScoreList[index].ToString();
  159. RarityIconController.UpdateRarityIcon(item.m_rarity, _itemList[index], false);
  160. if (item.target.data == null)
  161. {
  162. LongPressGesture longPressGesture = new LongPressGesture(item.target);
  163. longPressGesture.once = true;
  164. longPressGesture.onAction.Add(OnLongPress);
  165. _listLongPress.Add(longPressGesture);
  166. }
  167. item.target.data = _itemList[index];
  168. UI_ListPartsItem.ProxyEnd();
  169. }
  170. private void OnLongPress(EventContext context)
  171. {
  172. LongPressGesture gesture = (LongPressGesture)context.sender;
  173. int itemId = (int)gesture.host.data;
  174. GoodsItemTipsController.ShowItemTips(itemId);
  175. }
  176. }
  177. }