SentimentInfoPanel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Core.Audio;
  4. using Core.Language;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using Utility;
  11. namespace Fort23.Mono
  12. {
  13. [UIBinding(prefab = "SentimentInfoPanel")]
  14. public partial class SentimentInfoPanel : UIPanel
  15. {
  16. AccountFileInfo.SentimentProperty curretnSentimentProperty;
  17. // private EnergyWidget energyWidget;
  18. private AccountFileInfo.SentimentData sentimentData;
  19. List<SentimentEffectWidget> sentimentEffectWidgets = new List<SentimentEffectWidget>();
  20. private List<SentimentEffectConfig> _sentimentEffectConfigs;
  21. private List<SentimentEffectConfig> currentGroupSentimentEffectConfigs;
  22. public SentimentEffectWidget mainSentimentEffectWidget;
  23. private SentimentEffectWidget currentSentimentEffectWidget;
  24. private ItemWidgetType1 _itemWidgetType1;
  25. TitlePanel _titlePanel;
  26. private void Init()
  27. {
  28. isAddStack = true;
  29. }
  30. public async override CTask GetFocus()
  31. {
  32. AppBarPanel.OpenPanel(this);
  33. await base.GetFocus();
  34. }
  35. protected override void AddEvent()
  36. {
  37. }
  38. protected override void DelEvent()
  39. {
  40. }
  41. public override void AddButtonEvent()
  42. {
  43. Btn_Rest.onClick.AddListener(() =>
  44. {
  45. foreach (var sentimentDataSentimentProperty in sentimentData.sentimentProperties)
  46. {
  47. int count = 0;
  48. int itemid = 0;
  49. for (int i = 0; i < sentimentDataSentimentProperty.level; i++)
  50. {
  51. int level1 = sentimentData.sentimentProperties[0].level <= 0
  52. ? 1
  53. : sentimentData.sentimentProperties[0].level;
  54. int conFigId1 = sentimentData.sentimentProperties[0].groupId * 10 + level1;
  55. var sentimentEffectConfig1 = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId1);
  56. itemid = sentimentEffectConfig1.upConstItemId;
  57. count += sentimentEffectConfig1.upConstCount;
  58. }
  59. PlayerManager.Instance.BagController.AddItem(itemid, count);
  60. sentimentDataSentimentProperty.level = 0;
  61. }
  62. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  63. {
  64. sentimentEffectWidget.CustomInit(sentimentEffectWidget.sentimentProperty);
  65. }
  66. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  67. {
  68. sentimentEffectWidget.UpdateXian();
  69. }
  70. UpdateRestBtn();
  71. PlayerManager.Instance.myHero.ComputeHeroInfo();
  72. AccountFileInfo.Instance.SavePlayerData();
  73. });
  74. Btn_LingWu.onClick.AddListener(() =>
  75. {
  76. if (curretnSentimentProperty == null)
  77. {
  78. return;
  79. }
  80. if (currentSentimentEffectWidget.lastSentimentWidget != null &&
  81. currentSentimentEffectWidget.lastSentimentWidget.sentimentProperty.level <
  82. currentSentimentEffectWidget.sentimentEffectConfig.unlockLevel)
  83. {
  84. TipMessagePanel.OpenTipMessagePanel("前置节点没有解锁");
  85. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  86. return;
  87. }
  88. if (curretnSentimentProperty.level >= currentGroupSentimentEffectConfigs.Count)
  89. {
  90. TipMessagePanel.OpenTipMessagePanel("已经达到最大等级");
  91. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  92. return;
  93. }
  94. int level = curretnSentimentProperty.level <= 0 ? 1 : curretnSentimentProperty.level;
  95. int conFigId = curretnSentimentProperty.groupId * 10 + level;
  96. SentimentEffectConfig sentimentEffectConfig =
  97. ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  98. //TODO 消耗:心境点
  99. if (!PlayerManager.Instance.BagController.DeductItem(sentimentEffectConfig.upConstItemId,
  100. sentimentEffectConfig.upConstCount))
  101. {
  102. if (sentimentEffectConfig.upConstItemId == 22001)
  103. {
  104. string tips = LanguageManager.Instance.Text(10824, LanguageManager.Instance.Text(10825));
  105. TipMessagePanel.OpenTipMessagePanel(tips);
  106. }
  107. else
  108. {
  109. ItemSourcePanel.OpenPanel(sentimentEffectConfig.upConstItemId);
  110. }
  111. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  112. return;
  113. }
  114. AudioManager.Instance.PlayAudio("ui_tycg.wav");
  115. curretnSentimentProperty.level++;
  116. AccountFileInfo.Instance.SavePlayerData();
  117. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  118. {
  119. sentimentEffectWidget.UpdateXian();
  120. }
  121. UpdateRestBtn();
  122. UpdateUi();
  123. PlayerManager.Instance.myHero.ComputeHeroInfo();
  124. currentSentimentEffectWidget.CustomInit(curretnSentimentProperty);
  125. });
  126. }
  127. public int MapNumber(int input)
  128. {
  129. if (input >= 1 && input <= 3)
  130. {
  131. return 0;
  132. }
  133. else if (input >= 4 && input <= 6)
  134. {
  135. return 1;
  136. }
  137. else if (input >= 7 && input <= 9)
  138. {
  139. return 2;
  140. }
  141. else
  142. {
  143. return -1;
  144. }
  145. }
  146. public async override CTask<bool> AsyncInit(object[] uiData)
  147. {
  148. sentimentData = uiData[0] as AccountFileInfo.SentimentData;
  149. _sentimentEffectConfigs = ConfigComponent.Instance.GetAll<SentimentEffectConfig>().ToList();
  150. mainSentimentEffectWidget =
  151. await UIManager.Instance.CreateGComponentForObject<SentimentEffectWidget>(MainSentimentEffectWidget,
  152. null);
  153. mainSentimentEffectWidget.CustomInit(sentimentData.mainSentiment);
  154. mainSentimentEffectWidget.OnClick = OnClick;
  155. int level1 = sentimentData.sentimentProperties[0].level <= 0
  156. ? 1
  157. : sentimentData.sentimentProperties[0].level;
  158. int conFigId1 = sentimentData.sentimentProperties[0].groupId * 10 + level1;
  159. var sentimentEffectConfig1 = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId1);
  160. if (_titlePanel == null)
  161. {
  162. _titlePanel = await TitlePanel.OpenPanel(new List<int>() { sentimentEffectConfig1.upConstItemId });
  163. }
  164. else
  165. {
  166. _titlePanel.CustomInit(new List<int>() { sentimentEffectConfig1.upConstItemId });
  167. }
  168. return await base.AsyncInit(uiData);
  169. }
  170. public async override CTask Show()
  171. {
  172. await base.Show();
  173. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  174. {
  175. UIManager.Instance.DormancyGComponent(sentimentEffectWidget);
  176. }
  177. sentimentEffectWidgets.Clear();
  178. foreach (var sentimentDataSentimentProperty in sentimentData.sentimentProperties)
  179. {
  180. int level = sentimentDataSentimentProperty.level <= 0 ? 1 : sentimentDataSentimentProperty.level;
  181. int conFigId = sentimentDataSentimentProperty.groupId * 10 + level;
  182. var sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  183. int index = MapNumber(sentimentEffectConfig.pos);
  184. SentimentEffectWidget sentimentEffectWidget1 =
  185. await UIManager.Instance.CreateGComponent<SentimentEffectWidget>(null, Root[index]);
  186. sentimentEffectWidget1.CustomInit(sentimentDataSentimentProperty);
  187. sentimentEffectWidget1.OnClick = OnClick;
  188. sentimentEffectWidgets.Add(sentimentEffectWidget1);
  189. if (currentSentimentEffectWidget == null)
  190. {
  191. sentimentEffectWidget1.OnPointerClick();
  192. }
  193. }
  194. UpdateRestBtn();
  195. foreach (var rectTransform in Root)
  196. {
  197. LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
  198. }
  199. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  200. {
  201. int level = sentimentEffectWidget.sentimentProperty.level <= 0
  202. ? 1
  203. : sentimentEffectWidget.sentimentProperty.level;
  204. int conFigId = sentimentEffectWidget.sentimentProperty.groupId * 10 + level;
  205. var sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  206. SentimentEffectWidget sentimentEffectWidget1 = null;
  207. if (sentimentEffectConfig.lastSentimentEffectId ==
  208. mainSentimentEffectWidget.sentimentEffectConfig.groupId)
  209. {
  210. sentimentEffectWidget1 = mainSentimentEffectWidget;
  211. }
  212. else
  213. {
  214. sentimentEffectWidget1 = sentimentEffectWidgets.FirstOrDefault(s =>
  215. s.sentimentEffectConfig.groupId == sentimentEffectConfig.lastSentimentEffectId);
  216. }
  217. if (sentimentEffectWidget1 != null)
  218. {
  219. sentimentEffectWidget.CreatXian(XianRoot, sentimentEffectWidget1);
  220. }
  221. }
  222. }
  223. private void UpdateRestBtn()
  224. {
  225. bool isCanRest = false;
  226. foreach (var sentimentDataSentimentProperty in sentimentData.sentimentProperties)
  227. {
  228. if (sentimentDataSentimentProperty.level >= 1)
  229. {
  230. isCanRest = true;
  231. }
  232. }
  233. Btn_Rest.gameObject.SetActive(isCanRest);
  234. }
  235. private async void UpdateUi()
  236. {
  237. int level = curretnSentimentProperty.level <= 0 ? 1 : curretnSentimentProperty.level;
  238. int conFigId = curretnSentimentProperty.groupId * 10 + level;
  239. SentimentEffectConfig sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  240. currentGroupSentimentEffectConfigs = _sentimentEffectConfigs
  241. .Where(se => se.groupId == sentimentEffectConfig.groupId).ToList();
  242. Text_Name.text = LanguageManager.Instance.Text(sentimentEffectConfig.name);
  243. Text_Desc.text = UtilTools.GetString(LanguageManager.Instance.Text(sentimentEffectConfig.massge),
  244. sentimentEffectConfig.effectVale);
  245. UIManager.Instance.DormancyGComponent(_itemWidgetType1);
  246. _itemWidgetType1 = null;
  247. _itemWidgetType1 =
  248. await UIManager.Instance.CreateGComponentForObject<ItemWidgetType1>(ItemWidgetType1Gam, null);
  249. _itemWidgetType1.CustomInit(sentimentEffectConfig.upConstItemId, sentimentEffectConfig.upConstCount);
  250. if (curretnSentimentProperty.level >= currentGroupSentimentEffectConfigs.Count)
  251. {
  252. Text_CurrentLevel.text = $"{curretnSentimentProperty.level}级 ";
  253. Text_NextLevel.text = $"MAX级";
  254. }
  255. else
  256. {
  257. Text_CurrentLevel.text = $"{curretnSentimentProperty.level}级 ";
  258. Text_NextLevel.text = $"{curretnSentimentProperty.level + 1}级";
  259. }
  260. }
  261. private void OnClick(ItemWidgetBasic obj)
  262. {
  263. SentimentEffectWidget sentimentEffectWidget = obj as SentimentEffectWidget;
  264. currentSentimentEffectWidget = sentimentEffectWidget;
  265. curretnSentimentProperty = sentimentEffectWidget.sentimentProperty;
  266. Text_EffectName.text = LanguageManager.Instance.Text(sentimentEffectWidget.sentimentEffectConfig.name);
  267. xuanzhong.transform.SetParent(sentimentEffectWidget.xuanzhongroot);
  268. xuanzhong.transform.localPosition = Vector3.zero;
  269. xuanzhong.transform.localScale = Vector3.one;
  270. xuanzhong.gameObject.SetActive(true);
  271. UpdateUi();
  272. }
  273. public static async CTask OpenPanel(AccountFileInfo.SentimentData sentimentData)
  274. {
  275. await UIManager.Instance.LoadAndOpenPanel<SentimentInfoPanel>(null, uiData: new object[] { sentimentData });
  276. }
  277. public async override CTask Close()
  278. {
  279. foreach (var sentimentEffectWidget in sentimentEffectWidgets)
  280. {
  281. UIManager.Instance.DormancyGComponent(sentimentEffectWidget);
  282. }
  283. sentimentEffectWidgets.Clear();
  284. currentSentimentEffectWidget = null;
  285. curretnSentimentProperty = null;
  286. // UIManager.Instance.DormancyGComponent(energyWidget);
  287. // energyWidget = null;
  288. xuanzhong.transform.SetParent(transform);
  289. // xuanzhong.transform.localPosition = Vector3.zero;
  290. xuanzhong.gameObject.SetActive(false);
  291. await base.Close();
  292. }
  293. }
  294. }