SentimentInfoPanel.cs 11 KB

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