DaoYouInfoPanel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. List<DaoYouIdleEarningsWidget> _daoYouIdleEarningsWidgets = new List<DaoYouIdleEarningsWidget>();
  20. List<DaoYouaaFfixWidget> daoYouaaFfixWidgets = new List<DaoYouaaFfixWidget>();
  21. private TimerEntity _timerEntity = null;
  22. private DaoyouGiftConfig[] daoyouGiftConfigs;
  23. private void Init()
  24. {
  25. IsShowAppBar = true;
  26. isAddStack = true;
  27. }
  28. protected override void AddEvent()
  29. {
  30. }
  31. protected override void DelEvent()
  32. {
  33. }
  34. public override void AddButtonEvent()
  35. {
  36. Btn_Emotion.onClick.AddListener((() => { ShowMessage(); }));
  37. Btn_Facorability.onClick.AddListener(() =>
  38. {
  39. Info.SetActive(false);
  40. Facorability.SetActive(true);
  41. });
  42. Btn_InfoMation.onClick.AddListener(() =>
  43. {
  44. Info.SetActive(true);
  45. Facorability.SetActive(false);
  46. });
  47. Btn_SendGift.onClick.AddListener(async () =>
  48. {
  49. if (daoYouData.favorabilityLv >= _daoYouLevelWidgets.Count)
  50. {
  51. TipMessagePanel.OpenTipMessagePanel("道友等级已到最高");
  52. return;
  53. }
  54. AppBarPanel.ClosePanel();
  55. await UpdateGiveGiftRoot();
  56. GiveGite.gameObject.SetActive(true);
  57. });
  58. Btn_Love.onClick.AddListener(() =>
  59. {
  60. ClosePoolGive();
  61. saiXuanType = 2;
  62. List<ItemInfo> showItems = SaiXuan(saiXuanType);
  63. CreatItem(showItems);
  64. });
  65. Btn_Tongyong.onClick.AddListener(() =>
  66. {
  67. ClosePoolGive();
  68. saiXuanType = 1;
  69. List<ItemInfo> showItems = SaiXuan(saiXuanType);
  70. CreatItem(showItems);
  71. });
  72. Btn_Eveent.onClick.AddListener(() =>
  73. {
  74. if (daoYouData.favorabilityLv >= _daoyouModelConfig.EmotionLvforQuest
  75. && !EventSystemManager.Instance.BagIsEvent(_daoyouModelConfig.QuestID)
  76. && !EventSystemManager.Instance.IsEventTrigger(_daoyouModelConfig.QuestID))
  77. {
  78. AccountFileInfo.EventList eventList = EventSystemManager.Instance.AddEvent(_daoyouModelConfig.QuestID);
  79. AccountFileInfo.Instance.playerData.eventList.Add(eventList);
  80. AccountFileInfo.Instance.SavePlayerData();
  81. EventSystemManager.Instance.TriggerEvent(eventList);
  82. Btn_Eveent.gameObject.SetActive(false);
  83. }
  84. });
  85. Btn_Back.onClick.AddListener(() =>
  86. {
  87. ClosePoolGive();
  88. GiveGite.gameObject.SetActive(false);
  89. AppBarPanel.OpenPanel(this);
  90. });
  91. Btn_Add.onClick.AddListener(Add);
  92. Btn_Reduce.onClick.AddListener(Reduce);
  93. Btn_Max.onClick.AddListener(() =>
  94. {
  95. if (widgetItem1 == null)
  96. return;
  97. Slider_Give.value = (int)widgetItem1.itemInfo.count.Value;
  98. });
  99. Slider_Give.onValueChanged.AddListener((i) =>
  100. {
  101. count = (int)i;
  102. UpdateGiveItemCount();
  103. });
  104. Btn_Give.onClick.AddListener(() =>
  105. {
  106. if (widgetItem1 == null)
  107. {
  108. return;
  109. }
  110. if (daoyouGiftConfig.ID == 0)
  111. return;
  112. PlayerManager.Instance.BagController.DeductItem(daoyouGiftConfig.ItemID, count);
  113. emotionConfig emotionConfig = ConfigComponent.Instance.Get<emotionConfig>(daoYouData.emotion);
  114. for (int i = 0; i < count; i++)
  115. {
  116. int bl = Random.Range(emotionConfig.hanganUpRate[0], emotionConfig.hanganUpRate[1] + 1);
  117. daoYouData.exp += (int)(daoyouGiftConfig.emotionValue * bl * 0.001f);
  118. }
  119. DaoyouLevelupConfig[] configs = ConfigComponent.Instance.GetAll<DaoyouLevelupConfig>();
  120. for (var i = daoYouData.favorabilityLv; i < configs.Length; i++)
  121. {
  122. if (daoYouData.exp >= configs[i].exp)
  123. {
  124. daoYouData.exp -= configs[i].exp;
  125. daoYouData.favorabilityLv++;
  126. }
  127. }
  128. AccountFileInfo.Instance.SavePlayerData();
  129. UpdateUI();
  130. UpdateGiveGiftRoot();
  131. });
  132. }
  133. public async override CTask<bool> AsyncInit(object[] uiData)
  134. {
  135. daoYouData = uiData[0] as AccountFileInfo.DaoYouData;
  136. _daoyouModelConfig = ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  137. daoyouGiftConfigs = ConfigComponent.Instance.GetAll<DaoyouGiftConfig>();
  138. emotionConfig emotionConfig = ConfigComponent.Instance.Get<emotionConfig>(daoYouData.emotion);
  139. Text_message.text = LanguageManager.Instance.Text(emotionConfig.des);
  140. ShowMessage();
  141. await UpdateUI();
  142. return await base.AsyncInit(uiData);
  143. }
  144. private void ShowMessage()
  145. {
  146. dotPoint.SetActive(true);
  147. _timerEntity?.Dispose();
  148. _timerEntity = null;
  149. _timerEntity = TimerComponent.Instance.AddTimer(5000, () =>
  150. {
  151. dotPoint.SetActive(false);
  152. _timerEntity?.Dispose();
  153. _timerEntity = null;
  154. });
  155. }
  156. public async CTask UpdateUI()
  157. {
  158. foreach (var widgetItem in widgetItems)
  159. {
  160. UIManager.Instance.DormancyGComponent(widgetItem);
  161. }
  162. widgetItems.Clear();
  163. foreach (var daoYouLevelWidget in _daoYouLevelWidgets)
  164. {
  165. UIManager.Instance.DormancyGComponent(daoYouLevelWidget);
  166. }
  167. _daoYouLevelWidgets.Clear();
  168. foreach (var daoYouIdleEarningsWidget in _daoYouIdleEarningsWidgets)
  169. {
  170. UIManager.Instance.DormancyGComponent(daoYouIdleEarningsWidget);
  171. }
  172. _daoYouIdleEarningsWidgets.Clear();
  173. foreach (var daoYouaaFfixWidget in daoYouaaFfixWidgets)
  174. {
  175. UIManager.Instance.DormancyGComponent(daoYouaaFfixWidget);
  176. }
  177. daoYouaaFfixWidgets.Clear();
  178. if (daoYouData.favorabilityLv >= _daoyouModelConfig.EmotionLvforQuest
  179. && !EventSystemManager.Instance.BagIsEvent(_daoyouModelConfig.QuestID)
  180. && !EventSystemManager.Instance.IsEventTrigger(_daoyouModelConfig.QuestID))
  181. {
  182. Btn_Eveent.gameObject.SetActive(true);
  183. }
  184. else
  185. {
  186. Btn_Eveent.gameObject.SetActive(false);
  187. }
  188. Text_Name.text = LanguageManager.Instance.Text(_daoyouModelConfig.name);
  189. int index = 0;
  190. for (var i = 0; i < _daoyouModelConfig.desUnlockLv.Length; i++)
  191. {
  192. if (daoYouData.favorabilityLv >= _daoyouModelConfig.desUnlockLv[i])
  193. {
  194. index = i;
  195. }
  196. }
  197. Text_Desc.text = LanguageManager.Instance.Text(_daoyouModelConfig.des[index]);
  198. foreach (var i in _daoyouModelConfig.guajiBuffID)
  199. {
  200. DaoYouIdleEarningsWidget daoYouIdleEarningsWidget = await UIManager.Instance.CreateGComponent<DaoYouIdleEarningsWidget>(null, GuajiContent);
  201. daoYouIdleEarningsWidget.CustomInit(daoYouData, i);
  202. _daoYouIdleEarningsWidgets.Add(daoYouIdleEarningsWidget);
  203. }
  204. DaoyouLevelupConfig currentDaoyouLevelupConfig = ConfigComponent.Instance.Get<DaoyouLevelupConfig>(daoYouData.favorabilityLv);
  205. Text_CurrentName.text = LanguageManager.Instance.Text(currentDaoyouLevelupConfig.name);
  206. Text_CurrentLevel.text = daoYouData.favorabilityLv.ToString();
  207. Slider_LeveUp.maxValue = currentDaoyouLevelupConfig.exp;
  208. Text_Exp.text = $"{daoYouData.exp}/{currentDaoyouLevelupConfig.exp}";
  209. Slider_LeveUp.value = daoYouData.exp;
  210. if (_daoyouModelConfig.PreferGiftID != null)
  211. {
  212. foreach (var i in _daoyouModelConfig.PreferGiftID)
  213. {
  214. WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null, LoveItemContent);
  215. widgetItems.Add(widgetItem);
  216. if (_daoyouModelConfig.shownPreferGiftID.Contains(i) || (daoYouData != null && daoYouData.loveIds.Contains(i)))
  217. {
  218. widgetItem.InitWidget(new ItemInfo(i, 0));
  219. }
  220. else
  221. {
  222. widgetItem.ShowWenhao();
  223. }
  224. }
  225. }
  226. if (_daoyouModelConfig.daolvSkillID != null)
  227. {
  228. foreach (var i in _daoyouModelConfig.daolvSkillID)
  229. {
  230. DaoYouaaFfixWidget daoYouaaFfixWidge = await UIManager.Instance.CreateGComponent<DaoYouaaFfixWidget>(null, DaoLvContent);
  231. daoYouaaFfixWidge.CustomInit(i);
  232. daoYouaaFfixWidgets.Add(daoYouaaFfixWidge);
  233. }
  234. }
  235. DaoyouLevelupConfig[] configs = ConfigComponent.Instance.GetAll<DaoyouLevelupConfig>();
  236. foreach (var daoyouLevelupConfig in configs)
  237. {
  238. DaoYouLevelWidget daoYouLevelWidget = await UIManager.Instance.CreateGComponent<DaoYouLevelWidget>(null, DaoYouLevelWidgetContent);
  239. daoYouLevelWidget.CustomInit(daoYouData, daoyouLevelupConfig.ID);
  240. _daoYouLevelWidgets.Add(daoYouLevelWidget);
  241. }
  242. }
  243. List<ItemInfo> allItems = new List<ItemInfo>();
  244. private int saiXuanType = 1;
  245. public async CTask UpdateGiveGiftRoot()
  246. {
  247. ClosePoolGive();
  248. allItems.Clear();
  249. foreach (var daoyouGiftConfig in daoyouGiftConfigs)
  250. {
  251. if (PlayerManager.Instance.BagController.GetItemCount(daoyouGiftConfig.ItemID) > 0)
  252. {
  253. ItemInfo itemInfo = PlayerManager.Instance.BagController.GetItemInfo(daoyouGiftConfig.ItemID);
  254. allItems.Add(itemInfo);
  255. }
  256. }
  257. List<ItemInfo> showItems = SaiXuan(saiXuanType);
  258. CreatItem(showItems);
  259. }
  260. private List<ItemInfo> SaiXuan(int type)
  261. {
  262. List<ItemInfo> shownItems = new List<ItemInfo>();
  263. //全部
  264. if (type == 1)
  265. {
  266. shownItems = allItems.ToList();
  267. }
  268. //喜欢
  269. else if (type == 2)
  270. {
  271. foreach (var itemInfo in allItems)
  272. {
  273. if (_daoyouModelConfig.shownPreferGiftID.Contains(itemInfo.itemID) || (daoYouData != null && daoYouData.loveIds.Contains(itemInfo.itemID)))
  274. {
  275. shownItems.Add(itemInfo);
  276. }
  277. }
  278. }
  279. return shownItems;
  280. }
  281. private async CTask CreatItem(List<ItemInfo> shownItems)
  282. {
  283. // ClosePoolGive();
  284. foreach (var itemInfo in shownItems)
  285. {
  286. WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null, GiveGiftContent);
  287. widgetItem.InitWidget(itemInfo);
  288. widgetItem.OnClick = OnClick;
  289. giveWidgetItems.Add(widgetItem);
  290. }
  291. if (giveWidgetItems.Count > 0)
  292. {
  293. giveWidgetItems[0].OnPointerClick();
  294. }
  295. }
  296. DaoyouGiftConfig daoyouGiftConfig = default;
  297. private int count = 1;
  298. private WidgetItem widgetItem1;
  299. private async void OnClick(ItemWidgetBasic obj)
  300. {
  301. WidgetItem widgetItem = obj as WidgetItem;
  302. if (widgetItem1 == null)
  303. {
  304. widgetItem1 = await UIManager.Instance.CreateGComponent<WidgetItem>(null, WidgetItemRoot);
  305. widgetItem1.transform.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
  306. }
  307. widgetItem1.InitWidget(widgetItem.itemInfo);
  308. foreach (var giftConfig in daoyouGiftConfigs)
  309. {
  310. if (giftConfig.ItemID == widgetItem.itemInfo.itemID)
  311. {
  312. daoyouGiftConfig = giftConfig;
  313. break;
  314. }
  315. }
  316. Slider_Give.maxValue = widgetItem.itemInfo.count.Value;
  317. Slider_Give.minValue = 1;
  318. UpdateGiveItemCount();
  319. }
  320. private void Reduce()
  321. {
  322. if (widgetItem1 == null)
  323. return;
  324. count--;
  325. if (count < 1)
  326. {
  327. count = 1;
  328. }
  329. Slider_Give.value = count;
  330. }
  331. private void Add()
  332. {
  333. if (widgetItem1 == null)
  334. return;
  335. count++;
  336. if (count > widgetItem1.itemInfo.count.Value)
  337. {
  338. count = (int)widgetItem1.itemInfo.count.Value;
  339. }
  340. Slider_Give.value = count;
  341. }
  342. private void UpdateGiveItemCount()
  343. {
  344. emotionConfig emotionConfig = ConfigComponent.Instance.Get<emotionConfig>(daoYouData.emotion);
  345. Text_Count.text = $"当前选择数量{count}";
  346. Text_GiveGiftDesc.text = $"好感度+{daoyouGiftConfig.emotionValue} ({daoyouGiftConfig.emotionValue * emotionConfig.hanganUpRate[0] * 0.001} - {daoyouGiftConfig.emotionValue * emotionConfig.hanganUpRate[1] * 0.001})";
  347. }
  348. public override CTask GetFocus()
  349. {
  350. AppBarPanel.OpenPanel(this);
  351. return base.GetFocus();
  352. }
  353. public static async CTask OpenPanel(AccountFileInfo.DaoYouData daoYouData)
  354. {
  355. await UIManager.Instance.LoadAndOpenPanel<DaoYouInfoPanel>(null, uiData: new[] { daoYouData });
  356. }
  357. private void ClosePoolGive()
  358. {
  359. count = 0;
  360. daoyouGiftConfig = default;
  361. Slider_Give.value = 0;
  362. Slider_Give.minValue = 0;
  363. Slider_Give.maxValue = 0;
  364. foreach (var giveWidgetItem in giveWidgetItems)
  365. {
  366. UIManager.Instance.DormancyGComponent(giveWidgetItem);
  367. }
  368. giveWidgetItems.Clear();
  369. UIManager.Instance.DormancyGComponent(widgetItem1);
  370. widgetItem1 = null;
  371. }
  372. public override void Close()
  373. {
  374. daoyouGiftConfigs = null;
  375. foreach (var widgetItem in widgetItems)
  376. {
  377. UIManager.Instance.DormancyGComponent(widgetItem);
  378. }
  379. widgetItems.Clear();
  380. foreach (var daoYouLevelWidget in _daoYouLevelWidgets)
  381. {
  382. UIManager.Instance.DormancyGComponent(daoYouLevelWidget);
  383. }
  384. _daoYouLevelWidgets.Clear();
  385. foreach (var daoYouaaFfixWidget in daoYouaaFfixWidgets)
  386. {
  387. UIManager.Instance.DormancyGComponent(daoYouaaFfixWidget);
  388. }
  389. daoYouaaFfixWidgets.Clear();
  390. foreach (var daoYouIdleEarningsWidget in _daoYouIdleEarningsWidgets)
  391. {
  392. UIManager.Instance.DormancyGComponent(daoYouIdleEarningsWidget);
  393. }
  394. _daoYouIdleEarningsWidgets.Clear();
  395. allItems.Clear();
  396. saiXuanType = 1;
  397. ClosePoolGive();
  398. base.Close();
  399. }
  400. }
  401. }