Skip to content

Commit 40f3913

Browse files
committed
Merge branch 'master' into HEAD
2 parents 3c3fa05 + 637eb47 commit 40f3913

File tree

4 files changed

+55
-21
lines changed

4 files changed

+55
-21
lines changed

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ 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
50+
- `prioritize`: when prioritizing jobs of a specified type, also output how many of those jobs were already prioritized before you ran the command
51+
- `prioritize`: don't include already-prioritized jobs in the output of ``prioritize -j``
4852

4953
## Removed
5054

docs/prioritize.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ prioritize
77

88
This tool encourages specified types of jobs to get assigned and completed as
99
soon as possible. Finally, you can be sure your food will be hauled before
10-
rotting, your hides will be tanned before going bad, and the corpses of your
10+
it rots, your hides will be tanned before they go bad, and the corpses of your
1111
enemies will be cleared expediently from your entranceway.
1212

1313
You can prioritize a bunch of active jobs that you need done *right now*, or you
@@ -40,7 +40,8 @@ Examples
4040
Watch for and prioritize the default set of job types that the community has
4141
suggested and playtested (see below for details).
4242
``prioritize -j``
43-
Print out the list of active jobs that you can prioritize right now.
43+
Print out the list of not-yet prioritized jobs that you can prioritize
44+
right now.
4445
``prioritize ConstructBuilding DestroyBuilding``
4546
Prioritize all current building construction and destruction jobs.
4647
``prioritize -a --haul-labor=Food,Body StoreItemInStockpile``
@@ -56,8 +57,7 @@ Options
5657
``-d``, ``--delete``
5758
Stop automatically prioritizing new jobs of the specified job types.
5859
``-j``, ``--jobs``
59-
Print out how many current jobs of each type there are. This is useful for
60-
discovering the types of the jobs that you can prioritize right now. If any
60+
Print out how many current unprioritized jobs of each type there are. If any
6161
job types are specified, only jobs of those types are listed.
6262
``-l``, ``--haul-labor <labor>[,<labor>...]``
6363
For StoreItemInStockpile jobs, match only the specified hauling labor(s).
@@ -97,7 +97,7 @@ staring at the screen in annoyance for too long.
9797
You may be tempted to automatically prioritize ``ConstructBuilding`` jobs, but
9898
beware that if you engage in megaprojects where many constructions must be
9999
built, these jobs can consume your entire fortress if prioritized. It is often
100-
better to run ``prioritize ConstructBuilding`` by itself (i.e. without the
100+
better to run ``prioritize ConstructBuilding`` by itself (that is, without the
101101
``-a`` parameter) as needed to just prioritize the construction jobs that you
102102
have ready at the time if you need to "clear the queue".
103103

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

prioritize.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,23 @@ local function for_all_jobs(cb)
192192
end
193193

194194
local function boost(job_matchers, opts)
195-
local count = 0
195+
local count, already_prioritized = 0, 0
196196
for_all_jobs(
197197
function(job)
198-
if not job.flags.do_now and boost_job_if_matches(job, job_matchers) then
199-
count = count + 1
198+
local was_prioritized = job.flags.do_now
199+
if boost_job_if_matches(job, job_matchers) then
200+
if was_prioritized then
201+
already_prioritized = already_prioritized + 1
202+
else
203+
count = count + 1
204+
end
200205
end
201206
end)
202207
if not opts.quiet then
203208
print(('Prioritized %d job%s.'):format(count, count == 1 and '' or 's'))
209+
if already_prioritized > 0 then
210+
print(('%d job%s already prioritized.'):format(already_prioritized, already_prioritized == 1 and '' or 's'))
211+
end
204212
end
205213
end
206214

@@ -440,6 +448,7 @@ local function print_current_jobs(job_matchers, opts)
440448
local filtered = next(job_matchers)
441449
local function count_job(jobs, job)
442450
if filtered and not job_matchers[job.job_type] then return end
451+
if job.flags.do_now then return end
443452
local job_type = get_job_type_str(job)
444453
jobs[job_type] = (jobs[job_type] or 0) + 1
445454
end

0 commit comments

Comments
 (0)