临时提交

This commit is contained in:
2025-06-22 20:39:47 +08:00
parent b3d1135e23
commit d274ae0fec
24 changed files with 603 additions and 50 deletions

View File

@ -62,7 +62,12 @@ public partial class GameScene : Control
productionProcessor.Name = "ProductionProcessor";
AddChild(productionProcessor);
GD.Print("自动产线管理器初始化完成");
// 创建PowerManager
var powerManager = new PowerManager();
powerManager.Name = "PowerManager";
AddChild(powerManager);
GD.Print("自动产线管理器和电力管理器初始化完成");
}
private void InitializeUI()
@ -89,12 +94,12 @@ public partial class GameScene : Control
}
// 获取UI引用
powerGenerationLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerGeneration");
powerConsumptionLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerConsumption");
powerStorageLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerStorage");
powerDischargeLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerDischarge");
categoryTabs = GetNode<TabContainer>("HSplitContainer/RightPanel/VBoxContainer/CategoryTabs");
craftingQueue = GetNode<CraftingQueueManager>("HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue");
powerGenerationLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerGeneration");
powerConsumptionLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerConsumption");
powerStorageLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerStorage");
powerDischargeLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerDischarge");
categoryTabs = GetNode<TabContainer>("HBoxContainer/RightPanel/VBoxContainer/CategoryTabs");
craftingQueue = GetNode<CraftingQueueManager>("HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue");
// 初始化库存(保留用于兼容性)
InitializeInventory();
@ -148,19 +153,53 @@ public partial class GameScene : Control
private void UpdatePowerInfo()
{
// 这里可以从电力管理器获取实际数据
// 目前使用占位符数据
if (powerGenerationLabel != null)
powerGenerationLabel.Text = "发电: 0 KW";
if (powerConsumptionLabel != null)
powerConsumptionLabel.Text = "耗电: 0 KW";
if (powerStorageLabel != null)
powerStorageLabel.Text = "蓄电: 0 KWh";
if (powerDischargeLabel != null)
powerDischargeLabel.Text = "放电: 0 KW";
// 从PowerManager获取真实的电力数据
var powerManager = PowerManager.Instance;
if (powerManager != null)
{
var (generation, consumption, ratio) = powerManager.GetPowerStats();
if (powerGenerationLabel != null)
powerGenerationLabel.Text = $"发电: {generation:F1} W";
if (powerConsumptionLabel != null)
powerConsumptionLabel.Text = $"耗电: {consumption:F1} W";
if (powerStorageLabel != null)
powerStorageLabel.Text = $"电力满足率: {ratio * 100:F1}%";
if (powerDischargeLabel != null)
{
float deficit = Mathf.Max(0, consumption - generation);
powerDischargeLabel.Text = $"电力不足: {deficit:F1} W";
// 根据电力状态设置颜色
if (deficit > 0)
{
powerDischargeLabel.Modulate = new Color(1.0f, 0.3f, 0.3f); // 红色表示不足
}
else
{
powerDischargeLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示充足
powerDischargeLabel.Text = "电力充足";
}
}
}
else
{
// PowerManager未初始化时的默认显示
if (powerGenerationLabel != null)
powerGenerationLabel.Text = "发电: 0 W";
if (powerConsumptionLabel != null)
powerConsumptionLabel.Text = "耗电: 0 W";
if (powerStorageLabel != null)
powerStorageLabel.Text = "电力满足率: 100%";
if (powerDischargeLabel != null)
powerDischargeLabel.Text = "电力充足";
}
}
public override void _Input(InputEvent @event)
@ -295,6 +334,7 @@ public partial class GameScene : Control
inventoryManager.AddItem("miner", 6); // 添加6个采矿机
inventoryManager.AddItem("assembler", 3); // 添加3个组装机
inventoryManager.AddItem("chemical_plant", 2); // 添加2个化工厂
inventoryManager.AddItem("wind_turbine", 5); // 添加5个风力发电机
// 原材料
inventoryManager.AddItem("iron_ore", 50); // 添加50个铁矿
@ -309,10 +349,12 @@ public partial class GameScene : Control
inventoryManager.AddItem("copper_ingot", 20); // 添加20个铜块
GD.Print("已添加测试建筑设施和材料到库存:");
GD.Print("建筑设施: 钻机x10, 熔炉x8, 冶炼厂x5, 采矿机x6, 组装机x3, 化工厂x2");
GD.Print("建筑设施: 钻机x10, 熔炉x8, 冶炼厂x5, 采矿机x6, 组装机x3, 化工厂x2, 风力发电机x5");
GD.Print("原材料: 铁矿x50, 铜矿x40, 煤矿x60, 石矿x80, 水x100, 原油x30");
GD.Print("加工材料: 铁块x25, 铜块x20");
GD.Print("现在可以在生产线和合成标签中测试各种功能了!");
}
}