Skip to content

Commit

Permalink
Add filter to hide autosaves, load full data from save info
Browse files Browse the repository at this point in the history
- Make autosaves hidden by default in the list - makes it easier to see on-purpose saves
- Fully populate the save entry structure with data from the saved game information; now we have character and ship names, and total playtime
- Update for new ui.iconButton signature
  • Loading branch information
sturnclaw committed Aug 22, 2024
1 parent ba98f82 commit d48ef4e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
4 changes: 4 additions & 0 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,10 @@
"description": "",
"message": "Ship Type"
},
"SHOW_AUTOSAVES": {
"description": "Button tooltip indicating whether to show autosave files",
"message": "Show Autosaves"
},
"SIMULATING_UNIVERSE_EVOLUTION_N_BYEARS": {
"description": "",
"message": "Simulating evolution of the universe: {age} billion years ;-)"
Expand Down
54 changes: 40 additions & 14 deletions data/pigui/modules/saveloadgame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ local SaveGameEntry = utils.proto()
SaveGameEntry.name = ""
SaveGameEntry.character = lc.UNKNOWN
SaveGameEntry.shipName = ""
SaveGameEntry.shipClass = lc.UNKNOWN
SaveGameEntry.shipHull = lc.UNKNOWN
SaveGameEntry.credits = 0
SaveGameEntry.locationName = lc.UNKNOWN
SaveGameEntry.gameTime = 0
Expand All @@ -70,6 +70,8 @@ SaveLoadWindow.selectedFile = nil
SaveLoadWindow.searchStr = ""
SaveLoadWindow.savePath = ""
SaveLoadWindow.entryCache = {}
SaveLoadWindow.caseSensitive = false
SaveLoadWindow.showAutosaves = false

--==============================================================================

Expand All @@ -89,9 +91,9 @@ local function drawSaveEntryDetails(entry)
ui.icon(icons.ships_no_orbits, iconSize, iconColor)
ui.sameLine()
if #entry.shipName > 0 then
ui.text(entry.shipClass .. ": " .. entry.shipName)
ui.text(entry.shipHull .. ": " .. entry.shipName)
else
ui.text(entry.shipClass)
ui.text(entry.shipHull)
end

ui.icon(icons.money, iconSize, iconColor)
Expand Down Expand Up @@ -211,22 +213,23 @@ local function makeEntryForSave(file)
name = file.name,
compatible = compatible,
isAutosave = file.name:sub(1, 1) == "_",
-- character = lc.UNKNOWN -- No information about the pilot available
character = saveInfo.character,
timestamp = file.mtime.timestamp,
gameTime = saveInfo.time,
-- duration = 0, -- No duration information available
duration = saveInfo.duration,
locationName = location,
credits = saveInfo.credits,
-- shipName = lc.UNKNOWN, -- No information about the name of the ship available, either,
shipName = saveInfo.shipName,
shipHull = saveInfo.shipHull,
})

-- The saved ship name is the name of the *model* not the shipdef for some dumb reason
-- We treat the two as interchangeable for now
if saveInfo.ship then
-- Old saves store only the name of the ship's *model* file for some dumb reason
-- Treat the model name as the ship id and otherwise ignore it if we have proper data
if not saveInfo.shipHull then
local shipDef = ShipDef[saveInfo.ship]

if shipDef then
saveEntry.shipClass = shipDef.name
saveEntry.shipHull = shipDef.name
end
end

Expand All @@ -241,6 +244,10 @@ end

function SaveLoadWindow:makeFilteredList()
local shouldShow = function(f)
if not self.showAutosaves and f.name:sub(1, 1) == "_" then
return false
end

if #self.searchStr < minSearchTextLength then
return true
end
Expand Down Expand Up @@ -365,6 +372,14 @@ end

function SaveLoadWindow:onSetCaseSensitive(cs)
self.caseSensitive = cs

if #self.searchStr >= minSearchTextLength then
self:makeFilteredList()
end
end

function SaveLoadWindow:onSetShowAutosaves(sa)
self.showAutosaves = sa
self:makeFilteredList()
end

Expand All @@ -379,27 +394,38 @@ function SaveLoadWindow:drawSearchHeader()
ui.sameLine(0, style.windowPadding.x)
ui.icon(icons.search_lens, Vector2(headingFont.size), colors.font, lc.SEARCH)

local icon_size = Vector2(headingFont.size)
local icon_size_spacing = icon_size.x + ui.getItemSpacing().x

-- Draw search bar text entry
ui.withFont(bodyFont, function()
local height = ui.getFrameHeight()

ui.sameLine()
ui.addCursorPos(Vector2(0, (ui.getLineHeight() - height) / 2.0))

ui.nextItemWidth(ui.getContentRegion().x - (headingFont.size + ui.getItemSpacing().x))
ui.nextItemWidth(ui.getContentRegion().x - (icon_size_spacing * 2))
local searchStr, changed = ui.inputText("##searchStr", self.searchStr, {})

if changed then
self:message("onFilterChanged", searchStr)
end
end)

-- Draw case-sensitive toggle
local color = self.caseSensitive and ui.theme.buttonColors.default or ui.theme.buttonColors.transparent
ui.sameLine()
if ui.iconButton(icons.autopilot_fly_to, Vector2(ui.getLineHeight()), lui.CASE_SENSITIVE, color) then

-- Draw case-sensitive toggle
local case_sens_variant = not self.caseSensitive and ui.theme.buttonColors.transparent
if ui.iconButton("case_sensitive", icons.case_sensitive, lui.CASE_SENSITIVE, case_sens_variant, icon_size) then
self:message("onSetCaseSensitive", not self.caseSensitive)
end

ui.sameLine()

local autosave_variant = not self.showAutosaves and ui.theme.buttonColors.transparent
if ui.iconButton("show_autosaves", icons.view_internal, lui.SHOW_AUTOSAVES, autosave_variant, icon_size) then
self:message("onSetShowAutosaves", not self.showAutosaves)
end
end

function SaveLoadWindow:drawSaveFooter()
Expand Down

0 comments on commit d48ef4e

Please sign in to comment.