SuitView.cs 16 KB

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