view classes/VehicleExitButton.lua @ 223:c4b134512c50

Move RegisterBarType from modules to button classes
author Flick <flickerstreak@gmail.com>
date Mon, 22 Nov 2010 10:25:18 -0800
parents d08a74e86c96
children 158c9299185b
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"], 
  }, 
  { __index = Super } )

ReAction.Button.VehicleExit = VExitButton
ReAction:RegisterBarType(VExitButton)

function VExitButton:New( idx, config, bar )
  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:EnableMouse(true)
  f:RegisterForClicks("AnyUp")
  f:RegisterEvent("UPDATE_BINDINGS")

  -- attach to skinner
  bar:SkinButton(self)

  self:Refresh()
  self:UpdateHotkey()

  return self
end

function VExitButton:GetActionID()
  return 1
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