生产线样式,添加图标测试
This commit is contained in:
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user