ArenaDressInfoView.cs 16 KB

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