SuitView.cs 16 KB

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