diff --git a/assets/textures/Vanilla.png b/assets/textures/Vanilla.png new file mode 100644 index 0000000..e2f03ab Binary files /dev/null and b/assets/textures/Vanilla.png differ diff --git a/assets/textures/Vanilla.png.import b/assets/textures/Vanilla.png.import new file mode 100644 index 0000000..e8c38c1 --- /dev/null +++ b/assets/textures/Vanilla.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dqu31gnodu6dx" +path="res://.godot/imported/Vanilla.png-e047d959c482c0904984214d600a408f.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/textures/Vanilla.png" +dest_files=["res://.godot/imported/Vanilla.png-e047d959c482c0904984214d600a408f.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/textures/items/铁块.tres b/assets/textures/items/铁块.tres new file mode 100644 index 0000000..1a44941 --- /dev/null +++ b/assets/textures/items/铁块.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://dspnwr8l40k5c"] + +[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_d5s0q"] + +[resource] +atlas = ExtResource("1_d5s0q") +region = Rect2(720, 640, 80, 80) diff --git a/assets/textures/items/铜块.tres b/assets/textures/items/铜块.tres new file mode 100644 index 0000000..a4b5cb0 --- /dev/null +++ b/assets/textures/items/铜块.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://dsy5mm1nl1hxi"] + +[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_6lvrk"] + +[resource] +atlas = ExtResource("1_6lvrk") +region = Rect2(320, 400, 80, 80) diff --git a/data/config/crafting_recipes.json b/data/config/crafting_recipes.json index 1b8dc1a..adab6ef 100644 --- a/data/config/crafting_recipes.json +++ b/data/config/crafting_recipes.json @@ -12,6 +12,104 @@ "quantity": 1 } ] + }, + { + "id": "copper_ingot_smelting", + "outputItem": "copper_ingot", + "outputQuantity": 1, + "craftingMethod": "冶炼", + "craftingTime": 1.0, + "ingredients": [ + { + "itemId": "copper_ore", + "quantity": 1 + } + ] + }, + { + "id": "magnet_crafting", + "outputItem": "magnet", + "outputQuantity": 1, + "craftingMethod": "制作", + "craftingTime": 1.5, + "ingredients": [ + { + "itemId": "iron_ore", + "quantity": 2 + } + ] + }, + { + "id": "gear_crafting", + "outputItem": "gear", + "outputQuantity": 1, + "craftingMethod": "制作", + "craftingTime": 2.0, + "ingredients": [ + { + "itemId": "iron_ingot", + "quantity": 1 + } + ] + }, + { + "id": "magnetic_coil_crafting", + "outputItem": "magnetic_coil", + "outputQuantity": 2, + "craftingMethod": "制作", + "craftingTime": 3.0, + "ingredients": [ + { + "itemId": "magnet", + "quantity": 2 + }, + { + "itemId": "copper_ingot", + "quantity": 1 + } + ] + }, + { + "id": "circuit_board_crafting", + "outputItem": "circuit_board", + "outputQuantity": 2, + "craftingMethod": "制作", + "craftingTime": 2.5, + "ingredients": [ + { + "itemId": "iron_ingot", + "quantity": 2 + }, + { + "itemId": "copper_ingot", + "quantity": 1 + } + ] + }, + { + "id": "miner_crafting", + "outputItem": "miner", + "outputQuantity": 1, + "craftingMethod": "组装", + "craftingTime": 8.0, + "ingredients": [ + { + "itemId": "iron_ingot", + "quantity": 4 + }, + { + "itemId": "circuit_board", + "quantity": 2 + }, + { + "itemId": "magnetic_coil", + "quantity": 2 + }, + { + "itemId": "gear", + "quantity": 2 + } + ] } ] } \ No newline at end of file diff --git a/data/config/inventory_categories.json b/data/config/inventory_categories.json index 7ba47d9..1845f77 100644 --- a/data/config/inventory_categories.json +++ b/data/config/inventory_categories.json @@ -18,12 +18,20 @@ "copper_ingot" ] }, + { + "categoryName": "制作物品", + "items": [ + "magnet", + "gear", + "magnetic_coil", + "circuit_board" + ] + }, { "categoryName": "建筑设施", "items": [ "mining_drill", "furnace", - "smelter", "miner", "assembler", "chemical_plant" diff --git a/data/config/items.csv b/data/config/items.csv index 09ad178..724f99e 100644 --- a/data/config/items.csv +++ b/data/config/items.csv @@ -5,9 +5,13 @@ stone_ore,石矿,RawMaterial,基础建筑材料,可用于建造建筑,null,0,0 coal_ore,煤矿,RawMaterial,重要的能源资源,可用于发电,null,0,0,res://assets/textures/items/coal_ore.png water,水,RawMaterial,基础资源,可用于多种生产,null,0,0,res://assets/textures/items/water.png 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 +iron_ingot,铁块,ProcessedMaterial,由铁矿冶炼而成的基础材料,iron_ore:1,1.0,60.0,res://assets/textures/items/铁块.tres +copper_ingot,铜块,ProcessedMaterial,由铜矿冶炼而成的基础材料,copper_ore:1,1.0,60.0,res://assets/textures/items/铜块.tres +magnet,磁铁,ProcessedMaterial,由铁矿制作的磁性材料,用于制造电机等设备,iron_ore:2,1.5,0,res://assets/textures/items/magnet.png +gear,齿轮,ProcessedMaterial,由铁块制作的机械部件,用于制造复杂设备,iron_ingot:1,2.0,0,res://assets/textures/items/gear.png +magnetic_coil,磁线圈,Component,由磁铁和铜块制作的电磁组件,用于制造高级设备,magnet:2;copper_ingot:1,3.0,0,res://assets/textures/items/magnetic_coil.png +circuit_board,电路板,Component,由铁块和铜块制作的电子组件,用于制造高级设备,iron_ingot:2;copper_ingot:1,2.5,0,res://assets/textures/items/circuit_board.png +drill_machine,钻机,ProductionDevice,由多种组件制作的高级钻探设备,效率更高,iron_ingot:4;circuit_board:2;magnetic_coil:2;gear:2,8.0,500.0,res://assets/textures/items/drill_machine.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 diff --git a/data/config/production_lines.json b/data/config/production_lines.json index 419d2ec..6ad7939 100644 --- a/data/config/production_lines.json +++ b/data/config/production_lines.json @@ -9,7 +9,7 @@ "powerConsumption": 10, "buildingRequirements": [ { - "itemId": "mining_drill", + "itemId": "miner", "quantity": 1 } ], @@ -32,7 +32,7 @@ "powerConsumption": 10, "buildingRequirements": [ { - "itemId": "mining_drill", + "itemId": "miner", "quantity": 1 } ], @@ -55,7 +55,7 @@ "powerConsumption": 8, "buildingRequirements": [ { - "itemId": "mining_drill", + "itemId": "miner", "quantity": 1 } ], @@ -78,7 +78,7 @@ "powerConsumption": 8, "buildingRequirements": [ { - "itemId": "mining_drill", + "itemId": "miner", "quantity": 1 } ], diff --git a/data/config/resource_categories.json b/data/config/resource_categories.json index 45d44a4..d7c50fe 100644 --- a/data/config/resource_categories.json +++ b/data/config/resource_categories.json @@ -33,15 +33,23 @@ "copper_ingot" ] }, + { + "categoryName": "制作物品", + "itemIds": [ + "magnet", + "gear", + "magnetic_coil", + "circuit_board" + ] + }, { "categoryName": "建筑设施", "itemIds": [ - "mining_drill", "furnace", - "smelter", "miner", "assembler", - "chemical_plant" + "chemical_plant", + "miner" ] } ] \ No newline at end of file diff --git a/scenes/CraftingQueue.tscn b/scenes/CraftingQueue.tscn index a1e2a04..4b069a9 100644 --- a/scenes/CraftingQueue.tscn +++ b/scenes/CraftingQueue.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=2 format=3 uid="uid://bvn8xh2ywxe"] +[gd_scene load_steps=2 format=3 uid="uid://buswnr7ncyh4c"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1"] bg_color = Color(0.15, 0.15, 0.2, 0.8) @@ -21,6 +21,8 @@ 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 = 10 theme_override_constants/margin_top = 8 theme_override_constants/margin_right = 10 @@ -31,9 +33,9 @@ layout_mode = 2 [node name="TitleLabel" type="Label" parent="MarginContainer/VBoxContainer"] layout_mode = 2 +theme_override_font_sizes/font_size = 12 text = "合成队列" horizontal_alignment = 1 -theme_override_font_sizes/font_size = 12 [node name="HSeparator" type="HSeparator" parent="MarginContainer/VBoxContainer"] layout_mode = 2 @@ -66,4 +68,4 @@ size_flags_horizontal = 3 [node name="Slot5" type="Panel" parent="MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(48, 48) layout_mode = 2 -size_flags_horizontal = 3 \ No newline at end of file +size_flags_horizontal = 3 diff --git a/scenes/ManualCollectionItem.tscn b/scenes/ManualCollectionItem.tscn new file mode 100644 index 0000000..0e0e7e6 --- /dev/null +++ b/scenes/ManualCollectionItem.tscn @@ -0,0 +1,89 @@ +[gd_scene load_steps=3 format=3 uid="uid://dai5u7qk43gp6"] + +[ext_resource type="Script" path="res://scripts/ui/ManualCollectionItem.cs" id="1_x7y8z"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1"] +bg_color = Color(0.12, 0.15, 0.18, 0.95) +border_width_left = 1 +border_width_top = 1 +border_width_right = 1 +border_width_bottom = 1 +border_color = Color(0.2, 0.5, 0.2, 0.8) +corner_radius_top_left = 6 +corner_radius_top_right = 6 +corner_radius_bottom_right = 6 +corner_radius_bottom_left = 6 +shadow_color = Color(0, 0, 0, 0.2) +shadow_size = 1 +shadow_offset = Vector2(1, 1) + +[node name="ManualCollectionItem" type="Panel"] +custom_minimum_size = Vector2(130, 43) +theme_override_styles/panel = SubResource("StyleBoxFlat_1") +script = ExtResource("1_x7y8z") + +[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 = 5 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 5 +theme_override_constants/margin_bottom = 4 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 +theme_override_constants/separation = 3 + +[node name="TopRow" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_constants/separation = 5 + +[node name="IconTexture" type="TextureRect" parent="MarginContainer/VBoxContainer/TopRow"] +custom_minimum_size = Vector2(24, 24) +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="InfoContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/TopRow"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 0 + +[node name="NameLabel" type="Label" parent="MarginContainer/VBoxContainer/TopRow/InfoContainer"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.9, 1, 0.9, 1) +theme_override_font_sizes/font_size = 10 +text = "物品名称" +vertical_alignment = 1 + +[node name="StatusLabel" type="Label" parent="MarginContainer/VBoxContainer/TopRow/InfoContainer"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.7, 0.9, 0.7, 1) +theme_override_font_sizes/font_size = 8 +text = "点击采集" +vertical_alignment = 1 + +[node name="ProgressContainer" type="Control" parent="MarginContainer/VBoxContainer"] +visible = false +custom_minimum_size = Vector2(0, 4) +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.15, 0.15, 0.15, 0.8) + +[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.8, 0.3, 1) diff --git a/scenes/ProductionLineItem.tscn b/scenes/ProductionLineItem.tscn index 51b424f..9853c6f 100644 --- a/scenes/ProductionLineItem.tscn +++ b/scenes/ProductionLineItem.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://vao0wv2oib2a"] +[gd_scene load_steps=5 format=3 uid="uid://vao0wv2oib2a"] [ext_resource type="Script" path="res://scripts/ui/ProductionLineItem.cs" id="1_1"] +[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="2_o1rrk"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1"] bg_color = Color(0.15, 0.18, 0.22, 0.95) @@ -17,8 +18,12 @@ shadow_color = Color(0, 0, 0, 0.3) shadow_size = 2 shadow_offset = Vector2(1, 1) +[sub_resource type="AtlasTexture" id="AtlasTexture_cln0n"] +atlas = ExtResource("2_o1rrk") +region = Rect2(720, 640, 80, 80) + [node name="ProductionLineItem" type="Panel"] -custom_minimum_size = Vector2(240, 80) +custom_minimum_size = Vector2(250, 60) theme_override_styles/panel = SubResource("StyleBoxFlat_1") script = ExtResource("1_1") @@ -45,6 +50,7 @@ theme_override_constants/separation = 8 [node name="IconTexture" type="TextureRect" parent="MarginContainer/VBoxContainer/TopRow"] custom_minimum_size = Vector2(32, 32) layout_mode = 2 +texture = SubResource("AtlasTexture_cln0n") expand_mode = 1 stretch_mode = 5 diff --git a/scenes/game_scene.tscn b/scenes/game_scene.tscn index 0669487..fbf39b5 100644 --- a/scenes/game_scene.tscn +++ b/scenes/game_scene.tscn @@ -21,22 +21,21 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -color = Color(0.1, 0.1, 0.15, 1) +color = Color(0.670588, 0.756863, 1, 0.392157) -[node name="HSplitContainer" type="HSplitContainer" parent="."] +[node name="HBoxContainer" type="HBoxContainer" parent="."] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -split_offset = 230 -[node name="LeftPanel" type="Panel" parent="HSplitContainer"] -custom_minimum_size = Vector2(276, 0) +[node name="LeftPanel" type="Panel" parent="HBoxContainer"] +custom_minimum_size = Vector2(280, 0) layout_mode = 2 -[node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/LeftPanel"] +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/LeftPanel"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -44,11 +43,11 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -[node name="PowerInfo" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer"] +[node name="PowerInfo" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer"] custom_minimum_size = Vector2(0, 100) layout_mode = 2 -[node name="MarginContainer" type="MarginContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo"] +[node name="MarginContainer" type="MarginContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -60,51 +59,51 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 10 theme_override_constants/margin_bottom = 10 -[node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer"] layout_mode = 2 -[node name="PowerTitle" type="Label" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer"] +[node name="PowerTitle" type="Label" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer"] layout_mode = 2 text = "电力系统" horizontal_alignment = 1 -[node name="HSeparator" type="HSeparator" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer"] +[node name="HSeparator" type="HSeparator" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer"] layout_mode = 2 -[node name="PowerRow1" type="HBoxContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer"] +[node name="PowerRow1" type="HBoxContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 -[node name="PowerGeneration" type="Label" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1"] +[node name="PowerGeneration" type="Label" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1"] layout_mode = 2 size_flags_horizontal = 3 text = "发电: 0 KW" -[node name="PowerConsumption" type="Label" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1"] +[node name="PowerConsumption" type="Label" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1"] layout_mode = 2 size_flags_horizontal = 3 text = "耗电: 0 KW" -[node name="PowerRow2" type="HBoxContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer"] +[node name="PowerRow2" type="HBoxContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 -[node name="PowerStorage" type="Label" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2"] +[node name="PowerStorage" type="Label" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2"] layout_mode = 2 size_flags_horizontal = 3 text = "蓄电: 0 KWh" -[node name="PowerDischarge" type="Label" parent="HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2"] +[node name="PowerDischarge" type="Label" parent="HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2"] layout_mode = 2 size_flags_horizontal = 3 text = "放电: 0 KW" -[node name="CraftingQueue" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer"] +[node name="CraftingQueue" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer"] custom_minimum_size = Vector2(0, 80) layout_mode = 2 script = ExtResource("4_crafting_queue") -[node name="MarginContainer" type="MarginContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue"] +[node name="MarginContainer" type="MarginContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -116,68 +115,60 @@ theme_override_constants/margin_top = 8 theme_override_constants/margin_right = 10 theme_override_constants/margin_bottom = 8 -[node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer"] layout_mode = 2 -[node name="TitleLabel" type="Label" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer"] +[node name="TitleLabel" type="Label" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer"] layout_mode = 2 theme_override_font_sizes/font_size = 12 text = "合成队列" horizontal_alignment = 1 -[node name="HSeparator" type="HSeparator" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer"] +[node name="HSeparator" type="HSeparator" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer"] layout_mode = 2 -[node name="QueueContainer" type="HBoxContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer"] +[node name="QueueContainer" type="HBoxContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 theme_override_constants/separation = 2 -[node name="Slot1" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] +[node name="Slot1" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(30, 30) layout_mode = 2 -size_flags_horizontal = 3 -[node name="Slot2" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] +[node name="Slot2" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(30, 30) layout_mode = 2 -size_flags_horizontal = 3 -[node name="Slot3" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] +[node name="Slot3" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(30, 30) layout_mode = 2 -size_flags_horizontal = 3 -[node name="Slot4" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] +[node name="Slot4" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(30, 30) layout_mode = 2 -size_flags_horizontal = 3 -[node name="Slot5" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] +[node name="Slot5" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(30, 30) layout_mode = 2 -size_flags_horizontal = 3 -[node name="Slot6" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] +[node name="Slot6" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(30, 30) layout_mode = 2 -size_flags_horizontal = 3 -[node name="Slot7" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] +[node name="Slot7" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(30, 30) layout_mode = 2 -size_flags_horizontal = 3 -[node name="Slot8" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] +[node name="Slot8" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue/MarginContainer/VBoxContainer/QueueContainer"] custom_minimum_size = Vector2(30, 30) layout_mode = 2 -size_flags_horizontal = 3 -[node name="InventoryPanel" type="Panel" parent="HSplitContainer/LeftPanel/VBoxContainer"] +[node name="InventoryPanel" type="Panel" parent="HBoxContainer/LeftPanel/VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 -[node name="MarginContainer" type="MarginContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/InventoryPanel"] +[node name="MarginContainer" type="MarginContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/InventoryPanel"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -189,31 +180,32 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 10 theme_override_constants/margin_bottom = 10 -[node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer"] layout_mode = 2 -[node name="InventoryTitle" type="Label" parent="HSplitContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer/VBoxContainer"] +[node name="InventoryTitle" type="Label" parent="HBoxContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer/VBoxContainer"] layout_mode = 2 text = "库存" horizontal_alignment = 1 -[node name="HSeparator" type="HSeparator" parent="HSplitContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer/VBoxContainer"] +[node name="HSeparator" type="HSeparator" parent="HBoxContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer/VBoxContainer"] layout_mode = 2 -[node name="ScrollContainer" type="ScrollContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer/VBoxContainer"] +[node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer/VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 horizontal_scroll_mode = 0 -[node name="InventoryTableManager" type="VBoxContainer" parent="HSplitContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer/VBoxContainer/ScrollContainer"] +[node name="InventoryTableManager" type="VBoxContainer" parent="HBoxContainer/LeftPanel/VBoxContainer/InventoryPanel/MarginContainer/VBoxContainer/ScrollContainer"] layout_mode = 2 size_flags_horizontal = 3 script = ExtResource("3_inventory_table") -[node name="RightPanel" type="Panel" parent="HSplitContainer"] +[node name="RightPanel" type="Panel" parent="HBoxContainer"] layout_mode = 2 +size_flags_horizontal = 3 -[node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/RightPanel"] +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/RightPanel"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -221,7 +213,7 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -[node name="CategoryTabs" type="TabContainer" parent="HSplitContainer/RightPanel/VBoxContainer"] +[node name="CategoryTabs" type="TabContainer" parent="HBoxContainer/RightPanel/VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 theme_override_font_sizes/font_size = 24 diff --git a/scenes/test.tscn b/scenes/test.tscn index eb47169..c49c7f3 100644 --- a/scenes/test.tscn +++ b/scenes/test.tscn @@ -24,3 +24,11 @@ text = "test" [node name="HSeparator" type="HSeparator" parent="VBoxContainer/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 + +[node name="ScrollContainer" type="ScrollContainer" parent="."] +layout_mode = 0 +offset_left = 52.0 +offset_top = 53.0 +offset_right = 432.0 +offset_bottom = 342.0 +metadata/asd = false diff --git a/scripts/core/GameScene.cs b/scripts/core/GameScene.cs index a31cbfc..303785a 100644 --- a/scripts/core/GameScene.cs +++ b/scripts/core/GameScene.cs @@ -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个化工厂 diff --git a/scripts/inventory/InventoryManager.cs b/scripts/inventory/InventoryManager.cs index b49c6f1..b143433 100644 --- a/scripts/inventory/InventoryManager.cs +++ b/scripts/inventory/InventoryManager.cs @@ -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); // 添加齿轮,用于合成钻机 } // 添加物品到库存 diff --git a/scripts/inventory/InventoryTableManager.cs b/scripts/inventory/InventoryTableManager.cs index a0de36f..a418da9 100644 --- a/scripts/inventory/InventoryTableManager.cs +++ b/scripts/inventory/InventoryTableManager.cs @@ -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("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("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(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("res://assets/textures/icon.svg"); + if (defaultIcon != null) + { + iconTexture.Texture = defaultIcon; + } } } else { - // 使用默认图标 - var defaultIcon = GD.Load("res://assets/textures/icon.svg"); - if (defaultIcon != null) - { - iconTexture.Texture = defaultIcon; - } + // GD.Print($"图标文件不存在: {itemData.IconPath},使用默认图标"); + // // 使用默认图标 + // var defaultIcon = GD.Load("res://assets/textures/icon.svg"); + // if (defaultIcon != null) + // { + // iconTexture.Texture = defaultIcon; + // } } } diff --git a/scripts/production/CraftingQueueManager.cs b/scripts/production/CraftingQueueManager.cs index f15a495..8d86c84 100644 --- a/scripts/production/CraftingQueueManager.cs +++ b/scripts/production/CraftingQueueManager.cs @@ -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(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); } diff --git a/scripts/production/ManualCollectionPanel.cs b/scripts/production/ManualCollectionPanel.cs deleted file mode 100644 index 30046c9..0000000 --- a/scripts/production/ManualCollectionPanel.cs +++ /dev/null @@ -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(); - if (parent != null) - { - progressFill = parent.GetNode("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; - } -} \ No newline at end of file diff --git a/scripts/production/ProductionLineManager.cs b/scripts/production/ProductionLineManager.cs index 26b30d1..cbf292b 100644 --- a/scripts/production/ProductionLineManager.cs +++ b/scripts/production/ProductionLineManager.cs @@ -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]; diff --git a/scripts/ui/DynamicTabManager.cs b/scripts/ui/DynamicTabManager.cs index 4af988a..670f6cd 100644 --- a/scripts/ui/DynamicTabManager.cs +++ b/scripts/ui/DynamicTabManager.cs @@ -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("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(); + // 使用专门的手动采集场景 + itemPanel = manualCollectionItemScene.Instantiate(); 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(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("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(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("res://assets/textures/icon.svg"); + if (defaultIcon != null) + { + iconTexture.Texture = defaultIcon; + } + else + { + GD.PrintErr("无法加载默认图标"); + } + } + private void LoadDefaultIconForCrafting(TextureRect iconTexture) { var defaultIcon = GD.Load("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("HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue"); + var craftingQueue = gameScene.GetNode("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); }; } diff --git a/scripts/ui/ManualCollectionItem.cs b/scripts/ui/ManualCollectionItem.cs new file mode 100644 index 0000000..001bd64 --- /dev/null +++ b/scripts/ui/ManualCollectionItem.cs @@ -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("MarginContainer/VBoxContainer/TopRow/IconTexture"); + nameLabel = GetNode