战斗场景UI修改

This commit is contained in:
YiHan0621
2025-08-29 16:34:49 +08:00
parent efd64359a7
commit 12eb732b3c
17 changed files with 590 additions and 651 deletions

View File

@@ -27,6 +27,9 @@ namespace TcgEngine.UI
public Animator timeout_animator;
public AudioClip timeout_audio;
public Text player_prompt_text;
public Text opponent_prompt_text;
private float selector_timer = 0f;
private float end_turn_timer = 0f;
private int prev_time_val = 0;
@@ -76,7 +79,12 @@ namespace TcgEngine.UI
end_turn_button.interactable = yourturn && end_turn_timer > 1f;
end_turn_timer += Time.deltaTime;
selector_timer += Time.deltaTime;
// 提示玩家
player_prompt_text.text = yourturn ? "正在行动" : "正在等待";
opponent_prompt_text.text = yourturn ? "正在等待" : "正在行动";
//Timer
turn_count.text = "回合 " + data.turn_count.ToString();
turn_timer.enabled = data.turn_timer > 0f;

View File

@@ -1,5 +1,7 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
@@ -13,12 +15,14 @@ namespace TcgEngine.UI
public class IconBar : MonoBehaviour
{
public int value = 0;
public int max_value = 4;
public int max_value = 10;
public bool auto_refresh = true;
public Image[] icons;
public Sprite sprite_full;
public Sprite sprite_empty;
public List<Image> icons;
public Sprite mana_icon_true;
public Sprite mana_icon_false;
public GameObject mana_gem;
public Transform mana_magic_slot;
[Header("Value Display")]
public Text value_text; // 显示当前法力值数字的文本组件
@@ -26,7 +30,24 @@ namespace TcgEngine.UI
void Awake()
{
}
private void Start()
{
InitManaData();
}
private void InitManaData()
{
icons.Clear();
for (int i = 0; i < max_value; i++)
{
GameObject item = Instantiate(mana_gem, mana_magic_slot);
item.name = $"mana--{i}";
var img = item.GetComponent<Image>();
icons.Add(img);
}
}
void Update()
@@ -39,16 +60,14 @@ namespace TcgEngine.UI
{
if (icons == null)
return;
int index = 0;
foreach (Image icon in icons)
for (int i = 0; i < icons.Count; i++)
{
if (icon == null)
if (icons[i] == null)
continue;
icon.gameObject.SetActive(index < value || index < max_value);
icon.sprite = (index < value) ? sprite_full : sprite_empty;
index++;
// 前 value 个点亮,后面的变灰
icons[i].sprite = (i < value) ? mana_icon_true : mana_icon_false;
}
// 更新法力值数字文本
@@ -59,26 +78,7 @@ namespace TcgEngine.UI
{
if (value_text != null)
{
value_text.text = string.Format(value_format, value);
}
}
// 手动设置值并更新文本
public void SetValue(int new_value)
{
value = new_value;
UpdateValueText();
}
public void SetMat(Material mat)
{
if (icons == null)
return;
foreach (Image icon in icons)
{
if (icon != null)
icon.material = mat;
value_text.text = string.Format(value_format, value + "/10");
}
}
}