diff --git a/data/config/inventory_categories.json b/data/config/inventory_categories.json index 9bbd156..7ba47d9 100644 --- a/data/config/inventory_categories.json +++ b/data/config/inventory_categories.json @@ -6,7 +6,9 @@ "iron_ore", "copper_ore", "coal_ore", - "water" + "stone_ore", + "water", + "crude_oil" ] }, { @@ -15,6 +17,17 @@ "iron_ingot", "copper_ingot" ] + }, + { + "categoryName": "建筑设施", + "items": [ + "mining_drill", + "furnace", + "smelter", + "miner", + "assembler", + "chemical_plant" + ] } ] } \ No newline at end of file diff --git a/data/config/items.csv b/data/config/items.csv index bb30920..09ad178 100644 --- a/data/config/items.csv +++ b/data/config/items.csv @@ -7,6 +7,8 @@ water,水,RawMaterial,基础资源,可用于多种生产,null,0,0,res://assets crude_oil,原油,RawMaterial,重要的能源资源,可用于生产燃料,null,0,0,res://assets/textures/items/crude_oil.png iron_ingot,铁块,ProcessedMaterial,由铁矿冶炼而成的基础材料,iron_ore:1,1.0,60.0,res://assets/textures/items/iron_ingot.png copper_ingot,铜块,ProcessedMaterial,由铜矿冶炼而成的基础材料,copper_ore:1,1.0,60.0,res://assets/textures/items/copper_ingot.png +mining_drill,钻机,Building,自动采集矿石的钻探设备,iron_ingot:5;copper_ingot:3,4.0,300.0,res://assets/textures/buildings/mining_drill.png +furnace,熔炉,Building,自动冶炼矿石的熔炉设备,iron_ingot:4;stone_ore:2,3.5,250.0,res://assets/textures/buildings/furnace.png smelter,冶炼厂,Building,用于冶炼矿石的基础建筑,iron_ingot:4;copper_ingot:2,3.0,360.0,res://assets/textures/buildings/smelter.png miner,采矿机,Building,自动采集矿石的基础建筑,iron_ingot:3;copper_ingot:1,2.0,420.0,res://assets/textures/buildings/miner.png assembler,组装机,ProductionDevice,高级生产设备,可制造复杂物品,iron_ingot:6;copper_ingot:4,5.0,480.0,res://assets/textures/buildings/assembler.png diff --git a/data/config/production_lines.json b/data/config/production_lines.json new file mode 100644 index 0000000..419d2ec --- /dev/null +++ b/data/config/production_lines.json @@ -0,0 +1,152 @@ +{ + "ProductionLines": [ + { + "id": "iron_ore_extraction", + "name": "铁矿采集", + "category": "资源采集", + "description": "自动采集铁矿石", + "productionTime": 2.0, + "powerConsumption": 10, + "buildingRequirements": [ + { + "itemId": "mining_drill", + "quantity": 1 + } + ], + "recipe": { + "inputs": [], + "outputs": [ + { + "itemId": "iron_ore", + "quantity": 1 + } + ] + } + }, + { + "id": "copper_ore_extraction", + "name": "铜矿采集", + "category": "资源采集", + "description": "自动采集铜矿石", + "productionTime": 2.0, + "powerConsumption": 10, + "buildingRequirements": [ + { + "itemId": "mining_drill", + "quantity": 1 + } + ], + "recipe": { + "inputs": [], + "outputs": [ + { + "itemId": "copper_ore", + "quantity": 1 + } + ] + } + }, + { + "id": "coal_extraction", + "name": "煤矿采集", + "category": "资源采集", + "description": "自动采集煤炭", + "productionTime": 1.5, + "powerConsumption": 8, + "buildingRequirements": [ + { + "itemId": "mining_drill", + "quantity": 1 + } + ], + "recipe": { + "inputs": [], + "outputs": [ + { + "itemId": "coal_ore", + "quantity": 1 + } + ] + } + }, + { + "id": "stone_extraction", + "name": "石矿采集", + "category": "资源采集", + "description": "自动采集石头", + "productionTime": 1.8, + "powerConsumption": 8, + "buildingRequirements": [ + { + "itemId": "mining_drill", + "quantity": 1 + } + ], + "recipe": { + "inputs": [], + "outputs": [ + { + "itemId": "stone_ore", + "quantity": 1 + } + ] + } + }, + { + "id": "iron_smelting_auto", + "name": "自动冶炼铁块", + "category": "冶炼加工", + "description": "使用冶炼炉自动生产铁块", + "productionTime": 3.2, + "powerConsumption": 15, + "buildingRequirements": [ + { + "itemId": "furnace", + "quantity": 1 + } + ], + "recipe": { + "inputs": [ + { + "itemId": "iron_ore", + "quantity": 1 + } + ], + "outputs": [ + { + "itemId": "iron_ingot", + "quantity": 1 + } + ] + } + }, + { + "id": "copper_smelting_auto", + "name": "自动冶炼铜块", + "category": "冶炼加工", + "description": "使用冶炼炉自动生产铜块", + "productionTime": 3.2, + "powerConsumption": 15, + "buildingRequirements": [ + { + "itemId": "furnace", + "quantity": 1 + } + ], + "recipe": { + "inputs": [ + { + "itemId": "copper_ore", + "quantity": 1 + } + ], + "outputs": [ + { + "itemId": "copper_ingot", + "quantity": 1 + } + ] + } + } + ] +} \ No newline at end of file diff --git a/data/config/resource_categories.json b/data/config/resource_categories.json index 14fc9bc..45d44a4 100644 --- a/data/config/resource_categories.json +++ b/data/config/resource_categories.json @@ -36,13 +36,10 @@ { "categoryName": "建筑设施", "itemIds": [ + "mining_drill", + "furnace", "smelter", - "miner" - ] - }, - { - "categoryName": "生产设备", - "itemIds": [ + "miner", "assembler", "chemical_plant" ] diff --git a/scenes/ProductionLineItem.tscn b/scenes/ProductionLineItem.tscn new file mode 100644 index 0000000..51b424f --- /dev/null +++ b/scenes/ProductionLineItem.tscn @@ -0,0 +1,141 @@ +[gd_scene load_steps=3 format=3 uid="uid://vao0wv2oib2a"] + +[ext_resource type="Script" path="res://scripts/ui/ProductionLineItem.cs" id="1_1"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1"] +bg_color = Color(0.15, 0.18, 0.22, 0.95) +border_width_left = 1 +border_width_top = 1 +border_width_right = 1 +border_width_bottom = 1 +border_color = Color(0.3, 0.4, 0.5, 0.8) +corner_radius_top_left = 8 +corner_radius_top_right = 8 +corner_radius_bottom_right = 8 +corner_radius_bottom_left = 8 +shadow_color = Color(0, 0, 0, 0.3) +shadow_size = 2 +shadow_offset = Vector2(1, 1) + +[node name="ProductionLineItem" type="Panel"] +custom_minimum_size = Vector2(240, 80) +theme_override_styles/panel = SubResource("StyleBoxFlat_1") +script = ExtResource("1_1") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 8 +theme_override_constants/margin_top = 6 +theme_override_constants/margin_right = 8 +theme_override_constants/margin_bottom = 6 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 +theme_override_constants/separation = 4 + +[node name="TopRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="IconTexture" type="TextureRect" parent="MarginContainer/VBoxContainer/TopRow"] +custom_minimum_size = Vector2(32, 32) +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="MiddleContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/TopRow"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 2 + +[node name="TopInfoRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer/TopRow/MiddleContainer"] +layout_mode = 2 + +[node name="NameLabel" type="Label" parent="MarginContainer/VBoxContainer/TopRow/MiddleContainer/TopInfoRow"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 12 +text = "产线名称" +vertical_alignment = 1 + +[node name="ProductionLabel" type="Label" parent="MarginContainer/VBoxContainer/TopRow/MiddleContainer/TopInfoRow"] +layout_mode = 2 +theme_override_font_sizes/font_size = 10 +text = "0/s" +horizontal_alignment = 2 + +[node name="InfoRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer/TopRow/MiddleContainer"] +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="TimeLabel" type="Label" parent="MarginContainer/VBoxContainer/TopRow/MiddleContainer/InfoRow"] +modulate = Color(0.8, 0.9, 1, 1) +layout_mode = 2 +theme_override_font_sizes/font_size = 9 +text = "2.0s" + +[node name="PowerLabel" type="Label" parent="MarginContainer/VBoxContainer/TopRow/MiddleContainer/InfoRow"] +modulate = Color(1, 0.9, 0.7, 1) +layout_mode = 2 +theme_override_font_sizes/font_size = 9 +text = "10W" + +[node name="BuildingLabel" type="Label" parent="MarginContainer/VBoxContainer/TopRow/MiddleContainer/InfoRow"] +modulate = Color(0.9, 0.8, 1, 1) +layout_mode = 2 +theme_override_font_sizes/font_size = 9 +text = "需要: 钻机" + +[node name="RightContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/TopRow"] +layout_mode = 2 + +[node name="BuildingCountRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer/TopRow/RightContainer"] +layout_mode = 2 +theme_override_constants/separation = 4 + +[node name="DeviceLabel" type="Label" parent="MarginContainer/VBoxContainer/TopRow/RightContainer/BuildingCountRow"] +layout_mode = 2 +theme_override_font_sizes/font_size = 9 +text = "设备: 0" +horizontal_alignment = 2 + +[node name="ButtonsRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer/TopRow/RightContainer"] +layout_mode = 2 +theme_override_constants/separation = 2 + +[node name="RemoveButton" type="Button" parent="MarginContainer/VBoxContainer/TopRow/RightContainer/ButtonsRow"] +custom_minimum_size = Vector2(20, 18) +layout_mode = 2 +theme_override_font_sizes/font_size = 9 +text = "-" + +[node name="AddButton" type="Button" parent="MarginContainer/VBoxContainer/TopRow/RightContainer/ButtonsRow"] +custom_minimum_size = Vector2(20, 18) +layout_mode = 2 +theme_override_font_sizes/font_size = 9 +text = "+" + +[node name="ProgressContainer" type="Control" parent="MarginContainer/VBoxContainer"] +custom_minimum_size = Vector2(0, 6) +layout_mode = 2 + +[node name="ProgressBackground" type="ColorRect" parent="MarginContainer/VBoxContainer/ProgressContainer"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.2, 0.2, 0.2, 1) + +[node name="ProgressFill" type="ColorRect" parent="MarginContainer/VBoxContainer/ProgressContainer"] +layout_mode = 1 +anchors_preset = 9 +anchor_bottom = 1.0 +grow_vertical = 2 +color = Color(0.3, 0.7, 0.9, 1) diff --git a/scripts/core/GameScene.cs b/scripts/core/GameScene.cs index e779a30..a31cbfc 100644 --- a/scripts/core/GameScene.cs +++ b/scripts/core/GameScene.cs @@ -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