CultivateImmortal/Assets/Scripts/GameScene/UI/LowerPanel.cs

156 lines
4.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class LowerPanel : BasePanel
{
//按钮颜色,黄色
private string imgColor1 = "#FF9F00";
//按钮字体颜色,褐色
private string txtColor1 = "#A89500";
//暗蓝
private string txtColor2 = "#255746";
public Button btnFight;
public Button btnPerson;
public Button btnBag;
public Button btnWorld;
public TextMeshProUGUI txtFight;
public TextMeshProUGUI txtPerson;
public TextMeshProUGUI txtBag;
public TextMeshProUGUI txtWorld;
//选择的按钮
private Button btnChoose;
//选择的文字
private TextMeshProUGUI txtChoose;
//已选择的界面
private BasePanel choosePanel;
public override void Init()
{
//刚进游戏,按钮和文字选择为战斗
btnChoose = btnFight;
txtChoose = txtFight;
//战斗按钮
btnFight.onClick.AddListener(() =>
{
HidePanel(choosePanel);
SetColor(btnFight, txtFight);
UIManager.Instance.ShowPanel<BattlePanel>(E_UILayer.Bottom);
if (UIManager.Instance.GetPanel<TopPanel>() == null)
{
UIManager.Instance.ShowPanel<TopPanel>(E_UILayer.System);
}
choosePanel = null;
});
//人物按钮
btnPerson.onClick.AddListener(() =>
{
if (UIManager.Instance.GetPanel<UserPanel>() == null)
{
HidePanel(choosePanel);
SetColor(btnPerson, txtPerson);
UIManager.Instance.ShowPanel<UserPanel>(E_UILayer.Middle);
if (UIManager.Instance.GetPanel<TopPanel>() == null)
{
UIManager.Instance.ShowPanel<TopPanel>(E_UILayer.System);
}
choosePanel = UIManager.Instance.GetPanel<UserPanel>();
}
});
//背包按钮
btnBag.onClick.AddListener(() =>
{
if (UIManager.Instance.GetPanel<BagPanel>() == null)
{
HidePanel(choosePanel);
SetColor(btnBag, txtBag);
UIManager.Instance.ShowPanel<BagPanel>(E_UILayer.Middle);
if (UIManager.Instance.GetPanel<TopPanel>()!=null)
{
UIManager.Instance.HidePanel<TopPanel>();
}
choosePanel = UIManager.Instance.GetPanel<BagPanel>();
}
});
//世界按钮
btnWorld.onClick.AddListener(() =>
{
if (UIManager.Instance.GetPanel<WorldPanel>() == null)
{
HidePanel(choosePanel);
SetColor(btnWorld, txtWorld);
UIManager.Instance.ShowPanel<WorldPanel>(E_UILayer.Middle);
if (UIManager.Instance.GetPanel<TopPanel>() != null)
{
UIManager.Instance.HidePanel<TopPanel>();
}
choosePanel = UIManager.Instance.GetPanel<WorldPanel>();
}
});
}
/// <summary>
/// 按钮点击改变按钮的颜色
/// </summary>
/// <param name="btn"></param>
/// <param name="txt"></param>
public void SetColor(Button btn, TextMeshProUGUI txt)
{
Color imgColor, txtColor;
//设置颜色前先把上一次的按钮颜色重置
if (btnChoose!=null&&txtChoose!=null)
{
btnChoose.image.color = Color.white;
if (ColorUtility.TryParseHtmlString(txtColor2, out txtColor))
{
txtChoose.color = txtColor;
}
}
//然后设置此次点击的按钮颜色
if (ColorUtility.TryParseHtmlString(imgColor1, out imgColor))
{
btn.image.color = imgColor;
if (ColorUtility.TryParseHtmlString(txtColor1, out txtColor))
{
txt.color = txtColor;
}
}
//设置为新的按钮,方便下一次重置颜色
btnChoose = btn;
txtChoose = txt;
}
//隐藏面板
private void HidePanel(BasePanel choosePanel)
{
//当选择为空时,返回
if (choosePanel == null)
{
return;
}
switch (choosePanel)
{
case UserPanel:
UIManager.Instance.HidePanel<UserPanel>();
break;
case BagPanel:
UIManager.Instance.HidePanel<BagPanel>();
break;
case WorldPanel:
UIManager.Instance.HidePanel<WorldPanel>();
break;
}
}
}