using System.Collections.Generic; using System.Linq; using Core.Language; using Excel2Json; using Fort23.Core; using Fort23.UTool; using UnityEngine.UI; using Utility; namespace Fort23.Mono { [UIBinding(prefab = "SentimentInfoPanel")] public partial class SentimentInfoPanel : UIPanel { AccountFileInfo.SentimentProperty curretnSentimentProperty; private AccountFileInfo.SentimentData sentimentData; List sentimentEffectWidgets = new List(); private List _sentimentEffectConfigs; private List currentGroupSentimentEffectConfigs; public SentimentEffectWidget mainSentimentEffectWidget; private SentimentEffectWidget currentSentimentEffectWidget; private EnergyWidget energyWidget; private ItemWidgetType1 _itemWidgetType1; private void Init() { isAddStack = false; isPopUi = true; IsShowAppBar = false; } protected override void AddEvent() { } protected override void DelEvent() { } public override void AddButtonEvent() { Btn_Rest.onClick.AddListener(() => { foreach (var sentimentDataSentimentProperty in sentimentData.sentimentProperties) { int count = 0; for (int i = 0; i < sentimentDataSentimentProperty.level; i++) { int level1 = sentimentData.sentimentProperties[0].level <= 0 ? 1 : sentimentData.sentimentProperties[0].level; int conFigId1 = sentimentData.sentimentProperties[0].groupId * 10 + level1; var sentimentEffectConfig1 = ConfigComponent.Instance.Get(conFigId1); count += sentimentEffectConfig1.upConstCount; } PlayerManager.Instance.BagController.AddItem(energyWidget._itemConfig.ID, count); sentimentDataSentimentProperty.level = 0; } foreach (var sentimentEffectWidget in sentimentEffectWidgets) { sentimentEffectWidget.CustomInit(sentimentEffectWidget.sentimentProperty); } AccountFileInfo.Instance.SavePlayerData(); }); Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); }); Btn_LingWu.onClick.AddListener(() => { if (curretnSentimentProperty == null) { return; } if (currentSentimentEffectWidget.lastSentimentWidget.sentimentProperty.level < currentSentimentEffectWidget.sentimentEffectConfig.unlockLevel) { TipMessagePanel.OpenTipMessagePanel("前置节点没有解锁"); return; } if (curretnSentimentProperty.level >= currentGroupSentimentEffectConfigs.Count) { TipMessagePanel.OpenTipMessagePanel("已经达到最大等级"); return; } int level = curretnSentimentProperty.level <= 0 ? 1 : curretnSentimentProperty.level; int conFigId = curretnSentimentProperty.groupId * 100 + level + 1; SentimentEffectConfig sentimentEffectConfig = ConfigComponent.Instance.Get(conFigId); PlayerManager.Instance.BagController.DeductItem(sentimentEffectConfig.upConstItemId, sentimentEffectConfig.upConstCount); //扣除道具 // sentimentEffectConfig.upConstItemId. // s curretnSentimentProperty.level++; AccountFileInfo.Instance.SavePlayerData(); foreach (var sentimentEffectWidget in sentimentEffectWidgets) { sentimentEffectWidget.UpdateXian(); } UpdateUi(); currentSentimentEffectWidget.CustomInit(curretnSentimentProperty); }); } public int MapNumber(int input) { if (input >= 1 && input <= 3) { return 0; } else if (input >= 4 && input <= 6) { return 1; } else if (input >= 7 && input <= 9) { return 2; } else { return -1; } } public async override CTask AsyncInit(object[] uiData) { sentimentData = uiData[0] as AccountFileInfo.SentimentData; _sentimentEffectConfigs = ConfigComponent.Instance.GetAll().ToList(); mainSentimentEffectWidget = await UIManager.Instance.CreateGComponentForObject(MainSentimentEffectWidget, null); mainSentimentEffectWidget.CustomInit(sentimentData.mainSentiment); mainSentimentEffectWidget.OnClick = OnClick; int level1 = sentimentData.sentimentProperties[0].level <= 0 ? 1 : sentimentData.sentimentProperties[0].level; int conFigId1 = sentimentData.sentimentProperties[0].groupId * 10 + level1; var sentimentEffectConfig1 = ConfigComponent.Instance.Get(conFigId1); EnergyWidget energyWidget = await UIManager.Instance.CreateGComponent(null, Group_ResourceBar); energyWidget.CustomInit(sentimentEffectConfig1.upConstItemId); foreach (var sentimentDataSentimentProperty in sentimentData.sentimentProperties) { int level = sentimentDataSentimentProperty.level <= 0 ? 1 : sentimentDataSentimentProperty.level; int conFigId = sentimentDataSentimentProperty.groupId * 10 + level; var sentimentEffectConfig = ConfigComponent.Instance.Get(conFigId); int index = MapNumber(sentimentEffectConfig.pos); SentimentEffectWidget sentimentEffectWidget1 = await UIManager.Instance.CreateGComponent(null, Root[index]); sentimentEffectWidget1.CustomInit(sentimentDataSentimentProperty); sentimentEffectWidget1.OnClick = OnClick; sentimentEffectWidgets.Add(sentimentEffectWidget1); if (currentSentimentEffectWidget == null) { sentimentEffectWidget1.OnPointerClick(); } } foreach (var rectTransform in Root) { LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform); } return await base.AsyncInit(uiData); } public async override CTask Show() { await base.Show(); foreach (var sentimentEffectWidget in sentimentEffectWidgets) { int level = sentimentEffectWidget.sentimentProperty.level <= 0 ? 1 : sentimentEffectWidget.sentimentProperty.level; int conFigId = sentimentEffectWidget.sentimentProperty.groupId * 10 + level; var sentimentEffectConfig = ConfigComponent.Instance.Get(conFigId); SentimentEffectWidget sentimentEffectWidget1 = null; if (sentimentEffectConfig.lastSentimentEffectId == -1) { sentimentEffectWidget1 = mainSentimentEffectWidget; } else { sentimentEffectWidget1 = sentimentEffectWidgets.FirstOrDefault(s => s.sentimentEffectConfig.groupId == sentimentEffectConfig.lastSentimentEffectId); } sentimentEffectWidget.CreatXian(XianRoot, sentimentEffectWidget1); } } private async void UpdateUi() { int level = curretnSentimentProperty.level <= 0 ? 1 : curretnSentimentProperty.level; int conFigId = curretnSentimentProperty.groupId * 10 + level; SentimentEffectConfig sentimentEffectConfig = ConfigComponent.Instance.Get(conFigId); currentGroupSentimentEffectConfigs = _sentimentEffectConfigs.Where(se => se.groupId == sentimentEffectConfig.groupId).ToList(); Text_Name.text = LanguageManager.Instance.Text(sentimentEffectConfig.name); Text_Desc.text = UtilTools.GetString(LanguageManager.Instance.Text(sentimentEffectConfig.massge), sentimentEffectConfig.effectVale); UIManager.Instance.DormancyGComponent(_itemWidgetType1); _itemWidgetType1 = null; _itemWidgetType1 = await UIManager.Instance.CreateGComponentForObject(ItemWidgetType1Gam, null); _itemWidgetType1.CustomInit(sentimentEffectConfig.upConstItemId, sentimentEffectConfig.upConstCount); if (curretnSentimentProperty.level >= currentGroupSentimentEffectConfigs.Count) { Text_Level.text = $"{curretnSentimentProperty.level}级 ——> MAX级"; } else { Text_Level.text = $"{curretnSentimentProperty.level}级 ——> {curretnSentimentProperty.level + 1}级"; } } private void OnClick(ItemWidgetBasic obj) { SentimentEffectWidget sentimentEffectWidget = obj as SentimentEffectWidget; currentSentimentEffectWidget = sentimentEffectWidget; curretnSentimentProperty = sentimentEffectWidget.sentimentProperty; UpdateUi(); } public static async CTask OpenPanel(AccountFileInfo.SentimentData sentimentData) { await UIManager.Instance.LoadAndOpenPanel(null, uiData: new object[] { sentimentData }); } public override void Close() { foreach (var sentimentEffectWidget in sentimentEffectWidgets) { UIManager.Instance.DormancyGComponent(sentimentEffectWidget); } sentimentEffectWidgets.Clear(); currentSentimentEffectWidget = null; curretnSentimentProperty = null; UIManager.Instance.DormancyGComponent(energyWidget); energyWidget = null; base.Close(); } } }