ArenaDressInfoView.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 string _openViewName = "";
  19. private List<int> _itemList = new List<int>();
  20. private string[] _tags;
  21. private int _roleType = 0;//FightRoleType
  22. public override void Dispose()
  23. {
  24. if (_sceneObject != null)
  25. {
  26. GameObject.Destroy(_sceneObject);
  27. _sceneObject = null;
  28. }
  29. // _dressUpObj.Dispose();
  30. for (int i = 0; i < _listLongPress.Count; i++)
  31. {
  32. _listLongPress[i].Dispose();
  33. }
  34. _listLongPress.Clear();
  35. if (_ui != null)
  36. {
  37. _ui.Dispose();
  38. _ui = null;
  39. }
  40. base.Dispose();
  41. }
  42. protected override void OnInit()
  43. {
  44. base.OnInit();
  45. packageName = UI_ArenaUI.PACKAGE_NAME;
  46. _ui = UI_ArenaDressInfoUI.Create();
  47. this.viewCom = _ui.target;
  48. isfullScreen = true;
  49. _ui.m_c2.onChanged.Add(OnThemeChange);
  50. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  51. _ui.m_btnDress.onClick.Add(OnBtnDressClick);
  52. _ui.m_btnRecommend.onClick.Add(OnBtnRecommendClick);
  53. _ui.m_comValueInfo.m_btnFightScoreRule.onClick.Add(OnBtnFightScoreRule);
  54. _ui.m_grhCloseComFightScore.onClick.Add(OnCloseComFightScore);
  55. _ui.m_list.itemRenderer = RenderListItem;
  56. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneArenaDressUp"));
  57. }
  58. protected override void AddEventListener()
  59. {
  60. base.AddEventListener();
  61. }
  62. protected override void OnShown()
  63. {
  64. base.OnShown();
  65. _roleType = (int)(this.viewData as object[])[0];
  66. _themeIndex = (int)(this.viewData as object[])[1];
  67. _roleDatas = (this.viewData as object[])[2] as List<FightData>;
  68. _openViewName = (this.viewData as object[])[3].ToString();
  69. _ui.m_c1.selectedIndex = _roleType;
  70. _ui.m_c2.selectedIndex = _themeIndex;
  71. if (_sceneObject == null)
  72. {
  73. _sceneObject = GameObject.Instantiate(_scenePrefab);
  74. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  75. }
  76. UpdateView();
  77. }
  78. protected override void OnHide()
  79. {
  80. base.OnHide();
  81. if (_sceneObject != null)
  82. {
  83. GameObject.Destroy(_sceneObject);
  84. _sceneObject = null;
  85. }
  86. _ui.m_grhCloseComFightScore.visible = false;
  87. _ui.m_comValueInfo.m_c2.selectedIndex = 0;
  88. }
  89. protected override void RemoveEventListener()
  90. {
  91. base.RemoveEventListener();
  92. }
  93. private void OnClickBtnBack()
  94. {
  95. ViewManager.GoBackFrom(typeof(ArenaDressInfoView).FullName);//返回竞技场主界面
  96. if (!string.IsNullOrEmpty(_openViewName))
  97. {
  98. ViewManager.Show(_openViewName);//打开来源界面:如历史记录、排行榜
  99. }
  100. }
  101. private void OnThemeChange()
  102. {
  103. _themeIndex = _ui.m_c2.selectedIndex;
  104. if (_roleType == FightRoleType.MINE)
  105. {
  106. ArenaDataManager.Instance.SelectThemeIndex = _themeIndex;
  107. }
  108. UpdateView();
  109. }
  110. private void OnBtnFightScoreRule()
  111. {
  112. _ui.m_grhCloseComFightScore.visible = true;
  113. }
  114. private void OnCloseComFightScore()
  115. {
  116. _ui.m_comValueInfo.m_c2.selectedIndex = 0;
  117. _ui.m_grhCloseComFightScore.visible = false;
  118. }
  119. private void OnBtnDressClick()
  120. {
  121. ViewManager.Show<ArenaDressUpFightView>(null, new object[] { typeof(ArenaDressInfoView).FullName, new object[] { _roleType, _themeIndex, _roleDatas, "" } }, true);
  122. }
  123. private async void OnBtnRecommendClick()
  124. {
  125. for (int i = 0; i < ArenaDataManager.Instance.ThemeList.Count; i++)
  126. {
  127. int scoreType = ArenaDataManager.Instance.ThemeList[i];
  128. FightData roleData = ArenaDataManager.Instance.DressupList[i];
  129. roleData.scoreType = scoreType;
  130. roleData.itemList = ArenaDataManager.Instance.GetRecommentItemList(scoreType, roleData.tags);
  131. roleData.cardId = ArenaDataManager.Instance.GetRecommentCardId(scoreType, roleData.itemList);
  132. roleData.cardScore = ItemDataManager.GetItemAdditionScore(roleData.cardId, roleData.scoreType, roleData.tags);
  133. roleData.skillLvs = SkillDataManager.Instance.GetSkillLvs(roleData.cardId);
  134. FightDataManager.Instance.SetItemScoreList(roleData);
  135. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  136. _roleDatas = ArenaDataManager.Instance.DressupList;
  137. bool result = await ArenaSproxy.ReqChangeArenaDressup(i, roleData.cardId, roleData.itemList);
  138. if (!result)
  139. {
  140. PromptController.Instance.ShowFloatTextPrompt("保存失败");
  141. return;
  142. }
  143. }
  144. PromptController.Instance.ShowFloatTextPrompt("保存成功");
  145. UpdateView();
  146. }
  147. private void UpdateView()
  148. {
  149. // _itemList = _roleDatas[_themeIndex].itemList;
  150. _tags = _roleDatas[_themeIndex].tags;
  151. UpdateCardInfo(_roleDatas[_themeIndex].cardId);
  152. ArenaViewManager.Instance.UpdateValue(_ui.m_comValueInfo.target, _themeIndex, _roleDatas);
  153. MyDressUpHelper.dressUpObj.PutOnItemList(_roleDatas[_themeIndex].itemList);
  154. _itemList.Clear();
  155. for (int i = 0; i < _roleDatas[_themeIndex].itemList.Count; i++)
  156. {
  157. int itemId = _roleDatas[_themeIndex].itemList[i];
  158. if (itemId == ConstItemID.DEFULT_FA_XING
  159. || itemId == ConstItemID.DEFULT_LIAN_YI_QUN
  160. || itemId == ConstItemID.DEFULT_NEI_DA
  161. || itemId == ConstItemID.DEFULT_XIA_ZHUANG) continue;
  162. _itemList.Add(itemId);
  163. }
  164. _ui.m_list.numItems = _itemList.Count;
  165. }
  166. private void UpdateCardInfo(int cardId)
  167. {
  168. if (cardId == 0)
  169. {
  170. _ui.m_comCard.m_c1.selectedIndex = 0;
  171. return;
  172. }
  173. _ui.m_comCard.m_c1.selectedIndex = 1;
  174. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cardId);
  175. _ui.m_comCard.m_txtCardName.text = itemCfg.name;
  176. _ui.m_comCard.m_comCard.m_loaCard.url = ResPathUtil.GetCardSmallPath(itemCfg.res);
  177. _ui.m_comCard.m_loaScore.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  178. RarityIconController.UpdateRarityIcon(_ui.m_comCard.m_loaRarity, cardId, false);
  179. }
  180. private void RenderListItem(int index, GObject obj)
  181. {
  182. UI_ListPartsItem item = UI_ListPartsItem.Proxy(obj);
  183. item.m_iconSelected.visible = true;
  184. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemList[index]);
  185. item.m_txtTitle.text = itemCfg.name;
  186. item.m_ScoreType.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  187. item.m_icon.url = ResPathUtil.GetIconPath(itemCfg.res, "png");
  188. item.m_txtScore.text = _roleDatas[_themeIndex].itemScoreList[index].ToString();
  189. RarityIconController.UpdateRarityIcon(item.m_rarity, _itemList[index], false);
  190. if (item.target.data == null)
  191. {
  192. LongPressGesture longPressGesture = new LongPressGesture(item.target);
  193. longPressGesture.once = true;
  194. longPressGesture.onAction.Add(OnLongPress);
  195. _listLongPress.Add(longPressGesture);
  196. }
  197. item.target.data = _itemList[index];
  198. UI_ListPartsItem.ProxyEnd();
  199. }
  200. private void OnLongPress(EventContext context)
  201. {
  202. LongPressGesture gesture = (LongPressGesture)context.sender;
  203. int itemId = (int)gesture.host.data;
  204. GoodsItemTipsController.ShowItemTips(itemId);
  205. }
  206. }
  207. }