生产线样式,添加图标测试

This commit is contained in:
2025-06-19 00:02:41 +08:00
parent 50dc434ed9
commit b3d1135e23
23 changed files with 868 additions and 384 deletions

View File

@ -30,6 +30,12 @@ public partial class ProductionLineItem : Panel
progressFill = GetNode<ColorRect>("MarginContainer/VBoxContainer/ProgressContainer/ProgressFill");
iconTexture = GetNode<TextureRect>("MarginContainer/VBoxContainer/TopRow/IconTexture");
// 设置进度条初始状态
if (progressFill != null)
{
progressFill.AnchorRight = 0.0f;
}
// 连接按钮信号
addButton.Pressed += OnAddButtonPressed;
removeButton.Pressed += OnRemoveButtonPressed;
@ -130,11 +136,16 @@ public partial class ProductionLineItem : Panel
if (ResourceLoader.Exists(iconPath))
{
var texture = GD.Load<Texture2D>(iconPath);
if (texture != null)
// 尝试加载为Texture2D资源
var resource = ResourceLoader.Load(iconPath);
if (resource is Texture2D texture)
{
iconTexture.Texture = texture;
}
else
{
GD.PrintErr($"资源不是Texture2D类型: {iconPath}");
}
}
}
@ -175,8 +186,12 @@ public partial class ProductionLineItem : Panel
productionLabel.Text = "0/s";
}
// 更新进度条
progressFill.AnchorRight = status.Progress;
// 更新进度条(添加边界检查,避免闪烁)
float newProgress = Mathf.Clamp(status.Progress, 0.0f, 1.0f);
if (progressFill.AnchorRight != newProgress)
{
progressFill.AnchorRight = newProgress;
}
// 更新按钮状态
UpdateButtonStates();