ClothingView.cs 17 KB

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