forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower-meter.lua
132 lines (111 loc) · 3.59 KB
/
power-meter.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
-- Interface front-end for power-meter plugin.
--[====[
gui/power-meter
===============
Activate an in-game interface for `power-meter` after selecting
:guilabel:`Pressure Plate` in the build menu.
.. image:: /docs/images/power-meter.png
The script follows the general look and feel of the regular pressure
plate build configuration page, but configures parameters relevant to
the modded power meter building.
]====]
local utils = require 'utils'
local gui = require 'gui'
local guidm = require 'gui.dwarfmode'
local dlg = require 'gui.dialogs'
local plugin = require('plugins.power-meter')
local bselector = df.global.buildreq
PowerMeter = defclass(PowerMeter, guidm.MenuOverlay)
PowerMeter.focus_path = 'power-meter'
PowerMeter.ATTRS {
frame_background = false
}
function PowerMeter:init()
self:assign{
min_power = 0, max_power = -1, invert = false,
}
end
function PowerMeter:onShow()
PowerMeter.super.onShow(self)
-- Send an event to update the errors
bselector.plate_info.flags.whole = 0
self:sendInputToParent('BUILDING_TRIGGER_ENABLE_WATER')
end
function PowerMeter:onRenderBody(dc)
dc:fill(0,0,dc.width-1,13,gui.CLEAR_PEN)
dc:seek(1,1):pen(COLOR_WHITE)
dc:string("Power Meter"):newline():newline(1)
dc:string("Placement"):newline():newline(1)
dc:string("Excess power range:")
dc:newline(3):key('BUILDING_TRIGGER_MIN_WATER_DOWN')
dc:key('BUILDING_TRIGGER_MIN_WATER_UP')
dc:string(": Min ")
if self.min_power <= 0 then
dc:string("(any)")
else
dc:string(''..self.min_power)
end
dc:newline(3):key('BUILDING_TRIGGER_MAX_WATER_DOWN')
dc:key('BUILDING_TRIGGER_MAX_WATER_UP')
dc:string(": Max ")
if self.max_power < 0 then
dc:string("(any)")
else
dc:string(''..self.max_power)
end
dc:newline():newline(1)
dc:key('CUSTOM_I'):string(": ")
if self.invert then
dc:string("Inverted")
else
dc:string("Not inverted")
end
end
function PowerMeter:onInput(keys)
if keys.CUSTOM_I then
self.invert = not self.invert
elseif keys.BUILDING_TRIGGER_MIN_WATER_UP then
self.min_power = self.min_power + 10
elseif keys.BUILDING_TRIGGER_MIN_WATER_DOWN then
self.min_power = math.max(0, self.min_power - 10)
elseif keys.BUILDING_TRIGGER_MAX_WATER_UP then
if self.max_power < 0 then
self.max_power = 0
else
self.max_power = self.max_power + 10
end
elseif keys.BUILDING_TRIGGER_MAX_WATER_DOWN then
self.max_power = math.max(-1, self.max_power - 10)
elseif keys.LEAVESCREEN then
self:dismiss()
self:sendInputToParent('LEAVESCREEN')
elseif keys.SELECT then
if #bselector.errors == 0 then
if not plugin.makePowerMeter(
bselector.plate_info,
self.min_power, self.max_power, self.invert
)
then
dlg.showMessage(
'Power Meter',
'Could not initialize.', COLOR_LIGHTRED
)
self:dismiss()
self:sendInputToParent('LEAVESCREEN')
return
end
self:sendInputToParent('SELECT')
if bselector.stage ~= 1 then
self:dismiss()
end
end
elseif self:propagateMoveKeys(keys) then
return
end
end
if dfhack.gui.getCurFocus() ~= 'dwarfmode/Build/Position/Trap'
or bselector.building_subtype ~= df.trap_type.PressurePlate
then
qerror("This script requires the build pressure plate sidebar")
end
PowerMeter():show()