SentimentInfoPanel.cs 11 KB

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