ArenaDressInfoView.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using cfg.GfgCfg;
  5. using ET;
  6. using FairyGUI;
  7. using UI.Arena;
  8. // using UI.DressUp;
  9. using UnityEngine;
  10. namespace GFGGame
  11. {
  12. public class ArenaDressInfoView : BaseWindow
  13. {
  14. private UI_ArenaDressInfoUI _ui;
  15. private GameObject _sceneObject;
  16. private List<LongPressGesture> _listLongPress = new List<LongPressGesture>();
  17. private List<FightData> _roleDatas; //可能是自己的搭配,也可能是对方玩家的搭配
  18. private int _themeIndex = 0;
  19. private string _openViewName = "";
  20. private List<int> _itemList = new List<int>();
  21. private List<string> _tags;
  22. private int _roleType = 0; //FightRoleType
  23. public override void Dispose()
  24. {
  25. if (_sceneObject != null)
  26. {
  27. PrefabManager.Instance.Restore(_sceneObject);
  28. _sceneObject = null;
  29. }
  30. // _dressUpObj.Dispose();
  31. for (int i = 0; i < _listLongPress.Count; i++)
  32. {
  33. _listLongPress[i].Dispose();
  34. }
  35. _listLongPress.Clear();
  36. if (_ui != null)
  37. {
  38. _ui.Dispose();
  39. _ui = null;
  40. }
  41. base.Dispose();
  42. }
  43. protected override void OnInit()
  44. {
  45. base.OnInit();
  46. packageName = UI_ArenaUI.PACKAGE_NAME;
  47. _ui = UI_ArenaDressInfoUI.Create();
  48. this.viewCom = _ui.target;
  49. isfullScreen = true;
  50. isReturnView = true;
  51. _ui.m_c2.onChanged.Add(OnThemeChange);
  52. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  53. _ui.m_btnConfire.onClick.Add(OnClickConfire);
  54. _ui.m_btnDress.onClick.Add(OnBtnDressClick);
  55. _ui.m_btnRecommend.onClick.Add(OnBtnRecommendClick);
  56. _ui.m_comValueInfo.m_btnFightScoreRule.onClick.Add(OnBtnFightScoreRule);
  57. _ui.m_grhCloseComFightScore.onClick.Add(OnCloseComFightScore);
  58. _ui.m_list.itemRenderer = RenderListItem;
  59. }
  60. protected override void AddEventListener()
  61. {
  62. base.AddEventListener();
  63. }
  64. protected override void OnShown()
  65. {
  66. base.OnShown();
  67. _roleType = (int)(this.viewData as object[])[0];
  68. _themeIndex = (int)(this.viewData as object[])[1];
  69. _roleDatas = (this.viewData as object[])[2] as List<FightData>;
  70. _openViewName = (this.viewData as object[])[3].ToString();
  71. _ui.m_grhCloseComFightScore.visible = false;
  72. _ui.m_c1.selectedIndex = _roleType;
  73. _ui.m_c2.selectedIndex = _themeIndex;
  74. if (_sceneObject == null)
  75. {
  76. // 异步加载场景对象
  77. PrefabManager.Instance.InstantiateAsync(
  78. ResPathUtil.GetPrefabPath("SceneArenaDressUp"),
  79. (go) =>
  80. {
  81. if (go != null)
  82. {
  83. _sceneObject = go;
  84. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  85. UpdateView(); // 场景加载完成后更新视图
  86. Timers.inst.AddUpdate(CheckGuide);
  87. }
  88. else
  89. {
  90. Debug.LogError("Failed to load SceneArenaDressUp prefab");
  91. // 可以在这里添加错误处理逻辑
  92. }
  93. }
  94. );
  95. }
  96. else
  97. {
  98. UpdateView();
  99. Timers.inst.AddUpdate(CheckGuide);
  100. }
  101. }
  102. protected override void OnHide()
  103. {
  104. base.OnHide();
  105. if (_sceneObject != null)
  106. {
  107. PrefabManager.Instance.Restore(_sceneObject);
  108. _sceneObject = null;
  109. }
  110. _ui.m_grhCloseComFightScore.visible = false;
  111. _ui.m_comValueInfo.m_c2.selectedIndex = 0;
  112. _ui.m_btnConfire.touchable = true;
  113. Timers.inst.Remove(CheckGuide);
  114. Timers.inst.Remove(SetConfireTouch);
  115. }
  116. protected override void RemoveEventListener()
  117. {
  118. base.RemoveEventListener();
  119. }
  120. private void OnClickBtnBack()
  121. {
  122. //ViewManager.GoBackFrom(typeof(ArenaDressInfoView).FullName); //返回竞技场主界面
  123. this.Hide();
  124. if (_roleType == FightRoleType.FieldWork)
  125. {
  126. ViewManager.Show<FieldWorkLevelInfoView>(new object[] { FieldWorkDataManager.Instance.currentLevelID });
  127. }
  128. //this.OnHide();
  129. //ViewManager.Show<ArenaView>(null, new object[] { typeof(MainUIView).FullName, this.viewData });
  130. //if (!string.IsNullOrEmpty(_openViewName))
  131. //{
  132. // ViewManager.Show(_openViewName); //打开来源界面:如历史记录、排行榜
  133. //}
  134. }
  135. private void SetConfireTouch(object parm)
  136. {
  137. _ui.m_btnConfire.touchable = true;
  138. Timers.inst.Remove(SetConfireTouch);
  139. }
  140. private void OnClickConfire()
  141. {
  142. ViewManager.GoBackFrom(typeof(ArenaDressInfoView).FullName);
  143. if (_roleType == FightRoleType.FieldWork)
  144. {
  145. ViewManager.Show<FieldWorkLevelInfoView>(new object[] { FieldWorkDataManager.Instance.currentLevelID });
  146. }
  147. }
  148. private void OnThemeChange()
  149. {
  150. _themeIndex = _ui.m_c2.selectedIndex;
  151. if (_roleType == FightRoleType.MINE)
  152. {
  153. ArenaDataManager.Instance.SelectThemeIndex = _themeIndex;
  154. }
  155. else if (_roleType == FightRoleType.FieldWork)
  156. {
  157. FieldWorkDataManager.Instance.SelectThemeIndex = _themeIndex;
  158. }
  159. UpdateView();
  160. }
  161. private void OnBtnFightScoreRule()
  162. {
  163. _ui.m_grhCloseComFightScore.visible = true;
  164. }
  165. private void OnCloseComFightScore()
  166. {
  167. _ui.m_comValueInfo.m_c2.selectedIndex = 0;
  168. _ui.m_grhCloseComFightScore.visible = false;
  169. }
  170. private void OnBtnDressClick()
  171. {
  172. if (_roleType != 2)
  173. {
  174. ViewManager.Show<ArenaDressUpFightView>();
  175. }
  176. else
  177. {
  178. ViewManager.Show<FieldWorkDressFightView>();
  179. }
  180. }
  181. private async void OnBtnRecommendClick()
  182. {
  183. //标记,本次推荐已经穿戴过的词牌,防止重复。
  184. var wearCardIds = new List<int>();
  185. if (_roleType == FightRoleType.MINE)
  186. {
  187. for (int i = 0; i < ArenaDataManager.Instance.ThemeList.Count; i++)
  188. {
  189. int scoreType = ArenaDataManager.Instance.ThemeList[i];
  190. FightData roleData = ArenaDataManager.Instance.DressupList[i];
  191. roleData.scoreType = scoreType;
  192. roleData.itemList = ArenaDataManager.Instance.GetRecommentItemList(scoreType, roleData.tags);
  193. roleData.cardId =
  194. ArenaDataManager.Instance.GetRecommentCardId(scoreType, roleData.itemList, wearCardIds);
  195. ArenaDataManager.Instance.SetMineFightAttr(roleData, scoreType);
  196. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  197. _roleDatas = ArenaDataManager.Instance.DressupList;
  198. List<long> fightScoreDatas = ArenaDataManager.Instance.GetFightScoreList(_roleDatas);
  199. bool result =
  200. await ArenaSproxy.ReqChangeArenaDressup(i, roleData.cardId, roleData.itemList, fightScoreDatas);
  201. if (!result)
  202. {
  203. PromptController.Instance.ShowFloatTextPrompt("保存失败");
  204. return;
  205. }
  206. }
  207. }
  208. else if (_roleType == FightRoleType.FieldWork)
  209. {
  210. _ui.m_btnConfire.touchable = false;
  211. Timers.inst.Add(1.0f, 1, SetConfireTouch);
  212. for (int i = 0; i < FieldWorkDataManager.Instance.ThemeList.Count; i++)
  213. {
  214. int scoreType = FieldWorkDataManager.Instance.ThemeList[i];
  215. FightData roleData = FieldWorkDataManager.Instance.DressupList[i];
  216. roleData.scoreType = scoreType;
  217. roleData.itemList = ArenaDataManager.Instance.GetFieldRecommentItemList(scoreType, roleData.tags);
  218. roleData.cardId =
  219. ArenaDataManager.Instance.GetRecommentCardId(scoreType, roleData.itemList, wearCardIds);
  220. ArenaDataManager.Instance.SetMineFightAttr(roleData, scoreType);
  221. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  222. _roleDatas = FieldWorkDataManager.Instance.DressupList;
  223. List<long> fightScoreDatas = ArenaDataManager.Instance.GetFightScoreList(_roleDatas);
  224. bool result = await FieldWorkSproxy.ReqChangeFieldWorkDressup();
  225. if (!result)
  226. {
  227. PromptController.Instance.ShowFloatTextPrompt("保存失败");
  228. return;
  229. }
  230. }
  231. }
  232. wearCardIds.Clear();
  233. PromptController.Instance.ShowFloatTextPrompt("保存成功");
  234. UpdateView();
  235. }
  236. private void UpdateView()
  237. {
  238. // _itemList = _roleDatas[_themeIndex].itemList;
  239. _tags = _roleDatas[_themeIndex].tags;
  240. UpdateCardInfo(_roleDatas[_themeIndex].cardId);
  241. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  242. {
  243. _ui.m_c4.selectedIndex = 0;
  244. ArenaViewManager.Instance.UpdateValue(_ui.m_comValueInfo.target, _themeIndex, _roleDatas);
  245. }
  246. else
  247. {
  248. _ui.m_c4.selectedIndex = 1;
  249. FieldWorkDataManager.Instance.UpdateValue(_ui.m_comFieldValueInfo.target, _themeIndex, _roleDatas);
  250. for (int i = 0; i < FieldWorkDataManager.Instance.ThemeList.Count; i++)
  251. {
  252. int scoreType = FieldWorkDataManager.Instance.ThemeList[i];
  253. FightData roleData = FieldWorkDataManager.Instance.DressupList[i];
  254. ArenaDataManager.Instance.SetMineFightAttr(roleData, scoreType);
  255. ScoreSystemData.Instance.SetEquipScoresWithPartId(roleData);
  256. }
  257. }
  258. MyDressUpHelper.dressUpObj.PutOnItemList(_roleDatas[_themeIndex].itemList);
  259. _itemList.Clear();
  260. for (int i = 0; i < _roleDatas[_themeIndex].itemList.Count; i++)
  261. {
  262. int itemId = _roleDatas[_themeIndex].itemList[i];
  263. if (itemId == ConstItemID.DEFULT_FA_XING
  264. || itemId == ConstItemID.DEFULT_LIAN_YI_QUN
  265. || itemId == ConstItemID.DEFULT_NEI_DA
  266. || itemId == ConstItemID.DEFULT_XIA_ZHUANG) continue;
  267. _itemList.Add(itemId);
  268. }
  269. _ui.m_list.numItems = _itemList.Count;
  270. }
  271. private void UpdateCardInfo(int cardId)
  272. {
  273. if (cardId == 0)
  274. {
  275. _ui.m_comCard.m_c1.selectedIndex = 0;
  276. return;
  277. }
  278. _ui.m_comCard.m_c1.selectedIndex = 1;
  279. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(cardId);
  280. _ui.m_comCard.m_txtCardName.text = itemCfg.Name;
  281. _ui.m_comCard.m_comCard.m_loaCard.url = ResPathUtil.GetCardIconPath(itemCfg.Res);
  282. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  283. {
  284. _ui.m_comCard.m_loaScore.url =
  285. ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  286. }
  287. else
  288. {
  289. _ui.m_comCard.m_loaScore.url =
  290. ResPathUtil.GetScorePath(FieldWorkDataManager.Instance.ThemeList[_themeIndex]);
  291. }
  292. RarityIconController.UpdateRarityIcon(_ui.m_comCard.m_loaRarity, cardId, false);
  293. }
  294. private void RenderListItem(int index, GObject obj)
  295. {
  296. UI_ListPartsItem item = UI_ListPartsItem.Proxy(obj);
  297. item.m_iconSelected.visible = true;
  298. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_itemList[index]);
  299. item.m_txtTitle.text = itemCfg.Name;
  300. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  301. {
  302. item.m_ScoreType.url = ResPathUtil.GetScorePath(ArenaDataManager.Instance.ThemeList[_themeIndex]);
  303. }
  304. else
  305. {
  306. item.m_ScoreType.url = ResPathUtil.GetScorePath(FieldWorkDataManager.Instance.ThemeList[_themeIndex]);
  307. }
  308. item.m_icon.url = ResPathUtil.GetIconPath(itemCfg.Res, "png");
  309. item.m_txtScore.text = _roleDatas[_themeIndex].itemScoreDic[_itemList[index]].ToString();
  310. RarityIconController.UpdateRarityIcon(item.m_rarity, _itemList[index], false);
  311. if (item.target.data == null)
  312. {
  313. LongPressGesture longPressGesture = new LongPressGesture(item.target);
  314. longPressGesture.once = true;
  315. longPressGesture.onAction.Add(OnLongPress);
  316. _listLongPress.Add(longPressGesture);
  317. }
  318. item.target.data = _itemList[index];
  319. UI_ListPartsItem.ProxyEnd();
  320. }
  321. private void OnLongPress(EventContext context)
  322. {
  323. LongPressGesture gesture = (LongPressGesture)context.sender;
  324. int itemId = (int)gesture.host.data;
  325. GoodsItemTipsController.ShowItemTips(itemId);
  326. }
  327. private void CheckGuide(object param)
  328. {
  329. if (GuideDataManager.IsGuideFinish(ConstGuideId.ARENA_OPEN) <= 0
  330. || (GuideDataManager.IsGuideFinish(ConstGuideId.FIELD) <= 0 &&
  331. InstanceZonesDataManager.FightScene == ConstInstanceZonesType.FieldWork &&
  332. InstanceZonesDataManager.CheckLevelPass(FieldWorkDataManager.Instance.guideLevelID)))
  333. {
  334. UpdateToCheckGuide(null);
  335. }
  336. else
  337. {
  338. Timers.inst.Remove(CheckGuide);
  339. }
  340. }
  341. protected override void UpdateToCheckGuide(object param)
  342. {
  343. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  344. GuideController.TryGuide(_ui.m_btnRecommend, ConstGuideId.ARENA_OPEN, 6, "");
  345. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.ARENA_OPEN, 7, "搭配好啦,挑个对手比拼吧~");
  346. if ((GuideDataManager.IsGuideFinish(ConstGuideId.FIELD) <= 0 &&
  347. InstanceZonesDataManager.FightScene == ConstInstanceZonesType.FieldWork))
  348. {
  349. GuideController.TryGuide(_ui.m_btnDress, ConstGuideId.FIELD, 6, "三套战斗方案可自由搭配且在同一关卡中服装可重复使用,让我们前往搭配吧!");
  350. GuideController.TryGuide(_ui.m_btnRecommend, ConstGuideId.FIELD, 12,
  351. "也可点击【推荐搭配】按钮快速搭配三套方案(同一个关卡中服装可重复使用)!");
  352. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.FIELD, 13, "让我们前往开启挑战吧!");
  353. }
  354. }
  355. protected override void TryCompleteGuide()
  356. {
  357. base.TryCompleteGuide();
  358. GuideController.TryCompleteGuideIndex(ConstGuideId.ARENA_OPEN, 7);
  359. }
  360. }
  361. }