HeroDetailPanel.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using Common.Utility.CombatEvent;
  2. using Core.Language;
  3. using Core.Utility;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Bag;
  8. using GameLogic.Hero;
  9. using UnityEngine;
  10. using UnityEngine.UI;
  11. using Utility;
  12. namespace Fort23.Mono
  13. {
  14. [UIBinding(prefab = "HeroDetailPanel" )]
  15. public partial class HeroDetailPanel : UIPanel
  16. {
  17. private HeroInfo heroInfo;
  18. private void Init()
  19. {
  20. // InitHeroDetailPanel();
  21. }
  22. protected override void AddEvent()
  23. {
  24. }
  25. protected override void DelEvent()
  26. {
  27. }
  28. public override void AddButtonEvent()
  29. {
  30. btnBack.onClick.AddListener(OnClickClose);
  31. btnUpgrade.onClick.AddListener(OnClickUpgrade);
  32. btnPromote.onClick.AddListener(OnClickPromote);
  33. }
  34. private void OnClickPromote()
  35. {
  36. if (PlayerManager.Instance.gameConstantConfig.maxStar <= heroInfo.star.Value)
  37. {
  38. LogTool.Log("已到达最高星级:" + PlayerManager.Instance.gameConstantConfig.maxStar);
  39. return;
  40. }
  41. // heroInfo.modelConfig.itemID
  42. if (BagController.Instance.DeductItem(heroInfo.modelConfig.itemID, heroInfo.promoteConfig.costCount))
  43. {
  44. heroInfo.Promote();
  45. UpdateAttributeUI();
  46. HeroUITools.SetStarShow(stars, heroInfo.star.Value);
  47. SendEvent(HeroUpType.Promote);
  48. }
  49. }
  50. private void OnClickUpgrade()
  51. {
  52. if (PlayerManager.Instance.gameConstantConfig.maxLv <= heroInfo.level.Value)
  53. {
  54. LogTool.Log("已到达最高等级:" + PlayerManager.Instance.gameConstantConfig.maxLv);
  55. return;
  56. }
  57. if (BagController.Instance.DuctHeroExp(heroInfo.powerUpConfig.levelUpExp))
  58. {
  59. heroInfo.Upgrade();
  60. UpdateAttributeUI();
  61. SendEvent(HeroUpType.Level);
  62. }
  63. }
  64. /// <summary>
  65. /// 发送英雄提升的事件
  66. /// </summary>
  67. /// <param name="upType">提升类型:升级、升星等.</param>
  68. private void SendEvent(HeroUpType upType)
  69. {
  70. HeroPowerUpEventData data = new HeroPowerUpEventData();
  71. data.heroModelID = heroInfo.modelID;
  72. data.upType = upType;
  73. PlayerManager.Instance.lastHeroInfo = heroInfo;
  74. EventManager.Instance.Dispatch(CustomEventType.HeroPowerUp, data);
  75. if (upType == HeroUpType.Level)
  76. {
  77. EventManager.Instance.Dispatch(CustomEventType.HeroLvUp, data);
  78. }
  79. else if (upType == HeroUpType.Promote)
  80. {
  81. EventManager.Instance.Dispatch(CustomEventType.HeroPromote, data);
  82. }
  83. }
  84. private void OnClickClose()
  85. {
  86. UIManager.Instance.HideUIUIPanel(this);
  87. }
  88. public void InitHeroDetailPanel(HeroInfo heroInfo)
  89. {
  90. this.heroInfo = heroInfo;
  91. iconZhiYe.icon_name = heroInfo.iconZhiYe;
  92. heroName.text = LanguageManager.Instance.Text(heroInfo.modelConfig.name);
  93. HeroUITools.SetStarShow(stars, heroInfo.star.Value);
  94. switch (heroInfo.modelConfig.rarity)
  95. {
  96. case 1:
  97. heroRarity.text = LanguageManager.Instance.Text(32);
  98. break;
  99. case 2:
  100. heroRarity.text = LanguageManager.Instance.Text(31);
  101. break;
  102. case 3:
  103. heroRarity.text = LanguageManager.Instance.Text(30);
  104. break;
  105. default:
  106. LogTool.Error("找不到hero的稀有度:" + heroInfo.modelConfig.ID);
  107. break;
  108. }
  109. UpdateAttributeUI();
  110. }
  111. public void UpdateAttributeUI()
  112. {
  113. txtHP.text = heroInfo.hp.Value.ToStringEx();
  114. txtATK.text = heroInfo.attack.Value.ToStringEx();
  115. txtDEF.text = heroInfo.defense.Value.ToStringEx();
  116. txtSHANBI.text = heroInfo.shanbi.Value.ToStringEx();
  117. txtLv.text = heroInfo.level.Value.ToStringEx();
  118. txtExpGain.text = heroInfo.expGain.Value.ToStringEx();
  119. string redColorStar = "";
  120. string redColorEnd = "";
  121. long curExp = BagController.Instance.GetItemInfo(GlobalParam.Item_HeroExp_ID).count.Value;
  122. long costExp = heroInfo.powerUpConfig.levelUpExp;
  123. if (costExp > curExp)
  124. {
  125. redColorStar = "<color=#FF4C4C>";
  126. redColorEnd = "</color>";
  127. }
  128. else
  129. {
  130. redColorStar = "";
  131. redColorEnd = "";
  132. }
  133. txtUpgrade.text = redColorStar + curExp + redColorEnd + "/" + costExp;
  134. long curHeroCount = BagController.Instance.GetItemInfo(heroInfo.modelConfig.itemID).count.Value;
  135. long costHeroCount = heroInfo.promoteConfig.costCount;
  136. if (costHeroCount > curHeroCount)
  137. {
  138. redColorStar = "<color=#FF4C4C>";
  139. redColorEnd = "</color>";
  140. }
  141. else
  142. {
  143. redColorStar = "";
  144. redColorEnd = "";
  145. }
  146. txtPromote.text = redColorStar + curHeroCount + redColorEnd + "/" + costHeroCount;
  147. }
  148. }
  149. }