forked from tb1337/wow-addon-iguild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColumns.lua
375 lines (343 loc) · 11.6 KB
/
Columns.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
-----------------------------
-- Get the addon table
-----------------------------
local AddonName, iGuild = ...;
local L = LibStub("AceLocale-3.0"):GetLocale(AddonName);
local LibCrayon = LibStub("LibCrayon-3.0");
local LibTourist = LibStub("LibTourist-3.0"); -- a really memory-eating lib.
local _G = _G; -- I always use _G.FUNC when I call a Global. Upvalueing done here.
local format = string.format;
local iconSize = 14;
local Mobile_Away_Icon = "\124TInterface\\ChatFrame\\UI-ChatIcon-ArmoryChat-AwayMobile:14:14:0:0:16:16:0:16:0:16\124t";
local Mobile_Busy_Icon = "\124TInterface\\ChatFrame\\UI-ChatIcon-ArmoryChat-BusyMobile:14:14:0:0:16:16:0:16:0:16\124t";
local Mobile_Icon = "\124TInterface\\ChatFrame\\UI-ChatIcon-ArmoryChat:14:14:0:0:16:16:0:16:0:16:73:177:73a\124t";
-----------------------------------------
-- Variables, functions and colors
-----------------------------------------
local COLOR_GOLD = "|cfffed100%s|r";
local COLOR_MASTER = "|cffff6644%s|r";
local COLOR_OFFICER = "|cff40c040%s|r";
local MAX_ACMPOINTS = 35800; -- see iGuild/Developer.lua
local MAX_PROFESSION_SKILL = 900; -- Battle for Azeroth
local working_member; -- set and resetted by OnEnter/OnLeave handlers
----------------------------
-- Sorting and Columns
-----------------------------
iGuild.Sort = {
-- sort by name
name_asc = function(a, b)
return a.name < b.name;
end,
-- sort by level and fall back to name
---------------------------------------------------------
level_asc = function(a, b)
if( a.level < b.level ) then
return true;
elseif( a.level > b.level ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
level_desc = function(a, b)
if( a.level > b.level ) then
return true;
elseif( a.level < b.level ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
-- sort by class and fall back to name
---------------------------------------------------------
class_asc = function(a, b)
if( a.class < b.class ) then
return true;
elseif( a.class > b.class ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
class_desc = function(a, b)
if( a.class > b.class ) then
return true;
elseif( a.class < b.class ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
-- sort by guild rank and fall back to name
---------------------------------------------------------
rank_asc = function(a, b)
if( a.grank < b.grank ) then
return true;
elseif( a.grank > b.grank ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
rank_desc = function(a, b)
if( a.grank > b.grank ) then
return true;
elseif( a.grank < b.grank ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
-- sort by achievement points and fall back to name
---------------------------------------------------------
points_asc = function(a, b)
if( a.apoints < b.apoints ) then
return true;
elseif( a.apoints > b.apoints ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
points_desc = function(a, b)
if( a.apoints > b.apoints ) then
return true;
elseif( a.apoints < b.apoints ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
-- sort by zone and fall back to name
---------------------------------------------------------
zone_asc = function(a, b)
if( a.zone < b.zone ) then
return true;
elseif( a.zone > b.zone ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end,
zone_desc = function(a, b)
if( a.zone > b.zone ) then
return true;
elseif( a.zone < b.zone ) then
return false;
else
return iGuild.Sort.name_asc(a, b);
end
end
};
-- iGuild dynamically displays columns in the order defined by the user. That's why we need to set up a table containing column info.
-- Each key of the table is named by the internal column name and stores another table, which defines how the column will behave. Keys:
-- label: simply stores the displayed name of a column.
-- brush(v): the brush defines how content in a column-cell is displayed. v is Roster-data (see top of file)
-- canUse(v): this OPTIONAL function checks if a column can be displayed for the user. Returns 1 or nil.
-- script(anchor, v, button): defines the click handler of a column-cell. This is optional! v is Roster-data.
-- scriptOnEnter(anchor, v): defines an OnEnter handler of a column-cell. This is optional! v is Roster-data.
-- scriptOnLeave(anchor, v): defines an OnLeave handler. It must be defined in ordner to get OnEnter handlers work. v is Roster-data.
-- scriptUse(v): this OPTIONAL function will check if a script handler will be attached to the column-cell. v is Roster-data. Returns 1 or nil.
iGuild.Columns = {
level = {
label = _G.LEVEL,
brush = function(member)
-- encolor by difficulty
if( iGuild.db.Column.level.Color == 2 ) then
local c = _G.GetQuestDifficultyColor(member.level);
return ("|cff%02x%02x%02x%s|r"):format(c.r *255, c.g *255, c.b *255, member.level);
-- encolor by threshold
elseif( iGuild.db.Column.level.Color == 3 ) then
return ("|cff%s%s|r"):format(LibCrayon:GetThresholdHexColor(member.level, _G.MAX_PLAYER_LEVEL), member.level);
-- no color
else
return (COLOR_GOLD):format(member.level);
end
end,
},
name = {
label = _G.NAME,
brush = function(member)
local status = "";
if( member.status == 1 ) then
status = ("<%s>"):format(_G.AFK);
if( member.mobile ) then
status = Mobile_Away_Icon;
end
elseif( member.status == 2 ) then
status = ("<%s>"):format(_G.DND);
if( member.mobile ) then
status = Mobile_Busy_Icon;
end
elseif( member.mobile ) then
status = Mobile_Icon;
end
-- encolor by class color
if( iGuild.db.Column.name.Color == 2 ) then
return ("|c%s%s|r"):format(_G.RAID_CLASS_COLORS[member.CLASS].colorStr, status..member.name);
-- no color
else
return (COLOR_GOLD):format(status..member.name);
end
end,
},
zone = {
label = _G.ZONE,
brush = function(member)
-- encolor by hostility
local r, g, b = LibTourist:GetFactionColor(member.zone);
return ("|cff%02x%02x%02x%s|r"):format(r *255, g *255, b *255, member.zone);
end,
},
rank = {
label = _G.RANK,
brush = function(member)
-- encolor by threshold
if( iGuild.db.Column.rank.Color == 2 ) then
local max_rank = _G.GuildControlGetNumRanks();
return ("|cff%s%s|r"):format(LibCrayon:GetThresholdHexColor(max_rank - member.grank, max_rank -1), _G.GuildControlGetRankName(member.grank));
-- no color
else
return (COLOR_GOLD):format(_G.GuildControlGetRankName(member.grank));
end
end,
script = function(_, member, button)
-- left clicks will promote, if we can promote
if( _G.IsAltKeyDown() and button == "LeftButton" and _G.CanGuildPromote() ) then
_G.GuildPromote(member.NAME);
end
-- right clicks will demote, if we can demote
if( _G.IsAltKeyDown() and button == "RightButton" and _G.CanGuildDemote() ) then
_G.GuildDemote(member.name);
end
end,
scriptOnEnter = function(anchor, member)
working_member = member;
local tip = iGuild:GetTooltip("Ranks", "UpdateRanksTooltip");
tip:SetPoint("TOPLEFT", anchor:GetParent(), "TOPRIGHT", 10, 10);
tip:Show();
end,
scriptOnLeave = function(anchor, member)
iGuild:GetTooltip("Ranks"):Release();
working_member = nil;
end,
scriptUse = function() return ( _G.CanGuildPromote() or _G.CanGuildDemote() ) end,
},
note = {
label = L["Note"],
brush = function(member)
return (COLOR_GOLD):format(member.note);
end,
},
officernote = {
label = L["OfficerNote"],
brush = function(member)
return (COLOR_OFFICER):format(member.onote);
end,
canUse = function() return _G.C_GuildInfo.CanViewOfficerNote() end,
},
notecombi = {
label = L["Note"].."*",
brush = function(member)
local normal, officer;
local note = "";
if( member.note ~= "" ) then
normal = 1;
end
if( _G.C_GuildInfo.CanViewOfficerNote() and member.onote ~= "" ) then
officer = 1;
end
if( normal and not officer ) then
note = (COLOR_GOLD):format(member.note);
elseif( officer and not normal ) then
note = (COLOR_OFFICER):format(member.onote);
elseif( normal and officer ) then
note = ("%s / %s"):format( (COLOR_GOLD):format(member.note), (COLOR_OFFICER):format(member.onote) );
end
return note;
end,
},
acmpoints = {
label = L["Points"],
brush = function(member)
local displayPoints = _G.BreakUpLargeNumbers(member.apoints);
-- encolor by threshold
if( iGuild.db.Column.acmpoints.Color == 2 ) then
return ("|cff%s%s|r"):format(LibCrayon:GetThresholdHexColor(member.apoints, MAX_ACMPOINTS), displayPoints);
-- no color
else
return (COLOR_GOLD):format(displayPoints);
end
end,
},
tradeskills = {
label = L["Tradeskills"],
brush = function(member)
local label = "";
for i = 1, 2 do
if( member["ts"..i] ) then
label = label..(i == 1 and "" or " ")..("|T%s:%d:%d|t"):format("Interface\\Addons\\iGuild\\Images\\TradeSkill\\"..member["ts"..i.."tex"], iconSize, iconSize);
if( iGuild.db.Column.tradeskills.ShowProgress ) then
if( iGuild.db.Column.tradeskills.Color == 2 ) then
label = ("%s|cff%s%s|r"):format(label, LibCrayon:GetThresholdHexColor(member["ts"..i.."prog"], MAX_PROFESSION_SKILL), member["ts"..i.."prog"]);
else
label = ("%s"..COLOR_GOLD):format(label, member["ts"..i.."prog"]);
end
end
end
end
return label;
end,
canUse = function() return iGuild.db.Column.tradeskills.Enable end,
script = function(_, member, button)
if( button == "LeftButton" and member.ts1 and _G.CanViewGuildRecipes(member.ts1id) ) then
_G.GetGuildMemberRecipes(member.NAME, member.ts1id);
elseif( button == "RightButton" and member.ts2 and _G.CanViewGuildRecipes(member.ts2id) ) then
_G.GetGuildMemberRecipes(member.NAME, member.ts2id);
end
end,
scriptUse = function(member) return ( member.ts1 and true or false ) end,
},
class = {
label = _G.CLASS,
brush = function(member)
if( iGuild.db.Column.class.Icon ) then
return "|TInterface\\Addons\\iGuild\\Images\\"..member.CLASS..":"..iconSize..":"..iconSize.."|t";
end
-- encolor by class color
if( iGuild.db.Column.class.Color == 2 ) then
return ("|c%s%s|r"):format(_G.RAID_CLASS_COLORS[member.CLASS].colorStr, member.class);
-- no color
else
return (COLOR_GOLD):format(member.class);
end
end,
},
grouped = {
label = _G.GROUP,
brush = function(member)
if( _G.UnitInParty(member.name) or _G.UnitInRaid(member.name) ) then
return "|TInterface\\RAIDFRAME\\ReadyCheck-Ready:"..iconSize..":"..iconSize.."|t";
else
return "";
end
end,
canUse = function()
return (_G.GetNumGroupMembers() ~= 0 or _G.GetNumSubgroupMembers() ~= 0);
end,
}
};
----------------------------
-- UpdateRanksTooltip
----------------------------
function iGuild:UpdateRanksTooltip(tip)
tip:Clear();
tip:SetColumnLayout(1, "LEFT");
local rankNum = _G.GuildControlGetNumRanks();
for i = 1, rankNum do
tip:AddLine(
("|cff%s%s|r"):format(LibCrayon:GetThresholdHexColor(rankNum - i, rankNum - 1), _G.GuildControlGetRankName(i))
..( i == working_member.grank and " |TInterface\\RAIDFRAME\\ReadyCheck-Ready:"..iconSize..":"..iconSize.."|t" or "")
);
end
end