ClothingView.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using FairyGUI;
  4. using UI.ClothingFoster;
  5. using UI.CommonGame;
  6. using UnityEngine;
  7. using ET;
  8. namespace GFGGame
  9. {
  10. public class ClothingView : BaseWindow
  11. {
  12. private UI_ClothingUI _ui;
  13. private GameObject _scenePrefab;
  14. private GameObject _sceneObject;
  15. private GoWrapper _wrapper;
  16. private GameObject _gameobject1;
  17. private GoWrapper _wrapper1;
  18. private DressUpObjDataCache _dressUpObjDataCache;
  19. private bool _actionIsPic;
  20. private List<int> _suitIds;//已解锁套装列表
  21. private SortedList _propertyList = new SortedList();
  22. private SortedList _addPropertyList = new SortedList();
  23. private int _suitId;
  24. private int _index;
  25. private bool _canRenew;
  26. public override void Dispose()
  27. {
  28. if (_ui != null)
  29. {
  30. _ui.Dispose();
  31. _ui = null;
  32. }
  33. base.Dispose();
  34. if (_sceneObject != null)
  35. {
  36. GameObject.Destroy(_sceneObject);
  37. _sceneObject = null;
  38. _wrapper.Dispose();
  39. _wrapper = null;
  40. }
  41. if (_scenePrefab != null)
  42. {
  43. GFGAsset.Release(ResPathUtil.GetPrefabPath("SceneSuitFoster"));
  44. _scenePrefab = null;
  45. }
  46. SceneController.DestroyObjectFromView(_gameobject1,_wrapper1);
  47. _propertyList.Clear();
  48. _addPropertyList.Clear();
  49. }
  50. protected override void OnInit()
  51. {
  52. base.OnInit();
  53. packageName = UI_ClothingUI.PACKAGE_NAME;
  54. _ui = UI_ClothingUI.Create();
  55. this.viewCom = _ui.target;
  56. // this.viewCom.Center();
  57. isfullScreen = true;
  58. // this.clickBlankToClose = false;
  59. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneSuitFoster"));
  60. _dressUpObjDataCache = new DressUpObjDataCache();
  61. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  62. _ui.m_btnLeft.onClick.Add(() => { OnClickBtnDirection(-1); });
  63. _ui.m_btnRight.onClick.Add(() => { OnClickBtnDirection(1); });
  64. _ui.m_comFosterReward.target.onClick.Add(OnClickComFosterReward);
  65. _ui.m_btnPropertyShow.onClick.Add(OnClickBtnPropertyShow);
  66. _ui.m_listFoster.itemRenderer = ListFosterItemRender;
  67. _ui.m_listFoster.onClickItem.Add(OnClickListFosterItem);
  68. _ui.m_listProperty.itemRenderer = ListPropertyItemRender;
  69. _ui.m_listRenewMaterial.itemRenderer = ListRenewMaterialItemRender;
  70. _ui.m_listRenewMaterial.onClickItem.Add(OnListRenewMaterialsItem);
  71. _ui.m_btnRenew.onClick.Add(OnClickBtnRenew);
  72. _ui.m_c1.onChanged.Add(OnTabChange);
  73. // EventAgent.AddEventListener(ConstMessage.GET_SUIT_INFOS)
  74. }
  75. protected override void AddEventListener()
  76. {
  77. EventAgent.AddEventListener(ConstMessage.MAINTAIN_SUIT, OnListenerFoster);
  78. EventAgent.AddEventListener(ConstMessage.GET_MAINTAIN_SUIT_BONUS, OnListenerGetFosterReward);
  79. EventAgent.AddEventListener(ConstMessage.MAKE_NEW_SUIT, OnListenerRenew);
  80. }
  81. protected override void OnShown()
  82. {
  83. base.OnShown();
  84. object[] datas = this.viewData as object[];
  85. _suitId = (int)datas[0];
  86. List<int> suitIds = datas[1] as List<int>;
  87. _suitIds = new List<int>();
  88. foreach (int suitId in suitIds)
  89. {
  90. if (DressUpMenuSuitDataManager.CheckHaveSuit(suitId))
  91. {
  92. _suitIds.Add(suitId);
  93. }
  94. }
  95. _index = SuitFosterDataManager.Instance.GetSuitFosterData(_suitId).maintainStep;
  96. _ui.m_c1.selectedIndex = 0;
  97. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("jingzhongh_bg");
  98. UpdateView();
  99. Timers.inst.AddUpdate(CheckGuide);
  100. }
  101. protected override void OnHide()
  102. {
  103. base.OnHide();
  104. Timers.inst.Remove(CheckGuide);
  105. }
  106. protected override void RemoveEventListener()
  107. {
  108. base.RemoveEventListener();
  109. EventAgent.RemoveEventListener(ConstMessage.MAINTAIN_SUIT, OnListenerFoster);
  110. EventAgent.RemoveEventListener(ConstMessage.GET_MAINTAIN_SUIT_BONUS, OnListenerGetFosterReward);
  111. EventAgent.RemoveEventListener(ConstMessage.MAKE_NEW_SUIT, OnListenerRenew);
  112. }
  113. private void OnClickBtnBack()
  114. {
  115. ViewManager.GoBackFrom(typeof(ClothingView).FullName);
  116. }
  117. private void OnTabChange()
  118. {
  119. if (_ui.m_c1.selectedIndex == 0)
  120. {
  121. UpdateFoster();
  122. }
  123. else
  124. {
  125. UpdateRenew();
  126. }
  127. }
  128. private void UpdateView()
  129. {
  130. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(_suitId);
  131. _ui.m_loaRarity.url = ResPathUtil.GetCommonGameResPath("hd_sxicon_" + cfg.rarity);// "ui://LuckyBox/;
  132. UpdateArrows();
  133. UpdateSuitView();
  134. UpdateFoster();
  135. UpdateRenew();
  136. }
  137. private void UpdateArrows()
  138. {
  139. int index = _suitIds.IndexOf(_suitId);
  140. int count = _suitIds.Count;
  141. _ui.m_btnRight.visible = (index + 1 < count);
  142. _ui.m_btnLeft.visible = (index - 1 >= 0);
  143. }
  144. private void UpdateSuitView(bool isPic = true)
  145. {
  146. _actionIsPic = isPic;
  147. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  148. _ui.m_txtName.text = suitCfg.name;
  149. if (_sceneObject != null)
  150. {
  151. GameObject.Destroy(_sceneObject);
  152. _sceneObject = null;
  153. }
  154. _sceneObject = GameObject.Instantiate(_scenePrefab);
  155. int scale = 100;
  156. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  157. _dressUpObjDataCache.setSceneObj(_sceneObject);
  158. _dressUpObjDataCache.PutOnDefaultSuitSaved(false);
  159. _dressUpObjDataCache.PutOnSuitCfg(_suitId, isPic, false, new int[] { ConstDressUpItemType.BEI_JING });
  160. if (_wrapper == null)
  161. {
  162. _wrapper = new GoWrapper(_sceneObject);
  163. _ui.m_holder.SetNativeObject(_wrapper);
  164. }
  165. else
  166. {
  167. _wrapper.wrapTarget = _sceneObject;
  168. }
  169. }
  170. private void OnClickBtnDirection(int direction)
  171. {
  172. int index = _suitIds.IndexOf(_suitId);
  173. int targetIndex = index + direction;
  174. if (targetIndex >= 0 && direction == -1 || targetIndex < _suitIds.Count && direction == 1)
  175. {
  176. _suitId = _suitIds[targetIndex];
  177. _index = SuitFosterDataManager.Instance.GetSuitFosterData(_suitId).maintainStep;
  178. UpdateView();
  179. }
  180. }
  181. /*************************************************养护************************************************/
  182. private void UpdateFoster()
  183. {
  184. _index = SuitFosterDataManager.Instance.GetSuitFosterData(_suitId).maintainStep;
  185. UpdateFosterReward();
  186. _propertyList.Clear();
  187. _addPropertyList.Clear();
  188. _ui.m_listFoster.numItems = SuitFosterCfgArray.Instance.GetCfgs(_suitId).Count;
  189. SuitFosterDataManager.Instance.GetPropertyData(_suitId, _index, out _propertyList, out _addPropertyList);
  190. _ui.m_listProperty.numItems = _propertyList.Count;
  191. }
  192. private void UpdateFosterReward()
  193. {
  194. SuitFosterDataManager.Instance.GetFosterRewardState(_suitId, out int state, out int index);
  195. SuitFosterCfg cfg = SuitFosterCfgArray.Instance.GetCfgs(_suitId)[index];
  196. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.rewardsArr[0][0]);
  197. _ui.m_comFosterReward.m_loaReward.url = ResPathUtil.GetIconPath(itemCfg);
  198. _ui.m_comFosterReward.m_c1.selectedIndex = state;
  199. }
  200. private void ListFosterItemRender(int index, GObject obj)
  201. {
  202. UI_ListFosterItem item = UI_ListFosterItem.Proxy(obj);
  203. item.target.data = index;
  204. item.m_finish.selectedIndex = SuitFosterDataManager.Instance.GetFosterState(_suitId, index);
  205. item.m_txtName.text = SuitFosterDataManager.Instance.stepNames[index];
  206. UI_ListFosterItem.ProxyEnd();
  207. }
  208. private void ListPropertyItemRender(int index, GObject obj)
  209. {
  210. UI_ListPropertyItem item = UI_ListPropertyItem.Proxy(obj);
  211. int score = (int)_propertyList.GetKey(index);
  212. item.m_txtProperty.text = _propertyList[score].ToString();
  213. item.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (score));
  214. UI_ListPropertyItem.ProxyEnd();
  215. }
  216. private void OnClickListFosterItem(EventContext context)
  217. {
  218. int index = (int)(context.data as GObject).data;
  219. int state = SuitFosterDataManager.Instance.GetFosterState(_suitId, index);
  220. if (state == 0)
  221. {
  222. PromptController.Instance.ShowFloatTextPrompt("已完成该阶段");
  223. }
  224. else if (state == 1)
  225. {
  226. ViewManager.Show<ClothingFosterView>(new object[] { _suitId, index, _propertyList, _addPropertyList, this.viewData });
  227. }
  228. else
  229. {
  230. PromptController.Instance.ShowFloatTextPrompt(string.Format("请完成{0}阶段", SuitFosterDataManager.Instance.stepNames[_index]));
  231. }
  232. }
  233. private void OnClickComFosterReward()
  234. {
  235. SuitFosterDataManager.Instance.GetFosterRewardState(_suitId, out int state, out int index);
  236. if (state == 1 || state == 2)
  237. {
  238. ViewManager.Show<ClothingRewardView>(_suitId);
  239. }
  240. else
  241. {
  242. SuitFosterProxy.SendGetMaintainSuitBonus(_suitId, index + 1).Coroutine();
  243. }
  244. }
  245. private void OnClickBtnPropertyShow()
  246. {
  247. ViewManager.Show<ClothingPropertyShowView>(new object[] { _suitId, _index });
  248. }
  249. private void OnListenerFoster()
  250. {
  251. _ui.m_comFosterAni.target.visible = true;
  252. _ui.m_comFosterAni.m_txtContent.text = string.Format("服装{0}中......", SuitFosterDataManager.Instance.stepNames[_index]);
  253. // _ui.m_comFosterAni.m_proFoster.value = 0;
  254. string resPath = ResPathUtil.GetViewEffectPath("ui_gcdh", "ui_gcdh_" + (_index + 1));
  255. SceneController.AddObjectToView(_gameobject1, _wrapper1, _ui.m_comFosterAni.m_holder, resPath, out _gameobject1, out _wrapper1);
  256. // _ui.m_comFosterAni.m_proFoster.TweenValue(100, 4f).OnComplete(() =>
  257. // {
  258. // ViewManager.Show<SuitFosterFinishView>(new object[] { _suitId, _index, _propertyList });
  259. // UpdateFoster();
  260. // _ui.m_comFosterAni.target.visible = false;
  261. // });
  262. _ui.m_comFosterAni.m_t0.Play(() =>
  263. {
  264. ViewManager.Show<ClothingFosterFinishView>(new object[] { _suitId, _index, _propertyList });
  265. UpdateFoster();
  266. _ui.m_comFosterAni.target.visible = false;
  267. });
  268. }
  269. private void OnListenerGetFosterReward(EventContext context)
  270. {
  271. SuitFosterCfg cfg = SuitFosterCfgArray.Instance.GetCfgs(_suitId)[(int)(context.data) - 1];
  272. BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(cfg.rewardsArr));
  273. UpdateFosterReward();
  274. Debug.Log("养护奖励:" + ItemDataManager.GetItemNum(100169));
  275. }
  276. /*************************************************换新************************************************/
  277. private void UpdateRenew()
  278. {
  279. _index = SuitFosterDataManager.Instance.GetSuitFosterData(_suitId).maintainStep;
  280. SuitFosterData suitFosterData = SuitFosterDataManager.Instance.GetSuitFosterData(_suitId);
  281. if (suitFosterData.makeNewState > 0)
  282. {
  283. _ui.m_c2.selectedIndex = 1;
  284. UpdateRenewFinish();
  285. }
  286. else
  287. {
  288. _ui.m_c2.selectedIndex = 0;
  289. UpdateRenewView();
  290. }
  291. }
  292. private void UpdateRenewView()
  293. {
  294. int suitrarity = SuitCfgArray.Instance.GetCfg(_suitId).rarity;
  295. SuitRenewCfg renewCfg = SuitRenewCfgArray.Instance.GetCfg(suitrarity);
  296. SuitFosterListCfg cfg = SuitFosterListCfgArray.Instance.GetCfg(_suitId);
  297. _ui.m_comRenewReward.target.visible = false;
  298. if (cfg.renewRewardsArr.Length > 0)
  299. {
  300. _ui.m_comRenewReward.target.visible = true;
  301. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.renewRewardsArr[0][0]);
  302. _ui.m_comRenewReward.m_loaReward.url = ResPathUtil.GetIconPath(itemCfg);
  303. }
  304. _ui.m_txtRenewProperty.text = string.Format("套装所有部件属性+{0}%", renewCfg.addition * 100 / 10000);
  305. _ui.m_txtRenewTips.text = string.Format("完成{0}阶段", SuitFosterDataManager.Instance.stepNames[cfg.renewOpenLv - 1]);
  306. _ui.m_listRenewMaterial.numItems = renewCfg.materialsArr.Length;
  307. _canRenew = true;
  308. UI_ComCostCurrency comConsumeCurrency = UI_ComCostCurrency.Proxy(_ui.m_comRenewCost);
  309. int has = ItemDataManager.GetItemNum(renewCfg.costId);
  310. int need = renewCfg.costNum;
  311. comConsumeCurrency.m_txtNeed.text = StringUtil.GetColorText(need.ToString(), has >= need ? "#FFF8EA" : "#C9F1A5");
  312. if (_canRenew && has < need) _canRenew = false;
  313. UI_ComCostCurrency.ProxyEnd();
  314. }
  315. private void UpdateRenewFinish()
  316. {
  317. int suitrarity = SuitCfgArray.Instance.GetCfg(_suitId).rarity;
  318. SuitRenewCfg renewCfg = SuitRenewCfgArray.Instance.GetCfg(suitrarity);
  319. _ui.m_txtRenewShow.text = string.Format("套装所有部件属性+{0}%", renewCfg.addition * 100 / 10000);
  320. _ui.m_comRenewRewardGet.target.visible = true;
  321. SuitFosterListCfg cfg = SuitFosterListCfgArray.Instance.GetCfg(_suitId);
  322. if (cfg.renewRewardsArr.Length <= 0)
  323. {
  324. _ui.m_comRenewRewardGet.target.visible = false;
  325. return;
  326. }
  327. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.renewRewardsArr[0][0]);
  328. _ui.m_comRenewRewardGet.m_loaReward.url = ResPathUtil.GetIconPath(itemCfg);
  329. }
  330. private void ListRenewMaterialItemRender(int index, GObject obj)
  331. {
  332. UI_ListMaterialsItem item = UI_ListMaterialsItem.Proxy(obj);
  333. int suitrarity = SuitCfgArray.Instance.GetCfg(_suitId).rarity;
  334. int[][] materialsArr = SuitRenewCfgArray.Instance.GetCfg(suitrarity).materialsArr;
  335. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(materialsArr[index][0]);
  336. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  337. int has = ItemDataManager.GetItemNum(itemCfg.id);
  338. int need = materialsArr[index][1];
  339. item.m_txtHas.text = StringUtil.GetColorText(has.ToString(), has >= need ? "#F2DB96" : "#C9F1A5");
  340. item.m_txtNeed.text = need.ToString();
  341. if (_canRenew && has < need) _canRenew = false;
  342. item.target.data = materialsArr[index][0];
  343. UI_ListMaterialsItem.ProxyEnd();
  344. }
  345. private void OnListRenewMaterialsItem(EventContext context)
  346. {
  347. int itemId = (int)(context.data as GComponent).data;
  348. // GoodsItemTipsController.ShowItemTips(itemId);
  349. ViewManager.Show(ViewName.APPROACH_OF_ITEM_VIEW, new object[] { itemId, new object[] { typeof(ClothingView).FullName, this.viewData } });
  350. }
  351. private async void OnClickBtnRenew()
  352. {
  353. if (!_canRenew)
  354. {
  355. PromptController.Instance.ShowFloatTextPrompt("材料不足");
  356. return;
  357. }
  358. SuitFosterData data = SuitFosterDataManager.Instance.GetSuitFosterData(_suitId);
  359. SuitFosterListCfg cfg = SuitFosterListCfgArray.Instance.GetCfg(_suitId);
  360. if (data.maintainStep < cfg.renewOpenLv)
  361. {
  362. PromptController.Instance.ShowFloatTextPrompt(string.Format("完成{0}开启换新", SuitFosterDataManager.Instance.stepNames[cfg.renewOpenLv - 1]));
  363. return;
  364. }
  365. int result = await SuitFosterProxy.SendMakeNewSuit(_suitId);
  366. if (result == ErrorCode.ERR_Success)
  367. {
  368. LogServerHelper.SendNodeLog((int)PlayParticipationEnum.FU_ZHUANG_YANG_CHENG, 2);
  369. }
  370. }
  371. private void OnListenerRenew()
  372. {
  373. ViewManager.Show<ClothingRenewFinishView>(_suitId);
  374. UpdateRenew();
  375. Debug.Log("换新奖励:" + ItemDataManager.GetItemNum(10370));
  376. }
  377. private void CheckGuide(object param)
  378. {
  379. if (GuideDataManager.IsGuideFinish(ConstGuideId.SUIT_LIST_VIEW) <= 0)
  380. {
  381. UpdateToCheckGuide(null);
  382. }
  383. else
  384. {
  385. Timers.inst.Remove(CheckGuide);
  386. }
  387. }
  388. protected override void UpdateToCheckGuide(object param)
  389. {
  390. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  391. GuideController.TryGuide(_ui.m_btnTabFoster, ConstGuideId.SUIT_LIST_VIEW, 4, "点击进行服饰养护工作");
  392. GuideController.TryGuide(_ui.m_btnTabRenew, ConstGuideId.SUIT_LIST_VIEW, 5, "完成养护流程后,可以对服饰进行焕新,获得更多新的套装配件哦~");
  393. GuideController.TryCompleteGuide(ConstGuideId.SUIT_LIST_VIEW, 5);
  394. }
  395. }
  396. }