MountDevelopPanelCtrl.Upgrade.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using XGame.Database;
  8. using XGame.Framework.UI;
  9. namespace FL.FGUI
  10. {
  11. public struct MountModelParam
  12. {
  13. public int tableId; //序号ID(坐骑id*10000+阶级*100+星级)
  14. public int unlockStep;
  15. public bool bLock; // 是否未解锁状态
  16. public string spineName;
  17. }
  18. public struct MountAttrParam
  19. {
  20. public EAttributeType attrType;
  21. public int curVal; // 当前星阶的属性值
  22. public int nextVal;
  23. }
  24. /// <summary>
  25. /// UI逻辑处理类 通用坐骑升级界面
  26. /// </summary>
  27. /// <typeparam name=""></typeparam>
  28. public partial class MountDevelopPanelCtrl : UIController<MountDevelopPanelVM>
  29. {
  30. private int _mountIndex; // 当前显示的坐骑的索引
  31. private int _universalId;
  32. private int _feedCostItemId; // 升星需要的道具id
  33. private zuoqiInfoTable _curMountInfo;
  34. private List<MountModelParam> _mountModelList; // 普通坐骑模型列表
  35. private List<MountAttrParam> _mountBaseAttrList;
  36. private List<MountAttrParam> _mountSpecialAttrList;
  37. private Dictionary<int, zuoqiInfoTable> _mountStepMap; // 坐骑星阶数据
  38. #region 普通坐骑(坐骑升级UI)
  39. /// <summary>
  40. /// 通用坐骑数据
  41. /// </summary>
  42. private void GetMouuntModelData()
  43. {
  44. _universalId = MountData.Instance.universalId;
  45. _curMountInfo = zuoqiInfoTableRepo.Get(MountData.Instance.universalId);
  46. XGame.Framework.Assert.IsNotNull(_curMountInfo, $"坐骑表zuoqiInfo信息不存在,id:{MountData.Instance.universalId}");
  47. var mountBaseInfo = zuoqiBaseTableRepo.Get(_curMountInfo.Zqid);
  48. if (mountBaseInfo != null)
  49. {
  50. ShowMountName(mountBaseInfo.Name);
  51. }
  52. _feedCostItemId = _curMountInfo.StarNeed[0];
  53. ShowFeedCostUI();
  54. _mountModelList.Clear();
  55. int starLv = _curMountInfo.Star;
  56. var cfgInfoList = zuoqiInfoTableRepo.GetAll();
  57. string lastModelName = string.Empty;
  58. foreach (var cfgInfo in cfgInfoList)
  59. {
  60. if (cfgInfo.Icon != lastModelName)
  61. {
  62. lastModelName = cfgInfo.Icon;
  63. _mountModelList.Add(new MountModelParam()
  64. {
  65. tableId = cfgInfo.Id,
  66. unlockStep = cfgInfo.Step,
  67. bLock = _curMountInfo.Step < cfgInfo.Step || starLv < cfgInfo.Star,
  68. spineName = cfgInfo.Picture
  69. });
  70. }
  71. if (cfgInfo.Star == 0 && !_mountStepMap.ContainsKey(cfgInfo.Step))
  72. {
  73. _mountStepMap.Add(cfgInfo.Step, cfgInfo);
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// 坐骑升级UI(普通坐骑)
  79. /// </summary>
  80. private void ShowUniversalMountsUI()
  81. {
  82. ShowSelectMount(_mountIndex);
  83. ShowMountBaseAttr(_curMountInfo.Star);
  84. ShowMountSpecialAttr(_curMountInfo.Star);
  85. VM.ExpBar.max = _curMountInfo.StarNeed[1];
  86. ShowExp();
  87. ShowStar();
  88. }
  89. /// <summary>
  90. /// 通用坐骑升星经验进度
  91. /// </summary>
  92. private void ShowExp()
  93. {
  94. VM.ExpBar.value = MountData.Instance.exp;
  95. }
  96. /// <summary>
  97. /// 通用坐骑的星级
  98. /// </summary>
  99. private void ShowStar()
  100. {
  101. VM.StarBar.GetController("StarLvCtrl").selectedIndex = _curMountInfo.Star;
  102. }
  103. /// <summary>
  104. /// 升星消耗
  105. /// </summary>
  106. private void ShowFeedCostUI()
  107. {
  108. VM.FeedCostItem.Ctrl.ShowCostUI(_feedCostItemId, 1);
  109. }
  110. /// <summary>
  111. /// (通用坐骑)特殊属性加成
  112. /// </summary>
  113. /// <param name="starLv"></param>
  114. private void ShowMountSpecialAttr(int starLv)
  115. {
  116. VM.SpecialStarLvLabel.text = starLv.ToString();
  117. var nextInfo = _mountStepMap.ContainsKey(_curMountInfo.Step + 1) ? _mountStepMap[_curMountInfo.Step +1] : null;
  118. bool bMaxStep = nextInfo == null;
  119. VM.SpecialAttrItem.Ctrl.OnRefresh(0, new MountAttrParam()
  120. {
  121. attrType = (EAttributeType)_curMountInfo.StarSkill[0],
  122. curVal = _curMountInfo.StarSkill[1],
  123. nextVal = bMaxStep ? 0 : nextInfo.StarSkill[0]
  124. });
  125. }
  126. /// <summary>
  127. /// (通用坐骑)基础属性加成UI
  128. /// </summary>
  129. /// <param name="starLv"></param>
  130. private void ShowMountBaseAttr(int starLv)
  131. {
  132. VM.BaseStarLvLabel.text = starLv.ToString();
  133. _mountBaseAttrList.Clear();
  134. var nextInfo = zuoqiInfoTableRepo.Get(_curMountInfo.Id + 1);
  135. bool bMax = nextInfo == null;
  136. int count = _curMountInfo.StepOwnAttr.Length;
  137. for (int i = 0; i < count; i += 2)
  138. {
  139. _mountBaseAttrList.Add(new MountAttrParam()
  140. {
  141. attrType = (EAttributeType)_curMountInfo.StepOwnAttr[i],
  142. curVal = _curMountInfo.StepOwnAttr[i + 1],
  143. nextVal = bMax ? 0 : nextInfo.StepOwnAttr[i + 1]
  144. });
  145. }
  146. VM.BaseAttrList.BindDatas(_mountBaseAttrList);
  147. }
  148. /// <summary>
  149. /// 显示选择的普通坐骑立绘
  150. /// </summary>
  151. private void ShowSelectMount(int selectIndex)
  152. {
  153. _mountIndex = selectIndex;
  154. var param = _mountModelList[_mountIndex];
  155. if (param.tableId > 0)
  156. {
  157. ShowMountPicture(param.spineName);
  158. ShowRideUI(!param.bLock);
  159. if (param.bLock)
  160. {
  161. ShowUnlockLv(true);
  162. VM.UnLockModelLabel.text = string.Format(StringDefine.UnlockMountStep, param.unlockStep);
  163. }
  164. else
  165. ShowRideUI(true);
  166. }
  167. ShowSwitchMountBtnState();
  168. }
  169. /// <summary>
  170. /// 是否显示解锁条件
  171. /// </summary>
  172. /// <param name="bShow"></param>
  173. private void ShowUnlockLv(bool bShow)
  174. {
  175. VM.UnLockModelLabel.visible = bShow;
  176. }
  177. /// <summary>
  178. /// 坐骑的立绘
  179. /// </summary>
  180. /// <param name="mountPicture"></param>
  181. private void ShowMountPicture(string mountPicture, bool bAdvance = false)
  182. {
  183. VM.MountPicture.icon = mountPicture;
  184. if (!bAdvance)
  185. {
  186. VM.TrainMountPicture.icon = mountPicture;
  187. }
  188. }
  189. /// <summary>
  190. /// 普通坐骑上一个/下一个切换按钮的状态
  191. /// </summary>
  192. private void ShowSwitchMountBtnState()
  193. {
  194. VM.LastBtn.visible = _mountIndex > 0;
  195. VM.NextBtn.visible = _mountIndex < _mountModelList.Count - 1;
  196. }
  197. /// <summary>
  198. /// 坐骑成功喂养
  199. /// </summary>
  200. /// <param name="eventId"></param>
  201. /// <param name="args"></param>
  202. private void FeedMountSucessful(int eventId, object args)
  203. {
  204. if (_universalId == MountData.Instance.universalId) return;
  205. GetMouuntModelData();
  206. ShowUniversalMountsUI();
  207. }
  208. #endregion
  209. }
  210. }