diff options
Diffstat (limited to 'client/menu/menu.gd')
-rw-r--r-- | client/menu/menu.gd | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/client/menu/menu.gd b/client/menu/menu.gd index 756e80c6..f077f947 100644 --- a/client/menu/menu.gd +++ b/client/menu/menu.gd @@ -29,6 +29,7 @@ signal submenu_close() const transition_scene = preload("res://menu/scene_transition.tscn") var transition: SceneTransition var parent_menu: Menu = null +var previous_path = null # : String var open_since = 0 func _ready(): @@ -40,6 +41,7 @@ func _ready(): update_parent_menu(self.get_parent()) if support_anim: anim_setup() if auto_anim: _menu_open() + get_tree().get_root().go_back_requested.connect(exit_maybe) func anim_setup(): transition = transition_scene.instantiate() @@ -80,20 +82,24 @@ func _disable_recursive(node: Node, state: bool): func exit(): await self._menu_exit() - get_parent().submenu_close.emit() - queue_free() + if previous_path != null: + replace_menu(previous_path) + else: + get_parent().submenu_close.emit() + queue_free() func quit(): await exit() get_parent().quit() -func replace_menu(path: String, data_ = null): +func replace_menu(path: String, data_ = null, prev_path = null): # prev_path: String? print("Replace menu: ", path) if popup != null: await popup.exit() _disable_recursive(self, true) await _menu_exit() - var new_popup = load(path).instantiate() + var new_popup: Menu = load(path).instantiate() new_popup.data = data_ + if prev_path != null: new_popup.previous_path = prev_path get_parent().add_child(new_popup) if parent_menu != null: parent_menu.popup = new_popup queue_free() @@ -132,8 +138,15 @@ func update_parent_menu(node: Node): elif node.get_parent() != null: update_parent_menu(node.get_parent()) func _input(_event): - if popup != null: return - if Time.get_ticks_msec() - open_since < 100: return if Input.is_action_just_pressed("menu"): - Sound.play_click() - exit() + exit_maybe() + if Input.is_action_just_pressed("reset"): + exit_maybe() + +func exit_maybe() -> void: + # Exit menu if all conditions are met + if popup != null: return + var time := Time.get_ticks_msec() + if time - open_since < 100: return + Sound.play_click() + exit() |