summaryrefslogtreecommitdiff
path: root/addons/escoria-ui-keyboard-9verbs/game.gd
diff options
context:
space:
mode:
authorradiohotline <radoihotline@disroot.rg>2026-08-25 16:33:56 +0300
committerradiohotline <radoihotline@disroot.rg>2026-08-25 16:33:56 +0300
commita89e744ed0e8c759caf041a580112365bbfe4303 (patch)
treedd61e320904176995727e86a857d00c90d4933ba /addons/escoria-ui-keyboard-9verbs/game.gd
parent6d53d8cac78250dc888aa49d5f9d4175c6652feb (diff)
escoria updateHEADmain
Diffstat (limited to 'addons/escoria-ui-keyboard-9verbs/game.gd')
-rw-r--r--addons/escoria-ui-keyboard-9verbs/game.gd111
1 files changed, 60 insertions, 51 deletions
diff --git a/addons/escoria-ui-keyboard-9verbs/game.gd b/addons/escoria-ui-keyboard-9verbs/game.gd
index 0e55973..e1b80fc 100644
--- a/addons/escoria-ui-keyboard-9verbs/game.gd
+++ b/addons/escoria-ui-keyboard-9verbs/game.gd
@@ -1,17 +1,6 @@
extends ESCGame
-const VERB_CLOSE = "close"
-const VERB_GIVE = "give"
-const VERB_LOOK = "look"
-const VERB_OPEN = "open"
-const VERB_PICKUP = "pickup"
-const VERB_PULL = "pull"
-const VERB_PUSH = "push"
-const VERB_TALK = "talk"
-const VERB_USE = "use"
-
-
"""
Implement methods to react to inputs.
@@ -49,6 +38,17 @@ Implement methods to react to inputs.
- _on_event_done(event_name: String)
"""
+const VERB_CLOSE = "close"
+const VERB_GIVE = "give"
+const VERB_LOOK = "look"
+const VERB_OPEN = "open"
+const VERB_PICKUP = "pickup"
+const VERB_PULL = "pull"
+const VERB_PUSH = "push"
+const VERB_TALK = "talk"
+const VERB_USE = "use"
+
+const INPUT_MAP = preload("res://addons/escoria-ui-keyboard-9verbs/input_map.gd")
@onready var verbs_menu = $ui/Control/panel_down/VBoxContainer/HBoxContainer\
/VerbsMargin/verbs_menu
@@ -58,7 +58,6 @@ Implement methods to react to inputs.
/MainMargin/VBoxContainer/room_select
@onready var inventory_ui = $ui/Control/panel_down/VBoxContainer/HBoxContainer\
/InventoryMargin/inventory_ui
-const input_map = preload("res://addons/escoria-ui-keyboard-9verbs/input_map.gd")
func _enter_tree():
var room_selector_parent = $ui/Control/panel_down/VBoxContainer\
@@ -75,46 +74,45 @@ func _enter_tree():
var input_handler = Callable(self, "_process_input")
escoria.inputs_manager.register_custom_input_handler(input_handler)
- input_map.add_actions_to_input_map()
+ INPUT_MAP.add_actions_to_input_map()
func _exit_tree():
escoria.inputs_manager.register_custom_input_handler(null)
- input_map.erase_actions_from_input_map()
+ INPUT_MAP.erase_actions_from_input_map()
func _process_input(event: InputEvent, is_default_state: bool) -> bool:
if not is_default_state:
return false
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_OPEN):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_OPEN):
verbs_menu.on_action_selected(VERB_OPEN)
return true
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_PICKUP):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_PICKUP):
verbs_menu.on_action_selected(VERB_PICKUP)
return true
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_PUSH):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_PUSH):
verbs_menu.on_action_selected(VERB_PUSH)
return true
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_CLOSE):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_CLOSE):
verbs_menu.on_action_selected(VERB_CLOSE)
return true
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_LOOK):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_LOOK):
verbs_menu.on_action_selected(VERB_LOOK)
return true
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_PULL):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_PULL):
verbs_menu.on_action_selected(VERB_PULL)
return true
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_GIVE):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_GIVE):
verbs_menu.on_action_selected(VERB_GIVE)
return true
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_USE):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_USE):
verbs_menu.on_action_selected(VERB_USE)
return true
- elif event.is_action_pressed(input_map.ACTION_SET_VERB_TALK):
+ if event.is_action_pressed(INPUT_MAP.ACTION_SET_VERB_TALK):
verbs_menu.on_action_selected(VERB_TALK)
return true
- else:
- return false
+ return false
## BACKGROUND ##
@@ -166,14 +164,14 @@ func element_focused(element_id: String) -> void:
# (ie verb+item(+target)) because the action is now being executed
# and the tooltip is already set because the item was focused
# (see element_focused() and inventory_item_focused())
- ESCActionManager.ACTION_INPUT_STATE.COMPLETED:
+ ESCActionManager.ActionInputState.COMPLETED:
return
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM, \
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_VERB_OR_ITEM, \
+ ESCActionManager.ActionInputState.AWAITING_ITEM:
tooltip.set_target(target_obj.tooltip_name)
-
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_TARGET_ITEM:
+ verbs_menu.set_by_name(target_obj.default_action)
+ ESCActionManager.ActionInputState.AWAITING_TARGET_ITEM:
tooltip.set_target2(target_obj.tooltip_name)
@@ -183,15 +181,15 @@ func element_unfocused() -> void:
# (ie verb+item(+target)) because the action is now being executed
# and the tooltip is already set because the item was focused
# (see element_focused() and inventory_item_focused())
- ESCActionManager.ACTION_INPUT_STATE.COMPLETED:
+ ESCActionManager.ActionInputState.COMPLETED:
return
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM, \
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_VERB_OR_ITEM, \
+ ESCActionManager.ActionInputState.AWAITING_ITEM:
tooltip.set_target("")
verbs_menu.unselect_actions()
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_TARGET_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_TARGET_ITEM:
tooltip.set_target2("")
@@ -213,23 +211,34 @@ func left_click_on_item(item_global_id: String, event: InputEvent) -> void:
# (ie verb+item(+target)) because the action is now being executed
# and the tooltip is already set because the item was focused
# (see element_focused() and inventory_item_focused())
- ESCActionManager.ACTION_INPUT_STATE.COMPLETED:
+ ESCActionManager.ActionInputState.COMPLETED:
return
# Just clicked on the item
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM, \
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_VERB_OR_ITEM, \
+ ESCActionManager.ActionInputState.AWAITING_ITEM:
tooltip.set_target(target_obj.tooltip_name)
# Clicked on item and now we're awaiting a target item
# This means we clicked the tool and we now need a target
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_TARGET_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_TARGET_ITEM:
tooltip.set_target(target_obj.tooltip_name, true)
func right_click_on_item(item_global_id: String, event: InputEvent) -> void:
- escoria.action_manager.set_current_action(verbs_menu.selected_action)
+ var action_verb: String = escoria.action_manager.current_action
+ if action_verb.is_empty():
+ action_verb = verbs_menu.selected_action
+ if action_verb.is_empty():
+ action_verb = escoria.object_manager.get_object(item_global_id).node.default_action
+ if action_verb.is_empty():
+ escoria.logger.warn(
+ self,
+ "Right click event: No default action verb defined for item %s. Aborting." % [item_global_id]
+ )
+ return
+ escoria.action_manager.set_current_action(action_verb)
escoria.action_manager.do(
escoria.action_manager.ACTION.ITEM_RIGHT_CLICK,
[item_global_id, event],
@@ -261,17 +270,17 @@ func left_click_on_inventory_item(inventory_item_global_id: String, event: Input
# (ie verb+item(+target)) because the action is now being executed
# and the tooltip is already set because the item was focused
# (see element_focused() and inventory_item_focused())
- ESCActionManager.ACTION_INPUT_STATE.COMPLETED:
+ ESCActionManager.ActionInputState.COMPLETED:
return
# Just clicked on the inventory item: do nothing special
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM, \
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_VERB_OR_ITEM, \
+ ESCActionManager.ActionInputState.AWAITING_ITEM:
return
# Clicked on inventory item and now we're awaiting a target item
# This means we clicked the tool and we now need a target
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_TARGET_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_TARGET_ITEM:
tooltip.set_target(target_obj.tooltip_name, true)
@@ -297,35 +306,35 @@ func inventory_item_focused(inventory_item_global_id: String) -> void:
# (ie verb+item(+target)) because the action is now being executed
# and the tooltip is already set because the item was focused
# (see element_focused() and inventory_item_focused())
- ESCActionManager.ACTION_INPUT_STATE.COMPLETED:
+ ESCActionManager.ActionInputState.COMPLETED:
return
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM, \
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_VERB_OR_ITEM, \
+ ESCActionManager.ActionInputState.AWAITING_ITEM:
tooltip.set_target(target_obj.tooltip_name)
# Hovering an ESCItem highlights its default action
if escoria.action_manager.current_action != VERB_USE and target_obj is ESCItem:
verbs_menu.set_by_name(target_obj.default_action)
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_TARGET_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_TARGET_ITEM:
tooltip.set_target2(target_obj.tooltip_name)
func inventory_item_unfocused() -> void:
match escoria.action_manager.action_state:
- ESCActionManager.ACTION_INPUT_STATE.COMPLETED:
+ ESCActionManager.ActionInputState.COMPLETED:
# Don't change the tooltip if an action input is completed
# (ie verb+item(+target)) because the action is now being executed
return
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM, \
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_VERB_OR_ITEM, \
+ ESCActionManager.ActionInputState.AWAITING_ITEM:
tooltip.set_target("")
verbs_menu.unselect_actions()
- ESCActionManager.ACTION_INPUT_STATE.AWAITING_TARGET_ITEM:
+ ESCActionManager.ActionInputState.AWAITING_TARGET_ITEM:
tooltip.set_target2("")