From bfd80993f28b5c17b283511b9a339af7a74ff05e Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 15 Nov 2022 23:12:39 +0100 Subject: [PATCH] Now PaintColorGrid sets the active project's color. --- .../ui/sidebar_modules/paint_color_grid.cpp | 31 +++++++++++++++++++ .../ui/sidebar_modules/paint_color_grid.h | 8 +++++ 2 files changed, 39 insertions(+) diff --git a/modules/paint/ui/sidebar_modules/paint_color_grid.cpp b/modules/paint/ui/sidebar_modules/paint_color_grid.cpp index 7c0348aa7..1a86b5170 100644 --- a/modules/paint/ui/sidebar_modules/paint_color_grid.cpp +++ b/modules/paint/ui/sidebar_modules/paint_color_grid.cpp @@ -29,8 +29,17 @@ SOFTWARE. #include "scene/gui/scroll_container.h" #include "scene/resources/style_box.h" +#include "../../nodes/paint_node.h" +#include "../../nodes/paint_project.h" + void PaintColorGrid::change_color_to(const Color &color) { emit_signal("color_change_request", color); + + PaintProject *proj = Object::cast_to(ObjectDB::get_instance(_current_paint_project)); + + if (proj) { + proj->set_current_color(color); + } } void PaintColorGrid::add_color_prefab(const Color &color) { Button *button = memnew(Button); @@ -54,7 +63,29 @@ void PaintColorGrid::add_color_prefab(const Color &color) { button->connect("pressed", this, "change_color_to", binds); } +void PaintColorGrid::_on_paint_node_selected(Node *p_paint_node) { + PaintNode *paint_node = Object::cast_to(p_paint_node); + + _current_paint_node = 0; + _current_paint_project = 0; + + if (!paint_node) { + return; + } + + _current_paint_node = paint_node->get_instance_id(); + + PaintProject *proj = paint_node->get_paint_project(); + + if (proj) { + _current_paint_project = proj->get_instance_id(); + } +} + PaintColorGrid::PaintColorGrid() { + _current_paint_node = 0; + _current_paint_project = 0; + ScrollContainer *scroll_container = memnew(ScrollContainer); scroll_container->set_custom_minimum_size(Size2(0, 145)); scroll_container->set_enable_h_scroll(false); diff --git a/modules/paint/ui/sidebar_modules/paint_color_grid.h b/modules/paint/ui/sidebar_modules/paint_color_grid.h index 9eef94d21..79336955f 100644 --- a/modules/paint/ui/sidebar_modules/paint_color_grid.h +++ b/modules/paint/ui/sidebar_modules/paint_color_grid.h @@ -26,8 +26,11 @@ SOFTWARE. */ #include "../paint_sidebar_module.h" +#include "core/object/object_id.h" class GridContainer; +class PaintNode; +class PaintProject; class PaintColorGrid : public PaintSidebarModule { GDCLASS(PaintColorGrid, PaintSidebarModule); @@ -41,6 +44,8 @@ public: void change_color_to(const Color &color); void add_color_prefab(const Color &color); + void _on_paint_node_selected(Node *paint_node); + PaintColorGrid(); ~PaintColorGrid(); @@ -48,6 +53,9 @@ protected: static void _bind_methods(); GridContainer *_grid; + + ObjectID _current_paint_node; + ObjectID _current_paint_project; }; #endif