SentimentInfoPanel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 EnergyWidget energyWidget;
  16. private AccountFileInfo.SentimentData sentimentData;
  17. List<SentimentEffectWidget> sentimentEffectWidgets = new List<SentimentEffectWidget>();
  18. private List<SentimentEffectConfig> _sentimentEffectConfigs;
  19. private List<SentimentEffectConfig> currentGroupSentimentEffectConfigs;
  20. public SentimentEffectWidget mainSentimentEffectWidget;
  21. private SentimentEffectWidget currentSentimentEffectWidget;
  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. if (PlayerManager.Instance.BagController.DeductItem(sentimentEffectConfig.upConstItemId, sentimentEffectConfig.upConstCount))
  79. {
  80. TipMessagePanel.OpenTipMessagePanel("道具不足");
  81. return;
  82. }
  83. //扣除道具
  84. // sentimentEffectConfig.upConstItemId.
  85. // s
  86. curretnSentimentProperty.level++;
  87. AccountFileInfo.Instance.SavePlayerData();
  88. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  89. {
  90. sentimentEffectWidget.UpdateXian();
  91. }
  92. UpdateUi();
  93. currentSentimentEffectWidget.CustomInit(curretnSentimentProperty);
  94. });
  95. }
  96. public int MapNumber(int input)
  97. {
  98. if (input >= 1 && input <= 3)
  99. {
  100. return 0;
  101. }
  102. else if (input >= 4 && input <= 6)
  103. {
  104. return 1;
  105. }
  106. else if (input >= 7 && input <= 9)
  107. {
  108. return 2;
  109. }
  110. else
  111. {
  112. return -1;
  113. }
  114. }
  115. public async override CTask<bool> AsyncInit(object[] uiData)
  116. {
  117. sentimentData = uiData[0] as AccountFileInfo.SentimentData;
  118. _sentimentEffectConfigs = ConfigComponent.Instance.GetAll<SentimentEffectConfig>().ToList();
  119. mainSentimentEffectWidget = await UIManager.Instance.CreateGComponentForObject<SentimentEffectWidget>(MainSentimentEffectWidget, null);
  120. mainSentimentEffectWidget.CustomInit(sentimentData.mainSentiment);
  121. mainSentimentEffectWidget.OnClick = OnClick;
  122. int level1 = sentimentData.sentimentProperties[0].level <= 0 ? 1 : sentimentData.sentimentProperties[0].level;
  123. int conFigId1 = sentimentData.sentimentProperties[0].groupId * 10 + level1;
  124. var sentimentEffectConfig1 = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId1);
  125. energyWidget =
  126. await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  127. energyWidget.CustomInit(sentimentEffectConfig1.upConstItemId);
  128. foreach (var sentimentDataSentimentProperty in sentimentData.sentimentProperties)
  129. {
  130. int level = sentimentDataSentimentProperty.level <= 0 ? 1 : sentimentDataSentimentProperty.level;
  131. int conFigId = sentimentDataSentimentProperty.groupId * 10 + level;
  132. var sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  133. int index = MapNumber(sentimentEffectConfig.pos);
  134. SentimentEffectWidget sentimentEffectWidget1 = await UIManager.Instance.CreateGComponent<SentimentEffectWidget>(null, Root[index]);
  135. sentimentEffectWidget1.CustomInit(sentimentDataSentimentProperty);
  136. sentimentEffectWidget1.OnClick = OnClick;
  137. sentimentEffectWidgets.Add(sentimentEffectWidget1);
  138. if (currentSentimentEffectWidget == null)
  139. {
  140. sentimentEffectWidget1.OnPointerClick();
  141. }
  142. }
  143. foreach (var rectTransform in Root)
  144. {
  145. LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
  146. }
  147. return await base.AsyncInit(uiData);
  148. }
  149. public async override CTask Show()
  150. {
  151. await base.Show();
  152. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  153. {
  154. int level = sentimentEffectWidget.sentimentProperty.level <= 0 ? 1 : sentimentEffectWidget.sentimentProperty.level;
  155. int conFigId = sentimentEffectWidget.sentimentProperty.groupId * 10 + level;
  156. var sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  157. SentimentEffectWidget sentimentEffectWidget1 = null;
  158. if (sentimentEffectConfig.lastSentimentEffectId == -1)
  159. {
  160. sentimentEffectWidget1 = mainSentimentEffectWidget;
  161. }
  162. else
  163. {
  164. sentimentEffectWidget1 = sentimentEffectWidgets.FirstOrDefault(s => s.sentimentEffectConfig.groupId == sentimentEffectConfig.lastSentimentEffectId);
  165. }
  166. sentimentEffectWidget.CreatXian(XianRoot, sentimentEffectWidget1);
  167. }
  168. }
  169. private async void UpdateUi()
  170. {
  171. int level = curretnSentimentProperty.level <= 0 ? 1 : curretnSentimentProperty.level;
  172. int conFigId = curretnSentimentProperty.groupId * 10 + level;
  173. SentimentEffectConfig sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  174. currentGroupSentimentEffectConfigs = _sentimentEffectConfigs.Where(se => se.groupId == sentimentEffectConfig.groupId).ToList();
  175. Text_Name.text = LanguageManager.Instance.Text(sentimentEffectConfig.name);
  176. Text_Desc.text = UtilTools.GetString(LanguageManager.Instance.Text(sentimentEffectConfig.massge), sentimentEffectConfig.effectVale);
  177. UIManager.Instance.DormancyGComponent(_itemWidgetType1);
  178. _itemWidgetType1 = null;
  179. _itemWidgetType1 = await UIManager.Instance.CreateGComponentForObject<ItemWidgetType1>(ItemWidgetType1Gam, null);
  180. _itemWidgetType1.CustomInit(sentimentEffectConfig.upConstItemId, sentimentEffectConfig.upConstCount);
  181. if (curretnSentimentProperty.level >= currentGroupSentimentEffectConfigs.Count)
  182. {
  183. Text_Level.text = $"{curretnSentimentProperty.level}级 ——> MAX级";
  184. }
  185. else
  186. {
  187. Text_Level.text = $"{curretnSentimentProperty.level}级 ——> {curretnSentimentProperty.level + 1}级";
  188. }
  189. }
  190. private void OnClick(ItemWidgetBasic obj)
  191. {
  192. SentimentEffectWidget sentimentEffectWidget = obj as SentimentEffectWidget;
  193. currentSentimentEffectWidget = sentimentEffectWidget;
  194. curretnSentimentProperty = sentimentEffectWidget.sentimentProperty;
  195. UpdateUi();
  196. }
  197. public static async CTask OpenPanel(AccountFileInfo.SentimentData sentimentData)
  198. {
  199. await UIManager.Instance.LoadAndOpenPanel<SentimentInfoPanel>(null, uiData: new object[] { sentimentData });
  200. }
  201. public override void Close()
  202. {
  203. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  204. {
  205. UIManager.Instance.DormancyGComponent(sentimentEffectWidget);
  206. }
  207. sentimentEffectWidgets.Clear();
  208. currentSentimentEffectWidget = null;
  209. curretnSentimentProperty = null;
  210. UIManager.Instance.DormancyGComponent(energyWidget);
  211. energyWidget = null;
  212. base.Close();
  213. }
  214. }
  215. }