Mercurial > wow > reaction
comparison modules/Stance.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 |
---|---|
18 -- mixins go here | 18 -- mixins go here |
19 ) | 19 ) |
20 | 20 |
21 -- handlers | 21 -- handlers |
22 function module:OnInitialize() | 22 function module:OnInitialize() |
23 self.db = ReAction.db:RegisterNamespace( moduleID, | |
24 { | |
25 profile = { | |
26 buttons = { } | |
27 } | |
28 } | |
29 ) | |
30 | |
31 self.buttons = { } | 23 self.buttons = { } |
32 | 24 |
33 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") | 25 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") |
34 ReAction.RegisterCallback(self, "OnDestroyBar") | 26 ReAction.RegisterCallback(self, "OnDestroyBar") |
35 ReAction.RegisterCallback(self, "OnRefreshBar") | 27 ReAction.RegisterCallback(self, "OnRefreshBar") |
36 ReAction.RegisterCallback(self, "OnEraseBar") | |
37 ReAction.RegisterCallback(self, "OnRenameBar") | |
38 end | 28 end |
39 | 29 |
40 function module:OnEnable() | 30 function module:OnEnable() |
41 ReAction:RegisterBarType(Button) | 31 ReAction:RegisterBarType(Button) |
42 end | 32 end |
56 self.buttons[bar] = nil | 46 self.buttons[bar] = nil |
57 end | 47 end |
58 end | 48 end |
59 | 49 |
60 function module:OnRefreshBar(event, bar, name) | 50 function module:OnRefreshBar(event, bar, name) |
61 if bar.config.type == moduleID then | 51 local config = bar:GetConfig() |
52 if config.type == moduleID then | |
62 local btns = self.buttons[bar] | 53 local btns = self.buttons[bar] |
63 if btns == nil then | 54 if btns == nil then |
64 btns = { } | 55 btns = { } |
65 self.buttons[bar] = btns | 56 self.buttons[bar] = btns |
66 end | 57 end |
67 local profile = self.db.profile | 58 if not config.buttons then |
68 if profile.buttons[name] == nil then | 59 config.buttons = { } |
69 profile.buttons[name] = {} | |
70 end | 60 end |
71 local btnCfg = profile.buttons[name] | 61 local btnCfg = config.buttons |
72 | 62 |
73 local r, c = bar:GetButtonGrid() | 63 local r, c = bar:GetButtonGrid() |
74 local n = r*c | 64 local n = r*c |
75 for i = 1, n do | 65 for i = 1, n do |
76 if btnCfg[i] == nil then | 66 if btnCfg[i] == nil then |
77 btnCfg[i] = {} | 67 btnCfg[i] = {} |
78 end | 68 end |
79 if btns[i] == nil then | 69 if btns[i] == nil then |
80 local success, r = pcall(Button.New,Button,i,profile,bar,i>1 and btnCfg[i-1].stanceID) | 70 local success, r = pcall(Button.New,Button,i,btnCfg,bar,i>1 and btnCfg[i-1].stanceID) |
81 if success and r then | 71 if success and r then |
82 btns[i] = r | 72 btns[i] = r |
83 bar:AddButton(i,r) | 73 bar:AddButton(i,r) |
84 else | 74 else |
85 n = i - 1 | 75 n = i - 1 |
100 end | 90 end |
101 end | 91 end |
102 | 92 |
103 end | 93 end |
104 | 94 |
105 function module:OnEraseBar(event, bar, name) | |
106 self.db.profile.buttons[name] = nil | |
107 end | |
108 | |
109 function module:OnRenameBar(event, bar, oldName, newName) | |
110 local b = self.db.profile.buttons | |
111 b[newname], b[oldname] = b[oldname], nil | |
112 end | |
113 | |
114 function module:RefreshAll() | |
115 for bar in pairs(self.buttons) do | |
116 self:OnRefreshBar(nil,bar,bar:GetName()) | |
117 end | |
118 end | |
119 |