Skip to content

Commit

Permalink
[*] Add code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
IceflowRE committed Jan 15, 2024
1 parent 2e0ed62 commit 821d5c2
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 77 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ You are also not able to use the property `custom_minimum_size` anymore as it is

### Changelog

#### 3.1.1

- Code improvement

#### 3.1.0

- Require Godot 4.2
Expand Down Expand Up @@ -235,6 +239,10 @@ Then use `Project` -> `Tools` -> `Icons Patcher` to patch the icons.

### Changelog

#### 1.3.2

- Code improvement

#### 1.3.1

- Replace legacy code
Expand Down Expand Up @@ -289,6 +297,11 @@ License class.

### Changelog

#### 1.7.6

- Fix scene id
- Code improvement

#### 1.7.5

- Fix license file existing check
Expand Down Expand Up @@ -413,6 +426,10 @@ If not log level is set, the log level of the parent logger will be used.

### Changelog

#### 1.5.1

- Code improvement

#### 1.5.0

- Require Godot 4.2
Expand Down Expand Up @@ -538,6 +555,10 @@ Shift JIS encoding utility.

### Changelog

#### 1.1.1

- Code optimizing

#### 1.1.0

- Require Godot 4.2
Expand Down Expand Up @@ -581,6 +602,10 @@ Let you apply the icon color theme properties for the texture button. Uses `self

### Changelog

#### 1.3.1

- Code improvement

#### 1.3.0

- Require Godot 4.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ func _get_children_min_size() -> Vector2:
if !(child is Control) || !child.visible:
continue
var child_min: Vector2 = child.get_combined_minimum_size()
min_size.x = max(min_size.x, child_min.x)
min_size.y = max(min_size.y, child_min.y)
min_size.x = maxf(min_size.x, child_min.x)
min_size.y = maxf(min_size.y, child_min.y)
return min_size

func _get_minimum_size() -> Vector2:
var min_size: Vector2 = self._get_children_min_size()
if self.stretch_mode == STRETCH_WIDTH_CONTROLS_HEIGHT:
var width: float = max(min_size.x, self.size.x)
var width: float = maxf(min_size.x, self.size.x)
min_size.y = width * self.ratio
elif self.stretch_mode == STRETCH_HEIGHT_CONTROLS_WIDTH:
var height: float = max(min_size.y, self.size.y)
var height: float = maxf(min_size.y, self.size.y)
min_size.x = height * self.ratio
return min_size
2 changes: 1 addition & 1 deletion addons/aspect_ratio_resize_container/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name="Aspect Ratio Resize Container"
description="Extending `AspectRatioContainer` and update it's own minimum size based on the children."
author="Iceflower S"
version="3.1.0"
version="3.1.1"
script="plugin.gd"
license="MIT"
repository="https://github.com/kenyoni-software/godot-addons"
Expand Down
2 changes: 1 addition & 1 deletion addons/glogging/glogging.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Logger:
self._log_level = level

func log_level() -> int:
if self.parent != null and self._log_level == LEVEL_NOTSET:
if self.parent != null && self._log_level == LEVEL_NOTSET:
return self.parent.log_level()
return self._log_level

Expand Down
2 changes: 1 addition & 1 deletion addons/glogging/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name="GLogging"
description="Adds a 'GLogging' singleton."
author="Iceflower S"
version="1.5.0"
version="1.5.1"
script="plugin.gd"
license="MIT"
repository="https://github.com/kenyoni-software/godot-addons"
Expand Down
2 changes: 1 addition & 1 deletion addons/icons_patcher/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name="Icons Patcher"
description="Will convert Pictogrammers icon to white."
author="Iceflower S"
version="1.3.1"
version="1.3.2"
script="plugin.gd"
license="MIT"
repository="https://github.com/kenyoni-software/godot-addons"
Expand Down
4 changes: 2 additions & 2 deletions addons/icons_patcher/tool_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ func _ready() -> void:

func _set_item_details(idx: int, settings_key: String, tooltip: String) -> void:
var path: String = ProjectSettings.get_setting(settings_key)
var can_use: bool = path != "" and DirAccess.dir_exists_absolute(path)
var can_use: bool = path != "" && DirAccess.dir_exists_absolute(path)
self.set_item_disabled(idx, !can_use)
if can_use:
self.set_item_icon(idx, null)
self.set_item_tooltip(idx, "")
else:
self.set_item_icon(idx, self.get_theme_icon("NodeWarning", "EditorIcons"))
self.set_item_icon(idx, self.get_theme_icon(&"NodeWarning", &"EditorIcons"))
self.set_item_tooltip(idx, tooltip)

func _on_about_to_popup() -> void:
Expand Down
2 changes: 1 addition & 1 deletion addons/licenses/internal/component_detail_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func _on_cell_selected() -> void:
if self._selected_item != null:
self._selected_item.clear_custom_bg_color(0)
self._selected_item = self.get_selected()
self._selected_item.set_custom_bg_color(0, self.get_theme_color("box_selection_fill_color", "Editor"))
self._selected_item.set_custom_bg_color(0, self.get_theme_color(&"box_selection_fill_color", &"Editor"))
if self.get_selected_column() == 0:
self._selected_item.deselect(0)
self._selected_item.select(1)
Expand Down
20 changes: 10 additions & 10 deletions addons/licenses/internal/components_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ func reload(scroll_to: Component = null) -> void:
# count current added custom components
var idx: int = 0

while idx < self._components.count() or readonly_idx < len(self._readonly_components):
while idx < self._components.count() || readonly_idx < len(self._readonly_components):
var component: Component = null
var cur_idx: int = 0
var cmp: bool = false
# compare readonly items with editable, to determine which one to show first
if idx < self._components.count() and readonly_idx < len(self._readonly_components):
if idx < self._components.count() && readonly_idx < len(self._readonly_components):
cmp = Licenses.compare_components_ascending(self._components.get_at(idx), self._readonly_components[readonly_idx])
if readonly_idx >= len(self._readonly_components) or cmp:
if readonly_idx >= len(self._readonly_components) || cmp:
component = self._components.get_at(idx)
cur_idx = idx
idx = idx + 1
elif idx >= self._components.count() or not cmp:
elif idx >= self._components.count() || not cmp:
component = self._readonly_components[readonly_idx]
cur_idx = readonly_idx
readonly_idx = readonly_idx + 1
Expand All @@ -77,8 +77,8 @@ func _create_item_menu() -> void:
self._item_menu = PopupMenu.new()
self._item_menu.name = "item_menu"
self._item_menu.id_pressed.connect(self._on_item_menu_pressed)
self._item_menu.add_icon_item(self.get_theme_icon("Duplicate", "EditorIcons"), "Duplicate")
self._item_menu.add_icon_item(self.get_theme_icon("Remove", "EditorIcons"), "Delete")
self._item_menu.add_icon_item(self.get_theme_icon(&"Duplicate", &"EditorIcons"), "Duplicate")
self._item_menu.add_icon_item(self.get_theme_icon(&"Remove", &"EditorIcons"), "Delete")
self._item_menu.size = self._item_menu.get_contents_minimum_size()
self.add_child(self._item_menu)

Expand All @@ -99,12 +99,12 @@ func _add_tree_item(component: Component, idx: int, parent: TreeItem) -> TreeIte
item.set_meta("idx", idx)
item.set_meta("readonly", component.readonly)
if not component.readonly:
item.add_button(0, self.get_theme_icon("Remove", "EditorIcons"), _BTN_ID_REMOVE)
item.add_button(0, self.get_theme_icon(&"Remove", &"EditorIcons"), _BTN_ID_REMOVE)
var tooltip: String = component.name
var comp_warnings: PackedStringArray = component.get_warnings()
if comp_warnings.size() != 0:
tooltip += "\n- " + "\n- ".join(comp_warnings)
item.set_icon(0, self.get_theme_icon("NodeWarning", "EditorIcons"))
item.set_icon(0, self.get_theme_icon(&"NodeWarning", &"EditorIcons"))
item.set_tooltip_text(0, tooltip)
return item

Expand All @@ -116,7 +116,7 @@ func _get_drag_data(at_position: Vector2) -> Variant:
var item: TreeItem = self.get_item_at_position(at_position)
if item == null:
return null
if not item.has_meta("idx") or (item.get_meta("readonly") as bool):
if not item.has_meta("idx") || (item.get_meta("readonly") as bool):
return null

self.set_drop_mode_flags(Tree.DROP_MODE_ON_ITEM)
Expand All @@ -125,7 +125,7 @@ func _get_drag_data(at_position: Vector2) -> Variant:
var tree_item: TreeItem = self.get_root().get_next_in_tree()
while tree_item != null:
if tree_item.has_meta("category"):
tree_item.set_custom_color(0, self.get_theme_color("accent_color", "Editor"))
tree_item.set_custom_color(0, self.get_theme_color(&"accent_color", &"Editor"))
tree_item = tree_item.get_next()

var preview: Label = Label.new()
Expand Down
16 changes: 8 additions & 8 deletions addons/licenses/internal/handler/array.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ func _init(tree_: ComponentDetailTree, item_: TreeItem, value_: Variant, propert
self.item.set_text(1, "[ " + str(len(self.value)) + " ]")
self.item.set_text_alignment(1, HORIZONTAL_ALIGNMENT_CENTER)
self._update_reset_button()
self.item.add_button(1, self.tree.get_theme_icon("Add", "EditorIcons"), 1)
self.item.add_button(1, self.tree.get_theme_icon("Remove", "EditorIcons"), 2)
self.item.add_button(1, self.tree.get_theme_icon(&"Add", &"EditorIcons"), 1)
self.item.add_button(1, self.tree.get_theme_icon(&"Remove", &"EditorIcons"), 2)

match self._get_child_property("")["type"]:
TYPE_STRING:
Expand All @@ -25,18 +25,18 @@ func _get_child_property(name: String) -> Dictionary:
match self.property["type"]:
TYPE_PACKED_STRING_ARRAY:
type = TYPE_STRING
if self.property["type"] == TYPE_ARRAY and self.property.get("constructor") != null:
if self.property["type"] == TYPE_ARRAY && self.property.get("constructor") != null:
type = TYPE_OBJECT
return {"name": name, "type": type, "hint": self.property.get("hint", PROPERTY_HINT_NONE), "hint_text": self.property.get("hint_text", ""), "constructor": self.property.get("constructor", null)}

static func can_handle(property: Dictionary) -> bool:
return property["type"] == TYPE_PACKED_STRING_ARRAY or property["type"] == TYPE_ARRAY and property.get("constructor") != null
return property["type"] == TYPE_PACKED_STRING_ARRAY || property["type"] == TYPE_ARRAY && property.get("constructor") != null

func _update_reset_button() -> void:
var button_id: int = self.item.get_button_by_id(0, 0)
if !self.value.is_empty() and button_id == -1:
self.item.add_button(0, self.tree.get_theme_icon("Reload", "EditorIcons"), 0)
elif self.value.is_empty() and button_id != -1:
if !self.value.is_empty() && button_id == -1:
self.item.add_button(0, self.tree.get_theme_icon(&"Reload", &"EditorIcons"), 0)
elif self.value.is_empty() && button_id != -1:
self.item.erase_button(0, button_id)

func button_clicked(column: int, id: int, mouse_button_idx: int) -> void:
Expand All @@ -62,7 +62,7 @@ func button_clicked(column: int, id: int, mouse_button_idx: int) -> void:
# remove
2:
var selected_item: TreeItem = self.tree._selected_item
if selected_item == null or selected_item.get_parent() != self.item:
if selected_item == null || selected_item.get_parent() != self.item:
return
self.value.remove_at(int(selected_item.get_text(0)))

Expand Down
2 changes: 1 addition & 1 deletion addons/licenses/internal/handler/object.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func _init(tree_: ComponentDetailTree, item_: TreeItem, value_: Variant, propert
self.tree._add_item(self.item, (self.value as Object).get(prop["name"]), prop)

static func can_handle(property: Dictionary) -> bool:
return property["type"] == TYPE_OBJECT and property.get("class_name", "") != "Script"
return property["type"] == TYPE_OBJECT && property.get("class_name", "") != "Script"

func child_edited(item: TreeItem) -> void:
var child = item.get_meta("handler")
Expand Down
6 changes: 3 additions & 3 deletions addons/licenses/internal/handler/string.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ static func can_handle(property: Dictionary) -> bool:

func _update_reset_button() -> void:
var button_id: int = self.item.get_button_by_id(0, 0)
if self.value != "" and button_id == -1:
self.item.add_button(0, self.tree.get_theme_icon("Reload", "EditorIcons"), 0)
elif self.value == "" and button_id != -1:
if self.value != "" && button_id == -1:
self.item.add_button(0, self.tree.get_theme_icon(&"Reload", &"EditorIcons"), 0)
elif self.value == "" && button_id != -1:
self.item.erase_button(0, button_id)

func button_clicked(column: int, id: int, mouse_button_idx: int) -> void:
Expand Down
21 changes: 10 additions & 11 deletions addons/licenses/internal/handler/string_file.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ func _init(tree_: ComponentDetailTree, item_: TreeItem, value_: Variant, propert
self.item.set_text(1, self.value)
self.item.set_editable(1, true)
self._update_reset_button()
self.item.add_button(1, self.tree.get_theme_icon("Load", "EditorIcons"), 1)
self.item.add_button(1, self.tree.get_theme_icon(&"Load", &"EditorIcons"), 1)

static func can_handle(property: Dictionary) -> bool:
return property["type"] == TYPE_STRING and property.get("hint", PROPERTY_HINT_NONE) == PROPERTY_HINT_FILE
return property["type"] == TYPE_STRING && property.get("hint", PROPERTY_HINT_NONE) == PROPERTY_HINT_FILE

func _update_reset_button() -> void:
var button_id: int = self.item.get_button_by_id(0, 0)
if self.value != "" and button_id == -1:
self.item.add_button(0, self.tree.get_theme_icon("Reload", "EditorIcons"), 0)
elif self.value == "" and button_id != -1:
if self.value != "" && button_id == -1:
self.item.add_button(0, self.tree.get_theme_icon(&"Reload", &"EditorIcons"), 0)
elif self.value == "" && button_id != -1:
self.item.erase_button(0, button_id)

func button_clicked(column: int, id: int, mouse_button_idx: int) -> void:
Expand All @@ -26,17 +26,16 @@ func button_clicked(column: int, id: int, mouse_button_idx: int) -> void:
self._update_reset_button()
self.tree._on_item_edited(self.item)
1:
var dialog: FileDialog = FileDialog.new()
var dialog: EditorFileDialog = EditorFileDialog.new()
self.tree.add_child(dialog)
if property.get("hint_text", "") == "*":
dialog.file_mode = FileDialog.FILE_MODE_OPEN_ANY
dialog.file_mode = EditorFileDialog.FILE_MODE_OPEN_ANY
else:
dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
self.tree.add_child(dialog)
var view_size: Vector2 = self.tree.get_viewport().size
dialog.popup_centered_ratio(0.4)
dialog.file_mode = EditorFileDialog.FILE_MODE_OPEN_FILE
dialog.close_requested.connect(dialog.queue_free)
dialog.file_selected.connect(self._on_path_selected)
dialog.dir_selected.connect(self._on_path_selected)
dialog.popup_centered_ratio(0.4)

func _on_path_selected(path: String) -> void:
self.value = path
Expand Down
10 changes: 5 additions & 5 deletions addons/licenses/internal/handler/string_multiline.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ func _init(tree_: ComponentDetailTree, item_: TreeItem, value_: Variant, propert
tooltip_text += "..."
self.item.set_tooltip_text(1, tooltip_text)
self._update_reset_button()
self.item.add_button(1, self.tree.get_theme_icon("DistractionFree", "EditorIcons"), 1)
self.item.add_button(1, self.tree.get_theme_icon(&"DistractionFree", &"EditorIcons"), 1)

static func can_handle(property: Dictionary) -> bool:
return property["type"] == TYPE_STRING and property.get("hint", PROPERTY_HINT_NONE) == PROPERTY_HINT_MULTILINE_TEXT
return property["type"] == TYPE_STRING && property.get("hint", PROPERTY_HINT_NONE) == PROPERTY_HINT_MULTILINE_TEXT

func _update_reset_button() -> void:
var button_id: int = self.item.get_button_by_id(0, 0)
if self.value != "" and button_id == -1:
self.item.add_button(0, self.tree.get_theme_icon("Reload", "EditorIcons"), 0)
elif self.value == "" and button_id != -1:
if self.value != "" && button_id == -1:
self.item.add_button(0, self.tree.get_theme_icon(&"Reload", &"EditorIcons"), 0)
elif self.value == "" && button_id != -1:
self.item.erase_button(0, button_id)

func button_clicked(column: int, id: int, mouse_button_idx: int) -> void:
Expand Down
18 changes: 9 additions & 9 deletions addons/licenses/internal/licenses.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ var _components: ComponentsContainer = ComponentsContainer.new()
var _file_watcher: FileSystemWatcher

func _ready() -> void:
self._license_file_load_button.icon = self.get_theme_icon("Load", "EditorIcons")
self._license_file_load_button.icon = self.get_theme_icon(&"Load", &"EditorIcons")
self._license_file_load_button.pressed.connect(self._on_data_file_load_button_clicked)
self._set_license_filepath_button.icon = self.get_theme_icon("ImportCheck", "EditorIcons")
self._set_license_filepath_button.icon = self.get_theme_icon(&"ImportCheck", &"EditorIcons")
self._set_license_filepath_button.pressed.connect(self._on_set_license_filepath_clicked)
self._license_file_edit.text_submitted.connect(self._on_data_file_edit_changed)
self._license_file_edit.text = Licenses.get_license_data_filepath()
Expand Down Expand Up @@ -62,7 +62,7 @@ func reload() -> void:
self._license_file_edit.right_icon = null
self._license_file_edit.tooltip_text = ""
else:
self._license_file_edit.right_icon = self.get_theme_icon("NodeWarning", "EditorIcons")
self._license_file_edit.right_icon = self.get_theme_icon(&"NodeWarning", &"EditorIcons")
self._license_file_edit.tooltip_text = res.err_msg

self._components.set_components(res.components)
Expand All @@ -71,22 +71,22 @@ func reload() -> void:

func _update_set_license_filepath_button() -> void:
if Licenses.get_license_data_filepath() == self._license_file_edit.text:
self._set_license_filepath_button.icon = self.get_theme_icon("ImportCheck", "EditorIcons")
self._set_license_filepath_button.icon = self.get_theme_icon(&"ImportCheck", &"EditorIcons")
self._set_license_filepath_button.tooltip_text = "Selected file is set as the project license file."
self._set_license_filepath_button.disabled = true
else:
self._set_license_filepath_button.icon = self.get_theme_icon("ImportFail", "EditorIcons")
self._set_license_filepath_button.icon = self.get_theme_icon(&"ImportFail", &"EditorIcons")
self._set_license_filepath_button.tooltip_text = "Set the current file as project license file."
self._set_license_filepath_button.disabled = false

func _on_data_file_load_button_clicked() -> void:
var dialog: FileDialog = FileDialog.new()
dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
dialog.current_path = self._license_file_edit.text
var dialog: EditorFileDialog = EditorFileDialog.new()
self.add_child(dialog)
dialog.popup_centered_ratio(0.4)
dialog.file_mode = EditorFileDialog.FILE_MODE_OPEN_FILE
dialog.current_path = self._license_file_edit.text
dialog.close_requested.connect(dialog.queue_free)
dialog.file_selected.connect(self._on_data_file_selected)
dialog.popup_centered_ratio(0.4)

func _on_data_file_edit_changed(new_text: String) -> void:
self._on_data_file_selected(new_text)
Expand Down
Loading

0 comments on commit 821d5c2

Please sign in to comment.