生产线样式,添加图标测试

This commit is contained in:
2025-06-19 00:02:41 +08:00
parent 50dc434ed9
commit b3d1135e23
23 changed files with 868 additions and 384 deletions

BIN
assets/textures/Vanilla.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 KiB

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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
}
]
}
]
}

View File

@ -18,12 +18,20 @@
"copper_ingot"
]
},
{
"categoryName": "制作物品",
"items": [
"magnet",
"gear",
"magnetic_coil",
"circuit_board"
]
},
{
"categoryName": "建筑设施",
"items": [
"mining_drill",
"furnace",
"smelter",
"miner",
"assembler",
"chemical_plant"

View File

@ -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

1 Id Name Category Description Recipe CraftTime PowerConsumption IconPath
5 coal_ore 煤矿 RawMaterial 重要的能源资源,可用于发电 null 0 0 res://assets/textures/items/coal_ore.png
6 water RawMaterial 基础资源,可用于多种生产 null 0 0 res://assets/textures/items/water.png
7 crude_oil 原油 RawMaterial 重要的能源资源,可用于生产燃料 null 0 0 res://assets/textures/items/crude_oil.png
8 iron_ingot 铁块 ProcessedMaterial 由铁矿冶炼而成的基础材料 iron_ore:1 1.0 60.0 res://assets/textures/items/iron_ingot.png res://assets/textures/items/铁块.tres
9 copper_ingot 铜块 ProcessedMaterial 由铜矿冶炼而成的基础材料 copper_ore:1 1.0 60.0 res://assets/textures/items/copper_ingot.png res://assets/textures/items/铜块.tres
10 mining_drill magnet 钻机 磁铁 Building ProcessedMaterial 自动采集矿石的钻探设备 由铁矿制作的磁性材料,用于制造电机等设备 iron_ingot:5;copper_ingot:3 iron_ore:2 4.0 1.5 300.0 0 res://assets/textures/buildings/mining_drill.png res://assets/textures/items/magnet.png
11 gear 齿轮 ProcessedMaterial 由铁块制作的机械部件,用于制造复杂设备 iron_ingot:1 2.0 0 res://assets/textures/items/gear.png
12 magnetic_coil 磁线圈 Component 由磁铁和铜块制作的电磁组件,用于制造高级设备 magnet:2;copper_ingot:1 3.0 0 res://assets/textures/items/magnetic_coil.png
13 circuit_board 电路板 Component 由铁块和铜块制作的电子组件,用于制造高级设备 iron_ingot:2;copper_ingot:1 2.5 0 res://assets/textures/items/circuit_board.png
14 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
15 furnace 熔炉 Building 自动冶炼矿石的熔炉设备 iron_ingot:4;stone_ore:2 3.5 250.0 res://assets/textures/buildings/furnace.png
16 smelter 冶炼厂 Building 用于冶炼矿石的基础建筑 iron_ingot:4;copper_ingot:2 3.0 360.0 res://assets/textures/buildings/smelter.png
17 miner 采矿机 Building 自动采集矿石的基础建筑 iron_ingot:3;copper_ingot:1 2.0 420.0 res://assets/textures/buildings/miner.png

View File

@ -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
}
],

View File

@ -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"
]
}
]

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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个化工厂

View File

@ -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); // 添加齿轮,用于合成钻机
}
// 添加物品到库存

View File

@ -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<PackedScene>("res://scenes/InventoryItem.tscn");
if (inventoryItemScene == null)
@ -97,6 +138,11 @@ public partial class InventoryTableManager : VBoxContainer
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<TextureRect>("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<Texture2D>(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<Texture2D>("res://assets/textures/icon.svg");
if (defaultIcon != null)
{
iconTexture.Texture = defaultIcon;
}
}
}
else
{
// 使用默认图标
var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
if (defaultIcon != null)
{
iconTexture.Texture = defaultIcon;
}
// GD.Print($"图标文件不存在: {itemData.IconPath}使用默认图标");
// // 使用默认图标
// var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
// if (defaultIcon != null)
// {
// iconTexture.Texture = defaultIcon;
// }
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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];

View File

@ -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<PackedScene>("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, "合成");
@ -165,6 +176,8 @@ public partial class DynamicTabManager : TabContainer
}
else
{
// 为每个分类创建块
foreach (var category in categories)
{
@ -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);
// 创建生产线网格 - 使用VBoxContainer实现垂直堆叠
var productionContainer = new VBoxContainer();
productionContainer.Name = $"{category}ProductionLines";
productionContainer.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
productionContainer.AddThemeConstantOverride("separation", 8); // 垂直间距
// 创建流容器来放置生产线(完全按照合成菜单的方式)
var flowContainer = new FlowContainer();
flowContainer.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
categoryContainer.AddChild(flowContainer);
// 添加该分类的所有生产线
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<Control>();
// 使用专门的手动采集场景
itemPanel = manualCollectionItemScene.Instantiate<ManualCollectionItem>();
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 == "合成")
@ -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,32 +402,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<Texture2D>(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<Texture2D>("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<Texture2D>(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}...";
}
}
@ -651,6 +632,19 @@ public partial class DynamicTabManager : TabContainer
}
}
private void LoadDefaultIcon(TextureRect iconTexture)
{
var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
if (defaultIcon != null)
{
iconTexture.Texture = defaultIcon;
}
else
{
GD.PrintErr("无法加载默认图标");
}
}
private void LoadDefaultIconForCrafting(TextureRect iconTexture)
{
var defaultIcon = GD.Load<Texture2D>("res://assets/textures/icon.svg");
@ -764,7 +758,7 @@ public partial class DynamicTabManager : TabContainer
}
// 尝试通过路径查找CraftingQueueManager
var craftingQueue = gameScene.GetNode<CraftingQueueManager>("HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue");
var craftingQueue = gameScene.GetNode<CraftingQueueManager>("HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue");
if (craftingQueue == null)
{
GD.PrintErr("无法找到CraftingQueueManager节点");
@ -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);
};
}

View File

@ -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<TextureRect>("MarginContainer/VBoxContainer/TopRow/IconTexture");
nameLabel = GetNode<Label>("MarginContainer/VBoxContainer/TopRow/InfoContainer/NameLabel");
statusLabel = GetNode<Label>("MarginContainer/VBoxContainer/TopRow/InfoContainer/StatusLabel");
progressFill = GetNode<ColorRect>("MarginContainer/VBoxContainer/ProgressContainer/ProgressFill");
// 瞬间采集模式不需要设置进度条初始颜色
// progressFill.Color = defaultProgressColor;
// 连接鼠标事件
GuiInput += OnGuiInput;
// 如果物品数据已经设置,现在应用它
if (itemData != null)
{
ApplyItemData();
}
GD.Print("ManualCollectionItem _Ready 完成");
}
public void SetupItem(string id, GameData.ItemData data)
{
itemId = id;
itemData = data;
// 如果UI组件还没有初始化延迟设置
if (nameLabel == null)
{
GD.Print("UI组件还未初始化延迟设置手动采集物品数据");
CallDeferred(nameof(ApplyItemData));
return;
}
ApplyItemData();
}
private void ApplyItemData()
{
if (itemData == null)
{
GD.PrintErr("itemData为null无法应用数据");
return;
}
// 确保UI组件已初始化
if (nameLabel == null)
{
GD.PrintErr("nameLabel仍然为nullUI初始化可能失败");
return;
}
// 设置物品名称
nameLabel.Text = itemData.Name;
// 加载图标
LoadItemIcon();
GD.Print($"成功设置手动采集物品: {itemData.Name}");
}
private void LoadItemIcon()
{
if (itemData == null || iconTexture == null) return;
if (!string.IsNullOrEmpty(itemData.IconPath) && ResourceLoader.Exists(itemData.IconPath))
{
// 尝试加载为Texture2D资源
var resource = ResourceLoader.Load(itemData.IconPath);
if (resource is Texture2D texture)
{
iconTexture.Texture = texture;
}
else
{
GD.PrintErr($"资源不是Texture2D类型: {itemData.IconPath}");
// 使用默认图标
var defaultTexture = GD.Load<Texture2D>("res://assets/textures/icon.svg");
if (defaultTexture != null)
{
iconTexture.Texture = defaultTexture;
}
}
}
else
{
// 使用默认图标
var defaultTexture = GD.Load<Texture2D>("res://assets/textures/icon.svg");
if (defaultTexture != null)
{
iconTexture.Texture = defaultTexture;
}
}
}
private void OnGuiInput(InputEvent @event)
{
if (@event is InputEventMouseButton mouseEvent)
{
if (mouseEvent.ButtonIndex == MouseButton.Left)
{
// 瞬间采集模式 - 点击一次立即完成一次采集
if (mouseEvent.Pressed)
{
InstantCollection();
}
// 原来的进度条采集模式(已注释)
/*
// 点击采集模式 - 只在按下时触发一次采集
if (mouseEvent.Pressed)
{
StartSingleCollection();
}
// 按住采集模式(已注释)
if (mouseEvent.Pressed)
{
// 开始采集
StartCollection();
}
else
{
// 停止采集
StopCollection();
}
*/
}
}
}
// 新增:瞬间采集方法
private void InstantCollection()
{
if (string.IsNullOrEmpty(itemId)) return;
// 添加物品到库存
if (InventoryManager.Instance != null)
{
InventoryManager.Instance.AddItem(itemId, 1);
GD.Print($"瞬间采集完成,获得: {itemData?.Name ?? itemId} x1");
}
// 简单的视觉反馈 - 短暂改变状态文本
if (statusLabel != null)
{
statusLabel.Text = "采集!";
statusLabel.Modulate = collectingProgressColor;
// 0.1秒后恢复状态
GetTree().CreateTimer(0.1).Timeout += () => {
if (statusLabel != null)
{
statusLabel.Text = "点击采集";
statusLabel.Modulate = new Color(0.7f, 0.9f, 0.7f, 1.0f);
}
};
}
}
// 新增:单次点击采集方法
private void StartSingleCollection()
{
if (string.IsNullOrEmpty(itemId)) return;
// 如果正在采集中,忽略点击
if (isCollecting) return;
isCollecting = true;
collectionProgress = 0.0f;
// 更新状态标签和进度条颜色
if (statusLabel != null)
{
statusLabel.Text = "采集中...";
statusLabel.Modulate = collectingProgressColor;
}
if (progressFill != null)
{
progressFill.Color = collectingProgressColor;
}
GD.Print($"开始采集: {itemData?.Name ?? itemId}");
}
private void CompleteCollection()
{
if (string.IsNullOrEmpty(itemId)) return;
// 添加物品到库存
if (InventoryManager.Instance != null)
{
InventoryManager.Instance.AddItem(itemId, 1);
GD.Print($"采集完成,获得: {itemData?.Name ?? itemId} x1");
}
// 点击采集模式 - 采集完成后停止
isCollecting = false;
collectionProgress = 0.0f;
UpdateStatusDisplay();
// 按住采集模式的连续采集逻辑(已注释但保留)
/*
// 重置采集状态
collectionProgress = 0.0f;
// 如果还在按住,继续下一轮采集
if (isCollecting)
{
GD.Print($"继续采集: {itemData?.Name ?? itemId}");
}
else
{
// 恢复状态显示
UpdateStatusDisplay();
}
*/
}
private void UpdateStatusDisplay()
{
if (statusLabel != null)
{
statusLabel.Text = "点击采集";
statusLabel.Modulate = new Color(0.7f, 0.9f, 0.7f, 1.0f);
}
if (progressFill != null)
{
progressFill.Color = defaultProgressColor;
if (!isCollecting)
{
progressFill.AnchorRight = 0.0f;
}
}
}
private void UpdateProgressBar()
{
if (progressFill != null)
{
if (isCollecting)
{
// 采集中显示当前进度
progressFill.AnchorRight = collectionProgress;
}
else
{
// 非采集状态显示0进度
progressFill.AnchorRight = 0.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;
}
// 按住采集相关方法(已注释但保留)
/*
private void StopCollection()
{
if (!isCollecting) return;
isCollecting = false;
collectionProgress = 0.0f;
// 恢复状态显示
UpdateStatusDisplay();
GD.Print($"停止采集: {itemData?.Name ?? itemId}");
}
*/
}

View File

@ -30,6 +30,12 @@ public partial class ProductionLineItem : Panel
progressFill = GetNode<ColorRect>("MarginContainer/VBoxContainer/ProgressContainer/ProgressFill");
iconTexture = GetNode<TextureRect>("MarginContainer/VBoxContainer/TopRow/IconTexture");
// 设置进度条初始状态
if (progressFill != null)
{
progressFill.AnchorRight = 0.0f;
}
// 连接按钮信号
addButton.Pressed += OnAddButtonPressed;
removeButton.Pressed += OnRemoveButtonPressed;
@ -130,11 +136,16 @@ public partial class ProductionLineItem : Panel
if (ResourceLoader.Exists(iconPath))
{
var texture = GD.Load<Texture2D>(iconPath);
if (texture != null)
// 尝试加载为Texture2D资源
var resource = ResourceLoader.Load(iconPath);
if (resource is Texture2D texture)
{
iconTexture.Texture = texture;
}
else
{
GD.PrintErr($"资源不是Texture2D类型: {iconPath}");
}
}
}
@ -175,8 +186,12 @@ public partial class ProductionLineItem : Panel
productionLabel.Text = "0/s";
}
// 更新进度条
progressFill.AnchorRight = status.Progress;
// 更新进度条(添加边界检查,避免闪烁)
float newProgress = Mathf.Clamp(status.Progress, 0.0f, 1.0f);
if (progressFill.AnchorRight != newProgress)
{
progressFill.AnchorRight = newProgress;
}
// 更新按钮状态
UpdateButtonStates();