@@ -14,6 +14,10 @@ local buildings = df.global.world.buildings
1414local caravans = df .global .plotinfo .caravans
1515local 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+
1721function 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
304308end
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\n Would 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\n Close 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
307338NOTIFICATIONS_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\n Would 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