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 save reminder to Adv mode and change colors based on how long it has been since a save #1384

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ Template for new versions:
## Fixes

## Misc Improvements
- `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
- `hide-tutorials`: if enabled, also hide tutorial popups for adventure mode
- `hide-tutorials`: new ``reset`` command that will re-enable popups in the current game
- `gui/notify`: save reminder now appears in adventure mode and also changes color to yellow at 30 minutes and to orange at 60 minutes
- `gui/notify`: moody dwarf notification turns red when they can't find workshop or items
- `gui/confirm`: in the delete manager order confirmation dialog, show a description of which order you have selected to delete

## Removed
Expand Down
56 changes: 39 additions & 17 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

-- FIXME 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
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 @@ -303,8 +307,43 @@ 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()
if dfhack.world.isFortressMode() then
local mins_since_save = dfhack.persistent.getUnsavedSeconds()//60
local message = 'It has been ' .. dfhack.formatInt(mins_since_save) .. ' 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)
else
local adv_warn_msg = "Unfortunately, quicksave doesn't currently work in Adventure mode, so you will need to save manually.\n\n"..
'Close this popup to open the options menu and select "Save and continue playing"'
dlg.showMessage("Unable to use quicksave", adv_warn_msg, 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 = {
{-- The save reminder should always be at the top, since it's important.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything here is important : P I'd actually argue that this should go at the bottom because it is more likely than other notifications to be visible for a long time

name='save-reminder',
desc='Shows a reminder if it has been more than '.. save_time_threshold_mins ..' minute(s) since your last save.',
default=true,
fn=get_save_alert,
on_click=save_popup
},
{
name='stuck_squad',
desc='Notifies when a squad is stuck on the world map.',
Expand Down Expand Up @@ -524,23 +563,6 @@ NOTIFICATIONS_BY_IDX = {
adv_fn=curry(get_bar, get_blood, get_max_blood, "Blood", COLOR_RED),
on_click=nil,
},
{
name='save-reminder',
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 "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,
},
}

NOTIFICATIONS_BY_NAME = {}
Expand Down