MountDevelopPanelCtrl.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Network;
  8. using System.Collections.Generic;
  9. using XGame.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. /// <summary>
  14. /// UI逻辑处理类
  15. /// </summary>
  16. /// <typeparam name=""></typeparam>
  17. public partial class MountDevelopPanelCtrl : UIController<MountDevelopPanelVM>
  18. {
  19. private int _pageIndex; // 当前显示的页签索引
  20. protected override void OnEnable(object intent)
  21. {
  22. AddUIListenres();
  23. AddEventListener();
  24. Init();
  25. }
  26. protected override void OnDisable()
  27. {
  28. RemoveUIListenres();
  29. RemoveEventListener();
  30. }
  31. #region UI事件
  32. private void AddUIListenres()
  33. {
  34. VM.UpgradeBtn.onClick.Add(OnClickUpgradeBtn);
  35. VM.TrainBtn.onClick.Add(OnClickTrainBtn);
  36. VM.AdvancedMountBtn.onClick.Add(OnClickAdvancedMountBtn);
  37. VM.LastBtn.onClick.Add(OnClickLastBtn);
  38. VM.NextBtn.onClick.Add(OnClickNextBtn);
  39. VM.RideBtn.onClick.Add(OnClickRideBtn);
  40. VM.FeedBtn.onClick.Add(OnClickFeedBtn);
  41. VM.OneClickFeedingBtn.onClick.Add(OnClickOneClickFeedingBtn);
  42. VM.UpgradePreviewBtn.onClick.Add(OnClickUpgradePreviewBtn);
  43. VM.EnableSkillBtn.onClick.Add(OnClickEnableSkillBtn);
  44. VM.UpgradeMountBtn.onClick.Add(OnClickUpgradeMountBtn);
  45. VM.UnlockMountBtn.onClick.Add(OnClickUnlockMountBtn);
  46. VM.AdvancedMountList.ItemClickEvent += ClickAdvancedMountItem;
  47. }
  48. private void RemoveUIListenres()
  49. {
  50. VM.UpgradeBtn.onClick.Remove(OnClickUpgradeBtn);
  51. VM.TrainBtn.onClick.Remove(OnClickTrainBtn);
  52. VM.AdvancedMountBtn.onClick.Remove(OnClickAdvancedMountBtn);
  53. VM.LastBtn.onClick.Remove(OnClickLastBtn);
  54. VM.NextBtn.onClick.Remove(OnClickNextBtn);
  55. VM.RideBtn.onClick.Remove(OnClickRideBtn);
  56. VM.FeedBtn.onClick.Remove(OnClickFeedBtn);
  57. VM.OneClickFeedingBtn.onClick.Remove(OnClickOneClickFeedingBtn);
  58. VM.UpgradePreviewBtn.onClick.Remove(OnClickUpgradePreviewBtn);
  59. VM.EnableSkillBtn.onClick.Remove(OnClickEnableSkillBtn);
  60. VM.UpgradeMountBtn.onClick.Remove(OnClickUpgradeMountBtn);
  61. VM.UnlockMountBtn.onClick.Remove(OnClickUnlockMountBtn);
  62. VM.AdvancedMountList.ItemClickEvent -= ClickAdvancedMountItem;
  63. }
  64. /// <summary>
  65. /// 坐骑升级页签按钮
  66. /// </summary>
  67. /// <param name="context"></param>
  68. private void OnClickUpgradeBtn(EventContext context)
  69. {
  70. ShowPage(0);
  71. }
  72. /// <summary>
  73. /// 坐骑驯养页签按钮
  74. /// </summary>
  75. /// <param name="context"></param>
  76. private void OnClickTrainBtn(EventContext context)
  77. {
  78. ShowPage(1);
  79. }
  80. /// <summary>
  81. /// 高级坐骑页签按钮
  82. /// </summary>
  83. /// <param name="context"></param>
  84. private void OnClickAdvancedMountBtn(EventContext context)
  85. {
  86. ShowPage(2);
  87. }
  88. private void OnClickLastBtn(EventContext context)
  89. {
  90. if (_mountIndex > 0) ShowSelectMount(_mountIndex - 1);
  91. }
  92. private void OnClickNextBtn(EventContext context)
  93. {
  94. if (_mountIndex < _mountModelList.Count - 1) ShowSelectMount(_mountIndex + 1);
  95. }
  96. private void OnClickRideBtn(EventContext context)
  97. {
  98. int mountId = _mountModelList[_mountIndex].tableId;
  99. if (mountId == MountData.Instance.mountModelId)
  100. {
  101. MountService.Instance.SendToRideDown();
  102. }
  103. else
  104. MountService.Instance.SendToRideMount(mountId);
  105. }
  106. private void OnClickFeedBtn(EventContext context)
  107. {
  108. if (_pageIndex == 0)
  109. MountService.Instance.SendToFeedMount();
  110. else if (_pageIndex == 1)
  111. MountService.Instance.SendToTrainingMountPart();
  112. }
  113. private void OnClickOneClickFeedingBtn(EventContext context)
  114. {
  115. if (_pageIndex == 0)
  116. MountService.Instance.SendToOneKeyFeedMount();
  117. else if (_pageIndex == 1)
  118. MountService.Instance.SendToOneKeyTraining();
  119. }
  120. private void OnClickUpgradePreviewBtn(EventContext context)
  121. {
  122. }
  123. private void OnClickEnableSkillBtn(EventContext context)
  124. {
  125. MountService.Instance.SendToEnableAdvancedSkill(_advancedMountsInfoList[_curAdvancedIndex].Id);
  126. }
  127. private void OnClickUpgradeMountBtn(EventContext context)
  128. {
  129. MountService.Instance.SendToUpgradeStar(_advancedMountsInfoList[_curAdvancedIndex].Id);
  130. }
  131. private void OnClickUnlockMountBtn(EventContext context)
  132. {
  133. MountService.Instance.SendToUnlockAdvancedMount(_advancedMountsInfoList[_curAdvancedIndex].Id);
  134. }
  135. #endregion
  136. private void AddEventListener()
  137. {
  138. EventSingle.Instance.AddListener(EventDefine.RefreshMountInfo, RefreshMountInfo);
  139. EventSingle.Instance.AddListener(EventDefine.ChangeRideState, ChangeRideState);
  140. EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnUpdateItemNum);
  141. EventSingle.Instance.AddListener(EventDefine.FeedMountSucessful, FeedMountSucessful);
  142. EventSingle.Instance.AddListener(EventDefine.TrainMountSucessful, TrainMountSucessful);
  143. EventSingle.Instance.AddListener(EventDefine.UnlockAdvancedMountSucessful, UnlockAdvancedMountSucessful);
  144. EventSingle.Instance.AddListener(EventDefine.UseMountSkillSucessful, UseMountSkillSucessful);
  145. EventSingle.Instance.AddListener(EventDefine.UpgradeAdvancedMountSucessful, UpgradeAdvancedMountSucessful);
  146. }
  147. private void RemoveEventListener()
  148. {
  149. EventSingle.Instance.RemoveListener(EventDefine.RefreshMountInfo, RefreshMountInfo);
  150. EventSingle.Instance.RemoveListener(EventDefine.ChangeRideState, ChangeRideState);
  151. EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnUpdateItemNum);
  152. EventSingle.Instance.RemoveListener(EventDefine.FeedMountSucessful, FeedMountSucessful);
  153. EventSingle.Instance.RemoveListener(EventDefine.TrainMountSucessful, TrainMountSucessful);
  154. EventSingle.Instance.RemoveListener(EventDefine.UnlockAdvancedMountSucessful, UnlockAdvancedMountSucessful);
  155. EventSingle.Instance.RemoveListener(EventDefine.UseMountSkillSucessful, UseMountSkillSucessful);
  156. EventSingle.Instance.RemoveListener(EventDefine.UpgradeAdvancedMountSucessful, UpgradeAdvancedMountSucessful);
  157. }
  158. private void Init()
  159. {
  160. if (_mountStepMap == null)_mountStepMap = new Dictionary<int, zuoqiInfoTable>();
  161. if (_mountModelList == null)_mountModelList = new List<MountModelParam>();
  162. if (_advancedMountsInfoList == null) _advancedMountsInfoList = new List<zuoqiBaseTable> ();
  163. if (_mountBaseAttrList == null) _mountBaseAttrList = new List<MountAttrParam> ();
  164. if (_mountSpecialAttrList == null) _mountSpecialAttrList = new List<MountAttrParam>();
  165. if (_trainPartsList == null)
  166. {
  167. _trainPartsList = new List<MountTrainingAreaNestedView>() { VM.TrainingTheHead, VM.TrainingTheBody, VM.TrainingFeet };
  168. }
  169. _mountIndex = 0;
  170. _pageIndex = 0;
  171. MountService.Instance.SendToMountData();
  172. }
  173. /// <summary>
  174. /// 道具数据变化
  175. /// </summary>
  176. /// <param name="eventId"></param>
  177. /// <param name="args"></param>
  178. private void OnUpdateItemNum(int eventId, object args)
  179. {
  180. var itemDataList = args as List<ActItem>;
  181. if (itemDataList?.Count > 0)
  182. {
  183. for (int i = 0; i < itemDataList.Count; i++)
  184. {
  185. if (_pageIndex == 0 && itemDataList[i].id == _feedCostItemId)
  186. {
  187. // 通用坐骑升星消耗
  188. ShowFeedCostUI();
  189. }
  190. else if (_pageIndex == 1 && itemDataList[i].id == _trainCostItemId)
  191. {
  192. // 通用坐骑驯养消耗
  193. ShowTrainCostUI();
  194. }
  195. }
  196. }
  197. }
  198. /// <summary>
  199. /// 返回坐骑数据,刷新坐骑界面UI
  200. /// </summary>
  201. /// <param name="eventId"></param>
  202. /// <param name="args"></param>
  203. private void RefreshMountInfo(int eventId, object args)
  204. {
  205. GetAdvanceMountData();
  206. GetMouuntModelData();
  207. if (_pageIndex == 0)
  208. {
  209. ShowPage(0);
  210. }
  211. }
  212. /// <summary>
  213. /// 页签切换事件
  214. /// </summary>
  215. /// <param name="pageIndex"></param>
  216. private void ShowPage(int pageIndex)
  217. {
  218. _pageIndex = pageIndex;
  219. VM.PageCtrl.selectedIndex = pageIndex;
  220. ShowAdvancedMountBtn(false);
  221. ShowUnlockLv(false);
  222. ShowEnableSkillBtn(false);
  223. ShowUpgradePreviewBtn(false);
  224. ShowMountStar(false);
  225. ShowTrainPartUI(pageIndex == 1);
  226. if (pageIndex == 0)
  227. {
  228. ShowUniversalMountsUI();
  229. }
  230. else if(pageIndex == 1)
  231. {
  232. ShowTrainMountsUI();
  233. ShowRideUI(false);
  234. }
  235. else if (pageIndex == 2)
  236. {
  237. ShowAdvancedMountUI();
  238. }
  239. }
  240. /// <summary>
  241. /// 是否显示高级坐骑的星级
  242. /// </summary>
  243. /// <param name="bShow"></param>
  244. private void ShowMountStar(bool bShow)
  245. {
  246. VM.MountStar.visible = bShow;
  247. }
  248. /// <summary>
  249. /// 显示坐骑名称
  250. /// </summary>
  251. /// <param name="name"></param>
  252. private void ShowMountName(string name)
  253. {
  254. VM.MountNameLabel.text = name;
  255. }
  256. /// <summary>
  257. /// 骑乘状态UI
  258. /// </summary>
  259. /// <param name="bShow"></param>
  260. /// <param name="bRide"></param>
  261. private void ShowRideUI(bool bShow, bool bRide = false)
  262. {
  263. VM.RideBtn.visible = bShow;
  264. if (bShow)
  265. {
  266. VM.RideCtrl.selectedIndex = bRide ? 1 : 0;
  267. }
  268. }
  269. /// <summary>
  270. /// 坐骑骑乘状态变化
  271. /// </summary>
  272. /// <param name="eventId"></param>
  273. /// <param name="args"></param>
  274. private void ChangeRideState(int eventId, object args)
  275. {
  276. if (_pageIndex == 0)
  277. {
  278. var param = _mountModelList[_mountIndex];
  279. if (param.tableId > 0)
  280. {
  281. ShowRideUI(!param.bLock, param.tableId == MountData.Instance.mountModelId);
  282. }
  283. }
  284. else if (_pageIndex == 2)
  285. {
  286. int mountId = _advancedMountsInfoList[_curAdvancedIndex].Id;
  287. ShowRideUI(MountData.Instance.IsUnLock(mountId), mountId == MountData.Instance.mountModelId);
  288. }
  289. }
  290. }
  291. }