Fix folder colors not present in editor dir dialog
This commit is contained in:
parent
578d937927
commit
c8ef9e6955
5 changed files with 43 additions and 11 deletions
|
@ -51,6 +51,11 @@
|
|||
Emitted when a file is moved from [param old_file] path to [param new_file] path.
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="folder_color_changed">
|
||||
<description>
|
||||
Emitted when folders change color.
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="folder_moved">
|
||||
<param index="0" name="old_folder" type="String" />
|
||||
<param index="1" name="new_folder" type="String" />
|
||||
|
|
|
@ -234,15 +234,15 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
|
|||
Color custom_color = has_custom_color ? folder_colors[assigned_folder_colors[lpath]] : Color();
|
||||
|
||||
if (has_custom_color) {
|
||||
subdirectory_item->set_icon_modulate(0, editor_is_dark_theme ? custom_color : custom_color * 1.75);
|
||||
subdirectory_item->set_custom_bg_color(0, Color(custom_color, editor_is_dark_theme ? 0.1 : 0.15));
|
||||
subdirectory_item->set_icon_modulate(0, editor_is_dark_theme ? custom_color : custom_color * ITEM_COLOR_SCALE);
|
||||
subdirectory_item->set_custom_bg_color(0, Color(custom_color, editor_is_dark_theme ? ITEM_ALPHA_MIN : ITEM_ALPHA_MAX));
|
||||
} else {
|
||||
TreeItem *parent = subdirectory_item->get_parent();
|
||||
if (parent) {
|
||||
Color parent_bg_color = parent->get_custom_bg_color(0);
|
||||
if (parent_bg_color != Color()) {
|
||||
bool parent_has_custom_color = assigned_folder_colors.has(parent->get_metadata(0));
|
||||
subdirectory_item->set_custom_bg_color(0, parent_has_custom_color ? parent_bg_color.darkened(0.3) : parent_bg_color);
|
||||
subdirectory_item->set_custom_bg_color(0, parent_has_custom_color ? parent_bg_color.darkened(ITEM_BG_DARK_SCALE) : parent_bg_color);
|
||||
subdirectory_item->set_icon_modulate(0, parent->get_icon_modulate(0));
|
||||
} else {
|
||||
subdirectory_item->set_icon_modulate(0, get_theme_color(SNAME("folder_icon_color"), SNAME("FileDialog")));
|
||||
|
@ -328,7 +328,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
|
|||
file_item->set_icon_max_width(0, icon_size);
|
||||
Color parent_bg_color = subdirectory_item->get_custom_bg_color(0);
|
||||
if (has_custom_color) {
|
||||
file_item->set_custom_bg_color(0, parent_bg_color.darkened(0.3));
|
||||
file_item->set_custom_bg_color(0, parent_bg_color.darkened(ITEM_BG_DARK_SCALE));
|
||||
} else if (parent_bg_color != Color()) {
|
||||
file_item->set_custom_bg_color(0, parent_bg_color);
|
||||
}
|
||||
|
@ -1068,7 +1068,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
|
|||
|
||||
files->set_item_metadata(-1, bd);
|
||||
files->set_item_selectable(-1, false);
|
||||
files->set_item_icon_modulate(-1, editor_is_dark_theme ? inherited_folder_color : inherited_folder_color * 1.75);
|
||||
files->set_item_icon_modulate(-1, editor_is_dark_theme ? inherited_folder_color : inherited_folder_color * ITEM_COLOR_SCALE);
|
||||
}
|
||||
|
||||
bool reversed = file_sort == FILE_SORT_NAME_REVERSE;
|
||||
|
@ -1082,7 +1082,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
|
|||
files->add_item(dname, folder_icon, true);
|
||||
files->set_item_metadata(-1, dpath);
|
||||
Color this_folder_color = has_custom_color ? folder_colors[assigned_folder_colors[dpath]] : inherited_folder_color;
|
||||
files->set_item_icon_modulate(-1, editor_is_dark_theme ? this_folder_color : this_folder_color * 1.75);
|
||||
files->set_item_icon_modulate(-1, editor_is_dark_theme ? this_folder_color : this_folder_color * ITEM_COLOR_SCALE);
|
||||
|
||||
if (previous_selection.has(dname)) {
|
||||
files->select(files->get_item_count() - 1, false);
|
||||
|
@ -3086,6 +3086,8 @@ void FileSystemDock::_folder_color_index_pressed(int p_index, PopupMenu *p_menu)
|
|||
|
||||
_update_tree(get_uncollapsed_paths());
|
||||
_update_file_list(true);
|
||||
|
||||
emit_signal(SNAME("folder_color_changed"));
|
||||
}
|
||||
|
||||
void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vector<String> &p_paths, bool p_display_path_dependent_options) {
|
||||
|
@ -3796,6 +3798,7 @@ void FileSystemDock::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo("folder_removed", PropertyInfo(Variant::STRING, "folder")));
|
||||
ADD_SIGNAL(MethodInfo("files_moved", PropertyInfo(Variant::STRING, "old_file"), PropertyInfo(Variant::STRING, "new_file")));
|
||||
ADD_SIGNAL(MethodInfo("folder_moved", PropertyInfo(Variant::STRING, "old_folder"), PropertyInfo(Variant::STRING, "new_folder")));
|
||||
ADD_SIGNAL(MethodInfo("folder_color_changed"));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("display_mode_changed"));
|
||||
}
|
||||
|
|
|
@ -381,6 +381,11 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static constexpr double ITEM_COLOR_SCALE = 1.75;
|
||||
static constexpr double ITEM_ALPHA_MIN = 0.1;
|
||||
static constexpr double ITEM_ALPHA_MAX = 0.15;
|
||||
static constexpr double ITEM_BG_DARK_SCALE = 0.3;
|
||||
|
||||
const HashMap<String, Color> &get_folder_colors() const;
|
||||
Dictionary get_assigned_folder_colors() const;
|
||||
|
||||
|
|
|
@ -32,27 +32,44 @@
|
|||
|
||||
#include "editor/directory_create_dialog.h"
|
||||
#include "editor/editor_file_system.h"
|
||||
#include "editor/filesystem_dock.h"
|
||||
#include "editor/themes/editor_theme_manager.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/tree.h"
|
||||
#include "servers/display_server.h"
|
||||
|
||||
void EditorDirDialog::_update_dir(TreeItem *p_item, EditorFileSystemDirectory *p_dir, const String &p_select_path) {
|
||||
void EditorDirDialog::_update_dir(const Color &p_default_folder_color, const Dictionary &p_assigned_folder_colors, const HashMap<String, Color> &p_folder_colors, bool p_is_dark_theme, TreeItem *p_item, EditorFileSystemDirectory *p_dir, const String &p_select_path) {
|
||||
updating = true;
|
||||
|
||||
const String path = p_dir->get_path();
|
||||
|
||||
p_item->set_metadata(0, path);
|
||||
p_item->set_icon(0, tree->get_editor_theme_icon(SNAME("Folder")));
|
||||
p_item->set_icon_modulate(0, tree->get_theme_color(SNAME("folder_icon_color"), SNAME("FileDialog")));
|
||||
|
||||
if (!p_item->get_parent()) {
|
||||
p_item->set_text(0, "res://");
|
||||
p_item->set_icon_modulate(0, p_default_folder_color);
|
||||
} else {
|
||||
if (!opened_paths.has(path) && (p_select_path.is_empty() || !p_select_path.begins_with(path))) {
|
||||
p_item->set_collapsed(true);
|
||||
}
|
||||
|
||||
p_item->set_text(0, p_dir->get_name());
|
||||
|
||||
if (p_assigned_folder_colors.has(path)) {
|
||||
const Color &folder_color = p_folder_colors[p_assigned_folder_colors[path]];
|
||||
p_item->set_icon_modulate(0, p_is_dark_theme ? folder_color : folder_color * FileSystemDock::ITEM_COLOR_SCALE);
|
||||
p_item->set_custom_bg_color(0, Color(folder_color, p_is_dark_theme ? FileSystemDock::ITEM_ALPHA_MIN : FileSystemDock::ITEM_ALPHA_MAX));
|
||||
} else {
|
||||
TreeItem *parent_item = p_item->get_parent();
|
||||
Color parent_bg_color = parent_item->get_custom_bg_color(0);
|
||||
if (parent_bg_color != Color()) {
|
||||
p_item->set_custom_bg_color(0, p_assigned_folder_colors.has(parent_item->get_metadata(0)) ? parent_bg_color.darkened(FileSystemDock::ITEM_BG_DARK_SCALE) : parent_bg_color);
|
||||
p_item->set_icon_modulate(0, parent_item->get_icon_modulate(0));
|
||||
} else {
|
||||
p_item->set_icon_modulate(0, p_default_folder_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path == new_dir_path || !p_item->get_parent()) {
|
||||
|
@ -62,7 +79,7 @@ void EditorDirDialog::_update_dir(TreeItem *p_item, EditorFileSystemDirectory *p
|
|||
updating = false;
|
||||
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
|
||||
TreeItem *ti = tree->create_item(p_item);
|
||||
_update_dir(ti, p_dir->get_subdir(i));
|
||||
_update_dir(p_default_folder_color, p_assigned_folder_colors, p_folder_colors, p_is_dark_theme, ti, p_dir->get_subdir(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +107,7 @@ void EditorDirDialog::reload(const String &p_path) {
|
|||
|
||||
tree->clear();
|
||||
TreeItem *root = tree->create_item();
|
||||
_update_dir(root, EditorFileSystem::get_singleton()->get_filesystem(), p_path);
|
||||
_update_dir(tree->get_theme_color(SNAME("folder_icon_color"), SNAME("FileDialog")), FileSystemDock::get_singleton()->get_assigned_folder_colors(), FileSystemDock::get_singleton()->get_folder_colors(), EditorThemeManager::is_dark_theme(), root, EditorFileSystem::get_singleton()->get_filesystem(), p_path);
|
||||
_item_collapsed(root);
|
||||
new_dir_path.clear();
|
||||
must_reload = false;
|
||||
|
@ -99,6 +116,8 @@ void EditorDirDialog::reload(const String &p_path) {
|
|||
void EditorDirDialog::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
FileSystemDock::get_singleton()->connect("folder_color_changed", callable_mp(this, &EditorDirDialog::reload).bind(""));
|
||||
|
||||
EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &EditorDirDialog::reload).bind(""));
|
||||
reload();
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ class EditorDirDialog : public ConfirmationDialog {
|
|||
|
||||
void _item_collapsed(Object *p_item);
|
||||
void _item_activated();
|
||||
void _update_dir(TreeItem *p_item, EditorFileSystemDirectory *p_dir, const String &p_select_path = String());
|
||||
void _update_dir(const Color &p_default_folder_color, const Dictionary &p_assigned_folder_colors, const HashMap<String, Color> &p_folder_colors, bool p_is_dark_theme, TreeItem *p_item, EditorFileSystemDirectory *p_dir, const String &p_select_path = String());
|
||||
|
||||
void _make_dir();
|
||||
void _make_dir_confirm(const String &p_path);
|
||||
|
|
Loading…
Reference in a new issue