From 2cea4df4e478d06ff5a9491f9af564a1bd6fdcc4 Mon Sep 17 00:00:00 2001 From: aBlueShadow Date: Fri, 6 Sep 2024 09:21:29 +0200 Subject: [PATCH] fix rotation behavior in tactical and single pilot (#2157) Co-authored-by: aBlueShadow --- src/screens/crew1/singlePilotScreen.cpp | 15 +++++++++------ src/screens/crew1/singlePilotScreen.h | 1 + src/screens/crew4/tacticalScreen.cpp | 11 +++++++---- src/screens/crew4/tacticalScreen.h | 1 + 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/screens/crew1/singlePilotScreen.cpp b/src/screens/crew1/singlePilotScreen.cpp index c9ed8c5e73..08c941d08b 100644 --- a/src/screens/crew1/singlePilotScreen.cpp +++ b/src/screens/crew1/singlePilotScreen.cpp @@ -50,19 +50,22 @@ SinglePilotScreen::SinglePilotScreen(GuiContainer* owner) radar->setRangeIndicatorStepSize(1000.0)->shortRange()->enableGhostDots()->enableWaypoints()->enableCallsigns()->enableHeadingIndicators()->setStyle(GuiRadarView::Circular); radar->setCallbacks( [this](sp::io::Pointer::Button button, glm::vec2 position) { + auto last_target = targets.get(); targets.setToClosestTo(position, 250, TargetsContainer::Targetable); - if (my_spaceship && targets.get()) + if (my_spaceship && targets.get() && (targets.get() != last_target)) my_spaceship->commandSetTarget(targets.get()); else if (my_spaceship) my_spaceship->commandTargetRotation(vec2ToAngle(position - my_spaceship->getPosition())); }, - [](glm::vec2 position) { - if (my_spaceship) + [this](glm::vec2 position) { + targets.setToClosestTo(position, 250, TargetsContainer::Targetable); + if (my_spaceship && !targets.get()) + drag_rotate=true; + if (drag_rotate) my_spaceship->commandTargetRotation(vec2ToAngle(position - my_spaceship->getPosition())); }, - [](glm::vec2 position) { - if (my_spaceship) - my_spaceship->commandTargetRotation(vec2ToAngle(position - my_spaceship->getPosition())); + [this](glm::vec2 position) { + drag_rotate=false; } ); radar->setAutoRotating(PreferencesManager::get("single_pilot_radar_lock","0")=="1"); diff --git a/src/screens/crew1/singlePilotScreen.h b/src/screens/crew1/singlePilotScreen.h index a6885c8acc..085fcf4309 100644 --- a/src/screens/crew1/singlePilotScreen.h +++ b/src/screens/crew1/singlePilotScreen.h @@ -31,6 +31,7 @@ class SinglePilotScreen : public GuiOverlay GuiRotationDial* missile_aim; GuiMissileTubeControls* tube_controls; GuiToggleButton* lock_aim; + bool drag_rotate; public: SinglePilotScreen(GuiContainer* owner); diff --git a/src/screens/crew4/tacticalScreen.cpp b/src/screens/crew4/tacticalScreen.cpp index 232ecdc17d..118ff35673 100644 --- a/src/screens/crew4/tacticalScreen.cpp +++ b/src/screens/crew4/tacticalScreen.cpp @@ -45,19 +45,22 @@ TacticalScreen::TacticalScreen(GuiContainer* owner) // Control targeting and piloting with radar interactions. radar->setCallbacks( [this](sp::io::Pointer::Button button, glm::vec2 position) { + auto last_target = targets.get(); targets.setToClosestTo(position, 250, TargetsContainer::Targetable); - if (my_spaceship && targets.get()) + if (my_spaceship && targets.get() && (targets.get() != last_target)) my_spaceship->commandSetTarget(targets.get()); else if (my_spaceship) my_spaceship->commandTargetRotation(vec2ToAngle(position - my_spaceship->getPosition())); }, [this](glm::vec2 position) { - if (my_spaceship) + targets.setToClosestTo(position, 250, TargetsContainer::Targetable); + if (my_spaceship && !targets.get()) + drag_rotate=true; + if (drag_rotate) my_spaceship->commandTargetRotation(vec2ToAngle(position - my_spaceship->getPosition())); }, [this](glm::vec2 position) { - if (my_spaceship) - my_spaceship->commandTargetRotation(vec2ToAngle(position - my_spaceship->getPosition())); + drag_rotate=false; } ); radar->setAutoRotating(PreferencesManager::get("tactical_radar_lock","0")=="1"); diff --git a/src/screens/crew4/tacticalScreen.h b/src/screens/crew4/tacticalScreen.h index 0de345d1be..a90574a02a 100644 --- a/src/screens/crew4/tacticalScreen.h +++ b/src/screens/crew4/tacticalScreen.h @@ -28,6 +28,7 @@ class TacticalScreen : public GuiOverlay GuiRotationDial* missile_aim; GuiMissileTubeControls* tube_controls; GuiToggleButton* lock_aim; + bool drag_rotate; public: TacticalScreen(GuiContainer* owner);