Skip to content

Commit 637eb47

Browse files
Add save reminder to Adv mode and change colors based on how long it has been since a save (#1384)
use `:lua reqscript('internal/notify/notifications').save_time_threshold_mins=X` to set the threshold to X mins --------- Co-authored-by: Myk <myk.taylor@gmail.com>
1 parent b6ba687 commit 637eb47

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Template for new versions:
4242
- `hide-tutorials`: handle tutorial popups for adventure mode
4343
- `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)
4444
- `gui/notify`: moody dwarf notification turns red when they can't reach workshop or items
45+
- `gui/notify`: save reminder now appears in adventure mode
46+
- `gui/notify`: save reminder changes color to yellow at 30 minutes and to orange at 60 minutes
4547
- `gui/confirm`: in the delete manager order confirmation dialog, show a description of which order you have selected to delete
4648
- `position`: display both adventurer and site pos simultaneously. Display map block pos+offset of selected tile.
4749
- `gui/sitemap`: shift click to start following the selected unit or artifact

internal/notify/notifications.lua

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ local buildings = df.global.world.buildings
1414
local caravans = df.global.plotinfo.caravans
1515
local units = df.global.world.units
1616

17+
-- TODO: Add a proper API and UI for notification configuration
18+
-- this is global so one can use `:lua reqscript('internal/notify/notifications').save_time_threshold_mins=X` to change the threshold to X mins.
19+
save_time_threshold_mins = save_time_threshold_mins or 15
20+
1721
function for_iter(vec, match_fn, action_fn, reverse)
1822
local offset = type(vec) == 'table' and 1 or 0
1923
local idx1 = reverse and #vec-1+offset or offset
@@ -303,6 +307,33 @@ local function get_bar(get_fn, get_max_fn, text, color)
303307
return nil
304308
end
305309

310+
local function get_save_alert()
311+
local mins_since_save = dfhack.persistent.getUnsavedSeconds()//60
312+
local pen = COLOR_LIGHTCYAN
313+
if mins_since_save < save_time_threshold_mins then return end
314+
if mins_since_save >= 4*save_time_threshold_mins then
315+
pen = COLOR_LIGHTRED
316+
elseif mins_since_save >= 2*save_time_threshold_mins then
317+
pen = COLOR_YELLOW
318+
end
319+
return {
320+
{text='Last save: ', pen=COLOR_WHITE},
321+
{text=dfhack.formatInt(mins_since_save) ..' mins ago', pen=pen},
322+
}
323+
end
324+
325+
local function save_popup()
326+
local mins_since_save = dfhack.persistent.getUnsavedSeconds()//60
327+
local message = 'It has been ' .. dfhack.formatInt(mins_since_save) .. ' minutes since your last save.'
328+
if dfhack.world.isFortressMode() then
329+
message = message .. '\n\nWould you like to save now? (Note: You can also close this reminder and save manually)'
330+
dlg.showYesNoPrompt('Save now?', message, nil, function() dfhack.run_script('quicksave') end)
331+
else
332+
message = message .. '\n\nClose this popup to open the options menu and select "Save and continue playing"'
333+
dlg.showMessage('Save reminder', message, COLOR_WHITE, function() gui.simulateInput(dfhack.gui.getDFViewscreen(true), 'OPTIONS') end)
334+
end
335+
end
336+
306337
-- the order of this list controls the order the notifications will appear in the overlay
307338
NOTIFICATIONS_BY_IDX = {
308339
{
@@ -526,20 +557,10 @@ NOTIFICATIONS_BY_IDX = {
526557
},
527558
{
528559
name='save-reminder',
529-
desc='Shows a reminder if it has been more than 15 minutes since your last save.',
560+
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'),
530561
default=true,
531-
dwarf_fn=function ()
532-
local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60
533-
if minsSinceSave >= 15 then
534-
return "Last save: ".. (dfhack.formatInt(minsSinceSave)) ..' mins ago'
535-
end
536-
end,
537-
on_click=function()
538-
local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60
539-
local message = 'It has been ' .. dfhack.formatInt(minsSinceSave) .. ' minutes since your last save. \n\nWould you like to save now?\n\n' ..
540-
'You can also close this reminder and save manually.'
541-
dlg.showYesNoPrompt('Save now?', message, nil, function() dfhack.run_script('quicksave') end)
542-
end,
562+
fn=get_save_alert,
563+
on_click=save_popup,
543564
},
544565
}
545566

0 commit comments

Comments
 (0)