ArenaDressInfoView.cs 15 KB

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