diff --git a/addons/escoria-core/game/core-scripts/esc_background.gd b/addons/escoria-core/game/core-scripts/esc_background.gd index 32b8f276..e468bcaa 100644 --- a/addons/escoria-core/game/core-scripts/esc_background.gd +++ b/addons/escoria-core/game/core-scripts/esc_background.gd @@ -34,6 +34,12 @@ signal left_click_on_bg(position) # - position: The position where the player clicked signal right_click_on_bg(position) +# Emitted when the mouse wheel was turned up +signal mouse_wheel_up + +# Emitted when the mouse wheel was turned down +signal mouse_wheel_down + # The ESC script connected to this background export(String, FILE, "*.esc") var esc_script = "" @@ -72,9 +78,7 @@ func _ready(): mouse_filter = MOUSE_FILTER_IGNORE if !Engine.is_editor_hint(): - connect("left_click_on_bg", escoria.inputs_manager, "_on_left_click_on_bg") - connect("right_click_on_bg", escoria.inputs_manager, "_on_right_click_on_bg") - connect("double_left_click_on_bg", escoria.inputs_manager, "_on_double_left_click_on_bg") + escoria.inputs_manager.register_background(self) # Manage inputs reaching the Area2D and emit the events to the input manager @@ -86,9 +90,9 @@ func _ready(): func manage_input(_viewport, event, _shape_idx) -> void: if event.is_action_pressed("switch_action_verb"): if event.button_index == BUTTON_WHEEL_UP: - escoria.inputs_manager._on_mousewheel_action(-1) + emit_signal("mouse_wheel_up") elif event.button_index == BUTTON_WHEEL_DOWN: - escoria.inputs_manager._on_mousewheel_action(1) + emit_signal("mouse_wheel_down") if event is InputEventMouseButton: var p = get_global_mouse_position() if event.doubleclick: diff --git a/addons/escoria-core/game/inputs_manager.gd b/addons/escoria-core/game/inputs_manager.gd index a8369412..6bb467e9 100644 --- a/addons/escoria-core/game/inputs_manager.gd +++ b/addons/escoria-core/game/inputs_manager.gd @@ -26,6 +26,66 @@ var hover_stack: Array = [] var hotspot_focused: String = "" +# Connect the item signals to the local methods +func register_inventory_item(item: Node): + item.connect( + "mouse_left_inventory_item", + self, + "_on_mouse_left_click_inventory_item" + ) + item.connect( + "mouse_double_left_inventory_item", + self, + "_on_mouse_double_left_click_inventory_item" + ) + item.connect( + "mouse_right_inventory_item", + self, + "_on_mouse_right_click_inventory_item" + ) + + item.connect( + "inventory_item_focused", + self, + "_on_mouse_entered_inventory_item" + ) + item.connect( + "inventory_item_unfocused", + self, + "_on_mouse_exited_inventory_item" + ) + + +func register_background(background: ESCBackground): + background.connect( + "left_click_on_bg", + self, + "_on_left_click_on_bg" + ) + background.connect( + "right_click_on_bg", + escoria.inputs_manager, + "_on_right_click_on_bg" + ) + background.connect( + "double_left_click_on_bg", + escoria.inputs_manager, + "_on_double_left_click_on_bg" + ) + background.connect( + "mouse_wheel_up", + self, + "_on_mousewheel_action", + [-1] + ) + background.connect( + "mouse_wheel_down", + self, + "_on_mousewheel_action", + [-1] + ) + + # Input event handler # # #### Parameters diff --git a/addons/escoria-core/game/scenes/inventory/inventory_ui.gd b/addons/escoria-core/game/scenes/inventory/inventory_ui.gd index c33bc067..a43e1fa7 100644 --- a/addons/escoria-core/game/scenes/inventory/inventory_ui.gd +++ b/addons/escoria-core/game/scenes/inventory/inventory_ui.gd @@ -81,32 +81,7 @@ func add_new_item_by_id(item_id: String) -> void: item_inventory_button.visible = true - item_inventory_button.connect( - "mouse_left_inventory_item", - escoria.inputs_manager, - "_on_mouse_left_click_inventory_item" - ) - item_inventory_button.connect( - "mouse_double_left_inventory_item", - escoria.inputs_manager, - "_on_mouse_double_left_click_inventory_item" - ) - item_inventory_button.connect( - "mouse_right_inventory_item", - escoria.inputs_manager, - "_on_mouse_right_click_inventory_item" - ) - - item_inventory_button.connect( - "inventory_item_focused", - escoria.inputs_manager, - "_on_mouse_entered_inventory_item" - ) - item_inventory_button.connect( - "inventory_item_unfocused", - escoria.inputs_manager, - "_on_mouse_exited_inventory_item" - ) + escoria.inputs_manager.register_inventory_item(item_inventory_button) # remove item fromInventory UI using its id set in its scene diff --git a/docs/api/ESCBackground.md b/docs/api/ESCBackground.md index 32b055eb..d61a826d 100644 --- a/docs/api/ESCBackground.md +++ b/docs/api/ESCBackground.md @@ -69,3 +69,5 @@ Texture or set size #### Parameters - position: The position where the player clicked +- signal mouse_wheel_up(): Emitted when the mouse wheel was turned up +- signal mouse_wheel_down(): Emitted when the mouse wheel was turned down diff --git a/docs/api/ESCInputsManager.md b/docs/api/ESCInputsManager.md index e7c8e2d9..894329d4 100644 --- a/docs/api/ESCInputsManager.md +++ b/docs/api/ESCInputsManager.md @@ -53,4 +53,21 @@ A LIFO stack of hovered items var hotspot_focused: String = "" ``` -The global id fo the topmost item from the hover_stack \ No newline at end of file +The global id fo the topmost item from the hover_stack + +## Method Descriptions + +### register\_inventory\_item + +```gdscript +func register_inventory_item(item: Node) +``` + +Connect the item signals to the local methods + +### register\_background + +```gdscript +func register_background(background: ESCBackground) +``` +