开始菜单

This commit is contained in:
2026-10-02 10:44:58 +08:00
parent 39790aecea
commit fbf00cf11f
6 changed files with 225 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
extends Control
## 游戏开始菜单 —— 只有界面,没有逻辑。
##
## 四个按钮按下去只把对应信号发出去:谁接、接了之后是加载世界、连服务器还是弹设置面板,
## 都不在这个文件里。这样菜单版式可以单独改,主流程也能单独换。
##
## 接线示例(放在外层,比如以后的主场景或一个菜单流程单例):
## menu.start_pressed.connect(_on_start)
## menu.multiplayer_pressed.connect(_on_multiplayer)
## menu.settings_pressed.connect(_on_settings)
## menu.quit_pressed.connect(get_tree().quit)
##
## 用法:把本场景设成 project.godot 的 application/run/main_scene 即可(这一步也没做)。
signal start_pressed
signal multiplayer_pressed
signal settings_pressed
signal quit_pressed
func _ready() -> void:
# 从游戏内退回菜单时鼠标可能还是被捕获的,先放出来 —— 不然菜单点不动。
# 这不算逻辑,是菜单能不能用的前提。
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
# 按钮只负责把 pressed 转发成信号,不在这里做任何决定。
%StartButton.pressed.connect(start_pressed.emit)
%MultiplayerButton.pressed.connect(multiplayer_pressed.emit)
%SettingsButton.pressed.connect(settings_pressed.emit)
%QuitButton.pressed.connect(quit_pressed.emit)
+1
View File
@@ -0,0 +1 @@
uid://bx1ahrgpx5hvg
+162
View File
@@ -0,0 +1,162 @@
[gd_scene load_steps=7 format=3]
[ext_resource type="Script" path="res://ui/main_menu.gd" id="1_menu"]
[sub_resource type="Gradient" id="Gradient_bg"]
offsets = PackedFloat32Array(0, 0.55, 1)
colors = PackedColorArray(0.09, 0.3, 0.78, 1, 0.28, 0.6, 0.95, 1, 0.78, 0.88, 1, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_bg"]
gradient = SubResource("Gradient_bg")
width = 4
height = 512
fill_from = Vector2(0.5, 0)
fill_to = Vector2(0.5, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_normal"]
content_margin_left = 20.0
content_margin_top = 10.0
content_margin_right = 20.0
content_margin_bottom = 10.0
bg_color = Color(1, 1, 1, 0.14)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(1, 1, 1, 0.5)
corner_radius_top_left = 12
corner_radius_top_right = 12
corner_radius_bottom_right = 12
corner_radius_bottom_left = 12
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hover"]
content_margin_left = 20.0
content_margin_top = 10.0
content_margin_right = 20.0
content_margin_bottom = 10.0
bg_color = Color(1, 1, 1, 0.32)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(1, 1, 1, 0.85)
corner_radius_top_left = 12
corner_radius_top_right = 12
corner_radius_bottom_right = 12
corner_radius_bottom_left = 12
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_pressed"]
content_margin_left = 20.0
content_margin_top = 10.0
content_margin_right = 20.0
content_margin_bottom = 10.0
bg_color = Color(0.05, 0.12, 0.3, 0.35)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(1, 1, 1, 0.95)
corner_radius_top_left = 12
corner_radius_top_right = 12
corner_radius_bottom_right = 12
corner_radius_bottom_left = 12
[node name="MainMenu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_menu")
[node name="Background" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
texture = SubResource("GradientTexture2D_bg")
expand_mode = 1
[node name="Center" type="CenterContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
[node name="Box" type="VBoxContainer" parent="Center"]
layout_mode = 2
theme_override_constants/separation = 18
[node name="Title" type="Label" parent="Center/Box"]
layout_mode = 2
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_colors/font_outline_color = Color(0.05, 0.1, 0.25, 0.85)
theme_override_constants/outline_size = 14
theme_override_font_sizes/font_size = 72
text = "AGAME"
horizontal_alignment = 1
[node name="Buttons" type="VBoxContainer" parent="Center/Box"]
layout_mode = 2
theme_override_colors/font_color = Color(1, 1, 1, 0.92)
theme_override_colors/font_focus_color = Color(1, 1, 1, 0.92)
theme_override_colors/font_hover_color = Color(1, 1, 1, 1)
theme_override_colors/font_pressed_color = Color(1, 1, 1, 1)
theme_override_constants/separation = 12
theme_override_font_sizes/font_size = 24
theme_override_styles/focus = SubResource("StyleBoxFlat_hover")
theme_override_styles/hover = SubResource("StyleBoxFlat_hover")
theme_override_styles/normal = SubResource("StyleBoxFlat_normal")
theme_override_styles/pressed = SubResource("StyleBoxFlat_pressed")
[node name="StartButton" type="Button" parent="Center/Box/Buttons"]
unique_name_in_owner = true
custom_minimum_size = Vector2(280, 54)
layout_mode = 2
text = "开始游戏"
[node name="MultiplayerButton" type="Button" parent="Center/Box/Buttons"]
unique_name_in_owner = true
custom_minimum_size = Vector2(280, 54)
layout_mode = 2
text = "联机"
[node name="SettingsButton" type="Button" parent="Center/Box/Buttons"]
unique_name_in_owner = true
custom_minimum_size = Vector2(280, 54)
layout_mode = 2
text = "设置"
[node name="QuitButton" type="Button" parent="Center/Box/Buttons"]
unique_name_in_owner = true
custom_minimum_size = Vector2(280, 54)
layout_mode = 2
text = "退出"
[node name="Version" type="Label" parent="."]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -180.0
offset_top = -40.0
offset_right = -18.0
offset_bottom = -14.0
grow_horizontal = 0
grow_vertical = 0
mouse_filter = 2
theme_override_colors/font_color = Color(1, 1, 1, 0.6)
theme_override_colors/font_outline_color = Color(0.05, 0.1, 0.25, 0.6)
theme_override_constants/outline_size = 4
theme_override_font_sizes/font_size = 14
text = "v0.1"
horizontal_alignment = 2