feat: Several fixes and optimizations (#467)
Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
@@ -24,7 +24,7 @@ const COMPARISON_DESCRIPTION = [
|
||||
"Checking if %s %s %s equals %s",
|
||||
"Checking if %s %s %s greater than %s",
|
||||
"Checking if %s %s %s less than %s",
|
||||
"Checking if %s is %s active%s"
|
||||
"Checking if %s %s %s active%s"
|
||||
]
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ func _init(comparison_string: String):
|
||||
# Run this comparison against the globals
|
||||
func run() -> bool:
|
||||
var global_name = self.flag
|
||||
|
||||
|
||||
escoria.logger.debug(
|
||||
COMPARISON_DESCRIPTION[self.comparison] % [
|
||||
"inventory item" if self.inventory else "global value",
|
||||
@@ -130,7 +130,7 @@ func run() -> bool:
|
||||
self.comparison_value:
|
||||
return_value = true
|
||||
elif self.comparison == COMPARISON_ACTIVITY and \
|
||||
escoria.object_manager.has_object(global_name) and \
|
||||
escoria.object_manager.has(global_name) and \
|
||||
escoria.object_manager.get_object(global_name).active:
|
||||
return_value = true
|
||||
|
||||
|
||||
@@ -91,9 +91,9 @@ func stop():
|
||||
# - name: The animation name to play
|
||||
# - backwards: Play backwards
|
||||
func play(name: String, backwards: bool = false):
|
||||
if _is_animation_player:
|
||||
if _is_animation_player and _animation_player.current_animation != "":
|
||||
_animation_player.seek(0)
|
||||
else:
|
||||
elif not _is_animation_player:
|
||||
_animated_sprite.frame = 0
|
||||
_current_animation = name
|
||||
if backwards and _is_animation_player:
|
||||
|
||||
@@ -34,7 +34,7 @@ func perform_walk(
|
||||
if destination.node is ESCLocation:
|
||||
target_position = destination.node.global_position
|
||||
else:
|
||||
target_position = destination.node.interact_position
|
||||
target_position = destination.node.get_interact_position()
|
||||
|
||||
var walk_context = ESCWalkContext.new(
|
||||
destination,
|
||||
@@ -127,7 +127,7 @@ func perform_inputevent_on_object(
|
||||
var player_global_pos = escoria.main.current_scene.player.global_position
|
||||
var clicked_position = event.position
|
||||
|
||||
if not player_global_pos == destination_position:
|
||||
if not player_global_pos.is_equal_approx(destination_position):
|
||||
dont_interact = true
|
||||
|
||||
# If no interaction should happen after player has arrived, leave
|
||||
|
||||
@@ -256,34 +256,6 @@ func show_ui():
|
||||
pass
|
||||
|
||||
|
||||
# Function is called if Project setting escoria/ui/tooltip_follows_mouse = true
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - p_position: Position of the mouse
|
||||
func update_tooltip_following_mouse_position(p_position: Vector2):
|
||||
var corrected_position = p_position
|
||||
|
||||
# clamp TOP
|
||||
if tooltip_node.tooltip_distance_to_edge_top(p_position) <= mouse_tooltip_margin:
|
||||
corrected_position.y = mouse_tooltip_margin
|
||||
|
||||
# clamp BOTTOM
|
||||
if tooltip_node.tooltip_distance_to_edge_bottom(p_position + tooltip_node.rect_size) <= mouse_tooltip_margin:
|
||||
corrected_position.y = escoria.game_size.y - mouse_tooltip_margin - tooltip_node.rect_size.y
|
||||
|
||||
# clamp LEFT
|
||||
if tooltip_node.tooltip_distance_to_edge_left(p_position - tooltip_node.rect_size/2) <= mouse_tooltip_margin:
|
||||
corrected_position.x = mouse_tooltip_margin
|
||||
|
||||
# clamp RIGHT
|
||||
if tooltip_node.tooltip_distance_to_edge_right(p_position + tooltip_node.rect_size/2) <= mouse_tooltip_margin:
|
||||
corrected_position.x = escoria.game_size.x - mouse_tooltip_margin - tooltip_node.rect_size.x
|
||||
|
||||
tooltip_node.anchor_right = 0.2
|
||||
tooltip_node.rect_position = corrected_position + tooltip_node.offset_from_cursor
|
||||
|
||||
|
||||
# Set the Editor debug mode
|
||||
func _set_editor_debug_mode(p_editor_debug_mode: int) -> void:
|
||||
editor_debug_mode = p_editor_debug_mode
|
||||
|
||||
@@ -299,10 +299,13 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
if mouse_in_shape:
|
||||
if event.doubleclick and event.button_index == BUTTON_LEFT:
|
||||
emit_signal("mouse_double_left_clicked_item", self, event)
|
||||
get_tree().set_input_as_handled()
|
||||
elif event.button_index == BUTTON_LEFT:
|
||||
emit_signal("mouse_left_clicked_item", self, event)
|
||||
get_tree().set_input_as_handled()
|
||||
elif event.button_index == BUTTON_RIGHT:
|
||||
emit_signal("mouse_right_clicked_item", self, event)
|
||||
get_tree().set_input_as_handled()
|
||||
|
||||
|
||||
# Return the animation player node
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# The escoria main script
|
||||
tool
|
||||
extends Node
|
||||
|
||||
# Signal sent when pause menu has to be displayed
|
||||
@@ -310,12 +311,6 @@ func _input(event):
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
emit_signal("request_pause_menu")
|
||||
|
||||
if ProjectSettings.get_setting("escoria/ui/tooltip_follows_mouse"):
|
||||
if escoria.main.current_scene and escoria.main.current_scene.game:
|
||||
if event is InputEventMouseMotion:
|
||||
escoria.main.current_scene.game. \
|
||||
update_tooltip_following_mouse_position(event.position)
|
||||
|
||||
|
||||
# Pauses or unpause the game
|
||||
#
|
||||
@@ -349,6 +344,110 @@ func run_event_from_script(script: ESCScript, event_name: String):
|
||||
[]
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
# Register a new project setting if it hasn't been defined already
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - name: Name of the project setting
|
||||
# - default: Default value
|
||||
# - info: Property info for the setting
|
||||
func register_setting(name: String, default, info: Dictionary):
|
||||
if not ProjectSettings.has_setting(name):
|
||||
ProjectSettings.set_setting(
|
||||
name,
|
||||
default
|
||||
)
|
||||
info.name = name
|
||||
ProjectSettings.add_property_info(info)
|
||||
|
||||
|
||||
# Register a user interface. This should be called in a deferred way
|
||||
# from the addon's _enter_tree.
|
||||
#
|
||||
# #### Parameters
|
||||
# - game_scene: Path to the game scene extending ESCGame
|
||||
func register_ui(game_scene: String):
|
||||
if not ProjectSettings.get_setting("escoria/ui/game_scene") in [
|
||||
"",
|
||||
game_scene
|
||||
]:
|
||||
logger.report_errors(
|
||||
"escoria.gd:register_ui()",
|
||||
[
|
||||
"Can't register user interface because %s is registered" % \
|
||||
ProjectSettings.get_setting("escoria/ui/game_scene")
|
||||
]
|
||||
)
|
||||
ProjectSettings.set_setting(
|
||||
"escoria/ui/game_scene",
|
||||
game_scene
|
||||
)
|
||||
|
||||
|
||||
# Deregister a user interface
|
||||
#
|
||||
# #### Parameters
|
||||
# - game_scene: Path to the game scene extending ESCGame
|
||||
func deregister_ui(game_scene: String):
|
||||
if ProjectSettings.get_setting("escoria/ui/game_scene") != game_scene:
|
||||
logger.report_errors(
|
||||
"escoria.gd:deregister_ui()",
|
||||
[
|
||||
(
|
||||
"Can't deregister user interface %s because it " +
|
||||
"is not registered."
|
||||
) % ProjectSettings.get_setting("escoria/ui/game_scene")
|
||||
]
|
||||
)
|
||||
ProjectSettings.set_setting(
|
||||
"escoria/ui/game_scene",
|
||||
""
|
||||
)
|
||||
|
||||
|
||||
# Register a dialog manager addon. This should be called in a deferred way
|
||||
# from the addon's _enter_tree.
|
||||
#
|
||||
# #### Parameters
|
||||
# - manager_class: Path to the manager class script
|
||||
func register_dialog_manager(manager_class: String):
|
||||
var dialog_managers: Array = ProjectSettings.get_setting(
|
||||
"escoria/ui/dialog_managers"
|
||||
)
|
||||
if manager_class in dialog_managers:
|
||||
return
|
||||
dialog_managers.push_back(manager_class)
|
||||
ProjectSettings.set_setting(
|
||||
"escoria/ui/dialog_managers",
|
||||
dialog_managers
|
||||
)
|
||||
|
||||
|
||||
# Deregister a dialog manager addon
|
||||
#
|
||||
# #### Parameters
|
||||
# - manager_class: Path to the manager class script
|
||||
func deregister_dialog_manager(manager_class: String):
|
||||
var dialog_managers: Array = ProjectSettings.get_setting(
|
||||
"escoria/ui/dialog_managers"
|
||||
)
|
||||
if not manager_class in dialog_managers:
|
||||
logger.report_warnings(
|
||||
"escoria.gd:deregister_dialog_manager()",
|
||||
[
|
||||
"Dialog manager %s is not registered" % manager_class
|
||||
]
|
||||
)
|
||||
return
|
||||
|
||||
dialog_managers.erase(manager_class)
|
||||
|
||||
ProjectSettings.set_setting(
|
||||
"escoria/ui/dialog_managers",
|
||||
dialog_managers
|
||||
)
|
||||
|
||||
|
||||
# Function called to quit the game.
|
||||
|
||||
Reference in New Issue
Block a user