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