-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathaquifer.lua
More file actions
185 lines (165 loc) · 5.41 KB
/
Copy pathaquifer.lua
File metadata and controls
185 lines (165 loc) · 5.41 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
local dig = require('plugins.dig')
local gui = require('gui')
local widgets = require('gui.widgets')
local selection_rect = df.global.selection_rect
local function reset_selection_rect()
selection_rect.start_x = -30000
selection_rect.start_y = -30000
selection_rect.start_z = -30000
end
--
-- Aquifer
--
Aquifer = defclass(Aquifer, widgets.Window)
Aquifer.ATTRS {
frame_title='Aquifer',
frame={w=38, h=15, r=2, t=18},
autoarrange_subviews=true,
autoarrange_gap=1,
resizable=true,
}
function Aquifer:init()
self:addviews{
widgets.Label{
frame={t=0, l=0},
text='Select map area to modify',
},
widgets.CycleHotkeyLabel{
view_id='action',
key='CUSTOM_CTRL_E',
label='Action:',
options={
{label='Drain', value='drain', pen=COLOR_LIGHTRED},
{label='Convert', value='convert', pen=COLOR_YELLOW},
{label='Add', value='add', pen=COLOR_BLUE},
},
on_change=function(val)
if val ~= 'drain' and self.subviews.aq_type:getOptionValue() == 'all' then
self.subviews.aq_type:cycle()
end
end,
},
widgets.CycleHotkeyLabel{
view_id='aq_type',
key='CUSTOM_CTRL_T',
label=function()
if self.subviews.action:getOptionValue() == 'convert' then
return 'To aquifer type:'
end
return 'Aquifer type:'
end,
options={
{label='All', value='all', pen=COLOR_LIGHTRED},
{label='Light', value='light', pen=COLOR_LIGHTBLUE},
{label='Heavy', value='heavy', pen=COLOR_BLUE},
},
initial_option='all',
on_change=function(val)
if val == 'all' and self.subviews.action:getOptionValue() ~= 'drain' then
self.subviews.aq_type:cycle()
end
end,
},
widgets.ToggleHotkeyLabel{
view_id='leaky',
key='CUSTOM_CTRL_K',
label=function()
if self.subviews.action:getOptionValue() == 'add' then
return 'Allow immediate leaks:'
end
return 'Affect only leaks:'
end,
initial_option=false,
},
widgets.Divider{
frame={h=1},
frame_style=gui.FRAME_THIN,
frame_style_l=false,
frame_style_r=false,
},
widgets.HotkeyLabel{
key='CUSTOM_CTRL_A',
label='Apply to entire level now',
on_activate=self:callback('action_level'),
},
}
end
function Aquifer:onRenderFrame(dc, rect)
dig.paintScreenWarmDamp(true, false)
Aquifer.super.onRenderFrame(self, dc, rect)
end
function Aquifer:onInput(keys)
if Aquifer.super.onInput(self, keys) then return true end
if keys.LEAVESCREEN or keys._MOUSE_R then
if selection_rect.start_x >= 0 then
reset_selection_rect()
return true
end
return false
end
local pos = nil
if keys._MOUSE_L and not self:getMouseFramePos() then
pos = dfhack.gui.getMousePos()
end
if pos then
if selection_rect.start_x >= 0 then
self:action_box(pos)
reset_selection_rect()
else
-- set this again just in case it got unset somehow
df.global.game.main_interface.main_designation_selected = df.main_designation_type.TOGGLE_ENGRAVING
-- use selection_rect so gui/design can display the dimensions overlay
selection_rect.start_x = pos.x
selection_rect.start_y = pos.y
selection_rect.start_z = pos.z
end
return true
end
end
function Aquifer:get_base_command()
local command = {'aquifer', '-q'}
table.insert(command, self.subviews.action:getOptionValue())
local aq_type = self.subviews.aq_type:getOptionValue()
if aq_type ~= 'all' then
table.insert(command, aq_type)
end
if self.subviews.leaky:getOptionValue() then
table.insert(command, '--leaky')
end
return command
end
function Aquifer:action_level()
local command = self:get_base_command()
table.insert(command, '-z')
dfhack.run_command(command)
end
function Aquifer:action_box(pos)
local command = self:get_base_command()
table.insert(command, ('%d,%d,%d'):
format(selection_rect.start_x, selection_rect.start_y, selection_rect.start_z))
table.insert(command, ('%d,%d,%d'):format(pos.x, pos.y, pos.z))
dfhack.run_command(command)
end
--
-- AquiferScreen
--
AquiferScreen = defclass(AquiferScreen, gui.ZScreen)
AquiferScreen.ATTRS {
focus_path='aquifer',
pass_movement_keys=true,
pass_mouse_clicks=false,
}
function AquiferScreen:init()
self.saved_designation_type = df.global.game.main_interface.main_designation_selected
df.global.game.main_interface.main_designation_selected = df.main_designation_type.TOGGLE_ENGRAVING
self:addviews{Aquifer{}}
end
function AquiferScreen:onDismiss()
reset_selection_rect()
df.global.game.main_interface.main_designation_selected = self.saved_designation_type
view = nil
end
if not dfhack.isMapLoaded() then
qerror('This script requires a map to be loaded')
end
view = view and view:raise() or AquiferScreen{}:show()