Added a new PaintProjectPropertyInspector class.

This commit is contained in:
Relintai 2022-11-17 17:46:03 +01:00
parent f72fa755e0
commit e53868f60f
5 changed files with 173 additions and 5 deletions

View File

@ -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")

View File

@ -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<PaintColorGrid>();
ClassDB::register_class<PaintCustomPropertyInspector>();
ClassDB::register_class<PaintToolsPropertyInspector>();
ClassDB::register_class<PaintProjectPropertyInspector>();
ClassDB::register_class<PaintNode>();
ClassDB::register_class<PaintCanvas>();

View File

@ -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);

View File

@ -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<PaintNode>(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<PaintProject>(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<PaintProject>(ObjectDB::get_instance(_current_paint_project));
ColorSelectorButton *button = Object::cast_to<ColorSelectorButton>(_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);
}

View File

@ -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