PlayerChangeImprintPanelCtrl.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Battle.Components.AI;
  8. using FL.Data;
  9. using System.Collections.Generic;
  10. using UnityEngine.UI;
  11. using XGame.Database;
  12. using XGame.Framework.UI;
  13. namespace FL.FGUI
  14. {
  15. /// <summary>
  16. /// UI逻辑处理类
  17. /// </summary>
  18. /// <typeparam name=""></typeparam>
  19. public partial class PlayerChangeImprintPanelCtrl : UIController<PlayerChangeImprintPanelVM>
  20. {
  21. private int _slotId; // 槽位id
  22. private int _runeType; // 符文类型
  23. private GButton[] _btnsArray;
  24. private runeTable _runeTableInfo;
  25. protected override void OnEnable(object intent)
  26. {
  27. AddUIListenres();
  28. _btnsArray = new GButton[3] {VM.AttackImprintBtn, VM.SkillImprintBtn, VM.PartnerImprintBtn };
  29. ShowUI(int.Parse(intent.ToString()));
  30. }
  31. protected override void OnDisable()
  32. {
  33. RemoveUIListenres();
  34. RemoveUIListenres();
  35. }
  36. #region UI事件
  37. private void AddUIListenres()
  38. {
  39. VM.CancelBtn.onClick.Add(OnClickCancelBtn);
  40. VM.SureBtn.onClick.Add(OnClickSureBtn);
  41. VM.AttackImprintBtn.onClick.Add(OnClickAttackImprintBtn);
  42. VM.SkillImprintBtn.onClick.Add(OnClickSkillImprintBtn);
  43. VM.PartnerImprintBtn.onClick.Add(OnClickPartnerImprintBtn);
  44. }
  45. private void RemoveUIListenres()
  46. {
  47. VM.CancelBtn.onClick.Remove(OnClickCancelBtn);
  48. VM.SureBtn.onClick.Remove(OnClickSureBtn);
  49. VM.AttackImprintBtn.onClick.Remove(OnClickAttackImprintBtn);
  50. VM.SkillImprintBtn.onClick.Remove(OnClickSkillImprintBtn);
  51. VM.PartnerImprintBtn.onClick.Remove(OnClickPartnerImprintBtn);
  52. }
  53. private void OnClickCancelBtn(EventContext context)
  54. {
  55. Context.ClosePanel();
  56. }
  57. private void OnClickSureBtn(EventContext context)
  58. {
  59. PlayerService.Instance.SendToChangeRuneType(PlayerData.Instance.CurPlanIndex, _slotId, _runeType);
  60. Context.ClosePanel();
  61. }
  62. private void OnClickAttackImprintBtn(EventContext context)
  63. {
  64. _runeType = _runeTableInfo.Handoff[0];
  65. ShowSelectUI(0);
  66. }
  67. private void OnClickSkillImprintBtn(EventContext context)
  68. {
  69. _runeType = _runeTableInfo.Handoff[1];
  70. ShowSelectUI(1);
  71. }
  72. private void OnClickPartnerImprintBtn(EventContext context)
  73. {
  74. _runeType = _runeTableInfo.Handoff[2];
  75. ShowSelectUI(2);
  76. }
  77. #endregion
  78. /// <summary>
  79. /// 显示可选择替换的符文UI
  80. /// </summary>
  81. /// <param name="imprintIndex"></param>
  82. private void ShowUI(int imprintIndex)
  83. {
  84. _slotId = imprintIndex + 1;
  85. _runeTableInfo = runeTableRepo.Get(_slotId);
  86. if (_runeTableInfo != null)
  87. {
  88. int count = _runeTableInfo.Name.Length;
  89. for (int i = 0; i < _btnsArray.Length; i++)
  90. {
  91. if (i < count)
  92. {
  93. _btnsArray[i].visible = true;
  94. _btnsArray[i].title = _runeTableInfo.Name[i];
  95. }
  96. else
  97. {
  98. _btnsArray[i].visible = false;
  99. }
  100. }
  101. }
  102. OnClickAttackImprintBtn(null);
  103. }
  104. private void ShowSelectUI(int index)
  105. {
  106. for (int i = 0; i < _btnsArray.Length; i++)
  107. {
  108. _btnsArray[i].GetController("SelectCtrl").selectedIndex = i == index ? 1 : 0;
  109. }
  110. }
  111. }
  112. }