Mercurial > wow > reaction
comparison modules/VehicleExit.lua @ 234:0e20f65375d5
Reworked button creation to not use goofy event driven semantics.
| author | Flick |
|---|---|
| date | Tue, 22 Mar 2011 17:05:51 -0700 |
| parents | c4b134512c50 |
| children |
comparison
equal
deleted
inserted
replaced
| 233:9b9f5fc84d34 | 234:0e20f65375d5 |
|---|---|
| 1 --[[ | 1 --[[ |
| 2 ReAction Vehicle Exit button module | 2 ReAction Vehicle Exit button options 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 --]] | 3 --]] |
| 9 | 4 |
| 10 -- local imports | 5 -- local imports |
| 11 local addonName, addonTable = ... | 6 local addonName, addonTable = ... |
| 12 local ReAction = addonTable.ReAction | 7 local ReAction = addonTable.ReAction |
| 23 function module:OnInitialize() | 18 function module:OnInitialize() |
| 24 self.registered = { } | 19 self.registered = { } |
| 25 self.buttons = { } | 20 self.buttons = { } |
| 26 | 21 |
| 27 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") | 22 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") |
| 28 | |
| 29 ReAction.RegisterCallback(self, "OnCreateBar") | |
| 30 ReAction.RegisterCallback(self, "OnDestroyBar") | |
| 31 ReAction.RegisterCallback(self, "OnRefreshBar") | |
| 32 end | |
| 33 | |
| 34 function module:OnCreateBar(event, bar, name) | |
| 35 if bar.config.type == moduleID then | |
| 36 self:OnRefreshBar(event, bar, name) | |
| 37 end | |
| 38 end | |
| 39 | |
| 40 function module:OnRefreshBar(event, bar, name) | |
| 41 local config = bar:GetConfig() | |
| 42 if config.type == moduleID then | |
| 43 if not config.buttons then | |
| 44 config.buttons = { } | |
| 45 end | |
| 46 local btnCfg = config.buttons | |
| 47 btnCfg[1] = btnCfg[1] or { } | |
| 48 | |
| 49 if self.buttons[bar] == nil then | |
| 50 local success, r = pcall(Button.New, Button, 1, btnCfg[1], bar) | |
| 51 if success and r then | |
| 52 self.buttons[bar] = r | |
| 53 bar:AddButton(1,r) | |
| 54 end | |
| 55 else | |
| 56 self.buttons[bar]:Refresh() | |
| 57 end | |
| 58 bar:ClipNButtons(1) | |
| 59 self:UpdateRegistration(bar) | |
| 60 end | |
| 61 end | |
| 62 | |
| 63 function module:OnDestroyBar(event, bar, name) | |
| 64 if self.buttons[bar] then | |
| 65 self.buttons[bar]:Destroy() | |
| 66 self.buttons[bar] = nil | |
| 67 end | |
| 68 end | |
| 69 | |
| 70 | |
| 71 function module:UpdateRegistration(bar) | |
| 72 -- auto show/hide when on a vehicle | |
| 73 local config = bar:GetConfig() | |
| 74 local f = bar:GetFrame() | |
| 75 if config.withControls then | |
| 76 if bar.vehicleExitStateRegistered then | |
| 77 UnregisterStateDriver(f, "unitexists") | |
| 78 bar.vehicleExitStateRegistered = false | |
| 79 end | |
| 80 bar:RegisterUnitWatch("vehicle",true) | |
| 81 else | |
| 82 bar:RegisterUnitWatch("vehicle",false) | |
| 83 if not bar.vehicleExitStateRegistered then | |
| 84 f:SetAttribute("unit","vehicle") | |
| 85 RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists | |
| 86 bar.vehicleExitStateRegistered = true | |
| 87 end | |
| 88 end | |
| 89 end | 23 end |
| 90 | 24 |
| 91 ---- Options ---- | 25 ---- Options ---- |
| 92 local Handler = { } | 26 local Handler = { } |
| 93 local meta = { __index = Handler } | 27 local meta = { __index = Handler } |
| 107 return not self:GetConfig().withControls | 41 return not self:GetConfig().withControls |
| 108 end | 42 end |
| 109 | 43 |
| 110 function Handler:SetPassengerOnly(info, value) | 44 function Handler:SetPassengerOnly(info, value) |
| 111 self:GetConfig().withControls = not value | 45 self:GetConfig().withControls = not value |
| 112 module:UpdateRegistration(self.bar) | 46 Button:UpdateRegistration(self.bar) |
| 113 end | 47 end |
| 114 | 48 |
| 115 | 49 |
| 116 function module:GetBarOptions(bar) | 50 function module:GetBarOptions(bar) |
| 117 if bar.config.type == moduleID then | 51 if bar.config.type == moduleID then |
