From a3bedba43a52951473ea3912c07dee1f54fd60b4 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 17 Nov 2022 23:32:09 +0100 Subject: [PATCH] Now PaintProject can store color presets. They also support defaults. --- modules/paint/nodes/paint_project.cpp | 39 +++++++++++++++++++++++++-- modules/paint/nodes/paint_project.h | 10 +++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/modules/paint/nodes/paint_project.cpp b/modules/paint/nodes/paint_project.cpp index 69ed11e84..f9883fab3 100644 --- a/modules/paint/nodes/paint_project.cpp +++ b/modules/paint/nodes/paint_project.cpp @@ -1,12 +1,29 @@ #include "paint_project.h" +#include "core/config/project_settings.h" + Color PaintProject::get_current_color() { return _current_color; } void PaintProject::set_current_color(const Color &color) { _current_color = color; - emit_signal("current_color_changed", _current_color); + emit_signal("current_color_changed", _current_color); +} + +PoolColorArray PaintProject::get_color_presets() { + return _color_presets; +} +void PaintProject::set_color_presets(const PoolColorArray &colors) { + _color_presets = colors; + + emit_signal("color_presets_changed"); +} + +void PaintProject::set_colors_as_default() { + if (ProjectSettings::get_singleton()) { + ProjectSettings::get_singleton()->set_setting("paint/color_presets/colors", _color_presets); + } } PaintProject::PaintProject() { @@ -16,10 +33,28 @@ PaintProject::PaintProject() { PaintProject::~PaintProject() { } +void PaintProject::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE) { + if (_color_presets.size() == 0) { + if (ProjectSettings::get_singleton()->has_setting("paint/color_presets/colors")) { + _color_presets = ProjectSettings::get_singleton()->get_setting("paint/color_presets/colors"); + } + } + } +} + void PaintProject::_bind_methods() { - ADD_SIGNAL(MethodInfo("current_color_changed", PropertyInfo(Variant::COLOR, "color"))); + ADD_SIGNAL(MethodInfo("current_color_changed", PropertyInfo(Variant::COLOR, "color"))); + ADD_SIGNAL(MethodInfo("color_presets_changed")); ClassDB::bind_method(D_METHOD("get_current_color"), &PaintProject::get_current_color); ClassDB::bind_method(D_METHOD("set_current_color", "size"), &PaintProject::set_current_color); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "current_color"), "set_current_color", "get_current_color"); + + ClassDB::bind_method(D_METHOD("get_color_presets"), &PaintProject::get_color_presets); + ClassDB::bind_method(D_METHOD("set_color_presets", "colors"), &PaintProject::set_color_presets); + ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "color_presets"), "set_color_presets", "get_color_presets"); + + ClassDB::bind_method(D_METHOD("set_colors_as_default"), &PaintProject::set_colors_as_default); + ADD_PROPERTY(PropertyInfo(Variant::NIL, "set_colors_as_default", PROPERTY_HINT_BUTTON, "set_colors_as_default"), "", ""); } diff --git a/modules/paint/nodes/paint_project.h b/modules/paint/nodes/paint_project.h index ae6c19e9c..02ebd6627 100644 --- a/modules/paint/nodes/paint_project.h +++ b/modules/paint/nodes/paint_project.h @@ -1,6 +1,8 @@ #ifndef PAINT_PROJECT_H #define PAINT_PROJECT_H +#include "core/containers/pool_vector.h" + #include "paint_node.h" class PaintProject : public PaintNode { @@ -10,13 +12,21 @@ public: Color get_current_color(); void set_current_color(const Color &color); + PoolColorArray get_color_presets(); + void set_color_presets(const PoolColorArray &colors); + + void set_colors_as_default(); + PaintProject(); ~PaintProject(); protected: + void _notification(int p_what); + static void _bind_methods(); Color _current_color; + PoolColorArray _color_presets; }; #endif