-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
trackstop | ||
========= | ||
|
||
.. dfhack-tool:: | ||
:summary: Overlay to allow changing track stop friction and dump direction after construction | ||
:tags: fort gameplay buildings interface | ||
|
||
This script provides an overlay that is managed by the `overlay` framework. | ||
The overlay allows the player to change the friction and dump direction of a selected track stop after it has been constructed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
-- Overlay to allow changing track stop friction and dump direction after construction | ||
--@ module = true | ||
local gui = require('gui') | ||
local widgets = require('gui.widgets') | ||
local overlay = require('plugins.overlay') | ||
|
||
TrackStopOverlay = defclass(TrackStopOverlay, overlay.OverlayWidget) | ||
TrackStopOverlay.ATTRS{ | ||
default_pos={x=-71, y=29}, | ||
default_enabled=true, | ||
viewscreens='dwarfmode/ViewSheets/BUILDING/Trap', | ||
frame={w=27, h=4}, | ||
frame_style=gui.MEDIUM_FRAME, | ||
frame_background=gui.CLEAR_PEN, | ||
} | ||
|
||
function TrackStopOverlay:getFriction() | ||
return dfhack.gui.getSelectedBuilding().friction | ||
end | ||
|
||
function TrackStopOverlay:setFriction(friction) | ||
local building = dfhack.gui.getSelectedBuilding() | ||
|
||
if friction == 'None' then | ||
building.friction = 10 | ||
elseif friction == 'Low' then | ||
building.friction = 50 | ||
elseif friction == 'Medium' then | ||
building.friction = 500 | ||
elseif friction == 'High' then | ||
building.friction = 10000 | ||
elseif friction == 'Max' then | ||
building.friction = 50000 | ||
end | ||
end | ||
|
||
function TrackStopOverlay:getDumpDirection() | ||
local building = dfhack.gui.getSelectedBuilding() | ||
local use_dump = building.use_dump | ||
local dump_x_shift = building.dump_x_shift | ||
local dump_y_shift = building.dump_y_shift | ||
|
||
if use_dump == 0 then | ||
return 'None' | ||
else | ||
if dump_x_shift == 0 and dump_y_shift == -1 then | ||
return 'North' | ||
elseif dump_x_shift == 1 and dump_y_shift == 0 then | ||
return 'East' | ||
elseif dump_x_shift == 0 and dump_y_shift == 1 then | ||
return 'South' | ||
elseif dump_x_shift == -1 and dump_y_shift == 0 then | ||
return 'West' | ||
end | ||
end | ||
end | ||
|
||
function TrackStopOverlay:setDumpDirection(direction) | ||
local building = dfhack.gui.getSelectedBuilding() | ||
|
||
if direction == 'None' then | ||
building.use_dump = 0 | ||
building.dump_x_shift = 0 | ||
building.dump_y_shift = 0 | ||
elseif direction == 'North' then | ||
building.use_dump = 1 | ||
building.dump_x_shift = 0 | ||
building.dump_y_shift = -1 | ||
elseif direction == 'East' then | ||
building.use_dump = 1 | ||
building.dump_x_shift = 1 | ||
building.dump_y_shift = 0 | ||
elseif direction == 'South' then | ||
building.use_dump = 1 | ||
building.dump_x_shift = 0 | ||
building.dump_y_shift = 1 | ||
elseif direction == 'West' then | ||
building.use_dump = 1 | ||
building.dump_x_shift = -1 | ||
building.dump_y_shift = 0 | ||
end | ||
end | ||
|
||
function TrackStopOverlay:render(dc) | ||
if not self:shouldRender() then | ||
return | ||
end | ||
|
||
local building = dfhack.gui.getSelectedBuilding() | ||
local friction = building.friction | ||
local friction_cycle = self.subviews.friction | ||
|
||
if friction == 10 then | ||
friction_cycle:setOption('None') | ||
elseif friction == 50 then | ||
friction_cycle:setOption('Low') | ||
elseif friction == 500 then | ||
friction_cycle:setOption('Medium') | ||
elseif friction == 10000 then | ||
friction_cycle:setOption('High') | ||
elseif friction == 50000 then | ||
friction_cycle:setOption('Max') | ||
end | ||
|
||
self.subviews.dump_direction:setOption(self:getDumpDirection()) | ||
|
||
TrackStopOverlay.super.render(self, dc) | ||
end | ||
|
||
function TrackStopOverlay:shouldRender() | ||
local building = dfhack.gui.getSelectedBuilding() | ||
return building and building.trap_type == df.trap_type.TrackStop | ||
end | ||
|
||
function TrackStopOverlay:onInput(keys) | ||
if not self:shouldRender() then | ||
return | ||
end | ||
TrackStopOverlay.super.onInput(self, keys) | ||
end | ||
|
||
function TrackStopOverlay:init() | ||
self:addviews{ | ||
widgets.Label{ | ||
frame={t=0, l=0}, | ||
text='Dump', | ||
}, | ||
widgets.CycleHotkeyLabel{ | ||
frame={t=0, l=9}, | ||
key='CUSTOM_CTRL_X', | ||
options={'None', 'North', 'East', 'South', 'West'}, | ||
view_id='dump_direction', | ||
on_change=function(val) self:setDumpDirection(val) end, | ||
}, | ||
widgets.Label{ | ||
frame={t=1, l=0}, | ||
text='Friction', | ||
}, | ||
widgets.CycleHotkeyLabel{ | ||
frame={t=1, l=9}, | ||
key='CUSTOM_CTRL_F', | ||
options={'None', 'Low', 'Medium', 'High', 'Max'}, | ||
view_id='friction', | ||
on_change=function(val) self:setFriction(val) end, | ||
}, | ||
} | ||
end | ||
|
||
OVERLAY_WIDGETS = { | ||
trackstop=TrackStopOverlay | ||
} | ||
|
||
if not dfhack_flags.module then | ||
main{...} | ||
end |