SentimentInfoPanel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Core.Language;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using UnityEngine.UI;
  8. using Utility;
  9. namespace Fort23.Mono
  10. {
  11. [UIBinding(prefab = "SentimentInfoPanel")]
  12. public partial class SentimentInfoPanel : UIPanel
  13. {
  14. AccountFileInfo.SentimentProperty curretnSentimentProperty;
  15. private AccountFileInfo.SentimentData sentimentData;
  16. List<SentimentEffectWidget> sentimentEffectWidgets = new List<SentimentEffectWidget>();
  17. private List<SentimentEffectConfig> _sentimentEffectConfigs;
  18. private List<SentimentEffectConfig> currentGroupSentimentEffectConfigs;
  19. public SentimentEffectWidget mainSentimentEffectWidget;
  20. private SentimentEffectWidget currentSentimentEffectWidget;
  21. private EnergyWidget energyWidget;
  22. private ItemWidgetType1 _itemWidgetType1;
  23. private void Init()
  24. {
  25. isAddStack = false;
  26. isPopUi = true;
  27. IsShowAppBar = false;
  28. }
  29. protected override void AddEvent()
  30. {
  31. }
  32. protected override void DelEvent()
  33. {
  34. }
  35. public override void AddButtonEvent()
  36. {
  37. Btn_Rest.onClick.AddListener(() =>
  38. {
  39. foreach (var sentimentDataSentimentProperty in sentimentData.sentimentProperties)
  40. {
  41. int count = 0;
  42. for (int i = 0; i < sentimentDataSentimentProperty.level; i++)
  43. {
  44. int level1 = sentimentData.sentimentProperties[0].level <= 0 ? 1 : sentimentData.sentimentProperties[0].level;
  45. int conFigId1 = sentimentData.sentimentProperties[0].groupId * 10 + level1;
  46. var sentimentEffectConfig1 = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId1);
  47. count += sentimentEffectConfig1.upConstCount;
  48. }
  49. PlayerManager.Instance.BagController.AddItem(energyWidget._itemConfig.ID, count);
  50. sentimentDataSentimentProperty.level = 0;
  51. }
  52. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  53. {
  54. sentimentEffectWidget.CustomInit(sentimentEffectWidget.sentimentProperty);
  55. }
  56. AccountFileInfo.Instance.SavePlayerData();
  57. });
  58. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  59. Btn_LingWu.onClick.AddListener(() =>
  60. {
  61. if (curretnSentimentProperty == null)
  62. {
  63. return;
  64. }
  65. if (currentSentimentEffectWidget.lastSentimentWidget.sentimentProperty.level < currentSentimentEffectWidget.sentimentEffectConfig.unlockLevel)
  66. {
  67. TipMessagePanel.OpenTipMessagePanel("前置节点没有解锁");
  68. return;
  69. }
  70. if (curretnSentimentProperty.level >= currentGroupSentimentEffectConfigs.Count)
  71. {
  72. TipMessagePanel.OpenTipMessagePanel("已经达到最大等级");
  73. return;
  74. }
  75. int level = curretnSentimentProperty.level <= 0 ? 1 : curretnSentimentProperty.level;
  76. int conFigId = curretnSentimentProperty.groupId * 100 + level + 1;
  77. SentimentEffectConfig sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  78. PlayerManager.Instance.BagController.DeductItem(sentimentEffectConfig.upConstItemId, sentimentEffectConfig.upConstCount);
  79. //扣除道具
  80. // sentimentEffectConfig.upConstItemId.
  81. // s
  82. curretnSentimentProperty.level++;
  83. AccountFileInfo.Instance.SavePlayerData();
  84. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  85. {
  86. sentimentEffectWidget.UpdateXian();
  87. }
  88. UpdateUi();
  89. currentSentimentEffectWidget.CustomInit(curretnSentimentProperty);
  90. });
  91. }
  92. public int MapNumber(int input)
  93. {
  94. if (input >= 1 && input <= 3)
  95. {
  96. return 0;
  97. }
  98. else if (input >= 4 && input <= 6)
  99. {
  100. return 1;
  101. }
  102. else if (input >= 7 && input <= 9)
  103. {
  104. return 2;
  105. }
  106. else
  107. {
  108. return -1;
  109. }
  110. }
  111. public async override CTask<bool> AsyncInit(object[] uiData)
  112. {
  113. sentimentData = uiData[0] as AccountFileInfo.SentimentData;
  114. _sentimentEffectConfigs = ConfigComponent.Instance.GetAll<SentimentEffectConfig>().ToList();
  115. mainSentimentEffectWidget = await UIManager.Instance.CreateGComponentForObject<SentimentEffectWidget>(MainSentimentEffectWidget, null);
  116. mainSentimentEffectWidget.CustomInit(sentimentData.mainSentiment);
  117. mainSentimentEffectWidget.OnClick = OnClick;
  118. int level1 = sentimentData.sentimentProperties[0].level <= 0 ? 1 : sentimentData.sentimentProperties[0].level;
  119. int conFigId1 = sentimentData.sentimentProperties[0].groupId * 10 + level1;
  120. var sentimentEffectConfig1 = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId1);
  121. EnergyWidget energyWidget =
  122. await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  123. energyWidget.CustomInit(sentimentEffectConfig1.upConstItemId);
  124. foreach (var sentimentDataSentimentProperty in sentimentData.sentimentProperties)
  125. {
  126. int level = sentimentDataSentimentProperty.level <= 0 ? 1 : sentimentDataSentimentProperty.level;
  127. int conFigId = sentimentDataSentimentProperty.groupId * 10 + level;
  128. var sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  129. int index = MapNumber(sentimentEffectConfig.pos);
  130. SentimentEffectWidget sentimentEffectWidget1 = await UIManager.Instance.CreateGComponent<SentimentEffectWidget>(null, Root[index]);
  131. sentimentEffectWidget1.CustomInit(sentimentDataSentimentProperty);
  132. sentimentEffectWidget1.OnClick = OnClick;
  133. sentimentEffectWidgets.Add(sentimentEffectWidget1);
  134. if (currentSentimentEffectWidget == null)
  135. {
  136. sentimentEffectWidget1.OnPointerClick();
  137. }
  138. }
  139. foreach (var rectTransform in Root)
  140. {
  141. LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
  142. }
  143. return await base.AsyncInit(uiData);
  144. }
  145. public async override CTask Show()
  146. {
  147. await base.Show();
  148. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  149. {
  150. int level = sentimentEffectWidget.sentimentProperty.level <= 0 ? 1 : sentimentEffectWidget.sentimentProperty.level;
  151. int conFigId = sentimentEffectWidget.sentimentProperty.groupId * 10 + level;
  152. var sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  153. SentimentEffectWidget sentimentEffectWidget1 = null;
  154. if (sentimentEffectConfig.lastSentimentEffectId == -1)
  155. {
  156. sentimentEffectWidget1 = mainSentimentEffectWidget;
  157. }
  158. else
  159. {
  160. sentimentEffectWidget1 = sentimentEffectWidgets.FirstOrDefault(s => s.sentimentEffectConfig.groupId == sentimentEffectConfig.lastSentimentEffectId);
  161. }
  162. sentimentEffectWidget.CreatXian(XianRoot, sentimentEffectWidget1);
  163. }
  164. }
  165. private async void UpdateUi()
  166. {
  167. int level = curretnSentimentProperty.level <= 0 ? 1 : curretnSentimentProperty.level;
  168. int conFigId = curretnSentimentProperty.groupId * 10 + level;
  169. SentimentEffectConfig sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  170. currentGroupSentimentEffectConfigs = _sentimentEffectConfigs.Where(se => se.groupId == sentimentEffectConfig.groupId).ToList();
  171. Text_Name.text = LanguageManager.Instance.Text(sentimentEffectConfig.name);
  172. Text_Desc.text = UtilTools.GetString(LanguageManager.Instance.Text(sentimentEffectConfig.massge), sentimentEffectConfig.effectVale);
  173. UIManager.Instance.DormancyGComponent(_itemWidgetType1);
  174. _itemWidgetType1 = null;
  175. _itemWidgetType1 = await UIManager.Instance.CreateGComponentForObject<ItemWidgetType1>(ItemWidgetType1Gam, null);
  176. _itemWidgetType1.CustomInit(sentimentEffectConfig.upConstItemId, sentimentEffectConfig.upConstCount);
  177. if (curretnSentimentProperty.level >= currentGroupSentimentEffectConfigs.Count)
  178. {
  179. Text_Level.text = $"{curretnSentimentProperty.level}级 ——> MAX级";
  180. }
  181. else
  182. {
  183. Text_Level.text = $"{curretnSentimentProperty.level}级 ——> {curretnSentimentProperty.level + 1}级";
  184. }
  185. }
  186. private void OnClick(ItemWidgetBasic obj)
  187. {
  188. SentimentEffectWidget sentimentEffectWidget = obj as SentimentEffectWidget;
  189. currentSentimentEffectWidget = sentimentEffectWidget;
  190. curretnSentimentProperty = sentimentEffectWidget.sentimentProperty;
  191. UpdateUi();
  192. }
  193. public static async CTask OpenPanel(AccountFileInfo.SentimentData sentimentData)
  194. {
  195. await UIManager.Instance.LoadAndOpenPanel<SentimentInfoPanel>(null, uiData: new object[] { sentimentData });
  196. }
  197. public override void Close()
  198. {
  199. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  200. {
  201. UIManager.Instance.DormancyGComponent(sentimentEffectWidget);
  202. }
  203. sentimentEffectWidgets.Clear();
  204. currentSentimentEffectWidget = null;
  205. curretnSentimentProperty = null;
  206. UIManager.Instance.DormancyGComponent(energyWidget);
  207. energyWidget = null;
  208. base.Close();
  209. }
  210. }
  211. }