parent
cca3cdbb82
commit
c8cfd73005
6 changed files with 193 additions and 30 deletions
@ -0,0 +1,51 @@ |
|||||||
|
public partial class EscapeMenu : CenterContainer |
||||||
|
{ |
||||||
|
[Export] public Container SideButtons { get; set; } |
||||||
|
[Export] public TabContainer Tabs { get; set; } |
||||||
|
|
||||||
|
public override void _Ready() |
||||||
|
{ |
||||||
|
foreach (var child in SideButtons.GetChildren()) |
||||||
|
if ((child is BaseButton button) && button.ToggleMode) |
||||||
|
button.Pressed += () => { |
||||||
|
for (var i = 0; i < Tabs.GetTabCount(); i++) |
||||||
|
if (Tabs.GetTabControl(i).Name == button.Name) |
||||||
|
Tabs.CurrentTab = i; |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public override void _Input(InputEvent @event) |
||||||
|
{ |
||||||
|
if (!Visible) { |
||||||
|
var isMouseCaptured = Input.MouseMode == Input.MouseModeEnum.Captured; |
||||||
|
if (!isMouseCaptured && @event.IsActionPressed("ui_cancel")) { |
||||||
|
Visible = true; |
||||||
|
GetViewport().SetInputAsHandled(); |
||||||
|
} |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (@event.IsActionPressed("ui_cancel")) { |
||||||
|
OnReturnPressed(); |
||||||
|
GetViewport().SetInputAsHandled(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void OnTabChanged(int tabIndex) |
||||||
|
{ |
||||||
|
var tabName = Tabs.GetTabControl(tabIndex).Name; |
||||||
|
foreach (var child in SideButtons.GetChildren()) |
||||||
|
if ((child is BaseButton button) && button.ToggleMode) |
||||||
|
button.ButtonPressed = button.Name == tabName; |
||||||
|
} |
||||||
|
|
||||||
|
public void OnReturnPressed() |
||||||
|
{ |
||||||
|
Visible = false; |
||||||
|
} |
||||||
|
|
||||||
|
public void OnQuitPressed() |
||||||
|
{ |
||||||
|
GetTree().Quit(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,92 @@ |
|||||||
|
[gd_scene load_steps=3 format=3 uid="uid://c5ooi36ibspfo"] |
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://EscapeMenu.cs" id="1_5qxrt"] |
||||||
|
|
||||||
|
[sub_resource type="LabelSettings" id="LabelSettings_u8eqm"] |
||||||
|
font_size = 22 |
||||||
|
|
||||||
|
[node name="EscapeMenu" type="CenterContainer" node_paths=PackedStringArray("SideButtons", "Tabs")] |
||||||
|
offset_right = 562.0 |
||||||
|
offset_bottom = 404.0 |
||||||
|
mouse_filter = 0 |
||||||
|
script = ExtResource("1_5qxrt") |
||||||
|
SideButtons = NodePath("PanelContainer/MarginContainer/VBoxContainer/GridContainer/SideButtons") |
||||||
|
Tabs = NodePath("PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer") |
||||||
|
|
||||||
|
[node name="PanelContainer" type="PanelContainer" parent="."] |
||||||
|
layout_mode = 2 |
||||||
|
|
||||||
|
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] |
||||||
|
layout_mode = 2 |
||||||
|
theme_override_constants/margin_left = 10 |
||||||
|
theme_override_constants/margin_top = 4 |
||||||
|
theme_override_constants/margin_right = 10 |
||||||
|
theme_override_constants/margin_bottom = 10 |
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"] |
||||||
|
layout_mode = 2 |
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"] |
||||||
|
layout_mode = 2 |
||||||
|
text = "Escape Menu" |
||||||
|
label_settings = SubResource("LabelSettings_u8eqm") |
||||||
|
horizontal_alignment = 1 |
||||||
|
|
||||||
|
[node name="GridContainer" type="GridContainer" parent="PanelContainer/MarginContainer/VBoxContainer"] |
||||||
|
layout_mode = 2 |
||||||
|
theme_override_constants/h_separation = 6 |
||||||
|
theme_override_constants/v_separation = 6 |
||||||
|
columns = 2 |
||||||
|
|
||||||
|
[node name="SideButtons" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer"] |
||||||
|
custom_minimum_size = Vector2(160, 0) |
||||||
|
layout_mode = 2 |
||||||
|
|
||||||
|
[node name="Gameplay" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/SideButtons"] |
||||||
|
layout_mode = 2 |
||||||
|
toggle_mode = true |
||||||
|
button_pressed = true |
||||||
|
text = "Gameplay" |
||||||
|
|
||||||
|
[node name="Multiplayer" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/SideButtons"] |
||||||
|
layout_mode = 2 |
||||||
|
toggle_mode = true |
||||||
|
text = "Multiplayer" |
||||||
|
|
||||||
|
[node name="TabContainer" type="TabContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer"] |
||||||
|
custom_minimum_size = Vector2(400, 300) |
||||||
|
layout_mode = 2 |
||||||
|
size_flags_vertical = 3 |
||||||
|
tabs_visible = false |
||||||
|
|
||||||
|
[node name="Gameplay" type="CenterContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer"] |
||||||
|
layout_mode = 2 |
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Gameplay"] |
||||||
|
layout_mode = 2 |
||||||
|
text = "Gameplay |
||||||
|
(nothing here yet)" |
||||||
|
horizontal_alignment = 1 |
||||||
|
|
||||||
|
[node name="Multiplayer" type="CenterContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer"] |
||||||
|
visible = false |
||||||
|
layout_mode = 2 |
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer"] |
||||||
|
layout_mode = 2 |
||||||
|
text = "Multiplayer |
||||||
|
(nothing here yet)" |
||||||
|
horizontal_alignment = 1 |
||||||
|
|
||||||
|
[node name="Quit" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer"] |
||||||
|
layout_mode = 2 |
||||||
|
text = "Quit to Desktop" |
||||||
|
|
||||||
|
[node name="Return" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer"] |
||||||
|
layout_mode = 2 |
||||||
|
text = "Return to Game |
||||||
|
" |
||||||
|
|
||||||
|
[connection signal="tab_changed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer" to="." method="OnTabChanged"] |
||||||
|
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/Quit" to="." method="OnQuitPressed"] |
||||||
|
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/Return" to="." method="OnReturnPressed"] |
Loading…
Reference in new issue