-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathHelpers.lua
More file actions
150 lines (142 loc) · 6.43 KB
/
Copy pathHelpers.lua
File metadata and controls
150 lines (142 loc) · 6.43 KB
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
---@class WK_Addon
local addon = select(2, ...)
---@class WK_Helpers
local Helpers = {}
addon.Helpers = Helpers
local Constants = addon.Constants
local LibLiqUI = addon.libs.LiqUI
local TableFind = LibLiqUI.Utils.TableFind
---True if the value is a secret (WoW API); use before comparing/using API return values that may be secret.
---@param value any
---@return boolean
function Helpers:IsSecretValue(value)
if issecretvalue == nil then return false end
---@diagnostic disable-next-line: param-type-mismatch
return issecretvalue(value)
end
---@param characterA table
---@param characterB table
---@return number
function Helpers:CompareCharacterNameRealm(characterA, characterB)
local nameCompare = strcmputf8i(characterA.name or "", characterB.name or "")
if nameCompare ~= 0 then return nameCompare end
return strcmputf8i(characterA.realmName or "", characterB.realmName or "")
end
---Format a timestamp for table cells (e.g. "Jul 24 - 5:55 PM").
---@param timestamp number
---@return string
function Helpers:FormatTimestamp(timestamp)
if not timestamp or timestamp <= 0 then
return "-"
end
local dateTable = date("*t", timestamp)
local timeText = GameTime_GetFormattedTime(dateTable.hour, dateTable.min, true)
return format("%s %d - %s", date("%b", timestamp), dateTable.day, timeText)
end
---Print a debug message
---@param ... any
function Helpers:Debug(...)
if addon.debug then
addon.Core:Print(...)
end
end
--- Render requirement tooltip
---@param objectiveProgressRequirement WK_ObjectiveProgressRequirement
---@param character WK_Character
---@param skillLineVariantID number
---@param objectiveCategoryID WK_ObjectiveCategoryId
function Helpers:RenderRequirementTooltip(objectiveProgressRequirement, character, skillLineVariantID, objectiveCategoryID)
local leftText = "-"
local rightText = "-"
local leftColor = WHITE_FONT_COLOR
local rightColor = WHITE_FONT_COLOR
if objectiveProgressRequirement.requirement.type == "item" then
leftText = format("ItemID: %d", objectiveProgressRequirement.requirement.id)
rightText = format("%d / %d", 0, objectiveProgressRequirement.requirement.amount or 0)
local quantity = character.items and character.items[objectiveProgressRequirement.requirement.id] or 0
local item = addon.Data.cache.items[objectiveProgressRequirement.requirement.id]
local itemCached = item and item:IsItemDataCached()
local name = "Loading..."
local icon = 134400
if itemCached then
icon = item:GetItemIcon() or 134400
name = item:GetItemLink() or "Loading..."
end
leftText = format("%s %s", CreateSimpleTextureMarkup(icon, 13, 13), name)
rightText = format("%d / %d", quantity, objectiveProgressRequirement.requirement.amount or 0)
if quantity >= objectiveProgressRequirement.requirement.amount then
rightColor = GREEN_FONT_COLOR
else
rightColor = RED_FONT_COLOR
end
elseif objectiveProgressRequirement.requirement.type == "currency" then
leftText = format("CurrencyID: %d", objectiveProgressRequirement.requirement.id)
rightText = format("%d / %d", 0, objectiveProgressRequirement.requirement.amount or 0)
local name = "Loading..."
local quantity = 0
local icon = 134400
local characterCurrency = character.currencies and character.currencies[objectiveProgressRequirement.requirement.id] or nil
if characterCurrency then
if characterCurrency.name then
name = characterCurrency.name
end
if characterCurrency.quantity then
quantity = characterCurrency.quantity
end
if characterCurrency.iconFileID and characterCurrency.iconFileID > 0 then
icon = characterCurrency.iconFileID
end
leftText = format("%s %s", CreateSimpleTextureMarkup(icon, 13, 13), name)
rightText = format("%d / %d", quantity, objectiveProgressRequirement.requirement.amount or 0)
end
if quantity >= objectiveProgressRequirement.requirement.amount then
rightColor = GREEN_FONT_COLOR
else
rightColor = RED_FONT_COLOR
end
elseif objectiveProgressRequirement.requirement.type == "quest" then
leftText = format("QuestID: %d", objectiveProgressRequirement.requirement.quests[1] or "?")
rightText = CreateAtlasMarkup("common-icon-redx", 12, 12)
if objectiveProgressRequirement.requirement.name then
leftText = format("%s %s", objectiveProgressRequirement.requirement.name, objectiveCategoryID == Constants.objectiveCategory.CatchUp and "" or "(Quest)")
end
if objectiveProgressRequirement.isCompleted then
rightText = CreateAtlasMarkup("common-icon-checkmark", 12, 12)
end
elseif objectiveProgressRequirement.requirement.type == "renown" then
leftText = format("FactionID: %d", objectiveProgressRequirement.requirement.id)
rightText = format("%d / %d", 0, objectiveProgressRequirement.requirement.amount or 0)
local level = 0
local factionInfo = C_MajorFactions.GetMajorFactionData(objectiveProgressRequirement.requirement.id)
if factionInfo then
leftText = format("%s (Renown)", factionInfo.name)
rightText = format("%d / %d", 0, objectiveProgressRequirement.requirement.amount or 0)
end
if character.factions and character.factions[objectiveProgressRequirement.requirement.id] then
level = character.factions[objectiveProgressRequirement.requirement.id].level or 0
rightText = format("%d / %d", level, objectiveProgressRequirement.requirement.amount or 0)
end
if level >= objectiveProgressRequirement.requirement.amount then
rightColor = GREEN_FONT_COLOR
else
rightColor = RED_FONT_COLOR
end
elseif objectiveProgressRequirement.requirement.type == "skill" then
leftText = format("SkillID: %d", objectiveProgressRequirement.requirement.id)
rightText = format("%d / %d", 0, objectiveProgressRequirement.requirement.amount or 0)
local skillLevel = 0
local characterProfession = TableFind(character.professions, function(profession)
return profession.skillLineVariantID == skillLineVariantID
end)
if characterProfession then
skillLevel = characterProfession.skillLevel or 0
end
rightText = format("%d / %d", skillLevel, objectiveProgressRequirement.requirement.amount or 0)
if skillLevel >= objectiveProgressRequirement.requirement.amount then
rightColor = GREEN_FONT_COLOR
else
rightColor = RED_FONT_COLOR
end
end
GameTooltip:AddDoubleLine(leftColor:WrapTextInColorCode(leftText), rightColor:WrapTextInColorCode(rightText), 1, 1, 1, 1, 1, 1)
end