Skip to content

Commit

Permalink
Some code cleanup + save sidebar collapsing
Browse files Browse the repository at this point in the history
Whether the sidebar is collapsed is now saved to editor state.

Simplifies ResourceListItem class into a contained class (avoids the public class name). Also uses RefCounted to avoid having to free them manually.

Some code cleanup.
  • Loading branch information
Jowan-Spooner committed Jul 26, 2024
1 parent 0f40cfa commit 1a24c54
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
21 changes: 0 additions & 21 deletions addons/dialogic/Editor/Common/ResourceItemList.gd

This file was deleted.

4 changes: 2 additions & 2 deletions addons/dialogic/Editor/Common/side_bar.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ script = ExtResource("1_jnq65")

[node name="VBoxHidden" type="VBoxContainer" parent="."]
unique_name_in_owner = true
visible = false
layout_mode = 2

[node name="OpenButton" type="Button" parent="VBoxHidden"]
Expand All @@ -39,7 +40,6 @@ icon_alignment = 1

[node name="VBoxPrimary" type="VBoxContainer" parent="."]
unique_name_in_owner = true
visible = false
layout_mode = 2
size_flags_vertical = 3

Expand Down Expand Up @@ -114,9 +114,9 @@ vertical_alignment = 1
[node name="SortOption" type="OptionButton" parent="VBoxPrimary/Margin/VSplitContainer/VBox/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
selected = 0
item_count = 1
popup/item_0/text = "Alphabetical (All)"
popup/item_0/id = 0

[node name="ContentListSection" type="VBoxContainer" parent="VBoxPrimary/Margin/VSplitContainer"]
unique_name_in_owner = true
Expand Down
41 changes: 35 additions & 6 deletions addons/dialogic/Editor/Common/sidebar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func _ready() -> void:
%RightClickMenu.add_icon_item(get_theme_icon("Filesystem", "EditorIcons"), "Show in FileSystem", 2)
%RightClickMenu.add_icon_item(get_theme_icon("ExternalLink", "EditorIcons"), "Open in External Program", 3)

await get_tree().process_frame
if DialogicUtil.get_editor_setting("sidebar_collapsed", false):
_hide_sidebar()


################################################################################
## SHOW/HIDE SIDEBAR
Expand All @@ -74,12 +78,14 @@ func _ready() -> void:
func _show_sidebar() -> void:
%VBoxPrimary.show()
%VBoxHidden.hide()
DialogicUtil.set_editor_setting("sidebar_collapsed", false)
show_sidebar.emit(true)


func _hide_sidebar() -> void:
%VBoxPrimary.hide()
%VBoxHidden.show()
DialogicUtil.set_editor_setting("sidebar_collapsed", true)
show_sidebar.emit(false)


Expand Down Expand Up @@ -123,24 +129,24 @@ func update_resource_list(resources_list: PackedStringArray = []) -> void:
)

resource_tree.clear()
var resource_list_items = []
var resource_list_items := []

var character_items = []
var character_items := []
for character_name in character_directory:
if character_directory[character_name] in resources_list:
if filter.is_empty() or filter.to_lower() in character_name.to_lower():
var item = ResourceListItem.new()
var item := ResourceListItem.new()
item.text = character_name
item.icon = load("res://addons/dialogic/Editor/Images/Resources/character.svg")
item.metadata = character_directory[character_name]
item.tooltip = character_directory[character_name]
character_items.append(item)

var timeline_items = []
var timeline_items := []
for timeline_name in timeline_directory:
if timeline_directory[timeline_name] in resources_list:
if filter.is_empty() or filter.to_lower() in timeline_name.to_lower():
var item = ResourceListItem.new()
var item := ResourceListItem.new()
item.text = timeline_name
item.icon = get_theme_icon("TripleBar", "EditorIcons")
item.metadata = timeline_directory[timeline_name]
Expand Down Expand Up @@ -206,7 +212,6 @@ func _on_resources_tree_item_clicked(_pos: Vector2, mouse_button_index: int) ->
if mouse_button_index == MOUSE_BUTTON_RIGHT:
%RightClickMenu.popup_on_parent(Rect2(get_global_mouse_position(), Vector2()))
(%RightClickMenu as PopupMenu).set_meta("item_clicked", resource_tree.get_selected())
# %RightClickMenu.set_meta("item_index", resource_tree.get_selected())


func _on_search_text_changed(new_text: String) -> void:
Expand Down Expand Up @@ -306,3 +311,27 @@ func _on_right_click_menu_id_pressed(id: int) -> void:

func _sort_by_item_text(a: ResourceListItem, b: ResourceListItem) -> bool:
return a.text < b.text


class ResourceListItem:
extends Object
var text: String
var index: int = -1
var icon: Texture
var metadata: String
var tooltip: String


func add_to_item_list(item_list: ItemList, current_file: String) -> void:
item_list.add_item(text, icon)
item_list.set_item_metadata(item_list.item_count - 1, metadata)
item_list.set_item_tooltip(item_list.item_count - 1, tooltip)


func current_file(sidebar: Control, resource_list: ItemList, current_file: String) -> void:
if metadata == current_file:
resource_list.select(index)
resource_list.set_item_custom_fg_color(
index, resource_list.get_theme_color("accent_color", "Editor")
)
sidebar.find_child("CurrentResource").text = metadata.get_file()
25 changes: 13 additions & 12 deletions addons/dialogic/Editor/editor_main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,7 @@ func _ready() -> void:
return

## CONNECTIONS
%Sidebar.show_sidebar.connect(
func(show: bool):
var h_split = (%HSplit as HSplitContainer)
if show:
h_split.dragger_visibility = SplitContainer.DRAGGER_VISIBLE
h_split.split_offset = 150
h_split.collapsed = false
else:
h_split.dragger_visibility = SplitContainer.DRAGGER_HIDDEN_COLLAPSED
h_split.split_offset = 0
h_split.collapsed = true
)
%Sidebar.show_sidebar.connect(_on_sidebar_toggled)

## REFERENCES
editors_manager = $EditorsManager
Expand All @@ -50,6 +39,18 @@ func _ready() -> void:
EditorInterface.get_base_control().theme_changed.connect(update_theme_additions)


func _on_sidebar_toggled(sidebar_shown: bool) -> void:
var h_split := (%HSplit as HSplitContainer)
if sidebar_shown:
h_split.dragger_visibility = SplitContainer.DRAGGER_VISIBLE
h_split.split_offset = 150
h_split.collapsed = false
else:
h_split.dragger_visibility = SplitContainer.DRAGGER_HIDDEN_COLLAPSED
h_split.split_offset = 0
h_split.collapsed = true


func update_theme_additions() -> void:
add_theme_stylebox_override(
"panel",
Expand Down

0 comments on commit 1a24c54

Please sign in to comment.