Skip to content
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

Add a save reminder to notifications panel #1373

Merged
merged 8 commits into from
Jan 16, 2025
Merged
21 changes: 21 additions & 0 deletions internal/notify/notifications.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ local buildings = df.global.world.buildings
local caravans = df.global.plotinfo.caravans
local units = df.global.world.units

SaveDur = 0

realSquidCoder marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -524,6 +526,25 @@ NOTIFICATIONS_BY_IDX = {
adv_fn=curry(get_bar, get_blood, get_max_blood, "Blood", COLOR_RED),
on_click=nil,
},
{
name='autosave',
realSquidCoder marked this conversation as resolved.
Show resolved Hide resolved
desc='Shows a reminder to save now and then.',
realSquidCoder marked this conversation as resolved.
Show resolved Hide resolved
default=true,
dwarf_fn=function ()
local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60
if minsSinceSave < 15 then
return nil
end
return "Last save: ".. (dfhack.formatInt(minsSinceSave)) ..' mins ago'
realSquidCoder marked this conversation as resolved.
Show resolved Hide resolved
end,
on_click=function ()
realSquidCoder marked this conversation as resolved.
Show resolved Hide resolved
local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60
local message = 'It has been ' .. (dfhack.formatInt(minsSinceSave)) .. ' mins since your last save. \n\nWould you like to save now? ' ..
'(Note: You can still close this reminder and save manually)'
realSquidCoder marked this conversation as resolved.
Show resolved Hide resolved
dlg.showYesNoPrompt('Save now?', message, nil, function()
dfhack.run_script('quicksave') end)
realSquidCoder marked this conversation as resolved.
Show resolved Hide resolved
end,
},
}

NOTIFICATIONS_BY_NAME = {}
Expand Down