Skip to content

Commit 87e6f1a

Browse files
authored
Merge pull request #884 from robob27/trackstop-overlay
Add trackstop and rollers overlays
2 parents 0ab2806 + ac3584b commit 87e6f1a

File tree

3 files changed

+253
-0
lines changed

3 files changed

+253
-0
lines changed

changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Template for new versions:
2828

2929
## New Tools
3030
- `sync-windmills`: synchronize or randomize movement of active windmills
31+
- `trackstop`: new overlay to allow changing track stop dump direction and friction and roller direction and speed after construction
3132

3233
## New Features
3334
- `gui/design`: show selected dimensions next to the mouse cursor when designating with vanilla tools, for example when painting a burrow or designating digging

docs/trackstop.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trackstop
2+
=========
3+
4+
.. dfhack-tool::
5+
:summary: Add dynamic configuration options for track stops.
6+
:tags: fort buildings interface
7+
8+
This script provides 2 overlays that are managed by the `overlay` framework. The script does nothing when executed.
9+
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 roller after it has been constructed.

trackstop.lua

+242
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
-- Overlay to allow changing track stop friction and dump direction after construction
2+
--@ module = true
3+
4+
if not dfhack_flags.module then
5+
qerror('trackstop cannot be called directly')
6+
end
7+
8+
local gui = require('gui')
9+
local widgets = require('gui.widgets')
10+
local overlay = require('plugins.overlay')
11+
local utils = require('utils')
12+
13+
local NORTH = 'North ^'
14+
local EAST = 'East >'
15+
local SOUTH = 'South v'
16+
local WEST = 'West <'
17+
18+
local LOW = 'Low'
19+
local MEDIUM = 'Medium'
20+
local HIGH = 'High'
21+
local HIGHER = 'Higher'
22+
local MAX = 'Max'
23+
24+
local NONE = 'None'
25+
26+
local FRICTION_MAP = {
27+
[NONE] = 10,
28+
[LOW] = 50,
29+
[MEDIUM] = 500,
30+
[HIGH] = 10000,
31+
[MAX] = 50000,
32+
}
33+
34+
local FRICTION_MAP_REVERSE = utils.invert(FRICTION_MAP)
35+
36+
local SPEED_MAP = {
37+
[LOW] = 10000,
38+
[MEDIUM] = 20000,
39+
[HIGH] = 30000,
40+
[HIGHER] = 40000,
41+
[MAX] = 50000,
42+
}
43+
44+
local SPEED_MAP_REVERSE = utils.invert(SPEED_MAP)
45+
46+
local DIRECTION_MAP = {
47+
[NORTH] = df.screw_pump_direction.FromSouth,
48+
[EAST] = df.screw_pump_direction.FromWest,
49+
[SOUTH] = df.screw_pump_direction.FromNorth,
50+
[WEST] = df.screw_pump_direction.FromEast,
51+
}
52+
53+
local DIRECTION_MAP_REVERSE = utils.invert(DIRECTION_MAP)
54+
55+
TrackStopOverlay = defclass(TrackStopOverlay, overlay.OverlayWidget)
56+
TrackStopOverlay.ATTRS{
57+
default_pos={x=-73, y=29},
58+
default_enabled=true,
59+
viewscreens='dwarfmode/ViewSheets/BUILDING/Trap/TrackStop',
60+
frame={w=25, h=4},
61+
frame_style=gui.MEDIUM_FRAME,
62+
frame_background=gui.CLEAR_PEN,
63+
}
64+
65+
function TrackStopOverlay:getFriction()
66+
return dfhack.gui.getSelectedBuilding().friction
67+
end
68+
69+
function TrackStopOverlay:setFriction(friction)
70+
local building = dfhack.gui.getSelectedBuilding()
71+
72+
building.friction = FRICTION_MAP[friction]
73+
end
74+
75+
function TrackStopOverlay:getDumpDirection()
76+
local building = dfhack.gui.getSelectedBuilding()
77+
local use_dump = building.use_dump
78+
local dump_x_shift = building.dump_x_shift
79+
local dump_y_shift = building.dump_y_shift
80+
81+
if use_dump == 0 then
82+
return NONE
83+
else
84+
if dump_x_shift == 0 and dump_y_shift == -1 then
85+
return NORTH
86+
elseif dump_x_shift == 1 and dump_y_shift == 0 then
87+
return EAST
88+
elseif dump_x_shift == 0 and dump_y_shift == 1 then
89+
return SOUTH
90+
elseif dump_x_shift == -1 and dump_y_shift == 0 then
91+
return WEST
92+
end
93+
end
94+
end
95+
96+
function TrackStopOverlay:setDumpDirection(direction)
97+
local building = dfhack.gui.getSelectedBuilding()
98+
99+
if direction == NONE then
100+
building.use_dump = 0
101+
building.dump_x_shift = 0
102+
building.dump_y_shift = 0
103+
elseif direction == NORTH then
104+
building.use_dump = 1
105+
building.dump_x_shift = 0
106+
building.dump_y_shift = -1
107+
elseif direction == EAST then
108+
building.use_dump = 1
109+
building.dump_x_shift = 1
110+
building.dump_y_shift = 0
111+
elseif direction == SOUTH then
112+
building.use_dump = 1
113+
building.dump_x_shift = 0
114+
building.dump_y_shift = 1
115+
elseif direction == WEST then
116+
building.use_dump = 1
117+
building.dump_x_shift = -1
118+
building.dump_y_shift = 0
119+
end
120+
end
121+
122+
function TrackStopOverlay:render(dc)
123+
local building = dfhack.gui.getSelectedBuilding()
124+
local friction = building.friction
125+
local friction_cycle = self.subviews.friction
126+
127+
friction_cycle:setOption(FRICTION_MAP_REVERSE[friction])
128+
129+
self.subviews.dump_direction:setOption(self:getDumpDirection())
130+
131+
TrackStopOverlay.super.render(self, dc)
132+
end
133+
134+
function TrackStopOverlay:init()
135+
self:addviews{
136+
widgets.CycleHotkeyLabel{
137+
frame={t=0, l=0},
138+
label='Dump',
139+
key='CUSTOM_CTRL_X',
140+
options={
141+
{label=NONE, value=NONE, pen=COLOR_BLUE},
142+
NORTH,
143+
EAST,
144+
SOUTH,
145+
WEST,
146+
},
147+
view_id='dump_direction',
148+
on_change=function(val) self:setDumpDirection(val) end,
149+
},
150+
widgets.CycleHotkeyLabel{
151+
label='Friction',
152+
frame={t=1, l=0},
153+
key='CUSTOM_CTRL_F',
154+
options={
155+
{label=NONE, value=NONE, pen=COLOR_BLUE},
156+
{label=LOW, value=LOW, pen=COLOR_GREEN},
157+
{label=MEDIUM, value=MEDIUM, pen=COLOR_YELLOW},
158+
{label=HIGH, value=HIGH, pen=COLOR_LIGHTRED},
159+
{label=MAX, value=MAX, pen=COLOR_RED},
160+
},
161+
view_id='friction',
162+
on_change=function(val) self:setFriction(val) end,
163+
},
164+
}
165+
end
166+
167+
RollerOverlay = defclass(RollerOverlay, overlay.OverlayWidget)
168+
RollerOverlay.ATTRS{
169+
default_pos={x=-71, y=29},
170+
default_enabled=true,
171+
viewscreens='dwarfmode/ViewSheets/BUILDING/Rollers',
172+
frame={w=27, h=4},
173+
frame_style=gui.MEDIUM_FRAME,
174+
frame_background=gui.CLEAR_PEN,
175+
}
176+
177+
function RollerOverlay:getDirection()
178+
local building = dfhack.gui.getSelectedBuilding()
179+
local direction = building.direction
180+
181+
return DIRECTION_MAP_REVERSE[direction]
182+
end
183+
184+
function RollerOverlay:setDirection(direction)
185+
local building = dfhack.gui.getSelectedBuilding()
186+
187+
building.direction = DIRECTION_MAP[direction]
188+
end
189+
190+
function RollerOverlay:getSpeed()
191+
local building = dfhack.gui.getSelectedBuilding()
192+
local speed = building.speed
193+
194+
return SPEED_MAP_REVERSE[speed]
195+
end
196+
197+
function RollerOverlay:setSpeed(speed)
198+
local building = dfhack.gui.getSelectedBuilding()
199+
200+
building.speed = SPEED_MAP[speed]
201+
end
202+
203+
function RollerOverlay:render(dc)
204+
local building = dfhack.gui.getSelectedBuilding()
205+
206+
self.subviews.direction:setOption(DIRECTION_MAP_REVERSE[building.direction])
207+
self.subviews.speed:setOption(SPEED_MAP_REVERSE[building.speed])
208+
209+
TrackStopOverlay.super.render(self, dc)
210+
end
211+
212+
function RollerOverlay:init()
213+
self:addviews{
214+
widgets.CycleHotkeyLabel{
215+
label='Direction',
216+
frame={t=0, l=0},
217+
key='CUSTOM_CTRL_X',
218+
options={NORTH, EAST, SOUTH, WEST},
219+
view_id='direction',
220+
on_change=function(val) self:setDirection(val) end,
221+
},
222+
widgets.CycleHotkeyLabel{
223+
label='Speed',
224+
frame={t=1, l=0},
225+
key='CUSTOM_CTRL_F',
226+
options={
227+
{label=LOW, value=LOW, pen=COLOR_BLUE},
228+
{label=MEDIUM, value=MEDIUM, pen=COLOR_GREEN},
229+
{label=HIGH, value=HIGH, pen=COLOR_YELLOW},
230+
{label=HIGHER, value=HIGHER, pen=COLOR_LIGHTRED},
231+
{label=MAX, value=MAX, pen=COLOR_RED},
232+
},
233+
view_id='speed',
234+
on_change=function(val) self:setSpeed(val) end,
235+
},
236+
}
237+
end
238+
239+
OVERLAY_WIDGETS = {
240+
trackstop=TrackStopOverlay,
241+
rollers=RollerOverlay,
242+
}

0 commit comments

Comments
 (0)