生产线样式,添加图标测试
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);
|
||||
}
|
||||
|
||||
@ -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];
|
||||
|
||||
Reference in New Issue
Block a user