Mercurial > wow > reaction
comparison modules/PetAction.lua @ 234:0e20f65375d5
Reworked button creation to not use goofy event driven semantics.
author | Flick |
---|---|
date | Tue, 22 Mar 2011 17:05:51 -0700 |
parents | c4b134512c50 |
children |
comparison
equal
deleted
inserted
replaced
233:9b9f5fc84d34 | 234:0e20f65375d5 |
---|---|
1 --[[ | 1 --[[ |
2 ReAction Pet Action button module | 2 ReAction Pet Action button options module |
3 | |
4 The button module implements standard action button functionality by wrapping Blizzard's | |
5 PetActionButton frame and associated functions. | |
6 | |
7 --]] | 3 --]] |
8 | 4 |
9 -- local imports | 5 -- local imports |
10 local addonName, addonTable = ... | 6 local addonName, addonTable = ... |
11 local ReAction = addonTable.ReAction | 7 local ReAction = addonTable.ReAction |
19 local module = ReAction:NewModule( moduleID ) | 15 local module = ReAction:NewModule( moduleID ) |
20 | 16 |
21 -- Button class | 17 -- Button class |
22 local Button = ReAction.Button.PetAction | 18 local Button = ReAction.Button.PetAction |
23 | 19 |
24 -- private | |
25 local function UpdateButtonLock(bar) | |
26 local f = bar:GetFrame() | |
27 f:SetAttribute("lockbuttons",bar.config.lockButtons) | |
28 f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat) | |
29 f:Execute( | |
30 [[ | |
31 lockButtons = self:GetAttribute("lockbuttons") | |
32 lockButtonsCombat = self:GetAttribute("lockbuttonscombat") | |
33 ]]) | |
34 end | |
35 | 20 |
36 -- module methods | 21 -- module methods |
37 function module:OnInitialize() | 22 function module:OnInitialize() |
38 self.buttons = { } | |
39 | |
40 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") | 23 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") |
41 | |
42 ReAction.RegisterCallback(self, "OnCreateBar") | |
43 ReAction.RegisterCallback(self, "OnDestroyBar") | |
44 ReAction.RegisterCallback(self, "OnRefreshBar") | |
45 end | 24 end |
46 | 25 |
47 function module:OnCreateBar(event, bar, name) | |
48 if bar.config.type == moduleID then | |
49 -- auto show/hide when pet exists | |
50 bar:RegisterUnitWatch("pet",true) | |
51 self:OnRefreshBar(event, bar, name) | |
52 end | |
53 end | |
54 | |
55 function module:OnRefreshBar(event, bar, name) | |
56 local config = bar:GetConfig() | |
57 if config.type == moduleID then | |
58 if self.buttons[bar] == nil then | |
59 self.buttons[bar] = { } | |
60 end | |
61 local btns = self.buttons[bar] | |
62 if not config.buttons then | |
63 config.buttons = { } | |
64 end | |
65 local btnCfg = config.buttons | |
66 | |
67 local r, c = bar:GetButtonGrid() | |
68 local n = r*c | |
69 for i = 1, n do | |
70 if btnCfg[i] == nil then | |
71 btnCfg[i] = {} | |
72 end | |
73 if btns[i] == nil then | |
74 local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].actionID) | |
75 if success and r then | |
76 btns[i] = r | |
77 bar:AddButton(i,r) | |
78 else | |
79 n = i - 1 | |
80 bar:ClipNButtons(n) | |
81 break | |
82 end | |
83 end | |
84 btns[i]:Refresh() | |
85 end | |
86 for i = n+1, #btns do | |
87 if btns[i] then | |
88 bar:RemoveButton(btns[i]) | |
89 btns[i] = btns[i]:Destroy() | |
90 if btnCfg[i] then | |
91 btnCfg[i] = nil | |
92 end | |
93 end | |
94 end | |
95 UpdateButtonLock(bar) | |
96 end | |
97 end | |
98 | |
99 function module:OnDestroyBar(event, bar, name) | |
100 if self.buttons[bar] then | |
101 local btns = self.buttons[bar] | |
102 for _,b in pairs(btns) do | |
103 if b then | |
104 b:Destroy() | |
105 end | |
106 end | |
107 self.buttons[bar] = nil | |
108 end | |
109 end | |
110 | 26 |
111 | 27 |
112 | 28 |
113 ---- Options ---- | 29 ---- Options ---- |
114 local Handler = { } | 30 local Handler = { } |
126 return self.config.lockButtons | 42 return self.config.lockButtons |
127 end | 43 end |
128 | 44 |
129 function Handler:SetLockButtons(info, value) | 45 function Handler:SetLockButtons(info, value) |
130 self.config.lockButtons = value | 46 self.config.lockButtons = value |
131 UpdateButtonLock(self.bar) | 47 Button:UpdateButtonLock(self.bar) |
132 end | 48 end |
133 | 49 |
134 function Handler:GetLockButtonsCombat() | 50 function Handler:GetLockButtonsCombat() |
135 return self.config.lockButtonsCombat | 51 return self.config.lockButtonsCombat |
136 end | 52 end |
137 | 53 |
138 function Handler:SetLockButtonsCombat(info, value) | 54 function Handler:SetLockButtonsCombat(info, value) |
139 self.config.lockButtonsCombat = value | 55 self.config.lockButtonsCombat = value |
140 UpdateButtonLock(self.bar) | 56 Button:UpdateButtonLock(self.bar) |
141 end | 57 end |
142 | 58 |
143 function Handler:LockButtonsCombatDisabled() | 59 function Handler:LockButtonsCombatDisabled() |
144 return not self.config.lockButtons | 60 return not self.config.lockButtons |
145 end | 61 end |