diff --git a/data/pigui/game.lua b/data/pigui/game.lua index f5acc921aae..7624dfc98e7 100644 --- a/data/pigui/game.lua +++ b/data/pigui/game.lua @@ -697,7 +697,7 @@ local function displayOnScreenObjects() -- if the navtarget is one of the collapsed ones, it's the most important table.insert(v.others, v.mainBody) v.mainBody = it - v.hasNavTarget = true + v.hasNavTarget = itbody == navTarget v.multiple = true else -- otherwise, just add it as a further body @@ -731,13 +731,13 @@ local function displayOnScreenObjects() end local mp = ui.getMousePos() -- click handler - if (Vector(mp.x,mp.y) - coords):magnitude() < iconsize then + if (Vector(mp.x,mp.y) - coords):magnitude() < iconsize * 1.5 then if not ui.isMouseHoveringAnyWindow() and ui.isMouseReleased(0) then - if v.hasNavTarget and ui.ctrlHeld() then - -- if ctrl-clicked and has nav target, unset nav target + if v.hasNavTarget then + -- if clicked and has nav target, unset nav target player:SetNavTarget(nil) - elseif v.hasCombatTarget and ui.ctrlHeld() then - -- if ctlr-clicked and has combat target, unset combat target + elseif v.hasCombatTarget then + -- if clicked and has combat target, unset combat target player:SetCombatTarget(nil) else if v.multiple then @@ -746,6 +746,13 @@ local function displayOnScreenObjects() else -- clicked on single, just set navtarget/combatTarget setTarget(v.mainBody.body) + if ui.ctrlHeld() then + local target = v.mainBody.body + if target == player:GetSetSpeedTarget() then + target = nil + end + player:SetSetSpeedTarget(target) + end end end end @@ -757,6 +764,13 @@ local function displayOnScreenObjects() ui.sameLine() if ui.selectable(v.mainBody.label, v.mainBody.body == navTarget, {}) then player:SetNavTarget(v.mainBody.body) + if ui.ctrlHeld() then + local target = v.mainBody.body + if target == player:GetSetSpeedTarget() then + target = nil + end + player:SetSetSpeedTarget(target) + end end for k,v in pairs(v.others) do ui.icon(getBodyIcon(v.body), size, colors.frame) diff --git a/src/LuaPlayer.cpp b/src/LuaPlayer.cpp index 2eef3827494..46a2725e7d0 100644 --- a/src/LuaPlayer.cpp +++ b/src/LuaPlayer.cpp @@ -78,6 +78,14 @@ static int l_set_nav_target(lua_State *l) return 0; } +static int l_set_set_speed_target(lua_State *l) +{ + Player *p = LuaObject::CheckFromLua(1); + Body *target = LuaObject::GetFromLua(2); + p->SetSetSpeedTarget(target); + return 0; +} + /* * Method: GetCombatTarget * @@ -553,10 +561,11 @@ template <> void LuaObject::RegisterClass() static const luaL_Reg l_methods[] = { { "IsPlayer", l_player_is_player }, - { "GetNavTarget", l_get_nav_target }, - { "SetNavTarget", l_set_nav_target }, - { "GetCombatTarget", l_get_combat_target }, - { "SetCombatTarget", l_set_combat_target }, + { "GetNavTarget", l_get_nav_target }, + { "SetNavTarget", l_set_nav_target }, + { "SetSetSpeedTarget", l_set_set_speed_target }, + { "GetCombatTarget", l_get_combat_target }, + { "SetCombatTarget", l_set_combat_target }, { "GetHyperspaceTarget", l_get_hyperspace_target }, { "SetHyperspaceTarget", l_set_hyperspace_target }, { "GetDistanceToZeroV", l_get_distance_to_zero_v }, diff --git a/src/Player.cpp b/src/Player.cpp index e77dce9854c..77b907836af 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -239,6 +239,13 @@ void Player::SetNavTarget(Body* const target, bool setSpeedTo) static_cast(m_controller)->SetNavTarget(target, setSpeedTo); Pi::onPlayerChangeTarget.emit(); } + +void Player::SetSetSpeedTarget(Body* const target) +{ + static_cast(m_controller)->SetSetSpeedTarget(target); + // TODO: not sure, do we actually need this? we are only changing the set speed target + Pi::onPlayerChangeTarget.emit(); +} //temporary targeting stuff ends Ship::HyperjumpStatus Player::InitiateHyperjumpTo(const SystemPath &dest, int warmup_time, double duration, LuaRef checks) { diff --git a/src/Player.h b/src/Player.h index 761adc9e2be..55270b3e91e 100644 --- a/src/Player.h +++ b/src/Player.h @@ -36,6 +36,7 @@ class Player: public Ship { Body *GetSetSpeedTarget() const; void SetCombatTarget(Body* const target, bool setSpeedTo = false); void SetNavTarget(Body* const target, bool setSpeedTo = false); + void SetSetSpeedTarget(Body* const target); virtual Ship::HyperjumpStatus InitiateHyperjumpTo(const SystemPath &dest, int warmup_time, double duration, LuaRef checks) override; virtual void AbortHyperjump() override; diff --git a/src/ShipController.cpp b/src/ShipController.cpp index e448dcd937e..38f3f76a4b3 100644 --- a/src/ShipController.cpp +++ b/src/ShipController.cpp @@ -433,3 +433,8 @@ void PlayerShipController::SetNavTarget(Body* const target, bool setSpeedTo) m_setSpeedTarget = 0; m_navTarget = target; } + +void PlayerShipController::SetSetSpeedTarget(Body* const target) +{ + m_setSpeedTarget = target; +} diff --git a/src/ShipController.h b/src/ShipController.h index 4b3dc440c2a..5d13f079d7d 100644 --- a/src/ShipController.h +++ b/src/ShipController.h @@ -86,6 +86,7 @@ class PlayerShipController : public ShipController Body *GetSetSpeedTarget() const override; void SetCombatTarget(Body* const target, bool setSpeedTo = false); void SetNavTarget(Body* const target, bool setSpeedTo = false); + void SetSetSpeedTarget(Body* const target); sigc::signal onRotationDampingChanged;