SuitView.cs 17 KB

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