DivineSenceInfoPanel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Core.Audio;
  5. using Core.Language;
  6. using Excel2Json;
  7. using Fort23.Core;
  8. using Fort23.UTool;
  9. using GameLogic.Bag;
  10. using UnityEngine;
  11. using Utility;
  12. namespace Fort23.Mono
  13. {
  14. [UIBinding(prefab = "DivineSenceInfoPanel")]
  15. public partial class DivineSenceInfoPanel : UIPanel
  16. {
  17. private Action<int, List<ItemInfo>> callback;
  18. private int useCount = 0;
  19. List<ItemInfo> useItems = new List<ItemInfo>();
  20. List<DivineSenceInfoBtnWidget> _divineSenceInfoBtnWidgets = new List<DivineSenceInfoBtnWidget>();
  21. private int maxCount;
  22. private DivineSenseConfig divineSenseConfig;
  23. private void Init()
  24. {
  25. isAddStack = true;
  26. }
  27. public override CTask GetFocus()
  28. {
  29. AppBarPanel.OpenPanel(this);
  30. TitlePanel.ClosePanel();
  31. CustomInit(callback);
  32. return base.GetFocus();
  33. }
  34. public override CTask LoseFocus()
  35. {
  36. return base.LoseFocus();
  37. }
  38. protected override void AddEvent()
  39. {
  40. }
  41. protected override void DelEvent()
  42. {
  43. }
  44. public override void AddButtonEvent()
  45. {
  46. Btn_Ok.onClick.AddListener(async () =>
  47. {
  48. if (EventSystemManager.Instance.GetShenShiCount() >=
  49. divineSenseConfig.MaxNum)
  50. {
  51. TipMessagePanel.OpenTipMessagePanel(10335);
  52. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  53. return;
  54. }
  55. // if (useCount == 0)
  56. // {
  57. // // DivineSenceRestoredPanel divineSenceRestoredPanel = await DivineSenceRestoredPanel.OpenPanel();
  58. // // await divineSenceRestoredPanel.UIClosed();
  59. // // CustomInit(callback);
  60. // return;
  61. // }
  62. if (AccountFileInfo.Instance.playerData.divineSensePoint <
  63. PlayerManager.Instance.gameConstantConfig.DetectEventCount)
  64. {
  65. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  66. DivineSenceRestoredPanel divineSenceRestoredPanel = await DivineSenceRestoredPanel.OpenPanel();
  67. await divineSenceRestoredPanel.UIClosed();
  68. CustomInit(callback);
  69. return;
  70. }
  71. useItems.Clear();
  72. foreach (var senceInfoBtnWidget in _divineSenceInfoBtnWidgets)
  73. {
  74. if (senceInfoBtnWidget.type == 2 && senceInfoBtnWidget.ItemInfo != null)
  75. {
  76. useItems.Add(senceInfoBtnWidget.ItemInfo);
  77. }
  78. }
  79. callback?.Invoke(useCount, useItems);
  80. GObjectPoolInterface.SetActive(false);
  81. // UIManager.Instance.HideUIUIPanel(this);
  82. });
  83. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  84. Slider_Count.onValueChanged.AddListener((c) => { Slider_Count_OnValueChanged(c); });
  85. Btn_Tip.onClick.AddListener(() => { DivineSenceLevelPreviewPanel.OpenPanel(); });
  86. Btn_Event.onClick.AddListener(async () =>
  87. {
  88. await DivineSenceEventPreviewPanel.OpenPanel();
  89. GObjectPoolInterface.SetActive(false);
  90. // UIManager.Instance.HideUIUIPanel(this, isBreadcrumbBarPanel: false);
  91. });
  92. }
  93. private void Slider_Count_OnValueChanged(float value)
  94. {
  95. useCount = (int)value;
  96. Text_Count.text = LanguageManager.Instance.Text(10253, value);
  97. // Text_shenshishangxian.text = $"({EventSystemManager.Instance.GetShenShiCount()}<color=green>+{value}</color>/{maxCount})";
  98. Text_shenshishangxian.text = $"({EventSystemManager.Instance.GetShenShiCount()}/{maxCount})";
  99. foreach (var senceInfoBtnWidget in _divineSenceInfoBtnWidgets)
  100. {
  101. senceInfoBtnWidget.UpdateItermCount(useCount);
  102. }
  103. }
  104. public async void CustomInit(Action<int, List<ItemInfo>> callback)
  105. {
  106. if (PlayerGuideManager.Instance.GuideIsCanDo(2, 1))
  107. {
  108. PlayerGuideManager.Instance.NextGuide();
  109. }
  110. // if (PlayerGuideManager.Instance.GuideIsCanDo(3, 1))
  111. // {
  112. // PlayerGuideManager.Instance.NextGuide();
  113. // }
  114. _divineSenceInfoBtnWidgets.Clear();
  115. divineSenseConfig =
  116. ConfigComponent.Instance.Get<DivineSenseConfig>(AccountFileInfo.Instance.playerData.divineSenseLevel);
  117. HeroPowerUpConfig heroPowerUpConfig = PlayerManager.Instance.myHero.powerUpConfig;
  118. Text_Level.text =
  119. LanguageManager.Instance.Text(10251, AccountFileInfo.Instance.playerData.divineSenseLevel);
  120. Text_Exp.text = $"{AccountFileInfo.Instance.playerData.divineSenseexp}/{divineSenseConfig.exp}";
  121. Slider_Exp.maxValue = divineSenseConfig.exp;
  122. Slider_Exp.value = AccountFileInfo.Instance.playerData.divineSenseexp;
  123. int count = (int)(AccountFileInfo.Instance.playerData.divineSensePoint /
  124. PlayerManager.Instance.gameConstantConfig.DetectEventCount);
  125. maxCount = heroPowerUpConfig.ShenshiMax / PlayerManager.Instance.gameConstantConfig.DetectEventCount;
  126. maxCount = maxCount > divineSenseConfig.MaxNum ? divineSenseConfig.MaxNum : maxCount;
  127. count = count + EventSystemManager.Instance.GetShenShiCount() > maxCount
  128. ? maxCount - EventSystemManager.Instance.GetShenShiCount()
  129. : count;
  130. int mincount = count > 2 ? 2 : count;
  131. if (count == 1 || count == 0)
  132. {
  133. Slider_Count.minValue = 0;
  134. Slider_Count.maxValue = count;
  135. Slider_Count.value = mincount;
  136. Slider_Count.interactable = false;
  137. }
  138. else
  139. {
  140. Slider_Count.minValue = 1;
  141. Slider_Count.maxValue = count;
  142. Slider_Count.value = mincount;
  143. Slider_Count.interactable = true;
  144. }
  145. Slider_Count_OnValueChanged(mincount);
  146. List<float> probabilities = UtilTools.CalculateProbabilities(divineSenseConfig.QualityBonusChance.ToList());
  147. for (var i = 0; i < Text_qs.Count; i++)
  148. {
  149. Text_qs[i].text = $"{probabilities[i] * 100:F1}%";
  150. }
  151. DivineSenceInfoBtnWidget divineSenceInfoBtnWidget =
  152. await UIManager.Instance.CreateGComponentForObject<DivineSenceInfoBtnWidget>(
  153. DivineSenceInfoBtnWidgetGam0, null);
  154. divineSenceInfoBtnWidget.CustomInit(-1, 1);
  155. divineSenceInfoBtnWidget.OnClick = OnClick;
  156. _divineSenceInfoBtnWidgets.Add(divineSenceInfoBtnWidget);
  157. divineSenceInfoBtnWidget =
  158. await UIManager.Instance.CreateGComponentForObject<DivineSenceInfoBtnWidget>(
  159. DivineSenceInfoBtnWidgetGam1, null);
  160. divineSenceInfoBtnWidget.CustomInit(-1, 2);
  161. divineSenceInfoBtnWidget.OnClick = OnClick;
  162. _divineSenceInfoBtnWidgets.Add(divineSenceInfoBtnWidget);
  163. // divineSenceInfoBtnWidget = await UIManager.Instance.CreateGComponentForObject<DivineSenceInfoBtnWidget>(DivineSenceInfoBtnWidgetGam2, null);
  164. // divineSenceInfoBtnWidget.CustomInit(-1, 2);
  165. // divineSenceInfoBtnWidget.OnClick = OnClick;
  166. // _divineSenceInfoBtnWidgets.Add(divineSenceInfoBtnWidget);
  167. this.callback = callback;
  168. }
  169. private async void OnClick(ItemWidgetBasic obj)
  170. {
  171. DivineSenceInfoBtnWidget divineSenceInfoBtnWidget = obj as DivineSenceInfoBtnWidget;
  172. if (divineSenceInfoBtnWidget.type == 1)
  173. {
  174. DivineSenceRestoredPanel divineSenceRestoredPanel = await DivineSenceRestoredPanel.OpenPanel();
  175. await divineSenceRestoredPanel.UIClosed();
  176. CustomInit(callback);
  177. return;
  178. }
  179. List<int> selectType = new List<int>();
  180. foreach (var senceInfoBtnWidget in _divineSenceInfoBtnWidgets)
  181. {
  182. if (senceInfoBtnWidget != divineSenceInfoBtnWidget && senceInfoBtnWidget.type != 1 &&
  183. senceInfoBtnWidget.ItemInfo != null)
  184. {
  185. selectType.Add(senceInfoBtnWidget.ItemInfo.config.associateID);
  186. }
  187. }
  188. DivineSenceItemPanel.OpenPanel(divineSenceInfoBtnWidget.ItemInfo, selectType, (id) =>
  189. {
  190. divineSenceInfoBtnWidget.CustomInit(id, divineSenceInfoBtnWidget.type);
  191. UpdateBl();
  192. },
  193. () =>
  194. {
  195. divineSenceInfoBtnWidget.CustomInit(-1, divineSenceInfoBtnWidget.type);
  196. UpdateBl();
  197. });
  198. }
  199. public void UpdateBl()
  200. {
  201. Map<int, int> probabilitiesMap = new Map<int, int>();
  202. foreach (var senceInfoBtnWidget in _divineSenceInfoBtnWidgets)
  203. {
  204. if (senceInfoBtnWidget.type == 2 && senceInfoBtnWidget.ItemInfo != null &&
  205. senceInfoBtnWidget.ItemInfo.config.associateID == 6)
  206. {
  207. if (!probabilitiesMap.ContainsKey(senceInfoBtnWidget.ItemInfo.config.associateVlaue[0]))
  208. {
  209. probabilitiesMap.Add(senceInfoBtnWidget.ItemInfo.config.associateVlaue[0],
  210. senceInfoBtnWidget.ItemInfo.config.associateVlaue[1]);
  211. }
  212. else
  213. {
  214. probabilitiesMap[senceInfoBtnWidget.ItemInfo.config.associateVlaue[0]] +=
  215. senceInfoBtnWidget.ItemInfo.config.associateVlaue[1];
  216. }
  217. }
  218. senceInfoBtnWidget.UpdateItermCount(useCount);
  219. }
  220. var QualityBonusChance = divineSenseConfig.QualityBonusChance.ToList();
  221. foreach (var keyValuePair in probabilitiesMap)
  222. {
  223. QualityBonusChance[keyValuePair.Key - 1] *= keyValuePair.Value + 0.01f;
  224. }
  225. List<float> probabilities = UtilTools.CalculateProbabilities(QualityBonusChance);
  226. for (var i = 0; i < Text_qs.Count; i++)
  227. {
  228. Text_qs[i].text = $"{probabilities[i] * 100:F2}%";
  229. }
  230. }
  231. public async static CTask OpenPanel(Action<int, List<ItemInfo>> callback)
  232. {
  233. DivineSenceInfoPanel divineSenceInfoPanel =
  234. await UIManager.Instance.LoadAndOpenPanel<DivineSenceInfoPanel>(null, UILayer.Middle);
  235. divineSenceInfoPanel.CustomInit(callback);
  236. }
  237. }
  238. }