Skip to content

Commit eba5ea9

Browse files
committed
Feedback
1 parent c7dd669 commit eba5ea9

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

docs/trackstop.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ trackstop
22
=========
33

44
.. dfhack-tool::
5-
:summary: Overlay to allow changing track stop friction and dump direction and roller direction and speed after construction.
6-
:tags: fort gameplay buildings interface
5+
:summary: Add dynamic configuration options for track stops.
6+
:tags: fort buildings interface
77

8-
This script provides 2 overlays that are managed by the `overlay` framework.
8+
This script provides 2 overlays that are managed by the `overlay` framework. The script does nothing when executed.
99
The trackstop overlay allows the player to change the friction and dump direction of a selected track stop after it has been constructed.
10-
The rollers overlay allows the player to change the roller direction and speed of a selected track stop after it has been constructed.
10+
The rollers overlay allows the player to change the roller direction and speed of a selected roller after it has been constructed.

trackstop.lua

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
-- Overlay to allow changing track stop friction and dump direction after construction
22
--@ module = true
3+
4+
if not dfhack_flags.module then
5+
qerror('trackstop cannot be called directly')
6+
end
7+
38
local gui = require('gui')
49
local widgets = require('gui.widgets')
510
local overlay = require('plugins.overlay')
11+
local utils = require('utils')
612

7-
local NORTH = 'North'
8-
local EAST = 'East'
9-
local SOUTH = 'South'
10-
local WEST = 'West'
13+
local NORTH = 'North ^'
14+
local EAST = 'East >'
15+
local SOUTH = 'South v'
16+
local WEST = 'West <'
1117

1218
local LOW = 'Low'
1319
local MEDIUM = 'Medium'
@@ -25,10 +31,7 @@ local FRICTION_MAP = {
2531
[MAX] = 50000,
2632
}
2733

28-
local FRICTION_MAP_REVERSE = {}
29-
for k, v in pairs(FRICTION_MAP) do
30-
FRICTION_MAP_REVERSE[v] = k
31-
end
34+
local FRICTION_MAP_REVERSE = utils.invert(FRICTION_MAP)
3235

3336
local SPEED_MAP = {
3437
[LOW] = 10000,
@@ -38,10 +41,7 @@ local SPEED_MAP = {
3841
[MAX] = 50000,
3942
}
4043

41-
local SPEED_MAP_REVERSE = {}
42-
for k, v in pairs(SPEED_MAP) do
43-
SPEED_MAP_REVERSE[v] = k
44-
end
44+
local SPEED_MAP_REVERSE = utils.invert(SPEED_MAP)
4545

4646
local DIRECTION_MAP = {
4747
[NORTH] = df.screw_pump_direction.FromSouth,
@@ -50,17 +50,14 @@ local DIRECTION_MAP = {
5050
[WEST] = df.screw_pump_direction.FromEast,
5151
}
5252

53-
local DIRECTION_MAP_REVERSE = {}
54-
for k, v in pairs(DIRECTION_MAP) do
55-
DIRECTION_MAP_REVERSE[v] = k
56-
end
53+
local DIRECTION_MAP_REVERSE = utils.invert(DIRECTION_MAP)
5754

5855
TrackStopOverlay = defclass(TrackStopOverlay, overlay.OverlayWidget)
5956
TrackStopOverlay.ATTRS{
60-
default_pos={x=-71, y=29},
57+
default_pos={x=-73, y=29},
6158
default_enabled=true,
6259
viewscreens='dwarfmode/ViewSheets/BUILDING/Trap',
63-
frame={w=27, h=4},
60+
frame={w=25, h=4},
6461
frame_style=gui.MEDIUM_FRAME,
6562
frame_background=gui.CLEAR_PEN,
6663
}
@@ -152,25 +149,31 @@ end
152149

153150
function TrackStopOverlay:init()
154151
self:addviews{
155-
widgets.Label{
156-
frame={t=0, l=0},
157-
text='Dump',
158-
},
159152
widgets.CycleHotkeyLabel{
160-
frame={t=0, l=9},
153+
frame={t=0, l=0},
154+
label='Dump',
161155
key='CUSTOM_CTRL_X',
162-
options={NONE, NORTH, EAST, SOUTH, WEST},
156+
options={
157+
{label=NONE, value=NONE, pen=COLOR_BLUE},
158+
NORTH,
159+
EAST,
160+
SOUTH,
161+
WEST,
162+
},
163163
view_id='dump_direction',
164164
on_change=function(val) self:setDumpDirection(val) end,
165165
},
166-
widgets.Label{
167-
frame={t=1, l=0},
168-
text='Friction',
169-
},
170166
widgets.CycleHotkeyLabel{
171-
frame={t=1, l=9},
167+
label='Friction',
168+
frame={t=1, l=0},
172169
key='CUSTOM_CTRL_F',
173-
options={NONE, LOW, MEDIUM, HIGH, MAX},
170+
options={
171+
{label=NONE, value=NONE, pen=COLOR_BLUE},
172+
{label=LOW, value=LOW, pen=COLOR_GREEN},
173+
{label=MEDIUM, value=MEDIUM, pen=COLOR_YELLOW},
174+
{label=HIGH, value=HIGH, pen=COLOR_LIGHTRED},
175+
{label=MAX, value=MAX, pen=COLOR_RED},
176+
},
174177
view_id='friction',
175178
on_change=function(val) self:setFriction(val) end,
176179
},
@@ -224,25 +227,25 @@ end
224227

225228
function RollerOverlay:init()
226229
self:addviews{
227-
widgets.Label{
228-
frame={t=0, l=0},
229-
text='Direction',
230-
},
231230
widgets.CycleHotkeyLabel{
232-
frame={t=0, l=10},
231+
label='Direction',
232+
frame={t=0, l=0},
233233
key='CUSTOM_CTRL_X',
234234
options={NORTH, EAST, SOUTH, WEST},
235235
view_id='direction',
236236
on_change=function(val) self:setDirection(val) end,
237237
},
238-
widgets.Label{
239-
frame={t=1, l=0},
240-
text='Speed',
241-
},
242238
widgets.CycleHotkeyLabel{
243-
frame={t=1, l=10},
239+
label='Speed',
240+
frame={t=1, l=0},
244241
key='CUSTOM_CTRL_F',
245-
options={LOW, MEDIUM, HIGH, HIGHER, MAX},
242+
options={
243+
{label=LOW, value=LOW, pen=COLOR_BLUE},
244+
{label=MEDIUM, value=MEDIUM, pen=COLOR_GREEN},
245+
{label=HIGH, value=HIGH, pen=COLOR_YELLOW},
246+
{label=HIGHER, value=HIGHER, pen=COLOR_LIGHTRED},
247+
{label=MAX, value=MAX, pen=COLOR_RED},
248+
},
246249
view_id='speed',
247250
on_change=function(val) self:setSpeed(val) end,
248251
},
@@ -253,7 +256,3 @@ OVERLAY_WIDGETS = {
253256
trackstop=TrackStopOverlay,
254257
rollers=RollerOverlay,
255258
}
256-
257-
if not dfhack_flags.module then
258-
main{...}
259-
end

0 commit comments

Comments
 (0)