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@175
|
11 local addonName, addonTable = ...
|
flickerstreak@175
|
12 local ReAction = addonTable.ReAction
|
flickerstreak@159
|
13 local L = ReAction.L
|
flickerstreak@159
|
14
|
flickerstreak@159
|
15 -- module declaration
|
flickerstreak@159
|
16 local moduleID = "VehicleExit"
|
flickerstreak@159
|
17 local module = ReAction:NewModule( moduleID )
|
flickerstreak@159
|
18
|
flickerstreak@159
|
19 -- Button class
|
flickerstreak@159
|
20 local Button = ReAction.Button.VehicleExit
|
flickerstreak@159
|
21
|
flickerstreak@159
|
22 -- module methods
|
flickerstreak@159
|
23 function module:OnInitialize()
|
flickerstreak@159
|
24 self.registered = { }
|
flickerstreak@159
|
25 self.buttons = { }
|
flickerstreak@159
|
26
|
flickerstreak@159
|
27 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@159
|
28
|
flickerstreak@159
|
29 ReAction.RegisterCallback(self, "OnCreateBar")
|
flickerstreak@159
|
30 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@159
|
31 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@159
|
32 end
|
flickerstreak@159
|
33
|
flickerstreak@159
|
34 function module:OnCreateBar(event, bar, name)
|
flickerstreak@159
|
35 if bar.config.type == moduleID then
|
flickerstreak@159
|
36 self:OnRefreshBar(event, bar, name)
|
flickerstreak@159
|
37 end
|
flickerstreak@159
|
38 end
|
flickerstreak@159
|
39
|
flickerstreak@159
|
40 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@222
|
41 local config = bar:GetConfig()
|
flickerstreak@222
|
42 if config.type == moduleID then
|
flickerstreak@222
|
43 if not config.buttons then
|
flickerstreak@222
|
44 config.buttons = { }
|
flickerstreak@159
|
45 end
|
flickerstreak@222
|
46 local btnCfg = config.buttons
|
flickerstreak@222
|
47 btnCfg[1] = btnCfg[1] or { }
|
flickerstreak@159
|
48
|
flickerstreak@159
|
49 if self.buttons[bar] == nil then
|
flickerstreak@222
|
50 local success, r = pcall(Button.New, Button, 1, btnCfg[1], bar)
|
flickerstreak@159
|
51 if success and r then
|
flickerstreak@159
|
52 self.buttons[bar] = r
|
flickerstreak@159
|
53 bar:AddButton(1,r)
|
flickerstreak@159
|
54 end
|
flickerstreak@159
|
55 else
|
flickerstreak@159
|
56 self.buttons[bar]:Refresh()
|
flickerstreak@159
|
57 end
|
flickerstreak@159
|
58 bar:ClipNButtons(1)
|
flickerstreak@159
|
59 self:UpdateRegistration(bar)
|
flickerstreak@159
|
60 end
|
flickerstreak@159
|
61 end
|
flickerstreak@159
|
62
|
flickerstreak@159
|
63 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@159
|
64 if self.buttons[bar] then
|
flickerstreak@159
|
65 self.buttons[bar]:Destroy()
|
flickerstreak@159
|
66 self.buttons[bar] = nil
|
flickerstreak@159
|
67 end
|
flickerstreak@159
|
68 end
|
flickerstreak@159
|
69
|
flickerstreak@159
|
70
|
flickerstreak@159
|
71 function module:UpdateRegistration(bar)
|
flickerstreak@159
|
72 -- auto show/hide when on a vehicle
|
flickerstreak@222
|
73 local config = bar:GetConfig()
|
flickerstreak@159
|
74 local f = bar:GetFrame()
|
flickerstreak@159
|
75 if config.withControls then
|
flickerstreak@159
|
76 if bar.vehicleExitStateRegistered then
|
flickerstreak@159
|
77 UnregisterStateDriver(f, "unitexists")
|
flickerstreak@159
|
78 bar.vehicleExitStateRegistered = false
|
flickerstreak@159
|
79 end
|
flickerstreak@159
|
80 bar:RegisterUnitWatch("vehicle",true)
|
flickerstreak@159
|
81 else
|
flickerstreak@159
|
82 bar:RegisterUnitWatch("vehicle",false)
|
flickerstreak@159
|
83 if not bar.vehicleExitStateRegistered then
|
flickerstreak@159
|
84 f:SetAttribute("unit","vehicle")
|
flickerstreak@165
|
85 RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists
|
flickerstreak@159
|
86 bar.vehicleExitStateRegistered = true
|
flickerstreak@159
|
87 end
|
flickerstreak@159
|
88 end
|
flickerstreak@159
|
89 end
|
flickerstreak@159
|
90
|
flickerstreak@159
|
91 ---- Options ----
|
flickerstreak@159
|
92 local Handler = { }
|
flickerstreak@159
|
93 local meta = { __index = Handler }
|
flickerstreak@159
|
94
|
flickerstreak@159
|
95 function Handler:New(bar)
|
flickerstreak@159
|
96 return setmetatable(
|
flickerstreak@159
|
97 {
|
flickerstreak@159
|
98 bar = bar
|
flickerstreak@159
|
99 }, meta)
|
flickerstreak@159
|
100 end
|
flickerstreak@159
|
101
|
flickerstreak@159
|
102 function Handler:GetConfig()
|
flickerstreak@222
|
103 return self.bar:GetConfig()
|
flickerstreak@159
|
104 end
|
flickerstreak@159
|
105
|
flickerstreak@159
|
106 function Handler:GetPassengerOnly()
|
flickerstreak@159
|
107 return not self:GetConfig().withControls
|
flickerstreak@159
|
108 end
|
flickerstreak@159
|
109
|
flickerstreak@159
|
110 function Handler:SetPassengerOnly(info, value)
|
flickerstreak@159
|
111 self:GetConfig().withControls = not value
|
flickerstreak@159
|
112 module:UpdateRegistration(self.bar)
|
flickerstreak@159
|
113 end
|
flickerstreak@159
|
114
|
flickerstreak@159
|
115
|
flickerstreak@159
|
116 function module:GetBarOptions(bar)
|
flickerstreak@159
|
117 if bar.config.type == moduleID then
|
flickerstreak@159
|
118 return {
|
flickerstreak@159
|
119 type = "group",
|
flickerstreak@159
|
120 name = L["Exit Vehicle"],
|
flickerstreak@159
|
121 handler = Handler:New(bar),
|
flickerstreak@159
|
122 args = {
|
flickerstreak@159
|
123 passengerOnly = {
|
flickerstreak@159
|
124 name = L["Show only when passenger"],
|
flickerstreak@159
|
125 desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"],
|
flickerstreak@159
|
126 order = 2,
|
flickerstreak@159
|
127 width = "double",
|
flickerstreak@159
|
128 type = "toggle",
|
flickerstreak@159
|
129 get = "GetPassengerOnly",
|
flickerstreak@159
|
130 set = "SetPassengerOnly",
|
flickerstreak@159
|
131 },
|
flickerstreak@159
|
132 }
|
flickerstreak@159
|
133 }
|
flickerstreak@159
|
134 end
|
flickerstreak@159
|
135 end
|
flickerstreak@159
|
136
|
flickerstreak@159
|
137
|