Skip to content

Commit

Permalink
Save color palette as resources to reuse later
Browse files Browse the repository at this point in the history
Co-authored-by: Micky <[email protected]>
  • Loading branch information
nongvantinh and Mickeon committed Oct 9, 2024
1 parent 4c4e673 commit 8e241c4
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 12 deletions.
16 changes: 16 additions & 0 deletions doc/classes/ColorPalette.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ColorPalette" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A resource class for managing a palette of colors, which can be loaded and saved using [ColorPicker].
</brief_description>
<description>
The [ColorPalette] resource is designed to store and manage a collection of colors. This resource is useful in scenarios where a predefined set of colors is required, such as for creating themes, designing user interfaces, or managing game assets. The built-in [ColorPicker] control can also make use of [ColorPalette] without additional code.
</description>
<tutorials>
</tutorials>
<members>
<member name="colors" type="PackedColorArray" setter="set_colors" getter="get_colors" default="PackedColorArray()">
A [PackedColorArray] containing the colors in the palette.
</member>
</members>
</class>
3 changes: 3 additions & 0 deletions doc/classes/ColorPicker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
<theme_item name="folded_arrow" data_type="icon" type="Texture2D">
The icon for color preset drop down menu when folded.
</theme_item>
<theme_item name="menu_option" data_type="icon" type="Texture2D">
The icon for color preset option menu.
</theme_item>
<theme_item name="overbright_indicator" data_type="icon" type="Texture2D">
The indicator used to signalize that the color value is outside the 0-1 range.
</theme_item>
Expand Down
12 changes: 12 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3422,6 +3422,11 @@ void EditorNode::_update_file_menu_closed() {
file_menu->set_item_disabled(file_menu->get_item_index(FILE_OPEN_PREV), false);
}

void EditorNode::_palette_quick_open_dialog() {
quick_open_color_palette->popup_dialog({ "ColorPalette" }, palette_file_selected_callback);
quick_open_color_palette->set_title(TTR("Quick Open Color Palette..."));
}

void EditorNode::replace_resources_in_object(Object *p_object, const Vector<Ref<Resource>> &p_source_resources, const Vector<Ref<Resource>> &p_target_resource) {
List<PropertyInfo> pi;
p_object->get_property_list(&pi);
Expand Down Expand Up @@ -3881,6 +3886,10 @@ void EditorNode::setup_color_picker(ColorPicker *p_picker) {

p_picker->set_color_mode((ColorPicker::ColorModeType)default_color_mode);
p_picker->set_picker_shape((ColorPicker::PickerShapeType)picker_shape);

p_picker->set_quick_open_callback(callable_mp(this, &EditorNode::_palette_quick_open_dialog));
p_picker->set_palette_saved_callback(callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::update_file));
palette_file_selected_callback = callable_mp(p_picker, &ColorPicker::_quick_open_palette_file_selected);
}

bool EditorNode::is_scene_open(const String &p_path) {
Expand Down Expand Up @@ -7827,6 +7836,9 @@ EditorNode::EditorNode() {
quick_open_dialog = memnew(EditorQuickOpenDialog);
gui_base->add_child(quick_open_dialog);

quick_open_color_palette = memnew(EditorQuickOpenDialog);
gui_base->add_child(quick_open_color_palette);

_update_recent_scenes();

set_process_shortcut_input(true);
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class EditorNode : public Node {
EditorPluginList *editor_plugins_force_input_forwarding = nullptr;
EditorPluginList *editor_plugins_force_over = nullptr;
EditorPluginList *editor_plugins_over = nullptr;
EditorQuickOpenDialog *quick_open_color_palette = nullptr;
EditorResourcePreview *resource_preview = nullptr;
EditorSelection *editor_selection = nullptr;
EditorSettingsDialog *editor_settings_dialog = nullptr;
Expand Down Expand Up @@ -413,6 +414,7 @@ class EditorNode : public Node {
Timer *editor_layout_save_delay_timer = nullptr;
Timer *scan_changes_timer = nullptr;
Button *distraction_free = nullptr;
Callable palette_file_selected_callback;

EditorBottomPanel *bottom_panel = nullptr;

Expand Down Expand Up @@ -534,6 +536,7 @@ class EditorNode : public Node {
void _export_as_menu_option(int p_idx);
void _update_file_menu_opened();
void _update_file_menu_closed();
void _palette_quick_open_dialog();

void _remove_plugin_from_enabled(const String &p_name);
void _plugin_over_edit(EditorPlugin *p_plugin, Object *p_object);
Expand Down
Loading

0 comments on commit 8e241c4

Please sign in to comment.