From a89e744ed0e8c759caf041a580112365bbfe4303 Mon Sep 17 00:00:00 2001 From: radiohotline Date: Tue, 25 Aug 2026 16:33:56 +0300 Subject: escoria update --- addons/escoria-ui-simplemouse/game.gd | 77 +++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 22 deletions(-) (limited to 'addons/escoria-ui-simplemouse/game.gd') diff --git a/addons/escoria-ui-simplemouse/game.gd b/addons/escoria-ui-simplemouse/game.gd index f18444d..4828862 100644 --- a/addons/escoria-ui-simplemouse/game.gd +++ b/addons/escoria-ui-simplemouse/game.gd @@ -1,10 +1,5 @@ extends ESCGame - -const VERB_USE = "use" -const VERB_WALK = "walk" - - """ Implement methods to react to inputs. @@ -42,6 +37,9 @@ Implement methods to react to inputs. - _on_event_done(event_name: String) """ +const VERB_USE = "use" +const VERB_WALK = "walk" + # Value to use for `device` argument to various `Input.get_joy` methods. const JOY_DEVICE = 0 @@ -64,18 +62,20 @@ const CHANGE_VERB_BUTTON = JOY_BUTTON_Y # Input action for use by InputMap const ESC_UI_CHANGE_VERB_ACTION = "esc_change_verb" +var targeted_node: Node + # true when a gamepad is connected. var _is_gamepad_connected = false # Tracks the mouse's current position onscreen. var _current_mouse_pos: Vector2 = Vector2.ZERO -var targeted_node: Node - func _ready(): hide_ui() $ui/tooltip.connect("tooltip_size_updated", Callable(self, "update_tooltip_following_mouse_position")) + escoria.inputs_manager.input_mode_changed.connect(_on_input_mode_changed) + func _enter_tree(): initialize_esc_game() @@ -148,10 +148,13 @@ func _on_gamepad_disconnected(): func _on_joy_connection_changed(device: int, connected: bool) -> void: if device != JOY_DEVICE: return - elif connected: + + _is_gamepad_connected = connected + if connected: _on_gamepad_connected() - else: - _on_gamepad_disconnected() + return + + _on_gamepad_disconnected() func _process(_delta) -> void: @@ -176,16 +179,18 @@ func _process_input(event: InputEvent, is_default_state: bool) -> bool: # ESCBackground is not guaranteed to be set, as we may be on # the "New Game" screen. return false - elif _is_gamepad_connected and event is InputEventJoypadButton: + + if _is_gamepad_connected and event is InputEventJoypadButton: escoria.logger.trace(self, "InputEventJoypadButton: %s" % [event.as_text()]) if event.is_action_pressed(escoria.inputs_manager.ESC_UI_PRIMARY_ACTION): # Admittedly, this breaks abstraction barriers and is completely # inappropriate, but it's what works right now. escoria.inputs_manager._on_left_click_on_bg(get_global_mouse_position()) return true - elif event.is_action_pressed(ESC_UI_CHANGE_VERB_ACTION): - mousewheel_action(1) - return true + + if event.is_action_pressed(ESC_UI_CHANGE_VERB_ACTION): + mousewheel_action(1) + return true return false @@ -335,7 +340,7 @@ func right_click_on_inventory_item(inventory_item_global_id: String, event: Inpu ) -func left_double_click_on_inventory_item(inventory_item_global_id: String, event: InputEvent) -> void: +func left_double_click_on_inventory_item(_inventory_item_global_id: String, _event: InputEvent) -> void: pass @@ -359,6 +364,14 @@ func inventory_item_unfocused() -> void: $mouse_layer/verbs_menu.set_by_name(VERB_WALK) +func open_inventory(): + $ui/inventory_ui.show_inventory() + + +func close_inventory(): + $ui/inventory_ui.hide_inventory() + + func mousewheel_action(direction: int): $mouse_layer/verbs_menu.iterate_actions_cursor(direction) @@ -379,22 +392,26 @@ func show_ui(): func hide_main_menu(): show_ui() - escoria.current_state = escoria.GAME_STATE.DEFAULT + $dialog_layer.propagate_call("set_visible", [true], true) + if escoria.current_state != escoria.GameState.LOADING: + escoria.current_state = escoria.GameState.DEFAULT if get_node(main_menu).visible: get_node(main_menu).hide() func show_main_menu(): - if escoria.current_state == escoria.GAME_STATE.PAUSED: + if escoria.current_state == escoria.GameState.PAUSED: return - escoria.current_state = escoria.GAME_STATE.PAUSED + escoria.current_state = escoria.GameState.PAUSED hide_ui() + $dialog_layer.propagate_call("set_visible", [false], true) if not get_node(main_menu).visible: get_node(main_menu).reset() get_node(main_menu).show() func unpause_game(): show_ui() - escoria.current_state = escoria.GAME_STATE.DEFAULT + $dialog_layer.propagate_call("set_visible", [true], true) + escoria.current_state = escoria.GameState.DEFAULT if get_node(pause_menu).visible: get_node(pause_menu).hide() escoria.object_manager.get_object(ESCObjectManager.SPEECH).node.resume() @@ -403,10 +420,11 @@ func unpause_game(): escoria.set_game_paused(false) func pause_game(): - if escoria.current_state == escoria.GAME_STATE.PAUSED: + if escoria.current_state == escoria.GameState.PAUSED: return - show_ui() - escoria.current_state = escoria.GAME_STATE.PAUSED + hide_ui() + $dialog_layer.propagate_call("set_visible", [false], true) + escoria.current_state = escoria.GameState.PAUSED if not get_node(pause_menu).visible: get_node(main_menu).reset() get_node(pause_menu).reset() @@ -475,3 +493,18 @@ func _on_event_done(_return_code: int, _event_name: String): func _on_room_ready(): $mouse_layer/verbs_menu.set_by_name(VERB_WALK) $mouse_layer/verbs_menu.action_manually_changed = false + +func _on_input_mode_changed(new_mode): + if new_mode == ESCInputsManager.INPUT_NONE: + $mouse_layer/verbs_menu.set_by_name("wait") + return + if ( + escoria.action_manager.action_state + == ESCActionManager.ActionInputState.AWAITING_TARGET_ITEM + ): + return + $mouse_layer/verbs_menu.set_by_name(escoria.action_manager.current_action) + + +func _on_MenuButton_pressed() -> void: + pause_game() -- cgit v1.3