Skip to content

Commit

Permalink
Make Ctrl-clicking select the set-speed target.
Browse files Browse the repository at this point in the history
  • Loading branch information
ecraven committed Aug 14, 2017
1 parent 90944a1 commit bf9266e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
26 changes: 20 additions & 6 deletions data/pigui/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions src/LuaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player>::CheckFromLua(1);
Body *target = LuaObject<Body>::GetFromLua(2);
p->SetSetSpeedTarget(target);
return 0;
}

/*
* Method: GetCombatTarget
*
Expand Down Expand Up @@ -553,10 +561,11 @@ template <> void LuaObject<Player>::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 },
Expand Down
7 changes: 7 additions & 0 deletions src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ void Player::SetNavTarget(Body* const target, bool setSpeedTo)
static_cast<PlayerShipController*>(m_controller)->SetNavTarget(target, setSpeedTo);
Pi::onPlayerChangeTarget.emit();
}

void Player::SetSetSpeedTarget(Body* const target)
{
static_cast<PlayerShipController*>(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) {
Expand Down
1 change: 1 addition & 0 deletions src/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/ShipController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/ShipController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> onRotationDampingChanged;

Expand Down

0 comments on commit bf9266e

Please sign in to comment.