flickerstreak@25
|
1 --[[
|
flickerstreak@62
|
2 ReAction bar state driver interface
|
flickerstreak@25
|
3
|
flickerstreak@25
|
4 --]]
|
flickerstreak@25
|
5
|
flickerstreak@25
|
6 -- local imports
|
flickerstreak@25
|
7 local ReAction = ReAction
|
flickerstreak@25
|
8 local L = ReAction.L
|
flickerstreak@25
|
9 local _G = _G
|
flickerstreak@90
|
10 local format = string.format
|
flickerstreak@25
|
11 local InCombatLockdown = InCombatLockdown
|
flickerstreak@90
|
12 local RegisterStateDriver = RegisterStateDriver
|
flickerstreak@25
|
13
|
flickerstreak@80
|
14 ReAction:UpdateRevision("$Revision$")
|
flickerstreak@77
|
15
|
flickerstreak@25
|
16 -- module declaration
|
flickerstreak@25
|
17 local moduleID = "State"
|
flickerstreak@65
|
18 local module = ReAction:NewModule( moduleID, "AceEvent-3.0" )
|
flickerstreak@62
|
19
|
flickerstreak@64
|
20 -- Utility --
|
flickerstreak@62
|
21
|
flickerstreak@62
|
22 -- traverse a table tree by key list and fetch the result or first nil
|
flickerstreak@62
|
23 local function tfetch(t, ...)
|
flickerstreak@62
|
24 for i = 1, select('#', ...) do
|
flickerstreak@62
|
25 t = t and t[select(i, ...)]
|
flickerstreak@62
|
26 end
|
flickerstreak@62
|
27 return t
|
flickerstreak@62
|
28 end
|
flickerstreak@62
|
29
|
flickerstreak@62
|
30 -- traverse a table tree by key list and build tree as necessary
|
flickerstreak@62
|
31 local function tbuild(t, ...)
|
flickerstreak@62
|
32 for i = 1, select('#', ...) do
|
flickerstreak@62
|
33 local key = select(i, ...)
|
flickerstreak@62
|
34 if not t[key] then t[key] = { } end
|
flickerstreak@62
|
35 t = t[key]
|
flickerstreak@62
|
36 end
|
flickerstreak@62
|
37 return t
|
flickerstreak@62
|
38 end
|
flickerstreak@62
|
39
|
flickerstreak@75
|
40 -- return a new array of keys of table 't', sorted by comparing
|
flickerstreak@75
|
41 -- sub-fields (obtained via tfetch) of the table values
|
flickerstreak@75
|
42 local function fieldsort( t, ... )
|
flickerstreak@75
|
43 local r = { }
|
flickerstreak@75
|
44 for k in pairs(t) do
|
flickerstreak@75
|
45 table.insert(r,k)
|
flickerstreak@75
|
46 end
|
flickerstreak@75
|
47 local path = { ... }
|
flickerstreak@75
|
48 table.sort(r, function(lhs, rhs)
|
flickerstreak@75
|
49 local olhs = tfetch(t[lhs], unpack(path)) or 0
|
flickerstreak@75
|
50 local orhs = tfetch(t[rhs], unpack(path)) or 0
|
flickerstreak@75
|
51 return olhs < orhs
|
flickerstreak@75
|
52 end)
|
flickerstreak@75
|
53 return r
|
flickerstreak@75
|
54 end
|
flickerstreak@75
|
55
|
flickerstreak@68
|
56
|
flickerstreak@90
|
57 local InitRules, ApplyStates, CleanupStates, SetProperty, GetProperty, RegisterProperty, ShowAll
|
flickerstreak@75
|
58
|
flickerstreak@75
|
59 -- PRIVATE --
|
flickerstreak@64
|
60 do
|
flickerstreak@90
|
61
|
flickerstreak@90
|
62 -- the field names must match the field names of the options table, below
|
flickerstreak@90
|
63 -- the field values are secure snippets
|
flickerstreak@90
|
64 local properties = {
|
flickerstreak@90
|
65 hide =
|
flickerstreak@90
|
66 [[
|
flickerstreak@90
|
67 local h = hide and hide[state] and not showAll
|
flickerstreak@90
|
68 if h ~= hidden then
|
flickerstreak@90
|
69 if h then
|
flickerstreak@90
|
70 self:Hide()
|
flickerstreak@90
|
71 else
|
flickerstreak@90
|
72 self:Show()
|
flickerstreak@90
|
73 end
|
flickerstreak@90
|
74 hidden = h
|
flickerstreak@90
|
75 end
|
flickerstreak@98
|
76 if showAll then
|
flickerstreak@98
|
77 control:CallMethod("UpdateHiddenLabel",hide[state])
|
flickerstreak@98
|
78 end
|
flickerstreak@90
|
79 ]],
|
flickerstreak@90
|
80
|
flickerstreak@90
|
81 --keybindState TODO: broken
|
flickerstreak@90
|
82
|
flickerstreak@90
|
83 -- the anchoring is handled in a special handler
|
flickerstreak@90
|
84 anchorEnable = true,
|
flickerstreak@90
|
85 --anchorFrame = true, TODO: broken
|
flickerstreak@90
|
86 anchorPoint = true,
|
flickerstreak@90
|
87 anchorRelPoint = true,
|
flickerstreak@90
|
88 anchorX = true,
|
flickerstreak@90
|
89 anchorY = true,
|
flickerstreak@90
|
90 enableScale = true,
|
flickerstreak@90
|
91 scale = true,
|
flickerstreak@90
|
92 }
|
flickerstreak@90
|
93
|
flickerstreak@92
|
94 local weak = { __mode = "k" }
|
flickerstreak@92
|
95 local statedrivers = setmetatable( { }, weak )
|
flickerstreak@92
|
96 local keybinds = setmetatable( { }, weak )
|
flickerstreak@90
|
97
|
flickerstreak@90
|
98 --
|
flickerstreak@90
|
99 -- Secure Handler Snippets
|
flickerstreak@90
|
100 --
|
flickerstreak@90
|
101 local SetHandlerData, SetStateDriver, SetStateKeybind, RefreshState
|
flickerstreak@90
|
102 do
|
flickerstreak@90
|
103 local stateHandler_propInit =
|
flickerstreak@90
|
104 [[
|
flickerstreak@90
|
105 propfuncs = table.new()
|
flickerstreak@90
|
106 local proplist = self:GetAttribute("prop-func-list")
|
flickerstreak@90
|
107 for s in string.gmatch(proplist, "(%w+)") do
|
flickerstreak@90
|
108 table.insert(propfuncs, s)
|
flickerstreak@90
|
109 end
|
flickerstreak@90
|
110 ]]
|
flickerstreak@90
|
111
|
flickerstreak@90
|
112 local onStateHandler =
|
flickerstreak@90
|
113 -- function _onstate-reaction( self, stateid, newstate )
|
flickerstreak@90
|
114 [[
|
flickerstreak@90
|
115 set_state = newstate or set_state
|
flickerstreak@90
|
116
|
flickerstreak@90
|
117 local oldState = state
|
flickerstreak@90
|
118 state = state_override or set_state or state
|
flickerstreak@90
|
119
|
flickerstreak@90
|
120 for i = 1, #propfuncs do
|
flickerstreak@90
|
121 control:RunAttribute("func-"..propfuncs[i])
|
flickerstreak@90
|
122 end
|
flickerstreak@90
|
123
|
flickerstreak@90
|
124 if anchorEnable and anchorEnable[state] ~= anchorstate then
|
flickerstreak@90
|
125 anchorstate = anchorEnable[state]
|
flickerstreak@90
|
126 control:RunAttribute("func-doanchor")
|
flickerstreak@90
|
127 end
|
flickerstreak@90
|
128
|
flickerstreak@90
|
129 control:ChildUpdate()
|
flickerstreak@90
|
130 ]]
|
flickerstreak@90
|
131
|
flickerstreak@90
|
132 local anchorHandler =
|
flickerstreak@90
|
133 -- function func-doanchor( self )
|
flickerstreak@90
|
134 [[
|
flickerstreak@90
|
135 -- TODO
|
flickerstreak@90
|
136 if anchorstate then
|
flickerstreak@90
|
137 -- TODO: get anchor data from state tables
|
flickerstreak@90
|
138 else
|
flickerstreak@90
|
139 -- TODO: get anchor data from defaults
|
flickerstreak@90
|
140 end
|
flickerstreak@90
|
141 ]]
|
flickerstreak@90
|
142
|
flickerstreak@90
|
143 local onClickHandler =
|
flickerstreak@90
|
144 -- function OnClick( self, button, down )
|
flickerstreak@90
|
145 [[
|
flickerstreak@90
|
146 if state_override == button then
|
flickerstreak@90
|
147 state_override = nil -- toggle
|
flickerstreak@90
|
148 else
|
flickerstreak@90
|
149 state_override = button
|
flickerstreak@90
|
150 end
|
flickerstreak@90
|
151 ]] .. onStateHandler
|
flickerstreak@90
|
152
|
flickerstreak@90
|
153 -- Construct a lua assignment as a code string and execute it within the header
|
flickerstreak@90
|
154 -- frame's sandbox. 'value' must be a string, boolean, number, or nil. If called
|
flickerstreak@90
|
155 -- with four arguments, then it treats 'varname' as an existing global table and
|
flickerstreak@90
|
156 -- sets a key-value pair. For a slight efficiency boost, pass the values in as
|
flickerstreak@90
|
157 -- attributes and fetch them as attributes from the snippet code, to leverage snippet
|
flickerstreak@90
|
158 -- caching.
|
flickerstreak@90
|
159 function SetHandlerData( bar, varname, value, key )
|
flickerstreak@90
|
160 local f = bar:GetFrame()
|
flickerstreak@90
|
161 f:SetAttribute("data-varname",varname)
|
flickerstreak@90
|
162 f:SetAttribute("data-value", value)
|
flickerstreak@90
|
163 f:SetAttribute("data-key", key)
|
flickerstreak@90
|
164 f:Execute(
|
flickerstreak@90
|
165 [[
|
flickerstreak@90
|
166 local name = self:GetAttribute("data-varname")
|
flickerstreak@90
|
167 local value = self:GetAttribute("data-value")
|
flickerstreak@90
|
168 local key = self:GetAttribute("data-key")
|
flickerstreak@90
|
169 if name then
|
flickerstreak@90
|
170 if key then
|
flickerstreak@90
|
171 if not _G[name] then
|
flickerstreak@90
|
172 _G[name] = table.new()
|
flickerstreak@90
|
173 end
|
flickerstreak@90
|
174 _G[name][key] = value
|
flickerstreak@90
|
175 else
|
flickerstreak@90
|
176 _G[name] = value
|
flickerstreak@90
|
177 end
|
flickerstreak@90
|
178 end
|
flickerstreak@90
|
179 ]])
|
flickerstreak@90
|
180 end
|
flickerstreak@90
|
181
|
flickerstreak@90
|
182 function SetDefaultAnchor( bar )
|
flickerstreak@90
|
183 local point, frame, relPoint, x, y = bar:GetAnchor()
|
flickerstreak@90
|
184 SetHandlerData(bar, "defaultAnchor", point, "point")
|
flickerstreak@90
|
185 SetHandlerData(bar, "defaultAnchor", relPoint, "relPoint")
|
flickerstreak@90
|
186 SetHandlerData(bar, "defaultAnchor", x, "x")
|
flickerstreak@90
|
187 SetHandlerData(bar, "defaultAnchor", y, "y")
|
flickerstreak@90
|
188
|
flickerstreak@90
|
189 if frame then
|
flickerstreak@90
|
190 local f = bar:GetFrame()
|
flickerstreak@90
|
191 f:SetFrameRef("defaultAnchor", f)
|
flickerstreak@90
|
192 f:Execute(
|
flickerstreak@90
|
193 [[
|
flickerstreak@90
|
194 defaultAnchor.frame = self:GetAttribute("frameref-defaultAnchor")
|
flickerstreak@90
|
195 ]])
|
flickerstreak@90
|
196 end
|
flickerstreak@90
|
197 end
|
flickerstreak@90
|
198
|
flickerstreak@90
|
199 function RefreshState( bar )
|
flickerstreak@90
|
200 SetDefaultAnchor(bar)
|
flickerstreak@95
|
201 bar:GetFrame():Execute(
|
flickerstreak@95
|
202 [[
|
flickerstreak@95
|
203 if self:GetAttribute("reaction-refresh") then
|
flickerstreak@95
|
204 control:RunAttribute("reaction-refresh")
|
flickerstreak@95
|
205 end
|
flickerstreak@95
|
206 ]])
|
flickerstreak@90
|
207 end
|
flickerstreak@90
|
208
|
flickerstreak@90
|
209 function SetStateDriver( bar, rule )
|
flickerstreak@90
|
210 local f = bar:GetFrame()
|
flickerstreak@90
|
211
|
flickerstreak@98
|
212 if not f.UpdateHiddenLabel then
|
flickerstreak@98
|
213 function f:UpdateHiddenLabel(hide)
|
flickerstreak@98
|
214 bar:SetLabelSubtext( hide and L["Hidden"] )
|
flickerstreak@98
|
215 end
|
flickerstreak@98
|
216 end
|
flickerstreak@98
|
217
|
flickerstreak@90
|
218 local props = { }
|
flickerstreak@90
|
219 for p, h in pairs(properties) do
|
flickerstreak@90
|
220 if type(h) == "string" then
|
flickerstreak@90
|
221 table.insert(props,p)
|
flickerstreak@90
|
222 f:SetAttribute("func-"..p, h)
|
flickerstreak@90
|
223 end
|
flickerstreak@90
|
224 end
|
flickerstreak@90
|
225 f:SetAttribute("prop-func-list", table.concat(props," "))
|
flickerstreak@90
|
226 f:Execute(stateHandler_propInit)
|
flickerstreak@90
|
227 f:SetAttribute("reaction-refresh", onStateHandler)
|
flickerstreak@90
|
228 f:SetAttribute("func-doanchor", anchorHandler)
|
flickerstreak@90
|
229
|
flickerstreak@90
|
230 if rule and #rule > 0 then
|
flickerstreak@90
|
231 f:SetAttribute( "_onstate-reaction", onStateHandler )
|
flickerstreak@90
|
232 RegisterStateDriver(f, "reaction", rule)
|
flickerstreak@90
|
233 statedrivers[bar] = rule
|
flickerstreak@90
|
234 elseif statedrivers[bar] then
|
flickerstreak@90
|
235 UnregisterStateDriver(f, "reaction")
|
flickerstreak@90
|
236 f:SetAttribute( "_onstate-reaction", nil )
|
flickerstreak@90
|
237 statedrivers[bar] = nil
|
flickerstreak@90
|
238 end
|
flickerstreak@90
|
239 end
|
flickerstreak@90
|
240
|
flickerstreak@90
|
241 function SetStateKeybind( bar, key, state )
|
flickerstreak@90
|
242 local f = bar:GetFrame()
|
flickerstreak@90
|
243
|
flickerstreak@90
|
244 local kb = keybinds[bar]
|
flickerstreak@90
|
245 if kb == nil then
|
flickerstreak@90
|
246 if key == nil then
|
flickerstreak@90
|
247 -- nothing to do
|
flickerstreak@90
|
248 return
|
flickerstreak@90
|
249 end
|
flickerstreak@90
|
250 kb = { }
|
flickerstreak@90
|
251 keybinds[bar] = kb
|
flickerstreak@90
|
252 end
|
flickerstreak@90
|
253
|
flickerstreak@90
|
254 -- clear the old binding, if any
|
flickerstreak@90
|
255 if kb[state] then
|
flickerstreak@90
|
256 SetOverrideBinding(f, false, kb[state], nil)
|
flickerstreak@90
|
257 end
|
flickerstreak@90
|
258 kb[state] = key
|
flickerstreak@90
|
259
|
flickerstreak@90
|
260 if key then
|
flickerstreak@90
|
261 f:SetAttribute("_onclick", onClickHandler)
|
flickerstreak@90
|
262 SetOverrideBindingClick(f, false, key, state, nil) -- state name is the virtual mouse button
|
flickerstreak@90
|
263 end
|
flickerstreak@90
|
264 end
|
flickerstreak@90
|
265 end
|
flickerstreak@90
|
266
|
flickerstreak@67
|
267 -- As far as I can tell the macro clauses are NOT locale-specific.
|
flickerstreak@67
|
268 local ruleformats = {
|
flickerstreak@67
|
269 stealth = "stealth",
|
flickerstreak@67
|
270 nostealth = "nostealth",
|
flickerstreak@67
|
271 shadowform = "form:1",
|
flickerstreak@67
|
272 noshadowform = "noform",
|
flickerstreak@67
|
273 pet = "pet",
|
flickerstreak@67
|
274 nopet = "nopet",
|
flickerstreak@67
|
275 harm = "target=target,harm",
|
flickerstreak@67
|
276 help = "target=target,help",
|
flickerstreak@67
|
277 notarget = "target=target,noexists",
|
flickerstreak@67
|
278 focusharm = "target=focus,harm",
|
flickerstreak@67
|
279 focushelp = "target=focus,help",
|
flickerstreak@67
|
280 nofocus = "target=focus,noexists",
|
flickerstreak@67
|
281 raid = "group:raid",
|
flickerstreak@67
|
282 party = "group:party",
|
flickerstreak@67
|
283 solo = "nogroup",
|
flickerstreak@67
|
284 combat = "combat",
|
flickerstreak@67
|
285 nocombat = "nocombat",
|
flickerstreak@75
|
286 possess = "bonusbar:5",
|
flickerstreak@67
|
287 }
|
flickerstreak@65
|
288
|
flickerstreak@97
|
289 -- Have to do these shenanigans instead of hardcoding the stances/forms because the
|
flickerstreak@97
|
290 -- ordering varies if the character is missing a form. For warriors this is rarely
|
flickerstreak@97
|
291 -- a problem (c'mon, who actually skips the level 10 def stance quest?) but for druids
|
flickerstreak@97
|
292 -- it can be. Some people never bother to do the aquatic form quest until well past
|
flickerstreak@97
|
293 -- when they get cat form, and stance 5/6 can be flight, tree, or moonkin depending
|
flickerstreak@97
|
294 -- on talents.
|
flickerstreak@65
|
295 function InitRules()
|
flickerstreak@65
|
296 local forms = { }
|
flickerstreak@67
|
297 -- sort by icon since it's locale-independent
|
flickerstreak@65
|
298 for i = 1, GetNumShapeshiftForms() do
|
flickerstreak@97
|
299 local icon, name, active = GetShapeshiftFormInfo(i)
|
flickerstreak@97
|
300 -- if it's the current form, the icon is wrong (Ability_Spell_WispSplode)
|
flickerstreak@97
|
301 -- so capture it from the spell info directly
|
flickerstreak@97
|
302 if active then
|
flickerstreak@97
|
303 local _1, _2
|
flickerstreak@97
|
304 _1, _2, icon = GetSpellInfo(name)
|
flickerstreak@97
|
305 end
|
flickerstreak@65
|
306 forms[icon] = i;
|
flickerstreak@65
|
307 end
|
flickerstreak@65
|
308 -- use 9 if not found since 9 is never a valid stance/form
|
flickerstreak@65
|
309 local defensive = forms["Interface\\Icons\\Ability_Warrior_DefensiveStance"] or 9
|
flickerstreak@65
|
310 local berserker = forms["Interface\\Icons\\Ability_Racial_Avatar"] or 9
|
flickerstreak@65
|
311 local bear = forms["Interface\\Icons\\Ability_Racial_BearForm"] or 9 -- bear and dire bear share the same icon
|
flickerstreak@65
|
312 local aquatic = forms["Interface\\Icons\\Ability_Druid_AquaticForm"] or 9
|
flickerstreak@65
|
313 local cat = forms["Interface\\Icons\\Ability_Druid_CatForm"] or 9
|
flickerstreak@65
|
314 local travel = forms["Interface\\Icons\\Ability_Druid_TravelForm"] or 9
|
flickerstreak@75
|
315 local tree = forms["Interface\\Icons\\Ability_Druid_TreeofLife"] or 9
|
flickerstreak@75
|
316 local moonkin = forms["Interface\\Icons\\Spell_Nature_ForceOfNature"] or 9
|
flickerstreak@67
|
317 local flight = forms["Interface\\Icons\\Ability_Druid_FlightForm"] or 9 -- flight and swift flight share the same icon
|
flickerstreak@65
|
318
|
flickerstreak@75
|
319 ruleformats.battle = "stance:1"
|
flickerstreak@75
|
320 ruleformats.defensive = format("stance:%d",defensive)
|
flickerstreak@75
|
321 ruleformats.berserker = format("stance:%d",berserker)
|
flickerstreak@75
|
322 ruleformats.caster = format("form:0/%d/%d/%d",aquatic, travel, flight)
|
flickerstreak@75
|
323 ruleformats.bear = format("form:%d",bear)
|
flickerstreak@75
|
324 ruleformats.cat = format("form:%d",cat)
|
flickerstreak@75
|
325 ruleformats.tree = format("form:%d",tree)
|
flickerstreak@75
|
326 ruleformats.moonkin = format("form:%d",moonkin)
|
flickerstreak@64
|
327 end
|
flickerstreak@62
|
328
|
flickerstreak@90
|
329 local function BuildRule(states)
|
flickerstreak@75
|
330 local rules = { }
|
flickerstreak@75
|
331 local default
|
flickerstreak@75
|
332
|
flickerstreak@75
|
333 for idx, state in ipairs(fieldsort(states, "rule", "order")) do
|
flickerstreak@75
|
334 local c = states[state].rule
|
flickerstreak@75
|
335 local type = c.type
|
flickerstreak@75
|
336 if type == "default" then
|
flickerstreak@75
|
337 default = default or state
|
flickerstreak@75
|
338 elseif type == "custom" then
|
flickerstreak@75
|
339 if c.custom then
|
flickerstreak@75
|
340 -- strip out all spaces from the custom rule
|
flickerstreak@75
|
341 table.insert(rules, format("%s %s", c.custom:gsub("%s",""), state))
|
flickerstreak@75
|
342 end
|
flickerstreak@95
|
343 elseif type == "any" or type == "all" then
|
flickerstreak@75
|
344 if c.values then
|
flickerstreak@75
|
345 local clauses = { }
|
flickerstreak@75
|
346 for key, value in pairs(c.values) do
|
flickerstreak@75
|
347 table.insert(clauses, ruleformats[key])
|
flickerstreak@75
|
348 end
|
flickerstreak@75
|
349 if #clauses > 0 then
|
flickerstreak@95
|
350 local sep = (type == "any") and "][" or ","
|
flickerstreak@95
|
351 table.insert(rules, format("[%s] %s", table.concat(clauses,sep), state))
|
flickerstreak@75
|
352 end
|
flickerstreak@75
|
353 end
|
flickerstreak@75
|
354 end
|
flickerstreak@75
|
355 end
|
flickerstreak@75
|
356 -- make sure that the default, if any, is last
|
flickerstreak@75
|
357 if default then
|
flickerstreak@75
|
358 table.insert(rules, default)
|
flickerstreak@75
|
359 end
|
flickerstreak@90
|
360 return table.concat(rules,";")
|
flickerstreak@90
|
361 end
|
flickerstreak@90
|
362
|
flickerstreak@90
|
363 local function BuildKeybinds( bar, states )
|
flickerstreak@90
|
364 for name, state in pairs(states) do
|
flickerstreak@90
|
365 local type = tfetch(state, "rule", "type")
|
flickerstreak@90
|
366 if type == "keybind" then
|
flickerstreak@90
|
367 local key = tfetch(state, "rule", "keybind")
|
flickerstreak@90
|
368 SetStateKeybind(bar, key, name)
|
flickerstreak@90
|
369 else
|
flickerstreak@90
|
370 SetStateKeybind(bar, nil, name) -- this clears an existing keybind
|
flickerstreak@90
|
371 end
|
flickerstreak@90
|
372 end
|
flickerstreak@90
|
373 end
|
flickerstreak@90
|
374
|
flickerstreak@90
|
375 function GetProperty( bar, state, propname )
|
flickerstreak@90
|
376 return tfetch(module.db.profile.bars, bar:GetName(), "states", state, propname)
|
flickerstreak@90
|
377 end
|
flickerstreak@90
|
378
|
flickerstreak@90
|
379 function SetProperty( bar, state, propname, value )
|
flickerstreak@90
|
380 local s = tbuild(module.db.profile.bars, bar:GetName(), "states", state)
|
flickerstreak@90
|
381 s[propname] = value
|
flickerstreak@90
|
382 SetHandlerData(bar, propname, value, state)
|
flickerstreak@90
|
383 RefreshState(bar)
|
flickerstreak@90
|
384 end
|
flickerstreak@90
|
385
|
flickerstreak@90
|
386 function RegisterProperty( propname, snippet )
|
flickerstreak@90
|
387 properties[propname] = snippet or true
|
flickerstreak@90
|
388 for _, bar in ReAction:IterateBars() do
|
flickerstreak@90
|
389 local states = tfetch(module.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@90
|
390 if states then
|
flickerstreak@90
|
391 for name, s in pairs(states) do
|
flickerstreak@90
|
392 SetHandlerData(bar, propname, s[propname], name)
|
flickerstreak@90
|
393 end
|
flickerstreak@90
|
394 SetStateDriver(bar, BuildRule(states))
|
flickerstreak@90
|
395 RefreshState(bar)
|
flickerstreak@90
|
396 end
|
flickerstreak@90
|
397 end
|
flickerstreak@90
|
398 end
|
flickerstreak@90
|
399
|
flickerstreak@90
|
400 function UnregisterProperty( propname )
|
flickerstreak@90
|
401 properties[propname] = nil
|
flickerstreak@90
|
402 for _, bar in ReAction:IterateBars() do
|
flickerstreak@90
|
403 SetHandlerData(bar, propname, nil)
|
flickerstreak@90
|
404 SetStateDriver(bar, BuildRule(states))
|
flickerstreak@90
|
405 RefreshState(bar)
|
flickerstreak@90
|
406 end
|
flickerstreak@75
|
407 end
|
flickerstreak@75
|
408
|
flickerstreak@75
|
409 function ApplyStates( bar )
|
flickerstreak@75
|
410 local states = tfetch(module.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@75
|
411 if states then
|
flickerstreak@90
|
412 for propname in pairs(properties) do
|
flickerstreak@90
|
413 for name, s in pairs(states) do
|
flickerstreak@90
|
414 SetHandlerData(bar, propname, s[propname], name)
|
flickerstreak@90
|
415 end
|
flickerstreak@75
|
416 end
|
flickerstreak@90
|
417 BuildKeybinds(bar, states)
|
flickerstreak@96
|
418 SetHandlerData(bar, "showAll", ReAction:GetConfigMode())
|
flickerstreak@90
|
419 SetStateDriver(bar, BuildRule(states))
|
flickerstreak@90
|
420 RefreshState(bar)
|
flickerstreak@68
|
421 end
|
flickerstreak@68
|
422 end
|
flickerstreak@68
|
423
|
flickerstreak@90
|
424 function CleanupStates( bar )
|
flickerstreak@90
|
425 SetStateDriver(bar, nil)
|
flickerstreak@90
|
426 end
|
flickerstreak@90
|
427
|
flickerstreak@90
|
428 function ShowAll( bar, show )
|
flickerstreak@92
|
429 if statedrivers[bar] then
|
flickerstreak@92
|
430 SetHandlerData(bar, "showAll", show)
|
flickerstreak@92
|
431 RefreshState(bar)
|
flickerstreak@92
|
432 end
|
flickerstreak@90
|
433 end
|
flickerstreak@64
|
434 end
|
flickerstreak@64
|
435
|
flickerstreak@64
|
436
|
flickerstreak@68
|
437
|
flickerstreak@68
|
438 -- module event handlers --
|
flickerstreak@68
|
439
|
flickerstreak@65
|
440 function module:OnInitialize()
|
flickerstreak@65
|
441 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@65
|
442 {
|
flickerstreak@65
|
443 profile = {
|
flickerstreak@65
|
444 bars = { },
|
flickerstreak@65
|
445 }
|
flickerstreak@65
|
446 }
|
flickerstreak@65
|
447 )
|
flickerstreak@65
|
448
|
flickerstreak@97
|
449 self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
|
flickerstreak@65
|
450
|
flickerstreak@65
|
451 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@65
|
452
|
flickerstreak@65
|
453 ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar")
|
flickerstreak@90
|
454 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@65
|
455 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@65
|
456 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@65
|
457 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@65
|
458 ReAction.RegisterCallback(self, "OnConfigModeChanged")
|
flickerstreak@65
|
459 end
|
flickerstreak@65
|
460
|
flickerstreak@97
|
461 function module:OnEnable()
|
flickerstreak@97
|
462 self:UPDATE_SHAPESHIFT_FORMS() -- it doesn't fire on a /reloadui
|
flickerstreak@97
|
463 end
|
flickerstreak@97
|
464
|
flickerstreak@97
|
465 function module:UPDATE_SHAPESHIFT_FORMS()
|
flickerstreak@97
|
466 -- Re-parse the rules table according to the new form list.
|
flickerstreak@97
|
467 -- This happens both at initial login (after PLAYER_ENTERING_WORLD)
|
flickerstreak@97
|
468 -- as well as when gaining new abilities.
|
flickerstreak@97
|
469 InitRules()
|
flickerstreak@97
|
470 for name, bar in ReAction:IterateBars() do
|
flickerstreak@97
|
471 self:OnRefreshBar(nil,bar,name)
|
flickerstreak@66
|
472 end
|
flickerstreak@65
|
473 end
|
flickerstreak@65
|
474
|
flickerstreak@65
|
475 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@65
|
476 local c = self.db.profile.bars[name]
|
flickerstreak@65
|
477 if c then
|
flickerstreak@68
|
478 ApplyStates(bar)
|
flickerstreak@65
|
479 end
|
flickerstreak@65
|
480 end
|
flickerstreak@65
|
481
|
flickerstreak@90
|
482 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@90
|
483 CleanupStates(bar)
|
flickerstreak@90
|
484 end
|
flickerstreak@90
|
485
|
flickerstreak@65
|
486 function module:OnEraseBar(event, bar, name)
|
flickerstreak@65
|
487 self.db.profile.bars[name] = nil
|
flickerstreak@65
|
488 end
|
flickerstreak@65
|
489
|
flickerstreak@65
|
490 function module:OnRenameBar(event, bar, oldname, newname)
|
flickerstreak@75
|
491 local bars = self.db.profile.bars
|
flickerstreak@65
|
492 bars[newname], bars[oldname] = bars[oldname], nil
|
flickerstreak@65
|
493 end
|
flickerstreak@65
|
494
|
flickerstreak@65
|
495 function module:OnConfigModeChanged(event, mode)
|
flickerstreak@90
|
496 for name, bar in ReAction:IterateBars() do
|
flickerstreak@90
|
497 if self.db.profile.bars[name] then
|
flickerstreak@90
|
498 ShowAll(bar, mode)
|
flickerstreak@90
|
499 end
|
flickerstreak@90
|
500 end
|
flickerstreak@65
|
501 end
|
flickerstreak@65
|
502
|
flickerstreak@64
|
503
|
flickerstreak@64
|
504
|
flickerstreak@64
|
505 -- Options --
|
flickerstreak@64
|
506
|
flickerstreak@79
|
507 local CreateBarOptions, RegisterPropertyOptions
|
flickerstreak@62
|
508 do
|
flickerstreak@79
|
509 local playerClass = select(2, UnitClass("player"))
|
flickerstreak@62
|
510 local function ClassCheck(...)
|
flickerstreak@62
|
511 for i = 1, select('#',...) do
|
flickerstreak@79
|
512 if playerClass == select(i,...) then
|
flickerstreak@62
|
513 return false
|
flickerstreak@62
|
514 end
|
flickerstreak@62
|
515 end
|
flickerstreak@62
|
516 return true
|
flickerstreak@62
|
517 end
|
flickerstreak@62
|
518
|
flickerstreak@64
|
519 -- pre-sorted by the order they should appear in
|
flickerstreak@64
|
520 local rules = {
|
flickerstreak@64
|
521 -- rule hidden fields
|
flickerstreak@64
|
522 { "stance", ClassCheck("WARRIOR"), { {battle = L["Battle Stance"]}, {defensive = L["Defensive Stance"]}, {berserker = L["Berserker Stance"]} } },
|
flickerstreak@75
|
523 { "form", ClassCheck("DRUID"), { {caster = L["Caster Form"]}, {bear = L["Bear Form"]}, {cat = L["Cat Form"]}, {tree = L["Tree of Life"]}, {moonkin = L["Moonkin Form"]} } },
|
flickerstreak@64
|
524 { "stealth", ClassCheck("ROGUE","DRUID"), { {stealth = L["Stealth"]}, {nostealth = L["No Stealth"]} } },
|
flickerstreak@64
|
525 { "shadow", ClassCheck("PRIEST"), { {shadowform = L["Shadowform"]}, {noshadowform = L["No Shadowform"]} } },
|
flickerstreak@64
|
526 { "pet", ClassCheck("HUNTER","WARLOCK"), { {pet = L["With Pet"]}, {nopet = L["Without Pet"]} } },
|
flickerstreak@64
|
527 { "target", false, { {harm = L["Hostile Target"]}, {help = L["Friendly Target"]}, {notarget = L["No Target"]} } },
|
flickerstreak@64
|
528 { "focus", false, { {focusharm = L["Hostile Focus"]}, {focushelp = L["Friendly Focus"]}, {nofocus = L["No Focus"]} } },
|
flickerstreak@75
|
529 { "possess", false, { {possess = L["Mind Control"]} } },
|
flickerstreak@64
|
530 { "group", false, { {raid = L["Raid"]}, {party = L["Party"]}, {solo = L["Solo"]} } },
|
flickerstreak@64
|
531 { "combat", false, { {combat = L["In Combat"]}, {nocombat = L["Out of Combat"]} } },
|
flickerstreak@62
|
532 }
|
flickerstreak@62
|
533
|
flickerstreak@64
|
534 local ruleSelect = { }
|
flickerstreak@64
|
535 local ruleMap = { }
|
flickerstreak@64
|
536 local optionMap = setmetatable({},{__mode="k"})
|
flickerstreak@62
|
537
|
flickerstreak@68
|
538 local pointTable = {
|
flickerstreak@68
|
539 NONE = " ",
|
flickerstreak@68
|
540 CENTER = L["Center"],
|
flickerstreak@68
|
541 LEFT = L["Left"],
|
flickerstreak@68
|
542 RIGHT = L["Right"],
|
flickerstreak@68
|
543 TOP = L["Top"],
|
flickerstreak@68
|
544 BOTTOM = L["Bottom"],
|
flickerstreak@68
|
545 TOPLEFT = L["Top Left"],
|
flickerstreak@68
|
546 TOPRIGHT = L["Top Right"],
|
flickerstreak@68
|
547 BOTTOMLEFT = L["Bottom Left"],
|
flickerstreak@68
|
548 BOTTOMRIGHT = L["Bottom Right"],
|
flickerstreak@68
|
549 }
|
flickerstreak@68
|
550
|
flickerstreak@64
|
551 -- unpack rules table into ruleSelect and ruleMap
|
flickerstreak@64
|
552 for _, c in ipairs(rules) do
|
flickerstreak@64
|
553 local rule, hidden, fields = unpack(c)
|
flickerstreak@64
|
554 if not hidden then
|
flickerstreak@64
|
555 for _, field in ipairs(fields) do
|
flickerstreak@64
|
556 local key, label = next(field)
|
flickerstreak@64
|
557 table.insert(ruleSelect, label)
|
flickerstreak@64
|
558 table.insert(ruleMap, key)
|
flickerstreak@62
|
559 end
|
flickerstreak@62
|
560 end
|
flickerstreak@62
|
561 end
|
flickerstreak@62
|
562
|
flickerstreak@79
|
563 local stateOptions = {
|
flickerstreak@79
|
564 ordering = {
|
flickerstreak@79
|
565 name = L["Info"],
|
flickerstreak@79
|
566 order = 1,
|
flickerstreak@79
|
567 type = "group",
|
flickerstreak@79
|
568 args = {
|
flickerstreak@79
|
569 delete = {
|
flickerstreak@79
|
570 name = L["Delete this State"],
|
flickerstreak@79
|
571 order = -1,
|
flickerstreak@79
|
572 type = "execute",
|
flickerstreak@79
|
573 func = "DeleteState",
|
flickerstreak@79
|
574 },
|
flickerstreak@79
|
575 rename = {
|
flickerstreak@79
|
576 name = L["Name"],
|
flickerstreak@79
|
577 order = 1,
|
flickerstreak@79
|
578 type = "input",
|
flickerstreak@79
|
579 get = "GetName",
|
flickerstreak@79
|
580 set = "SetStateName",
|
flickerstreak@79
|
581 pattern = "^%w*$",
|
flickerstreak@79
|
582 usage = L["State names must be alphanumeric without spaces"],
|
flickerstreak@79
|
583 },
|
flickerstreak@79
|
584 ordering = {
|
flickerstreak@79
|
585 name = L["Evaluation Order"],
|
flickerstreak@79
|
586 desc = L["State transitions are evaluated in the order listed:\nMove a state up or down to change the order"],
|
flickerstreak@79
|
587 order = 2,
|
flickerstreak@79
|
588 type = "group",
|
flickerstreak@79
|
589 inline = true,
|
flickerstreak@79
|
590 args = {
|
flickerstreak@79
|
591 up = {
|
flickerstreak@79
|
592 name = L["Up"],
|
flickerstreak@79
|
593 order = 1,
|
flickerstreak@79
|
594 type = "execute",
|
flickerstreak@79
|
595 width = "half",
|
flickerstreak@79
|
596 func = "MoveStateUp",
|
flickerstreak@79
|
597 },
|
flickerstreak@79
|
598 down = {
|
flickerstreak@79
|
599 name = L["Down"],
|
flickerstreak@79
|
600 order = 2,
|
flickerstreak@79
|
601 type = "execute",
|
flickerstreak@79
|
602 width = "half",
|
flickerstreak@79
|
603 func = "MoveStateDown",
|
flickerstreak@79
|
604 }
|
flickerstreak@79
|
605 }
|
flickerstreak@79
|
606 }
|
flickerstreak@79
|
607 }
|
flickerstreak@79
|
608 },
|
flickerstreak@79
|
609 properties = {
|
flickerstreak@79
|
610 name = L["Properties"],
|
flickerstreak@79
|
611 order = 2,
|
flickerstreak@79
|
612 type = "group",
|
flickerstreak@79
|
613 args = {
|
flickerstreak@79
|
614 desc = {
|
flickerstreak@79
|
615 name = L["Set the properties for the bar when in this state"],
|
flickerstreak@79
|
616 order = 1,
|
flickerstreak@79
|
617 type = "description"
|
flickerstreak@79
|
618 },
|
flickerstreak@79
|
619 hide = {
|
flickerstreak@79
|
620 name = L["Hide Bar"],
|
flickerstreak@81
|
621 order = 90,
|
flickerstreak@79
|
622 type = "toggle",
|
flickerstreak@79
|
623 set = "SetProp",
|
flickerstreak@79
|
624 get = "GetProp",
|
flickerstreak@79
|
625 },
|
flickerstreak@90
|
626 --[[ BROKEN
|
flickerstreak@90
|
627 keybindState = {
|
flickerstreak@79
|
628 name = L["Override Keybinds"],
|
flickerstreak@79
|
629 desc = L["Set this state to maintain its own set of keybinds which override the defaults when active"],
|
flickerstreak@81
|
630 order = 91,
|
flickerstreak@79
|
631 type = "toggle",
|
flickerstreak@79
|
632 set = "SetProp",
|
flickerstreak@79
|
633 get = "GetProp",
|
flickerstreak@90
|
634 }, ]]
|
flickerstreak@79
|
635 position = {
|
flickerstreak@79
|
636 name = L["Position"],
|
flickerstreak@81
|
637 order = 92,
|
flickerstreak@79
|
638 type = "group",
|
flickerstreak@79
|
639 inline = true,
|
flickerstreak@79
|
640 args = {
|
flickerstreak@90
|
641 anchorEnable = {
|
flickerstreak@79
|
642 name = L["Set New Position"],
|
flickerstreak@79
|
643 order = 1,
|
flickerstreak@79
|
644 type = "toggle",
|
flickerstreak@79
|
645 set = "SetProp",
|
flickerstreak@79
|
646 get = "GetProp",
|
flickerstreak@79
|
647 },
|
flickerstreak@90
|
648 --[[ TODO: broken
|
flickerstreak@90
|
649 anchorFrame = {
|
flickerstreak@90
|
650 name = L["Anchor Frame"],
|
flickerstreak@90
|
651 order = 2,
|
flickerstreak@90
|
652 type = "select",
|
flickerstreak@90
|
653 values = "GetAnchorFrames",
|
flickerstreak@90
|
654 set = ???
|
flickerstreak@90
|
655 get = ???
|
flickerstreak@90
|
656 }, ]]
|
flickerstreak@79
|
657 anchorPoint = {
|
flickerstreak@79
|
658 name = L["Point"],
|
flickerstreak@90
|
659 order = 3,
|
flickerstreak@79
|
660 type = "select",
|
flickerstreak@79
|
661 values = pointTable,
|
flickerstreak@79
|
662 set = "SetAnchorPointProp",
|
flickerstreak@79
|
663 get = "GetAnchorPointProp",
|
flickerstreak@79
|
664 disabled = "GetAnchorDisabled",
|
flickerstreak@79
|
665 hidden = "GetAnchorDisabled",
|
flickerstreak@79
|
666 },
|
flickerstreak@79
|
667 anchorRelPoint = {
|
flickerstreak@79
|
668 name = L["Relative Point"],
|
flickerstreak@90
|
669 order = 4,
|
flickerstreak@79
|
670 type = "select",
|
flickerstreak@79
|
671 values = pointTable,
|
flickerstreak@79
|
672 set = "SetAnchorPointProp",
|
flickerstreak@79
|
673 get = "GetAnchorPointProp",
|
flickerstreak@79
|
674 disabled = "GetAnchorDisabled",
|
flickerstreak@79
|
675 hidden = "GetAnchorDisabled",
|
flickerstreak@79
|
676 },
|
flickerstreak@79
|
677 anchorX = {
|
flickerstreak@79
|
678 name = L["X Offset"],
|
flickerstreak@90
|
679 order = 5,
|
flickerstreak@79
|
680 type = "range",
|
flickerstreak@79
|
681 min = -100,
|
flickerstreak@79
|
682 max = 100,
|
flickerstreak@79
|
683 step = 1,
|
flickerstreak@79
|
684 set = "SetProp",
|
flickerstreak@79
|
685 get = "GetProp",
|
flickerstreak@79
|
686 disabled = "GetAnchorDisabled",
|
flickerstreak@79
|
687 hidden = "GetAnchorDisabled",
|
flickerstreak@79
|
688 },
|
flickerstreak@79
|
689 anchorY = {
|
flickerstreak@79
|
690 name = L["Y Offset"],
|
flickerstreak@90
|
691 order = 6,
|
flickerstreak@79
|
692 type = "range",
|
flickerstreak@79
|
693 min = -100,
|
flickerstreak@79
|
694 max = 100,
|
flickerstreak@79
|
695 step = 1,
|
flickerstreak@79
|
696 set = "SetProp",
|
flickerstreak@79
|
697 get = "GetProp",
|
flickerstreak@79
|
698 disabled = "GetAnchorDisabled",
|
flickerstreak@79
|
699 hidden = "GetAnchorDisabled",
|
flickerstreak@79
|
700 },
|
flickerstreak@79
|
701 },
|
flickerstreak@79
|
702 },
|
flickerstreak@79
|
703 scale = {
|
flickerstreak@79
|
704 name = L["Scale"],
|
flickerstreak@81
|
705 order = 93,
|
flickerstreak@79
|
706 type = "group",
|
flickerstreak@79
|
707 inline = true,
|
flickerstreak@79
|
708 args = {
|
flickerstreak@79
|
709 enableScale = {
|
flickerstreak@79
|
710 name = L["Set New Scale"],
|
flickerstreak@79
|
711 order = 1,
|
flickerstreak@79
|
712 type = "toggle",
|
flickerstreak@79
|
713 set = "SetProp",
|
flickerstreak@79
|
714 get = "GetProp",
|
flickerstreak@79
|
715 },
|
flickerstreak@79
|
716 scale = {
|
flickerstreak@79
|
717 name = L["Scale"],
|
flickerstreak@79
|
718 order = 2,
|
flickerstreak@79
|
719 type = "range",
|
flickerstreak@79
|
720 min = 0.1,
|
flickerstreak@79
|
721 max = 2.5,
|
flickerstreak@79
|
722 step = 0.05,
|
flickerstreak@79
|
723 isPercent = true,
|
flickerstreak@79
|
724 set = "SetProp",
|
flickerstreak@79
|
725 get = "GetProp",
|
flickerstreak@79
|
726 disabled = "GetScaleDisabled",
|
flickerstreak@79
|
727 hidden = "GetScaleDisabled",
|
flickerstreak@79
|
728 },
|
flickerstreak@79
|
729 },
|
flickerstreak@79
|
730 },
|
flickerstreak@79
|
731 },
|
flickerstreak@79
|
732 plugins = { }
|
flickerstreak@79
|
733 },
|
flickerstreak@79
|
734 rules = {
|
flickerstreak@79
|
735 name = L["Rule"],
|
flickerstreak@79
|
736 order = 3,
|
flickerstreak@79
|
737 type = "group",
|
flickerstreak@79
|
738 args = {
|
flickerstreak@79
|
739 mode = {
|
flickerstreak@79
|
740 name = L["Select this state"],
|
flickerstreak@79
|
741 order = 2,
|
flickerstreak@79
|
742 type = "select",
|
flickerstreak@79
|
743 style = "radio",
|
flickerstreak@79
|
744 values = {
|
flickerstreak@79
|
745 default = L["by default"],
|
flickerstreak@79
|
746 any = L["when ANY of these"],
|
flickerstreak@79
|
747 all = L["when ALL of these"],
|
flickerstreak@79
|
748 custom = L["via custom rule"],
|
flickerstreak@79
|
749 keybind = L["via keybinding"],
|
flickerstreak@79
|
750 },
|
flickerstreak@79
|
751 set = "SetType",
|
flickerstreak@79
|
752 get = "GetType",
|
flickerstreak@79
|
753 },
|
flickerstreak@79
|
754 clear = {
|
flickerstreak@79
|
755 name = L["Clear All"],
|
flickerstreak@79
|
756 order = 3,
|
flickerstreak@79
|
757 type = "execute",
|
flickerstreak@79
|
758 hidden = "GetClearAllDisabled",
|
flickerstreak@79
|
759 disabled = "GetClearAllDisabled",
|
flickerstreak@79
|
760 func = "ClearAllConditions",
|
flickerstreak@79
|
761 },
|
flickerstreak@79
|
762 inputs = {
|
flickerstreak@79
|
763 name = L["Conditions"],
|
flickerstreak@79
|
764 order = 4,
|
flickerstreak@79
|
765 type = "multiselect",
|
flickerstreak@79
|
766 hidden = "GetConditionsDisabled",
|
flickerstreak@79
|
767 disabled = "GetConditionsDisabled",
|
flickerstreak@79
|
768 values = ruleSelect,
|
flickerstreak@79
|
769 set = "SetCondition",
|
flickerstreak@79
|
770 get = "GetCondition",
|
flickerstreak@79
|
771 },
|
flickerstreak@79
|
772 custom = {
|
flickerstreak@79
|
773 name = L["Custom Rule"],
|
flickerstreak@79
|
774 order = 5,
|
flickerstreak@79
|
775 type = "input",
|
flickerstreak@79
|
776 multiline = true,
|
flickerstreak@79
|
777 hidden = "GetCustomDisabled",
|
flickerstreak@79
|
778 disabled = "GetCustomDisabled",
|
flickerstreak@79
|
779 desc = L["Syntax like macro rules: see preset rules for examples"],
|
flickerstreak@79
|
780 set = "SetCustomRule",
|
flickerstreak@79
|
781 get = "GetCustomRule",
|
flickerstreak@79
|
782 validate = "ValidateCustomRule",
|
flickerstreak@79
|
783 },
|
flickerstreak@79
|
784 keybind = {
|
flickerstreak@79
|
785 name = L["Keybinding"],
|
flickerstreak@79
|
786 order = 6,
|
flickerstreak@79
|
787 inline = true,
|
flickerstreak@79
|
788 hidden = "GetKeybindDisabled",
|
flickerstreak@79
|
789 disabled = "GetKeybindDisabled",
|
flickerstreak@79
|
790 type = "group",
|
flickerstreak@79
|
791 args = {
|
flickerstreak@79
|
792 desc = {
|
flickerstreak@79
|
793 name = L["Invoking a state keybind toggles an override of all other transition rules."],
|
flickerstreak@79
|
794 order = 1,
|
flickerstreak@79
|
795 type = "description",
|
flickerstreak@79
|
796 },
|
flickerstreak@79
|
797 keybind = {
|
flickerstreak@79
|
798 name = L["State Hotkey"],
|
flickerstreak@79
|
799 desc = L["Define an override toggle keybind"],
|
flickerstreak@79
|
800 order = 2,
|
flickerstreak@79
|
801 type = "keybinding",
|
flickerstreak@79
|
802 set = "SetKeybind",
|
flickerstreak@79
|
803 get = "GetKeybind",
|
flickerstreak@79
|
804 },
|
flickerstreak@79
|
805 },
|
flickerstreak@79
|
806 },
|
flickerstreak@79
|
807 },
|
flickerstreak@79
|
808 },
|
flickerstreak@79
|
809 }
|
flickerstreak@79
|
810
|
flickerstreak@90
|
811 local handlers = { }
|
flickerstreak@90
|
812 local meta = {
|
flickerstreak@90
|
813 __index = function(self, key)
|
flickerstreak@90
|
814 for _, h in pairs(handlers) do
|
flickerstreak@90
|
815 if h[key] then
|
flickerstreak@90
|
816 return h[key]
|
flickerstreak@90
|
817 end
|
flickerstreak@90
|
818 end
|
flickerstreak@90
|
819 end,
|
flickerstreak@90
|
820 }
|
flickerstreak@90
|
821 local StateHandler = setmetatable({ }, meta)
|
flickerstreak@90
|
822 local proto = { __index = StateHandler }
|
flickerstreak@90
|
823
|
flickerstreak@90
|
824 function RegisterPropertyOptions( field, options, handler )
|
flickerstreak@90
|
825 stateOptions.properties.plugins[field] = options
|
flickerstreak@90
|
826 handlers[field] = handler
|
flickerstreak@90
|
827 end
|
flickerstreak@90
|
828
|
flickerstreak@90
|
829 function UnregisterPropertyOptions( field )
|
flickerstreak@90
|
830 stateOptions.properties.plugins[field] = nil
|
flickerstreak@90
|
831 handlers[field] = nil
|
flickerstreak@90
|
832 end
|
flickerstreak@79
|
833
|
flickerstreak@79
|
834 function StateHandler:New( bar, opts )
|
flickerstreak@90
|
835 local self = setmetatable(
|
flickerstreak@90
|
836 {
|
flickerstreak@90
|
837 bar = bar
|
flickerstreak@90
|
838 },
|
flickerstreak@90
|
839 proto )
|
flickerstreak@79
|
840
|
flickerstreak@79
|
841 function self:GetName()
|
flickerstreak@79
|
842 return opts.name
|
flickerstreak@79
|
843 end
|
flickerstreak@79
|
844
|
flickerstreak@79
|
845 function self:SetName(name)
|
flickerstreak@79
|
846 opts.name = name
|
flickerstreak@79
|
847 end
|
flickerstreak@79
|
848
|
flickerstreak@79
|
849 function self:GetOrder()
|
flickerstreak@79
|
850 return opts.order
|
flickerstreak@79
|
851 end
|
flickerstreak@79
|
852
|
flickerstreak@79
|
853 -- get reference to states table: even if the bar
|
flickerstreak@79
|
854 -- name changes the states table ref won't
|
flickerstreak@79
|
855 self.states = tbuild(module.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@90
|
856 self.state = tbuild(self.states, opts.name)
|
flickerstreak@79
|
857
|
flickerstreak@90
|
858 opts.order = self:GetRuleField("order")
|
flickerstreak@79
|
859 if opts.order == nil then
|
flickerstreak@79
|
860 -- add after the highest
|
flickerstreak@79
|
861 opts.order = 100
|
flickerstreak@79
|
862 for _, state in pairs(self.states) do
|
flickerstreak@79
|
863 local x = tonumber(tfetch(state, "rule", "order"))
|
flickerstreak@79
|
864 if x and x >= opts.order then
|
flickerstreak@79
|
865 opts.order = x + 1
|
flickerstreak@79
|
866 end
|
flickerstreak@79
|
867 end
|
flickerstreak@90
|
868 self:SetRuleField("order",opts.order)
|
flickerstreak@79
|
869 end
|
flickerstreak@79
|
870
|
flickerstreak@79
|
871 return self
|
flickerstreak@79
|
872 end
|
flickerstreak@79
|
873
|
flickerstreak@79
|
874 -- helper methods
|
flickerstreak@79
|
875
|
flickerstreak@90
|
876 function StateHandler:SetRuleField( key, value, ... )
|
flickerstreak@90
|
877 tbuild(self.state, "rule", ...)[key] = value
|
flickerstreak@79
|
878 end
|
flickerstreak@79
|
879
|
flickerstreak@90
|
880 function StateHandler:GetRuleField( ... )
|
flickerstreak@90
|
881 return tfetch(self.state, "rule", ...)
|
flickerstreak@79
|
882 end
|
flickerstreak@79
|
883
|
flickerstreak@79
|
884 function StateHandler:FixAll( setkey )
|
flickerstreak@79
|
885 -- if multiple selections in the same group are chosen when 'all' is selected,
|
flickerstreak@79
|
886 -- keep only one of them. If changing the mode, the first in the fields list will
|
flickerstreak@79
|
887 -- be chosen arbitrarily. Otherwise, if selecting a new checkbox from the field-set,
|
flickerstreak@79
|
888 -- it will be retained.
|
flickerstreak@79
|
889 local notified = false
|
flickerstreak@90
|
890 if self:GetRuleField("type") == "all" then
|
flickerstreak@79
|
891 for _, c in ipairs(rules) do
|
flickerstreak@79
|
892 local rule, hidden, fields = unpack(c)
|
flickerstreak@79
|
893 local once = false
|
flickerstreak@79
|
894 if setkey then
|
flickerstreak@79
|
895 for idx, field in ipairs(fields) do
|
flickerstreak@79
|
896 if next(field) == setkey then
|
flickerstreak@79
|
897 once = true
|
flickerstreak@79
|
898 end
|
flickerstreak@79
|
899 end
|
flickerstreak@79
|
900 end
|
flickerstreak@79
|
901 for idx, field in ipairs(fields) do
|
flickerstreak@79
|
902 local key = next(field)
|
flickerstreak@90
|
903 if self:GetRuleField("values",key) then
|
flickerstreak@79
|
904 if once and key ~= setkey then
|
flickerstreak@90
|
905 self:SetRuleField(key,false,"values")
|
flickerstreak@79
|
906 if not setkey and not notified then
|
flickerstreak@79
|
907 ReAction:UserError(L["Warning: one or more incompatible rules were turned off"])
|
flickerstreak@79
|
908 notified = true
|
flickerstreak@79
|
909 end
|
flickerstreak@79
|
910 end
|
flickerstreak@79
|
911 once = true
|
flickerstreak@79
|
912 end
|
flickerstreak@79
|
913 end
|
flickerstreak@79
|
914 end
|
flickerstreak@79
|
915 end
|
flickerstreak@79
|
916 end
|
flickerstreak@79
|
917
|
flickerstreak@79
|
918 function StateHandler:GetNeighbors()
|
flickerstreak@79
|
919 local before, after
|
flickerstreak@79
|
920 for k, v in pairs(self.states) do
|
flickerstreak@79
|
921 local o = tonumber(tfetch(v, "rule", "order"))
|
flickerstreak@79
|
922 if o and k ~= self:GetName() then
|
flickerstreak@79
|
923 local obefore = tfetch(self.states,before,"rule","order")
|
flickerstreak@79
|
924 local oafter = tfetch(self.states,after,"rule","order")
|
flickerstreak@79
|
925 if o < self:GetOrder() and (not obefore or obefore < o) then
|
flickerstreak@79
|
926 before = k
|
flickerstreak@79
|
927 end
|
flickerstreak@79
|
928 if o > self:GetOrder() and (not oafter or oafter > o) then
|
flickerstreak@79
|
929 after = k
|
flickerstreak@79
|
930 end
|
flickerstreak@79
|
931 end
|
flickerstreak@79
|
932 end
|
flickerstreak@79
|
933 return before, after
|
flickerstreak@79
|
934 end
|
flickerstreak@79
|
935
|
flickerstreak@79
|
936 function StateHandler:SwapOrder( a, b )
|
flickerstreak@79
|
937 -- do options table
|
flickerstreak@79
|
938 local args = optionMap[self.bar].args
|
flickerstreak@79
|
939 args[a].order, args[b].order = args[b].order, args[a].order
|
flickerstreak@79
|
940 -- do profile
|
flickerstreak@79
|
941 a = tbuild(self.states, a, "rule")
|
flickerstreak@79
|
942 b = tbuild(self.states, b, "rule")
|
flickerstreak@79
|
943 a.order, b.order = b.order, a.order
|
flickerstreak@79
|
944 end
|
flickerstreak@79
|
945
|
flickerstreak@79
|
946 -- handler methods
|
flickerstreak@79
|
947
|
flickerstreak@79
|
948 function StateHandler:GetProp( info )
|
flickerstreak@79
|
949 -- gets property of the same name as the options arg
|
flickerstreak@79
|
950 return GetProperty(self.bar, self:GetName(), info[#info])
|
flickerstreak@79
|
951 end
|
flickerstreak@79
|
952
|
flickerstreak@79
|
953 function StateHandler:SetProp( info, value )
|
flickerstreak@79
|
954 -- sets property of the same name as the options arg
|
flickerstreak@79
|
955 SetProperty(self.bar, self:GetName(), info[#info], value)
|
flickerstreak@79
|
956 end
|
flickerstreak@79
|
957
|
flickerstreak@79
|
958 function StateHandler:DeleteState()
|
flickerstreak@79
|
959 if self.states[self:GetName()] then
|
flickerstreak@79
|
960 self.states[self:GetName()] = nil
|
flickerstreak@79
|
961 ApplyStates(self.bar)
|
flickerstreak@79
|
962 end
|
flickerstreak@79
|
963 optionMap[self.bar].args[self:GetName()] = nil
|
flickerstreak@79
|
964 end
|
flickerstreak@79
|
965
|
flickerstreak@79
|
966 function StateHandler:SetStateName(info, value)
|
flickerstreak@79
|
967 -- check for existing state name
|
flickerstreak@79
|
968 if self.states[value] then
|
flickerstreak@79
|
969 ReAction:UserError(format(L["State named '%s' already exists"],value))
|
flickerstreak@79
|
970 return
|
flickerstreak@79
|
971 end
|
flickerstreak@79
|
972 local args = optionMap[self.bar].args
|
flickerstreak@79
|
973 local name = self:GetName()
|
flickerstreak@79
|
974 self.states[value], args[value], self.states[name], args[name] = self.states[name], args[name], nil, nil
|
flickerstreak@79
|
975 self:SetName(value)
|
flickerstreak@79
|
976 ApplyStates(self.bar)
|
flickerstreak@83
|
977 ReAction:ShowEditor(self.bar, moduleID, value)
|
flickerstreak@83
|
978 end
|
flickerstreak@79
|
979
|
flickerstreak@79
|
980 function StateHandler:MoveStateUp()
|
flickerstreak@79
|
981 local before, after = self:GetNeighbors()
|
flickerstreak@79
|
982 if before then
|
flickerstreak@79
|
983 self:SwapOrder(before, self:GetName())
|
flickerstreak@79
|
984 ApplyStates(self.bar)
|
flickerstreak@79
|
985 end
|
flickerstreak@79
|
986 end
|
flickerstreak@79
|
987
|
flickerstreak@79
|
988 function StateHandler:MoveStateDown()
|
flickerstreak@79
|
989 local before, after = self:GetNeighbors()
|
flickerstreak@79
|
990 if after then
|
flickerstreak@79
|
991 self:SwapOrder(self:GetName(), after)
|
flickerstreak@79
|
992 ApplyStates(self.bar)
|
flickerstreak@79
|
993 end
|
flickerstreak@79
|
994 end
|
flickerstreak@79
|
995
|
flickerstreak@79
|
996 function StateHandler:GetAnchorDisabled()
|
flickerstreak@79
|
997 return not GetProperty(self.bar, self:GetName(), "enableAnchor")
|
flickerstreak@79
|
998 end
|
flickerstreak@79
|
999
|
flickerstreak@79
|
1000 function StateHandler:SetAnchorPointProp(info, value)
|
flickerstreak@79
|
1001 self:SetProp(info, value ~= "NONE" and value or nil)
|
flickerstreak@79
|
1002 end
|
flickerstreak@79
|
1003
|
flickerstreak@79
|
1004 function StateHandler:GetAnchorPointProp(info)
|
flickerstreak@79
|
1005 return self:GetProp(info) or "NONE"
|
flickerstreak@79
|
1006 end
|
flickerstreak@79
|
1007
|
flickerstreak@79
|
1008 function StateHandler:GetScaleDisabled()
|
flickerstreak@79
|
1009 return not GetProperty(self.bar, self:GetName(), "enableScale")
|
flickerstreak@79
|
1010 end
|
flickerstreak@79
|
1011
|
flickerstreak@79
|
1012 function StateHandler:SetType(info, value)
|
flickerstreak@90
|
1013 self:SetRuleField("type", value)
|
flickerstreak@79
|
1014 self:FixAll()
|
flickerstreak@79
|
1015 ApplyStates(self.bar)
|
flickerstreak@79
|
1016 end
|
flickerstreak@79
|
1017
|
flickerstreak@79
|
1018 function StateHandler:GetType()
|
flickerstreak@90
|
1019 return self:GetRuleField("type")
|
flickerstreak@79
|
1020 end
|
flickerstreak@79
|
1021
|
flickerstreak@79
|
1022 function StateHandler:GetClearAllDisabled()
|
flickerstreak@90
|
1023 local t = self:GetRuleField("type")
|
flickerstreak@79
|
1024 return not( t == "any" or t == "all" or t == "custom")
|
flickerstreak@79
|
1025 end
|
flickerstreak@79
|
1026
|
flickerstreak@79
|
1027 function StateHandler:ClearAllConditions()
|
flickerstreak@90
|
1028 local t = self:GetRuleField("type")
|
flickerstreak@79
|
1029 if t == "custom" then
|
flickerstreak@90
|
1030 self:SetRuleField("custom","")
|
flickerstreak@79
|
1031 elseif t == "any" or t == "all" then
|
flickerstreak@90
|
1032 self:SetRuleField("values", {})
|
flickerstreak@79
|
1033 end
|
flickerstreak@79
|
1034 ApplyStates(self.bar)
|
flickerstreak@79
|
1035 end
|
flickerstreak@79
|
1036
|
flickerstreak@79
|
1037 function StateHandler:GetConditionsDisabled()
|
flickerstreak@90
|
1038 local t = self:GetRuleField("type")
|
flickerstreak@79
|
1039 return not( t == "any" or t == "all")
|
flickerstreak@79
|
1040 end
|
flickerstreak@79
|
1041
|
flickerstreak@79
|
1042 function StateHandler:SetCondition(info, key, value)
|
flickerstreak@90
|
1043 self:SetRuleField(ruleMap[key], value or nil, "values")
|
flickerstreak@79
|
1044 if value then
|
flickerstreak@79
|
1045 self:FixAll(ruleMap[key])
|
flickerstreak@79
|
1046 end
|
flickerstreak@79
|
1047 ApplyStates(self.bar)
|
flickerstreak@79
|
1048 end
|
flickerstreak@79
|
1049
|
flickerstreak@79
|
1050 function StateHandler:GetCondition(info, key)
|
flickerstreak@90
|
1051 return self:GetRuleField("values", ruleMap[key]) or false
|
flickerstreak@79
|
1052 end
|
flickerstreak@79
|
1053
|
flickerstreak@79
|
1054 function StateHandler:GetCustomDisabled()
|
flickerstreak@90
|
1055 return self:GetRuleField("type") ~= "custom"
|
flickerstreak@79
|
1056 end
|
flickerstreak@79
|
1057
|
flickerstreak@79
|
1058 function StateHandler:SetCustomRule(info, value)
|
flickerstreak@90
|
1059 self:SetRuleField("custom",value)
|
flickerstreak@79
|
1060 ApplyStates(self.bar)
|
flickerstreak@79
|
1061 end
|
flickerstreak@79
|
1062
|
flickerstreak@79
|
1063 function StateHandler:GetCustomRule()
|
flickerstreak@90
|
1064 return self:GetRuleField("custom") or ""
|
flickerstreak@79
|
1065 end
|
flickerstreak@79
|
1066
|
flickerstreak@79
|
1067 function StateHandler:ValidateCustomRule(info, value)
|
flickerstreak@79
|
1068 local s = value:gsub("%s","") -- remove all spaces
|
flickerstreak@79
|
1069 -- unfortunately %b and captures don't support the '+' notation, or this would be considerably simpler
|
flickerstreak@79
|
1070 repeat
|
flickerstreak@79
|
1071 if s == "" then
|
flickerstreak@79
|
1072 return true
|
flickerstreak@79
|
1073 end
|
flickerstreak@79
|
1074 local c, r = s:match("(%b[])(.*)")
|
flickerstreak@79
|
1075 if c == nil and s and #s > 0 then
|
flickerstreak@79
|
1076 return format(L["Invalid custom rule '%s': each clause must appear within [brackets]"],value or "")
|
flickerstreak@79
|
1077 end
|
flickerstreak@79
|
1078 s = r
|
flickerstreak@79
|
1079 until c == nil
|
flickerstreak@79
|
1080 return true
|
flickerstreak@79
|
1081 end
|
flickerstreak@79
|
1082
|
flickerstreak@79
|
1083 function StateHandler:GetKeybindDisabled()
|
flickerstreak@90
|
1084 return self:GetRuleField("type") ~= "keybind"
|
flickerstreak@79
|
1085 end
|
flickerstreak@79
|
1086
|
flickerstreak@79
|
1087 function StateHandler:GetKeybind()
|
flickerstreak@90
|
1088 return self:GetRuleField("keybind")
|
flickerstreak@79
|
1089 end
|
flickerstreak@79
|
1090
|
flickerstreak@79
|
1091 function StateHandler:SetKeybind(info, value)
|
flickerstreak@79
|
1092 if value and #value == 0 then
|
flickerstreak@79
|
1093 value = nil
|
flickerstreak@79
|
1094 end
|
flickerstreak@90
|
1095 self:SetRuleField("keybind",value)
|
flickerstreak@79
|
1096 ApplyStates(self.bar)
|
flickerstreak@79
|
1097 end
|
flickerstreak@79
|
1098
|
flickerstreak@62
|
1099 local function CreateStateOptions(bar, name)
|
flickerstreak@62
|
1100 local opts = {
|
flickerstreak@62
|
1101 type = "group",
|
flickerstreak@62
|
1102 name = name,
|
flickerstreak@64
|
1103 childGroups = "tab",
|
flickerstreak@79
|
1104 args = stateOptions
|
flickerstreak@25
|
1105 }
|
flickerstreak@62
|
1106
|
flickerstreak@79
|
1107 opts.handler = StateHandler:New(bar,opts)
|
flickerstreak@64
|
1108
|
flickerstreak@62
|
1109 return opts
|
flickerstreak@25
|
1110 end
|
flickerstreak@62
|
1111
|
flickerstreak@79
|
1112 function module:GetBarOptions(bar)
|
flickerstreak@62
|
1113 local private = { }
|
flickerstreak@75
|
1114 local states = tbuild(module.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@62
|
1115 local options = {
|
flickerstreak@77
|
1116 name = L["Dynamic State"],
|
flickerstreak@62
|
1117 type = "group",
|
flickerstreak@77
|
1118 order = -1,
|
flickerstreak@64
|
1119 childGroups = "tree",
|
flickerstreak@62
|
1120 disabled = InCombatLockdown,
|
flickerstreak@62
|
1121 args = {
|
flickerstreak@64
|
1122 __desc__ = {
|
flickerstreak@68
|
1123 name = L["States are evaluated in the order they are listed"],
|
flickerstreak@68
|
1124 order = 1,
|
flickerstreak@64
|
1125 type = "description",
|
flickerstreak@64
|
1126 },
|
flickerstreak@64
|
1127 __new__ = {
|
flickerstreak@64
|
1128 name = L["New State..."],
|
flickerstreak@64
|
1129 order = 2,
|
flickerstreak@68
|
1130 type = "group",
|
flickerstreak@62
|
1131 args = {
|
flickerstreak@64
|
1132 name = {
|
flickerstreak@64
|
1133 name = L["State Name"],
|
flickerstreak@64
|
1134 desc = L["Set a name for the new state"],
|
flickerstreak@68
|
1135 order = 1,
|
flickerstreak@68
|
1136 type = "input",
|
flickerstreak@64
|
1137 get = function() return private.newstatename or "" end,
|
flickerstreak@64
|
1138 set = function(info,value) private.newstatename = value end,
|
flickerstreak@64
|
1139 pattern = "^%w*$",
|
flickerstreak@64
|
1140 usage = L["State names must be alphanumeric without spaces"],
|
flickerstreak@64
|
1141 },
|
flickerstreak@64
|
1142 create = {
|
flickerstreak@68
|
1143 name = L["Create State"],
|
flickerstreak@68
|
1144 order = 2,
|
flickerstreak@64
|
1145 type = "execute",
|
flickerstreak@64
|
1146 func = function ()
|
flickerstreak@64
|
1147 local name = private.newstatename
|
flickerstreak@68
|
1148 if states[name] then
|
flickerstreak@75
|
1149 ReAction:UserError(format(L["State named '%s' already exists"],name))
|
flickerstreak@68
|
1150 else
|
flickerstreak@68
|
1151 -- TODO: select default state options and pass as final argument
|
flickerstreak@68
|
1152 states[name] = { }
|
flickerstreak@68
|
1153 optionMap[bar].args[name] = CreateStateOptions(bar,name)
|
flickerstreak@81
|
1154 ReAction:ShowEditor(bar, moduleID, name)
|
flickerstreak@68
|
1155 private.newstatename = ""
|
flickerstreak@68
|
1156 end
|
flickerstreak@64
|
1157 end,
|
flickerstreak@64
|
1158 disabled = function()
|
flickerstreak@64
|
1159 local name = private.newstatename or ""
|
flickerstreak@64
|
1160 return #name == 0 or name:find("%W")
|
flickerstreak@64
|
1161 end,
|
flickerstreak@62
|
1162 }
|
flickerstreak@62
|
1163 }
|
flickerstreak@64
|
1164 }
|
flickerstreak@62
|
1165 }
|
flickerstreak@62
|
1166 }
|
flickerstreak@79
|
1167 for name, config in pairs(states) do
|
flickerstreak@79
|
1168 options.args[name] = CreateStateOptions(bar,name)
|
flickerstreak@62
|
1169 end
|
flickerstreak@64
|
1170 optionMap[bar] = options
|
flickerstreak@62
|
1171 return options
|
flickerstreak@62
|
1172 end
|
flickerstreak@25
|
1173 end
|
flickerstreak@25
|
1174
|
flickerstreak@79
|
1175 -- Module API --
|
flickerstreak@79
|
1176
|
flickerstreak@90
|
1177 -- Pass in a property field-name, an implementation secure snippet, a static options table, and an
|
flickerstreak@79
|
1178 -- optional options handler method-table
|
flickerstreak@79
|
1179 --
|
flickerstreak@79
|
1180 -- The options table is static, i.e. not bar-specific and should only reference handler method
|
flickerstreak@79
|
1181 -- strings (either existing ones or those added via optHandler). The existing options are ordered
|
flickerstreak@81
|
1182 -- 90-99. Order #1 is reserved for the heading.
|
flickerstreak@79
|
1183 --
|
flickerstreak@90
|
1184 -- The contents of optHandler, if provided, will be added to the existing StateHandler options metatable.
|
flickerstreak@79
|
1185 -- See above, for existing API. In particular see the properties set up in the New method: self.bar,
|
flickerstreak@79
|
1186 -- self.states, and self:GetName(), and the generic property handlers self:GetProp() and self:SetProp().
|
flickerstreak@79
|
1187 --
|
flickerstreak@90
|
1188 function module:RegisterStateProperty( field, snippetHandler, options, optHandler )
|
flickerstreak@90
|
1189 RegisterProperty(field, snippetHandler)
|
flickerstreak@79
|
1190 RegisterPropertyOptions(field, options, optHandler)
|
flickerstreak@25
|
1191 end
|
flickerstreak@79
|
1192
|
flickerstreak@90
|
1193 function module:UnregisterStateProperty( field )
|
flickerstreak@90
|
1194 UnregisterProperty(field)
|
flickerstreak@90
|
1195 UnregisterPropertyOptions(field)
|
flickerstreak@90
|
1196 end
|