From d46071190d64f3f1d44c03469adde4f7e52c2c1a Mon Sep 17 00:00:00 2001 From: Goy288 Date: Mon, 9 Dec 2024 11:57:55 -0800 Subject: [PATCH 1/2] Change the icon resource retrieval to use `preload()`, and make the paths local instead of global. --- addons/script-ide/plugin.gd | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/addons/script-ide/plugin.gd b/addons/script-ide/plugin.gd index 2a65c0d..ba14fe3 100644 --- a/addons/script-ide/plugin.gd +++ b/addons/script-ide/plugin.gd @@ -18,6 +18,18 @@ const OPEN_OUTLINE_POPUP: StringName = SCRIPT_IDE + &"open_outline_popup" ## Editor setting for the 'Open Scripts Popup' shortcut const OPEN_SCRIPTS_POPUP: StringName = SCRIPT_IDE + &"open_scripts_popup" +#region Preloaded icon resources +const ICON_KEYWORD: Image = preload("icon/keyword.svg") +const ICON_FUNC: Image = preload("icon/func.svg") +const ICON_FUNC_GET: Image = preload("icon/func_get.svg") +const ICON_FUNC_SET: Image = preload("icon/func_set.svg") +const ICON_PROPERTY: Image = preload("icon/property.svg") +const ICON_EXPORT: Image = preload("icon/export.svg") +const ICON_SIGNAL: Image = preload("icon/signal.svg") +const ICON_CONSTANT: Image = preload("icon/constant.svg") +const ICON_CLASS: Image = preload("icon/class.svg") +#endregion + const GETTER: StringName = &"get" const SETTER: StringName = &"set" const UNDERSCORE: StringName = &"_" @@ -89,15 +101,15 @@ var suppress_settings_sync: bool = false #region Enter / Exit -> Plugin setup ## Change the Godot script UI and transform into an IDE like UI func _enter_tree() -> void: - keyword_icon = create_editor_texture(load("res://addons/script-ide/icon/keyword.svg")) - func_icon = create_editor_texture(load("res://addons/script-ide/icon/func.svg")) - func_get_icon = create_editor_texture(load("res://addons/script-ide/icon/func_get.svg")) - func_set_icon = create_editor_texture(load("res://addons/script-ide/icon/func_set.svg")) - property_icon = create_editor_texture(load("res://addons/script-ide/icon/property.svg")) - export_icon = create_editor_texture(load("res://addons/script-ide/icon/export.svg")) - signal_icon = create_editor_texture(load("res://addons/script-ide/icon/signal.svg")) - constant_icon = create_editor_texture(load("res://addons/script-ide/icon/constant.svg")) - class_icon = create_editor_texture(load("res://addons/script-ide/icon/class.svg")) + keyword_icon = create_editor_texture(ICON_KEYWORD) + func_icon = create_editor_texture(ICON_FUNC) + func_get_icon = create_editor_texture(ICON_FUNC_GET) + func_set_icon = create_editor_texture(ICON_FUNC_SET) + property_icon = create_editor_texture(ICON_PROPERTY) + export_icon = create_editor_texture(ICON_EXPORT) + signal_icon = create_editor_texture(ICON_SIGNAL) + constant_icon = create_editor_texture(ICON_CONSTANT) + class_icon = create_editor_texture(ICON_CLASS) is_outline_right = get_setting(OUTLINE_POSITION_RIGHT, is_outline_right) hide_private_members = get_setting(HIDE_PRIVATE_MEMBERS, hide_private_members) From 8d09b1ebb95f8fc6d90e751f68516b321a6fc527 Mon Sep 17 00:00:00 2001 From: BunkWire2X8 <44177200+BunkWire2X8@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:14:01 -0800 Subject: [PATCH 2/2] Removed preload reliance Due to `load()` not having built-in support for relative paths, unlike `preload()`, I use `get_script().get_path().get_base_dir()` and `String.path_join()` to concatenate the relative icon paths with the script's current base directory. --- addons/script-ide/plugin.gd | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/addons/script-ide/plugin.gd b/addons/script-ide/plugin.gd index ba14fe3..77d7915 100644 --- a/addons/script-ide/plugin.gd +++ b/addons/script-ide/plugin.gd @@ -18,18 +18,6 @@ const OPEN_OUTLINE_POPUP: StringName = SCRIPT_IDE + &"open_outline_popup" ## Editor setting for the 'Open Scripts Popup' shortcut const OPEN_SCRIPTS_POPUP: StringName = SCRIPT_IDE + &"open_scripts_popup" -#region Preloaded icon resources -const ICON_KEYWORD: Image = preload("icon/keyword.svg") -const ICON_FUNC: Image = preload("icon/func.svg") -const ICON_FUNC_GET: Image = preload("icon/func_get.svg") -const ICON_FUNC_SET: Image = preload("icon/func_set.svg") -const ICON_PROPERTY: Image = preload("icon/property.svg") -const ICON_EXPORT: Image = preload("icon/export.svg") -const ICON_SIGNAL: Image = preload("icon/signal.svg") -const ICON_CONSTANT: Image = preload("icon/constant.svg") -const ICON_CLASS: Image = preload("icon/class.svg") -#endregion - const GETTER: StringName = &"get" const SETTER: StringName = &"set" const UNDERSCORE: StringName = &"_" @@ -101,15 +89,17 @@ var suppress_settings_sync: bool = false #region Enter / Exit -> Plugin setup ## Change the Godot script UI and transform into an IDE like UI func _enter_tree() -> void: - keyword_icon = create_editor_texture(ICON_KEYWORD) - func_icon = create_editor_texture(ICON_FUNC) - func_get_icon = create_editor_texture(ICON_FUNC_GET) - func_set_icon = create_editor_texture(ICON_FUNC_SET) - property_icon = create_editor_texture(ICON_PROPERTY) - export_icon = create_editor_texture(ICON_EXPORT) - signal_icon = create_editor_texture(ICON_SIGNAL) - constant_icon = create_editor_texture(ICON_CONSTANT) - class_icon = create_editor_texture(ICON_CLASS) + var script_path: String = get_script().get_path().get_base_dir() + + keyword_icon = create_editor_texture(load(script_path.path_join("icon/keyword.svg"))) + func_icon = create_editor_texture(load(script_path.path_join("icon/func.svg"))) + func_get_icon = create_editor_texture(load(script_path.path_join("icon/func_get.svg"))) + func_set_icon = create_editor_texture(load(script_path.path_join("icon/func_set.svg"))) + property_icon = create_editor_texture(load(script_path.path_join("icon/property.svg"))) + export_icon = create_editor_texture(load(script_path.path_join("icon/export.svg"))) + signal_icon = create_editor_texture(load(script_path.path_join("icon/signal.svg"))) + constant_icon = create_editor_texture(load(script_path.path_join("icon/constant.svg"))) + class_icon = create_editor_texture(load(script_path.path_join("icon/class.svg"))) is_outline_right = get_setting(OUTLINE_POSITION_RIGHT, is_outline_right) hide_private_members = get_setting(HIDE_PRIVATE_MEMBERS, hide_private_members)