Mercurial > wow > reaction
comparison modules/VehicleExit.lua @ 222:d08a74e86c96
un-namespace totem, pet, stance, vehicle exit
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Sun, 21 Nov 2010 14:42:38 -0800 |
| parents | e63aefb8a555 |
| children | c4b134512c50 |
comparison
equal
deleted
inserted
replaced
| 221:bb13624de7e1 | 222:d08a74e86c96 |
|---|---|
| 19 -- Button class | 19 -- Button class |
| 20 local Button = ReAction.Button.VehicleExit | 20 local Button = ReAction.Button.VehicleExit |
| 21 | 21 |
| 22 -- module methods | 22 -- module methods |
| 23 function module:OnInitialize() | 23 function module:OnInitialize() |
| 24 self.db = ReAction.db:RegisterNamespace( moduleID, | |
| 25 { | |
| 26 profile = { | |
| 27 buttons = { } | |
| 28 } | |
| 29 } | |
| 30 ) | |
| 31 self.registered = { } | 24 self.registered = { } |
| 32 self.buttons = { } | 25 self.buttons = { } |
| 33 | 26 |
| 34 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") | 27 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") |
| 35 | 28 |
| 36 ReAction.RegisterCallback(self, "OnCreateBar") | 29 ReAction.RegisterCallback(self, "OnCreateBar") |
| 37 ReAction.RegisterCallback(self, "OnDestroyBar") | 30 ReAction.RegisterCallback(self, "OnDestroyBar") |
| 38 ReAction.RegisterCallback(self, "OnRefreshBar") | 31 ReAction.RegisterCallback(self, "OnRefreshBar") |
| 39 ReAction.RegisterCallback(self, "OnEraseBar") | |
| 40 ReAction.RegisterCallback(self, "OnRenameBar") | |
| 41 end | 32 end |
| 42 | 33 |
| 43 function module:OnEnable() | 34 function module:OnEnable() |
| 44 ReAction:RegisterBarType(Button) | 35 ReAction:RegisterBarType(Button) |
| 45 end | 36 end |
| 53 self:OnRefreshBar(event, bar, name) | 44 self:OnRefreshBar(event, bar, name) |
| 54 end | 45 end |
| 55 end | 46 end |
| 56 | 47 |
| 57 function module:OnRefreshBar(event, bar, name) | 48 function module:OnRefreshBar(event, bar, name) |
| 58 if bar.config.type == moduleID then | 49 local config = bar:GetConfig() |
| 59 local profile = self.db.profile | 50 if config.type == moduleID then |
| 60 if profile.buttons[name] == nil then | 51 if not config.buttons then |
| 61 profile.buttons[name] = {} | 52 config.buttons = { } |
| 62 end | 53 end |
| 63 local btnCfg = profile.buttons[name] | 54 local btnCfg = config.buttons |
| 55 btnCfg[1] = btnCfg[1] or { } | |
| 64 | 56 |
| 65 if profile.buttons[name] == nil then | |
| 66 profile.buttons[name] = { } | |
| 67 end | |
| 68 if self.buttons[bar] == nil then | 57 if self.buttons[bar] == nil then |
| 69 local success, r = pcall(Button.New, Button, 1, profile.buttons[name], bar) | 58 local success, r = pcall(Button.New, Button, 1, btnCfg[1], bar) |
| 70 if success and r then | 59 if success and r then |
| 71 self.buttons[bar] = r | 60 self.buttons[bar] = r |
| 72 bar:AddButton(1,r) | 61 bar:AddButton(1,r) |
| 73 end | 62 end |
| 74 else | 63 else |
| 84 self.buttons[bar]:Destroy() | 73 self.buttons[bar]:Destroy() |
| 85 self.buttons[bar] = nil | 74 self.buttons[bar] = nil |
| 86 end | 75 end |
| 87 end | 76 end |
| 88 | 77 |
| 89 function module:OnEraseBar(event, bar, name) | |
| 90 self.db.profile.buttons[name] = nil | |
| 91 end | |
| 92 | |
| 93 function module:OnRenameBar(event, bar, oldname, newname) | |
| 94 local b = self.db.profile.buttons | |
| 95 b[newname], b[oldname] = b[oldname], nil | |
| 96 end | |
| 97 | |
| 98 | 78 |
| 99 function module:UpdateRegistration(bar) | 79 function module:UpdateRegistration(bar) |
| 100 -- auto show/hide when on a vehicle | 80 -- auto show/hide when on a vehicle |
| 101 local config = self.db.profile.buttons[bar:GetName()] | 81 local config = bar:GetConfig() |
| 102 local f = bar:GetFrame() | 82 local f = bar:GetFrame() |
| 103 if config.withControls then | 83 if config.withControls then |
| 104 if bar.vehicleExitStateRegistered then | 84 if bar.vehicleExitStateRegistered then |
| 105 UnregisterStateDriver(f, "unitexists") | 85 UnregisterStateDriver(f, "unitexists") |
| 106 bar.vehicleExitStateRegistered = false | 86 bar.vehicleExitStateRegistered = false |
| 126 bar = bar | 106 bar = bar |
| 127 }, meta) | 107 }, meta) |
| 128 end | 108 end |
| 129 | 109 |
| 130 function Handler:GetConfig() | 110 function Handler:GetConfig() |
| 131 return module.db.profile.buttons[self.bar:GetName()] | 111 return self.bar:GetConfig() |
| 132 end | 112 end |
| 133 | 113 |
| 134 function Handler:GetPassengerOnly() | 114 function Handler:GetPassengerOnly() |
| 135 return not self:GetConfig().withControls | 115 return not self:GetConfig().withControls |
| 136 end | 116 end |
