添加基础的生产线内容-不少bug

This commit is contained in:
2025-06-17 00:05:47 +08:00
parent 7a6cd423fc
commit 50dc434ed9
11 changed files with 1435 additions and 17 deletions

View File

@ -43,6 +43,51 @@ public partial class GameScene : Control
{
GD.Print("GameScene _Ready 开始");
// 先初始化管理器系统确保在UI创建之前完成
InitializeManagers();
// 等待一帧确保管理器完全初始化
CallDeferred(nameof(InitializeUI));
}
private void InitializeManagers()
{
// 创建ProductionLineManager
var productionLineManager = new ProductionLineManager();
productionLineManager.Name = "ProductionLineManager";
AddChild(productionLineManager);
// 创建ProductionProcessor
var productionProcessor = new ProductionProcessor();
productionProcessor.Name = "ProductionProcessor";
AddChild(productionProcessor);
GD.Print("自动产线管理器初始化完成");
}
private void InitializeUI()
{
GD.Print("开始初始化UI");
// 测试ProductionLineManager是否正常
var productionLineManager = ProductionLineManager.Instance;
if (productionLineManager != null)
{
var allLines = productionLineManager.GetAllProductionLines();
GD.Print($"ProductionLineManager已初始化共有 {allLines.Count} 个生产线");
var categories = productionLineManager.GetAllCategories();
GD.Print($"生产线分类数: {categories.Count}");
foreach (var category in categories)
{
GD.Print($"- 分类: {category}");
}
}
else
{
GD.PrintErr("ProductionLineManager 仍然为null");
}
// 获取UI引用
powerGenerationLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerGeneration");
powerConsumptionLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerConsumption");
@ -131,6 +176,246 @@ public partial class GameScene : Control
GD.Print("按下C键尝试开始铁块合成");
}
}
// 按P键测试自动产线
if (keyEvent.Keycode == Key.P)
{
TestProductionLine();
}
// 按L键列出所有产线
if (keyEvent.Keycode == Key.L)
{
ListAllProductionLines();
}
// 按B键测试生产线UI
if (keyEvent.Keycode == Key.B)
{
TestProductionLineUI();
}
// 按R键刷新标签页
if (keyEvent.Keycode == Key.R)
{
RefreshProductionLineTabs();
}
// 按I键查看库存状态
if (keyEvent.Keycode == Key.I)
{
ShowInventoryStatus();
}
}
}
private void TestProductionLine()
{
var productionLineManager = ProductionLineManager.Instance;
if (productionLineManager == null)
{
GD.PrintErr("ProductionLineManager not found");
return;
}
// 给库存添加一些建筑和材料用于测试
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("已添加测试物品到库存");
}
// 测试添加铁矿采集产线
productionLineManager.AddBuilding("iron_ore_extraction", 1);
// 测试添加自动冶炼产线
productionLineManager.AddBuilding("iron_smelting_auto", 1);
GD.Print("已启动测试产线");
}
private void ListAllProductionLines()
{
var productionLineManager = ProductionLineManager.Instance;
if (productionLineManager == null)
{
GD.PrintErr("ProductionLineManager not found");
return;
}
var allLines = productionLineManager.GetAllProductionLines();
GD.Print($"总共有 {allLines.Count} 个产线:");
foreach (var line in allLines)
{
string requirements = "";
if (line.BuildingRequirements != null && line.BuildingRequirements.Count > 0)
{
var req = line.BuildingRequirements[0];
var item = GameData.Instance?.GetItem(req.ItemId);
requirements = $"需要: {req.Quantity}x{item?.Name ?? req.ItemId}";
if (line.BuildingRequirements.Count > 1)
{
requirements += "...";
}
}
else
{
requirements = "无需求";
}
GD.Print($"- {line.Name} ({line.Category}): {line.ProductionTime}s, {line.PowerConsumption}W, {requirements}");
}
var activeLines = productionLineManager.GetAllActiveProductionLines();
GD.Print($"活跃产线: {activeLines.Count} 个");
foreach (var kvp in activeLines)
{
var activeLine = kvp.Value;
if (activeLine.IsActive)
{
var line = productionLineManager.GetProductionLine(activeLine.ProductionLineId);
GD.Print($" 活跃: {line?.Name} - {activeLine.BuildingCount} 个建筑, {activeLine.ProductionRate:F2}/s");
}
}
}
private void TestProductionLineUI()
{
// 给库存添加一些建筑用于测试
var inventoryManager = InventoryManager.Instance;
if (inventoryManager != null)
{
// 建筑设施
inventoryManager.AddItem("mining_drill", 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个化工厂
// 原材料
inventoryManager.AddItem("iron_ore", 50); // 添加50个铁矿
inventoryManager.AddItem("copper_ore", 40); // 添加40个铜矿
inventoryManager.AddItem("coal_ore", 60); // 添加60个煤矿修正ID
inventoryManager.AddItem("stone_ore", 80); // 添加80个石矿修正ID
inventoryManager.AddItem("water", 100); // 添加100个水
inventoryManager.AddItem("crude_oil", 30); // 添加30个原油
// 加工材料
inventoryManager.AddItem("iron_ingot", 25); // 添加25个铁块
inventoryManager.AddItem("copper_ingot", 20); // 添加20个铜块
GD.Print("已添加测试建筑设施和材料到库存:");
GD.Print("建筑设施: 钻机x10, 熔炉x8, 冶炼厂x5, 采矿机x6, 组装机x3, 化工厂x2");
GD.Print("原材料: 铁矿x50, 铜矿x40, 煤矿x60, 石矿x80, 水x100, 原油x30");
GD.Print("加工材料: 铁块x25, 铜块x20");
GD.Print("现在可以在生产线和合成标签中测试各种功能了!");
}
}
private void RefreshProductionLineTabs()
{
GD.Print("刷新生产线标签页");
if (categoryTabs != null)
{
var dynamicTabManager = categoryTabs as DynamicTabManager;
if (dynamicTabManager != null)
{
dynamicTabManager.RefreshTabs();
GD.Print("已刷新标签页");
}
else
{
GD.PrintErr("categoryTabs 不是 DynamicTabManager 类型");
}
}
else
{
GD.PrintErr("categoryTabs 为null");
}
}
private void ShowInventoryStatus()
{
GD.Print("=== 当前库存状态 ===");
var inventoryManager = InventoryManager.Instance;
if (inventoryManager == null)
{
GD.PrintErr("InventoryManager 实例为null");
return;
}
// 获取所有物品类别并显示库存
var gameData = GameData.Instance;
if (gameData == null)
{
GD.PrintErr("GameData 实例为null");
return;
}
var allItems = gameData.GetAllItems();
bool hasItems = false;
GD.Print("建筑设施:");
foreach (var kvp in allItems)
{
var itemId = kvp.Key;
var itemData = kvp.Value;
if (itemData.Category == GameData.ItemCategory.Building || itemData.Category == GameData.ItemCategory.ProductionDevice)
{
int quantity = inventoryManager.GetItemQuantity(itemId);
if (quantity > 0)
{
GD.Print($" {itemData.Name}: {quantity} 个");
hasItems = true;
}
}
}
GD.Print("原材料:");
foreach (var kvp in allItems)
{
var itemId = kvp.Key;
var itemData = kvp.Value;
if (itemData.Category == GameData.ItemCategory.RawMaterial)
{
int quantity = inventoryManager.GetItemQuantity(itemId);
if (quantity > 0)
{
GD.Print($" {itemData.Name}: {quantity} 个");
hasItems = true;
}
}
}
GD.Print("加工材料:");
foreach (var kvp in allItems)
{
var itemId = kvp.Key;
var itemData = kvp.Value;
if (itemData.Category == GameData.ItemCategory.ProcessedMaterial)
{
int quantity = inventoryManager.GetItemQuantity(itemId);
if (quantity > 0)
{
GD.Print($" {itemData.Name}: {quantity} 个");
hasItems = true;
}
}
}
if (!hasItems)
{
GD.Print("库存为空按B键添加测试物品");
}
GD.Print("=================");
}
}