CutePet/Assets/Scripts/GameScene/Panel/GamePanel.cs
2024-10-25 11:10:04 +08:00

287 lines
7.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GamePanel : BasePanel
{
//头像
public Button btnHead;
//金币提现
public Button btnJBTX;
//在线领金币
public Button btnZXLJB;
//闯关领金币
public Button btnCGLJB;
//邀请领金币
public Button btnYQLJB;
//排行榜
public Button btnPHB;
//展览
public Button btnEXH;
//选择关卡
public Button btnLev;
//技能1
public Button btnSkill1;
private string hexColor="#6F6F6F";
//技能2
public Button btnSkill2;
//人物名字
public Text txtUserName;
//人物金币
public Text txtGold;
//分数
public Text txtScore2;
public int scoreInt = 0;
//关卡
public Text txtLev2;
//关卡数
public int levInt=1;
//提示信息
public Text txtTips;
public Text txtSkillTips;
public GameObject imgSkill;
//显示时间
public float displayDuration = 0.5f;
//是否开启下一次按钮
private bool isCanButton = false;
public override void Init()
{
imgSkill.SetActive(false);
//获取所有关卡的名字
StartCoroutine(NetMgr.Instance.AllLevGet());
//每次进游戏更新一次玩家的礼包的数量
UpdatePlayerData();
UpdatePanel(GameDataMgr.Instance.player.customLev);
btnHead.onClick.AddListener(() =>
{
//显示用户信息界面
UIManager.Instance.ShowPanel<UserPanel>();
});
btnJBTX.onClick.AddListener(() =>
{
//显示金币提现界面
UIManager.Instance.ShowPanel<GoldRealPanel>();
});
btnZXLJB.onClick.AddListener(() =>
{
//显示在线领金币界面
UIManager.Instance.ShowPanel<OnlinePanel>();
});
btnCGLJB.onClick.AddListener(() =>
{
//显示闯关领金币界面
UIManager.Instance.ShowPanel<RushPanel>();
});
btnYQLJB.onClick.AddListener(() =>
{
//显示邀请领金币界面
UIManager.Instance.ShowPanel<InvitePanel>();
});
btnPHB.onClick.AddListener(() =>
{
//显示排行榜界面
UIManager.Instance.ShowPanel<RankPanel>();
});
btnEXH.onClick.AddListener(() =>
{
//显示展览界面
UIManager.Instance.ShowPanel<ExhPanel>();
btnEXH.gameObject.SetActive(false);
});
btnLev.onClick.AddListener(() =>
{
UIManager.Instance.ShowPanel<AllLevStatePanel>();
});
//技能1点击事件
btnSkill1.onClick.AddListener(() =>
{
if (!isCanButton)
{
if (GameMgr.Instance.skillOne == 100 && PlayerMain.Instance.isStart)
{
GameMgr.Instance.SkillOneDelPet();
UpdateColor(btnSkill1, hexColor);
}
else
{
ShowHintText("技能1未激活无法使用");
}
}
});
//技能2点击事件
btnSkill2.onClick.AddListener(() =>
{
if (!isCanButton)
{
if (GameMgr.Instance.skillTwo == 200 && PlayerMain.Instance.isStart)
{
PlayerMain.Instance.isStart = false;
PlayerMain.Instance.isSkillTwoStart = true;
UpdateColor(btnSkill2, hexColor);
}
else
{
ShowHintText("技能2未激活无法使用");
}
}
});
}
/// <summary>
/// 更新玩家模型
/// </summary>
private void UpdatePlayerData()
{
List<bool> playerList;
List<bool> playerTempList;
if (GameDataMgr.Instance.player.inviteGiftOpen.Count<GameDataMgr.Instance.playerTemp.inviteGiftOpen.Count)
{
playerList = GameDataMgr.Instance.player.inviteGiftOpen;
playerTempList = GameDataMgr.Instance.playerTemp.inviteGiftOpen;
for (int i = playerList.Count; i < playerTempList.Count; i++)
{
playerList.Add(false);
}
}
if (GameDataMgr.Instance.player.rushGiftOpen.Count < GameDataMgr.Instance.playerTemp.rushGiftOpen.Count)
{
playerList = GameDataMgr.Instance.player.rushGiftOpen;
playerTempList = GameDataMgr.Instance.playerTemp.rushGiftOpen;
for (int i = playerList.Count; i < playerTempList.Count; i++)
{
playerList.Add(false);
}
Debug.Log(GameDataMgr.Instance.player.rushGiftOpen.Count);
}
if (GameDataMgr.Instance.player.onlineGiftOpen.Count < GameDataMgr.Instance.playerTemp.onlineGiftOpen.Count)
{
playerList = GameDataMgr.Instance.player.onlineGiftOpen;
playerTempList = GameDataMgr.Instance.playerTemp.onlineGiftOpen;
for (int i = playerList.Count; i < playerTempList.Count; i++)
{
playerList.Add(false);
}
}
StartCoroutine(NetMgr.Instance.ChangeDataPost(GameDataMgr.Instance.player));
}
//给外界更新界面显示信息
public void UpdatePanel(int lev)
{
UpdateGold();
UpdateUsername();
UpdateLev(lev);
}
//给外界更新分数的方法
public void UpdateScore(int score)
{
txtScore2.text = score.ToString();
scoreInt=score;
}
//更外界改变游戏界面上金币的方法
public void UpdateGold()
{
txtGold.text = GameDataMgr.Instance.player.gold.ToString();
}
//给外界改变用户名字的方法
public void UpdateUsername()
{
txtUserName.text = GameDataMgr.Instance.player.username;
txtGold.text=GameDataMgr.Instance.player.gold.ToString();
}
//给外界改变关卡的方法
public void UpdateLev(int lev)
{
if (lev==0)
{
levInt = 1;
}
else
{
levInt = lev;
}
if (lev > 0 && lev < 10)
{
txtLev2.text = "00" + levInt.ToString();
}
else if (lev >= 10 && lev < 100)
{
txtLev2.text = "0" + levInt.ToString();
}
else
{
txtLev2.text = levInt.ToString();
}
txtScore2.text = 0.ToString();
GameMgr.Instance.skillOne = 0;
GameMgr.Instance.skillTwo = 0;
UpdateColor(btnSkill1,hexColor);
UpdateColor(btnSkill2,hexColor);
}
//改变技能按钮颜色
public void UpdateButon(int skillOne,int skillTwo)
{
string colorc="#FFFFFF";
if (skillOne==100)
{
UpdateColor(btnSkill1,colorc);
}
if (skillTwo==200)
{
UpdateColor(btnSkill2,colorc);
}
}
//改变单个按钮颜色
private void UpdateColor(Button btn,string colo)
{
// 定义一个Color变量来存储解析的颜色
Color newColor;
// 使用ColorUtility.TryParseHtmlString将十六进制字符串解析为Color
if (ColorUtility.TryParseHtmlString(colo, out newColor))
{
// 设置Image组件的颜色
btn.image.color = newColor;
}
}
// 显示提示文字并在一段时间后隐藏
void ShowHintText(string message)
{
isCanButton = true;
// 设置提示文字内容并显示
txtSkillTips.text = message;
imgSkill.SetActive(true);
// 启动协程,在一段时间后隐藏提示文字
StartCoroutine(HideGameObject());
}
// 协程:在一定时间后隐藏提示文字
private IEnumerator HideGameObject()
{
// 等待指定的时间
yield return new WaitForSeconds(displayDuration);
// 隐藏提示文字
imgSkill.SetActive(false);
isCanButton = false;
}
}