Port: full rtmi-ui plugin
This commit is contained in:
@@ -13,11 +13,11 @@ var item_count_manager = ESCItemCountManager.new()
|
|||||||
|
|
||||||
# Return the descriptor of the arguments of this command
|
# Return the descriptor of the arguments of this command
|
||||||
func configure() -> ESCCommandArgumentDescriptor:
|
func configure() -> ESCCommandArgumentDescriptor:
|
||||||
return ESCCommandArgumentDescriptor.new(
|
return ESCCommandArgumentDescriptor.new(
|
||||||
1,
|
1,
|
||||||
[TYPE_STRING, TYPE_INT],
|
[TYPE_STRING, TYPE_INT],
|
||||||
[null, 1]
|
[null, 1]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Validate wether the given arguments match the command descriptor
|
# Validate wether the given arguments match the command descriptor
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var item_count_manager = ESCItemCountManager.new()
|
|||||||
|
|
||||||
# Return the descriptor of the arguments of this command
|
# Return the descriptor of the arguments of this command
|
||||||
func configure() -> ESCCommandArgumentDescriptor:
|
func configure() -> ESCCommandArgumentDescriptor:
|
||||||
return ESCCommandArgumentDescriptor.new()
|
return ESCCommandArgumentDescriptor.new()
|
||||||
|
|
||||||
|
|
||||||
# Validate wether the given arguments match the command descriptor
|
# Validate wether the given arguments match the command descriptor
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func set_current_action(action: String):
|
|||||||
if action_state == ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM:
|
if action_state == ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM:
|
||||||
set_action_input_state(ACTION_INPUT_STATE.AWAITING_ITEM)
|
set_action_input_state(ACTION_INPUT_STATE.AWAITING_ITEM)
|
||||||
elif action_state == ACTION_INPUT_STATE.AWAITING_VERB:
|
elif action_state == ACTION_INPUT_STATE.AWAITING_VERB:
|
||||||
set_action_input_state(ACTION_INPUT_STATE.AWAITING_VERB_CONFIRM)
|
set_action_input_state(ACTION_INPUT_STATE.AWAITING_VERB_CONFIRMATION)
|
||||||
|
|
||||||
emit_signal("action_changed")
|
emit_signal("action_changed")
|
||||||
|
|
||||||
@@ -39,14 +39,14 @@ func _get_event_to_queue(
|
|||||||
action: String,
|
action: String,
|
||||||
target: ESCObject,
|
target: ESCObject,
|
||||||
combine_with: ESCObject = null
|
combine_with: ESCObject = null
|
||||||
) -> ESCEvent:
|
) -> ESCGrammarStmts.Event:
|
||||||
|
|
||||||
escoria.logger.info(
|
escoria.logger.info(
|
||||||
self,
|
self,
|
||||||
"Checking if action '%s' on '%s' is valid..." % [action, target]
|
"Checking if action '%s' on '%s' is valid..." % [action, target]
|
||||||
)
|
)
|
||||||
|
|
||||||
var event_to_return: ESCEvent = null
|
var event_to_return = null
|
||||||
|
|
||||||
# If we're using an action which item requires to combine
|
# If we're using an action which item requires to combine
|
||||||
if target.node is ESCItem \
|
if target.node is ESCItem \
|
||||||
@@ -189,7 +189,7 @@ func perform_inputevent_on_object(
|
|||||||
elif action_state == ACTION_INPUT_STATE.AWAITING_ITEM and need_combine and not tool_just_set:
|
elif action_state == ACTION_INPUT_STATE.AWAITING_ITEM and need_combine and not tool_just_set:
|
||||||
set_action_input_state(ACTION_INPUT_STATE.AWAITING_TARGET_ITEM)
|
set_action_input_state(ACTION_INPUT_STATE.AWAITING_TARGET_ITEM)
|
||||||
|
|
||||||
var event_to_queue: ESCEvent = null
|
var event_to_queue: ESCGrammarStmts.Event = null
|
||||||
|
|
||||||
# Manage exits
|
# Manage exits
|
||||||
if obj.node.is_exit and current_action in ["", ACTION_WALK]:
|
if obj.node.is_exit and current_action in ["", ACTION_WALK]:
|
||||||
@@ -241,15 +241,12 @@ func perform_inputevent_on_object(
|
|||||||
if not obj.node is ESCPlayer and \
|
if not obj.node is ESCPlayer and \
|
||||||
not escoria.inventory_manager.inventory_has(obj.global_id) and \
|
not escoria.inventory_manager.inventory_has(obj.global_id) and \
|
||||||
not event_flags & ESCEvent.FLAG_TK:
|
not event_flags & ESCEvent.FLAG_TK:
|
||||||
var context = _walk_towards_object(
|
var context = await _walk_towards_object(
|
||||||
obj,
|
obj,
|
||||||
event.position,
|
event.position,
|
||||||
event.doubleclick
|
event.doubleclick
|
||||||
)
|
)
|
||||||
|
|
||||||
if context is GDScriptFunctionState:
|
|
||||||
context = await context.completed
|
|
||||||
|
|
||||||
# In case of an interrupted walk, we don't want to proceed.
|
# In case of an interrupted walk, we don't want to proceed.
|
||||||
if context == null:
|
if context == null:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -50,9 +50,8 @@ func removeFromInventoryIfCountLessThan(global_id: String, value:= 1) -> void:
|
|||||||
func get_item(global_id: String) -> ESCItem:
|
func get_item(global_id: String) -> ESCItem:
|
||||||
var node = escoria.object_manager.get_object(global_id).node
|
var node = escoria.object_manager.get_object(global_id).node
|
||||||
if not node is ESCItem:
|
if not node is ESCItem:
|
||||||
escoria.logger.error(
|
escoria.logger.error(self,
|
||||||
"item_count_add: invalid object",
|
"Object is not an ESCItem"
|
||||||
["Object is not an ESCItem"]
|
|
||||||
)
|
)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
@tool
|
@tool
|
||||||
|
@icon("res://addons/escoria-core/design/esc_item.svg")
|
||||||
extends ESCItem
|
extends ESCItem
|
||||||
class_name ESCItemWithTooltip, "res://addons/escoria-core/design/esc_item.svg"
|
class_name ESCItemWithTooltip
|
||||||
|
|
||||||
# Action 3 tooltip texts if item is target. Dictionary with tool's global id as key.
|
# Action 3 tooltip texts if item is target. Dictionary with tool's global id as key.
|
||||||
@export var action3_target_texts: Dictionary = {}
|
@export var action3_target_texts: Dictionary = {}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
@tool
|
@tool
|
||||||
|
@icon("res://addons/escoria-core/design/esc_player.svg")
|
||||||
extends ESCItemWithTooltip
|
extends ESCItemWithTooltip
|
||||||
class_name ESCPlayerWithTooltip, "res://addons/escoria-core/design/esc_player.svg"
|
class_name ESCPlayerWithTooltip
|
||||||
|
|
||||||
# Whether the player can be selected like an item
|
# Whether the player can be selected like an item
|
||||||
@export var selectable: bool = false
|
@export var selectable: bool = false
|
||||||
@@ -8,7 +9,6 @@ class_name ESCPlayerWithTooltip, "res://addons/escoria-core/design/esc_player.sv
|
|||||||
|
|
||||||
# A player is always movable
|
# A player is always movable
|
||||||
func _init():
|
func _init():
|
||||||
super._init()
|
|
||||||
is_movable = true
|
is_movable = true
|
||||||
_force_registration = true
|
_force_registration = true
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,8 @@ const ONE_LINE_HEIGHT = 16
|
|||||||
var current_action: String
|
var current_action: String
|
||||||
|
|
||||||
# Target item/hotspot
|
# Target item/hotspot
|
||||||
var current_target: String: set = set_target
|
var current_target: String
|
||||||
|
var current_target_object: Object
|
||||||
var current_target_object: Object = null: set = set_target_object
|
|
||||||
|
|
||||||
# Preposition: on, with...
|
# Preposition: on, with...
|
||||||
var current_prep: String = "with"
|
var current_prep: String = "with"
|
||||||
|
|
||||||
@@ -58,7 +56,7 @@ var debug_texturerect_node: TextureRect
|
|||||||
var _room_is_ready: bool = false
|
var _room_is_ready: bool = false
|
||||||
|
|
||||||
# Tooltips are hidden
|
# Tooltips are hidden
|
||||||
var hidden: bool = false
|
var hiddenTooltip: bool = false
|
||||||
|
|
||||||
signal tooltip_size_updated
|
signal tooltip_size_updated
|
||||||
|
|
||||||
@@ -262,7 +260,7 @@ func tooltip_distance_to_edge_right(position: Vector2):
|
|||||||
|
|
||||||
func show():
|
func show():
|
||||||
escoria.logger.info(self, "show")
|
escoria.logger.info(self, "show")
|
||||||
hidden = false
|
hiddenTooltip = false
|
||||||
update_tooltip_text()
|
update_tooltip_text()
|
||||||
|
|
||||||
func hide():
|
func hide():
|
||||||
@@ -271,7 +269,7 @@ func hide():
|
|||||||
$tooltip2.visible = false;
|
$tooltip2.visible = false;
|
||||||
|
|
||||||
func setHidden():
|
func setHidden():
|
||||||
hidden = true
|
hiddenTooltip = true
|
||||||
hide()
|
hide()
|
||||||
|
|
||||||
# Clear the tooltip targets texts
|
# Clear the tooltip targets texts
|
||||||
|
|||||||
@@ -59,15 +59,15 @@ const DEADZONE = 0.2
|
|||||||
# Multiplier to apply to axis when it exceeds DEADZONE.
|
# Multiplier to apply to axis when it exceeds DEADZONE.
|
||||||
const AXIS_WEIGHT = 50.0
|
const AXIS_WEIGHT = 50.0
|
||||||
|
|
||||||
# JOY_BUTTON_2 corresponds to the "X" button on an XBox controller
|
# JOY_BUTTON_X corresponds to the "X" button on an XBox controller
|
||||||
# or the Square button on a Playstation controller. These appear to
|
# or the Square button on a Playstation controller. These appear to
|
||||||
# map to the "primary action," in practice, so we treat it like a left click.
|
# map to the "primary action," in practice, so we treat it like a left click.
|
||||||
const PRIMARY_ACTION_BUTTON = JOY_BUTTON_2
|
const PRIMARY_ACTION_BUTTON = JOY_BUTTON_X
|
||||||
|
|
||||||
# JOY_BUTTON_3 corresponds to the "Y" button on an XBox controller
|
# JOY_BUTTON_Y corresponds to the "Y" button on an XBox controller
|
||||||
# or the Triangle button on a Playstation controller. These appear to
|
# or the Triangle button on a Playstation controller. These appear to
|
||||||
# map to the "secondary action," in practice, so we treat it like a right click.
|
# map to the "secondary action," in practice, so we treat it like a right click.
|
||||||
const CHANGE_VERB_BUTTON = JOY_BUTTON_3
|
const CHANGE_VERB_BUTTON = JOY_BUTTON_Y
|
||||||
|
|
||||||
# Input action for use by InputMap
|
# Input action for use by InputMap
|
||||||
const ESC_UI_CHANGE_VERB_ACTION = "esc_change_verb"
|
const ESC_UI_CHANGE_VERB_ACTION = "esc_change_verb"
|
||||||
@@ -124,7 +124,7 @@ func _enter_tree():
|
|||||||
room_selector.visible = false
|
room_selector.visible = false
|
||||||
|
|
||||||
|
|
||||||
var input_handler = funcref(self, "_process_input")
|
var input_handler = Callable(self, "_process_input")
|
||||||
escoria.inputs_manager.register_custom_input_handler(input_handler)
|
escoria.inputs_manager.register_custom_input_handler(input_handler)
|
||||||
|
|
||||||
_is_gamepad_connected = Input.is_joy_known(JOY_DEVICE)
|
_is_gamepad_connected = Input.is_joy_known(JOY_DEVICE)
|
||||||
@@ -203,13 +203,13 @@ func _process(_delta) -> void:
|
|||||||
if !_is_gamepad_connected:
|
if !_is_gamepad_connected:
|
||||||
return
|
return
|
||||||
|
|
||||||
var x = Input.get_joy_axis(JOY_DEVICE, JOY_AXIS_0)
|
var x = Input.get_joy_axis(JOY_DEVICE, JOY_AXIS_LEFT_X)
|
||||||
var y = Input.get_joy_axis(JOY_DEVICE, JOY_AXIS_1)
|
var y = Input.get_joy_axis(JOY_DEVICE, JOY_AXIS_LEFT_Y)
|
||||||
var delta_x = int(x * AXIS_WEIGHT) if abs(x) > DEADZONE else 0
|
var delta_x = int(x * AXIS_WEIGHT) if abs(x) > DEADZONE else 0
|
||||||
var delta_y = int(y * AXIS_WEIGHT) if abs(y) > DEADZONE else 0
|
var delta_y = int(y * AXIS_WEIGHT) if abs(y) > DEADZONE else 0
|
||||||
if delta_x or delta_y:
|
if delta_x or delta_y:
|
||||||
var direction = Vector2(delta_x, delta_y)
|
var direction = Vector2(delta_x, delta_y)
|
||||||
escoria.logger.trace("gamepad direction:", [direction])
|
escoria.logger.trace(self, "gamepad direction: %s" % [direction])
|
||||||
var viewport = get_viewport()
|
var viewport = get_viewport()
|
||||||
viewport.warp_mouse(viewport.get_mouse_position() + direction)
|
viewport.warp_mouse(viewport.get_mouse_position() + direction)
|
||||||
|
|
||||||
@@ -220,14 +220,14 @@ func _process_input(event: InputEvent, is_default_state: bool) -> bool:
|
|||||||
# the "New Game" screen.
|
# the "New Game" screen.
|
||||||
return false
|
return false
|
||||||
elif _is_gamepad_connected and event is InputEventJoypadButton:
|
elif _is_gamepad_connected and event is InputEventJoypadButton:
|
||||||
escoria.logger.trace("InputEventJoypadButton:", [event.as_text()])
|
escoria.logger.trace(self, "InputEventJoypadButton: %s" % [event.as_text()])
|
||||||
if event.is_action_pressed(escoria.inputs_manager.ESC_UI_PRIMARY_ACTION):
|
if event.is_action_pressed(escoria.inputs_manager.ESC_UI_PRIMARY_ACTION):
|
||||||
# Admittedly, this breaks abstraction barriers and is completely
|
# Admittedly, this breaks abstraction barriers and is completely
|
||||||
# inappropriate, but it's what works right now.
|
# inappropriate, but it's what works right now.
|
||||||
escoria.inputs_manager._on_left_click_on_bg(get_global_mouse_position())
|
escoria.inputs_manager._on_left_click_on_bg(get_global_mouse_position())
|
||||||
return true
|
return true
|
||||||
elif event.is_action_pressed(ESC_UI_CHANGE_VERB_ACTION):
|
elif event.is_action_pressed(ESC_UI_CHANGE_VERB_ACTION):
|
||||||
escoria.logger.error("Someone invoked ESC_UI_CHANGE_VERB_ACTION:", [event.as_text()])
|
escoria.logger.error(self, "Someone invoked ESC_UI_CHANGE_VERB_ACTION: %s" % [event.as_text()])
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
@@ -477,7 +477,7 @@ func correctPosition(tooltip: ESCRichTooltip, size: Vector2, mouse_position: Vec
|
|||||||
return mouse_position - offset
|
return mouse_position - offset
|
||||||
|
|
||||||
func _on_event_done(return_code: int, _event_name: String):
|
func _on_event_done(return_code: int, _event_name: String):
|
||||||
escoria.logger.info(self, "EVENT DONE! code=" + String(return_code))
|
escoria.logger.info(self, "EVENT DONE! code= %s" % [return_code])
|
||||||
|
|
||||||
# Reset mouse cursor (should be not needed, but avoids not resetting the cursor on bugs)
|
# Reset mouse cursor (should be not needed, but avoids not resetting the cursor on bugs)
|
||||||
Input.set_custom_mouse_cursor(null)
|
Input.set_custom_mouse_cursor(null)
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ func _ready():
|
|||||||
var collision = get_parent().collision
|
var collision = get_parent().collision
|
||||||
if collision is CollisionPolygon2D:
|
if collision is CollisionPolygon2D:
|
||||||
outline = ItemOutline.new()
|
outline = ItemOutline.new()
|
||||||
outline.polygon = collision.get("polygon")
|
outline.polygon = collision.get("polygon")
|
||||||
outline.color = Color(1,1,1,0.2)
|
outline.color = Color(1, 1, 1, 0.2)
|
||||||
outline.set_outline_width(2.0)
|
outline.set_outline_width(2.0)
|
||||||
outline.set_outline_color(Color(1,1,1,1))
|
outline.set_outline_color(Color(1, 1, 1, 1))
|
||||||
collision.add_child(outline)
|
collision.add_child(outline)
|
||||||
outline.hide()
|
outline.hide()
|
||||||
|
|
||||||
@@ -26,9 +26,9 @@ func highlight(value: bool):
|
|||||||
|
|
||||||
func _process(_delta: float):
|
func _process(_delta: float):
|
||||||
if not outline is ItemOutline:
|
if not outline is ItemOutline:
|
||||||
return
|
return
|
||||||
if isHighlighted != lastHighlightState:
|
if isHighlighted != lastHighlightState:
|
||||||
if isHighlighted and escoria.current_state == escoria.GAME_STATE.DEFAULT and get_parent().is_interactive:
|
if isHighlighted and escoria.current_state == escoria.GAME_STATE.DEFAULT and get_parent().is_interactive:
|
||||||
outline.show()
|
outline.show()
|
||||||
else:
|
else:
|
||||||
outline.hide()
|
outline.hide()
|
||||||
|
|||||||
@@ -167,16 +167,8 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
|
|||||||
# forcing the registration, since we don't know if this object will be
|
# forcing the registration, since we don't know if this object will be
|
||||||
# overwritten ("forced") in the future and, if it is, if it's set to
|
# overwritten ("forced") in the future and, if it is, if it's set to
|
||||||
# auto-unregister or not. In most cases, objects are set to auto unregister.
|
# auto-unregister or not. In most cases, objects are set to auto unregister.
|
||||||
if object.node.is_connected(
|
if object.node.tree_exited.is_connected(unregister_object):
|
||||||
"tree_exited",
|
object.node.tree_exited.disconnect(unregister_object)
|
||||||
self,
|
|
||||||
"unregister_object"
|
|
||||||
):
|
|
||||||
object.node.disconnect(
|
|
||||||
"tree_exited",
|
|
||||||
self,
|
|
||||||
"unregister_object"
|
|
||||||
)
|
|
||||||
|
|
||||||
if force:
|
if force:
|
||||||
# If this ID already exists and we're about to overwrite it, do the
|
# If this ID already exists and we're about to overwrite it, do the
|
||||||
@@ -184,12 +176,7 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
|
|||||||
unregister_object_by_global_id(object.global_id, room_key)
|
unregister_object_by_global_id(object.global_id, room_key)
|
||||||
|
|
||||||
if auto_unregister:
|
if auto_unregister:
|
||||||
object.node.connect(
|
object.node.tree_exited.connect(unregister_object.bind(object, room_key))
|
||||||
"tree_exited",
|
|
||||||
self,
|
|
||||||
"unregister_object",
|
|
||||||
[object, room_key]
|
|
||||||
)
|
|
||||||
|
|
||||||
if "is_interactive" in object.node and object.node.is_interactive:
|
if "is_interactive" in object.node and object.node.is_interactive:
|
||||||
object.interactive = true
|
object.interactive = true
|
||||||
|
|||||||
Reference in New Issue
Block a user