PartnerEpiMainPanelCtrl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using System.Text;
  8. using FairyGUI;
  9. using FL.Data;
  10. using XGame;
  11. using XGame.Database;
  12. using XGame.Framework.UI;
  13. using XGame.Framework.Utils;
  14. namespace FL.FGUI
  15. {
  16. /// <summary>
  17. /// UI逻辑处理类
  18. /// </summary>
  19. /// <typeparam name=""></typeparam>
  20. public partial class PartnerEpiMainPanelCtrl : UIController<PartnerEpiMainPanelVM>
  21. {
  22. private bool _initialized = false;
  23. private bool _showPlanSwitch = false;
  24. private Controller _switchBtnCtrl;
  25. protected override void OnEnable(object intent)
  26. {
  27. AddUIListenres();
  28. AddEventListenres();
  29. InitList();
  30. UpView();
  31. }
  32. protected override void OnDisable()
  33. {
  34. RemoveUIListenres();
  35. RemoveEventListenres();
  36. ClearView();
  37. }
  38. #region UI事件
  39. private void AddUIListenres()
  40. {
  41. VM.OneUpBtn.onClick.Add(OnClickOneUpBtn);
  42. VM.OneStrongBtn.onClick.Add(OnClickOneStrongBtn);
  43. VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
  44. VM.MaskBtn.onClick.Add(OnClickMaskBtn);
  45. }
  46. private void RemoveUIListenres()
  47. {
  48. VM.OneUpBtn.onClick.Remove(OnClickOneUpBtn);
  49. VM.OneStrongBtn.onClick.Remove(OnClickOneStrongBtn);
  50. VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
  51. VM.MaskBtn.onClick.Remove(OnClickMaskBtn);
  52. }
  53. private void OnClickChangeBtn(EventContext context)
  54. {
  55. _showPlanSwitch = !_showPlanSwitch;
  56. if (EpigraphData.Instance.UpModeSelect > 0)
  57. {
  58. EpigraphService.Instance.FinishUpMode();
  59. }
  60. ShowPlanNested();
  61. RefreshBagEpigraph();
  62. }
  63. private void OnClickMaskBtn(EventContext context)
  64. {
  65. EpigraphService.Instance.FinishUpMode();
  66. }
  67. #region 事件监听
  68. private void AddEventListenres()
  69. {
  70. EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnUpdateAll);
  71. EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnUpdateAll);
  72. EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnUpdateAll);
  73. EventSingle.Instance.AddListener(EventDefine.PartnerPlanChange, OnPlanChange);
  74. EventSingle.Instance.AddListener(EventDefine.PartnerStrongAll, OnUpdateAll);
  75. EventSingle.Instance.AddListener(EventDefine.PartnerUpLevel, OnUpdateAll);
  76. EventSingle.Instance.AddListener(EventDefine.PartnerUpStar, OnUpdateAll);
  77. EventSingle.Instance.AddListener(EventDefine.PartnerWearAll, OnUpdateAll);
  78. EventSingle.Instance.AddListener(EventDefine.EpigraphWearAll, OnUpdateAll);
  79. EventSingle.Instance.AddListener(EventDefine.EpigraphStrongAll, OnUpdateAll);
  80. EventSingle.Instance.AddListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
  81. EventSingle.Instance.AddListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
  82. EventSingle.Instance.AddListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect);
  83. }
  84. private void RemoveEventListenres()
  85. {
  86. EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnUpdateAll);
  87. EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnUpdateAll);
  88. EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnUpdateAll);
  89. EventSingle.Instance.RemoveListener(EventDefine.PartnerPlanChange, OnPlanChange);
  90. EventSingle.Instance.RemoveListener(EventDefine.PartnerStrongAll, OnUpdateAll);
  91. EventSingle.Instance.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateAll);
  92. EventSingle.Instance.RemoveListener(EventDefine.PartnerUpStar, OnUpdateAll);
  93. EventSingle.Instance.RemoveListener(EventDefine.PartnerWearAll, OnUpdateAll);
  94. EventSingle.Instance.RemoveListener(EventDefine.EpigraphWearAll, OnUpdateAll);
  95. EventSingle.Instance.RemoveListener(EventDefine.EpigraphStrongAll, OnUpdateAll);
  96. EventSingle.Instance.RemoveListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
  97. EventSingle.Instance.RemoveListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
  98. EventSingle.Instance.RemoveListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect);
  99. }
  100. #endregion
  101. private void OnClickOneUpBtn(EventContext context)
  102. {
  103. EpigraphService.Instance.RequestEpiWearAll();
  104. }
  105. private void OnClickOneStrongBtn(EventContext context)
  106. {
  107. var list = EpigraphData.Instance.EpiList;
  108. var canUp = false;
  109. foreach (var epigraph in list)
  110. {
  111. var lvTable = epigraphUpTableRepo.GetEpiragphUp(epigraph.TableId, epigraph.StarLv);
  112. if (lvTable == null)
  113. {
  114. Log.Error($"铭文升星表不存在id:{epigraph.TableId},starLv:{epigraph.StarLv}");
  115. }
  116. if (ItemService.Instance.IsEnough(epigraph.TableId, lvTable.LevelUpCost, false))
  117. {
  118. canUp = true;
  119. break;
  120. }
  121. }
  122. if (canUp)
  123. {
  124. EpigraphService.Instance.RequestEpiStrongAll();
  125. }
  126. else
  127. {
  128. Context.ShowTips(StringDefine.EpigraphCantStarUpAll);
  129. }
  130. }
  131. #endregion
  132. #region 事件
  133. private void OnEpiUpSelect(int eventId, object args)
  134. {
  135. var sbId = (int)args;
  136. if (EpigraphData.Instance.UpModeSelect > 0)
  137. {
  138. EpigraphService.Instance.RequestEpiInset(sbId, EpigraphData.Instance.UpModeSelect);
  139. }
  140. }
  141. private void OnReName(int eventId, object args)
  142. {
  143. UpdatePlanName();
  144. }
  145. private void OnUpdateAll(int eventId, object args)
  146. {
  147. RefreshBagEpigraph();
  148. RefreshGoneUpPartners();
  149. }
  150. private void OnPlanChange(int eventId, object args)
  151. {
  152. UpdatePlanName();
  153. RefreshBagEpigraph();
  154. RefreshGoneUpPartners();
  155. }
  156. private void OnEpiUpdate(int eventId, object args)
  157. {
  158. RefreshBagEpigraph();
  159. RefreshGoneUpPartners();
  160. }
  161. /// <summary>
  162. /// 铭文上阵打开事件
  163. /// </summary>
  164. /// <param name="eventId"></param>
  165. /// <param name="args"></param>
  166. private void OnOpenUpMode(int eventId, object args)
  167. {
  168. if (_showPlanSwitch)
  169. {
  170. ShowPlanNested();
  171. RefreshBagEpigraph();
  172. }
  173. ShowUpMode();
  174. }
  175. private void OnFinishUpMode(int eventId, object args)
  176. {
  177. ShowUpMode();
  178. }
  179. #endregion
  180. private void InitList()
  181. {
  182. if (_initialized)
  183. return;
  184. VM.UpList.ListType = EGListType.None;
  185. VM.BagList.ListType = EGListType.Virtual;
  186. _switchBtnCtrl = VM.ChangeBtn.GetController("arr");
  187. _initialized = true;
  188. }
  189. private void UpView()
  190. {
  191. RefreshBagEpigraph();
  192. RefreshGoneUpPartners();
  193. UpdatePlanName();
  194. ShowPlanNested();
  195. ShowUpMode();
  196. }
  197. private void RefreshGoneUpPartners()
  198. {
  199. var plan = PartnersData.Instance.CurUsePlan;
  200. var list = new List<int>();
  201. for (int i = 0; i < PartnersData.GoneUpLimit; i++)
  202. {
  203. list.Add(i);
  204. }
  205. VM.UpList.BindDatas(list);
  206. }
  207. private void UpdatePlanName()
  208. {
  209. var plan = PartnersData.Instance.CurUsePlan;
  210. VM.PlanLabel.text = plan.Name;
  211. }
  212. private void RefreshBagEpigraph()
  213. {
  214. if (VM.State.selectedIndex == 1)
  215. return;
  216. var list = EpigraphTableRepo.GetAll();
  217. VM.BagList.BindDatas(list);
  218. ShowOwnerAttr();
  219. }
  220. private void ShowPlanNested()
  221. {
  222. VM.State.selectedIndex = _showPlanSwitch ? 1 : 0;
  223. _switchBtnCtrl.selectedIndex = _showPlanSwitch ? 1 : 0;
  224. if (_showPlanSwitch)
  225. {
  226. VM.PlanNested.Enable(null);
  227. VM.PlanNested.Ctrl.ShowUI();
  228. }
  229. else
  230. {
  231. VM.PlanNested.Disable();
  232. }
  233. }
  234. private void ShowUpMode()
  235. {
  236. if (PartnersData.Instance.UpModeSelect > 0)
  237. {
  238. VM.SelectMode.selectedIndex = 1;
  239. }
  240. else if (EpigraphData.Instance.UpModeSelect > 0)
  241. {
  242. VM.SelectMode.selectedIndex = 1;
  243. }
  244. else
  245. {
  246. VM.SelectMode.selectedIndex = 0;
  247. }
  248. }
  249. private void ClearView()
  250. {
  251. EpigraphService.Instance.FinishUpMode();
  252. PartnersService.Instance.FinishUpPartnerMode();
  253. _showPlanSwitch = false;
  254. VM.PlanNested.Disable();
  255. }
  256. public void ShowOwnerAttr()
  257. {
  258. var list = EpigraphData.Instance.EpiList;
  259. var map = new Dictionary<int, int>();
  260. foreach (var epigraph in list)
  261. {
  262. var starTable = epigraphUpTableRepo.GetEpiragphUp(
  263. epigraph.TableId,
  264. epigraph.StarLv
  265. );
  266. if (starTable == null)
  267. {
  268. Log.Error($"铭文升星表不存在id:{epigraph.TableId},starLv:{epigraph.StarLv}");
  269. continue;
  270. }
  271. var attrsArray = starTable.LvOwnAttr;
  272. if (attrsArray?.Length > 0)
  273. {
  274. for (int i = 0; i < attrsArray.Length; i += 2)
  275. {
  276. if (map.TryGetValue(attrsArray[i], out var attr))
  277. {
  278. map.Remove(attrsArray[i]);
  279. map.Add(attrsArray[i], attr + attrsArray[i + 1]);
  280. }
  281. else
  282. {
  283. map.Add(attrsArray[i], attrsArray[i + 1]);
  284. }
  285. }
  286. }
  287. }
  288. if (map.Count > 0)
  289. {
  290. var desc = StringBuilderUtils.Acquire();
  291. int index = 0;
  292. foreach (var pair in map)
  293. {
  294. if (index > 0)
  295. {
  296. desc.Append(",");
  297. index++;
  298. }
  299. GetAttributeDesc(pair.Key, pair.Value, ref desc);
  300. }
  301. VM.AttrLabel.text = desc.ToString();
  302. VM.HaveLabel.visible = true;
  303. VM.AttrLabel.visible = true;
  304. }
  305. else
  306. {
  307. VM.HaveLabel.visible = false;
  308. VM.AttrLabel.visible = false;
  309. }
  310. }
  311. private void GetAttributeDesc(int attrType, int attrValue, ref StringBuilder desc)
  312. {
  313. var attributeInfo = AttrDescTableRepo.Get(attrType);
  314. string valStr = attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
  315. desc.Append(attributeInfo?.ShowName);
  316. desc.Append(valStr);
  317. desc.Append("%");
  318. }
  319. }
  320. }