Skip to content
Snippets Groups Projects
Commit 0c596b42 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Merge branch 'main' into dev

parents dccc375a e81ca499
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,14 @@
#include <GlobalConstants.hpp>
#include <InputEventMouseMotion.hpp>
#include <InputEventMouseButton.hpp>
#include <Control.hpp>
#include <SceneTree.hpp>
void
avi::scene::PlayfulControlScheme::_register_methods()
{
register_method("_ready", &PlayfulControlScheme::_ready);
register_method("_input", &PlayfulControlScheme::_input);
register_method("_unhandled_input", &PlayfulControlScheme::_unhandled_input);
register_method("_process", &PlayfulControlScheme::_process);
}
......@@ -21,6 +23,7 @@ void
avi::scene::PlayfulControlScheme::_init()
{
viewCamera = nullptr;
gui = nullptr;
scrollValue = 0.0f;
}
......@@ -31,7 +34,7 @@ avi::scene::PlayfulControlScheme::_ready()
}
void
avi::scene::PlayfulControlScheme::_input(godot::InputEvent* event)
avi::scene::PlayfulControlScheme::_unhandled_input(godot::InputEvent* event)
{
if (!this->viewCamera) return;
......@@ -87,6 +90,11 @@ avi::scene::PlayfulControlScheme::_process(float delta)
attachment->rotate_object_local({1, 0, 0}, oldMouseDelta.y * delta * -1.0f);
}
// To prevent moving while typing, we check if any gui element has focus.
// This is not ideal (using just unhandled input would be better), but accumulating the unhandled input is not as smooth.
auto* focus = gui->get_focus_owner();
if (focus) return;
godot::Vector3 movement;
if (input->is_action_pressed("avi_camera_forward"))
movement += {0, 0, -1};
......@@ -132,6 +140,8 @@ avi::scene::PlayfulControlScheme::takeOver(avi::scene::ViewCamera* viewCamera)
viewCamera->set_transform(godot::Transform());
attachment->add_child(viewCamera);
if (!gui) gui = get_tree()->get_root()->get_node<godot::Control>("Root/GUI");
}
void
......
......@@ -21,7 +21,7 @@ namespace avi::scene
void _process(float delta);
void _input(godot::InputEvent* event);
void _unhandled_input(godot::InputEvent* event);
public:
void takeOver(avi::scene::ViewCamera* viewCamera) override;
......@@ -44,6 +44,8 @@ namespace avi::scene
void doTravel(float delta);
private:
godot::Control* gui;
struct Travel
{
godot::Transform startTransform{};
......
......@@ -12,7 +12,7 @@ void
avi::scene::TechnicalControlScheme::_register_methods()
{
register_method("_ready", &TechnicalControlScheme::_ready);
register_method("_input", &TechnicalControlScheme::_input);
register_method("_unhandled_input", &TechnicalControlScheme::_unhandled_input);
register_method("_process", &TechnicalControlScheme::_process);
}
......@@ -39,7 +39,7 @@ avi::scene::TechnicalControlScheme::_ready()
}
void
avi::scene::TechnicalControlScheme::_input(godot::InputEvent* event)
avi::scene::TechnicalControlScheme::_unhandled_input(godot::InputEvent* event)
{
auto* mouseMotionEvent = cast_to<godot::InputEventMouseMotion>(event);
if (mouseMotionEvent)
......@@ -81,6 +81,12 @@ avi::scene::TechnicalControlScheme::_process(float delta)
if (!isActive())
return;
if (isTraveling)
{
doTravel(delta);
return;
}
godot::Input* input = godot::Input::get_singleton();
// Whether the camera should be moved in any way
......@@ -88,12 +94,6 @@ avi::scene::TechnicalControlScheme::_process(float delta)
// Whether the camera should use alternative movement (e.g. move anchor instead of around anchor)
bool alternative = input->is_action_pressed("avi_camera_alt");
if (isTraveling)
{
doTravel(delta);
return;
}
if (moveCamera)
{
if (!alternative)
......
......@@ -20,7 +20,7 @@ namespace avi::scene
void _ready();
void _input(godot::InputEvent* event);
void _unhandled_input(godot::InputEvent* event);
void _process(float delta);
......
extends ViewportContainer
func _input(event):
get_node("3D").input(event)
func _unhandled_input(event):
get_node("3D").unhandled_input(event)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment