134134
135135local function checkForWorkshop ()
136136 if not next (allowed ) then
137- print (' no available workshops, disabling' )
137+ -- print('no available workshops, disabling')
138138 stop ()
139139 end
140140end
@@ -191,10 +191,10 @@ local function processUnit(workshop, idx, unit_id)
191191 watched [idx ][unit_id ] = nil
192192 return false
193193 elseif not canAccessWorkshop (unit , workshop ) then
194- dfhack .print (' -' )
194+ -- dfhack.print('-')
195195 return false
196196 elseif not unitIsAvailable (unit ) then
197- dfhack .print (' .' )
197+ -- dfhack.print('.')
198198 return false
199199 end
200200 -- We have an available unit
@@ -205,10 +205,9 @@ local function processUnit(workshop, idx, unit_id)
205205 if not success and workshop .profile .blocked_labors [BONE_CARVE ] == false then
206206 success = makeBoneCraft (unit , workshop )
207207 end
208- local name = (dfhack .TranslateName (dfhack .units .getVisibleName (unit )))
209208 if success then
210209 -- Why is the encoding still wrong, even when using df2console?
211- print (' assigned ' .. dfhack .df2console (name ))
210+ print (' idle-crafting: assigned crafting job to ' .. dfhack .df2console (dfhack . units . getReadableName ( unit ) ))
212211 watched [idx ][unit_id ] = nil
213212 allowed [workshop .id ] = df .global .world .frame_counter
214213 else
@@ -239,7 +238,7 @@ local function unit_loop()
239238 local workshop = locateWorkshop (workshop_id )
240239 -- workshop may have been destroyed, assigned a master, or does not allow crafting
241240 if not workshop or invalidProfile (workshop ) then
242- print (' workshop destroyed or has invalid profile' )
241+ -- print('workshop destroyed or has invalid profile')
243242 allowed [workshop_id ] = nil -- clearing during iteration is permitted
244243 goto next_workshop
245244 end
@@ -251,14 +250,14 @@ local function unit_loop()
251250
252251 -- check that we didn't schedule a job on the last iteration
253252 if (last_job_frame >= 0 ) and (current_frame < last_job_frame + 60 ) then
254- print ((' idle-crafting: disabling failing workshop (%d) until the next run of main loop' ):
255- format (workshop_id ))
253+ -- print(('idle-crafting: disabling failing workshop (%d) until the next run of main loop'):
254+ -- format(workshop_id))
256255 failing [workshop_id ] = true
257256 goto next_workshop
258257 end
259258
260- dfhack .print ((' idle-crafting: locating crafter for %s (%d)' ):
261- format (dfhack .buildings .getName (workshop ), workshop_id ))
259+ -- dfhack.print(('idle-crafting: locating crafter for %s (%d)'):
260+ -- format(dfhack.buildings.getName(workshop), workshop_id))
262261
263262 -- workshop is free to use, try to find a unit
264263 for idx , _ in ipairs (thresholds ) do
@@ -267,10 +266,10 @@ local function unit_loop()
267266 goto next_workshop
268267 end
269268 end
270- dfhack .print (' /' )
269+ -- dfhack.print('/')
271270 end
272271
273- print (' no unit found' )
272+ -- print('no unit found')
274273 :: next_workshop::
275274 end
276275 -- disable loop if there are no more units
@@ -283,7 +282,7 @@ local function unit_loop()
283282end
284283
285284local function main_loop ()
286- print (' idle crafting: running main loop' )
285+ -- print('idle crafting: running main loop')
287286 checkForWorkshop ()
288287 if not enabled then
289288 return
@@ -315,9 +314,9 @@ local function main_loop()
315314 end
316315 :: continue::
317316 end
318- print ((' watching %s dwarfs with crafting needs' ):format (
319- table.concat (num_watched , ' /' )
320- ))
317+ -- print(('watching %s dwarfs with crafting needs'):format(
318+ -- table.concat(num_watched, '/')
319+ -- ))
321320
322321 if watching then
323322 repeatutil .scheduleUnlessAlreadyScheduled (GLOBAL_KEY .. ' unit' , 53 , ' ticks' , unit_loop )
@@ -361,23 +360,32 @@ IdleCraftingOverlay.ATTRS {
361360 viewscreens = {
362361 ' dwarfmode/ViewSheets/BUILDING/Workshop/Craftsdwarfs/Workers' ,
363362 },
364- frame = { w = 55 , h = 1 },
363+ frame = { w = 54 , h = 1 },
365364}
366365
367366function IdleCraftingOverlay :init ()
368367 self :addviews {
369- widgets .CycleHotkeyLabel {
370- view_id = ' leisure_toggle' ,
371- frame = { l = 0 , t = 0 },
372- label = ' Allow idle dwarves to satisfy crafting needs:' ,
373- key = ' CUSTOM_I' ,
374- options = {
375- { label = ' yes' , value = true , pen = COLOR_GREEN },
376- { label = ' no' , value = false },
368+ widgets .BannerPanel {
369+ subviews = {
370+ widgets .CycleHotkeyLabel {
371+ view_id = ' leisure_toggle' ,
372+ frame = { t = 0 , l = 1 , r = 1 },
373+ label = ' Allow idle dwarves to satisfy crafting needs:' ,
374+ key = ' CUSTOM_I' ,
375+ options = {
376+ { label = ' yes' , value = true , pen = COLOR_GREEN },
377+ { label = ' no' , value = false },
378+ },
379+ initial_option = ' no' ,
380+ on_change = self :callback (' onClick' ),
381+ enabled = function ()
382+ local bld = dfhack .gui .getSelectedBuilding (true )
383+ if not bld then return end
384+ return not invalidProfile (bld )
385+ end ,
386+ }
377387 },
378- initial_option = ' no' ,
379- on_change = self :callback (' onClick' ),
380- }
388+ },
381389 }
382390end
383391
@@ -414,14 +422,12 @@ if dfhack_flags.module then
414422end
415423
416424if df .global .gamemode ~= df .game_mode .DWARF then
417- print (' this tool requires a loaded fort' )
418- return
425+ qerror (' this tool requires a loaded fort' )
419426end
420427
421428if dfhack_flags .enable then
422429 if dfhack_flags .enable_state then
423- print (' This tool is enabled by permitting idle crafting at a Craftsdarf\' s workshop' )
424- return
430+ qerror (' This tool is enabled by permitting idle crafting at a Craftsdarf\' s workshop' )
425431 else
426432 allowed = {}
427433 stop ()
0 commit comments