ClothingView.cs 19 KB

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