vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | assert( oRA, "oRA not found!") |
2 | |||
3 | ------------------------------ |
||
4 | -- Are you local? -- |
||
5 | ------------------------------ |
||
6 | |||
7 | local L = AceLibrary("AceLocale-2.2"):new("oRAOCoolDown") |
||
8 | |||
9 | local roster = AceLibrary("RosterLib-2.0") |
||
10 | |||
11 | ---------------------------- |
||
12 | -- Localization -- |
||
13 | ---------------------------- |
||
14 | |||
15 | L:RegisterTranslations("enUS", function() return { |
||
16 | ["CoolDown Monitor"] = true, |
||
17 | ["cooldown"] = true, |
||
18 | ["cooldownoptional"] = true, |
||
19 | ["Optional/CoolDown"] = true, |
||
20 | ["Options for CoolDown."] = true, |
||
21 | ["Toggle"] = true, |
||
22 | ["toggle"] = true, |
||
23 | ["Toggle the CoolDown Monitor."] = true, |
||
24 | } end ) |
||
25 | |||
26 | L:RegisterTranslations("koKR", function() return { |
||
27 | ["CoolDown Monitor"] = "재사용대기시간 모니터", |
||
28 | ["Optional/CoolDown"] = "부가/재사용대기시간", |
||
29 | ["Options for CoolDown."] = "재사용대기시간에 관한 설정.", |
||
30 | ["Toggle"] = "토글", |
||
31 | ["Toggle the CoolDown Monitor."] = "재사용대기시간 모니터 토글", |
||
32 | } end ) |
||
33 | |||
34 | L:RegisterTranslations("zhCN", function() return { |
||
35 | ["CoolDown Monitor"] = "冷却监视器", |
||
36 | ["cooldown"] = "冷却", |
||
37 | ["cooldownoptional"] = "cooldownoptional", |
||
38 | ["Optional/CoolDown"] = "Optional/CoolDown", |
||
39 | ["Options for CoolDown."] = "冷却监视器的选项", |
||
40 | ["Toggle"] = "显示", |
||
41 | ["toggle"] = "显示", |
||
42 | ["Toggle the CoolDown Monitor."] = "显示冷却监视器", |
||
43 | } end ) |
||
44 | |||
45 | L:RegisterTranslations("zhTW", function() return { |
||
46 | ["CoolDown Monitor"] = "冷卻監視器", |
||
47 | ["cooldown"] = "冷卻", |
||
48 | ["cooldownoptional"] = "cooldownoptional", |
||
49 | ["Optional/CoolDown"] = "可選/冷卻", |
||
50 | ["Options for CoolDown."] = "冷卻監視器的選項", |
||
51 | ["Toggle"] = "顯示", |
||
52 | ["toggle"] = "顯示", |
||
53 | ["Toggle the CoolDown Monitor."] = "顯示冷卻監視器", |
||
54 | } end ) |
||
55 | |||
56 | L:RegisterTranslations("frFR", function() return { |
||
57 | ["CoolDown Monitor"] = "Surveillance des \"cooldowns\"", |
||
58 | --["cooldown"] = true, |
||
59 | --["cooldownoptional"] = true, |
||
60 | ["Optional/CoolDown"] = "Optionnel/Temps de recharge", |
||
61 | ["Options for CoolDown."] = "Options concernant les temps de recharge.", |
||
62 | ["Toggle"] = "Afficher", |
||
63 | --["toggle"] = true, |
||
64 | ["Toggle the CoolDown Monitor."] = "Affiche ou non la surveillance des temps de recharge.", |
||
65 | } end ) |
||
66 | |||
67 | ---------------------------------- |
||
68 | -- Module Declaration -- |
||
69 | ---------------------------------- |
||
70 | |||
71 | oRAOCoolDown = oRA:NewModule(L["cooldownoptional"], "CandyBar-2.0") |
||
72 | oRAOCoolDown.defaults = { |
||
73 | hidden = false, |
||
74 | cooldowns = {}, |
||
75 | } |
||
76 | oRAOCoolDown.optional = true |
||
77 | oRAOCoolDown.name = L["Optional/CoolDown"] |
||
78 | oRAOCoolDown.consoleCmd = L["cooldown"] |
||
79 | oRAOCoolDown.consoleOptions = { |
||
80 | type = "group", |
||
81 | desc = L["Options for CoolDown."], |
||
82 | name = L["CoolDown Monitor"], |
||
83 | args = { |
||
84 | [L["toggle"]] = { |
||
85 | type = "toggle", name = L["Toggle"], |
||
86 | desc = L["Toggle the CoolDown Monitor."], |
||
87 | get = function() return not oRAOCoolDown.db.profile.hidden end, |
||
88 | set = function(v) |
||
89 | oRAOCoolDown:ToggleView() |
||
90 | end, |
||
91 | }, |
||
92 | } |
||
93 | } |
||
94 | |||
95 | ------------------------------ |
||
96 | -- Initialization -- |
||
97 | ------------------------------ |
||
98 | |||
99 | function oRAOCoolDown:OnEnable() |
||
100 | roster:Enable() |
||
101 | if not self.db.profile.cooldowns then self.db.profile.cooldowns = {} end |
||
102 | self.enabled = nil |
||
103 | |||
104 | self:RegisterEvent("oRA_LeftRaid") |
||
105 | self:RegisterEvent("oRA_JoinedRaid") |
||
106 | self:RegisterEvent("oRA_BarTexture") |
||
107 | end |
||
108 | |||
109 | function oRAOCoolDown:OnDisable() |
||
110 | self:UnregisterAllEvents() |
||
111 | self:DisableMonitor() |
||
112 | end |
||
113 | |||
114 | |||
115 | ------------------------ |
||
116 | -- Event Handlers -- |
||
117 | ------------------------ |
||
118 | |||
119 | function oRAOCoolDown:oRA_JoinedRaid() |
||
120 | if not self.enabled then |
||
121 | self.enabled = true |
||
122 | if not self.db.profile.hidden then |
||
123 | self:SetupFrames() |
||
124 | self.cdframe:Show() |
||
125 | self:StartAllCoolDowns() |
||
126 | end |
||
127 | self:RegisterCheck("CD", "oRA_CoolDown") |
||
128 | end |
||
129 | end |
||
130 | |||
131 | function oRAOCoolDown:oRA_LeftRaid() |
||
132 | self:DisableMonitor() |
||
133 | end |
||
134 | |||
135 | function oRAOCoolDown:oRA_CoolDown(msg, author) |
||
136 | msg = self:CleanMessage(msg) |
||
137 | local _,_,what,length = string.find( msg, "^CD (%d+) (%d+)") |
||
138 | if author and what and time then |
||
139 | if not self.db.profile.cooldowns then self.db.profile.cooldowns = {} end |
||
140 | self.db.profile.cooldowns[author] = time() + tonumber(length)*60 |
||
141 | self:StartCoolDown( author, tonumber(length)*60) |
||
142 | end |
||
143 | end |
||
144 | |||
145 | function oRAOCoolDown:oRA_BarTexture( texture ) |
||
146 | for key, val in pairs( self.db.profile.cooldowns) do |
||
147 | self:SetCandyBarTexture( "oRAOCoolDown "..key, self.core.bartextures[texture] ) |
||
148 | end |
||
149 | end |
||
150 | |||
151 | ------------------------- |
||
152 | -- Utility Functions -- |
||
153 | ------------------------- |
||
154 | |||
155 | function oRAOCoolDown:DisableMonitor() |
||
156 | self.enabled = nil |
||
157 | if self.cdframe and self.cdframe:IsVisible() then self.cdframe:Hide() end |
||
158 | self:StopAllCoolDowns() |
||
159 | self:UnregisterCheck("CD") |
||
160 | end |
||
161 | |||
162 | function oRAOCoolDown:SavePosition() |
||
163 | local f = self.cdframe |
||
164 | local x,y = f:GetLeft(), f:GetTop() |
||
165 | local s = f:GetEffectiveScale() |
||
166 | |||
167 | x,y = x*s,y*s |
||
168 | |||
169 | self.db.profile.posx = x |
||
170 | self.db.profile.posy = y |
||
171 | end |
||
172 | |||
173 | function oRAOCoolDown:RestorePosition() |
||
174 | local x = self.db.profile.posx |
||
175 | local y = self.db.profile.posy |
||
176 | |||
177 | if not x or not y then return end |
||
178 | |||
179 | local f = self.cdframe |
||
180 | local s = f:GetEffectiveScale() |
||
181 | |||
182 | x,y = x/s,y/s |
||
183 | |||
184 | f:ClearAllPoints() |
||
185 | f:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y) |
||
186 | end |
||
187 | |||
188 | function oRAOCoolDown:SetupFrames() |
||
189 | if not self.cdframe then |
||
190 | local cdframe = CreateFrame("Frame", "oRACoolDownFrame", UIParent) |
||
191 | cdframe:EnableMouse(true) |
||
192 | cdframe:SetMovable(true) |
||
193 | cdframe:RegisterForDrag("LeftButton") |
||
194 | cdframe:SetScript("OnDragStart", function() if IsAltKeyDown() then self["cdframe"]:StartMoving() end end) |
||
195 | cdframe:SetScript("OnDragStop", function() self["cdframe"]:StopMovingOrSizing() self:SavePosition() end) |
||
196 | cdframe:SetWidth(175) |
||
197 | cdframe:SetHeight(50) |
||
198 | --cdframe:SetBackdrop({ |
||
199 | -- bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", tile = true, tileSize = 16, |
||
200 | -- edgeFile = "Interface\Tooltips\UI-Tooltip-Border", edgeSize = 16, |
||
201 | -- insets = {left = 0, right = 0, top = 0, bottom = 0}, |
||
202 | --}) |
||
203 | --cdframe:SetBackdropColor(0,0,0,0.5) |
||
204 | --cdframe:SetBackdropBorderColor(1,1,1,.5) |
||
205 | cdframe:Hide() |
||
206 | cdframe:SetPoint("CENTER", UIParent, "CENTER", 0, 100) |
||
207 | |||
208 | local title = cdframe:CreateFontString(nil, "ARTWORK") |
||
209 | title:SetFontObject(GameFontNormalSmall) |
||
210 | title:SetText(L["CoolDown Monitor"]) |
||
211 | title:SetJustifyH("CENTER") |
||
212 | title:SetWidth(160) |
||
213 | title:SetHeight(12) |
||
214 | title:Show() |
||
215 | title:ClearAllPoints() |
||
216 | title:SetPoint("TOP", cdframe, "TOP", 0, -5) |
||
217 | |||
218 | local text = cdframe:CreateFontString(nil, "ARTWORK") |
||
219 | text:SetFontObject(GameFontHighlightSmall) |
||
220 | text:SetJustifyH("CENTER") |
||
221 | text:SetJustifyV("TOP") |
||
222 | text:SetWidth(160) |
||
223 | --text:SetHeight(25) |
||
224 | text:Show() |
||
225 | text:ClearAllPoints() |
||
226 | text:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -5) |
||
227 | |||
228 | self.cdframe = cdframe |
||
229 | self.title = title |
||
230 | self.text = text |
||
231 | |||
232 | self:RestorePosition() |
||
233 | end |
||
234 | end |
||
235 | |||
236 | |||
237 | function oRAOCoolDown:StartAllCoolDowns() |
||
238 | local t = time() |
||
239 | for key, val in pairs(self.db.profile.cooldowns) do |
||
240 | if t >= val then |
||
241 | self.db.profile.cooldowns[key] = nil |
||
242 | self:StopCoolDown( key ) |
||
243 | else |
||
244 | self:StartCoolDown( key, val - t ) |
||
245 | end |
||
246 | end |
||
247 | end |
||
248 | |||
249 | function oRAOCoolDown:StopAllCoolDowns() |
||
250 | local t = time() |
||
251 | for key, val in pairs(self.db.profile.cooldowns) do |
||
252 | if t >= val then self.db.profile.cooldowns[key] = nil end |
||
253 | self:StopCoolDown( key ) |
||
254 | end |
||
255 | end |
||
256 | |||
257 | function oRAOCoolDown:StartCoolDown( player, time ) |
||
258 | if not self.enabled or self.db.profile.hidden then return end |
||
259 | local unit = roster:GetUnitObjectFromName( player ) |
||
260 | if not unit then return end |
||
261 | self:RegisterCandyBarGroup("oRAOCoolDownGroup") |
||
262 | self:SetCandyBarGroupPoint("oRAOCoolDownGroup", "TOP", self.text, "BOTTOM", 0, -5 ) |
||
263 | self:RegisterCandyBar( "oRAOCoolDown "..player, time, player, nil, unit.class) |
||
264 | self:RegisterCandyBarWithGroup( "oRAOCoolDown "..player, "oRAOCoolDownGroup") |
||
265 | self:SetCandyBarWidth( "oRAOCoolDown "..player, 150) |
||
266 | self:SetCandyBarTexture( "oRAOCoolDown "..player, self.core.bartextures[self.core.db.profile.bartexture] ) |
||
267 | self:StartCandyBar( "oRAOCoolDown "..player, true) |
||
268 | end |
||
269 | |||
270 | function oRAOCoolDown:StopCoolDown( player ) |
||
271 | self:UnregisterCandyBar( "oRAOCoolDown "..player ) |
||
272 | end |
||
273 | |||
274 | |||
275 | ------------------------- |
||
276 | -- Command Handlers -- |
||
277 | ------------------------- |
||
278 | |||
279 | function oRAOCoolDown:ToggleView() |
||
280 | self.db.profile.hidden = not self.db.profile.hidden |
||
281 | if self.cdframe and self.cdframe:IsVisible() then |
||
282 | self:StopAllCoolDowns() |
||
283 | self.cdframe:Hide() |
||
284 | end |
||
285 | if self.enabled and not self.db.profile.hidden then |
||
286 | if not self.cdframe then self:SetupFrames() end |
||
287 | self.cdframe:Show() |
||
288 | self:StartAllCoolDowns() |
||
289 | end |
||
290 | end |