flickerstreak@159
|
1 --[[
|
flickerstreak@159
|
2 ReAction Vehicle Exit button module
|
flickerstreak@159
|
3
|
flickerstreak@159
|
4 The button module implements a single button which you can use
|
flickerstreak@159
|
5 to exit a vehicle that doesn't have controls (replacement for
|
flickerstreak@159
|
6 MainMenuBarLeaveVehicleButton).
|
flickerstreak@159
|
7
|
flickerstreak@159
|
8 --]]
|
flickerstreak@159
|
9
|
flickerstreak@159
|
10 -- local imports
|
flickerstreak@159
|
11 local ReAction = ReAction
|
flickerstreak@159
|
12 local L = ReAction.L
|
flickerstreak@159
|
13
|
flickerstreak@159
|
14 -- module declaration
|
flickerstreak@159
|
15 local moduleID = "VehicleExit"
|
flickerstreak@159
|
16 local module = ReAction:NewModule( moduleID )
|
flickerstreak@159
|
17
|
flickerstreak@159
|
18 -- Button class
|
flickerstreak@159
|
19 local Button = ReAction.Button.VehicleExit
|
flickerstreak@159
|
20
|
flickerstreak@159
|
21 -- module methods
|
flickerstreak@159
|
22 function module:OnInitialize()
|
flickerstreak@159
|
23 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@159
|
24 {
|
flickerstreak@159
|
25 profile = {
|
flickerstreak@159
|
26 buttons = { }
|
flickerstreak@159
|
27 }
|
flickerstreak@159
|
28 }
|
flickerstreak@159
|
29 )
|
flickerstreak@159
|
30 self.registered = { }
|
flickerstreak@159
|
31 self.buttons = { }
|
flickerstreak@159
|
32
|
flickerstreak@159
|
33 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@159
|
34
|
flickerstreak@159
|
35 ReAction.RegisterCallback(self, "OnCreateBar")
|
flickerstreak@159
|
36 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@159
|
37 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@159
|
38 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@159
|
39 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@159
|
40 end
|
flickerstreak@159
|
41
|
flickerstreak@159
|
42 function module:OnEnable()
|
flickerstreak@159
|
43 ReAction:RegisterBarType(L["Exit Vehicle Floater"],
|
flickerstreak@159
|
44 {
|
flickerstreak@159
|
45 type = moduleID ,
|
flickerstreak@159
|
46 defaultButtonSize = 36,
|
flickerstreak@159
|
47 defaultBarRows = 1,
|
flickerstreak@159
|
48 defaultBarCols = 1,
|
flickerstreak@159
|
49 defaultBarSpacing = 3
|
flickerstreak@159
|
50 })
|
flickerstreak@159
|
51 end
|
flickerstreak@159
|
52
|
flickerstreak@159
|
53 function module:OnDisable()
|
flickerstreak@159
|
54 ReAction:UnregisterBarType(L["Exit Vehicle Floater"])
|
flickerstreak@159
|
55 end
|
flickerstreak@159
|
56
|
flickerstreak@159
|
57 function module:OnCreateBar(event, bar, name)
|
flickerstreak@159
|
58 if bar.config.type == moduleID then
|
flickerstreak@159
|
59 self:OnRefreshBar(event, bar, name)
|
flickerstreak@159
|
60 end
|
flickerstreak@159
|
61 end
|
flickerstreak@159
|
62
|
flickerstreak@159
|
63 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@159
|
64 if bar.config.type == moduleID then
|
flickerstreak@159
|
65 local profile = self.db.profile
|
flickerstreak@159
|
66 if profile.buttons[name] == nil then
|
flickerstreak@159
|
67 profile.buttons[name] = {}
|
flickerstreak@159
|
68 end
|
flickerstreak@159
|
69 local btnCfg = profile.buttons[name]
|
flickerstreak@159
|
70
|
flickerstreak@159
|
71 if profile.buttons[name] == nil then
|
flickerstreak@159
|
72 profile.buttons[name] = { }
|
flickerstreak@159
|
73 end
|
flickerstreak@159
|
74 if self.buttons[bar] == nil then
|
flickerstreak@159
|
75 local success, r = pcall(Button.New, Button, 1, profile.buttons[name], bar)
|
flickerstreak@159
|
76 if success and r then
|
flickerstreak@159
|
77 self.buttons[bar] = r
|
flickerstreak@159
|
78 bar:AddButton(1,r)
|
flickerstreak@159
|
79 end
|
flickerstreak@159
|
80 else
|
flickerstreak@159
|
81 self.buttons[bar]:Refresh()
|
flickerstreak@159
|
82 end
|
flickerstreak@159
|
83 bar:ClipNButtons(1)
|
flickerstreak@159
|
84 self:UpdateRegistration(bar)
|
flickerstreak@159
|
85 end
|
flickerstreak@159
|
86 end
|
flickerstreak@159
|
87
|
flickerstreak@159
|
88 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@159
|
89 if self.buttons[bar] then
|
flickerstreak@159
|
90 self.buttons[bar]:Destroy()
|
flickerstreak@159
|
91 self.buttons[bar] = nil
|
flickerstreak@159
|
92 end
|
flickerstreak@159
|
93 end
|
flickerstreak@159
|
94
|
flickerstreak@159
|
95 function module:OnEraseBar(event, bar, name)
|
flickerstreak@159
|
96 self.db.profile.buttons[name] = nil
|
flickerstreak@159
|
97 end
|
flickerstreak@159
|
98
|
flickerstreak@159
|
99 function module:OnRenameBar(event, bar, oldname, newname)
|
flickerstreak@159
|
100 local b = self.db.profile.buttons
|
flickerstreak@159
|
101 b[newname], b[oldname] = b[oldname], nil
|
flickerstreak@159
|
102 end
|
flickerstreak@159
|
103
|
flickerstreak@159
|
104
|
flickerstreak@159
|
105 function module:UpdateRegistration(bar)
|
flickerstreak@159
|
106 -- auto show/hide when on a vehicle
|
flickerstreak@159
|
107 local config = self.db.profile.buttons[bar:GetName()]
|
flickerstreak@159
|
108 local f = bar:GetFrame()
|
flickerstreak@159
|
109 if config.withControls then
|
flickerstreak@159
|
110 if bar.vehicleExitStateRegistered then
|
flickerstreak@159
|
111 UnregisterStateDriver(f, "unitexists")
|
flickerstreak@159
|
112 bar.vehicleExitStateRegistered = false
|
flickerstreak@159
|
113 end
|
flickerstreak@159
|
114 bar:RegisterUnitWatch("vehicle",true)
|
flickerstreak@159
|
115 else
|
flickerstreak@159
|
116 bar:RegisterUnitWatch("vehicle",false)
|
flickerstreak@159
|
117 if not bar.vehicleExitStateRegistered then
|
flickerstreak@159
|
118 f:SetAttribute("unit","vehicle")
|
flickerstreak@165
|
119 RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists
|
flickerstreak@159
|
120 bar.vehicleExitStateRegistered = true
|
flickerstreak@159
|
121 end
|
flickerstreak@159
|
122 end
|
flickerstreak@159
|
123 end
|
flickerstreak@159
|
124
|
flickerstreak@159
|
125 ---- Options ----
|
flickerstreak@159
|
126 local Handler = { }
|
flickerstreak@159
|
127 local meta = { __index = Handler }
|
flickerstreak@159
|
128
|
flickerstreak@159
|
129 function Handler:New(bar)
|
flickerstreak@159
|
130 return setmetatable(
|
flickerstreak@159
|
131 {
|
flickerstreak@159
|
132 bar = bar
|
flickerstreak@159
|
133 }, meta)
|
flickerstreak@159
|
134 end
|
flickerstreak@159
|
135
|
flickerstreak@159
|
136 function Handler:GetConfig()
|
flickerstreak@159
|
137 return module.db.profile.buttons[self.bar:GetName()]
|
flickerstreak@159
|
138 end
|
flickerstreak@159
|
139
|
flickerstreak@159
|
140 function Handler:GetPassengerOnly()
|
flickerstreak@159
|
141 return not self:GetConfig().withControls
|
flickerstreak@159
|
142 end
|
flickerstreak@159
|
143
|
flickerstreak@159
|
144 function Handler:SetPassengerOnly(info, value)
|
flickerstreak@159
|
145 self:GetConfig().withControls = not value
|
flickerstreak@159
|
146 module:UpdateRegistration(self.bar)
|
flickerstreak@159
|
147 end
|
flickerstreak@159
|
148
|
flickerstreak@159
|
149
|
flickerstreak@159
|
150 function module:GetBarOptions(bar)
|
flickerstreak@159
|
151 if bar.config.type == moduleID then
|
flickerstreak@159
|
152 return {
|
flickerstreak@159
|
153 type = "group",
|
flickerstreak@159
|
154 name = L["Exit Vehicle"],
|
flickerstreak@159
|
155 handler = Handler:New(bar),
|
flickerstreak@159
|
156 args = {
|
flickerstreak@159
|
157 passengerOnly = {
|
flickerstreak@159
|
158 name = L["Show only when passenger"],
|
flickerstreak@159
|
159 desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"],
|
flickerstreak@159
|
160 order = 2,
|
flickerstreak@159
|
161 width = "double",
|
flickerstreak@159
|
162 type = "toggle",
|
flickerstreak@159
|
163 get = "GetPassengerOnly",
|
flickerstreak@159
|
164 set = "SetPassengerOnly",
|
flickerstreak@159
|
165 },
|
flickerstreak@159
|
166 }
|
flickerstreak@159
|
167 }
|
flickerstreak@159
|
168 end
|
flickerstreak@159
|
169 end
|
flickerstreak@159
|
170
|
flickerstreak@159
|
171
|