生产线样式,添加图标测试
This commit is contained in:
@ -190,28 +190,30 @@ public partial class CraftingQueueManager : Panel
|
||||
// 创建图标显示层
|
||||
var iconTexture = new TextureRect();
|
||||
iconTexture.Name = "ProductIcon";
|
||||
iconTexture.ExpandMode = TextureRect.ExpandModeEnum.FitWidthProportional;
|
||||
iconTexture.ExpandMode = TextureRect.ExpandModeEnum.FitHeightProportional;
|
||||
iconTexture.StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered;
|
||||
iconTexture.AnchorLeft = 0.1f;
|
||||
iconTexture.AnchorTop = 0.1f;
|
||||
iconTexture.AnchorRight = 0.9f;
|
||||
iconTexture.AnchorBottom = 0.9f;
|
||||
iconTexture.AnchorLeft = 0.0f;
|
||||
iconTexture.AnchorTop = 0.0f;
|
||||
iconTexture.AnchorRight = 1.0f;
|
||||
iconTexture.AnchorBottom = 1.0f;
|
||||
|
||||
// 获取产物的图标
|
||||
var outputItemData = GameData.Instance?.GetItem(recipe.OutputItem);
|
||||
if (outputItemData != null && !string.IsNullOrEmpty(outputItemData.IconPath))
|
||||
{
|
||||
// 尝试加载物品图标
|
||||
if (FileAccess.FileExists(outputItemData.IconPath))
|
||||
if (ResourceLoader.Exists(outputItemData.IconPath))
|
||||
{
|
||||
var texture = GD.Load<Texture2D>(outputItemData.IconPath);
|
||||
if (texture != null)
|
||||
// 尝试加载为Texture2D资源
|
||||
var resource = ResourceLoader.Load(outputItemData.IconPath);
|
||||
if (resource is Texture2D texture)
|
||||
{
|
||||
iconTexture.Texture = texture;
|
||||
GD.Print($"槽位{slotIndex}加载产物图标: {outputItemData.IconPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr($"资源不是Texture2D类型: {outputItemData.IconPath}");
|
||||
// 使用默认图标
|
||||
LoadDefaultIcon(iconTexture);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user