feat: Several fixes and optimizations (#467)

Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
Dennis Ploeger
2021-11-27 20:10:16 +01:00
committed by GitHub
parent 09446c794f
commit 47fe4df841
13 changed files with 397 additions and 312 deletions

View File

@@ -24,7 +24,7 @@ const COMPARISON_DESCRIPTION = [
"Checking if %s %s %s equals %s", "Checking if %s %s %s equals %s",
"Checking if %s %s %s greater than %s", "Checking if %s %s %s greater than %s",
"Checking if %s %s %s less than %s", "Checking if %s %s %s less than %s",
"Checking if %s is %s active%s" "Checking if %s %s %s active%s"
] ]
@@ -130,7 +130,7 @@ func run() -> bool:
self.comparison_value: self.comparison_value:
return_value = true return_value = true
elif self.comparison == COMPARISON_ACTIVITY and \ 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: escoria.object_manager.get_object(global_name).active:
return_value = true return_value = true

View File

@@ -91,9 +91,9 @@ func stop():
# - name: The animation name to play # - name: The animation name to play
# - backwards: Play backwards # - backwards: Play backwards
func play(name: String, backwards: bool = false): func play(name: String, backwards: bool = false):
if _is_animation_player: if _is_animation_player and _animation_player.current_animation != "":
_animation_player.seek(0) _animation_player.seek(0)
else: elif not _is_animation_player:
_animated_sprite.frame = 0 _animated_sprite.frame = 0
_current_animation = name _current_animation = name
if backwards and _is_animation_player: if backwards and _is_animation_player:

View File

@@ -34,7 +34,7 @@ func perform_walk(
if destination.node is ESCLocation: if destination.node is ESCLocation:
target_position = destination.node.global_position target_position = destination.node.global_position
else: else:
target_position = destination.node.interact_position target_position = destination.node.get_interact_position()
var walk_context = ESCWalkContext.new( var walk_context = ESCWalkContext.new(
destination, destination,
@@ -127,7 +127,7 @@ func perform_inputevent_on_object(
var player_global_pos = escoria.main.current_scene.player.global_position var player_global_pos = escoria.main.current_scene.player.global_position
var clicked_position = event.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 dont_interact = true
# If no interaction should happen after player has arrived, leave # If no interaction should happen after player has arrived, leave

View File

@@ -256,34 +256,6 @@ func show_ui():
pass 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 # Set the Editor debug mode
func _set_editor_debug_mode(p_editor_debug_mode: int) -> void: func _set_editor_debug_mode(p_editor_debug_mode: int) -> void:
editor_debug_mode = p_editor_debug_mode editor_debug_mode = p_editor_debug_mode

View File

@@ -299,10 +299,13 @@ func _unhandled_input(event: InputEvent) -> void:
if mouse_in_shape: if mouse_in_shape:
if event.doubleclick and event.button_index == BUTTON_LEFT: if event.doubleclick and event.button_index == BUTTON_LEFT:
emit_signal("mouse_double_left_clicked_item", self, event) emit_signal("mouse_double_left_clicked_item", self, event)
get_tree().set_input_as_handled()
elif event.button_index == BUTTON_LEFT: elif event.button_index == BUTTON_LEFT:
emit_signal("mouse_left_clicked_item", self, event) emit_signal("mouse_left_clicked_item", self, event)
get_tree().set_input_as_handled()
elif event.button_index == BUTTON_RIGHT: elif event.button_index == BUTTON_RIGHT:
emit_signal("mouse_right_clicked_item", self, event) emit_signal("mouse_right_clicked_item", self, event)
get_tree().set_input_as_handled()
# Return the animation player node # Return the animation player node

View File

@@ -1,4 +1,5 @@
# The escoria main script # The escoria main script
tool
extends Node extends Node
# Signal sent when pause menu has to be displayed # Signal sent when pause menu has to be displayed
@@ -310,12 +311,6 @@ func _input(event):
if event.is_action_pressed("ui_cancel"): if event.is_action_pressed("ui_cancel"):
emit_signal("request_pause_menu") 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 # Pauses or unpause the game
# #
@@ -351,6 +346,110 @@ func run_event_from_script(script: ESCScript, event_name: String):
return 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. # Function called to quit the game.
func quit(): func quit():
get_tree().notification(MainLoop.NOTIFICATION_WM_QUIT_REQUEST) get_tree().notification(MainLoop.NOTIFICATION_WM_QUIT_REQUEST)

View File

@@ -2,21 +2,31 @@
tool tool
extends EditorPlugin extends EditorPlugin
# Autoloads to instantiate
const autoloads = {
"escoria": "res://addons/escoria-core/game/escoria.tscn",
}
# Setup Escoria # Setup Escoria
func _enter_tree(): func _enter_tree():
for key in autoloads.keys(): add_autoload_singleton(
add_autoload_singleton(key, autoloads[key]) "escoria",
"res://addons/escoria-core/game/escoria.tscn"
)
# Add input actions in InputMap # Add input actions in InputMap
InputMap.add_action("switch_action_verb") InputMap.add_action("switch_action_verb")
InputMap.add_action("esc_show_debug_prompt") InputMap.add_action("esc_show_debug_prompt")
# Define standard settings
ProjectSettings.set_setting(
"application/run/main_scene",
"res://addons/escoria-core/game/main_scene.tscn"
)
ProjectSettings.set_setting(
"audio/default_bus_layout",
"res://addons/escoria-core/default_bus_layout.tres"
)
func _ready():
# Prepare settings # Prepare settings
set_escoria_main_settings() set_escoria_main_settings()
set_escoria_debug_settings() set_escoria_debug_settings()
@@ -27,14 +37,7 @@ func _enter_tree():
# Prepare the settings in the Escoria UI category # Prepare the settings in the Escoria UI category
func set_escoria_ui_settings(): func set_escoria_ui_settings():
ProjectSettings.set_setting( escoria.register_setting(
"audio/default_bus_layout",
"res://addons/escoria-core/default_bus_layout.tres"
)
if !ProjectSettings.has_setting("escoria/ui/tooltip_follows_mouse"):
ProjectSettings.set_setting("escoria/ui/tooltip_follows_mouse", true)
_register_setting(
"escoria/ui/default_dialog_type", "escoria/ui/default_dialog_type",
"", "",
{ {
@@ -42,62 +45,58 @@ func set_escoria_ui_settings():
} }
) )
if !ProjectSettings.has_setting("escoria/ui/game_scene"): escoria.register_setting(
ProjectSettings.set_setting("escoria/ui/game_scene", "") "escoria/ui/game_scene",
var game_scene_property_info = { "",
{
"name": "escoria/ui/game_scene", "name": "escoria/ui/game_scene",
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_FILE, "hint": PROPERTY_HINT_FILE,
"hint_string": "*.tscn, *.scn" "hint_string": "*.tscn, *.scn"
} }
ProjectSettings.add_property_info(game_scene_property_info)
if !ProjectSettings.has_setting("escoria/ui/items_autoregister_path"):
ProjectSettings.set_setting(
"escoria/ui/items_autoregister_path",
"res://game/items/escitems/"
) )
var game_scene_property_info = {
escoria.register_setting(
"escoria/ui/items_autoregister_path",
"res://game/items/escitems/",
{
"name": "escoria/ui/items_autoregister_path", "name": "escoria/ui/items_autoregister_path",
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_DIR "hint": PROPERTY_HINT_DIR
} }
ProjectSettings.add_property_info(game_scene_property_info)
if !ProjectSettings.has_setting("escoria/ui/default_transition"):
ProjectSettings.set_setting(
"escoria/ui/default_transition",
"curtain"
) )
ProjectSettings.add_property_info({
escoria.register_setting(
"escoria/ui/default_transition",
"curtain",
{
"name": "escoria/ui/default_transition", "name": "escoria/ui/default_transition",
"type": TYPE_STRING "type": TYPE_STRING
}) }
)
if !ProjectSettings.has_setting("escoria/ui/transition_paths"): escoria.register_setting(
ProjectSettings.set_setting(
"escoria/ui/transition_paths", "escoria/ui/transition_paths",
[ [
"res://addons/escoria-core/game/scenes/transitions/shaders/" "res://addons/escoria-core/game/scenes/transitions/shaders/"
] ],
) {
ProjectSettings.add_property_info({
"name": "escoria/ui/transition_paths", "name": "escoria/ui/transition_paths",
"type": TYPE_STRING_ARRAY, "type": TYPE_STRING_ARRAY,
"hint": PROPERTY_HINT_DIR "hint": PROPERTY_HINT_DIR
}) }
if !ProjectSettings.has_setting("escoria/ui/inventory_item_size"):
ProjectSettings.set_setting(
"escoria/ui/inventory_item_size",
Vector2(72, 72)
) )
ProjectSettings.add_property_info({
escoria.register_setting(
"escoria/ui/inventory_item_size",
Vector2(72, 72),
{
"name": "escoria/ui/inventory_item_size", "name": "escoria/ui/inventory_item_size",
"type": TYPE_VECTOR2 "type": TYPE_VECTOR2
}) }
)
_register_setting( escoria.register_setting(
"escoria/ui/dialog_managers", "escoria/ui/dialog_managers",
[], [],
{ {
@@ -107,196 +106,195 @@ func set_escoria_ui_settings():
# Prepare the settings in the Escoria main category # Prepare the settings in the Escoria main category
func set_escoria_main_settings(): func set_escoria_main_settings():
escoria.register_setting(
if !ProjectSettings.has_setting("escoria/main/game_version"): "escoria/main/game_version",
ProjectSettings.set_setting("escoria/main/game_version", "") "",
var game_version_property_info = { {
"name": "escoria/main/game_version",
"type": TYPE_STRING "type": TYPE_STRING
} }
ProjectSettings.add_property_info(game_version_property_info) )
if !ProjectSettings.has_setting("escoria/main/game_start_script"): escoria.register_setting(
ProjectSettings.set_setting("escoria/main/game_start_script", "") "escoria/main/game_start_script",
var game_start_script_property_info = { "",
"name": "escoria/main/game_start_script", {
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_FILE, "hint": PROPERTY_HINT_FILE,
"hint_string": "*.esc" "hint_string": "*.esc"
} }
ProjectSettings.add_property_info(game_start_script_property_info) )
if !ProjectSettings.has_setting("escoria/main/force_quit"): escoria.register_setting(
ProjectSettings.set_setting("escoria/main/force_quit", true) "escoria/main/force_quit",
var force_quit_property_info = { true,
"name": "escoria/main/force_quit", {
"type": TYPE_BOOL "type": TYPE_BOOL
} }
ProjectSettings.add_property_info(force_quit_property_info) )
ProjectSettings.set_setting("application/run/main_scene", "res://addons/escoria-core/game/main_scene.tscn") escoria.register_setting(
"escoria/main/command_directories",
if not ProjectSettings.has_setting("escoria/main/command_directories"): [
ProjectSettings.set_setting("escoria/main/command_directories", [
"res://addons/escoria-core/game/core-scripts/esc/commands" "res://addons/escoria-core/game/core-scripts/esc/commands"
]) ],
ProjectSettings.add_property_info({ {
"name": "escoria/main/command_directories",
"type": TYPE_ARRAY, "type": TYPE_ARRAY,
}) }
)
if !ProjectSettings.has_setting("escoria/main/text_lang"): escoria.register_setting(
ProjectSettings.set_setting("escoria/main/text_lang", TranslationServer.get_locale()) "escoria/main/text_lang",
var text_lang_property_info = { TranslationServer.get_locale(),
"name": "escoria/main/text_lang", {
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_NONE "hint": PROPERTY_HINT_NONE
} }
ProjectSettings.add_property_info(text_lang_property_info) )
if !ProjectSettings.has_setting("escoria/main/voice_lang"): escoria.register_setting(
ProjectSettings.set_setting("escoria/main/voice_lang", TranslationServer.get_locale()) "escoria/main/voice_lang",
var voice_lang_property_info = { TranslationServer.get_locale(),
"name": "escoria/main/voice_lang", {
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_NONE "hint": PROPERTY_HINT_NONE
} }
ProjectSettings.add_property_info(voice_lang_property_info) )
if !ProjectSettings.has_setting("escoria/main/savegames_path"): escoria.register_setting(
ProjectSettings.set_setting(
"escoria/main/savegames_path", "escoria/main/savegames_path",
"user://saves/" "user://saves/",
) {
var savegames_path_property_info = {
"name": "escoria/main/savegames_path",
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_DIR "hint": PROPERTY_HINT_DIR
} }
ProjectSettings.add_property_info(savegames_path_property_info) )
if !ProjectSettings.has_setting("escoria/main/settings_path"): escoria.register_setting(
ProjectSettings.set_setting(
"escoria/main/settings_path", "escoria/main/settings_path",
"user://" "user://",
) {
var settings_path_property_info = {
"name": "escoria/main/settings_path",
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_DIR "hint": PROPERTY_HINT_DIR
} }
ProjectSettings.add_property_info(settings_path_property_info) )
# Prepare the settings in the Escoria debug category # Prepare the settings in the Escoria debug category
func set_escoria_debug_settings(): func set_escoria_debug_settings():
if !ProjectSettings.has_setting("escoria/debug/terminate_on_warnings"): escoria.register_setting(
ProjectSettings.set_setting("escoria/debug/terminate_on_warnings", false) "escoria/debug/terminate_on_warnings",
false,
{
"type": TYPE_BOOL
}
)
if !ProjectSettings.has_setting("escoria/debug/terminate_on_errors"): escoria.register_setting(
ProjectSettings.set_setting("escoria/debug/terminate_on_errors", true) "escoria/debug/terminate_on_errors",
true,
{
"type": TYPE_BOOL
}
)
# Main language the game is developed in. Useful for translation management escoria.register_setting(
if !ProjectSettings.has_setting("escoria/debug/development_lang"): "escoria/debug/development_lang",
ProjectSettings.set_setting("escoria/debug/development_lang", "en") "en",
{
"type": TYPE_STRING
}
)
# Assure log level preference escoria.register_setting(
if not ProjectSettings.has_setting("escoria/debug/log_level"): "escoria/debug/log_level",
ProjectSettings.set_setting("escoria/debug/log_level", "ERROR") "ERROR",
var property_info = { {
"name": "escoria/debug/log_level",
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM, "hint": PROPERTY_HINT_ENUM,
"hint_string": "ERROR,WARNING,INFO,DEBUG" "hint_string": "ERROR,WARNING,INFO,DEBUG"
} }
ProjectSettings.add_property_info(property_info) )
# Define output log file path escoria.register_setting(
if not ProjectSettings.has_setting("escoria/debug/log_file_path"): "escoria/debug/log_file_path",
ProjectSettings.set_setting("escoria/debug/log_file_path", "user://") "user://",
var property_info = { {
"name": "escoria/debug/log_file_path",
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_DIR "hint": PROPERTY_HINT_DIR
} }
ProjectSettings.add_property_info(property_info) )
# Define crash message escoria.register_setting(
if not ProjectSettings.has_setting("escoria/debug/crash_message"):
ProjectSettings.set_setting(
"escoria/debug/crash_message", "escoria/debug/crash_message",
"We're sorry, but the game crashed. Please send us the " + "We're sorry, but the game crashed. Please send us the " +
"following files:\n\n%s" "following files:\n\n%s",
) {
var property_info = {
"name": "escoria/debug/crash_message",
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_MULTILINE_TEXT "hint": PROPERTY_HINT_MULTILINE_TEXT
} }
ProjectSettings.add_property_info(property_info) )
# Room selector preference escoria.register_setting(
if not ProjectSettings.has_setting("escoria/debug/enable_room_selector"): "escoria/debug/enable_room_selector",
ProjectSettings.set_setting("escoria/debug/enable_room_selector", false) false,
var property_info = { {
"name": "escoria/debug/enable_room_selector",
"type": TYPE_BOOL "type": TYPE_BOOL
} }
ProjectSettings.add_property_info(property_info) )
if not ProjectSettings.has_setting("escoria/debug/room_selector_room_dir"): escoria.register_setting(
ProjectSettings.set_setting("escoria/debug/room_selector_room_dir", "") "escoria/debug/room_selector_room_dir",
var property_info = { "",
"name": "escoria/debug/room_selector_room_dir", {
"type": TYPE_STRING, "type": TYPE_STRING,
"hint": PROPERTY_HINT_DIR "hint": PROPERTY_HINT_DIR
} }
ProjectSettings.add_property_info(property_info) )
# Prepare the settings in the Escoria sound settings # Prepare the settings in the Escoria sound settings
func set_escoria_sound_settings(): func set_escoria_sound_settings():
if !ProjectSettings.has_setting("escoria/sound/master_volume"): escoria.register_setting(
ProjectSettings.set_setting("escoria/sound/master_volume", 1) "escoria/sound/master_volume",
var master_data_property_info = { 1,
"name": "escoria/sound/master_volume", {
"type": TYPE_INT, "type": TYPE_INT,
"hint": PROPERTY_HINT_RANGE, "hint": PROPERTY_HINT_RANGE,
"hint_string": "0,1" "hint_string": "0,1"
} }
ProjectSettings.add_property_info(master_data_property_info) )
if !ProjectSettings.has_setting("escoria/sound/music_volume"): escoria.register_setting(
ProjectSettings.set_setting("escoria/sound/music_volume", 1) "escoria/sound/music_volume",
var music_data_property_info = { 1,
"name": "escoria/sound/music_volume", {
"type": TYPE_INT, "type": TYPE_INT,
"hint": PROPERTY_HINT_RANGE, "hint": PROPERTY_HINT_RANGE,
"hint_string": "0,1" "hint_string": "0,1"
} }
ProjectSettings.add_property_info(music_data_property_info) )
if !ProjectSettings.has_setting("escoria/sound/sfx_volume"): escoria.register_setting(
ProjectSettings.set_setting("escoria/sound/sfx_volume", 1) "escoria/sound/sfx_volume",
var sound_data_property_info = { 1,
"name": "escoria/sound/sfx_volume", {
"type": TYPE_INT, "type": TYPE_INT,
"hint": PROPERTY_HINT_RANGE, "hint": PROPERTY_HINT_RANGE,
"hint_string": "0,1" "hint_string": "0,1"
} }
ProjectSettings.add_property_info(sound_data_property_info) )
if !ProjectSettings.has_setting("escoria/sound/speech_volume"): escoria.register_setting(
ProjectSettings.set_setting("escoria/sound/speech_volume", 1) "escoria/sound/speech_volume",
var speech_data_property_info = { 1,
"name": "escoria/sound/speech_volume", {
"type": TYPE_INT, "type": TYPE_INT,
"hint": PROPERTY_HINT_RANGE, "hint": PROPERTY_HINT_RANGE,
"hint_string": "0,1" "hint_string": "0,1"
} }
ProjectSettings.add_property_info(speech_data_property_info) )
_register_setting( escoria.register_setting(
"escoria/sound/speech_enabled", "escoria/sound/speech_enabled",
1, 1,
{ {
@@ -304,7 +302,7 @@ func set_escoria_sound_settings():
} }
) )
_register_setting( escoria.register_setting(
"escoria/sound/speech_folder", "escoria/sound/speech_folder",
"res://speech", "res://speech",
{ {
@@ -313,7 +311,7 @@ func set_escoria_sound_settings():
} }
) )
_register_setting( escoria.register_setting(
"escoria/sound/speech_extension", "escoria/sound/speech_extension",
"ogg", "ogg",
{ {
@@ -322,23 +320,6 @@ func set_escoria_sound_settings():
) )
# 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)
# Prepare the settings in the Escoria platform category and may need special # Prepare the settings in the Escoria platform category and may need special
# setting per build # setting per build
func set_escoria_platform_settings(): func set_escoria_platform_settings():
@@ -346,18 +327,26 @@ func set_escoria_platform_settings():
# scenes. # scenes.
# If set to true, all generic scenes (UI, inventory, etc) will be loaded # If set to true, all generic scenes (UI, inventory, etc) will be loaded
# as any other scene. # as any other scene.
if !ProjectSettings.has_setting("escoria/platform/skip_cache"): escoria.register_setting(
ProjectSettings.set_setting("escoria/platform/skip_cache", false) "escoria/platform/skip_cache",
if !ProjectSettings.has_setting("escoria/platform/skip_cache.mobile"): false,
ProjectSettings.set_setting("escoria/platform/skip_cache.mobile", true) {
"type": TYPE_BOOL
}
)
escoria.register_setting(
"escoria/platform/skip_cache.mobile",
true,
{
"type": "TYPE_BOOL"
}
)
# Uninstall plugin # Uninstall plugin
func _exit_tree(): func _exit_tree():
for key in autoloads.keys(): remove_autoload_singleton("escoria")
if ProjectSettings.has_setting(key):
remove_autoload_singleton(key)
InputMap.erase_action("switch_action_verb") InputMap.erase_action("switch_action_verb")
InputMap.erase_action("esc_show_debug_prompt") InputMap.erase_action("esc_show_debug_prompt")

View File

@@ -3,31 +3,30 @@ tool
extends EditorPlugin extends EditorPlugin
var _escoria
const MANAGER_CLASS="res://addons/escoria-dialog-simple/esc_dialog_simple.gd" const MANAGER_CLASS="res://addons/escoria-dialog-simple/esc_dialog_simple.gd"
func _init() -> void:
_escoria = preload("res://addons/escoria-core/game/escoria.tscn")\
.instance()
# Register ourselves after setup # Register ourselves after setup
func _enter_tree() -> void: func _ready() -> void:
call_deferred("_register") call_deferred("_register")
# Unregister ourselves # Unregister ourselves
func _exit_tree() -> void: func _exit_tree() -> void:
_unregister() _escoria.deregister_dialog_manager(MANAGER_CLASS)
# Add ourselves to the list of dialog managers # Add ourselves to the list of dialog managers
func _register(): func _register():
_unregister() _escoria.register_dialog_manager(MANAGER_CLASS)
var dialog_managers: Array = ProjectSettings.get_setting( _escoria.register_setting(
"escoria/ui/dialog_managers"
)
dialog_managers.push_back(MANAGER_CLASS)
ProjectSettings.set_setting(
"escoria/ui/dialog_managers",
dialog_managers
)
_register_setting(
"escoria/dialog_simple/avatars_path", "escoria/dialog_simple/avatars_path",
"", "",
{ {
@@ -36,7 +35,7 @@ func _register():
} }
) )
_register_setting( _escoria.register_setting(
"escoria/dialog_simple/text_speed_per_character", "escoria/dialog_simple/text_speed_per_character",
0.1, 0.1,
{ {
@@ -44,7 +43,7 @@ func _register():
} }
) )
_register_setting( _escoria.register_setting(
"escoria/dialog_simple/fast_text_speed_per_character", "escoria/dialog_simple/fast_text_speed_per_character",
0.25, 0.25,
{ {
@@ -52,41 +51,10 @@ func _register():
} }
) )
_register_setting( _escoria.register_setting(
"escoria/dialog_simple/max_time_to_disappear", "escoria/dialog_simple/max_time_to_disappear",
1.0, 1.0,
{ {
"type": TYPE_REAL "type": TYPE_REAL
} }
) )
# Remove ourselves from the list of dialog managers
func _unregister():
var dialog_managers = ProjectSettings.get_setting(
"escoria/ui/dialog_managers"
)
dialog_managers.erase(MANAGER_CLASS)
ProjectSettings.set_setting(
"escoria/ui/dialog_managers",
dialog_managers
)
# 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)

View File

@@ -45,7 +45,6 @@ onready var inventory_ui = $ui/Control/panel_down/VBoxContainer/HBoxContainer\
/InventoryMargin/inventory_ui /InventoryMargin/inventory_ui
func _enter_tree(): func _enter_tree():
ProjectSettings.set_setting("escoria/ui/tooltip_follows_mouse", false)
escoria.action_manager.connect( escoria.action_manager.connect(
"action_finished", "action_finished",
self, self,
@@ -72,6 +71,7 @@ func _exit_tree():
) )
## BACKGROUND ## ## BACKGROUND ##
func left_click_on_bg(position: Vector2) -> void: func left_click_on_bg(position: Vector2) -> void:

View File

@@ -3,7 +3,16 @@ tool
extends EditorPlugin extends EditorPlugin
# Setup Escoria # Register UI
func _enter_tree(): func _enter_tree() -> void:
ProjectSettings.set_setting("escoria/ui/tooltip_follows_mouse", false) call_deferred("_register")
ProjectSettings.set_setting("escoria/ui/game_scene", "res://addons/escoria-ui-9verbs/game.tscn")
# Deregister UI
func _exit_tree() -> void:
escoria.deregister_ui("res://addons/escoria-ui-9verbs/game.tscn")
# Register UI with Escoria
func _register():
escoria.register_ui("res://addons/escoria-ui-9verbs/game.tscn")

View File

@@ -36,7 +36,6 @@ Implement methods to react to inputs.
""" """
func _enter_tree(): func _enter_tree():
ProjectSettings.set_setting("escoria/ui/tooltip_follows_mouse", true)
escoria.action_manager.connect( escoria.action_manager.connect(
"action_finished", "action_finished",
self, self,
@@ -61,6 +60,14 @@ func _exit_tree():
"_on_action_finished" "_on_action_finished"
) )
func _input(event: InputEvent) -> void:
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)
## BACKGROUND ## ## BACKGROUND ##
func left_click_on_bg(position: Vector2) -> void: func left_click_on_bg(position: Vector2) -> void:
@@ -202,6 +209,34 @@ func pause_game():
escoria.main.current_scene.hide() escoria.main.current_scene.hide()
# Update the tooltip
#
# #### 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
func _on_action_finished(): func _on_action_finished():
$mouse_layer/verbs_menu.clear_tool_texture() $mouse_layer/verbs_menu.clear_tool_texture()
$mouse_layer/verbs_menu.iterate_actions_cursor(0) $mouse_layer/verbs_menu.iterate_actions_cursor(0)

View File

@@ -3,7 +3,16 @@ tool
extends EditorPlugin extends EditorPlugin
# Setup Escoria # Register UI
func _enter_tree(): func _enter_tree():
ProjectSettings.set_setting("escoria/ui/tooltip_follows_mouse", true) call_deferred("_register")
ProjectSettings.set_setting("escoria/ui/game_scene", "res://addons/escoria-ui-simplemouse/game.tscn")
# Deregister UI
func _exit_tree() -> void:
escoria.deregister_ui("res://addons/escoria-ui-simplemouse/game.tscn")
# Register UI with Escoria
func _register():
escoria.register_ui("res://addons/escoria-ui-simplemouse/game.tscn")

View File

@@ -731,6 +731,7 @@ debug/crash_message="We're sorry, but the game crashed. Please send us the follo
%s" %s"
ui/default_dialog_scene="res://addons/escoria-core/ui_library/dialogs/floating_dialog_player.tscn" ui/default_dialog_scene="res://addons/escoria-core/ui_library/dialogs/floating_dialog_player.tscn"
esc/command_paths=[ "res://addons/escoria-core/game/core-scripts/esc/commands" ]
[input] [input]