vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 ItemBonusesFu = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDB-2.0", "AceHook-2.1", "AceEvent-2.0", "AceDebug-2.0", "FuBarPlugin-2.0")
2  
3 local L = AceLibrary("AceLocale-2.2"):new("ItemBonusesFu")
4 local tablet = AceLibrary("Tablet-2.0")
5 local crayon = AceLibrary("Crayon-2.0")
6 local compost = AceLibrary("Compost-2.0")
7 local dewdrop = AceLibrary("Dewdrop-2.0")
8 local bonus = AceLibrary("ItemBonusLib-1.0")
9  
10 local const = {
11 ItemBonuses_colors = {
12 X = 'FFD200', -- attributes
13 Y = '20FF20', -- skills
14 M = 'FFFFFF', -- melee
15 R = '00C0C0', -- ranged
16 C = 'FFFF00', -- spells
17 A = 'FF60FF', -- arcane
18 I = 'FF3600', -- fire
19 F = '00C0FF', -- frost
20 H = 'FFA400', -- holy
21 N = '00FF60', -- nature
22 S = 'AA12AC', -- shadow
23 L = '20FF20', -- life
24 P = '6060FF', -- mana
25 },
26  
27 ITEMBONUSES_EFFECTS = {
28 { effect = "STR", format = "+%d", short = "STR", color = "X", cat = "ATT" },
29 { effect = "AGI", format = "+%d", short = "AGI", color = "X", cat = "ATT" },
30 { effect = "STA", format = "+%d", short = "STA", color = "X", cat = "ATT" },
31 { effect = "INT", format = "+%d", short = "INT", color = "X", cat = "ATT" },
32 { effect = "SPI", format = "+%d", short = "SPI", color = "X", cat = "ATT" },
33 { effect = "ARMOR", format = "+%d", short = "ARM", color = "X", cat = "ATT" },
34  
35 { effect = "ARCANERES", format = "+%d", short = "R", color = "A", cat = "RES" },
36 { effect = "FIRERES", format = "+%d", short = "R", color = "I", cat = "RES" },
37 { effect = "NATURERES", format = "+%d", short = "R", color = "N", cat = "RES" },
38 { effect = "FROSTRES", format = "+%d", short = "R", color = "F", cat = "RES" },
39 { effect = "SHADOWRES", format = "+%d", short = "R", color = "S", cat = "RES" },
40  
41 { effect = "DEFENSE", format = "+%d", short = "DEF", color = "Y", cat = "SKILL" },
42 { effect = "MINING", format = "+%d", short = "MIN", color = "Y", cat = "SKILL" },
43 { effect = "HERBALISM", format = "+%d", short = "HER", color = "Y", cat = "SKILL" },
44 { effect = "SKINNING", format = "+%d", short = "SKI", color = "Y", cat = "SKILL" },
45 { effect = "FISHING", format = "+%d", short = "FIS", color = "Y", cat = "SKILL" },
46  
47 { effect = "ATTACKPOWER", format = "+%d", short = "AP", color = "M", cat = "BON" },
48 { effect = "ATTACKPOWERUNDEAD", format = "+%d", short = "APU", color = "M", cat = "BON" },
49 { effect = "ATTACKPOWERFERAL", format = "+%d", short = "APF", color = "M", cat = "BON" },
50 { effect = "CRIT", format = "+%d%%", short = "C", color = "M", cat = "BON" },
51 { effect = "BLOCK", format = "+%d%%", short = "B", color = "M", cat = "BON" },
52 { effect = "BLOCKVALUE", format = "+%d", short = "BV", color = "M", cat = "BON" },
53 { effect = "DODGE", format = "+%d%%", short = "D", color = "M", cat = "BON" },
54 { effect = "PARRY", format = "+%d%%", short = "P", color = "M", cat = "BON" },
55 { effect = "TOHIT", format = "+%d%%", short = "H", color = "M", cat = "BON" },
56 { effect = "RANGEDATTACKPOWER", format = "+%d", short = "A", color = "R", cat = "BON" },
57 { effect = "RANGEDCRIT", format = "+%d%%", short = "C", color = "R", cat = "BON" },
58  
59 { effect = "DMG", format = "+%d", short = "D", color = "C", cat = "SBON" },
60 { effect = "HEAL", format = "+%d", short = "H", color = "C", cat = "SBON"},
61 { effect = "HOLYCRIT", format = "+%d%%", short = "HC", color = "C", cat = "SBON" },
62 { effect = "SPELLCRIT", format = "+%d%%", short = "SC", color = "C", cat = "SBON" },
63 { effect = "SPELLTOHIT", format = "+%d%%", short = "SH", color = "C", cat = "SBON" },
64 { effect = "ARCANEDMG", format = "+%d", short = "D", color = "A", cat = "SBON" },
65 { effect = "FIREDMG", format = "+%d", short = "D", color = "I", cat = "SBON" },
66 { effect = "FROSTDMG", format = "+%d", short = "D", color = "F", cat = "SBON" },
67 { effect = "HOLYDMG", format = "+%d", short = "D", color = "H", cat = "SBON" },
68 { effect = "NATUREDMG", format = "+%d", short = "D", color = "N", cat = "SBON" },
69 { effect = "SHADOWDMG", format = "+%d", short = "D", color = "S", cat = "SBON" },
70 { effect = "DMGUNDEAD", format = "+%d", short = "D", color = "S", cat = "SBON" },
71 { effect = "SPELLPEN", format = "+%d", short = "SP", color = "C", cat = "SBON" },
72  
73 { effect = "HEALTH", format = "+%d", short = "P", color = "L", cat = "OBON" },
74 { effect = "HEALTHREG", format = "%d HP/5s", short = "R", color = "L", cat = "OBON" },
75 { effect = "MANA", format = "+%d", short = "P", color = "P", cat = "OBON" },
76 { effect = "MANAREG", format = "%d MP/5s", short = "R", color = "P", cat = "OBON" },
77 },
78 ITEMBONUSES_CATEGORIES = {ATT='Attributes', BON='Melee and ranged combat', SBON='Spells', RES='Resistance', SKILL='Skills', OBON='Life and mana'},
79 }
80  
81 ItemBonusesFu.version = "2.0." .. string.sub("$Revision: 9785 $", 12, -3)
82 ItemBonusesFu.date = string.sub("$Date: 2006-09-02 03:25:39 +0200 (Sa, 02 Sep 2006) $", 8, 17)
83 ItemBonusesFu.hasIcon = "Interface\\Icons\\Spell_Nature_EnchantArmor.blp"
84 ItemBonusesFu.hasNoColor = true
85 ItemBonusesFu.independentProfile = true
86  
87 function ItemBonusesFu:OnInitialize()
88 self:RegisterDB("FuBar_ItemBonusesDB")
89 end
90  
91 function ItemBonusesFu:OnEnable()
92 self:RegisterEvent("ItemBonusLib_Update", "Update", 1)
93 end
94  
95 function ItemBonusesFu:UpdateData()
96 self:Debug("Updating Data")
97 local check
98 for i,e in pairs(const.ITEMBONUSES_EFFECTS) do
99 if self.db.profile[e.effect] then
100 check = true
101 end
102 end
103 if not check then
104 self.db.profile.display_none = true
105 end
106 end
107  
108 function ItemBonusesFu:UpdateText()
109 self:Debug("Updating Text")
110 if self.db.profile.display_none then
111 if self.db.profile.short_display then
112 self:SetText(L["IB"])
113 else
114 self:SetText(L["Item Bonuses"])
115 end
116 else
117 if not bonus:IsActive() then
118 self:Debug("BonusScanner not active!")
119 self:SetText(crayon:Red(L["BonusScanner N/A"]))
120 else
121 local text = compost:Acquire()
122 for i,e in ipairs(const.ITEMBONUSES_EFFECTS) do
123 if self.db.profile[e.effect] then
124 table.insert(text, self:GetBonusText(e, false))
125 end
126 end
127 self:SetText(table.concat(text, " "))
128 compost:Reclaim(text)
129 end
130 end
131 end
132  
133 function ItemBonusesFu:OnTooltipUpdate()
134 self:Debug("Updating Tooltip")
135 if not bonus:IsActive() then
136 self:Debug("BonusScanner not active!")
137 local TabCat = tablet:AddCategory(
138 'columns', 1,
139 'child_textR', 1,
140 'child_textG', 0,
141 'child_textB', 0
142 )
143 TabCat:AddLine('text', L["BonusScanner N/A"])
144 else
145 local TabCat = compost:Acquire()
146 for i,itemcat in pairs(const.ITEMBONUSES_CATEGORIES) do
147 TabCat[i] = tablet:AddCategory(
148 'text', L[itemcat],
149 'columns', 2,
150 'textR', 0,
151 'textG', 1,
152 'textB', 0,
153 'child_textR', 1,
154 'child_textG', 1,
155 'child_textB', 0,
156 'child_text2R', 1,
157 'child_text2G', 1,
158 'child_text2B', 1
159 )
160 end
161  
162 for i,e in pairs(const.ITEMBONUSES_EFFECTS) do
163 local b = bonus:GetBonus(e.effect)
164 self:Debug(e.effect .. " = " .. b)
165 if b == 0 then
166 self:Debug("GetBonus returned 0, skipping")
167 else
168 local val
169 if e.format then
170 val = format(e.format,b)
171 else
172 val = b
173 end
174 TabCat[e.cat]:AddLine(
175 'text', bonus:GetBonusFriendlyName(e.effect),
176 'text2', val
177 )
178 end
179 end
180  
181 compost:Reclaim(TabCat)
182 end
183 end
184  
185 function ItemBonusesFu:OnMenuRequest(level, value)
186 if level == 1 then
187 dewdrop:AddLine(
188 'text', L["Display none"],
189 'func', function() self:ToggleOption("display_none", true) end,
190 'checked', self.db.profile.display_none
191 )
192 for i,e in pairs(const.ITEMBONUSES_CATEGORIES) do
193 dewdrop:AddLine(
194 'text', L[e],
195 'hasArrow', true,
196 'value', i
197 )
198 end
199 dewdrop:AddLine()
200 dewdrop:AddLine(
201 'text', L["Brief label text"],
202 'func', function() self:ToggleOption("short_display", true) end,
203 'checked', self.db.profile.short_display
204 )
205 dewdrop:AddLine(
206 'text', L["Show Colored text"],
207 'func', function() self:ToggleOption("colored", true) end,
208 'checked', self.db.profile.colored
209 )
210 elseif level == 2 then
211 for i,e in pairs(const.ITEMBONUSES_EFFECTS) do
212 if e.cat == value then
213 local my_e = e
214 dewdrop:AddLine(
215 'text', self:GetBonusText(my_e, true),
216 'func', function() self.db.profile.display_none = false; self:ToggleOption(my_e.effect, true) end,
217 'checked', self.db.profile[my_e.effect]
218 )
219 end
220 end
221 end
222 end
223  
224 function ItemBonusesFu:ToggleOption(var, doUpdate)
225 self.db.profile[var] = not self.db.profile[var]
226 if doUpdate then
227 self:Update()
228 end
229 return self.db.profile[var]
230 end
231  
232 function ItemBonusesFu:GetBonusText(EffectTable, forMenu)
233 local t = compost:Acquire()
234 local val
235 local b = bonus:GetBonus(EffectTable.effect)
236 local b_fn = bonus:GetBonusFriendlyName(EffectTable.effect)
237 if b == 0 then
238 self:Debug("GetBonus returned " .. b .. ", skipping")
239 else
240 val = format(EffectTable.format, b)
241 end
242 if forMenu then
243 table.insert(t, "[" .. crayon:Colorize(const.ItemBonuses_colors[EffectTable.color], EffectTable.short) .. "] " .. b_fn)
244 else
245 if self.db.profile.short_display then
246 table.insert(t, crayon:Colorize(const.ItemBonuses_colors[EffectTable.color], EffectTable.short))
247 else
248 table.insert(t, crayon:Colorize(const.ItemBonuses_colors[EffectTable.color], b_fn))
249 end
250 end
251 if not val then
252 if not forMenu then
253 val = format(EffectTable.format, 0)
254 else
255 local text = table.concat(t)
256 compost:Reclaim(t)
257 return text
258 end
259 end
260 if self.db.profile.colored then
261 val = crayon:Colorize(const.ItemBonuses_colors[EffectTable.color], val)
262 else
263 val = crayon:White(val)
264 end
265 if forMenu then
266 table.insert(t, " (" .. val .. ")")
267 else
268 table.insert(t, 1, " ")
269 table.insert(t, val)
270 end
271 local text = table.concat(t)
272 compost:Reclaim(t)
273 return text
274 end