@@ -58,7 +58,7 @@ local function swapElements(tbl, index1, index2)
58
58
end
59
59
60
60
local function reset_guide_paths (conditions )
61
- for _i , condition in ipairs (conditions ) do
61
+ for _ , condition in ipairs (conditions ) do
62
62
local gpath = condition .guide_path
63
63
64
64
if gpath then
@@ -260,19 +260,18 @@ function RollerOverlay:init()
260
260
}
261
261
end
262
262
263
- selected_stop = selected_stop or nil
264
-
265
263
ReorderStopsWindow = defclass (ReorderStopsWindow , widgets .Window )
266
264
ReorderStopsWindow .ATTRS {
267
265
frame = {t = 4 ,l = 60 ,w = 45 , h = 28 },
268
266
frame_title = ' Reorder Stops' ,
269
- view_id = ' main ' ,
267
+ resizable = true ,
270
268
}
271
269
272
270
local SELECT_STOP_HINT = ' Select a stop to move'
273
271
local SELECT_ANOTHER_STOP_HINT = ' Select another stop on the same route'
274
272
275
273
function ReorderStopsWindow :init ()
274
+ self .selected_stop = nil
276
275
self :addviews {
277
276
widgets .Label {
278
277
frame = {t = 0 ,l = 0 },
@@ -283,18 +282,15 @@ function ReorderStopsWindow:init()
283
282
view_id = ' routes' ,
284
283
frame = {t = 1 ,l = 1 },
285
284
choices = {},
286
- on_select = function (index , item )
285
+ on_select = function (_ , item )
287
286
if not item then return end
288
287
if item .type == ' stop' then
289
288
local item_pos = df .global .plotinfo .hauling .routes [item .route_index ].stops [item .stop_index ].pos
290
- df .global .game .main_interface .recenter_indicator_m .x = item_pos .x
291
- df .global .game .main_interface .recenter_indicator_m .y = item_pos .y
292
- df .global .game .main_interface .recenter_indicator_m .z = item_pos .z
293
- dfhack .gui .revealInDwarfmodeMap (item_pos , true )
289
+ dfhack .gui .revealInDwarfmodeMap (item_pos , true , true )
294
290
end
295
291
end ,
296
292
on_submit = function (index , item )
297
- if selected_stop then
293
+ if self . selected_stop then
298
294
local hauling = df .global .plotinfo .hauling
299
295
local routes = hauling .routes
300
296
local view_stops = hauling .view_stops
@@ -304,26 +300,26 @@ function ReorderStopsWindow:init()
304
300
if item .type == ' stop' then
305
301
local stop_index = item .stop_index
306
302
307
- -- don't allow moving stops to a different route
303
+ -- don't allow moving stops to a different route for now. TODO: investigate this
308
304
if selected_stop .route_index ~= item .route_index then
309
305
return
310
306
end
311
307
312
- swapElements (route .stops , stop_index , selected_stop .stop_index )
313
- swapElements (view_stops , selected_stop .list_position , index - 1 )
308
+ swapElements (route .stops , stop_index , self . selected_stop .stop_index )
309
+ swapElements (view_stops , self . selected_stop .list_position , index - 1 )
314
310
315
311
-- loop over each stop in the route, make the ids sequental and reset guide paths
316
- -- TODO: what else does this break?
312
+ -- TODO: figure out if changing the ids here breaks anything else
317
313
for i , stop in ipairs (route .stops ) do
318
314
stop .id = i + 1
319
315
reset_guide_paths (stop .conditions )
320
316
end
321
317
322
- selected_stop = nil
318
+ self . selected_stop = nil
323
319
end
324
320
else
325
321
if item .stop_index then
326
- selected_stop = item
322
+ self . selected_stop = item
327
323
end
328
324
end
329
325
@@ -340,7 +336,7 @@ function ReorderStopsWindow:updateList()
340
336
local choices = {}
341
337
local list_position = 0
342
338
343
- if selected_stop then
339
+ if self . selected_stop then
344
340
self .subviews .hint :setText (SELECT_ANOTHER_STOP_HINT )
345
341
else
346
342
self .subviews .hint :setText (SELECT_STOP_HINT )
@@ -364,7 +360,7 @@ function ReorderStopsWindow:updateList()
364
360
stop_name = ' Stop ' .. stop .id
365
361
end
366
362
367
- if selected_stop and selected_stop .list_position == list_position then
363
+ if self . selected_stop and self . selected_stop .list_position == list_position then
368
364
stop_name = ' => ' .. stop_name
369
365
end
370
366
@@ -389,8 +385,6 @@ function ReorderStopsModal:init()
389
385
end
390
386
391
387
function ReorderStopsModal :onDismiss ()
392
- reorder_stops_modal = nil
393
- selected_stop = nil
394
388
df .global .game .main_interface .recenter_indicator_m .x = - 30000
395
389
df .global .game .main_interface .recenter_indicator_m .y = - 30000
396
390
df .global .game .main_interface .recenter_indicator_m .z = - 30000
@@ -407,17 +401,11 @@ ReorderStopsOverlay.ATTRS{
407
401
408
402
function ReorderStopsOverlay :init ()
409
403
self :addviews {
410
- widgets .BannerPanel {
411
- subviews = {
412
- widgets .HotkeyLabel {
413
- frame = {t = 0 , l = 1 , r = 1 },
414
- label = ' DFHack reorder stops' ,
415
- key = ' CUSTOM_CTRL_E' ,
416
- on_activate = function ()
417
- reorder_stops_modal = reorder_stops_modal and reorder_stops_modal :raise () or ReorderStopsModal {}:show ()
418
- end ,
419
- },
420
- },
404
+ widgets .TextButton {
405
+ frame = {t = 0 , l = 0 },
406
+ label = ' DFHack reorder stops' ,
407
+ key = ' CUSTOM_CTRL_E' ,
408
+ on_activate = function () ReorderStopsModal {}:show () end ,
421
409
},
422
410
}
423
411
end
0 commit comments