vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local compost = AceLibrary("Compost-2.0")
2 local tablet = AceLibrary("Tablet-2.0")
3 local BC = AceLibrary("Babble-Class-2.0")
4 local T = AceLibrary("Tourist-2.0")
5 local R = AceLibrary("RosterLib-2.0")
6 local L = AceLibrary("AceLocale-2.0"):new("FuBar_FriendsFu")
7  
8 FuBar_FriendsFu = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceConsole-2.0", "AceDB-2.0", "FuBarPlugin-2.0")
9 FuBar_FriendsFu.hasIcon = true
10 FuBar_FriendsFu.hasNoColor = true
11 FuBar_FriendsFu.clickableTooltip = true
12 FuBar_FriendsFu:RegisterDB("FuBar_FriendsFuDB")
13 FuBar_FriendsFu:RegisterDefaults("profile", {
14 text = {
15 show_displayed = true,
16 show_online = true,
17 show_total = true,
18 },
19 tooltip = {
20 sort = "ZONE",
21 group_show = true,
22 name_color = "CLASS",
23 name_status = true,
24 class_show = false,
25 level_show = true,
26 level_color = "RELATIVE",
27 zone_show = true,
28 zone_color = "FACTION",
29 note_showauldlangsyne = true,
30 },
31 filter = {
32 class_druid = true,
33 class_hunter = true,
34 class_mage = true,
35 class_paladin = true,
36 class_priest = true,
37 class_rogue = true,
38 class_shaman = true,
39 class_warlock = true,
40 class_warrior = true,
41 level_0109 = true,
42 level_1019 = true,
43 level_2029 = true,
44 level_3039 = true,
45 level_4049 = true,
46 level_5059 = true,
47 level_60 = true,
48 zone_bg = true,
49 zone_inst = true,
50 zone_open = true,
51 }
52 })
53  
54 function FuBar_FriendsFu:OnInitialize()
55 self.lastUpdate = 0
56 end
57  
58 function FuBar_FriendsFu:OnEnable()
59 self:ScheduleRepeatingEvent(ShowFriends, 15)
60 self:RegisterEvent("FRIENDLIST_UPDATE", "Update")
61  
62 R:Enable()
63 self:RegisterEvent("RosterLib_RosterChanged", "UpdateTooltip")
64  
65 ShowFriends()
66 end
67  
68 function FuBar_FriendsFu:OnDisable()
69 R:Disable()
70 end
71  
72 local function table_multiinsert(...)
73 if arg.n < 2 or type(arg[1]) ~= "table" then
74 return
75 end
76 for i = 2, arg.n, 1 do
77 table.insert(arg[1], arg[i])
78 end
79 end
80  
81 FuBar_FriendsFu.sorts ={
82 NAME = function(a,b)
83 return a[1]<b[1]
84 end,
85 CLASS = function(a,b)
86 if a[3]<b[3] then
87 return true
88 elseif a[3]>b[3] then
89 return false
90 else
91 if a[2]<b[2] then
92 return true
93 elseif a[2]>b[2] then
94 return false
95 else
96 return FuBar_FriendsFu.sorts.NAME(a, b)
97 end
98 end
99 end,
100 LEVEL = function(a,b)
101 if a[2]<b[2] then
102 return true
103 elseif a[2]>b[2] then
104 return false
105 else
106 if a[3]<b[3] then
107 return true
108 elseif a[3]>b[3] then
109 return false
110 else
111 return FuBar_FriendsFu.sorts.NAME(a, b)
112 end
113 end
114 end,
115 ZONE = function(a,b)
116 if a[4]<b[4] then
117 return true
118 elseif a[4]>b[4] then
119 return false
120 else
121 return FuBar_FriendsFu.sorts.CLASS(a, b)
122 end
123 end,
124 }
125  
126 function FuBar_FriendsFu:OnDataUpdate()
127 if time() <= self.lastUpdate + 1 then return end
128 self.lastUpdate = time()
129  
130 if self.players then
131 self.players = compost.Reclaim(self.players, 1)
132 end
133 self.players = compost:Acquire()
134 self.playersShown = 0
135 self.playersOnline = 0
136 self.playersTotal = 0
137  
138 local numFriends = GetNumFriends()
139 local name, level, class, zone, online, status
140 for i = 1, numFriends, 1 do
141 name, level, class, zone, online, status = GetFriendInfo(i)
142 if not zone then zone = UNKNOWN end
143 if online then
144 self.playersOnline = self.playersOnline + 1
145 if self:checkFilter(class, level, zone) then
146 self.playersShown = self.playersShown + 1
147 table.insert(self.players, compost:Acquire(name, level, class, zone, status))
148 end
149 end
150 end
151 table.sort(self.players, self.sorts[self.db.profile.tooltip.sort])
152 self.playersTotal = numFriends
153 end
154  
155 function FuBar_FriendsFu:OnTextUpdate()
156 if self.playersTotal == 0 and GetNumFriends() ~= 0 then
157 self:SetText(L"Updating...")
158 return
159 end
160  
161 local temptext = ""
162 if self.db.profile.text.show_displayed then
163 temptext = temptext..self.playersShown
164 end
165 if self.db.profile.text.show_online then
166 if temptext ~= "" then
167 temptext = temptext.."/"
168 end
169 temptext = temptext..self.playersOnline
170 end
171 if self.db.profile.text.show_total then
172 if temptext ~= "" then
173 temptext = temptext.."/"
174 end
175 temptext = temptext..self.playersTotal
176 end
177 if temptext ~= "" then
178 self:SetText(temptext)
179 else
180 self:SetText("")
181 end
182 end
183  
184 function FuBar_FriendsFu:OnTooltipUpdate()
185 if self.playersTotal == 0 then
186 local cat = tablet:AddCategory(
187 'columns', 1,
188 'text', L"You aren't having any known friends.",
189 'hideBlankLine', true,
190 'showWithoutChildren', true
191 )
192 return
193 end
194  
195 if self.playersShown == 0 then
196 local cat = tablet:AddCategory(
197 'columns', 1,
198 'text', L"All friends offline or filtered.",
199 'hideBlankLine', true,
200 'showWithoutChildren', true
201 )
202 return
203 end
204  
205 local AuldLangSyne_loaded = IsAddOnLoaded("AuldLangSyne")
206  
207 local cols = compost:Acquire()
208 table.insert(cols, L"Name")
209 if self.db.profile.tooltip.class_show then
210 table.insert(cols, L"Class")
211 end
212 if self.db.profile.tooltip.level_show then
213 table.insert(cols, L"Level")
214 end
215 if self.db.profile.tooltip.zone_show then
216 table.insert(cols, L"Zone")
217 end
218 if (AuldLangSyne_loaded and self.db.profile.tooltip.note_showauldlangsyne) then
219 table.insert(cols, L"Notes")
220 end
221  
222 local cat = tablet:AddCategory(
223 'columns', table.getn(cols)
224 )
225 local header = compost:Acquire()
226 for i = 1, table.getn(cols) do
227 if i == 1 then
228 -- table_multiinsert(header, 'text', cols[i], 'textR', 1, 'textG', 1, 'textB', 1, 'justify', "CENTER")
229 table_multiinsert(header, 'text', cols[i], 'justify', "CENTER")
230 else
231 -- table_multiinsert(header, 'text'..i, cols[i], 'text'..i..'R', 1, 'text'..i..'G', 1, 'text'..i..'B', 1, 'justify'..i, "CENTER")
232 table_multiinsert(header, 'text'..i, cols[i], 'justify'..i, "CENTER")
233 end
234 end
235 cat:AddLine(unpack(header))
236 cols = compost:Reclaim(cols)
237 header = compost:Reclaim(header)
238 local line
239 local colcount
240 local temptext
241 local classcolorR, classcolorG, classcolorG
242 local levelcolor
243 local zonecolorR, zonecolorG, zonecolorB
244 for i = 1, table.getn(self.players) do
245 classcolorR, classcolorG, classcolorB = BC:GetColor(self.players[i][3])
246 levelcolor = GetDifficultyColor(self.players[i][2])
247 line = compost:Acquire()
248 if self.db.profile.tooltip.name_status and self.players[i][5] ~= "" then
249 table_multiinsert(line, 'text', self.players[i][5].." "..self.players[i][1])
250 else
251 table_multiinsert(line, 'text', self.players[i][1])
252 end
253 if self.db.profile.tooltip.name_color == "CLASS" then
254 table_multiinsert(line, 'textR', classcolorR, 'textG', classcolorG, 'textB', classcolorB)
255 else
256 table_multiinsert(line, 'textR', 1, 'textG', 1, 'textB', 0)
257 end
258 colcount = 1
259 if self.db.profile.tooltip.class_show then
260 colcount = colcount + 1
261 table.insert(line, 'text'..colcount)
262 table.insert(line, self.players[i][3])
263 table_multiinsert(line, 'text'..colcount..'R', classcolorR, 'text'..colcount..'G', classcolorG, 'text'..colcount..'B', classcolorB)
264 end
265 if self.db.profile.tooltip.level_show then
266 colcount = colcount + 1
267 table.insert(line, 'text'..colcount)
268 table.insert(line, self.players[i][2])
269 table_multiinsert(line, 'text'..colcount..'R', levelcolor.r, 'text'..colcount..'G', levelcolor.g, 'text'..colcount..'B', levelcolor.b)
270 end
271 if self.db.profile.tooltip.zone_show then
272 colcount = colcount + 1
273 table.insert(line, 'text'..colcount)
274 table.insert(line, self.players[i][4])
275 if self.db.profile.tooltip.zone_color == "FACTION" then
276 zonecolorR, zonecolorG, zonecolorB = T:GetFactionColor(self.players[i][4])
277 elseif self.db.profile.tooltip.zone_color == "LEVEL" then
278 zonecolorR, zonecolorG, zonecolorB = T:GetLevelColor(self.players[i][4])
279 else
280 zonecolorR, zonecolorG, zonecolorB = 1, 1, 0
281 end
282 table_multiinsert(line, 'text'..colcount..'R', zonecolorR, 'text'..colcount..'G', zonecolorG, 'text'..colcount..'B', zonecolorB)
283 end
284 if (AuldLangSyne_loaded and self.db.profile.tooltip.note_showauldlangsyne) then
285 colcount = colcount + 1
286 table.insert(line, 'text'..colcount)
287 temptext = ""
288 if AuldLangSyne_loaded and self.db.profile.tooltip.note_showauldlangsyne then
289 temptext = temptext ..((AuldLangSyne.db.realm.chars[self.players[i][1]] and AuldLangSyne.db.realm.chars[self.players[i][1]].note and (" {"..AuldLangSyne.db.realm.chars[self.players[i][1]].note.."} ")) or "")
290 end
291 table.insert(line, temptext)
292 table_multiinsert(line, 'text'..colcount..'R', 1, 'text'..colcount..'G', 1, 'text'..colcount..'B', 0)
293 end
294 table_multiinsert(line, 'func', 'OnNameClick', 'arg1', self, 'arg2', self.players[i][1])
295 if self.db.profile.tooltip.group_show then
296 table_multiinsert(line, 'hasCheck', true, 'checked', R:GetUnitIDFromName(self.players[i][1]) and true)
297 -- 'checkIcon', self.factions[i].isCollapsed and "Interface\\Buttons\\UI-PlusButton-Up" or "Interface\\Buttons\\UI-MinusButton-Up",
298 end
299  
300 cat:AddLine(unpack(line))
301 line = compost:Reclaim(line)
302 end
303 end
304  
305 function FuBar_FriendsFu:OnClick()
306 FriendsFrame.showFriendsList = true
307 ToggleFriendsFrame(1)
308 end
309  
310 function FuBar_FriendsFu:OnNameClick(name)
311 if not name then return end
312 if IsAltKeyDown() then
313 InviteByName(name)
314 else
315 SetItemRef("player:"..name, "|Hplayer:"..name.."|h["..name.."|h", "LeftButton")
316 end
317 end
318  
319 function FuBar_FriendsFu:checkFilter(class, level, zone)
320 if not self.db.profile.filter.class_druid and class == BC"Druid" then return false end
321 if not self.db.profile.filter.class_hunter and class == BC"Hunter" then return false end
322 if not self.db.profile.filter.class_mage and class == BC"Mage" then return false end
323 if not self.db.profile.filter.class_paladin and class == BC"Paladin" then return false end
324 if not self.db.profile.filter.class_priest and class == BC"Priest" then return false end
325 if not self.db.profile.filter.class_rogue and class == BC"Rogue" then return false end
326 if not self.db.profile.filter.class_shaman and class == BC"Shaman" then return false end
327 if not self.db.profile.filter.class_warlock and class == BC"Warlock" then return false end
328 if not self.db.profile.filter.class_warrior and class == BC"Warrior" then return false end
329  
330 if not self.db.profile.filter.level_0109 and level < 10 then return false end
331 if not self.db.profile.filter.level_1019 and level >= 10 and level < 20 then return false end
332 if not self.db.profile.filter.level_2029 and level >= 20 and level < 30 then return false end
333 if not self.db.profile.filter.level_3039 and level >= 30 and level < 40 then return false end
334 if not self.db.profile.filter.level_4049 and level >= 40 and level < 50 then return false end
335 if not self.db.profile.filter.level_5059 and level >= 50 and level < 60 then return false end
336 if not self.db.profile.filter.level_60 and level == 60 then return false end
337  
338 if not self.db.profile.filter.zone_bg and T:IsBattleground(zone) then return false end
339 if not self.db.profile.filter.zone_inst and T:IsInstance(zone) and not T:IsBattleground(zone) then return false end
340 if not self.db.profile.filter.zone_open and T:IsZone(zone) then return false end
341  
342 return true
343 end