WXGame/Blacksmith/Assets/Script/UI/BattlePanel.cs

242 lines
6.6 KiB
C#
Raw Normal View History

using System;
2024-12-04 17:26:27 +08:00
using System.Collections;
using System.Collections.Generic;
2024-12-13 20:38:15 +08:00
using TMPro;
2024-12-04 17:26:27 +08:00
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 战斗界面
/// </summary>
2024-12-04 17:26:27 +08:00
public class BattlePanel : MonoBehaviour
{
[SerializeField] private GameObject levelPanel;
[SerializeField] private GameObject readyPanel;
[SerializeField] private UIBattleItem _battleItem;
[SerializeField] private Transform _battleParent;
[SerializeField] private Transform itemParent;
2024-12-13 20:38:15 +08:00
[SerializeField] private TextMeshProUGUI _hpText;
[SerializeField] private TextMeshProUGUI _attackText;
2024-12-22 20:35:00 +08:00
[SerializeField] private Text name;
[SerializeField] private Image backImage;
[SerializeField] private List<PlayerBar> _playerBars;
[SerializeField] private List<UIBattleItem> _list;
[SerializeField] private Button battleButton;
[SerializeField] private Button openItemParent;
[SerializeField] private Button closeItemParent;
[SerializeField] private Button openWeaponry;
[SerializeField] private Button openSoldier;
[SerializeField] private Button startButton;
2024-12-20 18:51:07 +08:00
[SerializeField] private int levelID = 0;
2024-12-22 20:35:00 +08:00
[SerializeField] private Text _goldNum;
[SerializeField] private Text _diamondNum;
[SerializeField] private Text _physicalNum;
#region
2024-12-04 17:26:27 +08:00
// Start is called before the first frame update
void Start()
{
}
private void OnEnable()
{
battleButton.onClick.AddListener(OpenCombatPanel);
openWeaponry.onClick.AddListener(OpenVideoWeaponryEvent);
openSoldier.onClick.AddListener(OpenVideoSoldierEvent);
openItemParent.onClick.AddListener(OpenItemPanel);
closeItemParent.onClick.AddListener(CloseItemPanel);
startButton.onClick.AddListener(StartBattle);
readyPanel.SetActive(false);
}
2024-12-04 17:26:27 +08:00
// Update is called once per frame
void Update()
{
}
private void OnDestroy()
{
battleButton.onClick.RemoveListener(OpenCombatPanel);
openWeaponry.onClick.RemoveListener(OpenVideoWeaponryEvent);
openSoldier.onClick.RemoveListener(OpenVideoSoldierEvent);
openItemParent.onClick.RemoveListener(OpenItemPanel);
closeItemParent.onClick.RemoveListener(CloseItemPanel);
startButton.onClick.RemoveListener(StartBattle);
}
#endregion
#region
private void InitLevelPanel()
{
}
#endregion
#region
2024-12-20 18:51:07 +08:00
2024-12-22 20:35:00 +08:00
public void ResetLevelID()
2024-12-20 18:51:07 +08:00
{
for (int i = 0; i < JsonTab.Instance.tables.Level.DataList.Count; i++)
{
if (DataManager.GetLevelLock(JsonTab.Instance.tables.Level.DataList[i].ID))
{
levelID = JsonTab.Instance.tables.Level.DataList[i].ID;
}
}
2024-12-21 14:05:40 +08:00
DataManager.SetNowLevel(levelID);
2024-12-22 20:35:00 +08:00
OpenLevel();
}
public void OpenLevel()
{
BDebug.Log(levelID);
name.text = JsonTab.Instance.tables.Level.Get(DataManager.GetNowLevel()).Name;
backImage.sprite = AssetBundleManager.ins.Sprite(
JsonTab.Instance.tables.Level.Get(DataManager.GetNowLevel()).Levelicon, AtlasType.AtlasBattleBack);
ResetGold();
2024-12-20 18:51:07 +08:00
}
private void OpenCombatPanel()
{
2024-12-22 20:35:00 +08:00
if (DataManager.GetPhysical()>=5)
{
2024-12-22 20:35:00 +08:00
DataManager.RemovePhysical();
readyPanel.SetActive(true);
UIMgr.ins.CloseSwithPanel();
BattleManager.ins.ResetBattleData();
ResetItem();
foreach (var playerBar in _playerBars)
{
playerBar.RestData(this);
}
OpenItemPanel();
ResetReadyPanel();
int h = 0;
int a = 0;
BattleManager.ins.GetAttribute(ref h, ref a);
_hpText.text = h.ToString();
_attackText.text = a.ToString();
}
2024-12-13 20:38:15 +08:00
}
public void SetPlayerIndex()
{
foreach (var pBar in _playerBars)
{
pBar.ResetBack();
}
int h = 0;
int a = 0;
BattleManager.ins.GetAttribute(ref h, ref a);
_hpText.text = h.ToString();
_attackText.text = a.ToString();
}
public void ResetReadyPanel()
{
foreach (var pBar in _playerBars)
{
2024-12-13 20:38:15 +08:00
pBar.RestData(this);
}
foreach (var itemBar in _list)
{
itemBar.ResetText();
}
2024-12-11 20:35:20 +08:00
openSoldier.gameObject.SetActive(!BattleManager.ins.OpenVideoSoldier);
openWeaponry.gameObject.SetActive(!BattleManager.ins.OpenVideoWeaponry);
2024-12-13 20:38:15 +08:00
int h = 0;
int a = 0;
BattleManager.ins.GetAttribute(ref h, ref a);
_hpText.text = h.ToString();
_attackText.text = a.ToString();
}
private void ResetItem()
{
if (_list==null)
{
_list = new List<UIBattleItem>();
}
if (_list.Count != 0)
{
for (int i = 0; i < _list.Count; i++)
{
Destroy(_list[i].gameObject);
}
_list.Clear();
}
var dic = DataManager.ItemDictionary;
foreach (var dicData in dic)
{
2024-12-13 20:38:15 +08:00
if (JsonTab.Instance.tables.Item.Get(dicData.Key).Includearms!=0&&DataManager.GetItem(dicData.Key)>0)
{
var obj = Instantiate(_battleItem.gameObject, _battleParent);
obj.SetActive(true);
_list.Add(obj.GetComponent<UIBattleItem>());
obj.GetComponent<UIBattleItem>().ResetData(dicData.Key);
}
}
}
private void OpenItemPanel()
{
itemParent.gameObject.SetActive(true);
2024-12-11 20:35:20 +08:00
openItemParent.gameObject.SetActive(false);
closeItemParent.gameObject.SetActive(true);
}
private void CloseItemPanel()
{
itemParent.gameObject.SetActive(false);
2024-12-11 20:35:20 +08:00
openItemParent.gameObject.SetActive(true);
closeItemParent.gameObject.SetActive(false);
}
private void StartBattle()
{
2024-12-13 20:38:15 +08:00
if (BattleManager.ins.BattleStart())
{
BattleManager.ins.StartBattle();
}
}
2024-12-22 20:35:00 +08:00
public void ResetGold()
{
_goldNum.text = DataManager.GetItem(2).ToString();
_diamondNum.text = DataManager.GetItem(3).ToString();
_physicalNum.text=DataManager.GetPhysical().ToString();
}
#endregion
#region
private void OpenVideoWeaponryEvent()
{
BattleManager.ins.OpenVideoWeaponryEvent();
ResetReadyPanel();
}
private void OpenVideoSoldierEvent()
{
BattleManager.ins.OpenVideoSoldierEvent();
ResetReadyPanel();
}
#endregion
}