flickerstreak@109
|
1 --[[
|
flickerstreak@109
|
2 ReAction bar state driver interface
|
flickerstreak@109
|
3
|
flickerstreak@109
|
4 --]]
|
flickerstreak@109
|
5
|
flickerstreak@109
|
6 -- local imports
|
flickerstreak@175
|
7 local addonName, addonTable = ...
|
flickerstreak@175
|
8 local ReAction = addonTable.ReAction
|
flickerstreak@109
|
9 local L = ReAction.L
|
flickerstreak@109
|
10 local _G = _G
|
flickerstreak@109
|
11 local format = string.format
|
flickerstreak@109
|
12 local InCombatLockdown = InCombatLockdown
|
flickerstreak@109
|
13 local RegisterStateDriver = RegisterStateDriver
|
Flick@241
|
14 local tfetch = addonTable.tfetch
|
Flick@241
|
15 local tbuild = addonTable.tbuild
|
Flick@242
|
16 local ApplyStates = Bar.ApplyStates
|
Flick@242
|
17 local CleanupStates = Bar.CleanupStates
|
Flick@242
|
18 local SetProperty = Bar.SetStateProperty
|
Flick@242
|
19 local GetProperty = Bar.GetStateProperty
|
flickerstreak@109
|
20
|
flickerstreak@109
|
21 -- module declaration
|
flickerstreak@109
|
22 local moduleID = "State"
|
flickerstreak@109
|
23 local module = ReAction:NewModule( moduleID, "AceEvent-3.0" )
|
flickerstreak@109
|
24
|
flickerstreak@109
|
25
|
flickerstreak@109
|
26 -- module event handlers --
|
flickerstreak@109
|
27
|
flickerstreak@109
|
28 function module:OnInitialize()
|
flickerstreak@109
|
29 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@109
|
30 end
|
flickerstreak@109
|
31
|
flickerstreak@109
|
32
|
flickerstreak@109
|
33
|
flickerstreak@109
|
34
|
flickerstreak@109
|
35 -- Options --
|
flickerstreak@109
|
36
|
flickerstreak@109
|
37 do
|
flickerstreak@109
|
38 -- pre-sorted by the order they should appear in
|
flickerstreak@109
|
39 local rules = {
|
flickerstreak@118
|
40 -- rule fields
|
flickerstreak@118
|
41 { "stance", { {battle = L["Battle Stance"]}, {defensive = L["Defensive Stance"]}, {berserker = L["Berserker Stance"]} } },
|
flickerstreak@118
|
42 { "form", { {caster = L["Caster Form"]}, {bear = L["Bear Form"]}, {cat = L["Cat Form"]}, {tree = L["Tree of Life"]}, {moonkin = L["Moonkin Form"]} } },
|
flickerstreak@178
|
43 { "stealth", { {stealth = L["Stealth"]}, {nostealth = L["No Stealth"]}, {shadowdance = L["Shadow Dance"]} } },
|
flickerstreak@118
|
44 { "shadow", { {shadowform = L["Shadowform"]}, {noshadowform = L["No Shadowform"]} } },
|
flickerstreak@176
|
45 { "demon", { {demon = L["Demon Form"]}, {nodemon = L["No Demon Form"]} } },
|
flickerstreak@118
|
46 { "pet", { {pet = L["With Pet"]}, {nopet = L["Without Pet"]} } },
|
flickerstreak@118
|
47 { "target", { {harm = L["Hostile Target"]}, {help = L["Friendly Target"]}, {notarget = L["No Target"]} } },
|
flickerstreak@118
|
48 { "focus", { {focusharm = L["Hostile Focus"]}, {focushelp = L["Friendly Focus"]}, {nofocus = L["No Focus"]} } },
|
flickerstreak@118
|
49 { "possess", { {possess = L["Mind Control"]} } },
|
flickerstreak@118
|
50 { "vehicle", { {vehicle = L["In a Vehicle"]} } },
|
flickerstreak@118
|
51 { "group", { {raid = L["Raid"]}, {party = L["Party"]}, {solo = L["Solo"]} } },
|
flickerstreak@118
|
52 { "combat", { {combat = L["In Combat"]}, {nocombat = L["Out of Combat"]} } },
|
flickerstreak@109
|
53 }
|
flickerstreak@109
|
54
|
flickerstreak@109
|
55 local ruleSelect = { }
|
flickerstreak@109
|
56 local ruleMap = { }
|
flickerstreak@109
|
57 local optionMap = setmetatable({},{__mode="k"})
|
flickerstreak@109
|
58
|
flickerstreak@109
|
59 local pointTable = {
|
flickerstreak@109
|
60 NONE = " ",
|
flickerstreak@109
|
61 CENTER = L["Center"],
|
flickerstreak@109
|
62 LEFT = L["Left"],
|
flickerstreak@109
|
63 RIGHT = L["Right"],
|
flickerstreak@109
|
64 TOP = L["Top"],
|
flickerstreak@109
|
65 BOTTOM = L["Bottom"],
|
flickerstreak@109
|
66 TOPLEFT = L["Top Left"],
|
flickerstreak@109
|
67 TOPRIGHT = L["Top Right"],
|
flickerstreak@109
|
68 BOTTOMLEFT = L["Bottom Left"],
|
flickerstreak@109
|
69 BOTTOMRIGHT = L["Bottom Right"],
|
flickerstreak@109
|
70 }
|
flickerstreak@109
|
71
|
flickerstreak@109
|
72 -- unpack rules table into ruleSelect and ruleMap
|
flickerstreak@109
|
73 for _, c in ipairs(rules) do
|
flickerstreak@118
|
74 local rule, fields = unpack(c)
|
flickerstreak@118
|
75 for _, field in ipairs(fields) do
|
flickerstreak@118
|
76 local key, label = next(field)
|
flickerstreak@118
|
77 table.insert(ruleSelect, label)
|
flickerstreak@118
|
78 table.insert(ruleMap, key)
|
flickerstreak@109
|
79 end
|
flickerstreak@109
|
80 end
|
flickerstreak@109
|
81
|
flickerstreak@109
|
82 local stateOptions = {
|
flickerstreak@109
|
83 ordering = {
|
flickerstreak@109
|
84 name = L["Info"],
|
flickerstreak@109
|
85 order = 1,
|
flickerstreak@109
|
86 type = "group",
|
flickerstreak@109
|
87 args = {
|
flickerstreak@109
|
88 delete = {
|
flickerstreak@109
|
89 name = L["Delete this State"],
|
flickerstreak@109
|
90 order = -1,
|
flickerstreak@109
|
91 type = "execute",
|
flickerstreak@109
|
92 func = "DeleteState",
|
flickerstreak@109
|
93 },
|
flickerstreak@109
|
94 rename = {
|
flickerstreak@109
|
95 name = L["Name"],
|
flickerstreak@109
|
96 order = 1,
|
flickerstreak@109
|
97 type = "input",
|
flickerstreak@109
|
98 get = "GetName",
|
flickerstreak@109
|
99 set = "SetStateName",
|
flickerstreak@109
|
100 pattern = "^%w*$",
|
flickerstreak@109
|
101 usage = L["State names must be alphanumeric without spaces"],
|
flickerstreak@109
|
102 },
|
flickerstreak@109
|
103 ordering = {
|
flickerstreak@109
|
104 name = L["Evaluation Order"],
|
flickerstreak@109
|
105 desc = L["State transitions are evaluated in the order listed:\nMove a state up or down to change the order"],
|
flickerstreak@109
|
106 order = 2,
|
flickerstreak@109
|
107 type = "group",
|
flickerstreak@109
|
108 inline = true,
|
flickerstreak@109
|
109 args = {
|
flickerstreak@109
|
110 up = {
|
flickerstreak@109
|
111 name = L["Up"],
|
flickerstreak@109
|
112 order = 1,
|
flickerstreak@109
|
113 type = "execute",
|
flickerstreak@109
|
114 width = "half",
|
flickerstreak@109
|
115 func = "MoveStateUp",
|
flickerstreak@109
|
116 },
|
flickerstreak@109
|
117 down = {
|
flickerstreak@109
|
118 name = L["Down"],
|
flickerstreak@109
|
119 order = 2,
|
flickerstreak@109
|
120 type = "execute",
|
flickerstreak@109
|
121 width = "half",
|
flickerstreak@109
|
122 func = "MoveStateDown",
|
flickerstreak@109
|
123 }
|
flickerstreak@109
|
124 }
|
flickerstreak@109
|
125 }
|
flickerstreak@109
|
126 }
|
flickerstreak@109
|
127 },
|
flickerstreak@109
|
128 properties = {
|
flickerstreak@109
|
129 name = L["Properties"],
|
flickerstreak@109
|
130 order = 2,
|
flickerstreak@109
|
131 type = "group",
|
flickerstreak@109
|
132 args = {
|
flickerstreak@109
|
133 desc = {
|
flickerstreak@109
|
134 name = L["Set the properties for the bar when in this state"],
|
flickerstreak@109
|
135 order = 1,
|
flickerstreak@109
|
136 type = "description"
|
flickerstreak@109
|
137 },
|
Flick@239
|
138 page = {
|
Flick@239
|
139 name = L["Show Page #"],
|
Flick@239
|
140 order = 11,
|
Flick@239
|
141 type = "select",
|
Flick@239
|
142 width = "half",
|
Flick@239
|
143 disabled = "IsPageDisabled",
|
Flick@239
|
144 hidden = "IsPageHidden",
|
Flick@239
|
145 values = "GetPageValues",
|
Flick@239
|
146 set = "SetProp",
|
Flick@239
|
147 get = "GetPage",
|
Flick@239
|
148 },
|
flickerstreak@109
|
149 hide = {
|
flickerstreak@109
|
150 name = L["Hide Bar"],
|
flickerstreak@109
|
151 order = 90,
|
flickerstreak@109
|
152 type = "toggle",
|
flickerstreak@109
|
153 set = "SetProp",
|
flickerstreak@109
|
154 get = "GetProp",
|
flickerstreak@109
|
155 },
|
flickerstreak@109
|
156 --[[ BROKEN
|
flickerstreak@109
|
157 keybindState = {
|
flickerstreak@109
|
158 name = L["Override Keybinds"],
|
flickerstreak@109
|
159 desc = L["Set this state to maintain its own set of keybinds which override the defaults when active"],
|
flickerstreak@109
|
160 order = 91,
|
flickerstreak@109
|
161 type = "toggle",
|
flickerstreak@109
|
162 set = "SetProp",
|
flickerstreak@109
|
163 get = "GetProp",
|
flickerstreak@109
|
164 }, ]]
|
flickerstreak@109
|
165 position = {
|
flickerstreak@109
|
166 name = L["Position"],
|
flickerstreak@109
|
167 order = 92,
|
flickerstreak@109
|
168 type = "group",
|
flickerstreak@109
|
169 inline = true,
|
flickerstreak@109
|
170 args = {
|
flickerstreak@109
|
171 anchorEnable = {
|
flickerstreak@109
|
172 name = L["Reposition"],
|
flickerstreak@109
|
173 order = 1,
|
flickerstreak@109
|
174 type = "toggle",
|
flickerstreak@109
|
175 set = "SetProp",
|
flickerstreak@109
|
176 get = "GetProp",
|
flickerstreak@109
|
177 },
|
flickerstreak@109
|
178 anchorFrame = {
|
flickerstreak@109
|
179 name = L["Anchor Frame"],
|
flickerstreak@109
|
180 order = 2,
|
flickerstreak@109
|
181 type = "select",
|
flickerstreak@109
|
182 values = "GetAnchorFrames",
|
flickerstreak@109
|
183 set = "SetAnchorFrame",
|
flickerstreak@109
|
184 get = "GetAnchorFrame",
|
flickerstreak@109
|
185 disabled = "GetAnchorDisabled",
|
flickerstreak@109
|
186 hidden = "GetAnchorDisabled",
|
flickerstreak@109
|
187 },
|
flickerstreak@109
|
188 anchorPoint = {
|
flickerstreak@109
|
189 name = L["Point"],
|
flickerstreak@109
|
190 order = 3,
|
flickerstreak@109
|
191 type = "select",
|
flickerstreak@109
|
192 values = pointTable,
|
flickerstreak@109
|
193 set = "SetAnchorPointProp",
|
flickerstreak@109
|
194 get = "GetAnchorPointProp",
|
flickerstreak@109
|
195 disabled = "GetAnchorDisabled",
|
flickerstreak@109
|
196 hidden = "GetAnchorDisabled",
|
flickerstreak@109
|
197 },
|
flickerstreak@109
|
198 anchorRelPoint = {
|
flickerstreak@109
|
199 name = L["Relative Point"],
|
flickerstreak@109
|
200 order = 4,
|
flickerstreak@109
|
201 type = "select",
|
flickerstreak@109
|
202 values = pointTable,
|
flickerstreak@109
|
203 set = "SetAnchorPointProp",
|
flickerstreak@109
|
204 get = "GetAnchorPointProp",
|
flickerstreak@109
|
205 disabled = "GetAnchorDisabled",
|
flickerstreak@109
|
206 hidden = "GetAnchorDisabled",
|
flickerstreak@109
|
207 },
|
flickerstreak@109
|
208 anchorX = {
|
flickerstreak@109
|
209 name = L["X Offset"],
|
flickerstreak@109
|
210 order = 5,
|
flickerstreak@109
|
211 type = "range",
|
flickerstreak@109
|
212 min = -100,
|
flickerstreak@109
|
213 max = 100,
|
flickerstreak@109
|
214 step = 1,
|
flickerstreak@109
|
215 set = "SetProp",
|
flickerstreak@109
|
216 get = "GetProp",
|
flickerstreak@109
|
217 disabled = "GetAnchorDisabled",
|
flickerstreak@109
|
218 hidden = "GetAnchorDisabled",
|
flickerstreak@109
|
219 },
|
flickerstreak@109
|
220 anchorY = {
|
flickerstreak@109
|
221 name = L["Y Offset"],
|
flickerstreak@109
|
222 order = 6,
|
flickerstreak@109
|
223 type = "range",
|
flickerstreak@109
|
224 min = -100,
|
flickerstreak@109
|
225 max = 100,
|
flickerstreak@109
|
226 step = 1,
|
flickerstreak@109
|
227 set = "SetProp",
|
flickerstreak@109
|
228 get = "GetProp",
|
flickerstreak@109
|
229 disabled = "GetAnchorDisabled",
|
flickerstreak@109
|
230 hidden = "GetAnchorDisabled",
|
flickerstreak@109
|
231 },
|
flickerstreak@109
|
232 },
|
flickerstreak@109
|
233 },
|
flickerstreak@109
|
234 scale = {
|
flickerstreak@109
|
235 name = L["Scale"],
|
flickerstreak@109
|
236 order = 93,
|
flickerstreak@109
|
237 type = "group",
|
flickerstreak@109
|
238 inline = true,
|
flickerstreak@109
|
239 args = {
|
flickerstreak@109
|
240 enableScale = {
|
flickerstreak@109
|
241 name = L["Set New Scale"],
|
flickerstreak@109
|
242 order = 1,
|
flickerstreak@109
|
243 type = "toggle",
|
flickerstreak@109
|
244 set = "SetProp",
|
flickerstreak@109
|
245 get = "GetProp",
|
flickerstreak@109
|
246 },
|
flickerstreak@109
|
247 scale = {
|
flickerstreak@109
|
248 name = L["Scale"],
|
flickerstreak@109
|
249 order = 2,
|
flickerstreak@109
|
250 type = "range",
|
flickerstreak@109
|
251 min = 0.25,
|
flickerstreak@109
|
252 max = 2.5,
|
flickerstreak@109
|
253 step = 0.05,
|
flickerstreak@109
|
254 isPercent = true,
|
flickerstreak@109
|
255 set = "SetProp",
|
flickerstreak@109
|
256 get = "GetScale",
|
flickerstreak@109
|
257 disabled = "GetScaleDisabled",
|
flickerstreak@109
|
258 hidden = "GetScaleDisabled",
|
flickerstreak@109
|
259 },
|
flickerstreak@109
|
260 },
|
flickerstreak@109
|
261 },
|
flickerstreak@109
|
262 alpha = {
|
flickerstreak@109
|
263 name = L["Transparency"],
|
flickerstreak@109
|
264 order = 94,
|
flickerstreak@109
|
265 type = "group",
|
flickerstreak@109
|
266 inline = true,
|
flickerstreak@109
|
267 args = {
|
flickerstreak@109
|
268 enableAlpha = {
|
flickerstreak@109
|
269 name = L["Set Transparency"],
|
flickerstreak@109
|
270 order = 1,
|
flickerstreak@109
|
271 type = "toggle",
|
flickerstreak@109
|
272 set = "SetProp",
|
flickerstreak@109
|
273 get = "GetProp",
|
flickerstreak@109
|
274 },
|
flickerstreak@109
|
275 alpha = {
|
flickerstreak@109
|
276 name = L["Transparency"],
|
flickerstreak@109
|
277 order = 2,
|
flickerstreak@109
|
278 type = "range",
|
flickerstreak@109
|
279 min = 0,
|
flickerstreak@109
|
280 max = 1,
|
flickerstreak@109
|
281 step = 0.01,
|
flickerstreak@109
|
282 bigStep = 0.05,
|
flickerstreak@109
|
283 isPercent = true,
|
flickerstreak@109
|
284 set = "SetProp",
|
flickerstreak@109
|
285 get = "GetAlpha",
|
flickerstreak@109
|
286 disabled = "GetAlphaDisabled",
|
flickerstreak@109
|
287 hidden = "GetAlphaDisabled",
|
flickerstreak@109
|
288 },
|
flickerstreak@109
|
289 },
|
flickerstreak@109
|
290 },
|
flickerstreak@109
|
291 },
|
flickerstreak@109
|
292 plugins = { }
|
flickerstreak@109
|
293 },
|
flickerstreak@109
|
294 rules = {
|
flickerstreak@109
|
295 name = L["Rule"],
|
flickerstreak@109
|
296 order = 3,
|
flickerstreak@109
|
297 type = "group",
|
flickerstreak@109
|
298 args = {
|
flickerstreak@109
|
299 mode = {
|
flickerstreak@109
|
300 name = L["Select this state"],
|
flickerstreak@109
|
301 order = 2,
|
flickerstreak@109
|
302 type = "select",
|
flickerstreak@109
|
303 style = "radio",
|
flickerstreak@109
|
304 values = {
|
flickerstreak@109
|
305 default = L["by default"],
|
flickerstreak@109
|
306 any = L["when ANY of these"],
|
flickerstreak@109
|
307 all = L["when ALL of these"],
|
flickerstreak@109
|
308 custom = L["via custom rule"],
|
flickerstreak@109
|
309 keybind = L["via keybinding"],
|
flickerstreak@109
|
310 },
|
flickerstreak@109
|
311 set = "SetType",
|
flickerstreak@109
|
312 get = "GetType",
|
flickerstreak@109
|
313 },
|
flickerstreak@109
|
314 clear = {
|
flickerstreak@109
|
315 name = L["Clear All"],
|
flickerstreak@109
|
316 order = 3,
|
flickerstreak@109
|
317 type = "execute",
|
flickerstreak@109
|
318 hidden = "GetClearAllDisabled",
|
flickerstreak@109
|
319 disabled = "GetClearAllDisabled",
|
flickerstreak@109
|
320 func = "ClearAllConditions",
|
flickerstreak@109
|
321 },
|
flickerstreak@109
|
322 inputs = {
|
flickerstreak@109
|
323 name = L["Conditions"],
|
flickerstreak@109
|
324 order = 4,
|
flickerstreak@109
|
325 type = "multiselect",
|
flickerstreak@109
|
326 hidden = "GetConditionsDisabled",
|
flickerstreak@109
|
327 disabled = "GetConditionsDisabled",
|
flickerstreak@109
|
328 values = ruleSelect,
|
flickerstreak@109
|
329 set = "SetCondition",
|
flickerstreak@109
|
330 get = "GetCondition",
|
flickerstreak@109
|
331 },
|
flickerstreak@109
|
332 custom = {
|
flickerstreak@109
|
333 name = L["Custom Rule"],
|
flickerstreak@109
|
334 order = 5,
|
flickerstreak@109
|
335 type = "input",
|
flickerstreak@109
|
336 multiline = true,
|
flickerstreak@109
|
337 hidden = "GetCustomDisabled",
|
flickerstreak@109
|
338 disabled = "GetCustomDisabled",
|
flickerstreak@109
|
339 desc = L["Syntax like macro rules: see preset rules for examples"],
|
flickerstreak@109
|
340 set = "SetCustomRule",
|
flickerstreak@109
|
341 get = "GetCustomRule",
|
flickerstreak@109
|
342 validate = "ValidateCustomRule",
|
flickerstreak@109
|
343 },
|
flickerstreak@109
|
344 keybind = {
|
flickerstreak@109
|
345 name = L["Keybinding"],
|
flickerstreak@109
|
346 order = 6,
|
flickerstreak@109
|
347 inline = true,
|
flickerstreak@109
|
348 hidden = "GetKeybindDisabled",
|
flickerstreak@109
|
349 disabled = "GetKeybindDisabled",
|
flickerstreak@109
|
350 type = "group",
|
flickerstreak@109
|
351 args = {
|
flickerstreak@109
|
352 desc = {
|
flickerstreak@109
|
353 name = L["Invoking a state keybind toggles an override of all other transition rules."],
|
flickerstreak@109
|
354 order = 1,
|
flickerstreak@109
|
355 type = "description",
|
flickerstreak@109
|
356 },
|
flickerstreak@109
|
357 keybind = {
|
flickerstreak@109
|
358 name = L["State Hotkey"],
|
flickerstreak@109
|
359 desc = L["Define an override toggle keybind"],
|
flickerstreak@109
|
360 order = 2,
|
flickerstreak@109
|
361 type = "keybinding",
|
flickerstreak@109
|
362 set = "SetKeybind",
|
flickerstreak@109
|
363 get = "GetKeybind",
|
flickerstreak@109
|
364 },
|
flickerstreak@109
|
365 },
|
flickerstreak@109
|
366 },
|
flickerstreak@109
|
367 },
|
flickerstreak@109
|
368 },
|
flickerstreak@109
|
369 }
|
flickerstreak@109
|
370
|
Flick@240
|
371 local StateHandler = { }
|
Flick@240
|
372 local meta = { __index = StateHandler }
|
flickerstreak@109
|
373
|
flickerstreak@109
|
374 function StateHandler:New( bar, opts )
|
flickerstreak@109
|
375 local self = setmetatable(
|
flickerstreak@109
|
376 {
|
flickerstreak@109
|
377 bar = bar
|
flickerstreak@109
|
378 },
|
Flick@240
|
379 meta )
|
flickerstreak@109
|
380
|
flickerstreak@109
|
381 function self:GetName()
|
flickerstreak@109
|
382 return opts.name
|
flickerstreak@109
|
383 end
|
flickerstreak@109
|
384
|
flickerstreak@109
|
385 function self:SetName(name)
|
flickerstreak@109
|
386 opts.name = name
|
flickerstreak@109
|
387 end
|
flickerstreak@109
|
388
|
flickerstreak@109
|
389 function self:GetOrder()
|
flickerstreak@109
|
390 return opts.order
|
flickerstreak@109
|
391 end
|
flickerstreak@109
|
392
|
flickerstreak@109
|
393 -- get reference to states table: even if the bar
|
flickerstreak@109
|
394 -- name changes the states table ref won't
|
Flick@228
|
395 self.states = tbuild(bar:GetConfig(), "states")
|
flickerstreak@109
|
396 self.state = tbuild(self.states, opts.name)
|
flickerstreak@109
|
397
|
flickerstreak@109
|
398 opts.order = self:GetRuleField("order")
|
flickerstreak@109
|
399 if opts.order == nil then
|
flickerstreak@109
|
400 -- add after the highest
|
flickerstreak@109
|
401 opts.order = 100
|
flickerstreak@109
|
402 for _, state in pairs(self.states) do
|
flickerstreak@109
|
403 local x = tonumber(tfetch(state, "rule", "order"))
|
flickerstreak@109
|
404 if x and x >= opts.order then
|
flickerstreak@109
|
405 opts.order = x + 1
|
flickerstreak@109
|
406 end
|
flickerstreak@109
|
407 end
|
flickerstreak@109
|
408 self:SetRuleField("order",opts.order)
|
flickerstreak@109
|
409 end
|
flickerstreak@109
|
410
|
flickerstreak@109
|
411 return self
|
flickerstreak@109
|
412 end
|
flickerstreak@109
|
413
|
flickerstreak@109
|
414 -- helper methods
|
flickerstreak@109
|
415
|
flickerstreak@109
|
416 function StateHandler:SetRuleField( key, value, ... )
|
flickerstreak@109
|
417 tbuild(self.state, "rule", ...)[key] = value
|
flickerstreak@109
|
418 end
|
flickerstreak@109
|
419
|
flickerstreak@109
|
420 function StateHandler:GetRuleField( ... )
|
flickerstreak@109
|
421 return tfetch(self.state, "rule", ...)
|
flickerstreak@109
|
422 end
|
flickerstreak@109
|
423
|
flickerstreak@109
|
424 function StateHandler:FixAll( setkey )
|
flickerstreak@109
|
425 -- if multiple selections in the same group are chosen when 'all' is selected,
|
flickerstreak@109
|
426 -- keep only one of them. If changing the mode, the first in the fields list will
|
flickerstreak@109
|
427 -- be chosen arbitrarily. Otherwise, if selecting a new checkbox from the field-set,
|
flickerstreak@109
|
428 -- it will be retained.
|
flickerstreak@109
|
429 local notified = false
|
flickerstreak@109
|
430 if self:GetRuleField("type") == "all" then
|
flickerstreak@109
|
431 for _, c in ipairs(rules) do
|
flickerstreak@118
|
432 local rule, fields = unpack(c)
|
flickerstreak@109
|
433 local once = false
|
flickerstreak@109
|
434 if setkey then
|
flickerstreak@109
|
435 for idx, field in ipairs(fields) do
|
flickerstreak@109
|
436 if next(field) == setkey then
|
flickerstreak@109
|
437 once = true
|
flickerstreak@109
|
438 end
|
flickerstreak@109
|
439 end
|
flickerstreak@109
|
440 end
|
flickerstreak@109
|
441 for idx, field in ipairs(fields) do
|
flickerstreak@109
|
442 local key = next(field)
|
flickerstreak@109
|
443 if self:GetRuleField("values",key) then
|
flickerstreak@109
|
444 if once and key ~= setkey then
|
flickerstreak@109
|
445 self:SetRuleField(key,false,"values")
|
flickerstreak@109
|
446 if not setkey and not notified then
|
flickerstreak@109
|
447 ReAction:UserError(L["Warning: one or more incompatible rules were turned off"])
|
flickerstreak@109
|
448 notified = true
|
flickerstreak@109
|
449 end
|
flickerstreak@109
|
450 end
|
flickerstreak@109
|
451 once = true
|
flickerstreak@109
|
452 end
|
flickerstreak@109
|
453 end
|
flickerstreak@109
|
454 end
|
flickerstreak@109
|
455 end
|
flickerstreak@109
|
456 end
|
flickerstreak@109
|
457
|
flickerstreak@109
|
458 function StateHandler:GetNeighbors()
|
flickerstreak@109
|
459 local before, after
|
flickerstreak@109
|
460 for k, v in pairs(self.states) do
|
flickerstreak@109
|
461 local o = tonumber(tfetch(v, "rule", "order"))
|
flickerstreak@109
|
462 if o and k ~= self:GetName() then
|
flickerstreak@109
|
463 local obefore = tfetch(self.states,before,"rule","order")
|
flickerstreak@109
|
464 local oafter = tfetch(self.states,after,"rule","order")
|
flickerstreak@109
|
465 if o < self:GetOrder() and (not obefore or obefore < o) then
|
flickerstreak@109
|
466 before = k
|
flickerstreak@109
|
467 end
|
flickerstreak@109
|
468 if o > self:GetOrder() and (not oafter or oafter > o) then
|
flickerstreak@109
|
469 after = k
|
flickerstreak@109
|
470 end
|
flickerstreak@109
|
471 end
|
flickerstreak@109
|
472 end
|
flickerstreak@109
|
473 return before, after
|
flickerstreak@109
|
474 end
|
flickerstreak@109
|
475
|
flickerstreak@109
|
476 function StateHandler:SwapOrder( a, b )
|
flickerstreak@109
|
477 -- do options table
|
flickerstreak@109
|
478 local args = optionMap[self.bar].args
|
flickerstreak@109
|
479 args[a].order, args[b].order = args[b].order, args[a].order
|
flickerstreak@109
|
480 -- do profile
|
flickerstreak@109
|
481 a = tbuild(self.states, a, "rule")
|
flickerstreak@109
|
482 b = tbuild(self.states, b, "rule")
|
flickerstreak@109
|
483 a.order, b.order = b.order, a.order
|
flickerstreak@109
|
484 end
|
flickerstreak@109
|
485
|
flickerstreak@109
|
486 -- handler methods
|
flickerstreak@109
|
487
|
flickerstreak@109
|
488 function StateHandler:GetProp( info )
|
flickerstreak@109
|
489 -- gets property of the same name as the options arg
|
flickerstreak@109
|
490 return GetProperty(self.bar, self:GetName(), info[#info])
|
flickerstreak@109
|
491 end
|
flickerstreak@109
|
492
|
flickerstreak@109
|
493 function StateHandler:SetProp( info, value )
|
flickerstreak@109
|
494 -- sets property of the same name as the options arg
|
flickerstreak@109
|
495 SetProperty(self.bar, self:GetName(), info[#info], value)
|
flickerstreak@109
|
496 end
|
flickerstreak@109
|
497
|
flickerstreak@109
|
498 function StateHandler:DeleteState()
|
flickerstreak@109
|
499 if self.states[self:GetName()] then
|
flickerstreak@109
|
500 self.states[self:GetName()] = nil
|
flickerstreak@109
|
501 ApplyStates(self.bar)
|
flickerstreak@109
|
502 end
|
flickerstreak@109
|
503 optionMap[self.bar].args[self:GetName()] = nil
|
flickerstreak@109
|
504 end
|
flickerstreak@109
|
505
|
flickerstreak@109
|
506 function StateHandler:SetStateName(info, value)
|
flickerstreak@109
|
507 -- check for existing state name
|
flickerstreak@109
|
508 if self.states[value] then
|
flickerstreak@109
|
509 ReAction:UserError(format(L["State named '%s' already exists"],value))
|
flickerstreak@109
|
510 return
|
flickerstreak@109
|
511 end
|
flickerstreak@109
|
512 local args = optionMap[self.bar].args
|
flickerstreak@109
|
513 local name = self:GetName()
|
flickerstreak@109
|
514 self.states[value], args[value], self.states[name], args[name] = self.states[name], args[name], nil, nil
|
flickerstreak@109
|
515 self:SetName(value)
|
flickerstreak@109
|
516 ApplyStates(self.bar)
|
flickerstreak@109
|
517 ReAction:ShowEditor(self.bar, moduleID, value)
|
flickerstreak@109
|
518 end
|
flickerstreak@109
|
519
|
flickerstreak@109
|
520 function StateHandler:MoveStateUp()
|
flickerstreak@109
|
521 local before, after = self:GetNeighbors()
|
flickerstreak@109
|
522 if before then
|
flickerstreak@109
|
523 self:SwapOrder(before, self:GetName())
|
flickerstreak@109
|
524 ApplyStates(self.bar)
|
flickerstreak@109
|
525 end
|
flickerstreak@109
|
526 end
|
flickerstreak@109
|
527
|
flickerstreak@109
|
528 function StateHandler:MoveStateDown()
|
flickerstreak@109
|
529 local before, after = self:GetNeighbors()
|
flickerstreak@109
|
530 if after then
|
flickerstreak@109
|
531 self:SwapOrder(self:GetName(), after)
|
flickerstreak@109
|
532 ApplyStates(self.bar)
|
flickerstreak@109
|
533 end
|
flickerstreak@109
|
534 end
|
flickerstreak@109
|
535
|
flickerstreak@109
|
536 function StateHandler:GetAnchorDisabled()
|
flickerstreak@109
|
537 return not GetProperty(self.bar, self:GetName(), "anchorEnable")
|
flickerstreak@109
|
538 end
|
flickerstreak@109
|
539
|
Flick@239
|
540 function StateHandler:IsPageDisabled()
|
Flick@239
|
541 local n = self.bar:GetConfig().nPages or 1
|
Flick@239
|
542 return not (n > 1)
|
Flick@239
|
543 end
|
Flick@239
|
544
|
Flick@239
|
545 function StateHandler:IsPageHidden()
|
Flick@239
|
546 return not self.bar:GetConfig().nPages
|
Flick@239
|
547 end
|
Flick@239
|
548
|
Flick@239
|
549 function StateHandler:GetPageValues()
|
Flick@239
|
550 if not self._pagevalues then
|
Flick@239
|
551 self._pagevalues = { }
|
Flick@239
|
552 end
|
Flick@239
|
553 local n = self.bar:GetConfig().nPages
|
Flick@239
|
554 -- cache the results
|
Flick@239
|
555 if self._npages ~= n then
|
Flick@239
|
556 self._npages = n
|
Flick@239
|
557 wipe(self._pagevalues)
|
Flick@239
|
558 for i = 1, n do
|
Flick@239
|
559 self._pagevalues["page"..i] = i
|
Flick@239
|
560 end
|
Flick@239
|
561 end
|
Flick@239
|
562 return self._pagevalues
|
Flick@239
|
563 end
|
Flick@239
|
564
|
Flick@239
|
565 function StateHandler:GetPage(info)
|
Flick@239
|
566 return self:GetProp(info) or 1
|
Flick@239
|
567 end
|
Flick@239
|
568
|
flickerstreak@109
|
569 function StateHandler:GetAnchorFrames(info)
|
flickerstreak@109
|
570 self._anchorframes = self._anchorframes or { }
|
flickerstreak@109
|
571 table.wipe(self._anchorframes)
|
flickerstreak@109
|
572
|
flickerstreak@109
|
573 table.insert(self._anchorframes, "UIParent")
|
flickerstreak@109
|
574 for name, bar in ReAction:IterateBars() do
|
flickerstreak@109
|
575 table.insert(self._anchorframes, bar:GetFrame():GetName())
|
flickerstreak@109
|
576 end
|
flickerstreak@109
|
577 return self._anchorframes
|
flickerstreak@109
|
578 end
|
flickerstreak@109
|
579
|
flickerstreak@109
|
580 function StateHandler:GetAnchorFrame(info)
|
flickerstreak@109
|
581 local value = self:GetProp(info)
|
flickerstreak@109
|
582 for k,v in pairs(self._anchorframes) do
|
flickerstreak@109
|
583 if v == value then
|
flickerstreak@109
|
584 return k
|
flickerstreak@109
|
585 end
|
flickerstreak@109
|
586 end
|
flickerstreak@109
|
587 end
|
flickerstreak@109
|
588
|
flickerstreak@109
|
589 function StateHandler:SetAnchorFrame(info, value)
|
flickerstreak@109
|
590 local f = _G[self._anchorframes[value]]
|
flickerstreak@109
|
591 if f then
|
flickerstreak@157
|
592 self.bar:SetFrameRef("anchor-"..self:GetName(), f)
|
flickerstreak@109
|
593 self:SetProp(info, f:GetName())
|
flickerstreak@109
|
594 end
|
flickerstreak@109
|
595 end
|
flickerstreak@109
|
596
|
flickerstreak@109
|
597 function StateHandler:SetAnchorPointProp(info, value)
|
flickerstreak@109
|
598 self:SetProp(info, value ~= "NONE" and value or nil)
|
flickerstreak@109
|
599 end
|
flickerstreak@109
|
600
|
flickerstreak@109
|
601 function StateHandler:GetAnchorPointProp(info)
|
flickerstreak@109
|
602 return self:GetProp(info) or "NONE"
|
flickerstreak@109
|
603 end
|
flickerstreak@109
|
604
|
flickerstreak@109
|
605 function StateHandler:GetScale(info)
|
flickerstreak@109
|
606 return self:GetProp(info) or 1.0
|
flickerstreak@109
|
607 end
|
flickerstreak@109
|
608
|
flickerstreak@109
|
609 function StateHandler:GetScaleDisabled()
|
flickerstreak@109
|
610 return not GetProperty(self.bar, self:GetName(), "enableScale")
|
flickerstreak@109
|
611 end
|
flickerstreak@109
|
612
|
flickerstreak@109
|
613 function StateHandler:GetAlpha(info)
|
flickerstreak@109
|
614 return self:GetProp(info) or 1.0
|
flickerstreak@109
|
615 end
|
flickerstreak@109
|
616
|
flickerstreak@109
|
617 function StateHandler:GetAlphaDisabled()
|
flickerstreak@109
|
618 return not GetProperty(self.bar, self:GetName(), "enableAlpha")
|
flickerstreak@109
|
619 end
|
flickerstreak@109
|
620
|
flickerstreak@109
|
621 function StateHandler:SetType(info, value)
|
flickerstreak@109
|
622 self:SetRuleField("type", value)
|
flickerstreak@109
|
623 self:FixAll()
|
flickerstreak@109
|
624 ApplyStates(self.bar)
|
flickerstreak@109
|
625 end
|
flickerstreak@109
|
626
|
flickerstreak@109
|
627 function StateHandler:GetType()
|
flickerstreak@109
|
628 return self:GetRuleField("type")
|
flickerstreak@109
|
629 end
|
flickerstreak@109
|
630
|
flickerstreak@109
|
631 function StateHandler:GetClearAllDisabled()
|
flickerstreak@109
|
632 local t = self:GetRuleField("type")
|
flickerstreak@109
|
633 return not( t == "any" or t == "all" or t == "custom")
|
flickerstreak@109
|
634 end
|
flickerstreak@109
|
635
|
flickerstreak@109
|
636 function StateHandler:ClearAllConditions()
|
flickerstreak@109
|
637 local t = self:GetRuleField("type")
|
flickerstreak@109
|
638 if t == "custom" then
|
flickerstreak@109
|
639 self:SetRuleField("custom","")
|
flickerstreak@109
|
640 elseif t == "any" or t == "all" then
|
flickerstreak@109
|
641 self:SetRuleField("values", {})
|
flickerstreak@109
|
642 end
|
flickerstreak@109
|
643 ApplyStates(self.bar)
|
flickerstreak@109
|
644 end
|
flickerstreak@109
|
645
|
flickerstreak@109
|
646 function StateHandler:GetConditionsDisabled()
|
flickerstreak@109
|
647 local t = self:GetRuleField("type")
|
flickerstreak@109
|
648 return not( t == "any" or t == "all")
|
flickerstreak@109
|
649 end
|
flickerstreak@109
|
650
|
flickerstreak@109
|
651 function StateHandler:SetCondition(info, key, value)
|
flickerstreak@109
|
652 self:SetRuleField(ruleMap[key], value or nil, "values")
|
flickerstreak@109
|
653 if value then
|
flickerstreak@109
|
654 self:FixAll(ruleMap[key])
|
flickerstreak@109
|
655 end
|
flickerstreak@109
|
656 ApplyStates(self.bar)
|
flickerstreak@109
|
657 end
|
flickerstreak@109
|
658
|
flickerstreak@109
|
659 function StateHandler:GetCondition(info, key)
|
flickerstreak@109
|
660 return self:GetRuleField("values", ruleMap[key]) or false
|
flickerstreak@109
|
661 end
|
flickerstreak@109
|
662
|
flickerstreak@109
|
663 function StateHandler:GetCustomDisabled()
|
flickerstreak@109
|
664 return self:GetRuleField("type") ~= "custom"
|
flickerstreak@109
|
665 end
|
flickerstreak@109
|
666
|
flickerstreak@109
|
667 function StateHandler:SetCustomRule(info, value)
|
flickerstreak@109
|
668 self:SetRuleField("custom",value)
|
flickerstreak@109
|
669 ApplyStates(self.bar)
|
flickerstreak@109
|
670 end
|
flickerstreak@109
|
671
|
flickerstreak@109
|
672 function StateHandler:GetCustomRule()
|
flickerstreak@109
|
673 return self:GetRuleField("custom") or ""
|
flickerstreak@109
|
674 end
|
flickerstreak@109
|
675
|
flickerstreak@109
|
676 function StateHandler:ValidateCustomRule(info, value)
|
flickerstreak@109
|
677 local s = value:gsub("%s","") -- remove all spaces
|
flickerstreak@109
|
678 -- unfortunately %b and captures don't support the '+' notation, or this would be considerably simpler
|
flickerstreak@109
|
679 repeat
|
flickerstreak@109
|
680 if s == "" then
|
flickerstreak@109
|
681 return true
|
flickerstreak@109
|
682 end
|
flickerstreak@109
|
683 local c, r = s:match("(%b[])(.*)")
|
flickerstreak@109
|
684 if c == nil and s and #s > 0 then
|
flickerstreak@109
|
685 return format(L["Invalid custom rule '%s': each clause must appear within [brackets]"],value or "")
|
flickerstreak@109
|
686 end
|
flickerstreak@109
|
687 s = r
|
flickerstreak@109
|
688 until c == nil
|
flickerstreak@109
|
689 return true
|
flickerstreak@109
|
690 end
|
flickerstreak@109
|
691
|
flickerstreak@109
|
692 function StateHandler:GetKeybindDisabled()
|
flickerstreak@109
|
693 return self:GetRuleField("type") ~= "keybind"
|
flickerstreak@109
|
694 end
|
flickerstreak@109
|
695
|
flickerstreak@109
|
696 function StateHandler:GetKeybind()
|
flickerstreak@109
|
697 return self:GetRuleField("keybind")
|
flickerstreak@109
|
698 end
|
flickerstreak@109
|
699
|
flickerstreak@109
|
700 function StateHandler:SetKeybind(info, value)
|
flickerstreak@109
|
701 if value and #value == 0 then
|
flickerstreak@109
|
702 value = nil
|
flickerstreak@109
|
703 end
|
flickerstreak@109
|
704 self:SetRuleField("keybind",value)
|
flickerstreak@109
|
705 ApplyStates(self.bar)
|
flickerstreak@109
|
706 end
|
flickerstreak@109
|
707
|
flickerstreak@109
|
708 local function CreateStateOptions(bar, name)
|
flickerstreak@109
|
709 local opts = {
|
flickerstreak@109
|
710 type = "group",
|
flickerstreak@109
|
711 name = name,
|
flickerstreak@109
|
712 childGroups = "tab",
|
flickerstreak@109
|
713 args = stateOptions
|
flickerstreak@109
|
714 }
|
flickerstreak@109
|
715
|
flickerstreak@109
|
716 opts.handler = StateHandler:New(bar,opts)
|
flickerstreak@109
|
717
|
flickerstreak@109
|
718 return opts
|
flickerstreak@109
|
719 end
|
flickerstreak@109
|
720
|
flickerstreak@109
|
721 function module:GetBarOptions(bar)
|
flickerstreak@109
|
722 local private = { }
|
Flick@228
|
723 local states = tbuild(bar:GetConfig(), "states")
|
flickerstreak@109
|
724 local options = {
|
flickerstreak@109
|
725 name = L["Dynamic State"],
|
flickerstreak@109
|
726 type = "group",
|
flickerstreak@109
|
727 order = -1,
|
flickerstreak@109
|
728 childGroups = "tree",
|
flickerstreak@109
|
729 disabled = InCombatLockdown,
|
flickerstreak@109
|
730 args = {
|
flickerstreak@109
|
731 __desc__ = {
|
flickerstreak@109
|
732 name = L["States are evaluated in the order they are listed"],
|
flickerstreak@109
|
733 order = 1,
|
flickerstreak@109
|
734 type = "description",
|
flickerstreak@109
|
735 },
|
flickerstreak@109
|
736 __new__ = {
|
flickerstreak@109
|
737 name = L["New State..."],
|
flickerstreak@109
|
738 order = 2,
|
flickerstreak@109
|
739 type = "group",
|
flickerstreak@109
|
740 args = {
|
flickerstreak@109
|
741 name = {
|
flickerstreak@109
|
742 name = L["State Name"],
|
flickerstreak@109
|
743 desc = L["Set a name for the new state"],
|
flickerstreak@109
|
744 order = 1,
|
flickerstreak@109
|
745 type = "input",
|
flickerstreak@109
|
746 get = function() return private.newstatename or "" end,
|
flickerstreak@109
|
747 set = function(info,value) private.newstatename = value end,
|
flickerstreak@109
|
748 pattern = "^%w*$",
|
flickerstreak@109
|
749 usage = L["State names must be alphanumeric without spaces"],
|
flickerstreak@109
|
750 },
|
flickerstreak@109
|
751 create = {
|
flickerstreak@109
|
752 name = L["Create State"],
|
flickerstreak@109
|
753 order = 2,
|
flickerstreak@109
|
754 type = "execute",
|
flickerstreak@109
|
755 func = function ()
|
flickerstreak@109
|
756 local name = private.newstatename
|
flickerstreak@109
|
757 if states[name] then
|
flickerstreak@109
|
758 ReAction:UserError(format(L["State named '%s' already exists"],name))
|
flickerstreak@109
|
759 else
|
flickerstreak@109
|
760 -- TODO: select default state options and pass as final argument
|
flickerstreak@109
|
761 states[name] = { }
|
flickerstreak@109
|
762 optionMap[bar].args[name] = CreateStateOptions(bar,name)
|
flickerstreak@109
|
763 ReAction:ShowEditor(bar, moduleID, name)
|
flickerstreak@109
|
764 private.newstatename = ""
|
flickerstreak@109
|
765 end
|
flickerstreak@109
|
766 end,
|
flickerstreak@109
|
767 disabled = function()
|
flickerstreak@109
|
768 local name = private.newstatename or ""
|
flickerstreak@109
|
769 return #name == 0 or name:find("%W")
|
flickerstreak@109
|
770 end,
|
flickerstreak@109
|
771 }
|
flickerstreak@109
|
772 }
|
flickerstreak@109
|
773 }
|
flickerstreak@109
|
774 }
|
flickerstreak@109
|
775 }
|
flickerstreak@109
|
776 for name, config in pairs(states) do
|
flickerstreak@109
|
777 options.args[name] = CreateStateOptions(bar,name)
|
flickerstreak@109
|
778 end
|
flickerstreak@109
|
779 optionMap[bar] = options
|
flickerstreak@109
|
780 return options
|
flickerstreak@109
|
781 end
|
flickerstreak@109
|
782 end
|
flickerstreak@109
|
783
|
flickerstreak@109
|
784
|
flickerstreak@109
|
785 -- Export methods to Bar class --
|
flickerstreak@109
|
786
|
flickerstreak@109
|
787 ReAction.Bar.GetStateProperty = GetProperty
|
flickerstreak@109
|
788 ReAction.Bar.SetStateProperty = SetProperty
|