comparison VehicleExitButton.lua @ 245:65f2805957a0

No real reason to store some of the code in a subdirectory.
author Flick
date Sat, 26 Mar 2011 12:35:08 -0700
parents classes/VehicleExitButton.lua@0e20f65375d5
children 46b59a9ded76
comparison
equal deleted inserted replaced
244:f255cd69e890 245:65f2805957a0
1 local addonName, addonTable = ...
2 local ReAction = addonTable.ReAction
3 local L = ReAction.L
4 local format = string.format
5
6 --
7 -- VExitButton Button class
8 --
9 local buttonTypeID = "VehicleExit"
10 local Super = ReAction.Button
11 local VExitButton = setmetatable(
12 {
13 defaultBarConfig = {
14 type = buttonTypeID ,
15 btnWidth = 36,
16 btnHeight = 36,
17 btnRows = 1,
18 btnColumns = 1,
19 spacing = 3,
20 buttons = { }
21 },
22
23 barType = L["Exit Vehicle Floater"],
24 buttonTypeID = buttonTypeID
25 },
26 { __index = Super } )
27
28 ReAction.Button.VehicleExit = VExitButton
29 ReAction:RegisterBarType(VExitButton)
30
31 function VExitButton:New( config, bar, idx )
32 local name = format("ReAction_%s_VehicleExit_%d",bar:GetName(),idx)
33
34 self = Super.New(self, name, config, bar, idx, "SecureFrameTemplate, ActionButtonTemplate", "Button")
35
36 -- frame setup
37 local f = self:GetFrame()
38 self.frames.icon:SetTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up")
39 self.frames.icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375)
40
41 -- attribute setup
42 -- (none)
43
44 -- non secure scripts
45 f:SetScript("OnClick", VehicleExit)
46 f:SetScript("OnEnter", function(frame) GameTooltip_AddNewbieTip(frame, LEAVE_VEHICLE, 1.0, 1.0, 1.0, nil) end)
47 f:SetScript("OnLeave", GameTooltip_Hide)
48 f:SetScript("OnEvent", function(frame, evt, ...) self:OnEvent(evt,...) end)
49
50 -- event registration
51 f:EnableMouse(true)
52 f:RegisterForClicks("AnyUp")
53 f:RegisterEvent("UPDATE_BINDINGS")
54
55 -- attach to skinner
56 bar:SkinButton(self)
57
58 self:Refresh()
59 self:UpdateHotkey()
60
61 return self
62 end
63
64 function VExitButton:SetupBar(bar)
65 Super.SetupBar(self,bar)
66 self:UpdateRegistration(bar)
67 end
68
69 function VExitButton:GetActionID()
70 return 1
71 end
72
73 function VExitButton:Refresh()
74 Super.Refresh(self)
75 -- it seems that setscale kills the texcoord, have to refresh it
76 self.frames.icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375)
77 end
78
79 function VExitButton:OnEvent(event, ...)
80 if self[event] then
81 self[event](self, event, ...)
82 end
83 end
84
85 function VExitButton:UPDATE_BINDINGS()
86 self:UpdateHotkey()
87 end
88
89 function VExitButton:UpdateRegistration(bar)
90 -- auto show/hide when on a vehicle
91 local config = bar:GetConfig()
92 local f = bar:GetFrame()
93 if config.withControls then
94 if bar.vehicleExitStateRegistered then
95 UnregisterStateDriver(f, "unitexists")
96 bar.vehicleExitStateRegistered = false
97 end
98 bar:RegisterUnitWatch("vehicle",true)
99 else
100 bar:RegisterUnitWatch("vehicle",false)
101 if not bar.vehicleExitStateRegistered then
102 f:SetAttribute("unit","vehicle")
103 RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists
104 bar.vehicleExitStateRegistered = true
105 end
106 end
107 end
108