EditorPlugin can request user inputs from editor 3d view
This commit is contained in:
parent
d4e64e0e60
commit
d8b65b1657
@ -6069,6 +6069,7 @@ EditorNode::EditorNode() {
|
|||||||
|
|
||||||
editor_plugin_screen = NULL;
|
editor_plugin_screen = NULL;
|
||||||
editor_plugins_over = memnew(EditorPluginList);
|
editor_plugins_over = memnew(EditorPluginList);
|
||||||
|
editor_plugins_force_input_forwarding = memnew(EditorPluginList);
|
||||||
|
|
||||||
//force_top_viewport(true);
|
//force_top_viewport(true);
|
||||||
_edit_current();
|
_edit_current();
|
||||||
@ -6217,6 +6218,7 @@ EditorNode::~EditorNode() {
|
|||||||
memdelete(EditorHelp::get_doc_data());
|
memdelete(EditorHelp::get_doc_data());
|
||||||
memdelete(editor_selection);
|
memdelete(editor_selection);
|
||||||
memdelete(editor_plugins_over);
|
memdelete(editor_plugins_over);
|
||||||
|
memdelete(editor_plugins_force_input_forwarding);
|
||||||
memdelete(file_server);
|
memdelete(file_server);
|
||||||
EditorSettings::destroy();
|
EditorSettings::destroy();
|
||||||
}
|
}
|
||||||
@ -6252,10 +6254,14 @@ bool EditorPluginList::forward_gui_input(const Transform2D &p_canvas_xform, cons
|
|||||||
return discard;
|
return discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorPluginList::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
|
bool EditorPluginList::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled) {
|
||||||
bool discard = false;
|
bool discard = false;
|
||||||
|
|
||||||
for (int i = 0; i < plugins_list.size(); i++) {
|
for (int i = 0; i < plugins_list.size(); i++) {
|
||||||
|
if ((!serve_when_force_input_enabled) && plugins_list[i]->is_input_event_forwarding_always_enabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (plugins_list[i]->forward_spatial_gui_input(p_camera, p_event)) {
|
if (plugins_list[i]->forward_spatial_gui_input(p_camera, p_event)) {
|
||||||
discard = true;
|
discard = true;
|
||||||
}
|
}
|
||||||
@ -6271,6 +6277,10 @@ void EditorPluginList::forward_draw_over_canvas(const Transform2D &p_canvas_xfor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorPluginList::add_plugin(EditorPlugin *p_plugin) {
|
||||||
|
plugins_list.push_back(p_plugin);
|
||||||
|
}
|
||||||
|
|
||||||
bool EditorPluginList::empty() {
|
bool EditorPluginList::empty() {
|
||||||
return plugins_list.empty();
|
return plugins_list.empty();
|
||||||
}
|
}
|
||||||
|
@ -396,6 +396,7 @@ private:
|
|||||||
Vector<EditorPlugin *> editor_plugins;
|
Vector<EditorPlugin *> editor_plugins;
|
||||||
EditorPlugin *editor_plugin_screen;
|
EditorPlugin *editor_plugin_screen;
|
||||||
EditorPluginList *editor_plugins_over;
|
EditorPluginList *editor_plugins_over;
|
||||||
|
EditorPluginList *editor_plugins_force_input_forwarding;
|
||||||
|
|
||||||
EditorHistory editor_history;
|
EditorHistory editor_history;
|
||||||
EditorData editor_data;
|
EditorData editor_data;
|
||||||
@ -641,6 +642,7 @@ public:
|
|||||||
|
|
||||||
EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
|
EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
|
||||||
EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
|
EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
|
||||||
|
EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
|
||||||
PropertyEditor *get_property_editor() { return property_editor; }
|
PropertyEditor *get_property_editor() { return property_editor; }
|
||||||
VBoxContainer *get_property_editor_vb() { return prop_editor_vb; }
|
VBoxContainer *get_property_editor_vb() { return prop_editor_vb; }
|
||||||
|
|
||||||
@ -817,8 +819,9 @@ public:
|
|||||||
void make_visible(bool p_visible);
|
void make_visible(bool p_visible);
|
||||||
void edit(Object *p_object);
|
void edit(Object *p_object);
|
||||||
bool forward_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event);
|
bool forward_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event);
|
||||||
bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
|
bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
|
||||||
void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas);
|
void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas);
|
||||||
|
void add_plugin(EditorPlugin *p_plugin);
|
||||||
void clear();
|
void clear();
|
||||||
bool empty();
|
bool empty();
|
||||||
|
|
||||||
|
@ -147,6 +147,12 @@ void EditorPlugin::remove_tool_menu_item(const String &p_name) {
|
|||||||
//EditorNode::get_singleton()->remove_tool_menu_item(p_name);
|
//EditorNode::get_singleton()->remove_tool_menu_item(p_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorPlugin::set_input_event_forwarding_always_enabled() {
|
||||||
|
input_event_forwarding_always_enabled = true;
|
||||||
|
EditorPluginList *always_input_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding();
|
||||||
|
always_input_forwarding_list->add_plugin(this);
|
||||||
|
}
|
||||||
|
|
||||||
Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {
|
Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {
|
||||||
//??
|
//??
|
||||||
if (get_script_instance() && get_script_instance()->has_method("create_spatial_gizmo")) {
|
if (get_script_instance() && get_script_instance()->has_method("create_spatial_gizmo")) {
|
||||||
@ -372,6 +378,7 @@ void EditorPlugin::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("edit_resource"), &EditorPlugin::edit_resource);
|
ClassDB::bind_method(D_METHOD("edit_resource"), &EditorPlugin::edit_resource);
|
||||||
ClassDB::bind_method(D_METHOD("add_import_plugin"), &EditorPlugin::add_import_plugin);
|
ClassDB::bind_method(D_METHOD("add_import_plugin"), &EditorPlugin::add_import_plugin);
|
||||||
ClassDB::bind_method(D_METHOD("remove_import_plugin"), &EditorPlugin::remove_import_plugin);
|
ClassDB::bind_method(D_METHOD("remove_import_plugin"), &EditorPlugin::remove_import_plugin);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled);
|
||||||
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
|
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
|
||||||
ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_canvas", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "canvas:Control")));
|
ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_canvas", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "canvas:Control")));
|
||||||
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
|
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
|
||||||
@ -414,6 +421,7 @@ void EditorPlugin::_bind_methods() {
|
|||||||
|
|
||||||
EditorPlugin::EditorPlugin() {
|
EditorPlugin::EditorPlugin() {
|
||||||
undo_redo = NULL;
|
undo_redo = NULL;
|
||||||
|
input_event_forwarding_always_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorPlugin::~EditorPlugin() {
|
EditorPlugin::~EditorPlugin() {
|
||||||
|
@ -61,6 +61,8 @@ class EditorPlugin : public Node {
|
|||||||
|
|
||||||
UndoRedo *_get_undo_redo() { return undo_redo; }
|
UndoRedo *_get_undo_redo() { return undo_redo; }
|
||||||
|
|
||||||
|
bool input_event_forwarding_always_enabled;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
UndoRedo &get_undo_redo() { return *undo_redo; }
|
UndoRedo &get_undo_redo() { return *undo_redo; }
|
||||||
@ -106,6 +108,9 @@ public:
|
|||||||
void add_tool_submenu_item(const String &p_name, Object *p_submenu);
|
void add_tool_submenu_item(const String &p_name, Object *p_submenu);
|
||||||
void remove_tool_menu_item(const String &p_name);
|
void remove_tool_menu_item(const String &p_name);
|
||||||
|
|
||||||
|
void set_input_event_forwarding_always_enabled();
|
||||||
|
bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; }
|
||||||
|
|
||||||
virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
|
virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
|
||||||
virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event);
|
virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event);
|
||||||
virtual void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas);
|
virtual void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas);
|
||||||
|
@ -696,12 +696,19 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
|
|||||||
return; //do NONE
|
return; //do NONE
|
||||||
|
|
||||||
{
|
{
|
||||||
|
EditorNode *en = editor;
|
||||||
|
EditorPluginList *force_input_forwarding_list = en->get_editor_plugins_force_input_forwarding();
|
||||||
|
if (!force_input_forwarding_list->empty()) {
|
||||||
|
bool discard = force_input_forwarding_list->forward_spatial_gui_input(camera, p_event, true);
|
||||||
|
if (discard)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
EditorNode *en = editor;
|
EditorNode *en = editor;
|
||||||
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
|
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
|
||||||
|
|
||||||
if (!over_plugin_list->empty()) {
|
if (!over_plugin_list->empty()) {
|
||||||
bool discard = over_plugin_list->forward_spatial_gui_input(camera, p_event);
|
bool discard = over_plugin_list->forward_spatial_gui_input(camera, p_event, false);
|
||||||
if (discard)
|
if (discard)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user