生产线样式,添加图标测试
This commit is contained in:
@ -222,7 +222,6 @@ public partial class GameScene : Control
|
||||
var inventoryManager = InventoryManager.Instance;
|
||||
if (inventoryManager != null)
|
||||
{
|
||||
inventoryManager.AddItem("mining_drill", 2); // 添加2个钻机
|
||||
inventoryManager.AddItem("furnace", 1); // 添加1个熔炉
|
||||
inventoryManager.AddItem("iron_ore", 10); // 添加10个铁矿用于冶炼测试
|
||||
GD.Print("已添加测试物品到库存");
|
||||
@ -291,9 +290,8 @@ public partial class GameScene : Control
|
||||
if (inventoryManager != null)
|
||||
{
|
||||
// 建筑设施
|
||||
inventoryManager.AddItem("mining_drill", 10); // 添加10个钻机
|
||||
inventoryManager.AddItem("miner", 10); // 添加10个钻机
|
||||
inventoryManager.AddItem("furnace", 8); // 添加8个熔炉
|
||||
inventoryManager.AddItem("smelter", 5); // 添加5个冶炼厂
|
||||
inventoryManager.AddItem("miner", 6); // 添加6个采矿机
|
||||
inventoryManager.AddItem("assembler", 3); // 添加3个组装机
|
||||
inventoryManager.AddItem("chemical_plant", 2); // 添加2个化工厂
|
||||
|
||||
@ -93,6 +93,8 @@ public partial class InventoryManager : Node
|
||||
AddItem("water", 200);
|
||||
AddItem("iron_ingot", 25);
|
||||
AddItem("copper_ingot", 15);
|
||||
AddItem("magnet", 8); // 添加磁铁,用于合成磁线圈
|
||||
AddItem("gear", 6); // 添加齿轮,用于合成钻机
|
||||
}
|
||||
|
||||
// 添加物品到库存
|
||||
|
||||
@ -10,6 +10,47 @@ public partial class InventoryTableManager : VBoxContainer
|
||||
{
|
||||
GD.Print("InventoryTableManager _Ready 开始");
|
||||
|
||||
// 设置父级ScrollContainer的滚动条宽度
|
||||
var scrollContainer = GetParent() as ScrollContainer;
|
||||
if (scrollContainer != null)
|
||||
{
|
||||
// 直接在滚动条组件上设置主题覆盖
|
||||
var vScrollBar = scrollContainer.GetVScrollBar();
|
||||
var hScrollBar = scrollContainer.GetHScrollBar();
|
||||
|
||||
if (vScrollBar != null)
|
||||
{
|
||||
// 尝试多种不同的属性名称
|
||||
vScrollBar.AddThemeConstantOverride("width", 1);
|
||||
vScrollBar.AddThemeConstantOverride("scroll_bar_width", 1);
|
||||
vScrollBar.AddThemeConstantOverride("scrollbar_width", 1);
|
||||
vScrollBar.AddThemeConstantOverride("bar_width", 1);
|
||||
|
||||
// 创建超细的样式框
|
||||
var thinStyle = new StyleBoxFlat();
|
||||
thinStyle.BgColor = new Color(0.3f, 0.3f, 0.3f, 0.6f);
|
||||
thinStyle.SetContentMarginAll(0);
|
||||
|
||||
var thinGrabber = new StyleBoxFlat();
|
||||
thinGrabber.BgColor = new Color(0.7f, 0.7f, 0.7f, 0.8f);
|
||||
thinGrabber.SetContentMarginAll(0);
|
||||
|
||||
// 应用样式
|
||||
vScrollBar.AddThemeStyleboxOverride("scroll", thinStyle);
|
||||
vScrollBar.AddThemeStyleboxOverride("grabber", thinGrabber);
|
||||
vScrollBar.AddThemeStyleboxOverride("grabber_highlight", thinGrabber);
|
||||
vScrollBar.AddThemeStyleboxOverride("grabber_pressed", thinGrabber);
|
||||
|
||||
// 设置最小尺寸
|
||||
vScrollBar.CustomMinimumSize = new Vector2(1, 0);
|
||||
|
||||
GD.Print("设置垂直滚动条样式和宽度");
|
||||
}
|
||||
|
||||
|
||||
GD.Print("已直接在滚动条组件上应用超细样式");
|
||||
}
|
||||
|
||||
// 加载库存物品场景
|
||||
inventoryItemScene = GD.Load<PackedScene>("res://scenes/InventoryItem.tscn");
|
||||
if (inventoryItemScene == null)
|
||||
@ -96,6 +137,11 @@ public partial class InventoryTableManager : VBoxContainer
|
||||
separator.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
separator.SizeFlagsVertical = Control.SizeFlags.ShrinkCenter;
|
||||
titleContainer.AddChild(separator);
|
||||
|
||||
// 添加右侧间距,避免内容紧贴滚动条
|
||||
var rightSpacer = new Control();
|
||||
rightSpacer.CustomMinimumSize = new Vector2(10, 0);
|
||||
titleContainer.AddChild(rightSpacer);
|
||||
|
||||
categoryContainer.AddChild(titleContainer);
|
||||
|
||||
@ -111,7 +157,17 @@ public partial class InventoryTableManager : VBoxContainer
|
||||
itemsContainer.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
itemsContainer.AddThemeConstantOverride("h_separation", 4); // 减少水平间距
|
||||
itemsContainer.AddThemeConstantOverride("v_separation", 4); // 垂直间距
|
||||
categoryContainer.AddChild(itemsContainer);
|
||||
|
||||
// 创建一个HBoxContainer来包装GridContainer,以便添加右侧间距
|
||||
var itemsWrapper = new HBoxContainer();
|
||||
itemsWrapper.AddChild(itemsContainer);
|
||||
|
||||
// 添加右侧间距
|
||||
var itemsRightSpacer = new Control();
|
||||
itemsRightSpacer.CustomMinimumSize = new Vector2(10, 0);
|
||||
itemsWrapper.AddChild(itemsRightSpacer);
|
||||
|
||||
categoryContainer.AddChild(itemsWrapper);
|
||||
|
||||
// 保存容器引用
|
||||
categoryContainers[category.CategoryName] = itemsContainer;
|
||||
@ -193,23 +249,37 @@ public partial class InventoryTableManager : VBoxContainer
|
||||
var iconTexture = inventoryItem.GetNode<TextureRect>("MarginContainer/HBoxContainer/IconTexture");
|
||||
if (iconTexture != null && !string.IsNullOrEmpty(itemData.IconPath))
|
||||
{
|
||||
GD.Print($"图标路径: {itemData.IconPath}");
|
||||
// 检查文件是否存在
|
||||
if (Godot.FileAccess.FileExists(itemData.IconPath))
|
||||
if (ResourceLoader.Exists(itemData.IconPath))
|
||||
{
|
||||
var texture = GD.Load<Texture2D>(itemData.IconPath);
|
||||
if (texture != null)
|
||||
// 尝试加载为Texture2D资源
|
||||
var resource = ResourceLoader.Load(itemData.IconPath);
|
||||
if (resource is Texture2D textureResource)
|
||||
{
|
||||
iconTexture.Texture = texture;
|
||||
|
||||
iconTexture.Texture = textureResource;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr($"资源不是Texture2D类型: {itemData.IconPath}");
|
||||
// 使用默认图标
|
||||
var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
|
||||
if (defaultIcon != null)
|
||||
{
|
||||
iconTexture.Texture = defaultIcon;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用默认图标
|
||||
var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
|
||||
if (defaultIcon != null)
|
||||
{
|
||||
iconTexture.Texture = defaultIcon;
|
||||
}
|
||||
// GD.Print($"图标文件不存在: {itemData.IconPath},使用默认图标");
|
||||
// // 使用默认图标
|
||||
// var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
|
||||
// if (defaultIcon != null)
|
||||
// {
|
||||
// iconTexture.Texture = defaultIcon;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -1,192 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
public partial class ManualCollectionPanel : Control
|
||||
{
|
||||
// 采集相关参数
|
||||
private const float COLLECTION_TIME = 1.0f; // 采集时间1秒
|
||||
|
||||
// 状态变量
|
||||
private bool isCollecting = false;
|
||||
private float collectionProgress = 0.0f;
|
||||
private string itemId;
|
||||
|
||||
// UI引用
|
||||
private ColorRect progressFill;
|
||||
private Color originalProgressColor;
|
||||
private Color collectingProgressColor = new Color(1.0f, 0.8f, 0.3f, 1.0f); // 采集时的橙色
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
GD.Print("ManualCollectionPanel _Ready 开始");
|
||||
|
||||
// 获取进度条引用 - 现在需要从父节点获取
|
||||
var parent = GetParent<Control>();
|
||||
if (parent != null)
|
||||
{
|
||||
progressFill = parent.GetNode<ColorRect>("MarginContainer/VBoxContainer/ProgressContainer/ProgressFill");
|
||||
if (progressFill != null)
|
||||
{
|
||||
originalProgressColor = progressFill.Color;
|
||||
GD.Print("成功获取进度条引用");
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr("无法获取进度条引用");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr("无法获取父节点");
|
||||
}
|
||||
|
||||
// 连接鼠标事件
|
||||
GuiInput += OnGuiInput;
|
||||
GD.Print("已连接鼠标事件");
|
||||
|
||||
GD.Print("ManualCollectionPanel _Ready 完成");
|
||||
}
|
||||
|
||||
// 设置物品ID
|
||||
public void SetItemId(string id)
|
||||
{
|
||||
itemId = id;
|
||||
GD.Print($"设置手动采集面板物品ID: {itemId}");
|
||||
}
|
||||
|
||||
// 处理输入事件
|
||||
private void OnGuiInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton mouseEvent)
|
||||
{
|
||||
if (mouseEvent.ButtonIndex == MouseButton.Left)
|
||||
{
|
||||
//打印鼠标事件
|
||||
GD.Print($"鼠标事件: {mouseEvent}");
|
||||
|
||||
if (mouseEvent.Pressed)
|
||||
{
|
||||
// 开始采集
|
||||
StartCollection();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 停止采集
|
||||
StopCollection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 开始采集
|
||||
private void StartCollection()
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemId)) return;
|
||||
|
||||
isCollecting = true;
|
||||
collectionProgress = 0.0f;
|
||||
|
||||
// 改变进度条颜色表示正在采集
|
||||
if (progressFill != null)
|
||||
{
|
||||
progressFill.Color = collectingProgressColor;
|
||||
}
|
||||
|
||||
GD.Print($"开始采集: {itemId}");
|
||||
}
|
||||
|
||||
// 停止采集
|
||||
private void StopCollection()
|
||||
{
|
||||
if (!isCollecting) return;
|
||||
|
||||
isCollecting = false;
|
||||
collectionProgress = 0.0f;
|
||||
|
||||
// 恢复进度条
|
||||
UpdateProgressBar();
|
||||
|
||||
// 恢复原始颜色
|
||||
if (progressFill != null)
|
||||
{
|
||||
progressFill.Color = originalProgressColor;
|
||||
}
|
||||
|
||||
GD.Print($"停止采集: {itemId}");
|
||||
}
|
||||
|
||||
// 完成采集
|
||||
private void CompleteCollection()
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemId)) return;
|
||||
|
||||
// 添加物品到库存
|
||||
if (InventoryManager.Instance != null)
|
||||
{
|
||||
InventoryManager.Instance.AddItem(itemId, 1);
|
||||
GD.Print($"采集完成,获得: {itemId} x1");
|
||||
}
|
||||
|
||||
// 重置采集状态
|
||||
collectionProgress = 0.0f;
|
||||
|
||||
// 如果还在按住,继续下一轮采集
|
||||
if (isCollecting)
|
||||
{
|
||||
GD.Print($"继续采集: {itemId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 恢复进度条显示
|
||||
UpdateProgressBar();
|
||||
if (progressFill != null)
|
||||
{
|
||||
progressFill.Color = originalProgressColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新进度条显示
|
||||
private void UpdateProgressBar()
|
||||
{
|
||||
if (progressFill != null)
|
||||
{
|
||||
if (isCollecting)
|
||||
{
|
||||
// 采集中显示当前进度
|
||||
progressFill.AnchorRight = collectionProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 非采集状态显示满进度(表示可采集)
|
||||
progressFill.AnchorRight = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (isCollecting)
|
||||
{
|
||||
// 更新采集进度
|
||||
collectionProgress += (float)delta / COLLECTION_TIME;
|
||||
|
||||
// 限制进度在0-1之间
|
||||
collectionProgress = Mathf.Clamp(collectionProgress, 0.0f, 1.0f);
|
||||
|
||||
// 更新进度条显示
|
||||
UpdateProgressBar();
|
||||
|
||||
// 检查是否完成采集
|
||||
if (collectionProgress >= 1.0f)
|
||||
{
|
||||
CompleteCollection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 清理
|
||||
public override void _ExitTree()
|
||||
{
|
||||
GuiInput -= OnGuiInput;
|
||||
}
|
||||
}
|
||||
@ -190,8 +190,10 @@ public partial class ProductionLineManager : Node
|
||||
{
|
||||
activeProductionLines[productionLineId] = new ActiveProductionLine
|
||||
{
|
||||
ProductionLineId = productionLineId
|
||||
ProductionLineId = productionLineId,
|
||||
RemainingTime = productionLine.ProductionTime // 从完整的生产时间开始
|
||||
};
|
||||
GD.Print($"创建新产线 {productionLine.Name},初始剩余时间: {productionLine.ProductionTime}s");
|
||||
}
|
||||
|
||||
var activeLine = activeProductionLines[productionLineId];
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class DynamicTabManager : TabContainer
|
||||
{
|
||||
private PackedScene itemPanelScene;
|
||||
private PackedScene craftingItemScene;
|
||||
private PackedScene productionLineItemScene;
|
||||
private PackedScene manualCollectionItemScene;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@ -38,6 +40,14 @@ public partial class DynamicTabManager : TabContainer
|
||||
return;
|
||||
}
|
||||
|
||||
// 加载ManualCollectionItem场景(用于手动采集)
|
||||
manualCollectionItemScene = GD.Load<PackedScene>("res://scenes/ManualCollectionItem.tscn");
|
||||
if (manualCollectionItemScene == null)
|
||||
{
|
||||
GD.PrintErr("无法加载ManualCollectionItem场景");
|
||||
return;
|
||||
}
|
||||
|
||||
GD.Print("开始初始化标签页");
|
||||
// 延迟初始化以确保所有管理器都已初始化
|
||||
CallDeferred(nameof(InitializeTabs));
|
||||
@ -101,9 +111,10 @@ public partial class DynamicTabManager : TabContainer
|
||||
// 为合成相关的分类创建块
|
||||
foreach (var category in allCategories)
|
||||
{
|
||||
// 合成标签包含:手动采集、冶炼、建筑设施
|
||||
// 合成标签包含:手动采集、冶炼、制作物品、建筑设施
|
||||
if (category.CategoryName == "手动采集" ||
|
||||
category.CategoryName == "冶炼" ||
|
||||
category.CategoryName == "制作物品" ||
|
||||
category.CategoryName == "建筑设施")
|
||||
{
|
||||
CreateCategoryBlock(vboxContainer, category, "合成");
|
||||
@ -134,14 +145,14 @@ public partial class DynamicTabManager : TabContainer
|
||||
if (productionLineManager == null)
|
||||
{
|
||||
GD.PrintErr("ProductionLineManager 实例为null,创建空的生产线标签");
|
||||
|
||||
|
||||
// 创建一个提示标签
|
||||
var noDataLabel = new Label();
|
||||
noDataLabel.Text = "生产线管理器未初始化";
|
||||
noDataLabel.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
noDataLabel.VerticalAlignment = VerticalAlignment.Center;
|
||||
vboxContainer.AddChild(noDataLabel);
|
||||
|
||||
|
||||
// 添加到TabContainer
|
||||
AddChild(scrollContainer);
|
||||
SetTabTitle(GetTabCount() - 1, "生产线");
|
||||
@ -155,7 +166,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
if (categories.Count == 0)
|
||||
{
|
||||
GD.Print("没有找到生产线分类,创建提示标签");
|
||||
|
||||
|
||||
// 创建一个提示标签
|
||||
var noDataLabel = new Label();
|
||||
noDataLabel.Text = "暂无生产线配置";
|
||||
@ -165,6 +176,8 @@ public partial class DynamicTabManager : TabContainer
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
// 为每个分类创建块
|
||||
foreach (var category in categories)
|
||||
{
|
||||
@ -176,7 +189,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
// 添加到TabContainer
|
||||
AddChild(scrollContainer);
|
||||
SetTabTitle(GetTabCount() - 1, "生产线");
|
||||
|
||||
|
||||
GD.Print("生产线标签创建完成");
|
||||
}
|
||||
|
||||
@ -215,27 +228,19 @@ public partial class DynamicTabManager : TabContainer
|
||||
|
||||
categoryContainer.AddChild(titleContainer);
|
||||
|
||||
// 添加小间距
|
||||
var spacer = new Control();
|
||||
spacer.CustomMinimumSize = new Vector2(0, 5);
|
||||
categoryContainer.AddChild(spacer);
|
||||
// 创建流容器来放置生产线(完全按照合成菜单的方式)
|
||||
var flowContainer = new FlowContainer();
|
||||
flowContainer.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
categoryContainer.AddChild(flowContainer);
|
||||
|
||||
// 创建生产线网格 - 使用VBoxContainer实现垂直堆叠
|
||||
var productionContainer = new VBoxContainer();
|
||||
productionContainer.Name = $"{category}ProductionLines";
|
||||
productionContainer.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
productionContainer.AddThemeConstantOverride("separation", 8); // 垂直间距
|
||||
|
||||
// 添加该分类的所有生产线
|
||||
AddProductionLinesToContainer(productionContainer, category);
|
||||
|
||||
categoryContainer.AddChild(productionContainer);
|
||||
AddProductionLinesToContainer(flowContainer, category);
|
||||
|
||||
// 添加到父容器
|
||||
parentContainer.AddChild(categoryContainer);
|
||||
}
|
||||
|
||||
private void AddProductionLinesToContainer(VBoxContainer container, string category)
|
||||
private void AddProductionLinesToContainer(FlowContainer container, string category)
|
||||
{
|
||||
GD.Print($"为分类 '{category}' 添加生产线");
|
||||
|
||||
@ -298,7 +303,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
labelSpacer.CustomMinimumSize = new Vector2(10, 0);
|
||||
titleContainer.AddChild(labelSpacer);
|
||||
|
||||
// HSeparator 横线分隔符
|
||||
// 使用HSeparator横线分隔符
|
||||
var separator = new HSeparator();
|
||||
separator.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
separator.SizeFlagsVertical = Control.SizeFlags.ShrinkCenter;
|
||||
@ -306,71 +311,46 @@ public partial class DynamicTabManager : TabContainer
|
||||
|
||||
categoryContainer.AddChild(titleContainer);
|
||||
|
||||
// 添加小间距
|
||||
var spacer = new Control();
|
||||
spacer.CustomMinimumSize = new Vector2(0, 5);
|
||||
categoryContainer.AddChild(spacer);
|
||||
|
||||
// 创建物品网格 - 使用HFlowContainer实现自适应宽度
|
||||
var flowContainer = new HFlowContainer();
|
||||
flowContainer.Name = $"{category.CategoryName}Grid";
|
||||
// 创建流容器来放置物品
|
||||
var flowContainer = new FlowContainer();
|
||||
flowContainer.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
flowContainer.AddThemeConstantOverride("h_separation", 10); // 水平间距
|
||||
flowContainer.AddThemeConstantOverride("v_separation", 8); // 垂直间距
|
||||
|
||||
// 添加该分类的所有物品
|
||||
AddItemsToFlow(flowContainer, category.CategoryName, tabType);
|
||||
|
||||
categoryContainer.AddChild(flowContainer);
|
||||
|
||||
// 添加到父容器
|
||||
parentContainer.AddChild(categoryContainer);
|
||||
}
|
||||
|
||||
private void AddItemsToFlow(HFlowContainer flowContainer, string categoryName, string tabType)
|
||||
{
|
||||
GD.Print($"为分类 '{categoryName}' 添加物品到流容器,标签类型: {tabType}");
|
||||
|
||||
var categoryManager = ResourceCategoryManager.Instance;
|
||||
if (categoryManager == null)
|
||||
// 获取分类中的物品数据
|
||||
var items = ResourceCategoryManager.Instance?.GetItemsByCategory(category.CategoryName);
|
||||
if (items == null)
|
||||
{
|
||||
GD.PrintErr("ResourceCategoryManager 实例为null");
|
||||
GD.PrintErr($"无法获取分类 {category.CategoryName} 的物品数据");
|
||||
return;
|
||||
}
|
||||
|
||||
var items = categoryManager.GetItemsByCategory(categoryName);
|
||||
GD.Print($"分类 '{categoryName}' 中有 {items.Count} 个物品");
|
||||
GD.Print($"分类 {category.CategoryName} 包含 {items.Count} 个物品");
|
||||
|
||||
foreach (var kvp in items)
|
||||
// 为每个物品创建对应的面板
|
||||
foreach (var itemPair in items)
|
||||
{
|
||||
var itemId = kvp.Key;
|
||||
var itemData = kvp.Value;
|
||||
|
||||
GD.Print($"创建物品面板: {itemId} - {itemData.Name}");
|
||||
string itemId = itemPair.Key;
|
||||
var itemData = itemPair.Value;
|
||||
string categoryName = category.CategoryName;
|
||||
|
||||
Control itemPanel;
|
||||
|
||||
// 手动采集始终使用ItemPanel(保持按住采集功能)
|
||||
|
||||
// 手动采集使用新的ManualCollectionItem
|
||||
if (categoryName == "手动采集")
|
||||
{
|
||||
// 手动采集使用ItemPanel
|
||||
itemPanel = itemPanelScene.Instantiate<Control>();
|
||||
// 使用专门的手动采集场景
|
||||
itemPanel = manualCollectionItemScene.Instantiate<ManualCollectionItem>();
|
||||
if (itemPanel == null)
|
||||
{
|
||||
GD.PrintErr($"无法实例化ItemPanel for {itemId}");
|
||||
GD.PrintErr($"无法实例化ManualCollectionItem for {itemId}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 添加手动采集脚本
|
||||
var manualCollectionScript = new ManualCollectionPanel();
|
||||
manualCollectionScript.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.FullRect);
|
||||
manualCollectionScript.MouseFilter = Control.MouseFilterEnum.Stop; // 拦截鼠标事件
|
||||
itemPanel.AddChild(manualCollectionScript);
|
||||
manualCollectionScript.SetItemId(itemId);
|
||||
GD.Print($"为 {itemId} 添加手动采集功能");
|
||||
// 设置手动采集物品数据
|
||||
var manualCollectionItem = itemPanel as ManualCollectionItem;
|
||||
manualCollectionItem?.SetupItem(itemId, itemData);
|
||||
|
||||
// 设置物品数据(手动采集不是生产设备)
|
||||
SetupItemPanel(itemPanel, itemData, false);
|
||||
GD.Print($"为 {itemId} 创建手动采集面板");
|
||||
}
|
||||
// 其他合成物品根据标签类型选择面板
|
||||
else if (tabType == "合成")
|
||||
@ -382,7 +362,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
GD.PrintErr($"无法实例化CraftingItem for {itemId}");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// 设置合成物品数据
|
||||
SetupCraftingItem(itemPanel, itemData, categoryName);
|
||||
}
|
||||
@ -406,6 +386,11 @@ public partial class DynamicTabManager : TabContainer
|
||||
// 添加到流容器
|
||||
flowContainer.AddChild(itemPanel);
|
||||
}
|
||||
|
||||
// 添加分类块到父容器
|
||||
parentContainer.AddChild(categoryContainer);
|
||||
|
||||
GD.Print($"成功创建分类块: {category.CategoryName},包含 {items.Count} 个物品");
|
||||
}
|
||||
|
||||
private void SetupItemPanel(Control itemPanel, GameData.ItemData itemData, bool isProductionDevice = true)
|
||||
@ -417,34 +402,27 @@ public partial class DynamicTabManager : TabContainer
|
||||
if (iconTexture != null && !string.IsNullOrEmpty(itemData.IconPath))
|
||||
{
|
||||
// 检查文件是否存在
|
||||
if (Godot.FileAccess.FileExists(itemData.IconPath))
|
||||
if (ResourceLoader.Exists(itemData.IconPath))
|
||||
{
|
||||
var texture = GD.Load<Texture2D>(itemData.IconPath);
|
||||
if (texture != null)
|
||||
// 尝试加载为Texture2D资源
|
||||
var resource = ResourceLoader.Load(itemData.IconPath);
|
||||
if (resource is Texture2D texture)
|
||||
{
|
||||
iconTexture.Texture = texture;
|
||||
GD.Print($"设置图标成功: {itemData.IconPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr($"无法加载图标: {itemData.IconPath}");
|
||||
GD.PrintErr($"资源不是Texture2D类型: {itemData.IconPath}");
|
||||
LoadDefaultIcon(iconTexture);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"图标文件不存在: {itemData.IconPath},使用默认图标");
|
||||
// 默认使用icon.svg
|
||||
var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
|
||||
if (defaultIcon != null)
|
||||
{
|
||||
iconTexture.Texture = defaultIcon;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr("无法加载默认图标-1");
|
||||
}
|
||||
LoadDefaultIcon(iconTexture);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 设置名称
|
||||
@ -525,23 +503,25 @@ public partial class DynamicTabManager : TabContainer
|
||||
if (iconTexture != null && !string.IsNullOrEmpty(itemData.IconPath))
|
||||
{
|
||||
// 检查文件是否存在
|
||||
if (Godot.FileAccess.FileExists(itemData.IconPath))
|
||||
if (ResourceLoader.Exists(itemData.IconPath))
|
||||
{
|
||||
var texture = GD.Load<Texture2D>(itemData.IconPath);
|
||||
if (texture != null)
|
||||
// 尝试加载为Texture2D资源
|
||||
var resource = ResourceLoader.Load(itemData.IconPath);
|
||||
if (resource is Texture2D texture)
|
||||
{
|
||||
iconTexture.Texture = texture;
|
||||
GD.Print($"设置合成物品图标成功: {itemData.IconPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadDefaultIconForCrafting(iconTexture);
|
||||
GD.PrintErr($"资源不是Texture2D类型: {itemData.IconPath}");
|
||||
LoadDefaultIcon(iconTexture);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"合成物品图标文件不存在: {itemData.IconPath},使用默认图标");
|
||||
LoadDefaultIconForCrafting(iconTexture);
|
||||
LoadDefaultIcon(iconTexture);
|
||||
}
|
||||
}
|
||||
|
||||
@ -565,14 +545,15 @@ public partial class DynamicTabManager : TabContainer
|
||||
{
|
||||
// 显示第一个材料,如果有多个材料可以显示"..."
|
||||
var firstIngredient = recipe.Ingredients[0];
|
||||
var itemName = GameData.Instance?.GetItem(firstIngredient.ItemId)?.Name ?? firstIngredient.ItemId;
|
||||
|
||||
if (recipe.Ingredients.Count == 1)
|
||||
|
||||
|
||||
if (recipe.Ingredients.Count <= 3)
|
||||
{
|
||||
materialsLabel.Text = $"材料: {firstIngredient.Quantity}x{itemName}";
|
||||
materialsLabel.Text = $"材料:{string.Join(" ", recipe.Ingredients.Select(s => $"{s.Quantity}x{ GameData.Instance?.GetItem(s.ItemId)?.Name ?? s.ItemId}"))}";
|
||||
}
|
||||
else
|
||||
{
|
||||
var itemName = GameData.Instance?.GetItem(firstIngredient.ItemId)?.Name ?? firstIngredient.ItemId;
|
||||
materialsLabel.Text = $"材料: {firstIngredient.Quantity}x{itemName}...";
|
||||
}
|
||||
}
|
||||
@ -635,7 +616,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
craftButton.Disabled = false;
|
||||
craftButton.Text = "合成";
|
||||
craftButton.Modulate = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
|
||||
// 连接按钮点击事件
|
||||
craftButton.Pressed += () => OnCraftButtonPressed(itemData.Id, craftingItem);
|
||||
}
|
||||
@ -651,6 +632,19 @@ public partial class DynamicTabManager : TabContainer
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadDefaultIcon(TextureRect iconTexture)
|
||||
{
|
||||
var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
|
||||
if (defaultIcon != null)
|
||||
{
|
||||
iconTexture.Texture = defaultIcon;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr("无法加载默认图标");
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadDefaultIconForCrafting(TextureRect iconTexture)
|
||||
{
|
||||
var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
|
||||
@ -667,7 +661,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
private void OnCraftButtonPressed(string itemId, Control craftingItem)
|
||||
{
|
||||
GD.Print($"点击合成按钮: {itemId}");
|
||||
|
||||
|
||||
// 检查合成配方管理器是否可用
|
||||
if (CraftingRecipeManager.Instance == null)
|
||||
{
|
||||
@ -713,7 +707,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
{
|
||||
int currentAmount = InventoryManager.Instance?.GetItemQuantity(ingredient.ItemId) ?? 0;
|
||||
int requiredAmount = ingredient.Quantity * quantity;
|
||||
|
||||
|
||||
if (currentAmount < requiredAmount)
|
||||
{
|
||||
canCraftAll = false;
|
||||
@ -764,7 +758,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
}
|
||||
|
||||
// 尝试通过路径查找CraftingQueueManager
|
||||
var craftingQueue = gameScene.GetNode<CraftingQueueManager>("HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue");
|
||||
var craftingQueue = gameScene.GetNode<CraftingQueueManager>("HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue");
|
||||
if (craftingQueue == null)
|
||||
{
|
||||
GD.PrintErr("无法找到CraftingQueueManager节点");
|
||||
@ -785,12 +779,12 @@ public partial class DynamicTabManager : TabContainer
|
||||
{
|
||||
// 设置初始值
|
||||
quantityInput.Text = "1";
|
||||
|
||||
|
||||
// 如果没有配方,禁用数量控制
|
||||
quantityInput.Editable = hasRecipe;
|
||||
minusButton.Disabled = !hasRecipe;
|
||||
plusButton.Disabled = !hasRecipe;
|
||||
|
||||
|
||||
if (!hasRecipe)
|
||||
{
|
||||
quantityInput.Modulate = new Color(0.6f, 0.6f, 0.6f, 1.0f);
|
||||
@ -799,7 +793,8 @@ public partial class DynamicTabManager : TabContainer
|
||||
}
|
||||
|
||||
// 连接减号按钮事件
|
||||
minusButton.Pressed += () => {
|
||||
minusButton.Pressed += () =>
|
||||
{
|
||||
int currentValue = GetQuantityValue(quantityInput);
|
||||
if (currentValue > 1)
|
||||
{
|
||||
@ -808,7 +803,8 @@ public partial class DynamicTabManager : TabContainer
|
||||
};
|
||||
|
||||
// 连接加号按钮事件
|
||||
plusButton.Pressed += () => {
|
||||
plusButton.Pressed += () =>
|
||||
{
|
||||
int currentValue = GetQuantityValue(quantityInput);
|
||||
if (currentValue < 99) // 限制最大值为99
|
||||
{
|
||||
@ -817,7 +813,8 @@ public partial class DynamicTabManager : TabContainer
|
||||
};
|
||||
|
||||
// 连接输入框文本变化事件
|
||||
quantityInput.TextChanged += (string newText) => {
|
||||
quantityInput.TextChanged += (string newText) =>
|
||||
{
|
||||
ValidateQuantityInput(quantityInput, newText);
|
||||
};
|
||||
}
|
||||
|
||||
327
scripts/ui/ManualCollectionItem.cs
Normal file
327
scripts/ui/ManualCollectionItem.cs
Normal file
@ -0,0 +1,327 @@
|
||||
using Godot;
|
||||
|
||||
public partial class ManualCollectionItem : Panel
|
||||
{
|
||||
// 采集相关参数
|
||||
private const float COLLECTION_TIME = 1.0f; // 采集时间1秒
|
||||
|
||||
// 状态变量
|
||||
private bool isCollecting = false;
|
||||
private float collectionProgress = 0.0f;
|
||||
private string itemId;
|
||||
private GameData.ItemData itemData;
|
||||
|
||||
// UI组件引用
|
||||
private TextureRect iconTexture;
|
||||
private Label nameLabel;
|
||||
private Label statusLabel;
|
||||
private ColorRect progressFill;
|
||||
|
||||
// 进度条颜色
|
||||
private Color defaultProgressColor = new Color(0.3f, 0.8f, 0.3f, 1.0f); // 绿色
|
||||
private Color collectingProgressColor = new Color(1.0f, 0.8f, 0.3f, 1.0f); // 采集时的橙色
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// 获取UI组件引用
|
||||
iconTexture = GetNode<TextureRect>("MarginContainer/VBoxContainer/TopRow/IconTexture");
|
||||
nameLabel = GetNode<Label>("MarginContainer/VBoxContainer/TopRow/InfoContainer/NameLabel");
|
||||
statusLabel = GetNode<Label>("MarginContainer/VBoxContainer/TopRow/InfoContainer/StatusLabel");
|
||||
progressFill = GetNode<ColorRect>("MarginContainer/VBoxContainer/ProgressContainer/ProgressFill");
|
||||
|
||||
// 瞬间采集模式不需要设置进度条初始颜色
|
||||
// progressFill.Color = defaultProgressColor;
|
||||
|
||||
// 连接鼠标事件
|
||||
GuiInput += OnGuiInput;
|
||||
|
||||
// 如果物品数据已经设置,现在应用它
|
||||
if (itemData != null)
|
||||
{
|
||||
ApplyItemData();
|
||||
}
|
||||
|
||||
GD.Print("ManualCollectionItem _Ready 完成");
|
||||
}
|
||||
|
||||
public void SetupItem(string id, GameData.ItemData data)
|
||||
{
|
||||
itemId = id;
|
||||
itemData = data;
|
||||
|
||||
// 如果UI组件还没有初始化,延迟设置
|
||||
if (nameLabel == null)
|
||||
{
|
||||
GD.Print("UI组件还未初始化,延迟设置手动采集物品数据");
|
||||
CallDeferred(nameof(ApplyItemData));
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyItemData();
|
||||
}
|
||||
|
||||
private void ApplyItemData()
|
||||
{
|
||||
if (itemData == null)
|
||||
{
|
||||
GD.PrintErr("itemData为null,无法应用数据");
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保UI组件已初始化
|
||||
if (nameLabel == null)
|
||||
{
|
||||
GD.PrintErr("nameLabel仍然为null,UI初始化可能失败");
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置物品名称
|
||||
nameLabel.Text = itemData.Name;
|
||||
|
||||
// 加载图标
|
||||
LoadItemIcon();
|
||||
|
||||
GD.Print($"成功设置手动采集物品: {itemData.Name}");
|
||||
}
|
||||
|
||||
private void LoadItemIcon()
|
||||
{
|
||||
if (itemData == null || iconTexture == null) return;
|
||||
|
||||
if (!string.IsNullOrEmpty(itemData.IconPath) && ResourceLoader.Exists(itemData.IconPath))
|
||||
{
|
||||
// 尝试加载为Texture2D资源
|
||||
var resource = ResourceLoader.Load(itemData.IconPath);
|
||||
if (resource is Texture2D texture)
|
||||
{
|
||||
iconTexture.Texture = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr($"资源不是Texture2D类型: {itemData.IconPath}");
|
||||
// 使用默认图标
|
||||
var defaultTexture = GD.Load<Texture2D>("res://assets/textures/icon.svg");
|
||||
if (defaultTexture != null)
|
||||
{
|
||||
iconTexture.Texture = defaultTexture;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用默认图标
|
||||
var defaultTexture = GD.Load<Texture2D>("res://assets/textures/icon.svg");
|
||||
if (defaultTexture != null)
|
||||
{
|
||||
iconTexture.Texture = defaultTexture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGuiInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton mouseEvent)
|
||||
{
|
||||
if (mouseEvent.ButtonIndex == MouseButton.Left)
|
||||
{
|
||||
// 瞬间采集模式 - 点击一次立即完成一次采集
|
||||
if (mouseEvent.Pressed)
|
||||
{
|
||||
InstantCollection();
|
||||
}
|
||||
|
||||
// 原来的进度条采集模式(已注释)
|
||||
/*
|
||||
// 点击采集模式 - 只在按下时触发一次采集
|
||||
if (mouseEvent.Pressed)
|
||||
{
|
||||
StartSingleCollection();
|
||||
}
|
||||
|
||||
// 按住采集模式(已注释)
|
||||
if (mouseEvent.Pressed)
|
||||
{
|
||||
// 开始采集
|
||||
StartCollection();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 停止采集
|
||||
StopCollection();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:瞬间采集方法
|
||||
private void InstantCollection()
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemId)) return;
|
||||
|
||||
// 添加物品到库存
|
||||
if (InventoryManager.Instance != null)
|
||||
{
|
||||
InventoryManager.Instance.AddItem(itemId, 1);
|
||||
GD.Print($"瞬间采集完成,获得: {itemData?.Name ?? itemId} x1");
|
||||
}
|
||||
|
||||
// 简单的视觉反馈 - 短暂改变状态文本
|
||||
if (statusLabel != null)
|
||||
{
|
||||
statusLabel.Text = "采集!";
|
||||
statusLabel.Modulate = collectingProgressColor;
|
||||
|
||||
// 0.1秒后恢复状态
|
||||
GetTree().CreateTimer(0.1).Timeout += () => {
|
||||
if (statusLabel != null)
|
||||
{
|
||||
statusLabel.Text = "点击采集";
|
||||
statusLabel.Modulate = new Color(0.7f, 0.9f, 0.7f, 1.0f);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:单次点击采集方法
|
||||
private void StartSingleCollection()
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemId)) return;
|
||||
|
||||
// 如果正在采集中,忽略点击
|
||||
if (isCollecting) return;
|
||||
|
||||
isCollecting = true;
|
||||
collectionProgress = 0.0f;
|
||||
|
||||
// 更新状态标签和进度条颜色
|
||||
if (statusLabel != null)
|
||||
{
|
||||
statusLabel.Text = "采集中...";
|
||||
statusLabel.Modulate = collectingProgressColor;
|
||||
}
|
||||
|
||||
if (progressFill != null)
|
||||
{
|
||||
progressFill.Color = collectingProgressColor;
|
||||
}
|
||||
|
||||
GD.Print($"开始采集: {itemData?.Name ?? itemId}");
|
||||
}
|
||||
|
||||
private void CompleteCollection()
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemId)) return;
|
||||
|
||||
// 添加物品到库存
|
||||
if (InventoryManager.Instance != null)
|
||||
{
|
||||
InventoryManager.Instance.AddItem(itemId, 1);
|
||||
GD.Print($"采集完成,获得: {itemData?.Name ?? itemId} x1");
|
||||
}
|
||||
|
||||
// 点击采集模式 - 采集完成后停止
|
||||
isCollecting = false;
|
||||
collectionProgress = 0.0f;
|
||||
UpdateStatusDisplay();
|
||||
|
||||
// 按住采集模式的连续采集逻辑(已注释但保留)
|
||||
/*
|
||||
// 重置采集状态
|
||||
collectionProgress = 0.0f;
|
||||
|
||||
// 如果还在按住,继续下一轮采集
|
||||
if (isCollecting)
|
||||
{
|
||||
GD.Print($"继续采集: {itemData?.Name ?? itemId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 恢复状态显示
|
||||
UpdateStatusDisplay();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void UpdateStatusDisplay()
|
||||
{
|
||||
if (statusLabel != null)
|
||||
{
|
||||
statusLabel.Text = "点击采集";
|
||||
statusLabel.Modulate = new Color(0.7f, 0.9f, 0.7f, 1.0f);
|
||||
}
|
||||
|
||||
if (progressFill != null)
|
||||
{
|
||||
progressFill.Color = defaultProgressColor;
|
||||
if (!isCollecting)
|
||||
{
|
||||
progressFill.AnchorRight = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateProgressBar()
|
||||
{
|
||||
if (progressFill != null)
|
||||
{
|
||||
if (isCollecting)
|
||||
{
|
||||
// 采集中显示当前进度
|
||||
progressFill.AnchorRight = collectionProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 非采集状态显示0进度
|
||||
progressFill.AnchorRight = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
// 瞬间采集模式不需要进度条更新
|
||||
// 原来的进度条更新逻辑(已注释)
|
||||
/*
|
||||
if (isCollecting)
|
||||
{
|
||||
// 更新采集进度
|
||||
collectionProgress += (float)delta / COLLECTION_TIME;
|
||||
|
||||
// 限制进度在0-1之间
|
||||
collectionProgress = Mathf.Clamp(collectionProgress, 0.0f, 1.0f);
|
||||
|
||||
// 更新进度条显示
|
||||
UpdateProgressBar();
|
||||
|
||||
// 检查是否完成采集
|
||||
if (collectionProgress >= 1.0f)
|
||||
{
|
||||
CompleteCollection();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
// 清理事件
|
||||
GuiInput -= OnGuiInput;
|
||||
}
|
||||
|
||||
// 按住采集相关方法(已注释但保留)
|
||||
/*
|
||||
private void StopCollection()
|
||||
{
|
||||
if (!isCollecting) return;
|
||||
|
||||
isCollecting = false;
|
||||
collectionProgress = 0.0f;
|
||||
|
||||
// 恢复状态显示
|
||||
UpdateStatusDisplay();
|
||||
|
||||
GD.Print($"停止采集: {itemData?.Name ?? itemId}");
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -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