Mercurial > wow > reaction
diff ExtraActionButton.lua @ 299:e337b39dc491
Add ExtraActionButton support
author | Flick |
---|---|
date | Wed, 14 Nov 2012 16:38:53 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ExtraActionButton.lua Wed Nov 14 16:38:53 2012 -0800 @@ -0,0 +1,114 @@ +local _, ns = ... +local ReAction = ns.ReAction +local L = ReAction.L +local format = string.format + +-- +-- ExtraAction Button class +-- +local buttonTypeID = "ExtraAction" +local Super = ReAction.Button.Action +local ExtraAction = setmetatable( + { + defaultBarConfig = { + type = buttonTypeID , + btnWidth = 52, + btnHeight = 52, + btnRows = 1, + btnColumns = 1, + spacing = 3, + buttons = { } + }, + + barType = L["Special Action Button"], + buttonTypeID = buttonTypeID + }, + { __index = Super } ) + +ReAction.Button.ExtraAction = ExtraAction +ReAction:RegisterBarType(ExtraAction) + +function ExtraAction:New( config, bar, idx, idHint ) + -- don't invoke the base ActionButton constructor, since it does a bunch of stuff that + -- we don't need. Instead, call the Button base constructor directly instead and + -- re-implement the bits of the ActionButton constructor that we actually need. + self = ReAction.Button.New(self, config, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) + + self.barConfig = bar:GetConfig() + + local f = self:GetFrame() + local barFrame = bar:GetFrame() + + self.rangeTimer = TOOLTIP_UPDATE_TIME + + self:SetActionIDPool("special-action",1) + config.actionID = self:AcquireActionID(config.actionID, idHint, true) + self.nPages = 1 + + -- compute the actual game action-ID from the extra bar offset page + local actionID = config.actionID + (GetExtraBarIndex() - 1)*NUM_ACTIONBAR_BUTTONS + self.actionID = actionID + f.action = actionID + + -- attribute setup + f:SetAttribute("type","action") + f:SetAttribute("checkselfcast", true) + f:SetAttribute("checkfocuscast", true) + f:SetAttribute("action", actionID) + f:SetAttribute("default-action", actionID) + f:SetAttribute("bar-idx",idx) + + -- non secure scripts + f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end) + f:SetScript("OnEnter", function(frame) self:OnEnter() end) + f:SetScript("OnLeave", function(frame) self:OnLeave() end) + f:SetScript("OnAttributeChanged", function(frame, attr, value) self:OnAttributeChanged(attr, value) end) + f:SetScript("PostClick", function(frame, ...) self:PostClick(...) end) + f:SetScript("OnUpdate", function(frame, elapsed) self:OnUpdate(elapsed) end) + + -- event registration + for _, evt in pairs(self.eventList) do + f:RegisterEvent(evt) + end + + -- register to use the C cooldown implementation + SetActionUIButton(f, actionID, f.cooldown) + + -- attach to skinner + bar:SkinButton(self) + + self:Refresh() + + return self +end + +function ExtraAction:Destroy() + -- similarly, don't call the ActionButton destructor function, call the Button destructor function + ReAction.Button.Destroy(self) +end + +function ExtraAction:SetupBar(bar) + -- again don't call the ActionButton:SetupBar method, because it does a lot of things we don't need/want. + -- however the Button base class SetupBar method does need to be called. + ReAction.Button.SetupBar(self,bar) + + -- show/hide the bar based on whether we have an extrabar. Hook into the unitexists mechanism that the pet bar uses. + RegisterStateDriver(bar:GetFrame(), "unitexists", "[extrabar] show ; hide") +end + +function ExtraAction:ShowGrid() + -- override: do nothing +end + +function ExtraAction:ShowGridTemp( show ) + -- override: do nothing +end + +function ExtraAction:SetActionID() + -- override: action ID never changes +end + +function ExtraAction:RefreshPages() + -- override: action ID never changes +end +