forked from ArtOfShred/LuiExtended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.lua
173 lines (155 loc) · 5.82 KB
/
Functions.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
--[[
LuiExtended
License: The MIT License (MIT)
--]]
local strfmt = string.format
-- Called from the menu and on initialization to update timestamp color when changed.
local TimeStampColorize
function LUIE.UpdateTimeStampColor()
TimeStampColorize = ZO_ColorDef:New(unpack(LUIE.ChatAnnouncements.SV.TimeStampColor)):ToHex()
end
-- Return a formatted time
-- Stolen from pChat, thanks @Ayantir
-- TODO: use ZOS functions instead
function LUIE.CreateTimestamp(timeStr, formatStr)
local formatStr = formatStr or LUIE.ChatAnnouncements.SV.TimeStampFormat
-- Split up default timestamp
local hours, minutes, seconds = timeStr:match("([^%:]+):([^%:]+):([^%:]+)")
local hoursNoLead = tonumber(hours) -- Hours without leading zero
local hours12NoLead = (hoursNoLead - 1)%12 + 1
local hours12
if (hours12NoLead < 10) then
hours12 = "0" .. hours12NoLead
else
hours12 = hours12NoLead
end
local pUp = "AM"
local pLow = "am"
if (hoursNoLead >= 12) then
pUp = "PM"
pLow = "pm"
end
-- Create new one
local timestamp = formatStr
timestamp = timestamp:gsub("HH", hours)
timestamp = timestamp:gsub("H", hoursNoLead)
timestamp = timestamp:gsub("hh", hours12)
timestamp = timestamp:gsub("h", hours12NoLead)
timestamp = timestamp:gsub("m", minutes)
timestamp = timestamp:gsub("s", seconds)
timestamp = timestamp:gsub("A", pUp)
timestamp = timestamp:gsub("a", pLow)
return timestamp
end
-- FormatMessage helper function
local function FormatMessage(msg, doTimestamp)
local msg = msg or ""
if doTimestamp then
local timestring = GetTimeString()
-- Color Code to match pChat default
msg = strfmt("|c%s[%s]|r %s", TimeStampColorize, LUIE.CreateTimestamp(timestring), msg)
end
return msg
end
-- Easy Print to Chat
function LUIE.PrintToChat(msg, isSystem)
if LUIE.ChatAnnouncements.SV.ChatMethod == "Print to All Tabs" then
if not LUIE.ChatAnnouncements.SV.ChatBypass and CHAT_SYSTEM.primaryContainer then
local msg = FormatMessage(msg or "no message", LUIE.ChatAnnouncements.SV.TimeStamp)
-- Add timestamps if bypass is not enabled
CHAT_SYSTEM.primaryContainer:OnChatEvent(nil, msg, CHAT_CATEGORY_SYSTEM)
else
-- Otherwise send as a normal message and let other addons handle this.
CHAT_SYSTEM:AddMessage(msg)
end
else
-- If we have system messages sent to display in all windows then just print to all windows at once, otherwise send messages to individual tabs.
if CHAT_SYSTEM.primaryContainer then
if isSystem and LUIE.ChatAnnouncements.SV.ChatSystemAll then
local msg = FormatMessage(msg or "no message", LUIE.ChatAnnouncements.SV.TimeStamp)
-- Post as a System message so that it can appear in multiple tabs.
CHAT_SYSTEM.primaryContainer:OnChatEvent(nil, msg, CHAT_CATEGORY_SYSTEM)
else
local chatContainer = CHAT_SYSTEM.primaryContainer
for i = 1, #chatContainer.windows do
if LUIE.ChatAnnouncements.SV.ChatTab[i] == true then
local chatWindow = CHAT_SYSTEM.primaryContainer["windows"][i]
local msg = FormatMessage(msg or "no message", LUIE.ChatAnnouncements.SV.TimeStamp)
chatContainer:AddEventMessageToWindow(chatWindow, msg, CHAT_CATEGORY_SYSTEM)
end
end
end
end
end
end
-- Returns a formatted number with commas
-- Function no comma to be added in a later date.
function LUIE.AbbreviateNumber(number, shorten, comma)
if number > 0 and shorten then
local value
local suffix
if number >= 1000000000 then
value = number / 1000000000
suffix = "G"
elseif number >= 1000000 then
value = number / 1000000
suffix = "M"
elseif number >= 1000 then
value = number / 1000
suffix = "k"
else
value = number
end
-- If we could not conver even to "G", return full number
if value >= 1000 then
if comma then
value = ZO_LocalizeDecimalNumber(number)
return value
else
return number
end
elseif value >= 100 or suffix == nil then
value = strfmt("%d", value)
else
value = strfmt("%.1f", value)
end
if suffix ~= nil then
value = value .. suffix
end
return value
end
-- Add commas if needed
if comma then
local value = ZO_LocalizeDecimalNumber(number)
return value
end
return number
end
function LUIE.UpdateGuildData()
local GuildsIndex = GetNumGuilds()
LUIE.GuildIndexData = {}
for i = 1,GuildsIndex do
local id = GetGuildId(i)
local name = GetGuildName(id)
local guildAlliance = GetGuildAlliance(id)
LUIE.GuildIndexData[i] = {id=id, name=name, guildAlliance=guildAlliance}
end
end
-- Simple function to check veteran difficult (VMA isn't considered being in a Veteran Dungeon so we have to do some filtering)
function LUIE.ResolveVeteranDifficulty()
if GetGroupSize() <= 1 and IsUnitUsingVeteranDifficulty('player') then
return true
elseif GetCurrentZoneDungeonDifficulty() == 2 or IsGroupUsingVeteranDifficulty() == true then
return true
else
return false
end
end
-- Simple function that checks for AvA / IC / BG Status and returns true if the player is in any of these
function LUIE.ResolvePVPZone()
if IsPlayerInAvAWorld() == true or IsActiveWorldBattleground() == true or IsInImperialCity() == true then
return true
else
return false
end
end