Optimized item and background signal handling (#365)
Co-authored-by: Dennis Ploeger <develop@dieploegers.de> Co-authored-by: dploeger <dploeger@users.noreply.github.com>
This commit is contained in:
@@ -34,6 +34,12 @@ signal left_click_on_bg(position)
|
|||||||
# - position: The position where the player clicked
|
# - position: The position where the player clicked
|
||||||
signal right_click_on_bg(position)
|
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
|
# The ESC script connected to this background
|
||||||
export(String, FILE, "*.esc") var esc_script = ""
|
export(String, FILE, "*.esc") var esc_script = ""
|
||||||
@@ -72,9 +78,7 @@ func _ready():
|
|||||||
mouse_filter = MOUSE_FILTER_IGNORE
|
mouse_filter = MOUSE_FILTER_IGNORE
|
||||||
|
|
||||||
if !Engine.is_editor_hint():
|
if !Engine.is_editor_hint():
|
||||||
connect("left_click_on_bg", escoria.inputs_manager, "_on_left_click_on_bg")
|
escoria.inputs_manager.register_background(self)
|
||||||
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")
|
|
||||||
|
|
||||||
|
|
||||||
# Manage inputs reaching the Area2D and emit the events to the input manager
|
# 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:
|
func manage_input(_viewport, event, _shape_idx) -> void:
|
||||||
if event.is_action_pressed("switch_action_verb"):
|
if event.is_action_pressed("switch_action_verb"):
|
||||||
if event.button_index == BUTTON_WHEEL_UP:
|
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:
|
elif event.button_index == BUTTON_WHEEL_DOWN:
|
||||||
escoria.inputs_manager._on_mousewheel_action(1)
|
emit_signal("mouse_wheel_down")
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
var p = get_global_mouse_position()
|
var p = get_global_mouse_position()
|
||||||
if event.doubleclick:
|
if event.doubleclick:
|
||||||
|
|||||||
@@ -26,6 +26,66 @@ var hover_stack: Array = []
|
|||||||
var hotspot_focused: String = ""
|
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
|
# Input event handler
|
||||||
#
|
#
|
||||||
# #### Parameters
|
# #### Parameters
|
||||||
|
|||||||
@@ -81,32 +81,7 @@ func add_new_item_by_id(item_id: String) -> void:
|
|||||||
|
|
||||||
item_inventory_button.visible = true
|
item_inventory_button.visible = true
|
||||||
|
|
||||||
item_inventory_button.connect(
|
escoria.inputs_manager.register_inventory_item(item_inventory_button)
|
||||||
"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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# remove item fromInventory UI using its id set in its scene
|
# remove item fromInventory UI using its id set in its scene
|
||||||
|
|||||||
@@ -69,3 +69,5 @@ Texture or set size
|
|||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- position: The position where the player clicked
|
- 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
|
||||||
|
|||||||
@@ -53,4 +53,21 @@ A LIFO stack of hovered items
|
|||||||
var hotspot_focused: String = ""
|
var hotspot_focused: String = ""
|
||||||
```
|
```
|
||||||
|
|
||||||
The global id fo the topmost item from the hover_stack
|
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)
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user