vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local dewdrop = DewdropLib:GetInstance('1.0')
2 local tablet = TabletLib:GetInstance('1.0')
3 local metro = Metrognome:GetInstance('1')
4 local crayon = CrayonLib:GetInstance("1.0")
5  
6 DamageMetersFu = FuBarPlugin:GetInstance("1.2"):new({
7 name = DamageMetersFuLocals.NAME,
8 description = DamageMetersFuLocals.DESCRIPTION,
9 version = "1.2.1",
10 releaseDate = "05-27-2006",
11 aceCompatible = 103,
12 fuCompatible = 102,
13 author = "Blindchuck <Ropetown>",
14 email = "c@chuckg.org",
15 website = "http://chuckg.wowinterface.com",
16 category = "combat", -- Set this to the appropriate category.
17 db = AceDatabase:new("DamageMetersFuDB"),
18  
19 defaults = {
20 short_display = false,
21 color_display = false,
22 use_dm_colors = false,
23 shownValues = {},
24 shownRanks = {},
25 shownLeaders = {}
26 },
27  
28 cmd = AceChatCmd:new(DamageMetersFuLocals.COMMANDS, DamageMetersFuLocals.CMD_OPTIONS),
29 loc = DamageMetersFuLocals,
30 hasIcon = "Interface\\AddOns\\FuBaR_DamageMetersFu\\DamageMeters.blp",
31 cannotDetachTooltip = TRUE
32 })
33  
34 function DamageMetersFu:IsQuantityShown(var, quantity)
35 -- Check to see if there is currently a quantity type being shown for this type.
36 if ( self.data["shown"..var][quantity]) then
37 return true
38 else
39 return false
40 end
41 end
42  
43 function DamageMetersFu:ToggleQuantity(var, quantity)
44 if ( self.data["shown" .. var][quantity] ~= nil ) then
45 self.data["shown" .. var][quantity] = not self.data["shown" .. var][quantity]
46 else
47 self.data["shown" .. var][quantity] = true
48 end
49  
50 -- We always need to update if the user has selected a new variable to show so the appropriate variables are displayed.
51 self:Update()
52 end
53  
54 function DamageMetersFu:ToggleOption(var, doUpdate)
55 if self.data[var] then
56 self.data[var] = not self.data[var]
57 else
58 self.data[var] = true
59 end
60  
61 if doUpdate then
62 self:Update()
63 end
64 end
65  
66 function DamageMetersFu:Initialize()
67 -- Check if DM is loaded and setup our variable we use for checking.
68 self.DMEnabled = self:IsDamageMetersLoaded();
69 end
70  
71 function DamageMetersFu:Enable()
72 -- put something that would be run every time this is enabled. Happens at the very start as well, after Initialize.
73 if ( self.DMEnabled ) then
74 if ( not self.rankTable ) then
75 -- Setup our rankTable references for differing versions of DM; namely 4.2.1 vs 4.3.x
76 if ( DamageMeters_VERSION == 4500 ) then
77 self.rankTable = DamageMeters_rankTables[DMT_ACTIVE]
78 else
79 self.rankTable = "DamageMeters_rankTable"
80 self.rankTableGlobal = true
81 end
82 end
83  
84 metro:Register(self.name, self.OnUpdate, 1, self)
85 metro:Start(self.name)
86 end
87 end
88  
89 function DamageMetersFu:Disable()
90 -- you do not need to unregister the event here, all events/hooks are unregistered on disable implicitly.
91 if ( self.DMEnabled ) then
92 metro:Unregister(self.name)
93 end
94 end
95  
96 function DamageMetersFu:OnUpdate()
97 self:Update()
98 end
99  
100 function DamageMetersFu:OnClick()
101 if (self.DMEnabled) then
102 DamageMeters_ToggleShow()
103 end
104 end
105  
106 function DamageMetersFu:MenuSettings(level, value)
107 if ( self.DMEnabled ) then
108 if ( level == 1 ) then
109 -- Display None
110 dewdrop:AddLine(
111 'text', self.loc.MENU_DISPLAY_NONE,
112 'func', function()
113 self.data.shownValues = {}
114 self.data.shownRanks = {}
115 self.data.shownLeaders = {}
116 end
117 )
118  
119 -- Value
120 dewdrop:AddLine(
121 'text', self.loc.MENU_VALUE,
122 'hasArrow', true,
123 'value', self.loc.MENU_VALUE
124 )
125  
126 -- Rank
127 dewdrop:AddLine(
128 'text', self.loc.MENU_RANK,
129 'hasArrow', true,
130 'value', self.loc.MENU_RANK
131 )
132  
133 -- Leader
134 dewdrop:AddLine(
135 'text', self.loc.MENU_LEADER,
136 'hasArrow', true,
137 'value', self.loc.MENU_LEADER
138 )
139  
140 dewdrop:AddLine();
141  
142 -- The other stuff; reset position, pause parsing, and clear current.
143 dewdrop:AddLine(
144 'text', self.loc.MENU_RESET_POSITION,
145 'arg1', self,
146 'func', "DMResetPos"
147 )
148  
149 dewdrop:AddLine(
150 'text', self.loc.MENU_PAUSE,
151 'arg1', self,
152 'func', "DMTogglePause",
153 'checked', self:DMGetPauseState()
154 )
155  
156 dewdrop:AddLine(
157 'text', self.loc.MENU_CLEAR,
158 'arg1', self,
159 'func', "DMClear"
160 )
161  
162 dewdrop:AddLine()
163  
164 -- Basic Settings
165 dewdrop:AddLine(
166 'text', self.loc.MENU_SHORT_DISPLAY,
167 'func', function()
168 self:ToggleOption("short_display", true)
169 end,
170 'checked', self.data.short_display
171 )
172  
173 dewdrop:AddLine(
174 'text', self.loc.MENU_COLOR_DISPLAY,
175 'func', function()
176 self:ToggleOption("color_display", true)
177 end,
178 'checked', self.data.color_display
179 )
180  
181 dewdrop:AddLine(
182 'text', self.loc.MENU_USE_DM_COLORS,
183 'func', function()
184 self:ToggleOption("use_dm_colors", true)
185 end,
186 'checked', self.data.use_dm_colors
187 )
188  
189 elseif ( level == 2 ) then
190 -- value = text from the arrow pointing here.
191 -- now our quantity types, they're the same through all menu types so we don't bother checking the value.
192  
193 for i,e in self.loc.DAMAGEMETERS_QUANT do
194 dewdrop:AddLine(
195 'text', crayon:Colorize(self:GetQuantityColorCode(i), e.name),
196 'arg1', self,
197 'func', "ToggleQuantity",
198 'arg2', value,
199 'arg3', i,
200 'checked', self:IsQuantityShown(value, i)
201 )
202 end
203 end
204 end
205 end
206  
207 function DamageMetersFu:UpdateText()
208 if ( not self.DMEnabled ) then
209 -- DM not installed message
210 self:SetText(crayon:Red(self.loc.DAMAGEMETERS_MISSING))
211 else
212 local text = ""
213  
214 -- run through selected values
215 for i,e in self.data.shownValues do
216 if ( self.data.shownValues[i] ) then
217 text = text .. " " .. self:GetValueText(i)
218 end
219 end
220  
221 -- run through the selected ranks
222 local playerRanks = ( self.rankTableGlobal and getglobal(self.rankTable) or self.rankTable )[UnitName("Player")]
223 for i,e in self.data.shownRanks do
224 if ( self.data.shownRanks[i] ) then
225 if ( playerRanks ~= nil ) then
226 text = text .. " " .. self:GetRankText(i, playerRanks[i])
227 else
228 text = text .. " " .. self:GetRankText(i, nil)
229 end
230 end
231  
232  
233 end
234  
235 -- run through the selected leader boards
236 for i,e in self.data.shownLeaders do
237 if ( self.data.shownLeaders[i] ) then
238 text = text .. " " .. self:GetLeaderText(i)
239 end
240 end
241  
242 -- user hasn't selected anything to display or we're in a paused state.
243 if ( text == "" or self:DMGetPauseState() ) then
244 text = crayon:White(self.loc.TEXT)
245 end
246  
247 -- set the text
248 self:SetText(text);
249 end
250 end
251  
252 function DamageMetersFu:GetValueText(quantity)
253 -- short display
254 if ( self.data.short_display ) then
255 -- color the whole string or color just the descriptor.
256 if ( self.data.color_display ) then
257 return crayon:Colorize(self:GetQuantityColorCode(quantity), self.loc.DAMAGEMETERS_QUANT[quantity].abbr) .. crayon:White("=" .. DamageMeters_GetQuantityValueString(quantity, UnitName("Player")))
258 else
259 return crayon:Yellow(self.loc.DAMAGEMETERS_QUANT[quantity].abbr) .. crayon:White("=" .. DamageMeters_GetQuantityValueString(quantity, UnitName("Player")))
260 end
261 else
262 if ( self.data.color_display ) then
263 return crayon:Colorize(self:GetQuantityColorCode(quantity), self.loc.DAMAGEMETERS_QUANT[quantity].name) .. crayon:White("=" .. DamageMeters_GetQuantityValueString(quantity, UnitName("Player")))
264 else
265 return crayon:Yellow(self.loc.DAMAGEMETERS_QUANT[quantity].name) .. crayon:White("=" .. DamageMeters_GetQuantityValueString(quantity, UnitName("Player")))
266 end
267 end
268 end
269  
270 function DamageMetersFu:GetRankText(quantity, rank)
271 if ( rank == nil or rank == "") then
272 rank = "-"
273 end
274  
275 -- short display
276 if ( self.data.short_display ) then
277 -- color the whole string or color just the descriptor.
278 if ( self.data.color_display ) then
279 return crayon:Colorize(self:GetQuantityColorCode(quantity), self.loc.DAMAGEMETERS_QUANT[quantity].abbr .. "#") .. crayon:White("=" .. rank)
280 else
281 return crayon:Yellow(self.loc.DAMAGEMETERS_QUANT[quantity].abbr .. "#") .. crayon:White("=" .. rank)
282 end
283 else
284 if ( self.data.color_display ) then
285 return crayon:Colorize(self:GetQuantityColorCode(quantity), self.loc.DAMAGEMETERS_QUANT[quantity].name .. "#") .. crayon:White("=" .. rank)
286 else
287 return crayon:Yellow(self.loc.DAMAGEMETERS_QUANT[quantity].name .. "#") .. crayon:White("=" .. rank)
288 end
289 end
290 end
291  
292 function DamageMetersFu:GetLeaderText(quantity)
293 -- short display
294 if ( self.data.short_display ) then
295 -- color the whole string or color just the descriptor.
296 if ( self.data.color_display ) then
297 return crayon:Colorize(self:GetQuantityColorCode(quantity), self.loc.DAMAGEMETERS_QUANT[quantity].abbr .. "L") .. crayon:White("=" .. self:GetLeaderName(quantity))
298 else
299 return crayon:Yellow(self.loc.DAMAGEMETERS_QUANT[quantity].abbr .. "L") .. crayon:White("=" .. self:GetLeaderName(quantity))
300 end
301 else
302 if ( self.data.color_display ) then
303 return crayon:Colorize(self:GetQuantityColorCode(quantity), self.loc.DAMAGEMETERS_QUANT[quantity].name .. "L") .. crayon:White("=" .. self:GetLeaderName(quantity))
304 else
305 return crayon:Yellow(self.loc.DAMAGEMETERS_QUANT[quantity].name .. "L") .. crayon:White("=" .. self:GetLeaderName(quantity))
306 end
307 end
308 end
309  
310 function DamageMetersFu:GetLeaderName(quantity)
311 if ( self.DMEnabled ) then
312 for player, struct in ( self.rankTableGlobal and getglobal(self.rankTable) or self.rankTable ) do
313 if (struct[quantity] == 1) then
314 return player;
315 end
316 end
317  
318 return "-"
319 end
320 end
321  
322 -- Retrieve color codes from DM or builtin
323 function DamageMetersFu:GetQuantityColorCode(quantity)
324 -- Damage Meters default codes, + cff
325 if ( self.data.use_dm_colors ) then
326 return string.format("%02X%02X%02X",
327 DamageMeters_quantityColor[quantity][1]*255,
328 DamageMeters_quantityColor[quantity][2]*255,
329 DamageMeters_quantityColor[quantity][3]*255)
330 else
331 return self.loc.DAMAGEMETERS_QUANT[quantity].color
332 end
333 end
334  
335 function DamageMetersFu:UpdateTooltip()
336 -- DM is loaded, so click to show/hide the window. Otherwise, learn to install the right mods newbert.
337 if (self.DMEnabled) then
338 tablet:SetHint(self.loc.HINT)
339 else
340 tablet:SetHint(self.loc.DAMAGEMETERS_MISSING_DESC)
341 end
342 end
343  
344 --
345 -- Utility Functions
346 --
347  
348 function DamageMetersFu:PrintD(msg)
349 DEFAULT_CHAT_FRAME:AddMessage(msg,0.50,0.50,1.00);
350 end
351  
352 function DamageMetersFu:IsDamageMetersLoaded()
353 local _, _, _, enabled, _, _, _ = GetAddOnInfo("DamageMeters")
354  
355 if (enabled == 1) then -- We know Fubar is running, so check DamageMeters
356 self:PrintD("DamageMeters: FuBaR Plugin Available") -- for the plugin
357 return true -- return 1
358 else -- otherwise Fubar is running but DamageMeters is not
359 self:PrintD("DamageMeters: DamageMetersNot Loaded.") -- so let us know
360 return false -- and return
361 end
362 end
363  
364 --
365 -- Access to damage meters functions/data.
366 --
367  
368 -- Reset frame position
369 function DamageMetersFu:DMResetPos()
370 if (self.DMEnabled) then
371 DamageMeters_ResetPos()
372 end
373 end
374  
375 -- Pause parsing
376 function DamageMetersFu:DMTogglePause()
377 if (self.DMEnabled) then
378 DamageMeters_TogglePause()
379 end
380 end
381  
382 -- Retrieve the status of the pause state.
383 function DamageMetersFu:DMGetPauseState()
384 if ( DamageMeters_pauseState == 1 ) then
385 return true
386 else
387 return false
388 end
389 end
390  
391 -- Clear current data
392 function DamageMetersFu:DMClear()
393 if (self.DMEnabled) then
394 DamageMeters_Clear()
395 end
396 end
397  
398 DamageMetersFu:RegisterForLoad()