wip menu
This commit is contained in:
111
Menu.gd
111
Menu.gd
@@ -1,57 +1,82 @@
|
||||
extends Control
|
||||
|
||||
signal game_started()
|
||||
signal track_changed()
|
||||
signal skin_changed(skin)
|
||||
|
||||
enum Actions { PLAY, CHANGE_TRACK, QUIT }
|
||||
var _focus = null setget _set_focus
|
||||
enum Actions {
|
||||
PLAY,
|
||||
ENTER_OPTIONS,
|
||||
EXIT_OPTIONS,
|
||||
NEXT_TRACK,
|
||||
PREV_TRACK,
|
||||
# PREV_SKIN,
|
||||
# NEXT_SKIN,
|
||||
# PREV_INPUT_MODE,
|
||||
# NEXT_INPUT_MODE,
|
||||
# PREV_GAME_MODE,
|
||||
# NEXT_GAME_MODE,
|
||||
QUIT,
|
||||
}
|
||||
var actions = {} # Registered actions
|
||||
var _focus = null # The node that has focus
|
||||
|
||||
|
||||
func _set_focus(value):
|
||||
_focus = value
|
||||
print("New focus: ", value)
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
_connect_action("Main/Jouer", Actions.PLAY)
|
||||
_connect_action("Main/Options", Actions.ENTER_OPTIONS)
|
||||
_connect_action("Main/Quitter", Actions.QUIT)
|
||||
|
||||
_connect_action("Options/Return", Actions.EXIT_OPTIONS)
|
||||
_connect_action("Options/TrackSelection/LeftArrow", Actions.PREV_TRACK)
|
||||
_connect_action("Options/TrackSelection/RightArrow", Actions.NEXT_TRACK)
|
||||
|
||||
TrackSelection.connect("track_changed", self, "_on_track_changed")
|
||||
_on_track_changed()
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if _focus != null:
|
||||
if event.button_index == BUTTON_LEFT and event.pressed:
|
||||
match _focus:
|
||||
Actions.PLAY:
|
||||
emit_signal("game_started")
|
||||
Actions.CHANGE_TRACK:
|
||||
emit_signal("track_changed")
|
||||
Actions.QUIT:
|
||||
get_tree().quit()
|
||||
# TODO: Handle navigation
|
||||
if event is InputEventMouseButton and _focus != null:
|
||||
if event.button_index == BUTTON_LEFT and event.pressed:
|
||||
match actions[_focus]:
|
||||
Actions.PLAY:
|
||||
emit_signal("game_started")
|
||||
Actions.ENTER_OPTIONS:
|
||||
$Main.set_visible(false)
|
||||
$Options.set_visible(true)
|
||||
Actions.EXIT_OPTIONS:
|
||||
$Main.set_visible(true)
|
||||
$Options.set_visible(false)
|
||||
Actions.QUIT:
|
||||
get_tree().quit()
|
||||
Actions.PREV_TRACK:
|
||||
TrackSelection.set_previous_track()
|
||||
Actions.NEXT_TRACK:
|
||||
TrackSelection.set_next_track()
|
||||
|
||||
func _on_Jouer_mouse_exited():
|
||||
get_node("Main/Jouer").set("custom_colors/font_color", Color.white)
|
||||
|
||||
func _on_track_changed():
|
||||
get_node("Options/TrackSelection/Value").set_text(TrackSelection.get_current_track_name())
|
||||
|
||||
|
||||
func _connect_action(node_path, action):
|
||||
var node = get_node(node_path)
|
||||
node.connect("mouse_entered", self, "set_focus", [node])
|
||||
node.connect("mouse_exited", self, "leave_focus", [node])
|
||||
actions[node] = action
|
||||
|
||||
|
||||
func set_focus(node):
|
||||
_set_active(true, node)
|
||||
_focus = node
|
||||
|
||||
|
||||
func leave_focus(node):
|
||||
_set_active(false, node)
|
||||
_focus = null
|
||||
|
||||
|
||||
func _on_Jouer_mouse_entered():
|
||||
get_node("Main/Jouer").set("custom_colors/font_color", Color.orange)
|
||||
_set_focus(Actions.PLAY)
|
||||
|
||||
func _on_Options_mouse_exited():
|
||||
get_node("Main/Options").set("custom_colors/font_color", Color.white)
|
||||
_focus = null
|
||||
|
||||
func _on_Options_mouse_entered():
|
||||
get_node("Main/Options").set("custom_colors/font_color", Color.orange)
|
||||
_set_focus(Actions.CHANGE_TRACK)
|
||||
|
||||
|
||||
func _on_Quitter_mouse_entered():
|
||||
get_node("Main/Quitter").set("custom_colors/font_color", Color.orange)
|
||||
_set_focus(Actions.QUIT)
|
||||
|
||||
func _on_Quitter_mouse_exited():
|
||||
get_node("Main/Quitter").set("custom_colors/font_color", Color.white)
|
||||
_focus = null
|
||||
func _set_active(is_active, node):
|
||||
# Updates the focus effect for node
|
||||
var color = Color.orange if is_active else Color.white
|
||||
node.set("custom_colors/font_color", color)
|
||||
Reference in New Issue
Block a user