From e53868f60f534d1a5b004c88b119a60cf6008f34 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 17 Nov 2022 17:46:03 +0100 Subject: [PATCH] Added a new PaintProjectPropertyInspector class. --- modules/paint/SCsub | 1 + modules/paint/register_types.cpp | 2 + .../ui/property_inspectors/paint_color_grid.h | 7 +- .../paint_project_property_inspector.cpp | 111 ++++++++++++++++++ .../paint_project_property_inspector.h | 57 +++++++++ 5 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 modules/paint/ui/property_inspectors/paint_project_property_inspector.cpp create mode 100644 modules/paint/ui/property_inspectors/paint_project_property_inspector.h diff --git a/modules/paint/SCsub b/modules/paint/SCsub index 6187c19a6..6225dab1c 100644 --- a/modules/paint/SCsub +++ b/modules/paint/SCsub @@ -32,6 +32,7 @@ module_env.add_source_files(env.modules_sources,"ui/paint_visual_grid.cpp") module_env.add_source_files(env.modules_sources,"ui/property_inspectors/paint_color_grid.cpp") module_env.add_source_files(env.modules_sources,"ui/property_inspectors/paint_custom_property_inspector.cpp") module_env.add_source_files(env.modules_sources,"ui/property_inspectors/paint_tools_property_inspector.cpp") +module_env.add_source_files(env.modules_sources,"ui/property_inspectors/paint_project_property_inspector.cpp") module_env.add_source_files(env.modules_sources,"ui/paint_sidebar.cpp") module_env.add_source_files(env.modules_sources,"ui/paint_sidebar_module.cpp") diff --git a/modules/paint/register_types.cpp b/modules/paint/register_types.cpp index c0f9caff5..c09c93e43 100644 --- a/modules/paint/register_types.cpp +++ b/modules/paint/register_types.cpp @@ -45,6 +45,7 @@ SOFTWARE. #include "ui/property_inspectors/paint_color_grid.h" #include "ui/property_inspectors/paint_custom_property_inspector.h" +#include "ui/property_inspectors/paint_project_property_inspector.h" #include "ui/property_inspectors/paint_tools_property_inspector.h" #include "nodes/paint_canvas.h" @@ -81,6 +82,7 @@ void register_paint_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/modules/paint/ui/property_inspectors/paint_color_grid.h b/modules/paint/ui/property_inspectors/paint_color_grid.h index 63fb5cac0..fe07a68f4 100644 --- a/modules/paint/ui/property_inspectors/paint_color_grid.h +++ b/modules/paint/ui/property_inspectors/paint_color_grid.h @@ -28,6 +28,8 @@ SOFTWARE. #include "paint_custom_property_inspector.h" #include "core/object/object_id.h" +//TODO remove + class GridContainer; class PaintNode; class PaintProject; @@ -36,11 +38,6 @@ class PaintColorGrid : public PaintCustomPropertyInspector { GDCLASS(PaintColorGrid, PaintCustomPropertyInspector); public: - // TODO this should store settings in PaintProjects - // TODO the default settigns could be stored in the editor settings, so project specific pallettes can be done - // TODO It should get the project node for a given PaintNode - // NOTE The current color should be stored in PaintNodes - void change_color_to(const Color &color); void add_color_prefab(const Color &color); diff --git a/modules/paint/ui/property_inspectors/paint_project_property_inspector.cpp b/modules/paint/ui/property_inspectors/paint_project_property_inspector.cpp new file mode 100644 index 000000000..09ced619f --- /dev/null +++ b/modules/paint/ui/property_inspectors/paint_project_property_inspector.cpp @@ -0,0 +1,111 @@ +/* +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "paint_project_property_inspector.h" + +#include "scene/gui/button.h" +#include "scene/gui/color_picker.h" +#include "scene/gui/flow_container.h" +#include "scene/gui/scroll_container.h" + +#include "../../nodes/paint_node.h" +#include "../../nodes/paint_project.h" + +void PaintProjectPropertyInspector::add_grid_button(const Color &color) { + ColorSelectorButton *color_selector_button = memnew(ColorSelectorButton); + + color_selector_button->set_custom_minimum_size(Size2(35, 30)); + + _color_grid->add_child(color_selector_button); + + color_selector_button->set_pick_color(color); + color_selector_button->connect("color_changed", this, "_on_grid_color_changed", varray(_color_grid->get_child_count() - 1)); + color_selector_button->connect("pressed", this, "_on_grid_color_selected", varray(_color_grid->get_child_count() - 1)); +} + +void PaintProjectPropertyInspector::_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(); + } +} + +void PaintProjectPropertyInspector::_on_grid_color_changed(const Color &color, const int index) { + PaintProject *proj = Object::cast_to(ObjectDB::get_instance(_current_paint_project)); + + if (proj) { + //proj->set_current_color(color); + //store + } +} + +void PaintProjectPropertyInspector::_on_grid_color_selected(const int index) { + PaintProject *proj = Object::cast_to(ObjectDB::get_instance(_current_paint_project)); + + ColorSelectorButton *button = Object::cast_to(_color_grid->get_child(index)); + ERR_FAIL_COND(!button); + + if (proj) { + proj->set_current_color(button->get_pick_color()); + } +} + +PaintProjectPropertyInspector::PaintProjectPropertyInspector() { + _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); + add_child(scroll_container); + + _color_grid = memnew(HFlowContainer); + scroll_container->add_child(_color_grid); + + _color_grid->set_h_size_flags(SIZE_EXPAND_FILL); + _color_grid->set_v_size_flags(SIZE_EXPAND_FILL); + + //TODO add button + for (int i = 0; i < 30; ++i) { + add_grid_button(Color(Math::randf(), Math::randf(), Math::randf())); + } +} + +PaintProjectPropertyInspector::~PaintProjectPropertyInspector() { +} + +void PaintProjectPropertyInspector::_bind_methods() { + ClassDB::bind_method(D_METHOD("_on_grid_color_changed"), &PaintProjectPropertyInspector::_on_grid_color_changed); + ClassDB::bind_method(D_METHOD("_on_grid_color_selected"), &PaintProjectPropertyInspector::_on_grid_color_selected); +} diff --git a/modules/paint/ui/property_inspectors/paint_project_property_inspector.h b/modules/paint/ui/property_inspectors/paint_project_property_inspector.h new file mode 100644 index 000000000..54162942e --- /dev/null +++ b/modules/paint/ui/property_inspectors/paint_project_property_inspector.h @@ -0,0 +1,57 @@ +#ifndef PAINT_PROJECT_PROPERTY_INSPECTOR_H +#define PAINT_PROJECT_PROPERTY_INSPECTOR_H + +/* +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "core/object/object_id.h" +#include "paint_custom_property_inspector.h" + +class GridContainer; +class PaintNode; +class PaintProject; +class HFlowContainer; + +class PaintProjectPropertyInspector : public PaintCustomPropertyInspector { + GDCLASS(PaintProjectPropertyInspector, PaintCustomPropertyInspector); + +public: + void add_grid_button(const Color &color); + + void _on_paint_node_selected(Node *paint_node); + + PaintProjectPropertyInspector(); + ~PaintProjectPropertyInspector(); + +protected: + void _on_grid_color_changed(const Color &color, const int index); + void _on_grid_color_selected(const int index); + + static void _bind_methods(); + + HFlowContainer *_color_grid; + + ObjectID _current_paint_node; + ObjectID _current_paint_project; +}; + +#endif