Now PaintNodes can handle input events coming from the editor plugin.

This commit is contained in:
Relintai 2022-11-16 15:25:27 +01:00
parent afa0e83f78
commit c683e675e1
4 changed files with 44 additions and 2 deletions

View File

@ -34,6 +34,13 @@ Color PaintNode::util_random_color_alt() {
return PaintUtilities::random_color_alt(); return PaintUtilities::random_color_alt();
} }
bool PaintNode::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
return call("_forward_canvas_gui_input", p_event);
}
bool PaintNode::_forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
return false;
}
PaintProject *PaintNode::get_paint_project() { PaintProject *PaintNode::get_paint_project() {
PaintNode *p = this; PaintNode *p = this;
@ -87,5 +94,9 @@ void PaintNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("util_random_color"), &PaintNode::util_random_color); ClassDB::bind_method(D_METHOD("util_random_color"), &PaintNode::util_random_color);
ClassDB::bind_method(D_METHOD("util_random_color_alt"), &PaintNode::util_random_color_alt); ClassDB::bind_method(D_METHOD("util_random_color_alt"), &PaintNode::util_random_color_alt);
BIND_VMETHOD(MethodInfo(Variant::BOOL, "_forward_canvas_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ClassDB::bind_method(D_METHOD("forward_canvas_gui_input", "event"), &PaintNode::forward_canvas_gui_input);
ClassDB::bind_method(D_METHOD("_forward_canvas_gui_input", "event"), &PaintNode::_forward_canvas_gui_input);
ClassDB::bind_method(D_METHOD("get_paint_project"), &PaintNode::get_paint_project); ClassDB::bind_method(D_METHOD("get_paint_project"), &PaintNode::get_paint_project);
} }

View File

@ -24,6 +24,9 @@ public:
Color util_random_color(); Color util_random_color();
Color util_random_color_alt(); Color util_random_color_alt();
bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
bool _forward_canvas_gui_input(const Ref<InputEvent> &p_event);
PaintProject *get_paint_project(); PaintProject *get_paint_project();
String get_configuration_warning() const; String get_configuration_warning() const;

View File

@ -44,7 +44,9 @@ String PaintEditorPlugin::get_name() const {
} }
void PaintEditorPlugin::edit(Object *p_object) { void PaintEditorPlugin::edit(Object *p_object) {
_sidebar->on_paint_node_selected(Object::cast_to<PaintNode>(p_object)); _active_node = Object::cast_to<PaintNode>(p_object);
_sidebar->on_paint_node_selected(_active_node);
} }
bool PaintEditorPlugin::handles(Object *p_object) const { bool PaintEditorPlugin::handles(Object *p_object) const {
return p_object->is_class("PaintNode"); return p_object->is_class("PaintNode");
@ -53,7 +55,16 @@ void PaintEditorPlugin::edited_scene_changed() {
} }
bool PaintEditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) { bool PaintEditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
if (!_active_node) {
return false; return false;
}
if (!ObjectDB::instance_validate(_active_node)) {
_active_node = NULL;
return false;
}
return _active_node->forward_canvas_gui_input(p_event);
} }
void PaintEditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay) { void PaintEditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay) {
} }
@ -61,6 +72,8 @@ void PaintEditorPlugin::forward_canvas_force_draw_over_viewport(Control *p_overl
} }
PaintEditorPlugin::PaintEditorPlugin(EditorNode *p_node) { PaintEditorPlugin::PaintEditorPlugin(EditorNode *p_node) {
_active_node = NULL;
editor = p_node; editor = p_node;
EDITOR_DEF("editors/paint/editor_side", 0); EDITOR_DEF("editors/paint/editor_side", 0);
@ -88,6 +101,12 @@ PaintEditorPlugin::~PaintEditorPlugin() {
Engine::get_singleton()->remove_global("PaintEditorPlugin"); Engine::get_singleton()->remove_global("PaintEditorPlugin");
} }
void PaintEditorPlugin::on_node_removed(Node *node) {
if (_active_node == node) {
_active_node = NULL;
}
}
void PaintEditorPlugin::_notification(int p_what) { void PaintEditorPlugin::_notification(int p_what) {
if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
switch ((int)EditorSettings::get_singleton()->get("editors/paint/editor_side")) { switch ((int)EditorSettings::get_singleton()->get("editors/paint/editor_side")) {
@ -98,9 +117,14 @@ void PaintEditorPlugin::_notification(int p_what) {
CanvasItemEditor::get_singleton()->move_control_to_right_panel(_sidebar); CanvasItemEditor::get_singleton()->move_control_to_right_panel(_sidebar);
} break; } break;
} }
} else if (p_what == NOTIFICATION_READY) {
if (!get_tree()->is_connected("node_removed", this, "on_node_removed")) {
get_tree()->connect("node_removed", this, "on_node_removed");
}
} }
} }
void PaintEditorPlugin::_bind_methods() { void PaintEditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_sidebar"), &PaintEditorPlugin::get_sidebar); ClassDB::bind_method(D_METHOD("get_sidebar"), &PaintEditorPlugin::get_sidebar);
ClassDB::bind_method(D_METHOD("on_node_removed", "node"), &PaintEditorPlugin::on_node_removed);
} }

View File

@ -29,6 +29,7 @@ SOFTWARE.
class PaintWindow; class PaintWindow;
class Texture; class Texture;
class PaintSidebar; class PaintSidebar;
class PaintNode;
class PaintEditorPlugin : public EditorPlugin { class PaintEditorPlugin : public EditorPlugin {
GDCLASS(PaintEditorPlugin, EditorPlugin); GDCLASS(PaintEditorPlugin, EditorPlugin);
@ -53,11 +54,14 @@ public:
EditorNode *editor; EditorNode *editor;
protected: protected:
void on_node_removed(Node *node);
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
PaintSidebar *_sidebar; PaintSidebar *_sidebar;
PaintNode *_active_node;
}; };
#endif #endif