Skip to content

Commit

Permalink
fix rotation behavior in tactical and single pilot (#2157)
Browse files Browse the repository at this point in the history
Co-authored-by: aBlueShadow <falter@mxdreamer>
  • Loading branch information
aBlueShadow and aBlueShadow authored Sep 6, 2024
1 parent 405e499 commit 2cea4df
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/screens/crew1/singlePilotScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/screens/crew1/singlePilotScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SinglePilotScreen : public GuiOverlay
GuiRotationDial* missile_aim;
GuiMissileTubeControls* tube_controls;
GuiToggleButton* lock_aim;
bool drag_rotate;
public:
SinglePilotScreen(GuiContainer* owner);

Expand Down
11 changes: 7 additions & 4 deletions src/screens/crew4/tacticalScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/screens/crew4/tacticalScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TacticalScreen : public GuiOverlay
GuiRotationDial* missile_aim;
GuiMissileTubeControls* tube_controls;
GuiToggleButton* lock_aim;
bool drag_rotate;
public:
TacticalScreen(GuiContainer* owner);

Expand Down

0 comments on commit 2cea4df

Please sign in to comment.