ArenaDressInfoView.cs 8.2 KB

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