114 lines
3.2 KiB
GDScript
114 lines
3.2 KiB
GDScript
extends Control
|
|
|
|
signal game_started()
|
|
signal skin_changed(skin)
|
|
|
|
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 _ready():
|
|
_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)
|
|
_connect_action("Options/GameMode/LeftArrow", Actions.PREV_GAME_MODE)
|
|
_connect_action("Options/GameMode/RightArrow", Actions.NEXT_GAME_MODE)
|
|
_connect_action("Options/InputMode/LeftArrow", Actions.PREV_INPUT_MODE)
|
|
_connect_action("Options/InputMode/RightArrow", Actions.NEXT_INPUT_MODE)
|
|
_update_options_values()
|
|
|
|
TrackSelection.connect("track_changed", self, "_on_track_changed")
|
|
_on_track_changed()
|
|
|
|
|
|
func _input(event):
|
|
# 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()
|
|
Actions.NEXT_GAME_MODE,Actions.PREV_GAME_MODE:
|
|
if Global.settings.game_mode == Global.GameMode.TRAIN:
|
|
Global.settings.game_mode = Global.GameMode.EASY
|
|
else:
|
|
Global.settings.game_mode = Global.GameMode.TRAIN
|
|
_update_options_values()
|
|
|
|
Actions.NEXT_INPUT_MODE,Actions.PREV_INPUT_MODE:
|
|
if Global.settings.input_mode == Global.InputMode.MOUSE:
|
|
Global.settings.input_mode = Global.InputMode.KEYBOARD
|
|
else:
|
|
Global.settings.input_mode = Global.InputMode.MOUSE
|
|
_update_options_values()
|
|
|
|
|
|
|
|
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 _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)
|
|
|
|
|
|
func _update_options_values():
|
|
var new_text
|
|
match Global.settings.game_mode:
|
|
Global.GameMode.EASY: new_text = "Facile"
|
|
Global.GameMode.TRAIN: new_text = "Entraînement"
|
|
get_node("Options/GameMode/Value").set_text(new_text)
|
|
|
|
match Global.settings.input_mode:
|
|
Global.InputMode.MOUSE: new_text = "Souris"
|
|
Global.InputMode.KEYBOARD: new_text = "Clavier"
|
|
get_node("Options/InputMode/Value").set_text(new_text) |