Files
MinFt/Client/Assets/Scripts/UI/Shop/FishingShopPanel.cs
2026-04-27 12:07:32 +08:00

128 lines
3.4 KiB
C#

using asap.core;
using DG.Tweening;
using GameCore;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class FishingShopPanel : BasePanel
{
public Button btn_close;
#region tabChange
[SerializeField]
GameObject
tab_diamond,
go_diamond,
tab_items,
go_items;
[SerializeField]
Toggle
tog_diamond,
tog_item;
[SerializeField]
TMP_Text
txt_level,
txt_energy,
txt_diamond;
int _curDiamond;
int _curEnergy;
#endregion
private void Awake()
{
UIManager.Instance.panelStack.Push(UITypes.FishingShopPanel);
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
#if AGG
using (var e = GEvent.GameEvent("enter_shop")) { }
#endif
}
protected override void Start()
{
GContext.OnEvent<LackOfResourceConfirmEvent>().Subscribe(x =>
{
OnSwitchTab(x.state);
}).AddTo(disposables);
GContext.OnEvent<ResAddEvent>().Where(x => x.id == 1005).Subscribe(x =>
{
DiamondAddAnim();
}).AddTo(disposables);
GContext.OnEvent<ResAddEvent>().Where(x => x.id == 1001).Subscribe(x =>
{
EnergyAddAnim();
}).AddTo(disposables);
oldPanelName = PanelName;
base.Start();
btn_close.onClick.AddListener(async () =>
{
if (UIManager.Instance.panelStack.Count > 0)
{
UIManager.Instance.panelStack.Pop();
}
if (UIManager.Instance.panelStack.Count > 0)
{
UIType topUI = UIManager.Instance.panelStack.Pop();
await UIManager.Instance.ShowUI(topUI);
}
else
{
RestartShowHomeUIEvent restartShowHomeUIEvent = new RestartShowHomeUIEvent();
GContext.Publish(restartShowHomeUIEvent);
}
UIManager.Instance.DestroyUI(UITypes.FishingShopPanel);
});
//New
tog_item.OnValueChangedAsObservable().Where(x => x).Subscribe(_ => OnSwitchTab(0)).AddTo(disposables);
tog_diamond.OnValueChangedAsObservable().Where(x => x).Subscribe(_ => OnSwitchTab(1)).AddTo(disposables);
var playerData = GContext.container.Resolve<PlayerData>();
_curDiamond = playerData.diamond;
_curEnergy = playerData.Energy;
txt_diamond.text = ConvertTools.GetNumberString2(_curDiamond);
txt_level.text = playerData.lv.ToString();
txt_energy.text = ConvertTools.GetNumberString2(_curEnergy);
}
#region New
void OnSwitchTab(int scope)
{
if (scope == 0)
{
go_diamond.SetActive(false);
go_items.SetActive(true);
tab_diamond.SetActive(false);
tab_items.SetActive(true);
}
else if (scope == 1)
{
go_diamond.SetActive(true);
go_items.SetActive(false);
tab_diamond.SetActive(true);
tab_items.SetActive(false);
}
}
void DiamondAddAnim()
{
_curDiamond = GContext.container.Resolve<PlayerData>().diamond;
txt_diamond.text = ConvertTools.GetNumberString2(_curDiamond);
}
void EnergyAddAnim()
{
_curEnergy = GContext.container.Resolve<PlayerData>().Energy;
txt_energy.text = ConvertTools.GetNumberString2(_curEnergy);
}
#endregion
}