Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some things with regards to the sector map #4906

Merged
merged 3 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,10 @@
"description": "",
"message": "No missions."
},
"NO_VALID_ROUTE": {
"description": "Message in the sector map, issued by the autoroute function.",
"message": "No valid route to the selected system."
},
"N_LIGHT_YEARS_N_MAX": {
"description": "",
"message": "{range} light years ({maxRange} max)"
Expand Down
25 changes: 25 additions & 0 deletions data/pigui/libs/message-box.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Copyright © 2008-2020 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local ui = require 'pigui'
local ModalWindow = require 'pigui.libs.modal-win'

local OK_BUTTON_WIDTH = 100

local msgbox = {}

msgbox.OK = function(msg)
ModalWindow.New('PopupMessageBox', function(self)
ui.text(msg)
local width = ui.getContentRegion().x
if width > OK_BUTTON_WIDTH then
ui.dummy(Vector2((width - OK_BUTTON_WIDTH) / 2, 0))
ui.sameLine()
end
if ui.button("OK", Vector2(OK_BUTTON_WIDTH, 0)) then
self:close()
end
end):open()
end

return msgbox
17 changes: 15 additions & 2 deletions data/pigui/modules/hyperjump-planner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local lc = Lang.GetResource("core")
local lui = Lang.GetResource("ui-core");

local ui = require 'pigui'
local mb = require 'pigui.libs.message-box'

local player = nil
local colors = ui.theme.colors
Expand Down Expand Up @@ -176,6 +177,7 @@ local function updateHyperspaceTarget()
sectorView:SetHyperspaceTarget(hyperjump_route[1].path)
else
sectorView:ResetHyperspaceTarget()
selected_jump = nil
end
end

Expand Down Expand Up @@ -225,14 +227,18 @@ local function showJumpRoute()
mainButton(icons.retrograde_thin, lui.CLEAR_ROUTE,
function()
sectorView:ClearRoute()
selected_jump = nil
updateHyperspaceTarget()
end)
ui.sameLine()

mainButton(icons.hyperspace, lui.AUTO_ROUTE,
function()
sectorView:AutoRoute()
local result = sectorView:AutoRoute()
if result == "NO_DRIVE" then
mb.OK(lui.NO_DRIVE)
elseif result == "NO_VALID_ROUTE" then
mb.OK(lui.NO_VALID_ROUTE)
end
updateHyperspaceTarget()
end)
ui.sameLine()
Expand Down Expand Up @@ -361,4 +367,11 @@ function hyperJumpPlanner.onEnterSystem(ship)
updateHyperspaceTarget()
end

function hyperJumpPlanner.onGameEnd(ship)
-- clear the route out so it doesn't show up if the user starts a new game
sectorView:ClearRoute()
-- also clear the route list, saved in this module
buildJumpRouteList()
end

return hyperJumpPlanner
74 changes: 40 additions & 34 deletions data/pigui/modules/map-sector-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ function Windows.systemInfo.Show()
local starsystem = systempath:GetStarSystem()
local clicked = false
ui.withID(label, function()
local jumpData = ""
if not current_systempath:IsSameSystem(systempath) then
local jumpStatus, distance, fuelRequired, duration = player:GetHyperspaceDetails(current_systempath, systempath)
jumpData = jumpStatus .. " " .. string.format("%.2f", distance) .. lc.UNIT_LY .. " " .. fuelRequired .. lc.UNIT_TONNES .. " " .. ui.Format.Duration(duration, 2)
end
-- selected system label
textIcon(icons.info)
ui.sameLine()
ui.text(starsystem.name .. " (" .. math.floor(systempath.sectorX) .. ", " .. math.floor(systempath.sectorY) .. ", " .. math.floor(systempath.sectorZ) .. ")")
Expand All @@ -119,14 +115,47 @@ function Windows.systemInfo.Show()
sectorView:GotoSystemPath(systempath)
end
end
-- selected system alternative labels
if next(starsystem.other_names) ~= nil then
ui.pushTextWrapPos(ui.getContentRegion().x)
ui.textWrapped(table.concat(starsystem.other_names, ", "))
ui.popTextWrapPos()
end
-- jump data
if not current_systempath:IsSameSystem(systempath) then
ui.separator()
ui.text(jumpData)
local jumpStatus, distance, fuelRequired, duration = player:GetHyperspaceDetails(current_systempath, systempath)
ui.text(jumpStatus .. " " .. string.format("%.2f", distance) .. lc.UNIT_LY .. " " .. fuelRequired .. lc.UNIT_TONNES .. " " .. ui.Format.Duration(duration, 2))
end
-- description
ui.pushTextWrapPos(ui.getContentRegion().x)
ui.textWrapped(starsystem.shortDescription)
ui.popTextWrapPos()
ui.separator()
local stars = starsystem:GetStars()
-- number of stars
local numstars = starsystem.numberOfStars
local numstarstext = ""
if numstars == 4 then
numstarstext = lc.QUADRUPLE_SYSTEM
elseif numstars == 3 then
numstarstext = lc.TRIPLE_SYSTEM
elseif numstars == 2 then
numstarstext = lc.BINARY_SYSTEM
else
numstarstext = starsystem.rootSystemBody.astroDescription
end
ui.text(numstarstext)
-- star list
local stars = starsystem:GetJumpable()
for _,star in pairs(stars) do
if ui.selectable(star.name, star.path == systempath, {}) then
local pos = ui.getCursorPos() + Vector2(0, 1) -- add vertical alignment, not quite necessary
if ui.selectable("## " .. star.name, star.path == systempath, {}) then
clicked = star.path
end
ui.setCursorPos(pos)
textIcon(icons.sun)
ui.sameLine()
ui.text(star.name)
end
if clicked then
sectorView:SwitchToPath(clicked)
Expand All @@ -138,25 +167,6 @@ function Windows.systemInfo.Show()
hyperJumpPlanner.updateInRoute(systempath)
prevSystemPath = systempath
end

local numstars = starsystem.numberOfStars
local numstarstext = ""
if numstars == 4 then
numstarstext = lc.QUADRUPLE_SYSTEM
elseif numstars == 3 then
numstarstext = lc.TRIPLE_SYSTEM
elseif numstars == 2 then
numstarstext = lc.BINARY_SYSTEM
else
numstarstext = starsystem.rootSystemBody.astroDescription
end
ui.text(numstarstext)
if next(starsystem.other_names) ~= nil then
ui.text(table.concat(starsystem.other_names, ", "))
end
ui.pushTextWrapPos(ui.getContentRegion().x)
ui.textWrapped(starsystem.shortDescription)
ui.popTextWrapPos()
end)
end
end
Expand Down Expand Up @@ -268,8 +278,8 @@ function Windows.searchBar.Show()
ui.text(lc.SEARCH)
search_text, changed = ui.inputText("", search_text, {})
if search_text ~= "" then
local parsedSystem = SystemPath.ParseString(search_text)
if parsedSystem ~= nil then
local parsedSystem = changed and SystemPath.ParseString(search_text)
if parsedSystem and parsedSystem ~= nil then
sectorView:GotoSectorPath(parsedSystem)
else
local systempaths = sectorView:SearchNearbyStarSystemsByName(search_text)
Expand Down Expand Up @@ -416,11 +426,7 @@ Event.Register("onLeaveSystem", function()
hyperspaceDetailsCache = {}
end)
-- events moved from hyperJumpPlanner
Event.Register("onGameEnd",
function(ship)
-- clear the route out so it doesn't show up if the user starts a new game
sectorView:ClearRoute()
end)
Event.Register("onGameEnd", hyperJumpPlanner.onGameEnd)
Event.Register("onEnterSystem", hyperJumpPlanner.onEnterSystem)
Event.Register("onShipEquipmentChanged", hyperJumpPlanner.onShipEquipmentChanged)

Expand Down
41 changes: 15 additions & 26 deletions src/SectorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void SectorView::SetSelected(const SystemPath &path)
m_selected = path;
else if (path.IsSystemPath()) {
RefCountedPtr<StarSystem> system = m_galaxy->GetStarSystem(path);
m_selected = system->GetStars()[CheckIndexInRoute(path)]->GetPath();
m_selected = CheckPathInRoute(system->GetStars()[0]->GetPath());
}
}

Expand All @@ -378,34 +378,18 @@ void SectorView::SwitchToPath(const SystemPath &path)
GotoSystem(path);
}

void SectorView::SwapSelectedHyperspaceTarget()
{
SystemPath tmpTarget = GetHyperspaceTarget();
SetHyperspaceTarget(GetSelected());
if (m_automaticSystemSelection) {
GotoSystem(tmpTarget);
} else {
RefCountedPtr<StarSystem> system = m_galaxy->GetStarSystem(tmpTarget);
SetSelected(system->GetStars()[CheckIndexInRoute(tmpTarget)]->GetPath());
}
}

void SectorView::OnClickSystem(const SystemPath &path)
{
SwitchToPath(path);
}

// check the route, maybe this system is there, then we'll take star number from there
// if single system, bodyindex = 0; if multisystem, bodyindex = (0 or 1),2 ...
int SectorView::CheckIndexInRoute(const SystemPath &path)
// check the route, maybe this system is there, then we'll take the path from the route
const SystemPath &SectorView::CheckPathInRoute(const SystemPath &path)
{
for (auto &p : m_route)
if (p.IsSameSystem(path)) {
if (p.bodyIndex > 0)
return p.bodyIndex - 1;
return 0;
}
return 0;
for (const auto &p : m_route)
if (p.IsSameSystem(path))
return p;
return path;
}

void SectorView::PutSystemLabels(RefCountedPtr<Sector> sec, const vector3f &origin, int drawRadius)
Expand Down Expand Up @@ -636,13 +620,16 @@ std::vector<SystemPath> SectorView::GetRoute()
return m_route;
}

void SectorView::AutoRoute(const SystemPath &start, const SystemPath &target, std::vector<SystemPath> &outRoute) const
const std::string SectorView::AutoRoute(const SystemPath &start, const SystemPath &target, std::vector<SystemPath> &outRoute) const
{
const RefCountedPtr<const Sector> start_sec = m_galaxy->GetSector(start);
const RefCountedPtr<const Sector> target_sec = m_galaxy->GetSector(target);

LuaRef try_hdrive = LuaObject<Player>::CallMethod<LuaRef>(Pi::player, "GetEquip", "engine", 1);
if (try_hdrive.IsNil())
return "NO_DRIVE";
// Get the player's hyperdrive from Lua, later used to calculate the duration between systems
const ScopedTable hyperdrive = ScopedTable(LuaObject<Player>::CallMethod<LuaRef>(Pi::player, "GetEquip", "engine", 1));
const ScopedTable hyperdrive = ScopedTable(try_hdrive);
// Cache max range so it doesn't get recalculated every time we call GetDuration
const float max_range = hyperdrive.CallMethod<float>("GetMaximumRange", Pi::player);

Expand Down Expand Up @@ -764,7 +751,9 @@ void SectorView::AutoRoute(const SystemPath &start, const SystemPath &target, st
u = path_prev[u];
}
std::reverse(std::begin(outRoute), std::end(outRoute));
return "OKAY";
}
return "NO_VALID_ROUTE";
}

void SectorView::DrawRouteLines(const vector3f &playerAbsPos, const matrix4x4f &trans)
Expand Down Expand Up @@ -1160,7 +1149,7 @@ void SectorView::Update()

if (!m_selected.IsSameSystem(new_selected)) {
RefCountedPtr<StarSystem> system = m_galaxy->GetStarSystem(new_selected);
SetSelected(system->GetStars()[CheckIndexInRoute(new_selected)]->GetPath());
SetSelected(CheckPathInRoute(system->GetStars()[0]->GetPath()));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/SectorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class SectorView : public UIView, public DeleteEmitter {
void GotoCurrentSystem() { GotoSystem(m_current); }
void GotoSelectedSystem() { GotoSystem(m_selected); }
void GotoHyperspaceTarget() { GotoSystem(m_hyperspaceTarget); }
void SwapSelectedHyperspaceTarget();
bool IsCenteredOn(const SystemPath &path);
void SaveToJson(Json &jsonObj) override;

Expand Down Expand Up @@ -76,7 +75,7 @@ class SectorView : public UIView, public DeleteEmitter {
bool RemoveRouteItem(const std::vector<SystemPath>::size_type element);
void ClearRoute();
std::vector<SystemPath> GetRoute();
void AutoRoute(const SystemPath &start, const SystemPath &target, std::vector<SystemPath> &outRoute) const;
const std::string AutoRoute(const SystemPath &start, const SystemPath &target, std::vector<SystemPath> &outRoute) const;
void SetDrawRouteLines(bool value) { m_drawRouteLines = value; }

static struct InputBinding : public Input::InputFrame {
Expand Down Expand Up @@ -131,7 +130,7 @@ class SectorView : public UIView, public DeleteEmitter {
void AddStarBillboard(const matrix4x4f &modelview, const vector3f &pos, const Color &col, float size);

void OnClickSystem(const SystemPath &path);
int CheckIndexInRoute(const SystemPath &path);
const SystemPath &CheckPathInRoute(const SystemPath &path);

RefCountedPtr<Sector> GetCached(const SystemPath &loc) { return m_sectorCache->GetCached(loc); }
void ShrinkCache();
Expand Down
2 changes: 1 addition & 1 deletion src/SystemInfoView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void SystemInfoView::OnBodySelected(SystemBody *b)
Body *body = m_game->GetSpace()->FindBodyForPath(&path);
if (body != 0)
Pi::player->SetNavTarget(body);
} else if (b->GetSuperType() == SystemBody::SUPERTYPE_STAR) { // We allow hyperjump to any star of the system
} else if (b->IsJumpable()) {
m_game->GetSectorView()->SwitchToPath(path);
}
}
Expand Down
Loading