@@ -227,54 +227,30 @@ function DifficultySettingsOverlay:get_df_struct()
227
227
end
228
228
229
229
---- --------------------------
230
- -- StandingOrdersOverlay
230
+ -- ImportExportAutoOverlay
231
231
--
232
232
233
- StandingOrdersOverlay = defclass (StandingOrdersOverlay , overlay .OverlayWidget )
234
- StandingOrdersOverlay .ATTRS {
235
- desc = ' Adds buttons to the standing orders screen for saving and restoring settings.' ,
236
- default_pos = {x = 6 , y =- 5 },
237
- viewscreens = ' dwarfmode/Info/LABOR/STANDING_ORDERS/AUTOMATED_WORKSHOPS' ,
233
+ ImportExportAutoOverlay = defclass (ImportExportAutoOverlay , overlay .OverlayWidget )
234
+ ImportExportAutoOverlay .ATTRS {
238
235
default_enabled = true ,
239
- frame = {w = 78 , h = 5 },
240
236
frame_style = gui .MEDIUM_FRAME ,
241
237
frame_background = gui .CLEAR_PEN ,
238
+ save_label = DEFAULT_NIL ,
239
+ load_label = DEFAULT_NIL ,
240
+ auto_label = DEFAULT_NIL ,
241
+ save_fn = DEFAULT_NIL ,
242
+ load_fn = DEFAULT_NIL ,
243
+ has_data_fn = DEFAULT_NIL ,
244
+ autostart_command = DEFAULT_NIL ,
242
245
}
243
246
244
- local li = df .global .plotinfo .labor_info
245
-
246
- local function save_standing_orders ()
247
- local standing_orders = {}
248
- for name , val in pairs (df .global ) do
249
- if name :startswith (' standing_orders_' ) then
250
- standing_orders [name ] = val
251
- end
252
- end
253
- config .data .standing_orders = standing_orders
254
- local chores = {}
255
- chores .enabled = li .flags .children_do_chores
256
- chores .labors = utils .clone (li .chores )
257
- config .data .chores = chores
258
- config :write ()
259
- end
260
-
261
- local function load_standing_orders ()
262
- for name , val in pairs (config .data .standing_orders or {}) do
263
- df .global [name ] = val
264
- end
265
- li .flags .children_do_chores = not not safe_index (config .data .chores , ' enabled' )
266
- for i , val in ipairs (safe_index (config .data .chores , ' labors' ) or {}) do
267
- li .chores [i - 1 ] = val
268
- end
269
- end
270
-
271
- function StandingOrdersOverlay :init ()
247
+ function ImportExportAutoOverlay :init ()
272
248
self :addviews {
273
249
widgets .HotkeyLabel {
274
250
view_id = ' save' ,
275
251
frame = {l = 0 , t = 0 , w = 39 },
276
252
key = ' CUSTOM_CTRL_E' ,
277
- label = ' Save standing orders (all tabs) ' ,
253
+ label = self . save_label ,
278
254
on_activate = self :callback (' do_save' ),
279
255
},
280
256
widgets .Label {
@@ -288,9 +264,9 @@ function StandingOrdersOverlay:init()
288
264
view_id = ' load' ,
289
265
frame = {l = 42 , t = 0 , w = 34 },
290
266
key = ' CUSTOM_CTRL_I' ,
291
- label = ' Load saved standing orders ' ,
267
+ label = self . load_label ,
292
268
on_activate = self :callback (' do_load' ),
293
- enabled = function () return next ( config . data . standing_orders or {}) end ,
269
+ enabled = self . has_data_fn ,
294
270
},
295
271
widgets .Label {
296
272
view_id = ' load_flash' ,
@@ -303,38 +279,37 @@ function StandingOrdersOverlay:init()
303
279
view_id = ' auto' ,
304
280
frame = {l = 0 , t = 2 },
305
281
key = ' CUSTOM_CTRL_A' ,
306
- label = ' Apply saved settings for new embarks: ' ,
282
+ label = self . auto_label ,
307
283
on_change = self :callback (' do_auto' ),
308
- enabled = function () return next ( config . data . standing_orders or {}) end ,
284
+ enabled = self . has_data_fn ,
309
285
},
310
286
}
311
287
end
312
288
313
- function StandingOrdersOverlay :do_save ()
289
+ function ImportExportAutoOverlay :do_save ()
314
290
flash (self , ' save' )
315
- save_standing_orders ()
291
+ self . save_fn ()
316
292
end
317
293
318
- function StandingOrdersOverlay :do_load ()
294
+ function ImportExportAutoOverlay :do_load ()
319
295
flash (self , ' load' )
320
- load_standing_orders ()
296
+ self . load_fn ()
321
297
end
322
298
323
- local autostart_command = ' gui/settings-manager load-standing-orders'
324
-
325
- SOMessage = defclass (SOMessage , widgets .Window )
326
- SOMessage .ATTRS {
299
+ AutoMessage = defclass (AutoMessage , widgets .Window )
300
+ AutoMessage .ATTRS {
327
301
frame = {w = 61 , h = 9 },
302
+ autostart_command = DEFAULT_NIL ,
328
303
enabled = DEFAULT_NIL ,
329
304
}
330
305
331
- function SOMessage :init ()
306
+ function AutoMessage :init ()
332
307
self :addviews {
333
308
widgets .Label {
334
309
view_id = ' label' ,
335
310
frame = {t = 0 , l = 0 },
336
311
text = {
337
- ' The "' , autostart_command , ' " command' , NEWLINE ,
312
+ ' The "' , self . autostart_command , ' " command' , NEWLINE ,
338
313
' has been ' ,
339
314
{text = self .enabled and ' enabled' or ' disabled' , pen = self .enabled and COLOR_GREEN or COLOR_LIGHTRED },
340
315
' in the ' ,
@@ -363,37 +338,173 @@ function SOMessage:init()
363
338
}
364
339
end
365
340
366
- SOMessageScreen = defclass (SOMessageScreen , gui .ZScreenModal )
367
- SOMessageScreen .ATTRS {
341
+ AutoMessageScreen = defclass (AutoMessageScreen , gui .ZScreenModal )
342
+ AutoMessageScreen .ATTRS {
368
343
focus_path = ' settings-manager/prompt' ,
344
+ autostart_command = DEFAULT_NIL ,
369
345
enabled = DEFAULT_NIL ,
370
346
}
371
347
372
- function SOMessageScreen :init ()
348
+ function AutoMessageScreen :init ()
373
349
self :addviews {
374
- SOMessage {
350
+ AutoMessage {
375
351
frame_title = (self .enabled and ' Enabled' or ' Disabled' ).. ' auto-restore' ,
376
- enabled = self .enabled
352
+ autostart_command = self .autostart_command ,
353
+ enabled = self .enabled ,
377
354
},
378
355
}
379
356
end
380
357
381
- function StandingOrdersOverlay :do_auto (val )
382
- dfhack .run_script (' control-panel' , (val and ' ' or ' no' ) .. ' autostart' , autostart_command )
383
- SOMessageScreen { enabled = val }:show ()
358
+ function ImportExportAutoOverlay :do_auto (val )
359
+ dfhack .run_script (' control-panel' , (val and ' ' or ' no' ) .. ' autostart' , self . autostart_command )
360
+ AutoMessageScreen { autostart_command = self . autostart_command , enabled = val }:show ()
384
361
end
385
362
386
- function StandingOrdersOverlay :onRenderFrame (dc , rect )
387
- StandingOrdersOverlay .super .onRenderFrame (self , dc , rect )
388
- local enabled = control_panel .get_autostart (autostart_command )
363
+ function ImportExportAutoOverlay :onRenderFrame (dc , rect )
364
+ ImportExportAutoOverlay .super .onRenderFrame (self , dc , rect )
365
+ local enabled = control_panel .get_autostart (self . autostart_command )
389
366
self .subviews .auto :setOption (enabled )
390
367
end
391
368
369
+ ---- --------------------------
370
+ -- StandingOrdersOverlay
371
+ --
372
+
373
+ local li = df .global .plotinfo .labor_info
374
+
375
+ local function save_standing_orders ()
376
+ local standing_orders = {}
377
+ for name , val in pairs (df .global ) do
378
+ if name :startswith (' standing_orders_' ) then
379
+ standing_orders [name ] = val
380
+ end
381
+ end
382
+ config .data .standing_orders = standing_orders
383
+ local chores = {}
384
+ chores .enabled = li .flags .children_do_chores
385
+ chores .labors = utils .clone (li .chores )
386
+ config .data .chores = chores
387
+ config :write ()
388
+ end
389
+
390
+ local function load_standing_orders ()
391
+ for name , val in pairs (config .data .standing_orders or {}) do
392
+ df .global [name ] = val
393
+ end
394
+ li .flags .children_do_chores = not not safe_index (config .data .chores , ' enabled' )
395
+ for i , val in ipairs (safe_index (config .data .chores , ' labors' ) or {}) do
396
+ li .chores [i - 1 ] = val
397
+ end
398
+ end
399
+
400
+ local function has_saved_standing_orders ()
401
+ return next (config .data .standing_orders or {})
402
+ end
403
+
404
+ StandingOrdersOverlay = defclass (StandingOrdersOverlay , ImportExportAutoOverlay )
405
+ StandingOrdersOverlay .ATTRS {
406
+ desc = ' Adds buttons to the standing orders screen for saving and restoring settings.' ,
407
+ default_pos = {x = 6 , y =- 5 },
408
+ viewscreens = ' dwarfmode/Info/LABOR/STANDING_ORDERS/AUTOMATED_WORKSHOPS' ,
409
+ frame = {w = 78 , h = 5 },
410
+ save_label = ' Save standing orders (all tabs)' ,
411
+ load_label = ' Load saved standing orders' ,
412
+ auto_label = ' Apply saved settings for new embarks:' ,
413
+ save_fn = save_standing_orders ,
414
+ load_fn = load_standing_orders ,
415
+ has_data_fn = has_saved_standing_orders ,
416
+ autostart_command = ' gui/settings-manager load-standing-orders' ,
417
+ }
418
+
419
+ ---- --------------------------
420
+ -- WorkDetailsOverlay
421
+ --
422
+
423
+ local function clone_wd_flags (flags )
424
+ return {
425
+ cannot_be_everybody = flags .cannot_be_everybody ,
426
+ no_modify = flags .no_modify ,
427
+ mode = flags .mode ,
428
+ }
429
+ end
430
+
431
+ local function save_work_details ()
432
+ local details = {}
433
+ for idx , wd in ipairs (li .work_details ) do
434
+ local detail = {
435
+ name = wd .name ,
436
+ icon = wd .icon ,
437
+ work_detail_flags = clone_wd_flags (wd .work_detail_flags ),
438
+ allowed_labors = utils .clone (wd .allowed_labors ),
439
+ }
440
+ details [idx + 1 ] = detail
441
+ end
442
+ config .data .work_details = details
443
+ config :write ()
444
+ end
445
+
446
+ local function load_work_details ()
447
+ if not config .data .work_details or # config .data .work_details < 10 then
448
+ -- not enough data to cover built-in work details
449
+ return
450
+ end
451
+ li .work_details :resize (# config .data .work_details )
452
+ -- keep unit assignments for overwritten indices
453
+ for idx , wd in ipairs (config .data .work_details ) do
454
+ local detail = {
455
+ new = df .work_detail ,
456
+ name = wd .name ,
457
+ icon = wd .icon ,
458
+ work_detail_flags = wd .work_detail_flags ,
459
+ }
460
+ li .work_details [idx - 1 ] = detail
461
+ local al = li .work_details [idx - 1 ].allowed_labors
462
+ for i ,v in ipairs (wd .allowed_labors ) do
463
+ al [i - 1 ] = v
464
+ end
465
+ end
466
+ local scr = dfhack .gui .getDFViewscreen (true )
467
+ if dfhack .gui .matchFocusString (' dwarfmode/Info/LABOR/WORK_DETAILS' , scr ) then
468
+ gui .simulateInput (scr , ' LEAVESCREEN' )
469
+ gui .simulateInput (scr , ' D_LABOR' )
470
+ end
471
+ end
472
+
473
+ local function has_saved_work_details ()
474
+ return next (config .data .work_details or {})
475
+ end
476
+
477
+ WorkDetailsOverlay = defclass (WorkDetailsOverlay , ImportExportAutoOverlay )
478
+ WorkDetailsOverlay .ATTRS {
479
+ desc = ' Adds buttons to the work details screen for saving and restoring settings.' ,
480
+ default_pos = {x = 80 , y =- 5 },
481
+ viewscreens = ' dwarfmode/Info/LABOR/WORK_DETAILS' ,
482
+ frame = {w = 35 , h = 5 },
483
+ save_label = ' Save work details' ,
484
+ load_label = ' Load work details' ,
485
+ auto_label = ' Load for new embarks:' ,
486
+ save_fn = save_work_details ,
487
+ load_fn = load_work_details ,
488
+ has_data_fn = has_saved_work_details ,
489
+ autostart_command = ' gui/settings-manager load-work-details' ,
490
+ }
491
+
492
+ function WorkDetailsOverlay :init ()
493
+ self .subviews .save .frame .w = 25
494
+ self .subviews .save_flash .frame .l = 10
495
+ self .subviews .load .frame .t = 1
496
+ self .subviews .load .frame .l = 0
497
+ self .subviews .load .frame .w = 25
498
+ self .subviews .load_flash .frame .t = 1
499
+ self .subviews .load_flash .frame .l = 10
500
+ end
501
+
392
502
OVERLAY_WIDGETS = {
393
503
embark_difficulty = DifficultyEmbarkOverlay ,
394
504
embark_notification = DifficultyEmbarkNotificationOverlay ,
395
505
settings_difficulty = DifficultySettingsOverlay ,
396
506
standing_orders = StandingOrdersOverlay ,
507
+ work_details = WorkDetailsOverlay ,
397
508
}
398
509
399
510
if dfhack_flags .module then
@@ -447,6 +558,16 @@ elseif command == 'load-standing-orders' then
447
558
else
448
559
qerror (' must be in a loaded fort' )
449
560
end
561
+ elseif command == ' save-work-details' then
562
+ if is_fort then save_work_details ()
563
+ else
564
+ qerror (' must be in a loaded fort' )
565
+ end
566
+ elseif command == ' load-work-details' then
567
+ if is_fort then load_work_details ()
568
+ else
569
+ qerror (' must be in a loaded fort' )
570
+ end
450
571
else
451
572
print (dfhack .script_help ())
452
573
end
0 commit comments