SuitView.cs 15 KB

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