flickerstreak@134
|
1 --[[
|
flickerstreak@134
|
2 ReAction Stance button module
|
flickerstreak@134
|
3
|
flickerstreak@134
|
4 --]]
|
flickerstreak@134
|
5
|
flickerstreak@134
|
6 -- local imports
|
flickerstreak@175
|
7 local addonName, addonTable = ...
|
flickerstreak@175
|
8 local ReAction = addonTable.ReAction
|
flickerstreak@134
|
9 local L = ReAction.L
|
flickerstreak@134
|
10 local _G = _G
|
flickerstreak@134
|
11
|
flickerstreak@134
|
12 -- Stance button
|
flickerstreak@134
|
13 local Button = ReAction.Button.Stance
|
flickerstreak@134
|
14
|
flickerstreak@134
|
15 -- module declaration
|
flickerstreak@134
|
16 local moduleID = "Stance"
|
flickerstreak@134
|
17 local module = ReAction:NewModule( moduleID
|
flickerstreak@134
|
18 -- mixins go here
|
flickerstreak@134
|
19 )
|
flickerstreak@134
|
20
|
flickerstreak@134
|
21 -- handlers
|
flickerstreak@134
|
22 function module:OnInitialize()
|
flickerstreak@134
|
23 self.buttons = { }
|
flickerstreak@134
|
24
|
flickerstreak@134
|
25 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
|
flickerstreak@134
|
26 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@134
|
27 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@134
|
28 end
|
flickerstreak@134
|
29
|
flickerstreak@134
|
30 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@134
|
31 local btns = self.buttons[bar]
|
flickerstreak@134
|
32 if btns then
|
flickerstreak@134
|
33 for _,b in pairs(btns) do
|
flickerstreak@134
|
34 if b then
|
flickerstreak@134
|
35 b:Destroy()
|
flickerstreak@134
|
36 end
|
flickerstreak@134
|
37 end
|
flickerstreak@134
|
38 self.buttons[bar] = nil
|
flickerstreak@134
|
39 end
|
flickerstreak@134
|
40 end
|
flickerstreak@134
|
41
|
flickerstreak@134
|
42 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@222
|
43 local config = bar:GetConfig()
|
flickerstreak@222
|
44 if config.type == moduleID then
|
flickerstreak@134
|
45 local btns = self.buttons[bar]
|
flickerstreak@134
|
46 if btns == nil then
|
flickerstreak@134
|
47 btns = { }
|
flickerstreak@134
|
48 self.buttons[bar] = btns
|
flickerstreak@134
|
49 end
|
flickerstreak@222
|
50 if not config.buttons then
|
flickerstreak@222
|
51 config.buttons = { }
|
flickerstreak@134
|
52 end
|
flickerstreak@222
|
53 local btnCfg = config.buttons
|
flickerstreak@134
|
54
|
flickerstreak@134
|
55 local r, c = bar:GetButtonGrid()
|
flickerstreak@134
|
56 local n = r*c
|
flickerstreak@134
|
57 for i = 1, n do
|
flickerstreak@134
|
58 if btnCfg[i] == nil then
|
flickerstreak@134
|
59 btnCfg[i] = {}
|
flickerstreak@134
|
60 end
|
flickerstreak@134
|
61 if btns[i] == nil then
|
flickerstreak@222
|
62 local success, r = pcall(Button.New,Button,i,btnCfg,bar,i>1 and btnCfg[i-1].stanceID)
|
flickerstreak@134
|
63 if success and r then
|
flickerstreak@134
|
64 btns[i] = r
|
flickerstreak@134
|
65 bar:AddButton(i,r)
|
flickerstreak@134
|
66 else
|
flickerstreak@134
|
67 n = i - 1
|
flickerstreak@134
|
68 bar:ClipNButtons(n)
|
flickerstreak@134
|
69 break
|
flickerstreak@134
|
70 end
|
flickerstreak@134
|
71 end
|
flickerstreak@134
|
72 btns[i]:Refresh()
|
flickerstreak@134
|
73 end
|
flickerstreak@134
|
74 for i = n+1, #btns do
|
flickerstreak@134
|
75 if btns[i] then
|
flickerstreak@134
|
76 bar:RemoveButton(btns[i])
|
flickerstreak@134
|
77 btns[i] = btns[i]:Destroy()
|
flickerstreak@134
|
78 if btnCfg[i] then
|
flickerstreak@134
|
79 btnCfg[i] = nil
|
flickerstreak@134
|
80 end
|
flickerstreak@134
|
81 end
|
flickerstreak@134
|
82 end
|
flickerstreak@134
|
83 end
|
flickerstreak@134
|
84
|
flickerstreak@134
|
85 end
|
flickerstreak@134
|
86
|