MountUpgradeNestedCtrl.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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. public struct MountModelParam
  14. {
  15. public int tableId; //序号ID(坐骑id*10000+阶级*100+星级)
  16. public int unlockStep;
  17. public bool bLock; // 是否未解锁状态
  18. public string spineName;
  19. }
  20. public struct MountAttrParam
  21. {
  22. public EAttributeType attrType;
  23. public int curVal; // 当前星阶的属性值
  24. public int nextVal;
  25. }
  26. /// <summary>
  27. /// UI逻辑处理类
  28. /// </summary>
  29. /// <typeparam name=""></typeparam>
  30. public partial class MountUpgradeNestedCtrl : UIController<MountUpgradeNestedVM>
  31. {
  32. private bool _bInitData = true;
  33. private int _mountIndex; // 当前显示的坐骑的索引
  34. private int _universalId;
  35. private int _feedCostItemId; // 升星需要的道具id
  36. private zuoqiInfoTable _curMountInfo;
  37. private List<MountModelParam> _mountModelList; // 普通坐骑模型列表
  38. private List<MountAttrParam> _mountBaseAttrList;
  39. private List<MountAttrParam> _mountSpecialAttrList;
  40. private Dictionary<int, zuoqiInfoTable> _mountStepMap; // 坐骑星阶数据
  41. /// <summary>
  42. /// 通用坐骑每阶的最大升星等级
  43. /// </summary>
  44. private const int MaxStarLv = 10;
  45. protected override void OnEnable(object intent)
  46. {
  47. AddUIListenres();
  48. AddEventListener();
  49. }
  50. protected override void OnDisable()
  51. {
  52. RemoveUIListenres();
  53. RemoveEventListener();
  54. VM.MountSpine.url = string.Empty;
  55. }
  56. private void AddEventListener()
  57. {
  58. Context.AddListener(EventDefine.ChangeRideState, ChangeRideState);
  59. Context.AddListener(EventDefine.UpdataItemData, OnUpdateItemNum);
  60. Context.AddListener(EventDefine.FeedMountSucessful, FeedMountSucessful);
  61. }
  62. private void RemoveEventListener()
  63. {
  64. Context.RemoveListener(EventDefine.ChangeRideState, ChangeRideState);
  65. Context.RemoveListener(EventDefine.UpdataItemData, OnUpdateItemNum);
  66. Context.RemoveListener(EventDefine.FeedMountSucessful, FeedMountSucessful);
  67. }
  68. public void ClearData()
  69. {
  70. _mountModelList?.Clear();
  71. _mountModelList = null;
  72. _mountBaseAttrList?.Clear();
  73. _mountBaseAttrList = null;
  74. _mountSpecialAttrList?.Clear();
  75. _mountSpecialAttrList = null;
  76. _mountStepMap?.Clear();
  77. _mountStepMap = null;
  78. _bInitData = true;
  79. }
  80. #region UI事件
  81. private void AddUIListenres()
  82. {
  83. VM.LastBtn.onClick.Add(OnClickLastBtn);
  84. VM.NextBtn.onClick.Add(OnClickNextBtn);
  85. VM.RideBtn.onClick.Add(OnClickRideBtn);
  86. VM.FeedBtn.onClick.Add(OnClickFeedBtn);
  87. VM.OneClickFeedingBtn.onClick.Add(OnClickOneClickFeedingBtn);
  88. }
  89. private void RemoveUIListenres()
  90. {
  91. VM.LastBtn.onClick.Remove(OnClickLastBtn);
  92. VM.NextBtn.onClick.Remove(OnClickNextBtn);
  93. VM.RideBtn.onClick.Remove(OnClickRideBtn);
  94. VM.FeedBtn.onClick.Remove(OnClickFeedBtn);
  95. VM.OneClickFeedingBtn.onClick.Remove(OnClickOneClickFeedingBtn);
  96. }
  97. private void OnClickLastBtn(EventContext context)
  98. {
  99. if (_mountIndex > 0) ShowSelectMount(_mountIndex - 1);
  100. }
  101. private void OnClickNextBtn(EventContext context)
  102. {
  103. if (_mountIndex < _mountModelList.Count - 1) ShowSelectMount(_mountIndex + 1);
  104. }
  105. private void OnClickRideBtn(EventContext context)
  106. {
  107. int mountId = _mountModelList[_mountIndex].tableId;
  108. if (mountId == MountData.Instance.MountModelId)
  109. {
  110. MountService.Instance.SendToRideDown();
  111. }
  112. else
  113. MountService.Instance.SendToRideMount(mountId);
  114. }
  115. private void OnClickFeedBtn(EventContext context)
  116. {
  117. MountService.Instance.SendToFeedMount();
  118. }
  119. private void OnClickOneClickFeedingBtn(EventContext context)
  120. {
  121. MountService.Instance.SendToOneKeyFeedMount();
  122. }
  123. #endregion
  124. private void Init()
  125. {
  126. if (_mountStepMap == null) _mountStepMap = new Dictionary<int, zuoqiInfoTable>();
  127. if (_mountModelList == null) _mountModelList = new List<MountModelParam>();
  128. if (_mountBaseAttrList == null) _mountBaseAttrList = new List<MountAttrParam>();
  129. if (_mountSpecialAttrList == null) _mountSpecialAttrList = new List<MountAttrParam>();
  130. }
  131. /// <summary>
  132. /// 通用坐骑数据
  133. /// </summary>
  134. private void GetMouuntModelData()
  135. {
  136. _universalId = MountData.Instance.UniversalId;
  137. _curMountInfo = zuoqiInfoTableRepo.Get(MountData.Instance.UniversalId);
  138. if (_curMountInfo == null)
  139. {
  140. XGame.Log.Error($"坐骑表zuoqiInfo信息不存在,id:{MountData.Instance.UniversalId}");
  141. return;
  142. }
  143. var mountBaseInfo = zuoqiBaseTableRepo.Get(_curMountInfo.Zqid);
  144. if (mountBaseInfo != null)
  145. {
  146. VM.MountNameLabel.text = mountBaseInfo.Name;
  147. }
  148. _feedCostItemId = _curMountInfo.StarNeed[0];
  149. _mountModelList.Clear();
  150. int starLv = _curMountInfo.Star;
  151. var cfgInfoList = zuoqiInfoTableRepo.GetAll();
  152. var first = cfgInfoList[0];
  153. var last = cfgInfoList[cfgInfoList.Length - 1];
  154. int mountId = first.Zqid;
  155. string lastModelName = string.Empty;
  156. int paramId = mountId * 10000;
  157. for (var step = first.Step; step <= last.Step; step++)
  158. {
  159. var mountInfo = zuoqiInfoTableRepo.Get(paramId + step * 100);
  160. if (mountInfo != null)
  161. {
  162. if (mountInfo.Spine != lastModelName)
  163. {
  164. lastModelName = mountInfo.Spine;
  165. _mountModelList.Add(new MountModelParam()
  166. {
  167. tableId = mountInfo.Id,
  168. unlockStep = mountInfo.Step,
  169. bLock = _curMountInfo.Step < mountInfo.Step || starLv < mountInfo.Star,
  170. spineName = mountInfo.Spine
  171. });
  172. }
  173. if (mountInfo.Star == 0 && !_mountStepMap.ContainsKey(mountInfo.Step))
  174. {
  175. _mountStepMap.Add(mountInfo.Step, mountInfo);
  176. }
  177. }
  178. }
  179. }
  180. /// <summary>
  181. /// 优先获取骑乘的普通坐骑索引,如果骑乘的不是普通坐骑,则显示当前解锁的最高阶坐骑索引
  182. /// </summary>
  183. private void SetMountIndex()
  184. {
  185. _mountIndex = 0;
  186. int showMountModelId = 0;
  187. var advanceMountInfo = zuoqiBaseTableRepo.Get(MountData.Instance.MountModelId);
  188. if (advanceMountInfo == null)
  189. {
  190. var mountModelInfo = zuoqiInfoTableRepo.Get(MountData.Instance.MountModelId);
  191. if (mountModelInfo != null)
  192. {
  193. showMountModelId = mountModelInfo.Id;
  194. }
  195. }
  196. for (int i = 0; i < _mountModelList.Count; i++)
  197. {
  198. if (showMountModelId == 0)
  199. {
  200. if (_mountModelList[i].unlockStep > _curMountInfo.Step)
  201. {
  202. return;
  203. }
  204. else
  205. {
  206. _mountIndex = i;
  207. }
  208. }
  209. else if (_mountModelList[i].tableId == showMountModelId)
  210. {
  211. _mountIndex = i;
  212. return;
  213. }
  214. }
  215. }
  216. /// <summary>
  217. /// 通用坐骑升级界面
  218. /// </summary>
  219. public void ShowUpgradeMountUI()
  220. {
  221. if (_bInitData)
  222. {
  223. Init();
  224. GetMouuntModelData();
  225. SetMountIndex();
  226. _bInitData = false;
  227. }
  228. ShowSelectMount(_mountIndex);
  229. ShowMountBaseAttr(_curMountInfo.Star);
  230. ShowMountSpecialAttr(_curMountInfo.Step);
  231. VM.ExpBar.max = _curMountInfo.StarNeed[1];
  232. ShowExp();
  233. ShowStar();
  234. ShowFeedCostUI();
  235. }
  236. /// <summary>
  237. /// 通用坐骑升星经验进度
  238. /// </summary>
  239. private void ShowExp()
  240. {
  241. VM.ExpBar.value = VM.MaxUpgradeStep.selectedIndex == 1 ? VM.ExpBar.max : MountData.Instance.UniversalExp;
  242. }
  243. /// <summary>
  244. /// 通用坐骑的星级
  245. /// </summary>
  246. private void ShowStar()
  247. {
  248. VM.StarBar.GetController("StarLvCtrl").selectedIndex = _curMountInfo.Star;
  249. }
  250. /// <summary>
  251. /// 升星消耗
  252. /// </summary>
  253. private void ShowFeedCostUI()
  254. {
  255. VM.FeedCostItem.Ctrl.ShowCostUI(_feedCostItemId, 1);
  256. }
  257. /// <summary>
  258. /// (通用坐骑)特殊属性加成
  259. /// </summary>
  260. /// <param name="starLv"></param>
  261. private void ShowMountSpecialAttr(int stepLv)
  262. {
  263. VM.MountStepLvLabel.text = stepLv.ToString();
  264. var nextInfo = _mountStepMap.ContainsKey(_curMountInfo.Step + 1) ? _mountStepMap[_curMountInfo.Step + 1] : null;
  265. bool bMaxStep = nextInfo == null;
  266. if (bMaxStep && _curMountInfo.Star == MaxStarLv)
  267. {
  268. ShowMaxUpgradeStep(true);//满星阶状态
  269. ShowCostItemNestedUI(false);
  270. }
  271. VM.SpecialAttrItem.Ctrl.OnRefresh(0, new MountAttrParam()
  272. {
  273. attrType = (EAttributeType)_curMountInfo.StarSkill[0],
  274. curVal = _curMountInfo.StarSkill[1],
  275. nextVal = bMaxStep ? 0 : nextInfo.StarSkill[1]
  276. });
  277. if (!bMaxStep)
  278. {
  279. VM.NextStepLvLabel.text = string.Format(StringDefine.UnlockNextMountStep, nextInfo.Step);
  280. }
  281. }
  282. /// <summary>
  283. /// 满星阶
  284. /// </summary>
  285. /// <param name="bShow"></param>
  286. private void ShowMaxUpgradeStep(bool bShow)
  287. {
  288. VM.MaxUpgradeStep.selectedIndex = bShow ? 1 : 0;
  289. }
  290. /// <summary>
  291. /// 通用坐骑升级消耗
  292. /// </summary>
  293. /// <param name="bShow"></param>
  294. private void ShowCostItemNestedUI(bool bShow)
  295. {
  296. if (bShow)
  297. VM.FeedCostItem.Enable(null);
  298. else
  299. VM.FeedCostItem.Disable();
  300. }
  301. /// <summary>
  302. /// (通用坐骑)基础属性加成UI
  303. /// </summary>
  304. /// <param name="starLv"></param>
  305. private void ShowMountBaseAttr(int starLv)
  306. {
  307. VM.BaseStarLvLabel.text = string.Format(StringDefine.MountStarLevel, _curMountInfo.Step, starLv);
  308. _mountBaseAttrList.Clear();
  309. zuoqiInfoTable nextInfo;
  310. if (starLv < MaxStarLv)
  311. nextInfo = zuoqiInfoTableRepo.Get(_curMountInfo.Id + 1);
  312. else
  313. {
  314. //坐骑id*10000+阶级*100+星级
  315. nextInfo = zuoqiInfoTableRepo.Get(_curMountInfo.Zqid * 10000 + (_curMountInfo.Step + 1)*100);
  316. }
  317. bool bMax = nextInfo == null;
  318. int count = _curMountInfo.StepOwnAttr.Length;
  319. if (!bMax)
  320. {
  321. VM.NextStarLvLabel.text = string.Format(StringDefine.MountStarLevel, nextInfo.Step, nextInfo.Star);
  322. }
  323. for (int i = 0; i < count; i += 2)
  324. {
  325. _mountBaseAttrList.Add(new MountAttrParam()
  326. {
  327. attrType = (EAttributeType)_curMountInfo.StepOwnAttr[i],
  328. curVal = _curMountInfo.StepOwnAttr[i + 1],
  329. nextVal = bMax ? 0 : nextInfo.StepOwnAttr[i + 1]
  330. });
  331. }
  332. VM.BaseAttrList.BindDatas(_mountBaseAttrList);
  333. }
  334. /// <summary>
  335. /// 显示选择的普通坐骑立绘
  336. /// </summary>
  337. private void ShowSelectMount(int selectIndex)
  338. {
  339. _mountIndex = selectIndex;
  340. var param = _mountModelList[_mountIndex];
  341. if (param.tableId > 0)
  342. {
  343. ShowMountSpine(param.spineName, true);
  344. ShowRideUI(!param.bLock);
  345. ShowUnlockLv(param.bLock);
  346. if (param.bLock)
  347. {
  348. VM.UnLockModelLabel.text = string.Format(StringDefine.UnlockMountStep, param.unlockStep);
  349. }
  350. else
  351. ShowRideUI(true, param.tableId == MountData.Instance.MountModelId);
  352. }
  353. ShowSwitchMountBtnState();
  354. }
  355. /// <summary>
  356. /// 是否显示解锁条件
  357. /// </summary>
  358. /// <param name="bShow"></param>
  359. private void ShowUnlockLv(bool bShow)
  360. {
  361. VM.UnLockModelLabel.visible = bShow;
  362. }
  363. /// <summary>
  364. /// 坐骑的立绘
  365. /// </summary>
  366. /// <param name="mountPicture"></param>
  367. private void ShowMountSpine(string spineName, bool bShowTraining = false)
  368. {
  369. VM.MountSpine.LoadSpine(spineName, "stand", true);
  370. }
  371. /// <summary>
  372. /// 普通坐骑上一个/下一个切换按钮的状态
  373. /// </summary>
  374. private void ShowSwitchMountBtnState()
  375. {
  376. VM.LastBtn.visible = _mountIndex > 0;
  377. VM.NextBtn.visible = _mountIndex < _mountModelList.Count - 1;
  378. }
  379. /// <summary>
  380. /// 坐骑成功喂养
  381. /// </summary>
  382. /// <param name="eventId"></param>
  383. /// <param name="args"></param>
  384. private void FeedMountSucessful(int eventId, object args)
  385. {
  386. if (_universalId == MountData.Instance.UniversalId)
  387. {
  388. ShowExp();
  389. return;
  390. }
  391. GetMouuntModelData();
  392. ShowUpgradeMountUI();
  393. }
  394. /// <summary>
  395. /// 坐骑骑乘状态变化
  396. /// </summary>
  397. /// <param name="eventId"></param>
  398. /// <param name="args"></param>
  399. private void ChangeRideState(int eventId, object args)
  400. {
  401. var param = _mountModelList[_mountIndex];
  402. if (param.tableId > 0)
  403. {
  404. ShowRideUI(!param.bLock, param.tableId == MountData.Instance.MountModelId);
  405. }
  406. }
  407. /// <summary>
  408. /// 骑乘状态UI
  409. /// </summary>
  410. /// <param name="bShow"></param>
  411. /// <param name="bRide"></param>
  412. private void ShowRideUI(bool bShow, bool bRide = false)
  413. {
  414. VM.RideBtn.visible = bShow;
  415. if (bShow)
  416. {
  417. VM.RideCtrl.selectedIndex = bRide ? 1 : 0;
  418. }
  419. }
  420. /// <summary>
  421. /// 道具数据变化
  422. /// </summary>
  423. /// <param name="eventId"></param>
  424. /// <param name="args"></param>
  425. private void OnUpdateItemNum(int eventId, object args)
  426. {
  427. var itemDataList = args as List<ActItem>;
  428. if (itemDataList?.Count > 0)
  429. {
  430. for (int i = 0; i < itemDataList.Count; i++)
  431. {
  432. if (itemDataList[i].id == _feedCostItemId)
  433. {
  434. // 通用坐骑升星消耗
  435. ShowFeedCostUI();
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }