Skip to content

Commit

Permalink
Display economy sidebar widget in System Map
Browse files Browse the repository at this point in the history
- Use sidebar for system overview and economy widgets
- Move current system name to center of map view
- Remove old system overview implementation
  • Loading branch information
Web-eWorks committed Jan 20, 2023
1 parent a54a420 commit 977ad1c
Showing 1 changed file with 82 additions and 35 deletions.
117 changes: 82 additions & 35 deletions data/pigui/modules/system-view-ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ local Vector2 = _G.Vector2
local lc = Lang.GetResource("core")
local luc = Lang.GetResource("ui-core")
local layout = require 'pigui.libs.window-layout'
local Sidebar = require 'pigui.libs.sidebar'

local player = nil
local colors = ui.theme.colors
local icons = ui.theme.icons
local styles = ui.theme.styles

local systemView = Game and Game.systemView -- for hot-reload

Expand Down Expand Up @@ -162,18 +164,20 @@ end
-- all windows in this view
local Windows = {
systemName = layout.NewWindow("SystemMapSystemName"),
systemOverview = layout.NewWindow("SystemMapOverview"),
systemOverviewHidden = layout.NewWindow("SystemOverviewHidden"),
objectInfo = layout.NewWindow("SystemMapObjectIngo"),
edgeButtons = layout.NewWindow("SystemMapEdgeButtons"),
orbitPlanner = layout.NewWindow("SystemMapOrbitPlanner"),
timeButtons = layout.NewWindow("SystemMapTimeButtons"),
unexplored = layout.NewWindow("SystemMapUnexplored")
}

Windows.systemName.style_colors["WindowBg"] = colors.transparent

local systemViewLayout = layout.New(Windows)
systemViewLayout.mainFont = winfont

local leftSidebar = Sidebar.New("##SidebarL", "left")

local systemOverviewWidget = require 'pigui.modules.system-overview-window'.New()
systemOverviewWidget.visible = true

Expand All @@ -185,35 +189,73 @@ function systemOverviewWidget:onBodyDoubleClicked(sBody)
systemView:ViewSelectedObject()
end

function Windows.systemOverview.ShouldShow()
return not Windows.unexplored.visible and systemOverviewWidget.visible
end
table.insert(leftSidebar.modules, {
priority = 1,
side = "left",
showInHyperspace = false,
icon = icons.system_overview,
tooltip = luc.TOGGLE_OVERVIEW_WINDOW,
exclusive = true,

function Windows.systemOverviewHidden.ShouldShow()
return not Windows.unexplored.visible and not systemOverviewWidget.visible
end
drawTitle = function()
if Windows.unexplored.visible then
ui.text(luc.UNEXPLORED_SYSTEM_NO_SYSTEM_VIEW)
else
systemOverviewWidget:displaySidebarTitle(Game.system)
end
end,

function Windows.systemOverview.Show()
local selected = { [systemView:GetSelectedObject().ref or true] = true }
ui.withFont(ui.fonts.pionillium.medium, function()
if ui.mainMenuButton(icons.system_overview, luc.TOGGLE_OVERVIEW_WINDOW) then
systemOverviewWidget.visible = false
drawBody = function()
local system = systemView:GetSystem() ---@type StarSystem
if not system or Windows.unexplored.visible then
return
end
ui.sameLine()
systemOverviewWidget:drawControlButtons()

systemOverviewWidget:displaySearch()
systemOverviewWidget:display(systemView:GetSystem(), nil, selected)
end)
end

function Windows.systemOverviewHidden.Show()
ui.withFont(ui.fonts.pionillium.medium, function()
if ui.mainMenuButton(icons.system_overview, luc.TOGGLE_OVERVIEW_WINDOW) then
systemOverviewWidget.visible = true
systemOverviewWidget.size.y = math.max(ui.getContentRegion().y, ui.screenHeight / 1.6)

local root = system.rootSystemBody
local selected = { [systemView:GetSelectedObject().ref or 0] = true }

systemOverviewWidget:display(Game.system, root, selected)
end
})

local systemEconView = require 'pigui.modules.system-econ-view'.New()

table.insert(leftSidebar.modules, {
priority = 2,
side = "left",
showInHyperspace = false,
icon = icons.money,
tooltip = luc.ECONOMY_TRADE,
exclusive = true,

drawTitle = function()
ui.text(luc.ECONOMY_TRADE)
end,

drawBody = function()
local selected = systemView:GetSelectedObject().ref ---@type SystemBody?
local docked = Game.player:GetDockedWith()
local current

if docked then
if not selected or not selected.isStation then
selected = docked:GetSystemBody()
else
current = docked:GetSystemBody()
end
end
end)
end

if not selected or not selected.isStation then
systemEconView:drawSystemComparison(systemView:GetSystem())
else
systemEconView:drawStationComparison(selected, current)
end
end
})

local function drawWindowControlButton(window, icon, tooltip)
local isWindowActive = true
Expand Down Expand Up @@ -720,7 +762,7 @@ function Windows.objectInfo:Show()
--FIXME there is some flickering when changing from one info to another
--which has different lenght. If the new one is shorter then the first header drawing
--seems to be too high (accodring to positioning relative to old info).
--Probably only durring the second drawing the position is ok. The window is anchored at bottom
--Probably only durring the second drawing the position is ok. The window is anchored at bottom
textIcon(getBodyIcon(obj))
ui.text(isSystemBody and body.name or body.label)
ui.spacing()
Expand Down Expand Up @@ -820,22 +862,21 @@ function Windows.objectInfo.Dummy()
end

function systemViewLayout:onUpdateWindowPivots(w)
w.edgeButtons.anchors = { ui.anchor.right, ui.anchor.center }
w.timeButtons.anchors = { ui.anchor.right, ui.anchor.bottom }
w.orbitPlanner.anchors = { ui.anchor.right, ui.anchor.bottom }
w.objectInfo.anchors = { ui.anchor.right, ui.anchor.bottom }
w.unexplored.anchors = { ui.anchor.center, ui.anchor.center }
w.systemName.anchors = { ui.anchor.center, ui.anchor.top }
w.edgeButtons.anchors = { ui.anchor.right, ui.anchor.center }
w.timeButtons.anchors = { ui.anchor.right, ui.anchor.bottom }
w.orbitPlanner.anchors = { ui.anchor.right, ui.anchor.bottom }
w.objectInfo.anchors = { ui.anchor.right, ui.anchor.bottom }
w.unexplored.anchors = { ui.anchor.center, ui.anchor.center }
end

function systemViewLayout:onUpdateWindowConstraints(w)
-- resizing, aligning windows - static
w.systemName.pos = Vector2(winfont.size)
w.systemName.pos.x = ui.screenWidth * 0.5
w.systemName.pos.y = styles.MainButtonSize.y + (styles.MainButtonPadding + styles.WindowPadding.y) * 2 -- matches fx-window.lua
w.systemName.size.x = 0 -- adaptive width
w.edgeButtons.size.y = 0 -- adaptive height

w.systemOverview.pos = w.systemName.pos + w.systemName.size
w.systemOverview.size.y = ui.screenHeight - w.systemOverview.pos.y - 12 - ui.timeWindowSize.y
w.systemOverviewHidden.pos = w.systemOverview.pos
w.edgeButtons.size.y = 0 -- adaptive height

w.orbitPlanner.pos = w.timeButtons.pos - Vector2(w.edgeButtons.size.x, w.timeButtons.size.y)
w.orbitPlanner.size.x = w.timeButtons.size.x - w.edgeButtons.size.x
Expand All @@ -855,13 +896,19 @@ local function displaySystemViewUI()
end

systemViewLayout:display()
ui.withStyleColors({ WindowBg = colors.transparent }, function()
leftSidebar:Draw()
end)

displayOnScreenObjects()

if ui.escapeKeyReleased() then
Game.SetView("sector")
end

if ui.ctrlHeld() and ui.isKeyReleased(ui.keys.delete) then
package.reimport 'pigui.modules.system-overview-window'
package.reimport 'pigui.modules.system-econ-view'
package.reimport()
end
end
Expand Down

0 comments on commit 977ad1c

Please sign in to comment.