Fix EditorInput not called on non-mouse events

main
copygirl 3 months ago
parent 5c1b66d8a6
commit 921f9685c1
  1. 15
      addons/terrain-editing/terrain_editing_plugin.gd
  2. 6
      terrain/Terrain+Editing.cs

@ -17,6 +17,8 @@ func _make_visible(visible: bool) -> void:
remove_control_from_container(CONTAINER, controls)
func _forward_3d_gui_input(camera: Camera3D, event: InputEvent) -> int:
var position := Vector3.ZERO
if event is InputEventMouse:
var previous_terrain := current_terrain
current_terrain = null
@ -33,17 +35,18 @@ func _forward_3d_gui_input(camera: Camera3D, event: InputEvent) -> int:
var result := space.intersect_ray(query)
var terrain := result.get("collider") as StaticBody3D
if is_terrain(terrain):
# Allow terrain access to editor undo redo functionality.
terrain.EditorUndoRedo = get_undo_redo()
if terrain.EditorInput(event, result["position"], controls):
return AFTER_GUI_INPUT_STOP
current_terrain = terrain
return AFTER_GUI_INPUT_PASS
position = result["position"]
if previous_terrain and previous_terrain != current_terrain:
previous_terrain.EditorUnfocus()
if current_terrain:
# Allow terrain access to editor undo redo functionality.
current_terrain.EditorUndoRedo = get_undo_redo()
if current_terrain.EditorInput(event, controls, position):
return AFTER_GUI_INPUT_STOP
return AFTER_GUI_INPUT_PASS
func is_terrain(object: Object) -> bool:

@ -24,10 +24,14 @@ public partial class Terrain
};
}
public bool EditorInput(InputEventMouse ev, Vector3 position, Control controls)
Vector3 _lastPosition;
public bool EditorInput(InputEvent ev, Control controls, Vector3 maybePos)
{
var prevent_default = false;
// If 'maybePosition' is Vector3.Zero, use previous know position, otherwise update.
var position = (maybePos == Vector3.Zero) ? _lastPosition : (_lastPosition = maybePos);
var toolMode = (ToolMode)(int)controls.Get("tool_mode");
var toolShape = (ToolShape)(int)controls.Get("tool_shape");
var texture = (int)controls.Get("texture");

Loading…
Cancel
Save