106 lines
3.1 KiB
GDScript
106 lines
3.1 KiB
GDScript
extends MarginContainer
|
|
|
|
# class member variables go here, for example:
|
|
# var a = 2
|
|
# var b = "textvar"
|
|
|
|
func _ready():
|
|
# Called every time the node is added to the scene.
|
|
# Initialization here
|
|
$Home.show()
|
|
$Settings.hide()
|
|
|
|
#func _process(delta):
|
|
# # Called every frame. Delta is time since last frame.
|
|
# # Update game logic here.
|
|
# pass
|
|
|
|
|
|
func _on_Home_setting_pressed():
|
|
$Home.hide()
|
|
$Settings.show()
|
|
$Help.hide()
|
|
|
|
|
|
func _on_Settings_return_pressed():
|
|
$Home.show()
|
|
$Settings.hide()
|
|
$Help.show()
|
|
|
|
func _on_Home_play_pressed():
|
|
if not get_tree().paused:
|
|
pause()
|
|
# $Home/MarginContainer/Menu/Buttons/VBoxContainer/PlayButton.text = "Play"
|
|
else:
|
|
play()
|
|
# $Home/MarginContainer/Menu/Buttons/VBoxContainer/PlayButton.text = "Pause"
|
|
|
|
# get_tree().paused = !get_tree().paused
|
|
# if get_tree().paused:-
|
|
# $Home/MarginContainer/Menu/Buttons/VBoxContainer/PlayButton.text = "Play"
|
|
# else:
|
|
# $Home/MarginContainer/Menu/Buttons/VBoxContainer/PlayButton.text = "Pause"
|
|
|
|
func _input(event):
|
|
# TODO revoir l'architecture des events.
|
|
# deplacer le mouvement dans la scene game plutot qu'ici
|
|
# et bloquer l'input sur ll'ui lorsqu'on est en jeu
|
|
# et inversement quand on est dans les menu (mouse free/captured).
|
|
# on ne dois pas naviguer dans les menu qd la souris est capturé (jeu en cours)
|
|
# et on ne dois aps avaner lorsqu'on est dans les menu
|
|
# ou que la souris est liberé pour agir sur les element du HUD?
|
|
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
|
if event.is_action_pressed("ui_test"):
|
|
print( "Event: ui_test" )
|
|
|
|
if event.is_action_pressed("ui_quit"):
|
|
get_tree().quit()
|
|
|
|
if event.is_action_pressed("ui_reload"):
|
|
if not $Settings.visible:
|
|
get_tree().reload_current_scene()
|
|
|
|
if event.is_action_pressed("ui_pause") and not event.is_echo():
|
|
if not $Settings.visible:
|
|
if not get_tree().paused:
|
|
pause()
|
|
else:
|
|
play()
|
|
# accept_event()
|
|
# ----------------------------------
|
|
# Capturing/Freeing the cursor
|
|
if Input.is_action_just_pressed("ui_free_cursor"):
|
|
if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE:
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
|
|
# grab_focus()
|
|
# grab_click_focus()
|
|
# release_focus()
|
|
print("Captured")
|
|
else:
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
|
# ----------------------------------
|
|
|
|
|
|
func pause():
|
|
get_tree().paused = true
|
|
show_menu()
|
|
func play():
|
|
get_tree().paused = false
|
|
hide_menu()
|
|
|
|
|
|
func show_menu():
|
|
$Home.show()
|
|
$Settings.hide()
|
|
$HUD.modulate.a = 0.5
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
|
func hide_menu():
|
|
$Settings.hide()
|
|
$Home.hide()
|
|
$Help.show()
|
|
$HUD.modulate.a = 1.0
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
|
|
func _on_Settings_font_changed( value ):
|
|
$HUD.get_theme().default_font.size = value
|