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@25
|
10 local InCombatLockdown = InCombatLockdown
|
flickerstreak@25
|
11
|
flickerstreak@25
|
12 -- module declaration
|
flickerstreak@25
|
13 local moduleID = "State"
|
flickerstreak@65
|
14 local module = ReAction:NewModule( moduleID, "AceEvent-3.0" )
|
flickerstreak@62
|
15
|
flickerstreak@64
|
16 -- Utility --
|
flickerstreak@62
|
17
|
flickerstreak@62
|
18 -- traverse a table tree by key list and fetch the result or first nil
|
flickerstreak@62
|
19 local function tfetch(t, ...)
|
flickerstreak@62
|
20 for i = 1, select('#', ...) do
|
flickerstreak@62
|
21 t = t and t[select(i, ...)]
|
flickerstreak@62
|
22 end
|
flickerstreak@62
|
23 return t
|
flickerstreak@62
|
24 end
|
flickerstreak@62
|
25
|
flickerstreak@62
|
26 -- traverse a table tree by key list and build tree as necessary
|
flickerstreak@62
|
27 local function tbuild(t, ...)
|
flickerstreak@62
|
28 for i = 1, select('#', ...) do
|
flickerstreak@62
|
29 local key = select(i, ...)
|
flickerstreak@62
|
30 if not t[key] then t[key] = { } end
|
flickerstreak@62
|
31 t = t[key]
|
flickerstreak@62
|
32 end
|
flickerstreak@62
|
33 return t
|
flickerstreak@62
|
34 end
|
flickerstreak@62
|
35
|
flickerstreak@64
|
36 -- PRIVATE --
|
flickerstreak@65
|
37 local InitRules, ApplyStates
|
flickerstreak@64
|
38 do
|
flickerstreak@67
|
39 -- As far as I can tell the macro clauses are NOT locale-specific.
|
flickerstreak@67
|
40 local ruleformats = {
|
flickerstreak@67
|
41 stealth = "stealth",
|
flickerstreak@67
|
42 nostealth = "nostealth",
|
flickerstreak@67
|
43 shadowform = "form:1",
|
flickerstreak@67
|
44 noshadowform = "noform",
|
flickerstreak@67
|
45 pet = "pet",
|
flickerstreak@67
|
46 nopet = "nopet",
|
flickerstreak@67
|
47 harm = "target=target,harm",
|
flickerstreak@67
|
48 help = "target=target,help",
|
flickerstreak@67
|
49 notarget = "target=target,noexists",
|
flickerstreak@67
|
50 focusharm = "target=focus,harm",
|
flickerstreak@67
|
51 focushelp = "target=focus,help",
|
flickerstreak@67
|
52 nofocus = "target=focus,noexists",
|
flickerstreak@67
|
53 raid = "group:raid",
|
flickerstreak@67
|
54 party = "group:party",
|
flickerstreak@67
|
55 solo = "nogroup",
|
flickerstreak@67
|
56 combat = "combat",
|
flickerstreak@67
|
57 nocombat = "nocombat",
|
flickerstreak@67
|
58 }
|
flickerstreak@65
|
59
|
flickerstreak@67
|
60 -- Have to do these shenanigans instead of hardcoding the stances/forms because
|
flickerstreak@67
|
61 -- the ordering varies if the character is missing a form. For warriors
|
flickerstreak@67
|
62 -- this is rarely a problem (c'mon, who actually skips the level 10 def stance quest?)
|
flickerstreak@67
|
63 -- but for druids it can be. Some people never bother to do the aquatic form quest
|
flickerstreak@67
|
64 -- until well past when they get cat form, and stance 5 can be flight, tree, or moonkin
|
flickerstreak@67
|
65 -- depending on talents.
|
flickerstreak@65
|
66 function InitRules()
|
flickerstreak@65
|
67 local forms = { }
|
flickerstreak@67
|
68 -- sort by icon since it's locale-independent
|
flickerstreak@65
|
69 for i = 1, GetNumShapeshiftForms() do
|
flickerstreak@65
|
70 local icon = GetShapeshiftFormInfo(i)
|
flickerstreak@65
|
71 forms[icon] = i;
|
flickerstreak@65
|
72 end
|
flickerstreak@65
|
73 -- use 9 if not found since 9 is never a valid stance/form
|
flickerstreak@65
|
74 local defensive = forms["Interface\\Icons\\Ability_Warrior_DefensiveStance"] or 9
|
flickerstreak@65
|
75 local berserker = forms["Interface\\Icons\\Ability_Racial_Avatar"] or 9
|
flickerstreak@65
|
76 local bear = forms["Interface\\Icons\\Ability_Racial_BearForm"] or 9 -- bear and dire bear share the same icon
|
flickerstreak@65
|
77 local aquatic = forms["Interface\\Icons\\Ability_Druid_AquaticForm"] or 9
|
flickerstreak@65
|
78 local cat = forms["Interface\\Icons\\Ability_Druid_CatForm"] or 9
|
flickerstreak@65
|
79 local travel = forms["Interface\\Icons\\Ability_Druid_TravelForm"] or 9
|
flickerstreak@65
|
80 local treekin = forms["Interface\\Icons\\Ability_Druid_TreeofLife"] or forms["Interface\\Icons\\Spell_Nature_ForceOfNature"] or 9
|
flickerstreak@67
|
81 local flight = forms["Interface\\Icons\\Ability_Druid_FlightForm"] or 9 -- flight and swift flight share the same icon
|
flickerstreak@65
|
82
|
flickerstreak@65
|
83 ruleformats.battle = "stance:1"
|
flickerstreak@65
|
84 ruleformats.defensive = ("stance:%d"):format(defensive)
|
flickerstreak@65
|
85 ruleformats.berserker = ("stance:%d"):format(berserker)
|
flickerstreak@65
|
86 ruleformats.caster = ("form:0/%d/%d/%d"):format(aquatic, travel, flight)
|
flickerstreak@65
|
87 ruleformats.bear = ("form:%d"):format(bear)
|
flickerstreak@65
|
88 ruleformats.cat = ("form:%d"):format(cat)
|
flickerstreak@65
|
89 ruleformats.treeOrMoonkin = ("form:%d"):format(treekin)
|
flickerstreak@64
|
90 end
|
flickerstreak@62
|
91
|
flickerstreak@65
|
92 local function BuildRuleString(states)
|
flickerstreak@64
|
93 local s = ""
|
flickerstreak@64
|
94 local default
|
flickerstreak@64
|
95 local sorted = { }
|
flickerstreak@64
|
96 for name in pairs(states) do
|
flickerstreak@64
|
97 table.insert(sorted,name)
|
flickerstreak@64
|
98 end
|
flickerstreak@64
|
99 table.sort(sorted, function(lhs, rhs)
|
flickerstreak@64
|
100 local olhs = tfetch(states[lhs],"rule","order") or 0
|
flickerstreak@64
|
101 local orhs = tfetch(states[rhs],"rule","order") or 0
|
flickerstreak@64
|
102 return olhs < orhs
|
flickerstreak@64
|
103 end)
|
flickerstreak@64
|
104 for idx, name in ipairs(sorted) do
|
flickerstreak@64
|
105 local state = states[name]
|
flickerstreak@64
|
106 local semi = #s > 0 and "; " or ""
|
flickerstreak@64
|
107 local mode = tfetch(state,"rule","type")
|
flickerstreak@64
|
108 if mode == "default" then
|
flickerstreak@64
|
109 default = name
|
flickerstreak@64
|
110 elseif mode == "custom" then
|
flickerstreak@64
|
111 if state.rule.custom then
|
flickerstreak@64
|
112 -- strip out all spaces from the custom rule
|
flickerstreak@64
|
113 s = ("%s%s%s %s"):format(s, semi, state.rule.custom:gsub("%s",""), name)
|
flickerstreak@64
|
114 end
|
flickerstreak@64
|
115 elseif mode == "any" then
|
flickerstreak@64
|
116 if state.rule.values then
|
flickerstreak@64
|
117 local clause = ""
|
flickerstreak@64
|
118 for key, value in pairs(state.rule.values) do
|
flickerstreak@64
|
119 clause = ("%s[%s]"):format(clause,ruleformats[key])
|
flickerstreak@64
|
120 end
|
flickerstreak@64
|
121 if #clause > 0 then
|
flickerstreak@64
|
122 s = ("%s%s%s %s"):format(s, semi, clause, name)
|
flickerstreak@64
|
123 end
|
flickerstreak@64
|
124 end
|
flickerstreak@64
|
125 elseif mode == "all" then
|
flickerstreak@64
|
126 if state.rule.values then
|
flickerstreak@64
|
127 local clause = ""
|
flickerstreak@64
|
128 for key, value in pairs(state.rule.values) do
|
flickerstreak@64
|
129 clause = ("%s%s%s"):format(clause,#clause > 0 and "," or "", ruleformats[key])
|
flickerstreak@64
|
130 end
|
flickerstreak@64
|
131 if #clause > 0 then
|
flickerstreak@64
|
132 s = ("%s%s[%s] %s"):format(s, semi, clause, name)
|
flickerstreak@64
|
133 end
|
flickerstreak@64
|
134 end
|
flickerstreak@64
|
135 end
|
flickerstreak@64
|
136 end
|
flickerstreak@64
|
137 if default then
|
flickerstreak@64
|
138 s = ("%s%s%s"):format(s, #s > 0 and "; " or "", default)
|
flickerstreak@64
|
139 end
|
flickerstreak@64
|
140 return s
|
flickerstreak@64
|
141 end
|
flickerstreak@64
|
142
|
flickerstreak@64
|
143 local drivers = setmetatable({},{__mode="k"})
|
flickerstreak@64
|
144
|
flickerstreak@64
|
145 function ApplyStates( bar )
|
flickerstreak@64
|
146 local states = tfetch(module.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@64
|
147 if states then
|
flickerstreak@64
|
148 local frame = bar:GetFrame()
|
flickerstreak@64
|
149 local string = BuildRuleString(states)
|
flickerstreak@64
|
150 ReAction:Print("'"..string.."'")
|
flickerstreak@64
|
151 if string and #string > 0 then
|
flickerstreak@64
|
152 -- register a handler to set the value of attribute "state-reaction"
|
flickerstreak@64
|
153 -- in response to events as per the rule string
|
flickerstreak@64
|
154 RegisterStateDriver(frame, "reaction", string)
|
flickerstreak@64
|
155 drivers[bar] = true
|
flickerstreak@64
|
156 -- register a trivial map for each "statemap-reaction-XXX" to set 'state' to 'XXX'
|
flickerstreak@64
|
157 for state in pairs(states) do
|
flickerstreak@64
|
158 frame:SetAttribute(("statemap-reaction-%s"):format(state), state)
|
flickerstreak@64
|
159 end
|
flickerstreak@64
|
160 elseif drivers[bar] then
|
flickerstreak@64
|
161 UnregisterStateDriver(frame, "reaction")
|
flickerstreak@64
|
162 drivers[bar] = nil
|
flickerstreak@64
|
163 end
|
flickerstreak@64
|
164 end
|
flickerstreak@64
|
165 end
|
flickerstreak@64
|
166 end
|
flickerstreak@64
|
167
|
flickerstreak@64
|
168
|
flickerstreak@65
|
169 -- module event handlers
|
flickerstreak@65
|
170 function module:OnInitialize()
|
flickerstreak@65
|
171 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@65
|
172 {
|
flickerstreak@65
|
173 profile = {
|
flickerstreak@65
|
174 bars = { },
|
flickerstreak@65
|
175 }
|
flickerstreak@65
|
176 }
|
flickerstreak@65
|
177 )
|
flickerstreak@65
|
178
|
flickerstreak@65
|
179 InitRules()
|
flickerstreak@65
|
180 self:RegisterEvent("PLAYER_AURAS_CHANGED")
|
flickerstreak@65
|
181
|
flickerstreak@65
|
182 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@65
|
183
|
flickerstreak@65
|
184 ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar")
|
flickerstreak@65
|
185 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@65
|
186 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@65
|
187 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@65
|
188 ReAction.RegisterCallback(self, "OnConfigModeChanged")
|
flickerstreak@65
|
189 end
|
flickerstreak@65
|
190
|
flickerstreak@65
|
191 function module:PLAYER_AURAS_CHANGED()
|
flickerstreak@65
|
192 self:UnregisterEvent("PLAYER_AURAS_CHANGED")
|
flickerstreak@66
|
193 -- on login the number of stances is 0 until this event fires during the init sequence.
|
flickerstreak@66
|
194 -- however if you reload just the UI the number of stances is correct immediately
|
flickerstreak@66
|
195 -- and this event won't fire until you gain/lose buffs/debuffs, at which point you might
|
flickerstreak@66
|
196 -- be in combat.
|
flickerstreak@66
|
197 if not InCombatLockdown() then
|
flickerstreak@66
|
198 InitRules()
|
flickerstreak@66
|
199 for name, bar in ReAction:IterateBars() do
|
flickerstreak@67
|
200 self:OnRefreshBar(nil,bar,name)
|
flickerstreak@66
|
201 end
|
flickerstreak@66
|
202 end
|
flickerstreak@65
|
203 end
|
flickerstreak@65
|
204
|
flickerstreak@65
|
205 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@65
|
206 local c = self.db.profile.bars[name]
|
flickerstreak@65
|
207 if c then
|
flickerstreak@65
|
208 self:UpdateStates(bar)
|
flickerstreak@65
|
209 end
|
flickerstreak@65
|
210 end
|
flickerstreak@65
|
211
|
flickerstreak@65
|
212 function module:OnEraseBar(event, bar, name)
|
flickerstreak@65
|
213 self.db.profile.bars[name] = nil
|
flickerstreak@65
|
214 end
|
flickerstreak@65
|
215
|
flickerstreak@65
|
216 function module:OnRenameBar(event, bar, oldname, newname)
|
flickerstreak@65
|
217 local b = self.db.profile.bars
|
flickerstreak@65
|
218 bars[newname], bars[oldname] = bars[oldname], nil
|
flickerstreak@65
|
219 end
|
flickerstreak@65
|
220
|
flickerstreak@65
|
221 function module:OnConfigModeChanged(event, mode)
|
flickerstreak@65
|
222 -- TODO: unregister all state drivers (temporarily) and hidestates
|
flickerstreak@65
|
223 end
|
flickerstreak@65
|
224
|
flickerstreak@64
|
225
|
flickerstreak@64
|
226 -- API --
|
flickerstreak@64
|
227
|
flickerstreak@64
|
228 function module:UpdateStates( bar )
|
flickerstreak@64
|
229 ApplyStates(bar)
|
flickerstreak@64
|
230 end
|
flickerstreak@64
|
231
|
flickerstreak@64
|
232 function module:CreateState( bar, name )
|
flickerstreak@64
|
233 local states = tbuild(self.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@64
|
234 if states[name] then
|
flickerstreak@64
|
235 ReAction:UserError(L["State named '%s' already exists"]:format(name))
|
flickerstreak@64
|
236 else
|
flickerstreak@64
|
237 states[name] = { }
|
flickerstreak@64
|
238 end
|
flickerstreak@64
|
239 end
|
flickerstreak@64
|
240
|
flickerstreak@64
|
241 function module:DeleteState( bar, name )
|
flickerstreak@64
|
242 local states = tfetch(self.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@64
|
243 if states[name] then
|
flickerstreak@64
|
244 states[name] = nil
|
flickerstreak@67
|
245 self:UpdateStates(bar)
|
flickerstreak@64
|
246 end
|
flickerstreak@64
|
247 end
|
flickerstreak@64
|
248
|
flickerstreak@64
|
249 -- Options --
|
flickerstreak@64
|
250
|
flickerstreak@64
|
251 local CreateBarOptions
|
flickerstreak@62
|
252 do
|
flickerstreak@62
|
253 local function ClassCheck(...)
|
flickerstreak@62
|
254 for i = 1, select('#',...) do
|
flickerstreak@62
|
255 local _, c = UnitClass("player")
|
flickerstreak@62
|
256 if c == select(i,...) then
|
flickerstreak@62
|
257 return false
|
flickerstreak@62
|
258 end
|
flickerstreak@62
|
259 end
|
flickerstreak@62
|
260 return true
|
flickerstreak@62
|
261 end
|
flickerstreak@62
|
262
|
flickerstreak@64
|
263 -- pre-sorted by the order they should appear in
|
flickerstreak@64
|
264 local rules = {
|
flickerstreak@64
|
265 -- rule hidden fields
|
flickerstreak@64
|
266 { "stance", ClassCheck("WARRIOR"), { {battle = L["Battle Stance"]}, {defensive = L["Defensive Stance"]}, {berserker = L["Berserker Stance"]} } },
|
flickerstreak@64
|
267 { "form", ClassCheck("DRUID"), { {caster = L["Caster Form"]}, {bear = L["Bear Form"]}, {cat = L["Cat Form"]}, {treeOrMoonkin = L["Tree/Moonkin"]} } },
|
flickerstreak@64
|
268 { "stealth", ClassCheck("ROGUE","DRUID"), { {stealth = L["Stealth"]}, {nostealth = L["No Stealth"]} } },
|
flickerstreak@64
|
269 { "shadow", ClassCheck("PRIEST"), { {shadowform = L["Shadowform"]}, {noshadowform = L["No Shadowform"]} } },
|
flickerstreak@64
|
270 { "pet", ClassCheck("HUNTER","WARLOCK"), { {pet = L["With Pet"]}, {nopet = L["Without Pet"]} } },
|
flickerstreak@64
|
271 { "target", false, { {harm = L["Hostile Target"]}, {help = L["Friendly Target"]}, {notarget = L["No Target"]} } },
|
flickerstreak@64
|
272 { "focus", false, { {focusharm = L["Hostile Focus"]}, {focushelp = L["Friendly Focus"]}, {nofocus = L["No Focus"]} } },
|
flickerstreak@64
|
273 { "group", false, { {raid = L["Raid"]}, {party = L["Party"]}, {solo = L["Solo"]} } },
|
flickerstreak@64
|
274 { "combat", false, { {combat = L["In Combat"]}, {nocombat = L["Out of Combat"]} } },
|
flickerstreak@62
|
275 }
|
flickerstreak@62
|
276
|
flickerstreak@64
|
277 local ruleSelect = { }
|
flickerstreak@64
|
278 local ruleMap = { }
|
flickerstreak@64
|
279 local optionMap = setmetatable({},{__mode="k"})
|
flickerstreak@62
|
280
|
flickerstreak@64
|
281 -- unpack rules table into ruleSelect and ruleMap
|
flickerstreak@64
|
282 for _, c in ipairs(rules) do
|
flickerstreak@64
|
283 local rule, hidden, fields = unpack(c)
|
flickerstreak@64
|
284 if not hidden then
|
flickerstreak@64
|
285 for _, field in ipairs(fields) do
|
flickerstreak@64
|
286 local key, label = next(field)
|
flickerstreak@64
|
287 table.insert(ruleSelect, label)
|
flickerstreak@64
|
288 table.insert(ruleMap, key)
|
flickerstreak@62
|
289 end
|
flickerstreak@62
|
290 end
|
flickerstreak@62
|
291 end
|
flickerstreak@62
|
292
|
flickerstreak@62
|
293 local function CreateStateOptions(bar, name)
|
flickerstreak@62
|
294 local opts = {
|
flickerstreak@62
|
295 type = "group",
|
flickerstreak@62
|
296 name = name,
|
flickerstreak@64
|
297 childGroups = "tab",
|
flickerstreak@25
|
298 }
|
flickerstreak@62
|
299
|
flickerstreak@64
|
300 local states = tbuild(module.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@64
|
301
|
flickerstreak@64
|
302 local function put( key, value, ... )
|
flickerstreak@64
|
303 tbuild(states, opts.name, "rule", ...)[key] = value
|
flickerstreak@64
|
304 end
|
flickerstreak@64
|
305
|
flickerstreak@64
|
306 local function fetch( ... )
|
flickerstreak@64
|
307 return tfetch(states, opts.name, "rule", ...)
|
flickerstreak@64
|
308 end
|
flickerstreak@64
|
309
|
flickerstreak@64
|
310 local function fixall(setkey)
|
flickerstreak@64
|
311 -- if multiple selections in the same group are chosen when 'all' is selected,
|
flickerstreak@64
|
312 -- keep only one of them. If changing the mode, the first in the fields list will
|
flickerstreak@64
|
313 -- be chosen arbitrarily. Otherwise, if selecting a new checkbox from the field-set,
|
flickerstreak@64
|
314 -- it will be retained.
|
flickerstreak@64
|
315 local notified = false
|
flickerstreak@64
|
316 for _, c in ipairs(rules) do
|
flickerstreak@64
|
317 local rule, hidden, fields = unpack(c)
|
flickerstreak@64
|
318 local found = false
|
flickerstreak@64
|
319 for key in ipairs(fields) do
|
flickerstreak@64
|
320 if fetch("values",key) then
|
flickerstreak@64
|
321 if (found or setkey) and key ~= setkey then
|
flickerstreak@64
|
322 put(key,false,"values")
|
flickerstreak@64
|
323 if not setkey and not notified then
|
flickerstreak@64
|
324 ReAction:UserError(L["Warning: one or more incompatible rules were turned off"])
|
flickerstreak@64
|
325 notified = true
|
flickerstreak@64
|
326 end
|
flickerstreak@64
|
327 end
|
flickerstreak@64
|
328 found = true
|
flickerstreak@64
|
329 end
|
flickerstreak@62
|
330 end
|
flickerstreak@62
|
331 end
|
flickerstreak@62
|
332 end
|
flickerstreak@62
|
333
|
flickerstreak@64
|
334 local function getNeighbors()
|
flickerstreak@64
|
335 local before, after
|
flickerstreak@64
|
336 for k, v in pairs(states) do
|
flickerstreak@64
|
337 local o = tonumber(tfetch(v, "rule", "order"))
|
flickerstreak@64
|
338 if o and k ~= opts.name then
|
flickerstreak@64
|
339 local obefore = tfetch(states,before,"rule","order")
|
flickerstreak@64
|
340 local oafter = tfetch(states,after,"rule","order")
|
flickerstreak@64
|
341 if o < opts.order and (not obefore or obefore < o) then
|
flickerstreak@64
|
342 before = k
|
flickerstreak@64
|
343 end
|
flickerstreak@64
|
344 if o > opts.order and (not oafter or oafter > o) then
|
flickerstreak@64
|
345 after = k
|
flickerstreak@64
|
346 end
|
flickerstreak@64
|
347 end
|
flickerstreak@64
|
348 end
|
flickerstreak@64
|
349 return before, after
|
flickerstreak@64
|
350 end
|
flickerstreak@64
|
351
|
flickerstreak@64
|
352 local function swapOrder( a, b )
|
flickerstreak@64
|
353 -- do options table
|
flickerstreak@64
|
354 local args = optionMap[bar].args
|
flickerstreak@64
|
355 args[a].order, args[b].order = args[b].order, args[a].order
|
flickerstreak@64
|
356 -- do profile
|
flickerstreak@64
|
357 a = tbuild(states, a, "rule")
|
flickerstreak@64
|
358 b = tbuild(states, b, "rule")
|
flickerstreak@64
|
359 a.order, b.order = b.order, a.order
|
flickerstreak@64
|
360 end
|
flickerstreak@64
|
361
|
flickerstreak@64
|
362 local function update()
|
flickerstreak@64
|
363 module:UpdateStates(bar)
|
flickerstreak@64
|
364 end
|
flickerstreak@64
|
365
|
flickerstreak@64
|
366
|
flickerstreak@64
|
367 opts.order = fetch("order")
|
flickerstreak@64
|
368 if opts.order == nil then
|
flickerstreak@64
|
369 -- add after the highest
|
flickerstreak@64
|
370 opts.order = 100
|
flickerstreak@64
|
371 for _, state in pairs(states) do
|
flickerstreak@64
|
372 local x = tonumber(tfetch(state, "rule", "order"))
|
flickerstreak@64
|
373 if x and x >= opts.order then
|
flickerstreak@64
|
374 opts.order = x + 1
|
flickerstreak@64
|
375 end
|
flickerstreak@64
|
376 end
|
flickerstreak@64
|
377 put("order",opts.order)
|
flickerstreak@64
|
378 end
|
flickerstreak@64
|
379
|
flickerstreak@64
|
380 opts.args = {
|
flickerstreak@64
|
381 properties = {
|
flickerstreak@64
|
382 type = "group",
|
flickerstreak@64
|
383 name = L["Properties"],
|
flickerstreak@64
|
384 order = 1,
|
flickerstreak@64
|
385 args = {
|
flickerstreak@64
|
386 delete = {
|
flickerstreak@64
|
387 type = "execute",
|
flickerstreak@64
|
388 name = L["Delete this State"],
|
flickerstreak@64
|
389 func = function(info)
|
flickerstreak@64
|
390 module:DeleteState(bar,opts.name)
|
flickerstreak@64
|
391 optionMap[bar].args[opts.name] = nil
|
flickerstreak@64
|
392 end,
|
flickerstreak@64
|
393 order = -1
|
flickerstreak@64
|
394 },
|
flickerstreak@64
|
395 rename = {
|
flickerstreak@64
|
396 type = "input",
|
flickerstreak@64
|
397 name = L["Name"],
|
flickerstreak@64
|
398 order = 1,
|
flickerstreak@64
|
399 get = function() return opts.name end,
|
flickerstreak@64
|
400 set = function(info, value)
|
flickerstreak@64
|
401 -- check for existing state name
|
flickerstreak@64
|
402 if states[value] then
|
flickerstreak@64
|
403 L["State named '%s' already exists"]:format(value)
|
flickerstreak@64
|
404 end
|
flickerstreak@64
|
405 local args = optionMap[bar].args
|
flickerstreak@64
|
406 states[value], args[value], states[opts.name], args[opts.name] = states[opts.name], args[opts.name], nil, nil
|
flickerstreak@64
|
407 opts.name = value
|
flickerstreak@64
|
408 update()
|
flickerstreak@64
|
409 end,
|
flickerstreak@64
|
410 pattern = "^%w*$",
|
flickerstreak@64
|
411 usage = L["State names must be alphanumeric without spaces"],
|
flickerstreak@64
|
412 },
|
flickerstreak@64
|
413 ordering = {
|
flickerstreak@64
|
414 type = "group",
|
flickerstreak@64
|
415 inline = true,
|
flickerstreak@64
|
416 name = L["Evaluation Order"],
|
flickerstreak@64
|
417 desc = L["State transitions are evaluated in the order listed:\nMove a state up or down to change the order"],
|
flickerstreak@64
|
418 order = 2,
|
flickerstreak@64
|
419 args = {
|
flickerstreak@64
|
420 up = {
|
flickerstreak@64
|
421 type = "execute",
|
flickerstreak@64
|
422 name = L["Up"],
|
flickerstreak@64
|
423 width = "half",
|
flickerstreak@64
|
424 order = 1,
|
flickerstreak@64
|
425 func = function()
|
flickerstreak@64
|
426 local before, after = getNeighbors()
|
flickerstreak@64
|
427 if before then
|
flickerstreak@64
|
428 swapOrder(before, opts.name)
|
flickerstreak@64
|
429 update()
|
flickerstreak@64
|
430 end
|
flickerstreak@64
|
431 end,
|
flickerstreak@64
|
432 },
|
flickerstreak@64
|
433 down = {
|
flickerstreak@64
|
434 type = "execute",
|
flickerstreak@64
|
435 name = L["Down"],
|
flickerstreak@64
|
436 width = "half",
|
flickerstreak@64
|
437 order = 2,
|
flickerstreak@64
|
438 func = function()
|
flickerstreak@64
|
439 local before, after = getNeighbors()
|
flickerstreak@64
|
440 if after then
|
flickerstreak@64
|
441 ReAction:Print(opts.name, after)
|
flickerstreak@64
|
442 swapOrder(opts.name, after)
|
flickerstreak@64
|
443 update()
|
flickerstreak@64
|
444 end
|
flickerstreak@64
|
445 end,
|
flickerstreak@64
|
446 }
|
flickerstreak@64
|
447 }
|
flickerstreak@64
|
448 },
|
flickerstreak@64
|
449 -- keybinding for show-this-state would go here
|
flickerstreak@64
|
450 -- show/hide would go here
|
flickerstreak@64
|
451 -- page # would go here
|
flickerstreak@64
|
452 -- anchoring would go here
|
flickerstreak@64
|
453 }
|
flickerstreak@64
|
454 },
|
flickerstreak@64
|
455 rules = {
|
flickerstreak@64
|
456 type = "group",
|
flickerstreak@64
|
457 name = L["Rules"],
|
flickerstreak@64
|
458 order = 2,
|
flickerstreak@64
|
459 args = {
|
flickerstreak@64
|
460 mode = {
|
flickerstreak@64
|
461 type = "select",
|
flickerstreak@64
|
462 style = "radio",
|
flickerstreak@64
|
463 name = L["Select this state"],
|
flickerstreak@64
|
464 values = {
|
flickerstreak@64
|
465 default = L["by default"],
|
flickerstreak@64
|
466 any = L["when ANY of these"],
|
flickerstreak@64
|
467 all = L["when ALL of these"],
|
flickerstreak@64
|
468 custom = L["via custom rule"]
|
flickerstreak@64
|
469 },
|
flickerstreak@64
|
470 set = function( info, value )
|
flickerstreak@64
|
471 put("type", value)
|
flickerstreak@64
|
472 fixall()
|
flickerstreak@64
|
473 update()
|
flickerstreak@64
|
474 end,
|
flickerstreak@64
|
475 get = function( info )
|
flickerstreak@64
|
476 return fetch("type")
|
flickerstreak@64
|
477 end,
|
flickerstreak@64
|
478 order = 2
|
flickerstreak@64
|
479 },
|
flickerstreak@64
|
480 clear = {
|
flickerstreak@64
|
481 type = "execute",
|
flickerstreak@64
|
482 name = L["Clear All"],
|
flickerstreak@64
|
483 func = function()
|
flickerstreak@64
|
484 local type = fetch("type")
|
flickerstreak@64
|
485 if type == "custom" then
|
flickerstreak@64
|
486 put("custom","")
|
flickerstreak@64
|
487 elseif type == "any" or type == "all" then
|
flickerstreak@64
|
488 put("values", {})
|
flickerstreak@64
|
489 end
|
flickerstreak@64
|
490 update()
|
flickerstreak@64
|
491 end,
|
flickerstreak@64
|
492 order = 3
|
flickerstreak@64
|
493 },
|
flickerstreak@64
|
494 inputs = {
|
flickerstreak@64
|
495 type = "multiselect",
|
flickerstreak@64
|
496 name = L["Rules"],
|
flickerstreak@64
|
497 hidden = function()
|
flickerstreak@64
|
498 return fetch("type") == "custom"
|
flickerstreak@64
|
499 end,
|
flickerstreak@64
|
500 disabled = function()
|
flickerstreak@64
|
501 return fetch("type") == "default"
|
flickerstreak@64
|
502 end,
|
flickerstreak@64
|
503 values = ruleSelect,
|
flickerstreak@64
|
504 set = function(info, key, value )
|
flickerstreak@64
|
505 put(ruleMap[key], value or nil, "values")
|
flickerstreak@64
|
506 if value then
|
flickerstreak@64
|
507 fixall(ruleMap[key])
|
flickerstreak@64
|
508 end
|
flickerstreak@64
|
509 update()
|
flickerstreak@64
|
510 end,
|
flickerstreak@64
|
511 get = function(info, key)
|
flickerstreak@64
|
512 return fetch("values", ruleMap[key]) or false
|
flickerstreak@64
|
513 end,
|
flickerstreak@64
|
514 order = 4
|
flickerstreak@64
|
515 },
|
flickerstreak@64
|
516 custom = {
|
flickerstreak@64
|
517 type = "input",
|
flickerstreak@64
|
518 multiline = true,
|
flickerstreak@64
|
519 hidden = function()
|
flickerstreak@64
|
520 return fetch("type") ~= "custom"
|
flickerstreak@64
|
521 end,
|
flickerstreak@64
|
522 disabled = function()
|
flickerstreak@64
|
523 return fetch("type") == "default"
|
flickerstreak@64
|
524 end,
|
flickerstreak@64
|
525 name = L["Custom Rule"],
|
flickerstreak@64
|
526 desc = L["Syntax like macro rules: see preset rules for examples"],
|
flickerstreak@64
|
527 set = function(info, value)
|
flickerstreak@64
|
528 put("custom",value)
|
flickerstreak@64
|
529 update()
|
flickerstreak@64
|
530 end,
|
flickerstreak@64
|
531 get = function(info)
|
flickerstreak@64
|
532 return fetch("custom") or ""
|
flickerstreak@64
|
533 end,
|
flickerstreak@64
|
534 validate = function (info, rule)
|
flickerstreak@64
|
535 local s = rule:gsub("%s","") -- remove all spaces
|
flickerstreak@64
|
536 -- unfortunately %b and captures don't support the '+' notation, or this would be considerably simpler
|
flickerstreak@64
|
537 repeat
|
flickerstreak@64
|
538 if s == "" then
|
flickerstreak@64
|
539 return true
|
flickerstreak@64
|
540 end
|
flickerstreak@64
|
541 local c, r = s:match("(%b[])(.*)")
|
flickerstreak@64
|
542 if c == nil and s and #s > 0 then
|
flickerstreak@64
|
543 return L["Invalid custom rule '%s': each clause must appear within [brackets]"]:format(rule)
|
flickerstreak@64
|
544 end
|
flickerstreak@64
|
545 s = r
|
flickerstreak@64
|
546 until c == nil
|
flickerstreak@64
|
547 return true
|
flickerstreak@64
|
548 end,
|
flickerstreak@64
|
549 order = 5,
|
flickerstreak@64
|
550 }
|
flickerstreak@64
|
551 }
|
flickerstreak@64
|
552 }
|
flickerstreak@62
|
553 }
|
flickerstreak@62
|
554 return opts
|
flickerstreak@25
|
555 end
|
flickerstreak@62
|
556
|
flickerstreak@64
|
557
|
flickerstreak@62
|
558 CreateBarOptions = function(bar)
|
flickerstreak@62
|
559 local private = { }
|
flickerstreak@62
|
560 local options = {
|
flickerstreak@62
|
561 type = "group",
|
flickerstreak@62
|
562 name = L["Dynamic State"],
|
flickerstreak@64
|
563 childGroups = "tree",
|
flickerstreak@62
|
564 disabled = InCombatLockdown,
|
flickerstreak@62
|
565 args = {
|
flickerstreak@64
|
566 __desc__ = {
|
flickerstreak@64
|
567 type = "description",
|
flickerstreak@64
|
568 name = L["States are evaluated in the order they are listed"],
|
flickerstreak@64
|
569 order = 1
|
flickerstreak@64
|
570 },
|
flickerstreak@64
|
571 __new__ = {
|
flickerstreak@62
|
572 type = "group",
|
flickerstreak@64
|
573 name = L["New State..."],
|
flickerstreak@64
|
574 order = 2,
|
flickerstreak@62
|
575 args = {
|
flickerstreak@64
|
576 name = {
|
flickerstreak@64
|
577 type = "input",
|
flickerstreak@64
|
578 name = L["State Name"],
|
flickerstreak@64
|
579 desc = L["Set a name for the new state"],
|
flickerstreak@64
|
580 get = function() return private.newstatename or "" end,
|
flickerstreak@64
|
581 set = function(info,value) private.newstatename = value end,
|
flickerstreak@64
|
582 pattern = "^%w*$",
|
flickerstreak@64
|
583 usage = L["State names must be alphanumeric without spaces"],
|
flickerstreak@64
|
584 order = 1
|
flickerstreak@64
|
585 },
|
flickerstreak@64
|
586 create = {
|
flickerstreak@64
|
587 type = "execute",
|
flickerstreak@64
|
588 name = L["Create State"],
|
flickerstreak@64
|
589 func = function ()
|
flickerstreak@64
|
590 local name = private.newstatename
|
flickerstreak@64
|
591 module:CreateState(bar,name) -- TODO: select default state options and pass as final argument
|
flickerstreak@64
|
592 optionMap[bar].args[name] = CreateStateOptions(bar,name)
|
flickerstreak@64
|
593 private.newstatename = ""
|
flickerstreak@64
|
594 end,
|
flickerstreak@64
|
595 disabled = function()
|
flickerstreak@64
|
596 local name = private.newstatename or ""
|
flickerstreak@64
|
597 return #name == 0 or name:find("%W")
|
flickerstreak@64
|
598 end,
|
flickerstreak@64
|
599 order = 2,
|
flickerstreak@62
|
600 }
|
flickerstreak@62
|
601 }
|
flickerstreak@64
|
602 }
|
flickerstreak@62
|
603 }
|
flickerstreak@62
|
604 }
|
flickerstreak@62
|
605 local states = tfetch(module.db.profile.bars, bar:GetName(), "states")
|
flickerstreak@62
|
606 if states then
|
flickerstreak@62
|
607 for name, config in pairs(states) do
|
flickerstreak@64
|
608 options.args[name] = CreateStateOptions(bar,name)
|
flickerstreak@62
|
609 end
|
flickerstreak@62
|
610 end
|
flickerstreak@64
|
611 optionMap[bar] = options
|
flickerstreak@62
|
612 return options
|
flickerstreak@62
|
613 end
|
flickerstreak@25
|
614 end
|
flickerstreak@25
|
615
|
flickerstreak@62
|
616 function module:GetBarOptions(bar)
|
flickerstreak@64
|
617 return CreateBarOptions(bar)
|
flickerstreak@25
|
618 end
|