Rework GUI system
parent
28ecbd4729
commit
0a9b3f96d1
|
@ -0,0 +1,29 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Menu.tscn" type="PackedScene" id=1]
|
||||
|
||||
[node name="ControlsMenu" instance=ExtResource( 1 )]
|
||||
|
||||
[node name="MouseSensitivity" type="HBoxContainer" parent="." index="0"]
|
||||
offset_right = 337.0
|
||||
offset_bottom = 26.0
|
||||
script = null
|
||||
|
||||
[node name="Label" type="Label" parent="MouseSensitivity" index="0"]
|
||||
offset_right = 133.0
|
||||
offset_bottom = 26.0
|
||||
text = "Mouse sensitivity"
|
||||
structured_text_bidi_override_options = [ ]
|
||||
script = null
|
||||
|
||||
[node name="Slider" type="HSlider" parent="MouseSensitivity" index="1"]
|
||||
offset_left = 137.0
|
||||
offset_right = 337.0
|
||||
offset_bottom = 16.0
|
||||
rect_min_size = Vector2( 200, 0 )
|
||||
script = null
|
||||
|
||||
[node name="Back" parent="." index="1"]
|
||||
offset_top = 30.0
|
||||
offset_right = 337.0
|
||||
offset_bottom = 59.0
|
22
Game/GUI.gd
22
Game/GUI.gd
|
@ -1,8 +1,26 @@
|
|||
extends Control
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
@export var filename = "user://settings.save"
|
||||
var settings = {}
|
||||
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
if has_settings():
|
||||
load_settings()
|
||||
|
||||
func has_settings():
|
||||
return false
|
||||
|
||||
func save_settings():
|
||||
var file = File.new()
|
||||
file.open(filename, File.WRITE)
|
||||
file.store_var(settings)
|
||||
file.close()
|
||||
|
||||
func load_settings():
|
||||
var file = File.new()
|
||||
file.open(filename, File.READ)
|
||||
settings = file.get_var()
|
||||
file.close()
|
||||
|
||||
func quit_game():
|
||||
get_tree().quit()
|
||||
|
|
|
@ -1,35 +1,37 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://GUI.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Menu.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://MenuButton.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="GUI" type="CenterContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="MainMenu" parent="." instance=ExtResource( 2 )]
|
||||
[node name="Menu" parent="." instance=ExtResource( 2 )]
|
||||
offset_left = 477.0
|
||||
offset_top = 252.0
|
||||
offset_right = 547.0
|
||||
offset_bottom = 347.0
|
||||
|
||||
[node name="Options" type="Button" parent="MainMenu"]
|
||||
[node name="Options" parent="Menu" instance=ExtResource( 3 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_top = 33.0
|
||||
offset_right = 70.0
|
||||
offset_bottom = 62.0
|
||||
text = "options"
|
||||
script = null
|
||||
label = "options"
|
||||
|
||||
[node name="Quit" type="Button" parent="MainMenu"]
|
||||
[node name="Quit" parent="Menu" instance=ExtResource( 3 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_top = 66.0
|
||||
offset_right = 70.0
|
||||
offset_bottom = 95.0
|
||||
text = "quit"
|
||||
script = null
|
||||
label = "quit"
|
||||
|
||||
[connection signal="pressed" from="MainMenu/Options" to="MainMenu" method="open_menu" binds= [ "res://OptionsMenu.tscn" ]]
|
||||
[connection signal="pressed" from="MainMenu/Quit" to="." method="quit_game"]
|
||||
[connection signal="pressed" from="Menu/Options" to="Menu" method="open_menu" binds= [ "res://OptionsMenu.tscn" ]]
|
||||
[connection signal="pressed" from="Menu/Quit" to="." method="quit_game"]
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Menu.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://GraphicsMenu.gd" type="Script" id=2]
|
||||
[ext_resource path="res://MenuCheckButton.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="GraphicsMenu" instance=ExtResource( 1 )]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Fullscreen" type="CheckButton" parent="." index="0"]
|
||||
offset_right = 158.0
|
||||
[node name="Fullscreen" parent="." index="0" instance=ExtResource( 3 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_right = 76.0
|
||||
offset_bottom = 40.0
|
||||
text = "Fullscreen"
|
||||
script = null
|
||||
label = "Fullscreen"
|
||||
|
||||
[node name="Back" parent="." index="1"]
|
||||
offset_top = 44.0
|
||||
offset_right = 158.0
|
||||
offset_right = 76.0
|
||||
offset_bottom = 73.0
|
||||
|
||||
[connection signal="toggled" from="Fullscreen" to="." method="toggle_fullscreen"]
|
||||
[connection signal="data_changed" from="Fullscreen" to="." method="toggle_fullscreen"]
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
extends "res://MenuItem.gd"
|
||||
|
||||
func on_label_changed():
|
||||
self.text = label
|
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://MenuButton.gd" type="Script" id=1]
|
||||
|
||||
[node name="MenuButton" type="Button"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
extends "res://MenuData.gd"
|
||||
|
||||
func on_label_changed():
|
||||
self.text = label
|
||||
|
||||
func on_toggle(button_pressed):
|
||||
data = button_pressed
|
|
@ -0,0 +1,13 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://MenuCheckButton.gd" type="Script" id=1]
|
||||
|
||||
[node name="MenuCheckButton" type="CheckButton"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[connection signal="toggled" from="." to="." method="on_toggle"]
|
|
@ -0,0 +1,15 @@
|
|||
extends "res://MenuItem.gd"
|
||||
|
||||
signal data_changed(data)
|
||||
|
||||
var data = null:
|
||||
set(_data):
|
||||
emit_signal("data_changed", _data)
|
||||
data = _data
|
||||
save_data()
|
||||
|
||||
func save_data():
|
||||
var GUI = get_parent().get_parent()
|
||||
|
||||
GUI.settings[label] = data
|
||||
GUI.save_settings()
|
|
@ -0,0 +1,7 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://MenuItem.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://MenuData.gd" type="Script" id=2]
|
||||
|
||||
[node name="MenuData" instance=ExtResource( 1 )]
|
||||
script = ExtResource( 2 )
|
|
@ -0,0 +1,15 @@
|
|||
extends Control
|
||||
|
||||
@export var label = "":
|
||||
set(_label):
|
||||
label = _label
|
||||
on_label_changed()
|
||||
get:
|
||||
return label
|
||||
|
||||
func on_label_changed():
|
||||
pass
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass
|
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://MenuItem.gd" type="Script" id=1]
|
||||
|
||||
[node name="MenuItem" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
|
@ -1,25 +1,31 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Menu.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://MenuButton.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="OptionsMenu" instance=ExtResource( 1 )]
|
||||
|
||||
[node name="Graphics" type="Button" parent="." index="0"]
|
||||
offset_right = 80.0
|
||||
[node name="Graphics" parent="." index="0" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_right = 77.0
|
||||
offset_bottom = 29.0
|
||||
text = "Graphics"
|
||||
script = null
|
||||
text = "graphics"
|
||||
label = "graphics"
|
||||
|
||||
[node name="Controls" type="Button" parent="." index="1"]
|
||||
[node name="Controls" parent="." index="1" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_top = 33.0
|
||||
offset_right = 80.0
|
||||
offset_right = 77.0
|
||||
offset_bottom = 62.0
|
||||
text = "Controls"
|
||||
script = null
|
||||
text = "controls"
|
||||
label = "controls"
|
||||
|
||||
[node name="Back" parent="." index="2"]
|
||||
offset_top = 66.0
|
||||
offset_right = 80.0
|
||||
offset_right = 77.0
|
||||
offset_bottom = 95.0
|
||||
|
||||
[connection signal="pressed" from="Graphics" to="." method="open_menu" binds= [ "res://GraphicsMenu.tscn" ]]
|
||||
[connection signal="pressed" from="Controls" to="." method="open_menu" binds= [ "res://ControlsMenu.tscn" ]]
|
||||
|
|
Reference in New Issue