Skip to content

Commit d642880

Browse files
committed
Feedback/improvements
1 parent a7f269b commit d642880

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

trackstop.lua

+19-31
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ local function swapElements(tbl, index1, index2)
5858
end
5959

6060
local function reset_guide_paths(conditions)
61-
for _i, condition in ipairs(conditions) do
61+
for _, condition in ipairs(conditions) do
6262
local gpath = condition.guide_path
6363

6464
if gpath then
@@ -260,19 +260,18 @@ function RollerOverlay:init()
260260
}
261261
end
262262

263-
selected_stop = selected_stop or nil
264-
265263
ReorderStopsWindow = defclass(ReorderStopsWindow, widgets.Window)
266264
ReorderStopsWindow.ATTRS {
267265
frame={t=4,l=60,w=45, h=28},
268266
frame_title='Reorder Stops',
269-
view_id='main',
267+
resizable=true,
270268
}
271269

272270
local SELECT_STOP_HINT = 'Select a stop to move'
273271
local SELECT_ANOTHER_STOP_HINT = 'Select another stop on the same route'
274272

275273
function ReorderStopsWindow:init()
274+
self.selected_stop = nil
276275
self:addviews{
277276
widgets.Label{
278277
frame={t=0,l=0},
@@ -283,18 +282,15 @@ function ReorderStopsWindow:init()
283282
view_id='routes',
284283
frame={t=1,l=1},
285284
choices={},
286-
on_select=function(index, item)
285+
on_select=function(_, item)
287286
if not item then return end
288287
if item.type == 'stop' then
289288
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)
294290
end
295291
end,
296292
on_submit=function(index, item)
297-
if selected_stop then
293+
if self.selected_stop then
298294
local hauling = df.global.plotinfo.hauling
299295
local routes = hauling.routes
300296
local view_stops = hauling.view_stops
@@ -304,26 +300,26 @@ function ReorderStopsWindow:init()
304300
if item.type == 'stop' then
305301
local stop_index = item.stop_index
306302

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
308304
if selected_stop.route_index ~= item.route_index then
309305
return
310306
end
311307

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)
314310

315311
-- 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
317313
for i, stop in ipairs(route.stops) do
318314
stop.id = i + 1
319315
reset_guide_paths(stop.conditions)
320316
end
321317

322-
selected_stop = nil
318+
self.selected_stop = nil
323319
end
324320
else
325321
if item.stop_index then
326-
selected_stop = item
322+
self.selected_stop = item
327323
end
328324
end
329325

@@ -340,7 +336,7 @@ function ReorderStopsWindow:updateList()
340336
local choices = {}
341337
local list_position = 0
342338

343-
if selected_stop then
339+
if self.selected_stop then
344340
self.subviews.hint:setText(SELECT_ANOTHER_STOP_HINT)
345341
else
346342
self.subviews.hint:setText(SELECT_STOP_HINT)
@@ -364,7 +360,7 @@ function ReorderStopsWindow:updateList()
364360
stop_name = 'Stop ' .. stop.id
365361
end
366362

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
368364
stop_name = '=> ' .. stop_name
369365
end
370366

@@ -389,8 +385,6 @@ function ReorderStopsModal:init()
389385
end
390386

391387
function ReorderStopsModal:onDismiss()
392-
reorder_stops_modal = nil
393-
selected_stop = nil
394388
df.global.game.main_interface.recenter_indicator_m.x = -30000
395389
df.global.game.main_interface.recenter_indicator_m.y = -30000
396390
df.global.game.main_interface.recenter_indicator_m.z = -30000
@@ -407,17 +401,11 @@ ReorderStopsOverlay.ATTRS{
407401

408402
function ReorderStopsOverlay:init()
409403
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,
421409
},
422410
}
423411
end

0 commit comments

Comments
 (0)