From 582c89d0b45b68ed1c76a71963a787c8ecee35b1 Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Wed, 15 Jan 2025 10:13:26 -0600 Subject: [PATCH 1/8] add the lua side of the autosave code --- internal/notify/notifications.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/notify/notifications.lua b/internal/notify/notifications.lua index 0d312769d2..12b971aaf6 100644 --- a/internal/notify/notifications.lua +++ b/internal/notify/notifications.lua @@ -524,6 +524,22 @@ NOTIFICATIONS_BY_IDX = { adv_fn=curry(get_bar, get_blood, get_max_blood, "Blood", COLOR_RED), on_click=nil, }, + { + name='autosave', + desc='Shows a reminder to save now and then.', + default=true, + dwarf_fn=function () + local dur = dur or 8 + return "Save Reminder! Last Save: ".. dur ..' mins ago' + end, + on_click=function () + local dur = dur or 8 + local message = 'It has been ' .. dur .. ' mins since your last save. \n\nWould you like to save now? ' .. + '(Note: You can still close this reminder and save manually)' + dlg.showYesNoPrompt('Save now?', message, nil, function() + dfhack.run_script('quicksave') end) + end, + }, } NOTIFICATIONS_BY_NAME = {} From 0c85e31655134dcd9188e841f9d1e8a31065864d Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Wed, 15 Jan 2025 11:42:48 -0600 Subject: [PATCH 2/8] Add time calcs. --- internal/notify/notifications.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/notify/notifications.lua b/internal/notify/notifications.lua index 12b971aaf6..9e31bddbbd 100644 --- a/internal/notify/notifications.lua +++ b/internal/notify/notifications.lua @@ -14,6 +14,8 @@ local buildings = df.global.world.buildings local caravans = df.global.plotinfo.caravans local units = df.global.world.units +SaveDur = 0 + 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 @@ -529,12 +531,12 @@ NOTIFICATIONS_BY_IDX = { desc='Shows a reminder to save now and then.', default=true, dwarf_fn=function () - local dur = dur or 8 - return "Save Reminder! Last Save: ".. dur ..' mins ago' + local durMS = getTickCount() - getSaveTick() + SaveDur = durMS / (60 * 1000) -- 60 seconds, 1000 ms in a second + return "Save Reminder! Last Save: ".. SaveDur ..' mins ago' end, on_click=function () - local dur = dur or 8 - local message = 'It has been ' .. dur .. ' mins since your last save. \n\nWould you like to save now? ' .. + local message = 'It has been ' .. SaveDur .. ' mins since your last save. \n\nWould you like to save now? ' .. '(Note: You can still close this reminder and save manually)' dlg.showYesNoPrompt('Save now?', message, nil, function() dfhack.run_script('quicksave') end) From 4d6f9e5dbf3d674e593b2aba7e7d49b728472d28 Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:53:15 -0600 Subject: [PATCH 3/8] Update notifications.lua --- internal/notify/notifications.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/notify/notifications.lua b/internal/notify/notifications.lua index 9e31bddbbd..a90de9c981 100644 --- a/internal/notify/notifications.lua +++ b/internal/notify/notifications.lua @@ -531,12 +531,10 @@ NOTIFICATIONS_BY_IDX = { desc='Shows a reminder to save now and then.', default=true, dwarf_fn=function () - local durMS = getTickCount() - getSaveTick() - SaveDur = durMS / (60 * 1000) -- 60 seconds, 1000 ms in a second - return "Save Reminder! Last Save: ".. SaveDur ..' mins ago' + return "Save Reminder! Last Save: ".. dfhack.persistence.getCurSaveDur() ..' mins ago' end, on_click=function () - local message = 'It has been ' .. SaveDur .. ' mins since your last save. \n\nWould you like to save now? ' .. + local message = 'It has been ' .. dfhack.persistence.getCurSaveDur() .. ' mins since your last save. \n\nWould you like to save now? ' .. '(Note: You can still close this reminder and save manually)' dlg.showYesNoPrompt('Save now?', message, nil, function() dfhack.run_script('quicksave') end) From 8d00171b0461d93895f743c1c873c72f6931470f Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Wed, 15 Jan 2025 16:13:34 -0600 Subject: [PATCH 4/8] Added all the logic based on the added api --- internal/notify/notifications.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/notify/notifications.lua b/internal/notify/notifications.lua index a90de9c981..93ca5202a2 100644 --- a/internal/notify/notifications.lua +++ b/internal/notify/notifications.lua @@ -531,10 +531,15 @@ NOTIFICATIONS_BY_IDX = { desc='Shows a reminder to save now and then.', default=true, dwarf_fn=function () - return "Save Reminder! Last Save: ".. dfhack.persistence.getCurSaveDur() ..' mins ago' + local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60 + if minsSinceSave < 15 then + return nil + end + return "Last save: ".. (dfhack.formatInt(minsSinceSave)) ..' mins ago' end, on_click=function () - local message = 'It has been ' .. dfhack.persistence.getCurSaveDur() .. ' mins since your last save. \n\nWould you like to save now? ' .. + 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)' dlg.showYesNoPrompt('Save now?', message, nil, function() dfhack.run_script('quicksave') end) From 64ee438e2c9610860dc39cd7531a8dcae280e79e Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Wed, 15 Jan 2025 16:17:49 -0600 Subject: [PATCH 5/8] remove the whitespace --- internal/notify/notifications.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/notify/notifications.lua b/internal/notify/notifications.lua index 93ca5202a2..b6138dc415 100644 --- a/internal/notify/notifications.lua +++ b/internal/notify/notifications.lua @@ -535,7 +535,7 @@ NOTIFICATIONS_BY_IDX = { if minsSinceSave < 15 then return nil end - return "Last save: ".. (dfhack.formatInt(minsSinceSave)) ..' mins ago' + return "Last save: ".. (dfhack.formatInt(minsSinceSave)) ..' mins ago' end, on_click=function () local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60 From c5d180872e8c571e1c0cc0058363ae0009d0fbca Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:31:32 -0600 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Myk --- internal/notify/notifications.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/internal/notify/notifications.lua b/internal/notify/notifications.lua index b6138dc415..08e6c1eb0b 100644 --- a/internal/notify/notifications.lua +++ b/internal/notify/notifications.lua @@ -528,21 +528,19 @@ NOTIFICATIONS_BY_IDX = { }, { name='autosave', - desc='Shows a reminder to save now and then.', + desc='Shows a reminder if it has been more than 15 minutes since your last save.', default=true, dwarf_fn=function () local minsSinceSave = dfhack.persistent.getUnsavedSeconds()//60 - if minsSinceSave < 15 then - return nil + if minsSinceSave >= 15 then + return "Last save: ".. (dfhack.formatInt(minsSinceSave)) ..' mins ago' end - return "Last save: ".. (dfhack.formatInt(minsSinceSave)) ..' mins ago' end, - on_click=function () + on_click=function() 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)' - dlg.showYesNoPrompt('Save now?', message, nil, function() - dfhack.run_script('quicksave') end) + local message = 'It has been ' .. dfhack.formatInt(minsSinceSave) .. ' minutes since your last save. \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) end, }, } From 67b3f227d83ebe2e083cceaf9741e66b011e174d Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:35:07 -0600 Subject: [PATCH 7/8] Removed old global and renamed the notification --- internal/notify/notifications.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/notify/notifications.lua b/internal/notify/notifications.lua index 08e6c1eb0b..a527b43549 100644 --- a/internal/notify/notifications.lua +++ b/internal/notify/notifications.lua @@ -14,8 +14,6 @@ local buildings = df.global.world.buildings local caravans = df.global.plotinfo.caravans local units = df.global.world.units -SaveDur = 0 - 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 @@ -527,7 +525,7 @@ NOTIFICATIONS_BY_IDX = { on_click=nil, }, { - name='autosave', + name='save-reminder', desc='Shows a reminder if it has been more than 15 minutes since your last save.', default=true, dwarf_fn=function () From c577e9b25b55c8e212ac7c63697b8b2a2e0104d9 Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Wed, 15 Jan 2025 21:56:14 -0600 Subject: [PATCH 8/8] Update changelog.txt --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 97c2325dad..44bb9711e4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -35,6 +35,7 @@ Template for new versions: - `gui/settings-manager`: standing orders save/load now includes the reserved barrels setting - `gui/rename`: add overlay to worldgen screen allowing you to rename the world before the new world is saved - `gui/rename`: add overlay to the "Prepare carefully" embark screen that transparently fixes a DF bug where you can't give units nicknames or custom professions +- `gui/notify`: new notification type: save reminder; appears 15 minutes after a save is created or loaded, click to be asked to quicksave ## Fixes - `fix/dry-buckets`: don't empty buckets for wells that are actively in use