Merge pull request #64465 from TokageItLab/bind-after-gui-input

Bind `AfterGUIInput` to GDScript and update document
This commit is contained in:
Rémi Verschelde 2022-09-10 20:01:48 +02:00 committed by GitHub
commit b52305351d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 25 deletions

View file

@ -64,8 +64,8 @@
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
# Redraw viewport when cursor is moved. # Redraw viewport when cursor is moved.
update_overlays() update_overlays()
return true return EditorPlugin.AFTER_GUI_INPUT_STOP
return false return EditorPlugin.AFTER_GUI_INPUT_PASS
[/gdscript] [/gdscript]
[csharp] [csharp]
public override void _Forward3dDrawOverViewport(Godot.Control overlay) public override void _Forward3dDrawOverViewport(Godot.Control overlay)
@ -74,15 +74,15 @@
overlay.DrawCircle(overlay.GetLocalMousePosition(), 64, Colors.White); overlay.DrawCircle(overlay.GetLocalMousePosition(), 64, Colors.White);
} }
public override bool _Forward3dGuiInput(Godot.Camera3D camera, InputEvent @event) public override EditorPlugin.AfterGUIInput _Forward3dGuiInput(Godot.Camera3D camera, InputEvent @event)
{ {
if (@event is InputEventMouseMotion) if (@event is InputEventMouseMotion)
{ {
// Redraw viewport when cursor is moved. // Redraw viewport when cursor is moved.
UpdateOverlays(); UpdateOverlays();
return true; return EditorPlugin.AFTER_GUI_INPUT_STOP;
} }
return false; return EditorPlugin.AFTER_GUI_INPUT_PASS;
[/csharp] [/csharp]
[/codeblocks] [/codeblocks]
</description> </description>
@ -100,33 +100,33 @@
<param index="0" name="viewport_camera" type="Camera3D" /> <param index="0" name="viewport_camera" type="Camera3D" />
<param index="1" name="event" type="InputEvent" /> <param index="1" name="event" type="InputEvent" />
<description> <description>
Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 3D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [param event], otherwise forwards [param event] to other Editor classes. Example: Called when there is a root node in the current edited scene, [method _handles] is implemented, and an [InputEvent] happens in the 3D viewport. The return value decides whether the [InputEvent] is consumed or forwarded to other [EditorPlugin]s. See [enum AfterGUIInput] for options. Example:
[codeblocks] [codeblocks]
[gdscript] [gdscript]
# Prevents the InputEvent to reach other Editor classes. # Prevents the InputEvent from reaching other Editor classes.
func _forward_3d_gui_input(camera, event): func _forward_3d_gui_input(camera, event):
return EditorPlugin.AFTER_GUI_INPUT_STOP return EditorPlugin.AFTER_GUI_INPUT_STOP
[/gdscript] [/gdscript]
[csharp] [csharp]
// Prevents the InputEvent to reach other Editor classes. // Prevents the InputEvent from reaching other Editor classes.
public override bool _Forward3dGuiInput(Camera3D camera, InputEvent @event) public override EditorPlugin.AfterGUIInput _Forward3dGuiInput(Camera3D camera, InputEvent @event)
{ {
return EditorPlugin.AFTER_GUI_INPUT_STOP; return EditorPlugin.AFTER_GUI_INPUT_STOP;
} }
[/csharp] [/csharp]
[/codeblocks] [/codeblocks]
Must [code]return false[/code] in order to forward the [InputEvent] to other Editor classes. Example: Must [code]return EditorPlugin.AFTER_GUI_INPUT_PASS[/code] in order to forward the [InputEvent] to other Editor classes. Example:
[codeblocks] [codeblocks]
[gdscript] [gdscript]
# Consumes InputEventMouseMotion and forwards other InputEvent types. # Consumes InputEventMouseMotion and forwards other InputEvent types.
func _forward_3d_gui_input(camera, event): func _forward_3d_gui_input(camera, event):
return event is InputEventMouseMotion return EditorPlugin.AFTER_GUI_INPUT_STOP if event is InputEventMouseMotion else EditorPlugin.AFTER_GUI_INPUT_PASS
[/gdscript] [/gdscript]
[csharp] [csharp]
// Consumes InputEventMouseMotion and forwards other InputEvent types. // Consumes InputEventMouseMotion and forwards other InputEvent types.
public override bool _Forward3dGuiInput(Camera3D camera, InputEvent @event) public override EditorPlugin.AfterGUIInput _Forward3dGuiInput(Camera3D camera, InputEvent @event)
{ {
return @event is InputEventMouseMotion; return @event is InputEventMouseMotion ? EditorPlugin.AFTER_GUI_INPUT_STOP : EditorPlugin.AFTER_GUI_INPUT_PASS;
} }
[/csharp] [/csharp]
[/codeblocks] [/codeblocks]
@ -185,12 +185,12 @@
Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 2D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [param event], otherwise forwards [param event] to other Editor classes. Example: Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 2D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [param event], otherwise forwards [param event] to other Editor classes. Example:
[codeblocks] [codeblocks]
[gdscript] [gdscript]
# Prevents the InputEvent to reach other Editor classes. # Prevents the InputEvent from reaching other Editor classes.
func _forward_canvas_gui_input(event): func _forward_canvas_gui_input(event):
return true return true
[/gdscript] [/gdscript]
[csharp] [csharp]
// Prevents the InputEvent to reach other Editor classes. // Prevents the InputEvent from reaching other Editor classes.
public override bool ForwardCanvasGuiInput(InputEvent @event) public override bool ForwardCanvasGuiInput(InputEvent @event)
{ {
return true; return true;
@ -755,5 +755,14 @@
<constant name="DOCK_SLOT_MAX" value="8" enum="DockSlot"> <constant name="DOCK_SLOT_MAX" value="8" enum="DockSlot">
Represents the size of the [enum DockSlot] enum. Represents the size of the [enum DockSlot] enum.
</constant> </constant>
<constant name="AFTER_GUI_INPUT_PASS" value="0" enum="AfterGUIInput">
Forwards the [InputEvent] to other EditorPlugins.
</constant>
<constant name="AFTER_GUI_INPUT_STOP" value="1" enum="AfterGUIInput">
Prevents the [InputEvent] from reaching other Editor classes.
</constant>
<constant name="AFTER_GUI_INPUT_CUSTOM" value="2" enum="AfterGUIInput">
Pass the [InputEvent] to other editor plugins except the main [Node3D] one. This can be used to prevent node selection changes and work with sub-gizmos instead.
</constant>
</constants> </constants>
</class> </class>

View file

@ -7601,8 +7601,8 @@ EditorPlugin::AfterGUIInput EditorPluginList::forward_spatial_gui_input(Camera3D
if (current_after == EditorPlugin::AFTER_GUI_INPUT_STOP) { if (current_after == EditorPlugin::AFTER_GUI_INPUT_STOP) {
after = EditorPlugin::AFTER_GUI_INPUT_STOP; after = EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
if (after != EditorPlugin::AFTER_GUI_INPUT_STOP && current_after == EditorPlugin::AFTER_GUI_INPUT_DESELECT) { if (after != EditorPlugin::AFTER_GUI_INPUT_STOP && current_after == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
after = EditorPlugin::AFTER_GUI_INPUT_DESELECT; after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
} }
} }

View file

@ -972,6 +972,10 @@ void EditorPlugin::_bind_methods() {
BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UR); BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UR);
BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BR); BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BR);
BIND_ENUM_CONSTANT(DOCK_SLOT_MAX); BIND_ENUM_CONSTANT(DOCK_SLOT_MAX);
BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_PASS);
BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_STOP);
BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_CUSTOM);
} }
Ref<EditorUndoRedoManager> EditorPlugin::get_undo_redo() { Ref<EditorUndoRedoManager> EditorPlugin::get_undo_redo() {

View file

@ -204,7 +204,7 @@ public:
enum AfterGUIInput { enum AfterGUIInput {
AFTER_GUI_INPUT_PASS, AFTER_GUI_INPUT_PASS,
AFTER_GUI_INPUT_STOP, AFTER_GUI_INPUT_STOP,
AFTER_GUI_INPUT_DESELECT AFTER_GUI_INPUT_CUSTOM
}; };
//TODO: send a resource for editing to the editor node? //TODO: send a resource for editing to the editor node?
@ -312,6 +312,7 @@ public:
VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer); VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer);
VARIANT_ENUM_CAST(EditorPlugin::DockSlot); VARIANT_ENUM_CAST(EditorPlugin::DockSlot);
VARIANT_ENUM_CAST(EditorPlugin::AfterGUIInput);
typedef EditorPlugin *(*EditorPluginCreateFunc)(); typedef EditorPlugin *(*EditorPluginCreateFunc)();

View file

@ -1360,8 +1360,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (discard == EditorPlugin::AFTER_GUI_INPUT_STOP) { if (discard == EditorPlugin::AFTER_GUI_INPUT_STOP) {
return; return;
} }
if (discard == EditorPlugin::AFTER_GUI_INPUT_DESELECT) { if (discard == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
after = EditorPlugin::AFTER_GUI_INPUT_DESELECT; after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
} }
} }
} }
@ -1373,8 +1373,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (discard == EditorPlugin::AFTER_GUI_INPUT_STOP) { if (discard == EditorPlugin::AFTER_GUI_INPUT_STOP) {
return; return;
} }
if (discard == EditorPlugin::AFTER_GUI_INPUT_DESELECT) { if (discard == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
after = EditorPlugin::AFTER_GUI_INPUT_DESELECT; after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
} }
} }
} }
@ -1601,7 +1601,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
break; break;
} }
if (after != EditorPlugin::AFTER_GUI_INPUT_DESELECT) { if (after != EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
//clicking is always deferred to either move or release //clicking is always deferred to either move or release
clicked = _select_ray(b->get_position()); clicked = _select_ray(b->get_position());
selection_in_progress = true; selection_in_progress = true;
@ -1622,7 +1622,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
break; break;
} }
if (after != EditorPlugin::AFTER_GUI_INPUT_DESELECT) { if (after != EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
selection_in_progress = false; selection_in_progress = false;
if (clicked.is_valid()) { if (clicked.is_valid()) {

View file

@ -1143,7 +1143,7 @@ EditorPlugin::AfterGUIInput Skeleton3DEditorPlugin::forward_spatial_gui_input(Ca
se->update_bone_original(); se->update_bone_original();
} }
} }
return EditorPlugin::AFTER_GUI_INPUT_DESELECT; return EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
} }
return EditorPlugin::AFTER_GUI_INPUT_PASS; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }