Skip to content

Commit

Permalink
feat: add back button for options + label highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
myin142 committed May 21, 2023
1 parent 28f55d4 commit 5a2383d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/menu/AudioSettings.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name AudioSettings
extends Control

const AUDIO_SECTION = "audio"
Expand Down
4 changes: 3 additions & 1 deletion src/menu/InputSetting.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name InputSettings
extends Control

const INPUT_SECTION = "input"
Expand All @@ -24,8 +25,9 @@ func _ready():
_logger.warn("No event for action %s" % action)
continue

var label = Label.new()
var label = LabelHover.new()
label.text = action
label.control = button
container.add_child(label)

button.connect("pressed", func(): _on_remap_pressed(button))
Expand Down
21 changes: 21 additions & 0 deletions src/menu/LabelHover.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class_name LabelHover
extends Label

@export var toggle_visibility = false
@export var control: Control
@export var highlight_color = Color.WHITE

func _ready():
control.mouse_entered.connect(hover)
control.mouse_exited.connect(unhover)
unhover()

func hover():
add_theme_color_override("font_color", highlight_color)
if toggle_visibility:
show()

func unhover():
remove_theme_color_override("font_color")
if toggle_visibility:
hide()
11 changes: 9 additions & 2 deletions src/menu/Options.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ extends Control

const CONFIG_FILE = "user://settings.cfg"

@onready var _audio := $Audio
@onready var _input := $Input
@export var _audio: AudioSettings
@export var _input: InputSettings

var _logger = Logger.new("Options")
var _config = ConfigFile.new()
Expand Down Expand Up @@ -31,3 +31,10 @@ func _save_config():
_audio.save_settings(_config)
_input.save_settings(_config)
_config.save(CONFIG_FILE)


func _on_title_back_pressed():
var cancel_event = InputEventAction.new()
cancel_event.action = "ui_cancel"
cancel_event.pressed = true
Input.parse_input_event(cancel_event)
22 changes: 19 additions & 3 deletions src/menu/Options.tscn
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
[gd_scene load_steps=7 format=3 uid="uid://bh8672uj3c4gn"]
[gd_scene load_steps=10 format=3 uid="uid://bh8672uj3c4gn"]

[ext_resource type="Script" path="res://addons/menu-system/AudioSlider.gd" id="1"]
[ext_resource type="Script" path="res://src/menu/AudioSettings.gd" id="1_4l5hd"]
[ext_resource type="Theme" uid="uid://dyxpiak5ymujy" path="res://theme/theme.tres" id="1_sb63w"]
[ext_resource type="Script" path="res://src/menu/Options.gd" id="2_enfnm"]
[ext_resource type="PackedScene" uid="uid://bryo50hd7fs0k" path="res://src/ui/ui_button.tscn" id="2_jag4g"]
[ext_resource type="Script" path="res://src/menu/InputSetting.gd" id="3_pt256"]
[ext_resource type="PackedScene" uid="uid://blurtq1v44gav" path="res://addons/menu-system/RemapButton.tscn" id="5_34cxq"]
[ext_resource type="Script" path="res://src/menu/LabelHover.gd" id="5_htjkt"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qgskr"]
bg_color = Color(0, 0, 0, 0.705882)

[node name="Options" type="Control"]
[node name="Options" type="Control" node_paths=PackedStringArray("_audio", "_input")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_sb63w")
script = ExtResource("2_enfnm")
_audio = NodePath("CenterContainer/VBoxContainer/Options")
_input = NodePath("RemapKeyPopup")

[node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 1
Expand All @@ -29,16 +35,24 @@ grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
theme_override_constants/separation = 10

[node name="TitleBack" parent="CenterContainer/VBoxContainer" instance=ExtResource("2_jag4g")]
layout_mode = 2
text = "< Options"
alignment = 1

[node name="Options" type="GridContainer" parent="CenterContainer/VBoxContainer"]
layout_mode = 2
columns = 2
script = ExtResource("1_4l5hd")

[node name="Label" type="Label" parent="CenterContainer/VBoxContainer/Options"]
[node name="Label" type="Label" parent="CenterContainer/VBoxContainer/Options" node_paths=PackedStringArray("control")]
layout_mode = 2
text = "Sound"
vertical_alignment = 1
script = ExtResource("5_htjkt")
control = NodePath("../AudioSlider")

[node name="AudioSlider" type="HSlider" parent="CenterContainer/VBoxContainer/Options"]
layout_mode = 2
Expand Down Expand Up @@ -77,3 +91,5 @@ anchor_bottom = 1.0
[node name="Label" type="Label" parent="RemapKeyPopup/CenterContainer"]
layout_mode = 2
text = "Press any key..."

[connection signal="pressed" from="CenterContainer/VBoxContainer/TitleBack" to="." method="_on_title_back_pressed"]
2 changes: 0 additions & 2 deletions src/ui/start_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ text = "Exit"

[node name="Options" parent="." instance=ExtResource("7_m56wc")]
layout_mode = 1
grow_horizontal = 2
grow_vertical = 2

[node name="BGM" type="AudioStreamPlayer" parent="."]
stream = ExtResource("5_tcjoy")
Expand Down
3 changes: 2 additions & 1 deletion src/ui/ui_button.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
text = "Test"
text = "__Test__
"
alignment = 0
script = ExtResource("1_hotp4")
hover_sound = NodePath("Hover")
Expand Down

0 comments on commit 5a2383d

Please sign in to comment.