-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAltinatorFunctions.lua
More file actions
270 lines (245 loc) · 9.67 KB
/
AltinatorFunctions.lua
File metadata and controls
270 lines (245 loc) · 9.67 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
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
local AddonName, AltinatorNS = ...
local C = AltinatorNS.C
local L = LibStub("AceLocale-3.0"):GetLocale(AddonName)
function AltinatorNS:GetRealmCharactersSorted()
local characterNames = {}
local realm = GetNormalizedRealmName()
for key, char in pairs(self.AltinatorDB.global.characters) do
if char.Realm == realm and not self.AltinatorDB.global.hiddenCharacters[key] then
table.insert(characterNames, key)
end
end
table.sort(characterNames)
return characterNames
end
function AltinatorNS:GetCharacterIcons(char)
local faction = "h"
local factionIcon = "inv_bannerpvp_01"
local showRank = false
if(char.Faction == "Alliance") then
faction = "a"
factionIcon = "inv_bannerpvp_02"
end
if(char.Rank and char.Rank.Value>=5) then
factionIcon = "achievement_pvp_" .. faction .. "_"..string.format("%02d", char.Rank.Value-4)
showRank = true
end
factionIcon = "Interface\\ICONS\\" .. factionIcon
local raceIcon = "Interface\\ICONS\\Achievement_character_" .. char.Race.File .. "_" .. C["Genders"][char.Sex]
local classIcon = "Interface\\ICONS\\classicon_" .. char.Class.File
return factionIcon, raceIcon, classIcon, showRank
end
function AltinatorNS:MoneyToGoldString(money)
local copper = (("%02d"):format(money % 100))
local silver = (("%02d"):format((money / 100) % 100))
local gold = (("%02d"):format(money / 100 / 100))
local ccoin = "|TInterface\\MoneyFrame\\UI-CopperIcon:0:0:2:0|t "
local scoin = "|TInterface\\MoneyFrame\\UI-SilverIcon:0:0:2:0|t "
local gcoin = "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t "
return (gold..gcoin..silver..scoin..copper..ccoin)
end
function AltinatorNS:SplitString(str, delim, maxNb)
if string.find(str, delim) == nil then
return { str }
end
if maxNb == nil or maxNb < 1 then
maxNb = 0 -- No limit
end
local result = {}
local pat = "(.-)" .. delim .. "()"
local nb = 0
local lastPos
for part, pos in string.gmatch(str, pat) do
nb = nb + 1
result[nb] = part
lastPos = pos
if nb == maxNb then
break
end
end
-- Handle the last field
if nb ~= maxNb then
result[nb + 1] = string.sub(str, lastPos)
end
return result
end
function AltinatorNS:MergeObjects(mergeInto, mergeFrom)
for k, v in pairs(mergeFrom) do
if (type(v) == "table") and (type(mergeInto[k] or false) == "table") then
self:MergeObjects(mergeInto[k], mergeFrom[k])
else
mergeInto[k] = v
end
end
return mergeInto
end
function AltinatorNS:ShortTimeSpanToString(span)
local days = math.floor(span / 86400)
span = span - (days * 86400)
local hours = math.floor(span / 3600)
span = span - (hours * 3600)
local minutes = math.floor(span / 60)
span = span - (minutes * 60)
local seconds = span
if days>0 then
if days == 1 then
return days .. " " .. L["Day"]
else
return days .. " " .. L["Days"]
end
end
if hours>0 then
if hours == 1 then
return hours .. " " .. L["Hour"]
else
return hours .. " " .. L["Hours"]
end
end
if minutes>0 then
if minutes == 1 then
return minutes .. " " .. L["Minute"]
else
return minutes .. " " .. L["Minutes"]
end
end
if seconds>0 then
if seconds == 1 then
return seconds .. " " .. L["Second"]
else
return seconds .. " " .. L["Seconds"]
end
end
return ""
end
function AltinatorNS:LongTimeSpanToString(span)
local days = math.floor(span / 86400)
span = span - (days * 86400)
local hours = math.floor(span / 3600)
span = span - (hours * 3600)
local minutes = math.floor(span / 60)
span = span - (minutes * 60)
local seconds = span
local timeString = ""
if days>0 then
timeString = timeString .. days .. "\124cnADVENTURES_COMBAT_LOG_YELLOW:" .. L["DaysShort"] .. "\124r "
end
if hours>0 then
timeString = timeString .. hours .. "\124cnADVENTURES_COMBAT_LOG_YELLOW:" .. L["HoursShort"] .. "\124r "
end
if minutes>0 then
timeString = timeString .. minutes .. "\124cnADVENTURES_COMBAT_LOG_YELLOW:" .. L["MinutesShort"] .. "\124r "
end
return timeString
end
function AltinatorNS:GetLastReset()
local reset = C["ResetTimes"][GetCurrentRegion()]
local weekday = C_DateAndTime.GetCurrentCalendarTime().weekday
local today = time()
local daysBack = (weekday + 7 - reset.day) % 7
local lastReset = today - (daysBack * 86400)
local resetHour = reset.hour
local lastResetDate = date("*t", lastReset)
lastResetDate.hour = resetHour
lastResetDate.min = 0
lastResetDate.sec = 0
lastReset = time(lastResetDate)
if lastReset > today then
lastReset = lastReset - (7 * 86400)
end
return lastReset
end
function AltinatorNS:CreateInnerBorder(frame, itemQuality)
local iborder = frame.iborder or CreateFrame("Frame", nil, frame, "BackdropTemplate")
frame.iborder = iborder
frame.iborder:SetPoint("TOPLEFT", 1, -1)
frame.iborder:SetPoint("BOTTOMRIGHT", -1, 1)
frame.iborder:SetFrameLevel(frame:GetFrameLevel())
frame.iborder:SetBackdrop({
edgeFile = "Interface\\Buttons\\WHITE8x8", edgeSize = 1,
insets = { left = -1, right = -1, top = -1, bottom = -1}
})
local r, g, b, alpha = 0, 0, 0, 0
if itemQuality > -1 then
r, g, b, _ = C_Item.GetItemQualityColor(itemQuality)
alpha = 1
end
frame.iborder:SetBackdropBorderColor(r, g, b, alpha)
return frame.iborder
end
function AltinatorNS:CreateCharacterName(contentFrame, charIndex, char, anchor, OffsetX, baseOffsetY, iconSize)
contentFrame.FactionIcons[charIndex] = contentFrame.FactionIcons[charIndex] or contentFrame:CreateTexture("Faction_Icon_" .. charIndex, "BACKGROUND")
contentFrame.FactionIcons[charIndex]:SetSize(iconSize, iconSize)
contentFrame.FactionIcons[charIndex]:SetPoint("TOPLEFT", anchor, "TOPLEFT", OffsetX, baseOffsetY * -1 * (charIndex-1))
local factionIcon, raceIcon, classIcon, showRank = AltinatorNS:GetCharacterIcons(char)
if showRank then
contentFrame.FactionIcons[charIndex]:SetScript("OnEnter", function(self)
AltinatorNS.AltinatorTooltip:SetOwner(contentFrame, "ANCHOR_CURSOR")
AltinatorNS.AltinatorTooltip:SetText(char.Rank.Name)
end)
contentFrame.FactionIcons[charIndex]:SetScript("OnLeave", function(self)
AltinatorNS.AltinatorTooltip:Hide()
end)
else
contentFrame.FactionIcons[charIndex]:SetScript("OnEnter", nil)
contentFrame.FactionIcons[charIndex]:SetScript("OnLeave", nil)
end
contentFrame.FactionIcons[charIndex]:SetTexture(factionIcon)
contentFrame.RaceIcons[charIndex] = contentFrame.RaceIcons[charIndex] or contentFrame:CreateTexture("Race_Icon_" .. charIndex, "BACKGROUND")
contentFrame.RaceIcons[charIndex]:SetSize(iconSize, iconSize)
contentFrame.RaceIcons[charIndex]:SetPoint("LEFT", contentFrame.FactionIcons[charIndex], "LEFT", 15, 0)
contentFrame.RaceIcons[charIndex]:SetTexture(raceIcon)
contentFrame.ClassIcons[charIndex] = contentFrame.ClassIcons[charIndex] or contentFrame:CreateTexture("Class_Icon_" .. charIndex, "BACKGROUND")
contentFrame.ClassIcons[charIndex]:SetSize(iconSize, iconSize)
contentFrame.ClassIcons[charIndex]:SetPoint("LEFT", contentFrame.RaceIcons[charIndex], "LEFT", 15, 0)
contentFrame.ClassIcons[charIndex]:SetTexture(classIcon)
contentFrame.CharNames[charIndex] = contentFrame.CharNames[charIndex] or contentFrame:CreateFontString(nil,"ARTWORK","GameFontHighlight")
contentFrame.CharNames[charIndex]:SetPoint("LEFT", contentFrame.ClassIcons[charIndex], "LEFT", 20, 0)
contentFrame.CharNames[charIndex]:SetText(char.Name)
local cr, cg, cb, web = GetClassColor(char.Class.File)
contentFrame.CharNames[charIndex]:SetTextColor(cr, cg, cb)
end
function AltinatorNS:CreateScrollFrame(parent, topX, topY, bottomX, bottomY)
if not topX then topX = 0 end
if not topY then topY = -32 end
if not bottomX then bottomX = -22 end
if not bottomY then bottomY = 0 end
parent.ScrollFrame = parent.ScrollFrame or CreateFrame("ScrollFrame", nil, parent, "UIPanelScrollFrameTemplate")
parent.ScrollFrame:SetPoint("TOPLEFT", parent, "TOPLEFT", topX, topY)
parent.ScrollFrame:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", bottomX, bottomY)
parent.ScrollFrame:SetScript("OnMouseWheel", function(self, delta)
AltinatorNS:ScrollFrame_OnMouseWheel(self, delta)
end)
parent.ScrollFrame:EnableMouse(true)
parent.ScrollFrame.content = parent.ScrollFrame.content or CreateFrame("Frame", nil, parent.ScrollFrame)
parent.ScrollFrame.content:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, 0)
parent.ScrollFrame.content:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", 0, 0)
parent.ScrollFrame:SetScrollChild(parent.ScrollFrame.content);
return parent.ScrollFrame
end
function AltinatorNS:ScrollFrame_OnMouseWheel(self, delta)
local newValue = self:GetVerticalScroll() - (delta * 20)
if (newValue < 0) then
newValue = 0
elseif (newValue > self:GetVerticalScrollRange()) then
newValue = self:GetVerticalScrollRange()
end
self:SetVerticalScroll(newValue)
end
function AltinatorNS:ItemOnClick(item)
if IsShiftKeyDown() and ChatFrame1EditBox and ChatFrame1EditBox:IsVisible() then
ChatFrame1EditBox:Insert(item.TooltipItemLink)
end
if IsControlKeyDown() then
DressUpItemLink(item.TooltipItemLink)
end
end
function AltinatorNS:ItemOnEnter(item)
AltinatorNS.AltinatorTooltip:SetOwner(item, "ANCHOR_BOTTOMRIGHT")
AltinatorNS.AltinatorTooltip:SetHyperlink(item.TooltipItemLink)
if IsShiftKeyDown() then
GameTooltip_ShowCompareItem(AltinatorNS.AltinatorTooltip)
end
end
function AltinatorNS:ItemOnLeave(item)
AltinatorNS.AltinatorTooltip:Hide()
end