ArenaDressInfoView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 _sceneObject;
  14. private List<LongPressGesture> _listLongPress = new List<LongPressGesture>();
  15. private List<FightData> _roleDatas; //可能是自己的搭配,也可能是对方玩家的搭配
  16. private int _themeIndex = 0;
  17. private string _openViewName = "";
  18. private List<int> _itemList = new List<int>();
  19. private string[] _tags;
  20. private int _roleType = 0; //FightRoleType
  21. public override void Dispose()
  22. {
  23. if (_sceneObject != null)
  24. {
  25. PrefabManager.Instance.Restore(_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. isReturnView = 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. }
  57. protected override void AddEventListener()
  58. {
  59. base.AddEventListener();
  60. }
  61. protected override void OnShown()
  62. {
  63. base.OnShown();
  64. _roleType = (int)(this.viewData as object[])[0];
  65. _themeIndex = (int)(this.viewData as object[])[1];
  66. _roleDatas = (this.viewData as object[])[2] as List<FightData>;
  67. _openViewName = (this.viewData as object[])[3].ToString();
  68. if (_sceneObject == null)
  69. {
  70. _sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("SceneArenaDressUp"));
  71. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  72. }
  73. _ui.m_grhCloseComFightScore.visible = false;
  74. _ui.m_c1.selectedIndex = _roleType;
  75. _ui.m_c2.selectedIndex = _themeIndex;
  76. UpdateView();
  77. Timers.inst.AddUpdate(CheckGuide);
  78. }
  79. protected override void OnHide()
  80. {
  81. base.OnHide();
  82. if (_sceneObject != null)
  83. {
  84. PrefabManager.Instance.Restore(_sceneObject);
  85. _sceneObject = null;
  86. }
  87. _ui.m_grhCloseComFightScore.visible = false;
  88. _ui.m_comValueInfo.m_c2.selectedIndex = 0;
  89. Timers.inst.Remove(CheckGuide);
  90. }
  91. protected override void RemoveEventListener()
  92. {
  93. base.RemoveEventListener();
  94. }
  95. private void OnClickBtnBack()
  96. {
  97. //ViewManager.GoBackFrom(typeof(ArenaDressInfoView).FullName); //返回竞技场主界面
  98. this.Hide();
  99. //this.OnHide();
  100. //ViewManager.Show<ArenaView>(null, new object[] { typeof(MainUIView).FullName, this.viewData });
  101. //if (!string.IsNullOrEmpty(_openViewName))
  102. //{
  103. // ViewManager.Show(_openViewName); //打开来源界面:如历史记录、排行榜
  104. //}
  105. }
  106. private void OnThemeChange()
  107. {
  108. _themeIndex = _ui.m_c2.selectedIndex;
  109. if (_roleType == FightRoleType.MINE)
  110. {
  111. ArenaDataManager.Instance.SelectThemeIndex = _themeIndex;
  112. }
  113. else if(_roleType == FightRoleType.FieldWork)
  114. {
  115. FieldWorkDataManager.Instance.SelectThemeIndex = _themeIndex;
  116. }
  117. UpdateView();
  118. }
  119. private void OnBtnFightScoreRule()
  120. {
  121. _ui.m_grhCloseComFightScore.visible = true;
  122. }
  123. private void OnCloseComFightScore()
  124. {
  125. _ui.m_comValueInfo.m_c2.selectedIndex = 0;
  126. _ui.m_grhCloseComFightScore.visible = false;
  127. }
  128. private void OnBtnDressClick()
  129. {
  130. if(_roleType != 2)
  131. {
  132. ViewManager.Show<ArenaDressUpFightView>();
  133. }
  134. else
  135. {
  136. ViewManager.Show<FieldWorkDressFightView>();
  137. }
  138. }
  139. private async void OnBtnRecommendClick()
  140. {
  141. //标记,本次推荐已经穿戴过的词牌,防止重复。
  142. var wearCardIds = new List<int>();
  143. if (_roleType == FightRoleType.MINE)
  144. {
  145. for (int i = 0; i < ArenaDataManager.Instance.ThemeList.Count; i++)
  146. {
  147. int scoreType = ArenaDataManager.Instance.ThemeList[i];
  148. FightData roleData = ArenaDataManager.Instance.DressupList[i];
  149. roleData.scoreType = scoreType;
  150. roleData.itemList = ArenaDataManager.Instance.GetRecommentItemList(scoreType, roleData.tags);
  151. roleData.cardId =
  152. ArenaDataManager.Instance.GetRecommentCardId(scoreType, roleData.itemList, wearCardIds);
  153. ArenaDataManager.Instance.SetMineFightAttr(roleData, scoreType);
  154. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  155. _roleDatas = ArenaDataManager.Instance.DressupList;
  156. List<long> fightScoreDatas = ArenaDataManager.Instance.GetFightScoreList(_roleDatas);
  157. bool result = await ArenaSproxy.ReqChangeArenaDressup(i, roleData.cardId, roleData.itemList, fightScoreDatas);
  158. if (!result)
  159. {
  160. PromptController.Instance.ShowFloatTextPrompt("保存失败");
  161. return;
  162. }
  163. }
  164. }
  165. else if (_roleType == FightRoleType.FieldWork)
  166. {
  167. for (int i = 0; i < FieldWorkDataManager.Instance.ThemeList.Count; i++)
  168. {
  169. int scoreType = FieldWorkDataManager.Instance.ThemeList[i];
  170. FightData roleData = FieldWorkDataManager.Instance.DressupList[i];
  171. roleData.scoreType = scoreType;
  172. roleData.itemList = ArenaDataManager.Instance.GetRecommentItemList(scoreType, roleData.tags);
  173. roleData.cardId =
  174. ArenaDataManager.Instance.GetRecommentCardId(scoreType, roleData.itemList, wearCardIds);
  175. ArenaDataManager.Instance.SetMineFightAttr(roleData, scoreType);
  176. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  177. _roleDatas = FieldWorkDataManager.Instance.DressupList;
  178. List<long> fightScoreDatas = ArenaDataManager.Instance.GetFightScoreList(_roleDatas);
  179. bool result = await FieldWorkSproxy.ReqChangeFieldWorkDressup();
  180. if (!result)
  181. {
  182. PromptController.Instance.ShowFloatTextPrompt("保存失败");
  183. return;
  184. }
  185. }
  186. }
  187. wearCardIds.Clear();
  188. PromptController.Instance.ShowFloatTextPrompt("保存成功");
  189. UpdateView();
  190. }
  191. private void UpdateView()
  192. {
  193. // _itemList = _roleDatas[_themeIndex].itemList;
  194. _tags = _roleDatas[_themeIndex].tags;
  195. UpdateCardInfo(_roleDatas[_themeIndex].cardId);
  196. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  197. {
  198. _ui.m_c4.selectedIndex = 0;
  199. ArenaViewManager.Instance.UpdateValue(_ui.m_comValueInfo.target, _themeIndex, _roleDatas);
  200. }
  201. else
  202. {
  203. _ui.m_c4.selectedIndex = 1;
  204. FieldWorkDataManager.Instance.UpdateValue(_ui.m_comFieldValueInfo.target, _themeIndex, _roleDatas);
  205. for (int i = 0; i < FieldWorkDataManager.Instance.ThemeList.Count; i++)
  206. {
  207. int scoreType = FieldWorkDataManager.Instance.ThemeList[i];
  208. FightData roleData = FieldWorkDataManager.Instance.DressupList[i];
  209. ArenaDataManager.Instance.SetMineFightAttr(roleData, scoreType);
  210. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  211. }
  212. }
  213. MyDressUpHelper.dressUpObj.PutOnItemList(_roleDatas[_themeIndex].itemList);
  214. _itemList.Clear();
  215. for (int i = 0; i < _roleDatas[_themeIndex].itemList.Count; i++)
  216. {
  217. int itemId = _roleDatas[_themeIndex].itemList[i];
  218. if (itemId == ConstItemID.DEFULT_FA_XING
  219. || itemId == ConstItemID.DEFULT_LIAN_YI_QUN
  220. || itemId == ConstItemID.DEFULT_NEI_DA
  221. || itemId == ConstItemID.DEFULT_XIA_ZHUANG) continue;
  222. _itemList.Add(itemId);
  223. }
  224. _ui.m_list.numItems = _itemList.Count;
  225. }
  226. private void UpdateCardInfo(int cardId)
  227. {
  228. if (cardId == 0)
  229. {
  230. _ui.m_comCard.m_c1.selectedIndex = 0;
  231. return;
  232. }
  233. _ui.m_comCard.m_c1.selectedIndex = 1;
  234. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cardId);
  235. _ui.m_comCard.m_txtCardName.text = itemCfg.name;
  236. _ui.m_comCard.m_comCard.m_loaCard.url = ResPathUtil.GetCardIconPath(itemCfg.res);
  237. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  238. {
  239. _ui.m_comCard.m_loaScore.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  240. }
  241. else
  242. {
  243. _ui.m_comCard.m_loaScore.url = ResPathUtil.GetScorePath(FieldWorkDataManager.Instance.ThemeList[_themeIndex]);
  244. }
  245. RarityIconController.UpdateRarityIcon(_ui.m_comCard.m_loaRarity, cardId, false);
  246. }
  247. private void RenderListItem(int index, GObject obj)
  248. {
  249. UI_ListPartsItem item = UI_ListPartsItem.Proxy(obj);
  250. item.m_iconSelected.visible = true;
  251. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemList[index]);
  252. item.m_txtTitle.text = itemCfg.name;
  253. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  254. {
  255. item.m_ScoreType.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  256. }
  257. else
  258. {
  259. item.m_ScoreType.url = ResPathUtil.GetScorePath(FieldWorkDataManager.Instance.ThemeList[_themeIndex]);
  260. }
  261. item.m_icon.url = ResPathUtil.GetIconPath(itemCfg.res, "png");
  262. item.m_txtScore.text = _roleDatas[_themeIndex].itemScoreDic[_itemList[index]].ToString();
  263. RarityIconController.UpdateRarityIcon(item.m_rarity, _itemList[index], false);
  264. if (item.target.data == null)
  265. {
  266. LongPressGesture longPressGesture = new LongPressGesture(item.target);
  267. longPressGesture.once = true;
  268. longPressGesture.onAction.Add(OnLongPress);
  269. _listLongPress.Add(longPressGesture);
  270. }
  271. item.target.data = _itemList[index];
  272. UI_ListPartsItem.ProxyEnd();
  273. }
  274. private void OnLongPress(EventContext context)
  275. {
  276. LongPressGesture gesture = (LongPressGesture)context.sender;
  277. int itemId = (int)gesture.host.data;
  278. GoodsItemTipsController.ShowItemTips(itemId);
  279. }
  280. private void CheckGuide(object param)
  281. {
  282. if (GuideDataManager.IsGuideFinish(ConstGuideId.ARENA_OPEN) <= 0)
  283. {
  284. UpdateToCheckGuide(null);
  285. }
  286. else
  287. {
  288. Timers.inst.Remove(CheckGuide);
  289. }
  290. }
  291. protected override void UpdateToCheckGuide(object param)
  292. {
  293. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  294. GuideController.TryGuide(_ui.m_btnRecommend, ConstGuideId.ARENA_OPEN, 6, "");
  295. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.ARENA_OPEN, 7, "搭配好啦,挑个对手比拼吧~");
  296. }
  297. protected override void TryCompleteGuide()
  298. {
  299. base.TryCompleteGuide();
  300. GuideController.TryCompleteGuideIndex(ConstGuideId.ARENA_OPEN, 7);
  301. }
  302. }
  303. }