DaoYouInfoPanel.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 GameLogic.Bag;
  8. using UnityEngine;
  9. namespace Fort23.Mono
  10. {
  11. [UIBinding(prefab = "DaoYouInfoPanel")]
  12. public partial class DaoYouInfoPanel : UIPanel
  13. {
  14. private AccountFileInfo.DaoYouData daoYouData;
  15. private DaoyouModelConfig _daoyouModelConfig;
  16. List<WidgetItem> widgetItems = new List<WidgetItem>();
  17. List<WidgetItem> giveWidgetItems = new List<WidgetItem>();
  18. List<DaoYouLevelWidget> _daoYouLevelWidgets = new List<DaoYouLevelWidget>();
  19. private DaoyouGiftConfig[] daoyouGiftConfigs;
  20. private void Init()
  21. {
  22. IsShowAppBar = true;
  23. isAddStack = true;
  24. }
  25. protected override void AddEvent()
  26. {
  27. }
  28. protected override void DelEvent()
  29. {
  30. }
  31. public override void AddButtonEvent()
  32. {
  33. Btn_Facorability.onClick.AddListener(() =>
  34. {
  35. Info.SetActive(false);
  36. Facorability.SetActive(true);
  37. });
  38. Btn_InfoMation.onClick.AddListener(() =>
  39. {
  40. Info.SetActive(true);
  41. Facorability.SetActive(false);
  42. });
  43. Btn_SendGift.onClick.AddListener(async () =>
  44. {
  45. AppBarPanel.ClosePanel();
  46. await UpdateGiveGiftRoot();
  47. GiveGite.gameObject.SetActive(true);
  48. });
  49. Btn_Back.onClick.AddListener(() =>
  50. {
  51. ClosePoolGive();
  52. GiveGite.gameObject.SetActive(false);
  53. AppBarPanel.OpenPanel(this);
  54. });
  55. Btn_Add.onClick.AddListener(Add);
  56. Btn_Reduce.onClick.AddListener(Reduce);
  57. Btn_Max.onClick.AddListener(() => { Slider_Give.value = (int)widgetItem1.itemInfo.count.Value; });
  58. Slider_Give.onValueChanged.AddListener((i) =>
  59. {
  60. count = (int)i;
  61. UpdateGiveItemCount();
  62. });
  63. Btn_Give.onClick.AddListener(() =>
  64. {
  65. if (widgetItem1 == null)
  66. {
  67. return;
  68. }
  69. if (daoyouGiftConfig.ID == 0)
  70. return;
  71. PlayerManager.Instance.BagController.DeductItem(daoyouGiftConfig.ItemID, count);
  72. daoYouData.exp += daoyouGiftConfig.emotionValue * count;
  73. DaoyouLevelupConfig[] configs = ConfigComponent.Instance.GetAll<DaoyouLevelupConfig>();
  74. for (var i = daoYouData.favorabilityLv; i < configs.Length; i++)
  75. {
  76. if (daoYouData.exp >= configs[i].exp)
  77. {
  78. daoYouData.exp -= configs[i].exp;
  79. daoYouData.favorabilityLv++;
  80. }
  81. }
  82. AccountFileInfo.Instance.SavePlayerData();
  83. UpdateUI();
  84. UpdateGiveGiftRoot();
  85. });
  86. }
  87. public async override CTask<bool> AsyncInit(object[] uiData)
  88. {
  89. daoYouData = uiData[0] as AccountFileInfo.DaoYouData;
  90. _daoyouModelConfig = ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  91. daoyouGiftConfigs = ConfigComponent.Instance.GetAll<DaoyouGiftConfig>();
  92. await UpdateUI();
  93. return await base.AsyncInit(uiData);
  94. }
  95. public async CTask UpdateUI()
  96. {
  97. foreach (var widgetItem in widgetItems)
  98. {
  99. UIManager.Instance.DormancyGComponent(widgetItem);
  100. }
  101. widgetItems.Clear();
  102. foreach (var daoYouLevelWidget in _daoYouLevelWidgets)
  103. {
  104. UIManager.Instance.DormancyGComponent(daoYouLevelWidget);
  105. }
  106. _daoYouLevelWidgets.Clear();
  107. Text_Name.text = LanguageManager.Instance.Text(_daoyouModelConfig.name);
  108. int index = 0;
  109. for (var i = 0; i < _daoyouModelConfig.desUnlockLv.Length; i++)
  110. {
  111. if (daoYouData.favorabilityLv >= _daoyouModelConfig.desUnlockLv[i])
  112. {
  113. index = i;
  114. }
  115. }
  116. Text_Desc.text = LanguageManager.Instance.Text(_daoyouModelConfig.des[index]);
  117. DaoyouLevelupConfig currentDaoyouLevelupConfig = ConfigComponent.Instance.Get<DaoyouLevelupConfig>(daoYouData.favorabilityLv);
  118. Text_CurrentName.text = LanguageManager.Instance.Text(currentDaoyouLevelupConfig.name);
  119. Text_CurrentLevel.text = daoYouData.favorabilityLv.ToString();
  120. Slider_LeveUp.maxValue = currentDaoyouLevelupConfig.exp;
  121. Text_Exp.text = $"{daoYouData.exp}/{currentDaoyouLevelupConfig.exp}";
  122. Slider_LeveUp.value = daoYouData.exp;
  123. if (_daoyouModelConfig.PreferGiftID != null)
  124. {
  125. foreach (var i in _daoyouModelConfig.PreferGiftID)
  126. {
  127. if (_daoyouModelConfig.shownPreferGiftID.Contains(i) || (daoYouData != null && daoYouData.loveIds.Contains(i)))
  128. {
  129. WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null, LoveItemContent);
  130. widgetItem.InitWidget(new ItemInfo(i, 0));
  131. widgetItems.Add(widgetItem);
  132. }
  133. }
  134. }
  135. DaoyouLevelupConfig[] configs = ConfigComponent.Instance.GetAll<DaoyouLevelupConfig>();
  136. foreach (var daoyouLevelupConfig in configs)
  137. {
  138. DaoYouLevelWidget daoYouLevelWidget = await UIManager.Instance.CreateGComponent<DaoYouLevelWidget>(null, DaoYouLevelWidgetContent);
  139. daoYouLevelWidget.CustomInit(daoYouData, daoyouLevelupConfig.ID);
  140. _daoYouLevelWidgets.Add(daoYouLevelWidget);
  141. }
  142. }
  143. public async CTask UpdateGiveGiftRoot()
  144. {
  145. ClosePoolGive();
  146. foreach (var daoyouGiftConfig in daoyouGiftConfigs)
  147. {
  148. if (PlayerManager.Instance.BagController.GetItemCount(daoyouGiftConfig.ItemID) > 0)
  149. {
  150. ItemInfo itemInfo = PlayerManager.Instance.BagController.GetItemInfo(daoyouGiftConfig.ItemID);
  151. WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null, GiveGiftContent);
  152. widgetItem.InitWidget(itemInfo);
  153. widgetItem.OnClick = OnClick;
  154. giveWidgetItems.Add(widgetItem);
  155. }
  156. }
  157. }
  158. DaoyouGiftConfig daoyouGiftConfig = default;
  159. private int count = 1;
  160. private WidgetItem widgetItem1;
  161. private async void OnClick(ItemWidgetBasic obj)
  162. {
  163. WidgetItem widgetItem = obj as WidgetItem;
  164. if (widgetItem1 == null)
  165. {
  166. widgetItem1 = await UIManager.Instance.CreateGComponent<WidgetItem>(null, WidgetItemRoot);
  167. widgetItem1.transform.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
  168. }
  169. widgetItem1.InitWidget(widgetItem.itemInfo);
  170. foreach (var giftConfig in daoyouGiftConfigs)
  171. {
  172. if (giftConfig.ItemID == widgetItem.itemInfo.itemID)
  173. {
  174. daoyouGiftConfig = giftConfig;
  175. break;
  176. }
  177. }
  178. Slider_Give.maxValue = widgetItem.itemInfo.count.Value;
  179. Slider_Give.minValue = 1;
  180. UpdateGiveItemCount();
  181. }
  182. private void Reduce()
  183. {
  184. count--;
  185. if (count < 1)
  186. {
  187. count = 1;
  188. }
  189. Slider_Give.value = count;
  190. }
  191. private void Add()
  192. {
  193. count++;
  194. if (count > widgetItem1.itemInfo.count.Value)
  195. {
  196. count = (int)widgetItem1.itemInfo.count.Value;
  197. }
  198. Slider_Give.value = count;
  199. }
  200. private void UpdateGiveItemCount()
  201. {
  202. Text_Count.text = $"当前选择数量{count}";
  203. Text_GiveGiftDesc.text = $"好感度+{daoyouGiftConfig.emotionValue * count}";
  204. }
  205. public override CTask GetFocus()
  206. {
  207. AppBarPanel.OpenPanel(this);
  208. return base.GetFocus();
  209. }
  210. public static async CTask OpenPanel(AccountFileInfo.DaoYouData daoYouData)
  211. {
  212. await UIManager.Instance.LoadAndOpenPanel<DaoYouInfoPanel>(null, uiData: new[] { daoYouData });
  213. }
  214. private void ClosePoolGive()
  215. {
  216. count = 0;
  217. daoyouGiftConfig = default;
  218. foreach (var giveWidgetItem in giveWidgetItems)
  219. {
  220. UIManager.Instance.DormancyGComponent(giveWidgetItem);
  221. }
  222. giveWidgetItems.Clear();
  223. UIManager.Instance.DormancyGComponent(widgetItem1);
  224. widgetItem1 = null;
  225. }
  226. public override void Close()
  227. {
  228. daoyouGiftConfigs = null;
  229. foreach (var widgetItem in widgetItems)
  230. {
  231. UIManager.Instance.DormancyGComponent(widgetItem);
  232. }
  233. widgetItems.Clear();
  234. foreach (var daoYouLevelWidget in _daoYouLevelWidgets)
  235. {
  236. UIManager.Instance.DormancyGComponent(daoYouLevelWidget);
  237. }
  238. _daoYouLevelWidgets.Clear();
  239. ClosePoolGive();
  240. base.Close();
  241. }
  242. }
  243. }