Merge pull request #22402 from DualMatrix/colorpicker_presets
Made ColorPicker save it's presets while in editor.
This commit is contained in:
commit
fb5cbf2d30
@ -33,6 +33,11 @@
|
|||||||
#include "core/os/input.h"
|
#include "core/os/input.h"
|
||||||
#include "core/os/keyboard.h"
|
#include "core/os/keyboard.h"
|
||||||
#include "core/os/os.h"
|
#include "core/os/os.h"
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
#include "editor_settings.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "scene/gui/separator.h"
|
#include "scene/gui/separator.h"
|
||||||
#include "scene/main/viewport.h"
|
#include "scene/main/viewport.h"
|
||||||
|
|
||||||
@ -52,6 +57,16 @@ void ColorPicker::_notification(int p_what) {
|
|||||||
bt_add_preset->set_icon(get_icon("add_preset"));
|
bt_add_preset->set_icon(get_icon("add_preset"));
|
||||||
|
|
||||||
_update_color();
|
_update_color();
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
if (Engine::get_singleton()->is_editor_hint()) {
|
||||||
|
PoolColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PoolColorArray());
|
||||||
|
|
||||||
|
for (int i = 0; i < saved_presets.size(); i++) {
|
||||||
|
add_preset(saved_presets[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_PARENTED: {
|
case NOTIFICATION_PARENTED: {
|
||||||
|
|
||||||
@ -186,9 +201,22 @@ void ColorPicker::_update_presets() {
|
|||||||
|
|
||||||
preset->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), Rect2(Point2(), preset_size), true);
|
preset->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), Rect2(Point2(), preset_size), true);
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
if (Engine::get_singleton()->is_editor_hint()) {
|
||||||
|
PoolColorArray arr_to_save = PoolColorArray();
|
||||||
|
|
||||||
|
for (int i = 0; i < presets.size(); i++) {
|
||||||
|
preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]);
|
||||||
|
arr_to_save.insert(i, presets[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save);
|
||||||
|
}
|
||||||
|
#else
|
||||||
for (int i = 0; i < presets.size(); i++) {
|
for (int i = 0; i < presets.size(); i++) {
|
||||||
preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]);
|
preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPicker::_text_type_toggled() {
|
void ColorPicker::_text_type_toggled() {
|
||||||
|
Loading…
Reference in New Issue
Block a user