ArenaDressInfoView.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_grhCloseComFightScore.visible = false;
  70. _ui.m_c1.selectedIndex = _roleType;
  71. _ui.m_c2.selectedIndex = _themeIndex;
  72. if (_sceneObject == null)
  73. {
  74. _sceneObject = GameObject.Instantiate(_scenePrefab);
  75. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  76. }
  77. UpdateView();
  78. }
  79. protected override void OnHide()
  80. {
  81. base.OnHide();
  82. if (_sceneObject != null)
  83. {
  84. GameObject.Destroy(_sceneObject);
  85. _sceneObject = null;
  86. }
  87. _ui.m_grhCloseComFightScore.visible = false;
  88. _ui.m_comValueInfo.m_c2.selectedIndex = 0;
  89. }
  90. protected override void RemoveEventListener()
  91. {
  92. base.RemoveEventListener();
  93. }
  94. private void OnClickBtnBack()
  95. {
  96. ViewManager.GoBackFrom(typeof(ArenaDressInfoView).FullName);//返回竞技场主界面
  97. if (!string.IsNullOrEmpty(_openViewName))
  98. {
  99. ViewManager.Show(_openViewName);//打开来源界面:如历史记录、排行榜
  100. }
  101. }
  102. private void OnThemeChange()
  103. {
  104. _themeIndex = _ui.m_c2.selectedIndex;
  105. if (_roleType == FightRoleType.MINE)
  106. {
  107. ArenaDataManager.Instance.SelectThemeIndex = _themeIndex;
  108. }
  109. UpdateView();
  110. }
  111. private void OnBtnFightScoreRule()
  112. {
  113. _ui.m_grhCloseComFightScore.visible = true;
  114. }
  115. private void OnCloseComFightScore()
  116. {
  117. _ui.m_comValueInfo.m_c2.selectedIndex = 0;
  118. _ui.m_grhCloseComFightScore.visible = false;
  119. }
  120. private void OnBtnDressClick()
  121. {
  122. ViewManager.Show<ArenaDressUpFightView>(null, new object[] { typeof(ArenaDressInfoView).FullName, new object[] { _roleType, _themeIndex, _roleDatas, "" } }, true);
  123. }
  124. private async void OnBtnRecommendClick()
  125. {
  126. for (int i = 0; i < ArenaDataManager.Instance.ThemeList.Count; i++)
  127. {
  128. int scoreType = ArenaDataManager.Instance.ThemeList[i];
  129. FightData roleData = ArenaDataManager.Instance.DressupList[i];
  130. roleData.scoreType = scoreType;
  131. roleData.itemList = ArenaDataManager.Instance.GetRecommentItemList(scoreType, roleData.tags);
  132. roleData.cardId = ArenaDataManager.Instance.GetRecommentCardId(scoreType, roleData.itemList);
  133. roleData.cardScore = ItemDataManager.GetItemAdditionScore(roleData.cardId, roleData.scoreType, roleData.tags);
  134. roleData.skillLvs = SkillDataManager.Instance.GetSkillLvs(roleData.cardId);
  135. FightDataManager.Instance.SetItemScoreList(roleData);
  136. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  137. _roleDatas = ArenaDataManager.Instance.DressupList;
  138. bool result = await ArenaSproxy.ReqChangeArenaDressup(i, roleData.cardId, roleData.itemList);
  139. if (!result)
  140. {
  141. PromptController.Instance.ShowFloatTextPrompt("保存失败");
  142. return;
  143. }
  144. }
  145. PromptController.Instance.ShowFloatTextPrompt("保存成功");
  146. UpdateView();
  147. }
  148. private void UpdateView()
  149. {
  150. // _itemList = _roleDatas[_themeIndex].itemList;
  151. _tags = _roleDatas[_themeIndex].tags;
  152. UpdateCardInfo(_roleDatas[_themeIndex].cardId);
  153. ArenaViewManager.Instance.UpdateValue(_ui.m_comValueInfo.target, _themeIndex, _roleDatas);
  154. MyDressUpHelper.dressUpObj.PutOnItemList(_roleDatas[_themeIndex].itemList);
  155. _itemList.Clear();
  156. for (int i = 0; i < _roleDatas[_themeIndex].itemList.Count; i++)
  157. {
  158. int itemId = _roleDatas[_themeIndex].itemList[i];
  159. if (itemId == ConstItemID.DEFULT_FA_XING
  160. || itemId == ConstItemID.DEFULT_LIAN_YI_QUN
  161. || itemId == ConstItemID.DEFULT_NEI_DA
  162. || itemId == ConstItemID.DEFULT_XIA_ZHUANG) continue;
  163. _itemList.Add(itemId);
  164. }
  165. _ui.m_list.numItems = _itemList.Count;
  166. }
  167. private void UpdateCardInfo(int cardId)
  168. {
  169. if (cardId == 0)
  170. {
  171. _ui.m_comCard.m_c1.selectedIndex = 0;
  172. return;
  173. }
  174. _ui.m_comCard.m_c1.selectedIndex = 1;
  175. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cardId);
  176. _ui.m_comCard.m_txtCardName.text = itemCfg.name;
  177. _ui.m_comCard.m_comCard.m_loaCard.url = ResPathUtil.GetCardSmallPath(itemCfg.res);
  178. _ui.m_comCard.m_loaScore.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  179. RarityIconController.UpdateRarityIcon(_ui.m_comCard.m_loaRarity, cardId, false);
  180. }
  181. private void RenderListItem(int index, GObject obj)
  182. {
  183. UI_ListPartsItem item = UI_ListPartsItem.Proxy(obj);
  184. item.m_iconSelected.visible = true;
  185. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemList[index]);
  186. item.m_txtTitle.text = itemCfg.name;
  187. item.m_ScoreType.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  188. item.m_icon.url = ResPathUtil.GetIconPath(itemCfg.res, "png");
  189. item.m_txtScore.text = _roleDatas[_themeIndex].itemScoreDic[_itemList[index]].ToString();
  190. RarityIconController.UpdateRarityIcon(item.m_rarity, _itemList[index], false);
  191. if (item.target.data == null)
  192. {
  193. LongPressGesture longPressGesture = new LongPressGesture(item.target);
  194. longPressGesture.once = true;
  195. longPressGesture.onAction.Add(OnLongPress);
  196. _listLongPress.Add(longPressGesture);
  197. }
  198. item.target.data = _itemList[index];
  199. UI_ListPartsItem.ProxyEnd();
  200. }
  201. private void OnLongPress(EventContext context)
  202. {
  203. LongPressGesture gesture = (LongPressGesture)context.sender;
  204. int itemId = (int)gesture.host.data;
  205. GoodsItemTipsController.ShowItemTips(itemId);
  206. }
  207. }
  208. }