Mercurial > wow > reaction
comparison ReAction.lua @ 1:c11ca1d8ed91
Version 0.1
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Tue, 20 Mar 2007 21:03:57 +0000 |
parents | |
children | 8e0ff8ae4c08 |
comparison
equal
deleted
inserted
replaced
0:4e2ce2894c21 | 1:c11ca1d8ed91 |
---|---|
1 -- ReAction.lua | |
2 -- | |
3 -- Top-level file for the ReAction Action Bar add-on | |
4 -- | |
5 -- ReAction is implemented in terms of the Ace 2 library: http://www.wowace.com | |
6 -- | |
7 | |
8 -- key binding label constants | |
9 BINDING_HEADER_REACTION = "ReAction" | |
10 BINDING_NAME_REACTION_TOGGLELOCK = "Lock/Unlock ReAction" | |
11 | |
12 -- ReAction addon setup via Ace 2 | |
13 ReAction = AceLibrary("AceAddon-2.0"):new( | |
14 "AceConsole-2.0", | |
15 "AceEvent-2.0", | |
16 "AceDB-2.0", | |
17 "FuBarPlugin-2.0" | |
18 ) | |
19 | |
20 -- FuBar plugin setup | |
21 ReAction.hasIcon = false | |
22 ReAction.hasNoColor = true | |
23 ReAction.defaultPosition = "RIGHT" | |
24 ReAction.defaultMinimapPosition = 240 -- degrees | |
25 ReAction.OnMenuRequest = ReActionGlobalMenuOptions | |
26 | |
27 -- initial non-persistent state | |
28 ReAction.locked = true | |
29 | |
30 -- localization | |
31 -- local L = AceLibrary("AceLocale-2.0"):new("ReAction") | |
32 | |
33 | |
34 | |
35 -- Event handling | |
36 function ReAction:OnInitialize() | |
37 self:RegisterChatCommand( {"/reaction", "/rxn"}, ReActionConsoleOptions, "REACTION" ) | |
38 | |
39 self:RegisterDB("ReActionDB","ReActionDBPC") | |
40 self:RegisterDefaults("profile", ReActionProfileDefaults) | |
41 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown") | |
42 | |
43 AceLibrary("Dewdrop-2.0"):InjectAceOptionsTable(self, ReActionProfileMenuOptions) | |
44 end | |
45 | |
46 function ReAction:OnEnable() | |
47 if self.db.profile.firstRunDone ~= true then | |
48 -- Do some "first-run" setup | |
49 self.db.profile.firstRunDone = true | |
50 elseif self.db.profile.disabled == true then | |
51 -- print some kind of a warning | |
52 else | |
53 self:SetupBars() | |
54 end | |
55 end | |
56 | |
57 function ReAction:OnDisable() | |
58 self:Lock() | |
59 end | |
60 | |
61 function ReAction:OnProfileEnable() | |
62 -- handle profile switching | |
63 self:SetupBars() | |
64 self:Lock() | |
65 end | |
66 | |
67 function ReAction:CombatLockdown() | |
68 if not self:IsLocked() then | |
69 self:Lock() | |
70 UIErrorsFrame:AddMessage("ReAction bars locked when in combat") | |
71 end | |
72 end | |
73 | |
74 | |
75 -- lock/unlock ReAction | |
76 function ReAction:SetLocked( lock ) | |
77 self.locked = lock and true or false -- force data integrity | |
78 if not self.locked then | |
79 self:Print("Buttons disabled while unlocked") | |
80 end | |
81 for _, bar in ipairs(self.bars) do | |
82 if self.locked then bar:HideControls() else bar:ShowControls() end | |
83 end | |
84 end | |
85 | |
86 function ReAction:IsLocked() | |
87 return self.locked | |
88 end | |
89 | |
90 function ReAction:Lock() | |
91 self:SetLocked(true) | |
92 end | |
93 | |
94 function ReAction:Unlock() | |
95 self:SetLocked(false) | |
96 end | |
97 | |
98 function ReAction:ToggleLocked() | |
99 ReAction:SetLocked( not(self.locked) ) | |
100 end | |
101 | |
102 | |
103 | |
104 -- Hide the default Blizzard main bar artwork | |
105 function ReAction:HideArt() | |
106 if self.db.profile.hideArt then | |
107 MainMenuBar:Hide() -- this also hides the bags, xp bar, lag meter, and micro menu buttons. | |
108 else | |
109 MainMenuBar:Show() | |
110 end | |
111 end | |
112 | |
113 function ReAction:IsArtHidden() | |
114 return self.db.profile.hideArt | |
115 end | |
116 | |
117 function ReAction:SetHideArt( hide ) | |
118 self.db.profile.hideArt = hide and true or false -- force data integrity | |
119 self:HideArt() | |
120 end | |
121 | |
122 function ReAction:ToggleHideArt() | |
123 self:SetHideArt( not self:IsArtHidden() ) | |
124 end | |
125 | |
126 | |
127 | |
128 -- Keybinding color coding | |
129 function ReAction:SetKeyColorCoding( cc ) | |
130 self.db.profile.keyColorCode = cc | |
131 end | |
132 | |
133 function ReAction:IsKeyColorCodeEnabled() | |
134 return self.db.profile.keyColorCode | |
135 end | |
136 | |
137 function ReAction:ToggleKeyColorCoding() | |
138 self:SetKeyColorCoding(not self.db.profile.keyColorCode) | |
139 end | |
140 | |
141 | |
142 | |
143 -- Hide default Blizzard bars | |
144 local blizzDefaultBars = { | |
145 ActionButton1, | |
146 ActionButton2, | |
147 ActionButton3, | |
148 ActionButton4, | |
149 ActionButton5, | |
150 ActionButton6, | |
151 ActionButton7, | |
152 ActionButton8, | |
153 ActionButton9, | |
154 ActionButton10, | |
155 ActionButton11, | |
156 ActionButton12, | |
157 BonusActionBarFrame, | |
158 MultiBarLeft, | |
159 MultiBarRight, | |
160 MultiBarBottomLeft, | |
161 MultiBarBottomRight | |
162 } | |
163 | |
164 function ReAction:HideDefaultBars() | |
165 for _, f in pairs(blizzDefaultBars) do | |
166 f:Hide() | |
167 f:ClearAllPoints() | |
168 f:SetParent(ReActionButtonRecycler) | |
169 f:UnregisterAllEvents() | |
170 end | |
171 end | |
172 | |
173 | |
174 -- Reset bars to defaults | |
175 function ReAction:ResetBars() | |
176 self.db.profile.bars = ReActionProfileDefaults.bars | |
177 self:SetupBars() | |
178 end | |
179 | |
180 | |
181 -- re-sync action IDs | |
182 function ReAction:ResyncActionIDs() | |
183 -- TODO | |
184 end | |
185 | |
186 | |
187 | |
188 -- Bar manipulation | |
189 ReAction.bars = { } | |
190 | |
191 function ReAction:SetupBars() | |
192 -- hide the default Blizzard art, if configued | |
193 self:HideArt() | |
194 -- hide the default Blizzard bars | |
195 self:HideDefaultBars() | |
196 | |
197 -- set up the bars from the profile | |
198 for id, info in ipairs(self.db.profile.bars) do | |
199 if self.bars[id] then self.bars[id]:Destroy() end -- remove old version of bar if switching profiles | |
200 self.bars[id] = ReBar:new(info, id) | |
201 end | |
202 | |
203 -- remove excess bars | |
204 while #self.bars > #self.db.profile.bars do | |
205 table.remove(self.bars):Destroy() | |
206 end | |
207 | |
208 -- anchor the bars, have to do this in a second pass because | |
209 -- they might be anchored to each other in a non-ordered way | |
210 for _, bar in ipairs(self.bars) do | |
211 bar:ApplyAnchor() | |
212 end | |
213 end | |
214 | |
215 | |
216 function ReAction:NewBar() | |
217 local c = ReActionBarConfigDefaults | |
218 table.insert(self.bars, ReBar:new(c, #self.bars + 1)) | |
219 table.insert(self.db.profile.bars, c) | |
220 self:Unlock() | |
221 end | |
222 | |
223 | |
224 function ReAction:DeleteBar(id) | |
225 if self.bars[id] then | |
226 table.remove(self.bars, id):Destroy() | |
227 table.remove( self.db.profile.bars, id ) | |
228 end | |
229 end | |
230 | |
231 function ReAction:ToggleActionID() | |
232 if self.showActionIDs then | |
233 ReActionButton:HideAllActionIDs() | |
234 else | |
235 ReActionButton:ShowAllActionIDs() | |
236 end | |
237 self.showActionIDs = not self.showActionIDs | |
238 end | |
239 | |
240 function ReAction:IsActionIDVisible() | |
241 return self.showActionIDs | |
242 end | |
243 | |
244 | |
245 | |
246 -- FuBar plugin methods | |
247 local tablet = AceLibrary("Tablet-2.0") | |
248 | |
249 function ReAction:OnTooltipUpdate() | |
250 local c = tablet:AddCategory("columns", 2) | |
251 c:AddLine("text", "ReAction bar lock", "text2", self.locked and "|cffcc0000Locked|r" or "|cff00cc00Unlocked|r") | |
252 tablet:SetHint("|cffcc6600Shift-Click|r to toggle action bar lock. Right-click for options.") | |
253 end | |
254 | |
255 function ReAction:OnClick(button) | |
256 if IsShiftKeyDown() then | |
257 self:ToggleLocked() | |
258 end | |
259 self:UpdateDisplay() | |
260 end |