forked from anarior-nz/WorldQuestTab
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTemplates.lua
573 lines (491 loc) · 18 KB
/
Templates.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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
local addonName, addon = ...
local WQT = addon.WQT;
local _L = addon.L
local _V = addon.variables;
local ADD = LibStub("AddonDropDown-1.0");
local WQT_Utils = addon.WQT_Utils;
--------------------------------
-- WQT_ScrollFrameMixin
--------------------------------
WQT_ScrollFrameMixin = {};
function WQT_ScrollFrameMixin:OnLoad()
self.offset = 0;
self.scrollStep = 30;
self.max = 0;
self.ScrollBar:SetMinMaxValues(0, 0);
self.ScrollBar:SetValue(0);
self.ScrollChild:SetPoint("RIGHT", self)
end
function WQT_ScrollFrameMixin:OnShow()
self:SetChildHeight(self.ScrollChild:GetHeight());
end
function WQT_ScrollFrameMixin:UpdateChildFramePosition()
if (self.ScrollChild) then
self.ScrollChild:SetPoint("TOPLEFT", self, 0, self.offset);
end
end
function WQT_ScrollFrameMixin:ScrollValueChanged(value)
self.offset = max(0, min(value, self.max));
self:UpdateChildFramePosition();
end
function WQT_ScrollFrameMixin:OnMouseWheel(delta)
self.offset = self.offset - delta * self.scrollStep;
self.offset = max(0, min(self.offset, self.max));
self:UpdateChildFramePosition();
self.ScrollBar:SetValue(self.offset);
end
function WQT_ScrollFrameMixin:SetChildHeight(height)
self.ScrollChild:SetHeight(height);
self.max = max(0, height - self:GetHeight());
self.offset = min(self.offset, self.max);
self.ScrollBar:SetMinMaxValues(0, self.max);
end
----------------------------
-- Containers
----------------------------
WQT_ContainerButtonMixin = {};
function WQT_ContainerButtonMixin:OnClick()
self:SetSelected(not self.isSelected);
end
function WQT_ContainerButtonMixin:SetSelected(isSelected)
self.isSelected = isSelected;
if (self.container) then
if (self.isSelected) then
self.container:Show();
self.Selected:SetAlpha(0.5);
WQT_WorldQuestFrame:SelectTab(WQT_TabWorld);
else
self.container:Hide();
self.Selected:SetAlpha(0);
WQT_WorldQuestFrame:SelectTab(WQT_TabNormal);
end
end
end
function WQT_ContainerButtonMixin:OnEnter()
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:SetText(TRACKER_HEADER_WORLD_QUESTS, 1, 1, 1, true);
GameTooltip:Show();
end
function WQT_ContainerButtonMixin:OnLeave()
GameTooltip:Hide();
end
----------------------------
-- Utilities
----------------------------
local FORMAT_VERSION_MINOR = "%s|cFF888888.%s|r"
local FORMAT_H1 = "%s<h1 align='center'>%s</h1>";
local FORMAT_H2 = "%s<h2>%s:</h2>";
local FORMAT_p = "%s<p>%s</p>";
local FORMAT_WHITESPACE = "%s<h3> </h3>"
local function AddNotes(updateMessage, title, notes)
if (not notes) then return updateMessage; end
if (title) then
updateMessage = FORMAT_H2:format(updateMessage, title);
end
for k, note in ipairs(notes) do
updateMessage = FORMAT_p:format(updateMessage, note);
updateMessage = FORMAT_WHITESPACE:format(updateMessage);
end
updateMessage = FORMAT_WHITESPACE:format(updateMessage);
return updateMessage;
end
local cachedTypeData = {};
local cachedZoneInfo = {};
function WQT_Utils:GetSetting(...)
local settings = WQT.settings;
local index = 1;
local param = select(index, ...);
while (param ~= nil) do
if(settings[param] == nil) then
return nil
end;
settings = settings[param];
index = index + 1;
param = select(index, ...);
end
if (type(settings) == "table") then
return nil
end;
return settings;
end
function WQT_Utils:GetCachedMapInfo(zoneId)
zoneId = zoneId or 0;
local zoneInfo = cachedZoneInfo[zoneId];
if (not zoneInfo) then
zoneInfo = C_Map.GetMapInfo(zoneId);
if (zoneInfo and zoneInfo.name) then
cachedZoneInfo[zoneId] = zoneInfo;
end
end
return zoneInfo;
end
function WQT_Utils:GetFactionDataInternal(id)
if (not id) then
-- No faction
return _V["WQT_NO_FACTION_DATA"];
end;
local factionData = _V["WQT_FACTION_DATA"];
if (not factionData[id]) then
-- Add new faction in case it's not in our data yet
factionData[id] = { ["expansion"] = 0 ,["faction"] = nil ,["icon"] = 134400, ["unknown"] = true } -- Questionmark icon
factionData[id].name = GetFactionInfoByID(id) or "Unknown Faction";
WQT:debugPrint("Added new faction", id,factionData[id].name);
end
return factionData[id];
end
function WQT_Utils:GetCachedTypeIconData(questInfo)
local _, _, questType, _, _, tradeskillLineIndex = GetQuestTagInfo(questInfo.questId);
if (questInfo.isDaily) then
return "QuestDaily", 17, 17, true;
elseif (questInfo.isQuestStart) then
return "QuestNormal", 17, 17, true;
elseif (C_QuestLog.IsThreatQuest(questInfo.questId)) then
return "worldquest-icon-nzoth", 14, 14, true;
elseif (not questType) then
return "QuestBonusObjective", 21, 21, true;
end
local isNew = false;
local originalType = questType;
questType = questType or _V["WQT_TYPE_BONUSOBJECTIVE"];
if (not cachedTypeData[questType]) then
cachedTypeData[questType] = {};
isNew = true;
end
if (tradeskillLineIndex and not cachedTypeData[questType][tradeskillLineIndex]) then
cachedTypeData[questType][tradeskillLineIndex] = {};
isNew = true;
end
if (isNew) then
local atlasTexture, sizeX, sizeY = QuestUtil.GetWorldQuestAtlasInfo(originalType, false, tradeskillLineIndex);
if (tradeskillLineIndex) then
cachedTypeData[questType][tradeskillLineIndex] = {["texture"] = atlasTexture, ["x"] = sizeX, ["y"] = sizeY};
else
cachedTypeData[questType] = {["texture"] = atlasTexture, ["x"] = sizeX, ["y"] = sizeY};
end
end
if (tradeskillLineIndex) then
local data = cachedTypeData[questType][tradeskillLineIndex];
return data.texture, data.x, data.y;
end
local data = cachedTypeData[questType];
return data.texture, data.x, data.y;
end
function WQT_Utils:GetQuestTimeString(questInfo, fullString, unabreviated)
local timeLeftMinutes = 0
local timeLeftSeconds = 0
local timeString = "";
local timeStringShort = "";
local color = _V["WQT_COLOR_CURRENCY"];
local category = _V["TIME_REMAINING_CATEGORY"].none;
if (not questInfo or not questInfo.questId) then return timeLeftSeconds, timeString, color ,timeStringShort, timeLeftMinutes, category end
-- Time ran out, waiting for an update
if (self:QuestIsExpired(questInfo)) then
timeString = RAID_INSTANCE_EXPIRES_EXPIRED;
timeStringShort = "Exp."
color = GRAY_FONT_COLOR;
return 0, timeString, color,timeStringShort , 0, _V["TIME_REMAINING_CATEGORY"].expired;
end
timeLeftMinutes = C_TaskQuest.GetQuestTimeLeftMinutes(questInfo.questId) or 0;
timeLeftSeconds = C_TaskQuest.GetQuestTimeLeftSeconds(questInfo.questId) or 0;
if ( timeLeftSeconds and timeLeftSeconds > 0) then
local displayTime = timeLeftSeconds
if (displayTime < SECONDS_PER_HOUR and displayTime >= SECONDS_PER_MIN ) then
displayTime = displayTime + SECONDS_PER_MIN ;
end
if ( timeLeftSeconds < WORLD_QUESTS_TIME_CRITICAL_MINUTES * SECONDS_PER_MIN ) then
color = RED_FONT_COLOR;
timeString = SecondsToTime(displayTime, displayTime > SECONDS_PER_MIN and true or false, unabreviated);
category = _V["TIME_REMAINING_CATEGORY"].critical;
elseif displayTime < SECONDS_PER_HOUR then
timeString = SecondsToTime(displayTime, true);
color = _V["WQT_ORANGE_FONT_COLOR"];
category = _V["TIME_REMAINING_CATEGORY"].short
elseif displayTime < SECONDS_PER_DAY then
if (fullString) then
timeString = SecondsToTime(displayTime, true, unabreviated);
else
timeString = D_HOURS:format(displayTime / SECONDS_PER_HOUR);
end
color = _V["WQT_GREEN_FONT_COLOR"];
category = _V["TIME_REMAINING_CATEGORY"].medium;
else
if (fullString) then
timeString = SecondsToTime(displayTime, true, unabreviated);
else
timeString = D_DAYS:format(displayTime / SECONDS_PER_DAY );
end
local _, _, _, rarity, isElite = GetQuestTagInfo(questInfo.questId);
local isWeek = isElite and rarity == LE_WORLD_QUEST_QUALITY_EPIC
color = isWeek and _V["WQT_PURPLE_FONT_COLOR"] or _V["WQT_BLUE_FONT_COLOR"];
category = isWeek and _V["TIME_REMAINING_CATEGORY"].veryLong or _V["TIME_REMAINING_CATEGORY"].long;
end
end
-- start with default, for CN and KR
timeStringShort = timeString;
local t, str = string.match(timeString:gsub(" |4", ""), '(%d+)(%a)');
if t and str then
timeStringShort = t..str;
end
return timeLeftSeconds, timeString, color, timeStringShort ,timeLeftMinutes, category;
end
function WQT_Utils:GetPinTime(questInfo)
local seconds, _, color, timeStringShort, _, category = WQT_Utils:GetQuestTimeString(questInfo);
local start = 0;
local timeLeft = seconds;
local total = 0;
local maxTime, offset;
if (timeLeft > 0) then
if timeLeft >= 1440*60 then
maxTime = 5760*60;
offset = -720*60;
local _, _, _, rarity, isElite = GetQuestTagInfo(questInfo.questId);
if (timeLeft > maxTime or (isElite and rarity == LE_WORLD_QUEST_QUALITY_EPIC)) then
maxTime = 1440 * 7*60;
offset = 0;
end
elseif timeLeft >= 60*59 then --Minute display doesn't start until 59min left
maxTime = 1440*60;
offset = 60*60;
elseif timeLeft >= 15*60 then
maxTime= 60*60;
offset = -10*60;
else
maxTime = 15*60;
offset = 0;
end
start = (maxTime - timeLeft);
total = (maxTime + offset);
timeLeft = (timeLeft + offset);
end
return start, total, timeLeft, seconds, color, timeStringShort, category;
end
function WQT_Utils:QuestIsExpired(questInfo)
local timeLeftSeconds = C_TaskQuest.GetQuestTimeLeftSeconds(questInfo.questId) or 0;
return questInfo.time.seconds and questInfo.time.seconds > 0 and timeLeftSeconds < 1;
end
function WQT_Utils:GetMapInfoForQuest(questId)
local zoneId = C_TaskQuest.GetQuestZoneID(questId);
return WQT_Utils:GetCachedMapInfo(zoneId);
end
function WQT_Utils:ItterateAllBonusObjectivePins(func)
if(WorldMapFrame.pinPools.BonusObjectivePinTemplate) then
for mapPin in pairs(WorldMapFrame.pinPools.BonusObjectivePinTemplate.activeObjects) do
func(mapPin)
end
end
if(WorldMapFrame.pinPools.ThreatObjectivePinTemplate) then
for mapPin in pairs(WorldMapFrame.pinPools.ThreatObjectivePinTemplate.activeObjects) do
func(mapPin)
end
end
end
function WQT_Utils:ShowQuestTooltip(button, questInfo)
GameTooltip:SetOwner(button, "ANCHOR_RIGHT");
-- In case we somehow don't have data on this quest, even through that makes no sense at this point
if (not questInfo.questId or not HaveQuestData(questInfo.questId)) then
GameTooltip:SetText(RETRIEVING_DATA, RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
GameTooltip.recalculatePadding = true;
-- Add debug lines
WQT:AddDebugToTooltip(GameTooltip, questInfo);
GameTooltip:Show();
return;
end
local title, factionID, capped = C_TaskQuest.GetQuestInfoByQuestID(questInfo.questId);
local _, _, _, rarity = GetQuestTagInfo(questInfo.questId);
local qualityColor = WORLD_QUEST_QUALITY_COLORS[rarity or 1];
GameTooltip:SetText(title, qualityColor.r, qualityColor.g, qualityColor.b, 1, true);
if ( factionID ) then
local factionName = GetFactionInfoByID(factionID);
if ( factionName ) then
if (capped) then
GameTooltip:AddLine(factionName, GRAY_FONT_COLOR:GetRGB());
else
GameTooltip:AddLine(factionName);
end
end
end
-- Add time
local seconds, timeString, timeColor, _, _, category = WQT_Utils:GetQuestTimeString(questInfo, true, true)
if (seconds > 0 or category == _V["TIME_REMAINING_CATEGORY"].expired) then
timeColor = seconds <= SECONDS_PER_HOUR and timeColor or NORMAL_FONT_COLOR;
GameTooltip:AddLine(BONUS_OBJECTIVE_TIME_LEFT:format(timeString), timeColor.r, timeColor.g, timeColor.b);
end
local numObjectives = C_QuestLog.GetNumQuestObjectives(questInfo.questId);
for objectiveIndex = 1, numObjectives do
local objectiveText, _, finished = GetQuestObjectiveInfo(questInfo.questId, objectiveIndex, false);
if ( objectiveText and #objectiveText > 0 ) then
local objectiveColor = finished and GRAY_FONT_COLOR or HIGHLIGHT_FONT_COLOR;
GameTooltip:AddLine(QUEST_DASH .. objectiveText, objectiveColor.r, objectiveColor.g, objectiveColor.b, true);
end
end
local percent = C_TaskQuest.GetQuestProgressBarInfo(questInfo.questId);
if ( percent ) then
GameTooltip_ShowProgressBar(GameTooltip, 0, 100, percent, PERCENTAGE_STRING:format(percent));
end
if (questInfo.reward.type == WQT_REWARDTYPE.missing) then
GameTooltip:AddLine(RETRIEVING_DATA, RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
else
GameTooltip_AddQuestRewardsToTooltip(GameTooltip, questInfo.questId);
-- reposition compare frame
if((questInfo.reward.type == WQT_REWARDTYPE.equipment or questInfo.reward.type == WQT_REWARDTYPE.weapon) and GameTooltip.ItemTooltip:IsShown()) then
if IsModifiedClick("COMPAREITEMS") or C_CVar.GetCVarBool("alwaysCompareItems") then
-- Setup compare tootltips
GameTooltip_ShowCompareItem(GameTooltip.ItemTooltip.Tooltip);
-- If there is room to the right, give priority to show compare tooltips to the right of the tooltip
local totalWidth = 0;
if ( ShoppingTooltip1:IsShown() ) then
totalWidth = totalWidth + ShoppingTooltip1:GetWidth();
end
if ( ShoppingTooltip2:IsShown() ) then
totalWidth = totalWidth + ShoppingTooltip2:GetWidth();
end
if GameTooltip.ItemTooltip.Tooltip:GetRight() + totalWidth < GetScreenWidth() and ShoppingTooltip1:IsShown() then
ShoppingTooltip1:ClearAllPoints();
ShoppingTooltip1:SetPoint("TOPLEFT", GameTooltip.ItemTooltip.Tooltip, "TOPRIGHT");
ShoppingTooltip2:ClearAllPoints();
ShoppingTooltip2:SetPoint("TOPLEFT", ShoppingTooltip1, "TOPRIGHT");
end
-- Set higher frame level in case things overlap
local level = GameTooltip:GetFrameLevel();
ShoppingTooltip1:SetFrameLevel(level +2);
ShoppingTooltip2:SetFrameLevel(level +1);
end
end
end
WQT:AddDebugToTooltip(GameTooltip, questInfo);
GameTooltip:Show();
GameTooltip.recalculatePadding = true;
end
-- Climb map parents until the first continent type map it can find.
function WQT_Utils:GetContinentForMap(mapId)
local info = WQT_Utils:GetCachedMapInfo(mapId);
if not info then return mapId; end
local parent = info.parentMapID;
if not parent or info.mapType <= Enum.UIMapType.Continent then
return mapId, info.mapType
end
return self:GetContinentForMap(parent)
end
function WQT_Utils:GetMapWQProvider()
if WQT.mapWQProvider then return WQT.mapWQProvider; end
for k in pairs(WorldMapFrame.dataProviders) do
for k1 in pairs(k) do
if k1=="IsMatchingWorldMapFilters" then
WQT.mapWQProvider = k;
break;
end
end
end
return WQT.mapWQProvider;
end
function WQT_Utils:GetFlightWQProvider()
if (WQT.FlightmapPins) then return WQT.FlightmapPins; end
if (not FlightMapFrame) then return nil; end
for k in pairs(FlightMapFrame.dataProviders) do
if (type(k) == "table") then
for k2 in pairs(k) do
if (k2 == "activePins") then
WQT.FlightmapPins = k;
break;
end
end
end
end
return WQT.FlightmapPins;
end
function WQT_Utils:RefreshOfficialDataProviders()
-- Have to force remove the WQ data from the map because RefreshAllData doesn't do it
local mapWQProvider = WQT_Utils:GetMapWQProvider();
mapWQProvider:RemoveAllData();
WorldMapFrame:RefreshAllDataProviders();
-- Flight map world quests
local flightWQProvider = WQT_Utils:GetFlightWQProvider();
if (flightWQProvider) then
flightWQProvider:RemoveAllData();
flightWQProvider:RefreshAllData();
end
end
-- Compatibility with the TomTom add-on
function WQT_Utils:AddTomTomArrowByQuestId(questId)
if (not questId) then return; end
local zoneId = C_TaskQuest.GetQuestZoneID(questId);
if (zoneId) then
local title = C_TaskQuest.GetQuestInfoByQuestID(questId);
local x, y = C_TaskQuest.GetQuestLocation(questId, zoneId)
if (title and x and y) then
TomTom:AddWaypoint(zoneId, x, y, {["title"] = title, ["crazy"] = true});
end
end
end
function WQT_Utils:RemoveTomTomArrowbyQuestId(questId)
if (not questId) then return; end
local zoneId = C_TaskQuest.GetQuestZoneID(questId);
if (zoneId) then
local title = C_TaskQuest.GetQuestInfoByQuestID(questId);
local x, y = C_TaskQuest.GetQuestLocation(questId, zoneId)
if (title and x and y) then
local key = TomTom:GetKeyArgs(zoneId, x, y, title);
local wp = TomTom.waypoints[zoneId] and TomTom.waypoints[zoneId][key];
if (wp) then
TomTom:RemoveWaypoint(wp);
end
end
end
end
function WQT_Utils:QuestCountsToCap(questLogIndex)
local title, _, _, isHeader, _, _, frequency, questID, _, _, _, _, isTask, isBounty, _, isHidden, _ = GetQuestLogTitle(questLogIndex);
if (isHeader or isTask or isBounty) then
return false, isHidden;
end
local tagID, tagName = GetQuestTagInfo(questID)
local counts = true;
if (tagID and _V["QUESTS_NOT_COUNTING"][tagID]) then
counts = false;
end
return counts, isHidden;
end
-- Count quests counting to the quest log cap and collect hidden ones that can't be abandoned
function WQT_Utils:GetQuestLogInfo(hiddenList)
local numEntries = GetNumQuestLogEntries();
local maxQuests = C_QuestLog.GetMaxNumQuestsCanAccept();
local questCount = 0;
if (hiddenList) then
wipe(hiddenList);
end
for questLogIndex = 1, numEntries do
local counts, isHidden = WQT_Utils:QuestCountsToCap(questLogIndex);
if (counts) then
questCount = questCount + 1;
-- hidden quest counting to the cap
if (isHidden and hiddenList) then
tinsert(hiddenList, questLogIndex);
end
end
end
local color = questCount >= maxQuests and RED_FONT_COLOR or (questCount >= maxQuests-2 and _V["WQT_ORANGE_FONT_COLOR"] or _V["WQT_WHITE_FONT_COLOR"]);
return questCount, maxQuests, color;
end
function WQT_Utils:DeepWipeTable(t)
for k, v in pairs(t) do
if (type(v) == "table") then
self:DeepWipeTable(v)
end
end
wipe(t);
t = nil;
end
function WQT_Utils:FormatPatchNotes(notes, title)
local updateMessage = "<html><body><h3> </h3>";
updateMessage = FORMAT_H1:format(updateMessage, title);
updateMessage = FORMAT_WHITESPACE:format(updateMessage);
for i=1, #notes do
local patch = notes[i];
local version = patch.minor and FORMAT_VERSION_MINOR:format(patch.version, patch.minor) or patch.version;
updateMessage = FORMAT_H1:format(updateMessage, version);
updateMessage = AddNotes(updateMessage, nil, patch.intro);
updateMessage = AddNotes(updateMessage, "New", patch.new);
updateMessage = AddNotes(updateMessage, "Changes", patch.changes);
updateMessage = AddNotes(updateMessage, "Fixes", patch.fixes);
end
return updateMessage .. "</body></html>";
end