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

Use new icons in Worldview #5042

Merged
merged 1 commit into from
Dec 5, 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
379 changes: 339 additions & 40 deletions data/icons/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 22 additions & 1 deletion data/pigui/baseui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,32 @@ end

local modules = {}

-- Function: ui.registerModule
--
-- Register a modular widget for display in a specific view mode
--
-- Example:
-- > ui.registerModule('game', function() ... end)
--
-- Parameters:
-- mode - string, the UI binding point you want to register this module to
-- fun - a function (or table) that is responsible for drawing your custom UI.
-- If `fun` is a table, it should have a `draw` function. The `enabled`
-- key in the table is reserved for use by the module system.
function ui.registerModule(mode, fun)
if not modules[mode] then
modules[mode] = {}
end
table.insert(modules[mode], { fun = fun, enabled = true })
if type(fun) == 'function' then fun = { draw = fun } end
fun.enabled = true

if fun.id and modules[mode][fun.id] then
local idx = modules[mode][fun.id]
modules[mode][idx] = fun
else
table.insert(modules[mode], fun)
if fun.id then modules[mode][fun.id] = #modules[mode] end
end
end

function ui.getModules(mode)
Expand Down
2 changes: 2 additions & 0 deletions data/pigui/libs/forwarded.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ local pigui = Engine.pigui
local ui = {}

ui.calcTextAlignment = pigui.CalcTextAlignment
ui.alignTextToLineHeight = pigui.AlignTextToLineHeight
ui.alignTextToFramePadding = pigui.AlignTextToFramePadding
ui.lineOnClock = pigui.lineOnClock
ui.pointOnClock = pigui.pointOnClock
ui.screenWidth = pigui.screen_width
Expand Down
76 changes: 76 additions & 0 deletions data/pigui/modules/flight-ui/body-icons.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
-- Copyright © 2008-2020 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local utils = require 'utils'
local ui = require 'pigui'

local icons = ui.theme.icons

local ASTEROID_RADIUS = 1500000 -- rocky planets smaller than this (in meters) are considered an asteroid, not a planet

-- Return the icon used to display the given body
-- If forWorld is true, returns an icon variant suitable
-- for display at small resolutions in the world view
local function getBodyIcon(body, forWorld)
local st = body.superType
local t = body.type
if st == "STARPORT" then
local population = body:GetSystemBody().population
if t == "STARPORT_ORBITAL" then
if population > (22000 / 1e9) then
return icons.station_orbital_large
elseif population > (15000 / 1e9) then
return icons.spacestation
else
return icons.station_orbital_small
end
elseif body.type == "STARPORT_SURFACE" then
if forWorld then return icons.starport end

if population > (180000 / 1e9) then
return icons.starport_surface
elseif population > (120000 / 1e9) then
return icons.outpost_large
else
return icons.outpost_medium
end
-- don't use the outpost or surface starport icons
-- we need to increase the size of icon rendering first
end
elseif st == "GAS_GIANT" then
return icons.gas_giant
elseif st == "STAR" then
return icons.sun
elseif st == "ROCKY_PLANET" then
if body:IsMoon() then
return icons.moon
else
local sb = body:GetSystemBody()
if sb.radius < ASTEROID_RADIUS then
return icons.asteroid_hollow
else
return icons.rocky_planet
end
end
elseif body:IsShip() then
local shipClass = body:GetShipClass()
if icons[shipClass] then
return icons[shipClass]
else
print("data/pigui/game.lua: getBodyIcon unknown ship class " .. (shipClass and shipClass or "nil"))
return icons.ship -- TODO: better icon
end
elseif body:IsHyperspaceCloud() then
return icons.hyperspace -- TODO: better icon
elseif body:IsMissile() then
return icons.bullseye -- TODO: better icon
elseif body:IsCargoContainer() then
return icons.rocky_planet -- TODO: better icon
else
print("data/pigui/game.lua: getBodyIcon not sure how to process body, supertype: " .. (st and st or "nil") .. ", type: " .. (t and t or "nil"))
utils.print_r(body)
return icons.ship
end
end

return getBodyIcon
Loading