Skip to content

Commit

Permalink
Visual and textual improvements to police tab
Browse files Browse the repository at this point in the history
- Render crime lists as tables
- Use ui.tabBarFont() for consistent styling of the tab bar
- Show fine cost on payment button and change state based on player monetary state
- Sort criminal records by count of crimes committed
- Sort list of illegal commodities alphabetically
- Add introductory text to illegal commodity list
- Tweak rules/regulations text to mention that the distance pertains to laws enforced within the station's sensor coverage.
  • Loading branch information
Web-eWorks authored and impaktor committed Aug 23, 2024
1 parent 8f509df commit a819636
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 63 deletions.
28 changes: 24 additions & 4 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,17 @@
"description": "",
"message": "Crew Roster"
},
"CRIME": {
"description": "Heading introducing a single crime name or list of crime names",
"message": "Crime"
},
"CRIMINAL": {
"description": "Legal status of player",
"message": "Criminal"
},
"CRIMINAL_RECORD": {
"description": "Past crimes / crime history of character",
"message": "Criminal record"
"description": "Heading for past crimes / crime history of character, proper noun",
"message": "Criminal Record"
},
"CURRENT_FUEL": {
"description": "For hyperjump planner",
Expand Down Expand Up @@ -639,6 +643,10 @@
"description": "Financial statement of player, e.g. cash",
"message": "Finance"
},
"FINE": {
"description": "Cost of a criminal action",
"message": "Fine"
},
"FLIGHTLOG_DOCKING": {
"description": "Used in Flight Log, to indicate player's position. 'primary_info' is a station name",
"message": "Docking at {primary_info}"
Expand Down Expand Up @@ -1207,6 +1215,10 @@
"description": "An illegal action or commodity",
"message": "Illegal in System"
},
"ILLEGAL_COMMODITIES": {
"description": "Commodities illegal in the current system or polity",
"message": "Illegal Commodities"
},
"ILLEGAL_JUMP": {
"description": "A finable crime",
"message": "Reckless hyperjump registered"
Expand Down Expand Up @@ -1333,7 +1345,7 @@
},
"LEGAL_RULES": {
"description": "Refers to laws, rules and regulations",
"message": "Legal rules enforced in station controlled space, within: {distance}"
"message": "Legal rules applicable in station controlled space. Laws are sensor enforced within a distance of: {distance}"
},
"LEGAL_RULES_AND_REGULATIONS": {
"description": "Heading on a tab, keep it short",
Expand Down Expand Up @@ -1741,7 +1753,7 @@
},
"OUTSTANDING_FINES": {
"description": "Unpaid fines for crimes committed",
"message": "Outstanding fines"
"message": "Outstanding Fines"
},
"OUT_OF_RANGE": {
"description": "Ship jump status",
Expand Down Expand Up @@ -1851,6 +1863,10 @@
"description": "Player combat rating",
"message": "Poor"
},
"POSESSION_OF_COMMODITIES_ILLEGAL": {
"description": "",
"message": "Possession of certain commodities is illegal in this system."
},
"POSITION": {
"description": "The job title/position of crew memeber",
"message": "Position"
Expand Down Expand Up @@ -2315,6 +2331,10 @@
"description": "Message when restoring savegame",
"message": "There were errors in recovery:"
},
"THESE_ITEMS_ARE_PUNISHABLE_BY_FINE": {
"description": "",
"message": "Purchase, sale, and transportation of these items is punishable by a fine and possible confiscation"
},
"THE_SHIP_IS_UNDER_STATION_CONTROL_COMMANDER": {
"description": "",
"message": "The ship is under station control, Commander."
Expand Down
191 changes: 132 additions & 59 deletions data/pigui/modules/station-view/07-police.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ local orbiteer = ui.fonts.orbiteer
local face = nil
local stationSeed = false

local crimeTableID = "##CrimeTable"

local popup = ModalWindow.New('policePopup', function(self)
ui.text(l.YOU_NOT_ENOUGH_MONEY)
ui.text(l.YOU_NOT_ENOUGH_MONEY .. ".")
ui.dummy(Vector2((ui.getContentRegion().x - 100*rescaleVector.x) / 2, 0))
ui.sameLine()
if ui.button(l.OK, Vector2(100*rescaleVector.x, 0)) then
Expand All @@ -41,6 +43,7 @@ local widgetSizes = ui.rescaleUI({
buttonSize = Vector2(100,0),
dummySpaceSmall = Vector2(0, 10),
dummySpaceMedium = Vector2(0, 50),
tablePadding = Vector2(12, 4)
}, Vector2(1600, 900))


Expand All @@ -53,50 +56,81 @@ local function payfine(fine)
Game.player:ClearCrimeFine()
end

local function make_crime_list(record)
local crimes = utils.build_array(utils.map(
function(crime, v) return true, { count = v.count, name = Legal.CrimeType[crime].name } end,
pairs(record)
))

table.sort(crimes, function(a, b) return a.count > b.count end)

return crimes
end

-- Render a list of outstanding crimes
local function crime_table(crimes)
ui.withStyleVars({ CellPadding = widgetSizes.tablePadding }, function()
ui.beginTable(crimeTableID, 2, { "BordersInnerV" })

ui.tableSetupColumn("count", "WidthFixed")
ui.tableSetupColumn("name", "WidthStretch")

for _, v in pairs(crimes) do
ui.tableNextRow()

ui.tableNextColumn()
ui.text(v.count)

ui.tableNextColumn()
ui.text(v.name)
end

ui.endTable()
end)
end

local function crime_record()
local past_crimes, stump = Game.player:GetCrimeRecord()
if #utils.build_array(pairs(past_crimes)) > 0 then
local past_crimes = make_crime_list(Game.player:GetCrimeRecord())

if #past_crimes > 0 then
ui.withFont(orbiteer.heading, function()
ui.textColored(gray, l.CRIMINAL_RECORD)
ui.text(l.CRIMINAL_RECORD .. ":")
end)
ui.withFont(pionillium.body, function ()
for k,v in pairs(past_crimes) do
ui.textColored(gray, v.count)
-- start second column at this position:
ui.sameLine(widgetSizes.crimeRecordColumnWidth)
ui.textColored(gray, Legal.CrimeType[k].name)
end

ui.withStyleColors({ Text = ui.theme.colors.fontDim }, function()
crime_table(past_crimes)
end)
end
end


local function outstanding_fines()
local crimes, fine = Game.player:GetCrimeOutstanding()
if #utils.build_array(pairs(crimes)) > 0 then

local crime_list = make_crime_list(crimes)
if #crime_list > 0 then

-- headline
ui.dummy(widgetSizes.dummySpaceSmall)
ui.withFont(orbiteer.heading, function()
ui.text(l.OUTSTANDING_FINES)
ui.text(l.OUTSTANDING_FINES .. ":")
end)

-- wrap list in medlarge font
ui.withFont(pionillium.body, function()
for k,v in pairs(crimes) do
ui.text(v.count)
-- start second column at this position:
ui.sameLine(widgetSizes.crimeRecordColumnWidth)
ui.text(Legal.CrimeType[k].name)
end
crime_table(crime_list)
ui.spacing()

local canPay = Game.player:GetMoney() >= fine
local pay_fine_text = string.interp(l.PAY_FINE_OF_N,
{ amount = Format.Money(fine) })
ui.text(pay_fine_text)

if ui.button(l.PAY, widgetSizes.buttonSize) then
if ui.button(pay_fine_text, nil, not canPay and ui.theme.buttonColors.disabled) then
payfine(fine)
end

if not canPay and ui.isItemHovered() then
ui.setTooltip(l.YOU_NOT_ENOUGH_MONEY)
end
end)
else
ui.withFont(pionillium.body, function()
Expand All @@ -112,62 +146,101 @@ local function drawRulesAndRegulations()
distance = Format.Distance(station.lawEnforcedRange),
})
ui.text(header)
ui.text("")
ui.newLine()

local lawlessness = Game.system.lawlessness

for k,v in pairs(Legal.CrimeType) do
ui.text(v.name .. ":\t")
ui.sameLine()
ui.text(Format.Money(Legal:fine(k, lawlessness)))
end
local crimeList = utils.build_array(utils.map(
function(k, v) return true, { name = v.name, fine = Legal:fine(k, lawlessness)} end,
pairs(Legal.CrimeType)
))

table.sort(crimeList, function(a, b) return a.name < b.name end)

ui.withStyleVars({ CellPadding = widgetSizes.tablePadding }, function()
ui.beginTable("Crimes", 2, { "BordersInnerH" })
ui.tableSetupColumn(l.CRIME .. ":")
ui.tableSetupColumn(l.FINE .. ":")

ui.withFont(pionillium.heading, function()
ui.tableHeadersRow()
end)

for _, v in ipairs(crimeList) do
ui.tableNextRow()

ui.tableNextColumn()
ui.text(v.name .. ":")

ui.tableNextColumn()
ui.textAligned(Format.Money(v.fine), 1.0)
end

ui.endTable()
end)
end

local policeTabs = {
{
name = l.CRIMINAL_RECORD,
draw = function()
-- 1. If outstanding fines, show list & offer to pay
outstanding_fines()

ui.dummy(widgetSizes.dummySpaceSmall)

-- 2 If old payed fines, show grayd out list
crime_record()
end
},
{
name = l.LEGAL_RULES_AND_REGULATIONS,
draw = drawRulesAndRegulations
},
{
name = l.ILLEGAL_COMMODITIES,
draw = function()
ui.textWrapped(l.POSESSION_OF_COMMODITIES_ILLEGAL)
ui.spacing()
ui.separator()
ui.spacing()
ui.textWrapped(l.THESE_ITEMS_ARE_PUNISHABLE_BY_FINE .. ":")

ui.spacing()

-- Build a list of illegal goods in this system
local illegal = utils.map_array(utils.build_array(pairs(Commodities)), function(comm)
return not Game.system:IsCommodityLegal(comm.name) and comm:GetName() or nil
end)

-- Sort the list lexicographically
table.sort(illegal)

for _, name in ipairs(illegal) do
ui.text(name)
end
end
}
}

local function drawPolice()
local intro_txt = string.interp(l.THIS_IS_FACTION_POLICE,
{ faction_police = Game.system.faction.policeName, faction = Game.system.faction.name})

ui.withStyleVars({ItemSpacing = widgetSizes.itemSpacing}, function()
local padding = ui.getWindowPadding()
local infoColumnWidth = ui.getContentRegion().x
- widgetSizes.faceSize.x - widgetSizes.itemSpacing.x
- widgetSizes.faceSize.x - padding.x * 2

ui.child("CrimeStats", Vector2(infoColumnWidth, 0), {}, function()
ui.withFont(pionillium.heading, function ()
ui.text(intro_txt)
end)

if (ui.beginTabBar("tabs")) then
if ui.beginTabItem(l.CRIMINAL_RECORD) then
-- 1. If outstanding fines, show list & offer to pay
outstanding_fines()

ui.dummy(widgetSizes.dummySpaceMedium)

-- 2 If old payed fines, show grayd out list
crime_record()
ui.endTabItem()
end
if ui.beginTabItem(l.LEGAL_RULES_AND_REGULATIONS) then
drawRulesAndRegulations()
ui.endTabItem()
end

if ui.beginTabItem(l.ILLEGAL_IN_SYSTEM) then

for key, comm in pairs(Commodities) do
if not Game.system:IsCommodityLegal(comm.name) then
ui.text(comm:GetName())
end
end
ui.endTabItem()
end
ui.endTabBar()
end

ui.newLine()
ui.tabBarFont("tabs", policeTabs, pionillium.heading)
end)

ui.sameLine()
ui.sameLine(0, padding.x * 2)
if(face ~= nil) then face:render() end
end)
end
Expand Down

0 comments on commit a819636

Please sign in to comment.