Mercurial > wow > reaction
comparison modules/ReAction_PetAction/ReAction_PetAction.lua @ 93:567a885cdfad
- pet hotkey support
- fixed showgrid when in keybind mode for action buttons
- fixed a typo (bad 'self') in overlay.lua
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Fri, 17 Oct 2008 23:13:44 +0000 |
| parents | c2504a8b996c |
| children | 39265b16d208 |
comparison
equal
deleted
inserted
replaced
| 92:5f1d7a81317c | 93:567a885cdfad |
|---|---|
| 11 local L = ReAction.L | 11 local L = ReAction.L |
| 12 local _G = _G | 12 local _G = _G |
| 13 local CreateFrame = CreateFrame | 13 local CreateFrame = CreateFrame |
| 14 | 14 |
| 15 ReAction:UpdateRevision("$Revision$") | 15 ReAction:UpdateRevision("$Revision$") |
| 16 | |
| 17 -- libraries | |
| 18 local KB = LibStub("LibKeyBound-1.0") | |
| 16 | 19 |
| 17 -- module declaration | 20 -- module declaration |
| 18 local moduleID = "PetAction" | 21 local moduleID = "PetAction" |
| 19 local module = ReAction:NewModule( moduleID ) | 22 local module = ReAction:NewModule( moduleID ) |
| 20 | 23 |
| 38 ReAction.RegisterCallback(self, "OnDestroyBar") | 41 ReAction.RegisterCallback(self, "OnDestroyBar") |
| 39 ReAction.RegisterCallback(self, "OnRefreshBar") | 42 ReAction.RegisterCallback(self, "OnRefreshBar") |
| 40 ReAction.RegisterCallback(self, "OnEraseBar") | 43 ReAction.RegisterCallback(self, "OnEraseBar") |
| 41 ReAction.RegisterCallback(self, "OnRenameBar") | 44 ReAction.RegisterCallback(self, "OnRenameBar") |
| 42 ReAction.RegisterCallback(self, "OnConfigModeChanged") | 45 ReAction.RegisterCallback(self, "OnConfigModeChanged") |
| 46 | |
| 47 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") | |
| 48 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") | |
| 49 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") | |
| 43 end | 50 end |
| 44 | 51 |
| 45 function module:OnEnable() | 52 function module:OnEnable() |
| 46 ReAction:RegisterBarType(L["Pet Action Bar"], | 53 ReAction:RegisterBarType(L["Pet Action Bar"], |
| 47 { | 54 { |
| 140 UnregisterUnitWatch(f) | 147 UnregisterUnitWatch(f) |
| 141 f:Show() | 148 f:Show() |
| 142 else | 149 else |
| 143 RegisterUnitWatch(f) | 150 RegisterUnitWatch(f) |
| 144 end | 151 end |
| 152 end | |
| 153 end | |
| 154 end | |
| 155 | |
| 156 function module:LIBKEYBOUND_ENABLED(evt) | |
| 157 for _, buttons in pairs(self.buttons) do | |
| 158 for _, b in pairs(buttons) do | |
| 159 b:SetKeybindMode(true) | |
| 160 end | |
| 161 end | |
| 162 end | |
| 163 | |
| 164 function module:LIBKEYBOUND_DISABLED(evt) | |
| 165 for _, buttons in pairs(self.buttons) do | |
| 166 for _, b in pairs(buttons) do | |
| 167 b:SetKeybindMode(false) | |
| 145 end | 168 end |
| 146 end | 169 end |
| 147 end | 170 end |
| 148 | 171 |
| 149 | 172 |
| 193 rawset(self,idx,value) | 216 rawset(self,idx,value) |
| 194 end | 217 end |
| 195 }) | 218 }) |
| 196 | 219 |
| 197 local frameRecycler = {} | 220 local frameRecycler = {} |
| 221 local trash = CreateFrame("Frame") | |
| 222 local KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings | |
| 223 do | |
| 224 local buttonLookup = setmetatable({},{__mode="kv"}) | |
| 225 | |
| 226 -- Use KeyBound-1.0 for binding, but use Override bindings instead of | |
| 227 -- regular bindings to support multiple profile use. This is a little | |
| 228 -- weird with the KeyBound dialog box (which has per-char selector as well | |
| 229 -- as an OK/Cancel box) but it's the least amount of effort to implement. | |
| 230 function GetActionName(f) | |
| 231 local b = buttonLookup[f] | |
| 232 if b then | |
| 233 return format("%s:%s", b.bar:GetName(), b.idx) | |
| 234 end | |
| 235 end | |
| 236 | |
| 237 function GetHotkey(f) | |
| 238 local b = buttonLookup[f] | |
| 239 if b then | |
| 240 return KB:ToShortKey(b:GetConfig().hotkey) | |
| 241 end | |
| 242 end | |
| 243 | |
| 244 function SetKey(f, key) | |
| 245 local b = buttonLookup[f] | |
| 246 if b then | |
| 247 local c = b:GetConfig() | |
| 248 if c.hotkey then | |
| 249 SetOverrideBinding(f, false, c.hotkey, nil) | |
| 250 end | |
| 251 if key then | |
| 252 SetOverrideBindingClick(f, false, key, f:GetName(), nil) | |
| 253 end | |
| 254 c.hotkey = key | |
| 255 b:DisplayHotkey(GetHotkey(f)) | |
| 256 end | |
| 257 end | |
| 258 | |
| 259 function FreeKey(f, key) | |
| 260 local b = buttonLookup[f] | |
| 261 if b then | |
| 262 local c = b:GetConfig() | |
| 263 if c.hotkey == key then | |
| 264 local action = f:GetActionName() | |
| 265 SetOverrideBinding(f, false, c.hotkey, nil) | |
| 266 c.hotkey = nil | |
| 267 b:DisplayHotkey(nil) | |
| 268 return action | |
| 269 end | |
| 270 end | |
| 271 return ReAction:FreeOverrideHotkey(key) | |
| 272 end | |
| 273 | |
| 274 function ClearBindings(f) | |
| 275 SetKey(f, nil) | |
| 276 end | |
| 277 | |
| 278 function GetBindings(f) | |
| 279 local b = buttonLookup[f] | |
| 280 if b then | |
| 281 return b:GetConfig().hotkey | |
| 282 end | |
| 283 end | |
| 284 | |
| 285 function KBAttach( button ) | |
| 286 local f = button:GetFrame() | |
| 287 f.GetActionName = GetActionName | |
| 288 f.GetHotkey = GetHotkey | |
| 289 f.SetKey = SetKey | |
| 290 f.FreeKey = FreeKey | |
| 291 f.ClearBindings = ClearBindings | |
| 292 f.GetBindings = GetBindings | |
| 293 buttonLookup[f] = button | |
| 294 f:SetKey(button:GetConfig().hotkey) | |
| 295 ReAction:RegisterKeybindFrame(f) | |
| 296 if ReAction:GetKeybindMode() then | |
| 297 button.border:SetVertexColor(KB:GetColorKeyBoundMode()) | |
| 298 button.border:Show() | |
| 299 end | |
| 300 end | |
| 301 end | |
| 302 | |
| 198 local meta = { __index = Button } | 303 local meta = { __index = Button } |
| 199 | 304 |
| 200 function Button:New( bar, idx, config ) | 305 function Button:New( bar, idx, config ) |
| 201 -- create new self | 306 -- create new self |
| 202 self = setmetatable( | 307 self = setmetatable( |
| 219 local f = frameRecycler[name] | 324 local f = frameRecycler[name] |
| 220 if f then | 325 if f then |
| 221 f:SetParent(parent) | 326 f:SetParent(parent) |
| 222 else | 327 else |
| 223 f = CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate") | 328 f = CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate") |
| 329 -- ditch the old hotkey text because it's tied in ActionButton_Update() to the | |
| 330 -- standard binding. We use override bindings. | |
| 331 local hotkey = _G[name.."HotKey"] | |
| 332 hotkey:SetParent(trash) | |
| 333 hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray") | |
| 334 hotkey:SetWidth(36) | |
| 335 hotkey:SetHeight(18) | |
| 336 hotkey:SetJustifyH("RIGHT") | |
| 337 hotkey:SetJustifyV("TOP") | |
| 338 hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2) | |
| 339 f.hotkey = hotkey | |
| 340 f:HookScript("OnDragStart", function() self:Update() end) | |
| 341 f:HookScript("OnReceiveDrag", function() self:Update() end) | |
| 224 end | 342 end |
| 225 if config.actionID then | 343 if config.actionID then |
| 226 f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton | 344 f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton |
| 227 end | 345 end |
| 228 f:SetFrameStrata("MEDIUM") | 346 f:SetFrameStrata("MEDIUM") |
| 229 self.frame = f | 347 self.frame = f |
| 230 self.icon = _G[("%sIcon"):format(name)] | 348 self.icon = _G[("%sIcon"):format(name)] |
| 231 self.acTex = _G[("%sAutoCastable"):format(name)] | 349 self.acTex = _G[("%sAutoCastable"):format(name)] |
| 232 self.acModel = _G[("%sShine"):format(name)] | 350 self.acModel = _G[("%sShine"):format(name)] |
| 233 self.cooldown = _G[("%sCooldown"):format(name)] | 351 self.cooldown = _G[("%sCooldown"):format(name)] |
| 234 self.hotkey = _G[("%sHotKey"):format(name)] | 352 self.hotkey = f.hotkey |
| 235 | 353 self.border = _G[("%sBorder"):format(name)] |
| 236 f:HookScript("OnDragStart", function() self:Update() end) | 354 |
| 237 f:HookScript("OnReceiveDrag", function() self:Update() end) | |
| 238 | 355 |
| 239 f:RegisterEvent("PLAYER_CONTROL_LOST"); | 356 f:RegisterEvent("PLAYER_CONTROL_LOST"); |
| 240 f:RegisterEvent("PLAYER_CONTROL_GAINED"); | 357 f:RegisterEvent("PLAYER_CONTROL_GAINED"); |
| 241 f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED"); | 358 f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED"); |
| 242 f:RegisterEvent("UNIT_PET"); | 359 f:RegisterEvent("UNIT_PET"); |
| 254 else | 371 else |
| 255 self:Update() | 372 self:Update() |
| 256 end | 373 end |
| 257 end) | 374 end) |
| 258 | 375 |
| 259 --self.binder = ReAction:AttachBinder(self) | 376 KBAttach(self) |
| 260 | 377 |
| 261 self:Refresh() | 378 self:Refresh() |
| 379 self:SetKeybindMode(ReAction:GetKeybindMode()) | |
| 380 | |
| 262 return self | 381 return self |
| 263 end | 382 end |
| 264 | 383 |
| 265 function Button:Destroy() | 384 function Button:Destroy() |
| 266 local f = self.frame | 385 local f = self.frame |
| 352 local start, duration, enable = GetPetActionCooldown(self.frame:GetID()); | 471 local start, duration, enable = GetPetActionCooldown(self.frame:GetID()); |
| 353 CooldownFrame_SetTimer(self.cooldown, start, duration, enable); | 472 CooldownFrame_SetTimer(self.cooldown, start, duration, enable); |
| 354 end | 473 end |
| 355 | 474 |
| 356 function Button:UpdateHotkey() | 475 function Button:UpdateHotkey() |
| 357 | 476 self:DisplayHotkey(GetHotkey(self.frame)) |
| 358 end | 477 end |
| 359 | 478 |
| 360 function Button:ShowActionIDLabel(show) | 479 function Button:ShowActionIDLabel(show) |
| 361 if show then | 480 if show then |
| 362 -- store the action ID label in the frame due to frame recycling | 481 -- store the action ID label in the frame due to frame recycling |
| 372 self.actionIDLabel:Show() | 491 self.actionIDLabel:Show() |
| 373 elseif self.actionIDLabel then | 492 elseif self.actionIDLabel then |
| 374 self.actionIDLabel:Hide() | 493 self.actionIDLabel:Hide() |
| 375 end | 494 end |
| 376 end | 495 end |
| 496 | |
| 497 | |
| 498 function Button:SetKeybindMode(mode) | |
| 499 if mode then | |
| 500 self.border:SetVertexColor(KB:GetColorKeyBoundMode()) | |
| 501 self.border:Show() | |
| 502 else | |
| 503 self.border:Hide() | |
| 504 end | |
| 505 end | |
| 506 | |
| 507 function Button:DisplayHotkey( key ) | |
| 508 self.hotkey:SetText(key or "") | |
| 509 end |
