using System; using System.Collections.Generic; using Core.Audio; using Core.Language; using Fort23.Core; using GameLogic.Bag; using NetCore.Protocol.MemoryPack; namespace Fort23.Mono { [UIBinding(prefab = "RewardsPanel")] public partial class RewardsPanel : UIPanel { private void Init() { } protected override void AddEvent() { } protected override void DelEvent() { } public override void AddButtonEvent() { btnDi.onClick.AddListener(OnclickClose); } List widgetItems = new List(); private void OnclickClose() { UIManager.Instance.HideUIUIPanel(this); } public override void Close() { onClose?.Invoke(); foreach (var widgetItem in widgetItems) { UIManager.Instance.DormancyGComponent(widgetItem); } widgetItems.Clear(); base.Close(); } private Action onClose; public override CTask Show() { AudioManager.Instance.PlayAudio("jiangliui.wav"); return base.Show(); } public async void InitRewardsPanel(List rewards, Action onClose = null) { this.onClose = onClose; foreach (var widgetItem in widgetItems) { UIManager.Instance.DormancyGComponent(widgetItem); } widgetItems.Clear(); foreach (ItemInfo reward in rewards) { GenerateWidget(reward); } } public void SetTitle(string title) { txtlName.text = title; } public async void InitRewardsPanel(Dictionary rewardsDic, Action onClose = null) { this.onClose = onClose; foreach (var widgetItem in widgetItems) { UIManager.Instance.DormancyGComponent(widgetItem); } widgetItems.Clear(); foreach (KeyValuePair keyValuePair in rewardsDic) { GenerateWidget(keyValuePair.Value); } } private async void GenerateWidget(ItemInfo itemInfo) { WidgetItem widgetItem = await UIManager.Instance.CreateGComponent(null, root: itemRoot); widgetItem.InitWidget(itemInfo); widgetItems.Add(widgetItem); } public async static CTask OpenPanel(Dictionary rewardsDic, Action onClose = null) { RewardsPanel rewardsPanel = await UIManager.Instance.LoadAndOpenPanel(null, layer: UILayer.Top,isShowBG:true); rewardsPanel.InitRewardsPanel(rewardsDic, onClose); return rewardsPanel; } public async static CTask OpenPanel(List rewardsDic, Action onClose = null, int titleId = 0) { RewardsPanel rewardsPanel = await UIManager.Instance.LoadAndOpenPanel(null, layer: UILayer.Top,isShowBG:true); rewardsPanel.InitRewardsPanel(rewardsDic, onClose); if (titleId != 0) rewardsPanel.SetTitle(LanguageManager.Instance.Text(titleId)); return rewardsPanel; } } }