Skip to content

Add save reminder to Adv mode and change colors based on how long it has been since a save #1384

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

Merged
merged 23 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cc43b47
Add save reminder to Adv mode
realSquidCoder Jan 29, 2025
e4967df
Improved the Save Reminder
realSquidCoder Feb 9, 2025
cc38fde
Merge branch 'master' into squid-save-reminder
realSquidCoder Feb 9, 2025
df4553a
Update changelog.txt
realSquidCoder Feb 9, 2025
93f596a
Merge branch 'squid-save-reminder' of https://github.com/SquidCoderIn…
realSquidCoder Feb 9, 2025
90f918d
Update changelog.txt
realSquidCoder Feb 9, 2025
ae2d61b
Update notifications.lua
realSquidCoder Feb 9, 2025
88d9182
Merge branch 'master' into squid-save-reminder
realSquidCoder Feb 9, 2025
5d63529
Add explanation for lack of quicksave in adventure, instead of a sile…
realSquidCoder Feb 9, 2025
7d76956
clean up
realSquidCoder Feb 9, 2025
497d8c7
Update notifications.lua
realSquidCoder Feb 9, 2025
76b1a04
Explain the global var
realSquidCoder Feb 9, 2025
7c4165e
clean up 2
realSquidCoder Feb 9, 2025
072666f
Fix adv hang
realSquidCoder Feb 9, 2025
6a0d678
Update notifications.lua
realSquidCoder Feb 10, 2025
6bad835
Merge branch 'master' into squid-save-reminder
realSquidCoder Feb 11, 2025
b569e5d
Save reminder now works in adv mode
realSquidCoder Feb 11, 2025
3b17702
Merge branch 'DFHack:master' into squid-save-reminder
realSquidCoder Feb 14, 2025
322f8d6
Merge branch 'DFHack:master' into squid-save-reminder
realSquidCoder Feb 15, 2025
7e203b7
Merge branch 'DFHack:master' into squid-save-reminder
realSquidCoder Feb 16, 2025
886f811
Apply suggestions from code review
myk002 Feb 21, 2025
39fa2f5
Fix the whitespace
realSquidCoder Feb 21, 2025
7b91585
Apply suggestions from code review
myk002 Feb 22, 2025
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
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Template for new versions:
- `hide-tutorials`: handle tutorial popups for adventure mode
- `hide-tutorials`: new ``reset`` command that will re-enable popups in the current game (in case you hid them all and now want them back)
- `gui/notify`: moody dwarf notification turns red when they can't reach workshop or items
- `gui/notify`: save reminder now appears in adventure mode
- `gui/notify`: save reminder changes color to yellow at 30 minutes and to orange at 60 minutes
- `gui/confirm`: in the delete manager order confirmation dialog, show a description of which order you have selected to delete
- `position`: display both adventurer and site pos simultaneously. Display map block pos+offset of selected tile.

Expand Down
47 changes: 34 additions & 13 deletions internal/notify/notifications.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ local buildings = df.global.world.buildings
local caravans = df.global.plotinfo.caravans
local units = df.global.world.units

-- TODO: Add a proper API and UI for notification configuration
-- this is global so one can use `:lua reqscript('internal/notify/notifications').save_time_threshold_mins=X` to change the threshold to X mins.
save_time_threshold_mins = save_time_threshold_mins or 15

function for_iter(vec, match_fn, action_fn, reverse)
local offset = type(vec) == 'table' and 1 or 0
local idx1 = reverse and #vec-1+offset or offset
Expand Down Expand Up @@ -303,6 +307,33 @@ local function get_bar(get_fn, get_max_fn, text, color)
return nil
end

local function get_save_alert()
local mins_since_save = dfhack.persistent.getUnsavedSeconds()//60
local pen = COLOR_LIGHTCYAN
if mins_since_save < save_time_threshold_mins then return end
if mins_since_save >= 4*save_time_threshold_mins then
pen = COLOR_LIGHTRED
elseif mins_since_save >= 2*save_time_threshold_mins then
pen = COLOR_YELLOW
end
return {
{text='Last save: ', pen=COLOR_WHITE},
{text=dfhack.formatInt(mins_since_save) ..' mins ago', pen=pen},
}
end

local function save_popup()
local mins_since_save = dfhack.persistent.getUnsavedSeconds()//60
local message = 'It has been ' .. dfhack.formatInt(mins_since_save) .. ' minutes since your last save.'
if dfhack.world.isFortressMode() then
message = message .. '\n\nWould you like to save now? (Note: You can also close this reminder and save manually)'
dlg.showYesNoPrompt('Save now?', message, nil, function() dfhack.run_script('quicksave') end)
else
message = message .. '\n\nClose this popup to open the options menu and select "Save and continue playing"'
dlg.showMessage('Save reminder', message, COLOR_WHITE, function() gui.simulateInput(dfhack.gui.getDFViewscreen(true), 'OPTIONS') end)
end
end

-- the order of this list controls the order the notifications will appear in the overlay
NOTIFICATIONS_BY_IDX = {
{
Expand Down Expand Up @@ -526,20 +557,10 @@ NOTIFICATIONS_BY_IDX = {
},
{
name='save-reminder',
desc='Shows a reminder if it has been more than 15 minutes since your last save.',
desc=('Shows a reminder if it has been more than %d minute%s since your last save.'):format(save_time_threshold_mins, save_time_threshold_mins == 1 and '' or 's'),
default=true,
dwarf_fn=function ()
local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60
if minsSinceSave >= 15 then
return "Last save: ".. (dfhack.formatInt(minsSinceSave)) ..' mins ago'
end
end,
on_click=function()
local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60
local message = 'It has been ' .. dfhack.formatInt(minsSinceSave) .. ' minutes since your last save. \n\nWould you like to save now?\n\n' ..
'You can also close this reminder and save manually.'
dlg.showYesNoPrompt('Save now?', message, nil, function() dfhack.run_script('quicksave') end)
end,
fn=get_save_alert,
on_click=save_popup,
},
}

Expand Down