using System.Collections.Generic; using System.Linq; using Core.Language; using Excel2Json; using Fort23.Core; using Fort23.UTool; using GameLogic.Bag; using UnityEngine; namespace Fort23.Mono { [UIBinding(prefab = "DaoYouInfoPanel")] public partial class DaoYouInfoPanel : UIPanel { private AccountFileInfo.DaoYouData daoYouData; private DaoyouModelConfig _daoyouModelConfig; List widgetItems = new List(); List giveWidgetItems = new List(); List _daoYouLevelWidgets = new List(); private DaoyouGiftConfig[] daoyouGiftConfigs; private void Init() { IsShowAppBar = true; isAddStack = true; } protected override void AddEvent() { } protected override void DelEvent() { } public override void AddButtonEvent() { Btn_Facorability.onClick.AddListener(() => { Info.SetActive(false); Facorability.SetActive(true); }); Btn_InfoMation.onClick.AddListener(() => { Info.SetActive(true); Facorability.SetActive(false); }); Btn_SendGift.onClick.AddListener(async () => { AppBarPanel.ClosePanel(); await UpdateGiveGiftRoot(); GiveGite.gameObject.SetActive(true); }); Btn_Back.onClick.AddListener(() => { ClosePoolGive(); GiveGite.gameObject.SetActive(false); AppBarPanel.OpenPanel(this); }); Btn_Add.onClick.AddListener(Add); Btn_Reduce.onClick.AddListener(Reduce); Btn_Max.onClick.AddListener(() => { Slider_Give.value = (int)widgetItem1.itemInfo.count.Value; }); Slider_Give.onValueChanged.AddListener((i) => { count = (int)i; UpdateGiveItemCount(); }); Btn_Give.onClick.AddListener(() => { if (widgetItem1 == null) { return; } if (daoyouGiftConfig.ID == 0) return; PlayerManager.Instance.BagController.DeductItem(daoyouGiftConfig.ItemID, count); daoYouData.exp += daoyouGiftConfig.emotionValue * count; DaoyouLevelupConfig[] configs = ConfigComponent.Instance.GetAll(); for (var i = daoYouData.favorabilityLv; i < configs.Length; i++) { if (daoYouData.exp >= configs[i].exp) { daoYouData.exp -= configs[i].exp; daoYouData.favorabilityLv++; } } AccountFileInfo.Instance.SavePlayerData(); UpdateUI(); UpdateGiveGiftRoot(); }); } public async override CTask AsyncInit(object[] uiData) { daoYouData = uiData[0] as AccountFileInfo.DaoYouData; _daoyouModelConfig = ConfigComponent.Instance.Get(daoYouData.id); daoyouGiftConfigs = ConfigComponent.Instance.GetAll(); await UpdateUI(); return await base.AsyncInit(uiData); } public async CTask UpdateUI() { foreach (var widgetItem in widgetItems) { UIManager.Instance.DormancyGComponent(widgetItem); } widgetItems.Clear(); foreach (var daoYouLevelWidget in _daoYouLevelWidgets) { UIManager.Instance.DormancyGComponent(daoYouLevelWidget); } _daoYouLevelWidgets.Clear(); Text_Name.text = LanguageManager.Instance.Text(_daoyouModelConfig.name); int index = 0; for (var i = 0; i < _daoyouModelConfig.desUnlockLv.Length; i++) { if (daoYouData.favorabilityLv >= _daoyouModelConfig.desUnlockLv[i]) { index = i; } } Text_Desc.text = LanguageManager.Instance.Text(_daoyouModelConfig.des[index]); DaoyouLevelupConfig currentDaoyouLevelupConfig = ConfigComponent.Instance.Get(daoYouData.favorabilityLv); Text_CurrentName.text = LanguageManager.Instance.Text(currentDaoyouLevelupConfig.name); Text_CurrentLevel.text = daoYouData.favorabilityLv.ToString(); Slider_LeveUp.maxValue = currentDaoyouLevelupConfig.exp; Text_Exp.text = $"{daoYouData.exp}/{currentDaoyouLevelupConfig.exp}"; Slider_LeveUp.value = daoYouData.exp; if (_daoyouModelConfig.PreferGiftID != null) { foreach (var i in _daoyouModelConfig.PreferGiftID) { if (_daoyouModelConfig.shownPreferGiftID.Contains(i) || (daoYouData != null && daoYouData.loveIds.Contains(i))) { WidgetItem widgetItem = await UIManager.Instance.CreateGComponent(null, LoveItemContent); widgetItem.InitWidget(new ItemInfo(i, 0)); widgetItems.Add(widgetItem); } } } DaoyouLevelupConfig[] configs = ConfigComponent.Instance.GetAll(); foreach (var daoyouLevelupConfig in configs) { DaoYouLevelWidget daoYouLevelWidget = await UIManager.Instance.CreateGComponent(null, DaoYouLevelWidgetContent); daoYouLevelWidget.CustomInit(daoYouData, daoyouLevelupConfig.ID); _daoYouLevelWidgets.Add(daoYouLevelWidget); } } public async CTask UpdateGiveGiftRoot() { ClosePoolGive(); foreach (var daoyouGiftConfig in daoyouGiftConfigs) { if (PlayerManager.Instance.BagController.GetItemCount(daoyouGiftConfig.ItemID) > 0) { ItemInfo itemInfo = PlayerManager.Instance.BagController.GetItemInfo(daoyouGiftConfig.ItemID); WidgetItem widgetItem = await UIManager.Instance.CreateGComponent(null, GiveGiftContent); widgetItem.InitWidget(itemInfo); widgetItem.OnClick = OnClick; giveWidgetItems.Add(widgetItem); } } } DaoyouGiftConfig daoyouGiftConfig = default; private int count = 1; private WidgetItem widgetItem1; private async void OnClick(ItemWidgetBasic obj) { WidgetItem widgetItem = obj as WidgetItem; if (widgetItem1 == null) { widgetItem1 = await UIManager.Instance.CreateGComponent(null, WidgetItemRoot); widgetItem1.transform.GetComponent().anchoredPosition = Vector2.zero; } widgetItem1.InitWidget(widgetItem.itemInfo); foreach (var giftConfig in daoyouGiftConfigs) { if (giftConfig.ItemID == widgetItem.itemInfo.itemID) { daoyouGiftConfig = giftConfig; break; } } Slider_Give.maxValue = widgetItem.itemInfo.count.Value; Slider_Give.minValue = 1; UpdateGiveItemCount(); } private void Reduce() { count--; if (count < 1) { count = 1; } Slider_Give.value = count; } private void Add() { count++; if (count > widgetItem1.itemInfo.count.Value) { count = (int)widgetItem1.itemInfo.count.Value; } Slider_Give.value = count; } private void UpdateGiveItemCount() { Text_Count.text = $"当前选择数量{count}"; Text_GiveGiftDesc.text = $"好感度+{daoyouGiftConfig.emotionValue * count}"; } public override CTask GetFocus() { AppBarPanel.OpenPanel(this); return base.GetFocus(); } public static async CTask OpenPanel(AccountFileInfo.DaoYouData daoYouData) { await UIManager.Instance.LoadAndOpenPanel(null, uiData: new[] { daoYouData }); } private void ClosePoolGive() { count = 0; daoyouGiftConfig = default; foreach (var giveWidgetItem in giveWidgetItems) { UIManager.Instance.DormancyGComponent(giveWidgetItem); } giveWidgetItems.Clear(); UIManager.Instance.DormancyGComponent(widgetItem1); widgetItem1 = null; } public override void Close() { daoyouGiftConfigs = null; foreach (var widgetItem in widgetItems) { UIManager.Instance.DormancyGComponent(widgetItem); } widgetItems.Clear(); foreach (var daoYouLevelWidget in _daoYouLevelWidgets) { UIManager.Instance.DormancyGComponent(daoYouLevelWidget); } _daoYouLevelWidgets.Clear(); ClosePoolGive(); base.Close(); } } }