Flick@276
|
1 local _, ns = ...
|
Flick@276
|
2 local ReAction = ns.ReAction
|
flickerstreak@218
|
3 local L = ReAction.L
|
flickerstreak@159
|
4 local format = string.format
|
flickerstreak@159
|
5
|
flickerstreak@159
|
6 --
|
flickerstreak@159
|
7 -- VExitButton Button class
|
flickerstreak@159
|
8 --
|
flickerstreak@218
|
9 local buttonTypeID = "VehicleExit"
|
flickerstreak@159
|
10 local Super = ReAction.Button
|
flickerstreak@218
|
11 local VExitButton = setmetatable(
|
flickerstreak@218
|
12 {
|
flickerstreak@218
|
13 defaultBarConfig = {
|
flickerstreak@218
|
14 type = buttonTypeID ,
|
flickerstreak@218
|
15 btnWidth = 36,
|
flickerstreak@218
|
16 btnHeight = 36,
|
flickerstreak@218
|
17 btnRows = 1,
|
flickerstreak@218
|
18 btnColumns = 1,
|
flickerstreak@222
|
19 spacing = 3,
|
flickerstreak@222
|
20 buttons = { }
|
flickerstreak@218
|
21 },
|
flickerstreak@218
|
22
|
flickerstreak@218
|
23 barType = L["Exit Vehicle Floater"],
|
Flick@231
|
24 buttonTypeID = buttonTypeID
|
flickerstreak@218
|
25 },
|
flickerstreak@218
|
26 { __index = Super } )
|
flickerstreak@223
|
27
|
flickerstreak@159
|
28 ReAction.Button.VehicleExit = VExitButton
|
flickerstreak@223
|
29 ReAction:RegisterBarType(VExitButton)
|
flickerstreak@159
|
30
|
Flick@234
|
31 function VExitButton:New( config, bar, idx )
|
flickerstreak@159
|
32 local name = format("ReAction_%s_VehicleExit_%d",bar:GetName(),idx)
|
flickerstreak@159
|
33
|
flickerstreak@159
|
34 self = Super.New(self, name, config, bar, idx, "SecureFrameTemplate, ActionButtonTemplate", "Button")
|
flickerstreak@159
|
35
|
flickerstreak@159
|
36 -- frame setup
|
flickerstreak@159
|
37 local f = self:GetFrame()
|
flickerstreak@159
|
38 self.frames.icon:SetTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up")
|
flickerstreak@159
|
39 self.frames.icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375)
|
flickerstreak@159
|
40
|
flickerstreak@159
|
41 -- attribute setup
|
flickerstreak@159
|
42 -- (none)
|
flickerstreak@159
|
43
|
flickerstreak@159
|
44 -- non secure scripts
|
flickerstreak@159
|
45 f:SetScript("OnClick", VehicleExit)
|
flickerstreak@159
|
46 f:SetScript("OnEnter", function(frame) GameTooltip_AddNewbieTip(frame, LEAVE_VEHICLE, 1.0, 1.0, 1.0, nil) end)
|
flickerstreak@159
|
47 f:SetScript("OnLeave", GameTooltip_Hide)
|
flickerstreak@159
|
48 f:SetScript("OnEvent", function(frame, evt, ...) self:OnEvent(evt,...) end)
|
flickerstreak@159
|
49
|
flickerstreak@159
|
50 -- event registration
|
flickerstreak@159
|
51 f:RegisterEvent("UPDATE_BINDINGS")
|
flickerstreak@159
|
52
|
flickerstreak@159
|
53 -- attach to skinner
|
flickerstreak@159
|
54 bar:SkinButton(self)
|
flickerstreak@159
|
55
|
flickerstreak@159
|
56 self:Refresh()
|
flickerstreak@159
|
57 self:UpdateHotkey()
|
flickerstreak@159
|
58
|
flickerstreak@159
|
59 return self
|
flickerstreak@159
|
60 end
|
flickerstreak@159
|
61
|
Flick@234
|
62 function VExitButton:SetupBar(bar)
|
Flick@234
|
63 Super.SetupBar(self,bar)
|
Flick@234
|
64 self:UpdateRegistration(bar)
|
Flick@234
|
65 end
|
Flick@234
|
66
|
flickerstreak@159
|
67 function VExitButton:GetActionID()
|
flickerstreak@159
|
68 return 1
|
flickerstreak@159
|
69 end
|
flickerstreak@159
|
70
|
Flick@249
|
71 function VExitButton:AcquireActionID()
|
Flick@249
|
72 -- don't use pool
|
Flick@249
|
73 end
|
Flick@249
|
74
|
Flick@249
|
75 function VExitButton:ReleaseActionID()
|
Flick@249
|
76 -- don't use pool
|
Flick@249
|
77 end
|
Flick@249
|
78
|
flickerstreak@159
|
79 function VExitButton:Refresh()
|
flickerstreak@159
|
80 Super.Refresh(self)
|
flickerstreak@159
|
81 -- it seems that setscale kills the texcoord, have to refresh it
|
flickerstreak@159
|
82 self.frames.icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375)
|
flickerstreak@159
|
83 end
|
flickerstreak@159
|
84
|
flickerstreak@159
|
85 function VExitButton:OnEvent(event, ...)
|
flickerstreak@159
|
86 if self[event] then
|
flickerstreak@159
|
87 self[event](self, event, ...)
|
flickerstreak@159
|
88 end
|
flickerstreak@159
|
89 end
|
flickerstreak@159
|
90
|
flickerstreak@159
|
91 function VExitButton:UPDATE_BINDINGS()
|
flickerstreak@159
|
92 self:UpdateHotkey()
|
flickerstreak@159
|
93 end
|
Flick@234
|
94
|
Flick@234
|
95 function VExitButton:UpdateRegistration(bar)
|
Flick@234
|
96 -- auto show/hide when on a vehicle
|
Flick@234
|
97 local config = bar:GetConfig()
|
Flick@234
|
98 local f = bar:GetFrame()
|
Flick@234
|
99 if config.withControls then
|
Flick@234
|
100 if bar.vehicleExitStateRegistered then
|
Flick@234
|
101 UnregisterStateDriver(f, "unitexists")
|
Flick@234
|
102 bar.vehicleExitStateRegistered = false
|
Flick@234
|
103 end
|
Flick@234
|
104 bar:RegisterUnitWatch("vehicle",true)
|
Flick@234
|
105 else
|
Flick@234
|
106 bar:RegisterUnitWatch("vehicle",false)
|
Flick@234
|
107 if not bar.vehicleExitStateRegistered then
|
Flick@234
|
108 f:SetAttribute("unit","vehicle")
|
Flick@234
|
109 RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists
|
Flick@234
|
110 bar.vehicleExitStateRegistered = true
|
Flick@234
|
111 end
|
Flick@234
|
112 end
|
Flick@234
|
113 end
|
Flick@234
|
114
|