mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 04:16:50 +01:00
PaintProjectPropertyInspector now uses and manages the presets in PaintProjects.
This commit is contained in:
parent
2485665f89
commit
884fae4847
@ -31,7 +31,7 @@ SOFTWARE.
|
|||||||
#include "../../nodes/paint_node.h"
|
#include "../../nodes/paint_node.h"
|
||||||
#include "../../nodes/paint_project.h"
|
#include "../../nodes/paint_project.h"
|
||||||
|
|
||||||
void PaintProjectPropertyInspector::add_grid_button(const Color &color) {
|
void PaintProjectPropertyInspector::add_grid_button(const Color &color, const int color_index) {
|
||||||
ColorSelectorButton *color_selector_button = memnew(ColorSelectorButton);
|
ColorSelectorButton *color_selector_button = memnew(ColorSelectorButton);
|
||||||
|
|
||||||
color_selector_button->set_custom_minimum_size(Size2(35, 30));
|
color_selector_button->set_custom_minimum_size(Size2(35, 30));
|
||||||
@ -39,8 +39,29 @@ void PaintProjectPropertyInspector::add_grid_button(const Color &color) {
|
|||||||
_color_grid->add_child(color_selector_button);
|
_color_grid->add_child(color_selector_button);
|
||||||
|
|
||||||
color_selector_button->set_pick_color(color);
|
color_selector_button->set_pick_color(color);
|
||||||
color_selector_button->connect("color_changed", this, "_on_grid_color_button_changed", varray(_color_grid->get_child_count() - 1));
|
color_selector_button->set_meta("color_index", color_index);
|
||||||
color_selector_button->connect("pressed", this, "_on_grid_color_button_pressed", varray(_color_grid->get_child_count() - 1));
|
color_selector_button->connect("color_changed", this, "_on_grid_color_button_changed", varray(color_selector_button));
|
||||||
|
color_selector_button->connect("pressed", this, "_on_grid_color_button_pressed", varray(color_selector_button));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaintProjectPropertyInspector::create_grid_buttons() {
|
||||||
|
PaintProject *proj = Object::cast_to<PaintProject>(ObjectDB::get_instance(_current_paint_project));
|
||||||
|
|
||||||
|
if (!proj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolColorArray colors = proj->get_color_presets();
|
||||||
|
|
||||||
|
for (int i = 0; i < colors.size(); ++i) {
|
||||||
|
add_grid_button(colors[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaintProjectPropertyInspector::clear_grid_buttons() {
|
||||||
|
for (int i = 0; i < _color_grid->get_child_count(); ++i) {
|
||||||
|
_color_grid->get_child(i)->queue_delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintProjectPropertyInspector::_on_paint_node_selected(Node *p_paint_node) {
|
void PaintProjectPropertyInspector::_on_paint_node_selected(Node *p_paint_node) {
|
||||||
@ -60,26 +81,34 @@ void PaintProjectPropertyInspector::_on_paint_node_selected(Node *p_paint_node)
|
|||||||
if (!proj) {
|
if (!proj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_current_paint_project = proj->get_instance_id();
|
_current_paint_project = proj->get_instance_id();
|
||||||
_main_color_button->set_pick_color(proj->get_current_color());
|
_main_color_button->set_pick_color(proj->get_current_color());
|
||||||
|
|
||||||
|
create_grid_buttons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintProjectPropertyInspector::_on_grid_color_button_changed(const Color &color, const int index) {
|
void PaintProjectPropertyInspector::_on_grid_color_button_changed(const Color &color, Node *p_button) {
|
||||||
PaintProject *proj = Object::cast_to<PaintProject>(ObjectDB::get_instance(_current_paint_project));
|
PaintProject *proj = Object::cast_to<PaintProject>(ObjectDB::get_instance(_current_paint_project));
|
||||||
|
|
||||||
ColorSelectorButton *button = Object::cast_to<ColorSelectorButton>(_color_grid->get_child(index));
|
ColorSelectorButton *button = Object::cast_to<ColorSelectorButton>(p_button);
|
||||||
ERR_FAIL_COND(!button);
|
ERR_FAIL_COND(!button);
|
||||||
|
|
||||||
if (proj) {
|
if (proj) {
|
||||||
//store
|
_ignore_preset_changed_event = true;
|
||||||
|
|
||||||
|
int color_index = button->get_meta("color_index");
|
||||||
|
|
||||||
|
proj->set_preset_color(color_index, color);
|
||||||
|
|
||||||
|
_ignore_preset_changed_event = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintProjectPropertyInspector::_on_grid_color_button_pressed(const int index) {
|
void PaintProjectPropertyInspector::_on_grid_color_button_pressed(Node *p_button) {
|
||||||
PaintProject *proj = Object::cast_to<PaintProject>(ObjectDB::get_instance(_current_paint_project));
|
PaintProject *proj = Object::cast_to<PaintProject>(ObjectDB::get_instance(_current_paint_project));
|
||||||
|
|
||||||
ColorSelectorButton *button = Object::cast_to<ColorSelectorButton>(_color_grid->get_child(index));
|
ColorSelectorButton *button = Object::cast_to<ColorSelectorButton>(p_button);
|
||||||
ERR_FAIL_COND(!button);
|
ERR_FAIL_COND(!button);
|
||||||
|
|
||||||
if (proj) {
|
if (proj) {
|
||||||
@ -103,9 +132,35 @@ void PaintProjectPropertyInspector::_on_main_color_selected() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaintProjectPropertyInspector::_on_add_color_button_pressed() {
|
||||||
|
PaintProject *proj = Object::cast_to<PaintProject>(ObjectDB::get_instance(_current_paint_project));
|
||||||
|
|
||||||
|
if (proj) {
|
||||||
|
_ignore_preset_changed_event = true;
|
||||||
|
Color c = _main_color_button->get_pick_color();
|
||||||
|
proj->add_preset_color(c);
|
||||||
|
add_grid_button(c, proj->get_preset_color_count() - 1);
|
||||||
|
_ignore_preset_changed_event = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaintProjectPropertyInspector::_on_project_color_preset_changed() {
|
||||||
|
if (_ignore_preset_changed_event) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PaintProject *proj = Object::cast_to<PaintProject>(ObjectDB::get_instance(_current_paint_project));
|
||||||
|
|
||||||
|
if (proj) {
|
||||||
|
clear_grid_buttons();
|
||||||
|
create_grid_buttons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PaintProjectPropertyInspector::PaintProjectPropertyInspector() {
|
PaintProjectPropertyInspector::PaintProjectPropertyInspector() {
|
||||||
_current_paint_node = 0;
|
_current_paint_node = 0;
|
||||||
_current_paint_project = 0;
|
_current_paint_project = 0;
|
||||||
|
_ignore_preset_changed_event = false;
|
||||||
|
|
||||||
VBoxContainer *main_container = memnew(VBoxContainer);
|
VBoxContainer *main_container = memnew(VBoxContainer);
|
||||||
add_child(main_container);
|
add_child(main_container);
|
||||||
@ -131,19 +186,27 @@ PaintProjectPropertyInspector::PaintProjectPropertyInspector() {
|
|||||||
_main_color_button->connect("color_changed", this, "_on_main_color_changed");
|
_main_color_button->connect("color_changed", this, "_on_main_color_changed");
|
||||||
_main_color_button->connect("pressed", this, "_on_main_color_selected");
|
_main_color_button->connect("pressed", this, "_on_main_color_selected");
|
||||||
|
|
||||||
//TODO add button
|
_add_color_button = memnew(Button);
|
||||||
for (int i = 0; i < 30; ++i) {
|
row_container->add_child(_add_color_button);
|
||||||
add_grid_button(Color(Math::randf(), Math::randf(), Math::randf()));
|
_add_color_button->set_tooltip("Save color.");
|
||||||
}
|
_add_color_button->connect("pressed", this, "_on_add_color_button_pressed");
|
||||||
}
|
}
|
||||||
|
|
||||||
PaintProjectPropertyInspector::~PaintProjectPropertyInspector() {
|
PaintProjectPropertyInspector::~PaintProjectPropertyInspector() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaintProjectPropertyInspector::_notification(int p_what) {
|
||||||
|
if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) {
|
||||||
|
_add_color_button->set_icon(get_theme_icon("Add", "EditorIcons"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PaintProjectPropertyInspector::_bind_methods() {
|
void PaintProjectPropertyInspector::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("_on_grid_color_button_changed"), &PaintProjectPropertyInspector::_on_grid_color_button_changed);
|
ClassDB::bind_method(D_METHOD("_on_grid_color_button_changed"), &PaintProjectPropertyInspector::_on_grid_color_button_changed);
|
||||||
ClassDB::bind_method(D_METHOD("_on_grid_color_button_pressed"), &PaintProjectPropertyInspector::_on_grid_color_button_pressed);
|
ClassDB::bind_method(D_METHOD("_on_grid_color_button_pressed"), &PaintProjectPropertyInspector::_on_grid_color_button_pressed);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_on_main_color_changed"), &PaintProjectPropertyInspector::_on_main_color_changed);
|
ClassDB::bind_method(D_METHOD("_on_main_color_changed"), &PaintProjectPropertyInspector::_on_main_color_changed);
|
||||||
ClassDB::bind_method(D_METHOD("_on_main_color_selected"), &PaintProjectPropertyInspector::_on_main_color_selected);
|
ClassDB::bind_method(D_METHOD("_on_main_color_selected"), &PaintProjectPropertyInspector::_on_main_color_selected);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("_on_add_color_button_pressed"), &PaintProjectPropertyInspector::_on_add_color_button_pressed);
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,15 @@ class PaintNode;
|
|||||||
class PaintProject;
|
class PaintProject;
|
||||||
class HFlowContainer;
|
class HFlowContainer;
|
||||||
class ColorSelectorButton;
|
class ColorSelectorButton;
|
||||||
|
class Button;
|
||||||
|
|
||||||
class PaintProjectPropertyInspector : public PaintCustomPropertyInspector {
|
class PaintProjectPropertyInspector : public PaintCustomPropertyInspector {
|
||||||
GDCLASS(PaintProjectPropertyInspector, PaintCustomPropertyInspector);
|
GDCLASS(PaintProjectPropertyInspector, PaintCustomPropertyInspector);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void add_grid_button(const Color &color);
|
void add_grid_button(const Color &color, const int color_index);
|
||||||
|
void create_grid_buttons();
|
||||||
|
void clear_grid_buttons();
|
||||||
|
|
||||||
void _on_paint_node_selected(Node *paint_node);
|
void _on_paint_node_selected(Node *paint_node);
|
||||||
|
|
||||||
@ -45,18 +48,25 @@ public:
|
|||||||
~PaintProjectPropertyInspector();
|
~PaintProjectPropertyInspector();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _on_grid_color_button_changed(const Color &color, const int index);
|
void _on_grid_color_button_changed(const Color &color, Node *button);
|
||||||
void _on_grid_color_button_pressed(const int index);
|
void _on_grid_color_button_pressed(Node *button);
|
||||||
void _on_main_color_changed(const Color &color);
|
void _on_main_color_changed(const Color &color);
|
||||||
void _on_main_color_selected();
|
void _on_main_color_selected();
|
||||||
|
void _on_add_color_button_pressed();
|
||||||
|
void _on_project_color_preset_changed();
|
||||||
|
|
||||||
|
void _notification(int p_what);
|
||||||
|
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
HFlowContainer *_color_grid;
|
HFlowContainer *_color_grid;
|
||||||
ColorSelectorButton *_main_color_button;
|
ColorSelectorButton *_main_color_button;
|
||||||
|
Button *_add_color_button;
|
||||||
|
|
||||||
ObjectID _current_paint_node;
|
ObjectID _current_paint_node;
|
||||||
ObjectID _current_paint_project;
|
ObjectID _current_paint_project;
|
||||||
|
|
||||||
|
bool _ignore_preset_changed_event;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user