Mercurial > wow > reaction
view VehicleExitButton.lua @ 262:b2e401183d36 1.1 beta 6
Merge
author | Flick |
---|---|
date | Fri, 06 May 2011 15:49:42 -0700 |
parents | c918ff9ac787 |
children | 36a29870bf34 |
line wrap: on
line source
local addonName, addonTable = ... local ReAction = addonTable.ReAction local L = ReAction.L local format = string.format -- -- VExitButton Button class -- local buttonTypeID = "VehicleExit" local Super = ReAction.Button local VExitButton = setmetatable( { defaultBarConfig = { type = buttonTypeID , btnWidth = 36, btnHeight = 36, btnRows = 1, btnColumns = 1, spacing = 3, buttons = { } }, barType = L["Exit Vehicle Floater"], buttonTypeID = buttonTypeID }, { __index = Super } ) ReAction.Button.VehicleExit = VExitButton ReAction:RegisterBarType(VExitButton) function VExitButton:New( config, bar, idx ) local name = format("ReAction_%s_VehicleExit_%d",bar:GetName(),idx) self = Super.New(self, name, config, bar, idx, "SecureFrameTemplate, ActionButtonTemplate", "Button") -- frame setup local f = self:GetFrame() self.frames.icon:SetTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up") self.frames.icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375) -- attribute setup -- (none) -- non secure scripts f:SetScript("OnClick", VehicleExit) f:SetScript("OnEnter", function(frame) GameTooltip_AddNewbieTip(frame, LEAVE_VEHICLE, 1.0, 1.0, 1.0, nil) end) f:SetScript("OnLeave", GameTooltip_Hide) f:SetScript("OnEvent", function(frame, evt, ...) self:OnEvent(evt,...) end) -- event registration f:RegisterEvent("UPDATE_BINDINGS") -- attach to skinner bar:SkinButton(self) self:Refresh() self:UpdateHotkey() return self end function VExitButton:SetupBar(bar) Super.SetupBar(self,bar) self:UpdateRegistration(bar) end function VExitButton:GetActionID() return 1 end function VExitButton:AcquireActionID() -- don't use pool end function VExitButton:ReleaseActionID() -- don't use pool end function VExitButton:Refresh() Super.Refresh(self) -- it seems that setscale kills the texcoord, have to refresh it self.frames.icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375) end function VExitButton:OnEvent(event, ...) if self[event] then self[event](self, event, ...) end end function VExitButton:UPDATE_BINDINGS() self:UpdateHotkey() end function VExitButton:UpdateRegistration(bar) -- auto show/hide when on a vehicle local config = bar:GetConfig() local f = bar:GetFrame() if config.withControls then if bar.vehicleExitStateRegistered then UnregisterStateDriver(f, "unitexists") bar.vehicleExitStateRegistered = false end bar:RegisterUnitWatch("vehicle",true) else bar:RegisterUnitWatch("vehicle",false) if not bar.vehicleExitStateRegistered then f:SetAttribute("unit","vehicle") RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists bar.vehicleExitStateRegistered = true end end end