Init.lua 16.4 KB
Newer Older
Azilroka's avatar
Azilroka committed
1 2 3 4 5 6 7 8
local AddOnName = ...
local _G = _G
local LibStub = LibStub

local PA = LibStub('AceAddon-3.0'):NewAddon('ProjectAzilroka', 'AceEvent-3.0', 'AceTimer-3.0')

_G.ProjectAzilroka = PA

Azilroka's avatar
Azilroka committed
9 10 11 12 13 14 15 16
local select = select
local pairs = pairs
local sort = sort
local tinsert = tinsert
local print = print
local format = format
local strsplit = strsplit

Azilroka's avatar
Azilroka committed
17 18
local GetAddOnMetadata = GetAddOnMetadata
local GetAddOnEnableState = GetAddOnEnableState
Azilroka's avatar
Azilroka committed
19 20 21
local UnitName = UnitName
local UnitClass = UnitClass
local GetRealmName = GetRealmName
Azilroka's avatar
Azilroka committed
22
local UIParent = UIParent
Azilroka's avatar
Azilroka committed
23 24
local BNGetFriendInfo = BNGetFriendInfo
local BNGetGameAccountInfo = BNGetGameAccountInfo
Azilroka's avatar
Azilroka committed
25

Azilroka's avatar
Azilroka committed
26
-- Ace Libraries
Azilroka's avatar
Azilroka committed
27 28 29 30 31 32 33
PA.AC = LibStub('AceConfig-3.0')
PA.GUI = LibStub('AceGUI-3.0')
PA.ACR = LibStub('AceConfigRegistry-3.0')
PA.ACD = LibStub('AceConfigDialog-3.0')
PA.ACL = LibStub('AceLocale-3.0'):GetLocale(AddOnName, false)
PA.ADB = LibStub('AceDB-3.0')

Azilroka's avatar
Azilroka committed
34
-- Extra Libraries
Azilroka's avatar
Azilroka committed
35 36
PA.LSM = LibStub('LibSharedMedia-3.0')
PA.LDB = LibStub('LibDataBroker-1.1')
Azilroka's avatar
Azilroka committed
37
PA.LCG = LibStub("LibCustomGlow-1.0")
Azilroka's avatar
Azilroka committed
38
PA.LAB = LibStub('LibActionButton-1.0')
Azilroka's avatar
Azilroka committed
39
PA.ACH = LibStub('LibAceConfigHelper')
Azilroka's avatar
Azilroka committed
40 41

-- External Libraries
Azilroka's avatar
Azilroka committed
42
PA.Masque = LibStub("Masque", true)
Azilroka's avatar
Azilroka committed
43 44 45 46 47
PA.LCD = LibStub("LibClassicDurations", true)

if PA.LCD then
	PA.LCD:Register(AddOnName) 	-- Register LibClassicDurations
end
Azilroka's avatar
Azilroka committed
48 49 50 51 52 53 54 55 56

-- WoW Data
PA.MyClass = select(2, UnitClass('player'))
PA.MyName = UnitName('player')
PA.MyRace = select(2, UnitRace("player"))
PA.MyRealm = GetRealmName()
PA.Locale = GetLocale()
PA.Noop = function() end
PA.TexCoords = {.08, .92, .08, .92}
Azilroka's avatar
Azilroka committed
57

58
if _G.ElvUI then
59 60 61 62 63 64 65 66
	PA.TexCoords = {0, 1, 0, 1}
	local modifier = 0.04 * _G.ElvUI[1].db.general.cropIcon
	for i, v in ipairs(PA.TexCoords) do
		if i % 2 == 0 then
			PA.TexCoords[i] = v - modifier
		else
			PA.TexCoords[i] = v + modifier
		end
67 68
	end
end
Azilroka's avatar
Azilroka committed
69

Azilroka's avatar
Azilroka committed
70 71 72
PA.UIScale = UIParent:GetScale()
PA.MyFaction = UnitFactionGroup('player')

Azilroka's avatar
Azilroka committed
73 74
PA.Classic = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
PA.Retail = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
Azilroka's avatar
Azilroka committed
75

Azilroka's avatar
Azilroka committed
76 77
-- Pixel Perfect
PA.ScreenWidth, PA.ScreenHeight = GetPhysicalScreenSize()
Azilroka's avatar
Azilroka committed
78
PA.Multiple = 1
Azilroka's avatar
Azilroka committed
79
PA.Solid = PA.LSM:Fetch('background', 'Solid')
Azilroka's avatar
Azilroka committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

-- Project Data
function PA:IsAddOnEnabled(addon, character)
	if (type(character) == 'boolean' and character == true) then
		character = nil
	end
	return GetAddOnEnableState(character, addon) == 2
end

function PA:IsAddOnPartiallyEnabled(addon, character)
	if (type(character) == 'boolean' and character == true) then
		character = nil
	end
	return GetAddOnEnableState(character, addon) == 1
end

PA.Title = GetAddOnMetadata('ProjectAzilroka', 'Title')
PA.Version = GetAddOnMetadata('ProjectAzilroka', 'Version')
Azilroka's avatar
Azilroka committed
98
PA.Authors = GetAddOnMetadata('ProjectAzilroka', 'Author'):gsub(', ', '    ')
Azilroka's avatar
Azilroka committed
99

Azilroka's avatar
Azilroka committed
100
PA.AllPoints = { CENTER = 'CENTER', BOTTOM = 'BOTTOM', TOP = 'TOP', LEFT = 'LEFT', RIGHT = 'RIGHT', BOTTOMLEFT = 'BOTTOMLEFT', BOTTOMRIGHT = 'BOTTOMRIGHT', TOPLEFT = 'TOPLEFT', TOPRIGHT = 'TOPRIGHT' }
Azilroka's avatar
Azilroka committed
101 102 103

PA.ElvUI = PA:IsAddOnEnabled('ElvUI', PA.MyName)
PA.SLE = PA:IsAddOnEnabled('ElvUI_SLE', PA.MyName)
104
PA.NUI = PA:IsAddOnEnabled('ElvUI_NihilistUI', PA.MyName)
Azilroka's avatar
Azilroka committed
105 106 107 108
PA.Tukui = PA:IsAddOnEnabled('Tukui', PA.MyName)
PA.AzilUI = PA:IsAddOnEnabled('AzilUI', PA.MyName)
PA.AddOnSkins = PA:IsAddOnEnabled('AddOnSkins', PA.MyName)

109 110 111 112 113 114 115 116
-- Setup oUF for pbuf
local function GetoUF()
	local key = PA.ElvUI and "ElvUI" or PA.Tukui and "Tukui"
	if not key then return end
	return _G[_G.GetAddOnMetadata(key, 'X-oUF')]
end
PA.oUF = GetoUF()

Azilroka's avatar
Azilroka committed
117 118 119 120
PA.Classes = {}
for k, v in pairs(LOCALIZED_CLASS_NAMES_MALE) do PA.Classes[v] = k end
for k, v in pairs(LOCALIZED_CLASS_NAMES_FEMALE) do PA.Classes[v] = k end

Azilroka's avatar
Azilroka committed
121
function PA:ClassColorCode(class)
Azilroka's avatar
Azilroka committed
122
	local color = PA:GetClassColor(PA.Classes[class])
Azilroka's avatar
Azilroka committed
123 124 125 126 127 128 129 130 131 132
	return format('FF%02x%02x%02x', color.r * 255, color.g * 255, color.b * 255)
end

function PA:GetClassColor(class)
	return _G.CUSTOM_CLASS_COLORS and _G.CUSTOM_CLASS_COLORS[class] or _G.RAID_CLASS_COLORS[class] or { r = 1, g = 1, b = 1 }
end

local Color = PA:GetClassColor(PA.MyClass)
PA.ClassColor = { Color.r, Color.g, Color.b }

Azilroka's avatar
Azilroka committed
133 134 135
PA.ScanTooltip = CreateFrame('GameTooltip', 'PAScanTooltip', _G.UIParent, 'GameTooltipTemplate')
PA.ScanTooltip:SetOwner(_G.UIParent, "ANCHOR_NONE")

Azilroka's avatar
Azilroka committed
136 137 138 139 140
PA.PetBattleFrameHider = CreateFrame('Frame', 'PA_PetBattleFrameHider', UIParent, 'SecureHandlerStateTemplate')
PA.PetBattleFrameHider:SetAllPoints()
PA.PetBattleFrameHider:SetFrameStrata('LOW')
RegisterStateDriver(PA.PetBattleFrameHider, 'visibility', '[petbattle] hide; show')

Azilroka's avatar
stAM  
Azilroka committed
141 142 143 144 145 146 147 148 149 150 151 152 153
function PA:GetUIScale()
	local effectiveScale = _G.UIParent:GetEffectiveScale()
	local magic = effectiveScale

	local scale = max(.64, min(1.15, magic))

	if strlen(scale) > 6 then
		scale = tonumber(strsub(scale, 0, 6))
	end

	return magic/scale
end

Azilroka's avatar
Cleanup  
Azilroka committed
154 155 156 157
function PA:GetClassName(class)
	return PA.Classes[class]
end

Azilroka's avatar
Azilroka committed
158 159 160 161 162 163 164 165 166
function PA:Color(name)
	local color = '|cFF16C3F2%s|r'
	return (color):format(name)
end

function PA:Print(...)
	print(PA:Color(PA.Title..':'), ...)
end

Azilroka's avatar
Azilroka committed
167 168 169 170 171 172 173 174 175 176
function PA:ShortValue(value)
	if (value >= 1e6) then
		return gsub(format("%.1fm", value / 1e6), "%.?0+([km])$", "%1")
	elseif (value >= 1e3 or value <= -1e3) then
		return gsub(format("%.1fk", value / 1e3), "%.?0+([km])$", "%1")
	else
		return value
	end
end

Azilroka's avatar
Azilroka committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
function PA:RGBToHex(r, g, b, header, ending)
	r = r <= 1 and r >= 0 and r or 1
	g = g <= 1 and g >= 0 and g or 1
	b = b <= 1 and b >= 0 and b or 1
	return format('%s%02x%02x%02x%s', header or '|cff', r*255, g*255, b*255, ending or '')
end

function PA:HexToRGB(hex)
	local a, r, g, b = strmatch(hex, '^|?c?(%x%x)(%x%x)(%x%x)(%x?%x?)|?r?$')
	if not a then return 0, 0, 0, 0 end
	if b == '' then r, g, b, a = a, r, g, 'ff' end

	return tonumber(r, 16), tonumber(g, 16), tonumber(b, 16), tonumber(a, 16)
end

Azilroka's avatar
Azilroka committed
192 193 194 195 196 197 198 199 200
function PA:ConflictAddOn(AddOns)
	for AddOn in pairs(AddOns) do
		if PA:IsAddOnEnabled(AddOn, PA.MyName) then
			return true
		end
	end
	return false
end

Azilroka's avatar
1.58  
Azilroka committed
201 202 203 204 205 206
function PA:CountTable(T)
	local n = 0
	for _ in pairs(T) do n = n + 1 end
	return n
end

Azilroka's avatar
Azilroka committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220
function PA:PairsByKeys(t, f)
	local a = {}
	for n in pairs(t) do tinsert(a, n) end
	sort(a, f)
	local i = 0
	local iter = function()
		i = i + 1
		if a[i] == nil then return nil
			else return a[i], t[a[i]]
		end
	end
	return iter
end

221 222 223 224 225 226 227 228 229 230
function PA:AddKeysToTable(current, tbl)
	if type(current) ~= 'table' then return end

	for key, value in pairs(tbl) do
		if current[key] == nil then
			current[key] = value
		end
	end
end

Azilroka's avatar
Azilroka committed
231 232
function PA:SetTemplate(frame)
	if PA.AddOnSkins then
Azilroka's avatar
Azilroka committed
233
		_G.AddOnSkins[1]:SetTemplate(frame)
Azilroka's avatar
Azilroka committed
234
	else
Azilroka's avatar
Azilroka committed
235
		if not frame.SetBackdrop then _G.Mixin(frame,  _G.BackdropTemplateMixin) end
Azilroka's avatar
Azilroka committed
236 237 238 239 240
		if frame.SetTemplate then
			frame:SetTemplate('Transparent', true)
		else
			frame:SetBackdrop({ bgFile = PA.Solid, edgeFile = PA.Solid, tile = false, tileSize = 0, edgeSize = 1, insets = { left = 0, right = 0, top = 0, bottom = 0 } })
		end
Azilroka's avatar
Azilroka committed
241
		frame:SetBackdropColor(.08, .08, .08, .8)
Azilroka's avatar
Azilroka committed
242 243 244 245 246 247
		frame:SetBackdropBorderColor(0.2, 0.2, 0.2, 0)
	end
end

function PA:CreateBackdrop(frame)
	if PA.AddOnSkins then
Azilroka's avatar
Azilroka committed
248
		_G.AddOnSkins[1]:CreateBackdrop(frame)
Azilroka's avatar
Azilroka committed
249 250 251
	else
		frame.Backdrop = CreateFrame('Frame', nil, frame)
		frame.Backdrop:SetFrameLevel(frame:GetFrameLevel() - 1)
Azilroka's avatar
Azilroka committed
252
		frame.Backdrop:SetOutside(frame)
Azilroka's avatar
Azilroka committed
253
		PA:SetTemplate(frame.Backdrop)
Azilroka's avatar
Azilroka committed
254 255 256 257 258
	end
end

function PA:CreateShadow(frame)
	if PA.AddOnSkins then
Azilroka's avatar
Azilroka committed
259
		_G.AddOnSkins[1]:CreateShadow(frame)
Azilroka's avatar
Azilroka committed
260 261
	elseif frame.CreateShadow then
		frame:CreateShadow()
262
		if not PA.SLE and not PA.NUI then
Azilroka's avatar
1.63  
Azilroka committed
263
			PA.ES:RegisterFrameShadows(frame)
264
		elseif PA.SLE or PA.NUI then
Azilroka's avatar
1.63  
Azilroka committed
265 266
			_G.EnhancedShadows:RegisterShadow(frame.shadow)
		end
Azilroka's avatar
Azilroka committed
267 268 269 270 271 272 273 274 275 276 277 278 279
	end
end

function PA:SetInside(obj, anchor, xOffset, yOffset, anchor2)
	xOffset = xOffset or 1
	yOffset = yOffset or 1
	anchor = anchor or obj:GetParent()

	assert(anchor)
	if obj:GetPoint() then
		obj:ClearAllPoints()
	end

Azilroka's avatar
Azilroka committed
280 281
	obj:SetPoint('TOPLEFT', anchor, 'TOPLEFT', xOffset, -yOffset)
	obj:SetPoint('BOTTOMRIGHT', anchor2 or anchor, 'BOTTOMRIGHT', -xOffset, yOffset)
Azilroka's avatar
Azilroka committed
282 283 284 285 286 287 288 289 290 291 292 293
end

function PA:SetOutside(obj, anchor, xOffset, yOffset, anchor2)
	xOffset = xOffset or 1
	yOffset = yOffset or 1
	anchor = anchor or obj:GetParent()

	assert(anchor)
	if obj:GetPoint() then
		obj:ClearAllPoints()
	end

Azilroka's avatar
Azilroka committed
294 295
	obj:SetPoint('TOPLEFT', anchor, 'TOPLEFT', -xOffset, yOffset)
	obj:SetPoint('BOTTOMRIGHT', anchor2 or anchor, 'BOTTOMRIGHT', xOffset, -yOffset)
Azilroka's avatar
Azilroka committed
296 297
end

Azilroka's avatar
Azilroka committed
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
PA.ClassicServerNameByID = {
	[4703] = 'Amnennar',
	[4715] = 'Anathema',
	[4716] = 'Arcanite Reaper',
	[4742] = 'Ashbringer',
	[4387] = 'Ashkandi',
	[4372] = 'Atiesh',
	[4669] = 'Arugal',
	[4441] = 'Auberdine',
	[4376] = 'Azuresong',
	[4728] = 'Benediction',
	[4398] = 'Bigglesworth',
	[4397] = 'Blaumeux',
	[4746] = 'Bloodfang',
	[4648] = 'Bloodsail Buccaneers',
	[4386] = 'Deviate Delight',
	[4751] = 'Dragonfang',
	[4756] = "Dragon's Call",
	[4755] = 'Dreadmist',
	[4731] = 'Earthfury',
	[4749] = 'Earthshaker',
	[4440] = 'Everlook',
	[4408] = 'Faerlina',
	[4396] = 'Fairbanks',
	[4739] = 'Felstriker',
	[4744] = 'Finkle',
	[4467] = 'Firemaw',
	[4706] = 'Flamelash',
	[4702] = 'Gandling',
	[4476] = 'Gehennas',
	[4465] = 'Golemagg',
	[4647] = 'Grobbulus',
	[4732] = 'Heartseeker',
	[4763] = 'Heartstriker',
	[4406] = 'Herod',
	[4678] = 'Hydraxian Waterlords',
	[4698] = 'Incendius',
	[4758] = 'Judgement',
	[4700] = 'Kirtonos',
	[4699] = 'Kromcrush',
	[4399] = 'Kurinnaxx',
	[4442] = 'Lakeshire',
	[4801] = 'Loatheb',
	[4463] = 'Lucifron',
	[4813] = 'Mandokir',
	[4384] = 'Mankrik',
	[4454] = 'Mirage Raceway',
	[4701] = 'Mograine',
	[4373] = 'Myzrael',
	[4456] = 'Nethergarde Keep',
	[4729] = 'Netherwind',
	[4741] = 'Noggenfogger',
	[4374] = 'Old Blanchy',
	[4385] = 'Pagle',
	[4466] = 'Patchwerk',
	[4453] = 'Pyrewood Village',
	[4695] = 'Rattlegore',
	[4455] = 'Razorfen',
	[4478] = 'Razorgore',
	[4667] = 'Remulos',
	[4475] = 'Shazzrah',
	[4410] = 'Skeram',
	[4743] = 'Skullflame',
	[4696] = 'Smolderweb',
	[4409] = 'Stalagg',
	[4705] = 'Stonespine',
	[4726] = 'Sulfuras',
	[4464] = 'Sulfuron',
	[4737] = "Sul'thraze",
	[4757] = 'Ten Storms',
	[4407] = 'Thalnos',
	[4714] = 'Thunderfury',
	[4745] = 'Transcendence',
	[4477] = 'Venoxis',
	[4388] = 'Westfall',
	[4395] = 'Whitemane',
	[4727] = 'Windseeker',
	[4670] = 'Yojamba',
	[4676] = 'Zandalar Tribe',
	[4452] = 'Хроми',
	[4704] = 'Змейталак',
	[4754] = 'Рок-Делар',
	[4766] = 'Вестник Рока',
	[4474] = 'Пламегор',
}

local accountInfo = { gameAccountInfo = {} }
function PA:GetBattleNetInfo(friendIndex)
	if PA.Classic then
		local bnetIDAccount, accountName, battleTag, isBattleTag, _, bnetIDGameAccount, _, isOnline, lastOnline, isBnetAFK, isBnetDND, messageText, noteText, _, messageTime, _, isReferAFriend, canSummonFriend, isFavorite = BNGetFriendInfo(friendIndex)

		if not bnetIDGameAccount then return end

		local hasFocus, characterName, client, realmName, realmID, faction, race, class, guild, zoneName, level, gameText, broadcastText, broadcastTime, _, toonID, _, isGameAFK, isGameBusy, guid, wowProjectID, mobile  = BNGetGameAccountInfo(bnetIDGameAccount)

		accountInfo.bnetAccountID = bnetIDAccount
		accountInfo.accountName = accountName
		accountInfo.battleTag = battleTag
		accountInfo.isBattleTagFriend = isBattleTag
		accountInfo.isDND = isBnetDND
		accountInfo.isAFK = isBnetAFK
		accountInfo.isFriend = true
		accountInfo.isFavorite = isFavorite
		accountInfo.note = noteText
		accountInfo.rafLinkType = 0
		accountInfo.appearOffline = false
		accountInfo.customMessage = messageText
		accountInfo.lastOnlineTime = lastOnline
		accountInfo.customMessageTime = messageTime

		accountInfo.gameAccountInfo.clientProgram = client or "App"
		accountInfo.gameAccountInfo.richPresence = gameText ~= '' and gameText or PA.ACL["Mobile"]
		accountInfo.gameAccountInfo.gameAccountID = bnetIDGameAccount
		accountInfo.gameAccountInfo.isOnline = isOnline
		accountInfo.gameAccountInfo.isGameAFK = isGameAFK
		accountInfo.gameAccountInfo.isGameBusy = isGameBusy
		accountInfo.gameAccountInfo.isWowMobile = mobile
		accountInfo.gameAccountInfo.hasFocus = hasFocus
		accountInfo.gameAccountInfo.canSummon = canSummonFriend

		if wowProjectID == _G.WOW_PROJECT_MAINLINE then
			zoneName, realmName = strsplit("-", gameText)
		end

		if client == _G.BNET_CLIENT_WOW then
			accountInfo.gameAccountInfo.characterName = characterName
			accountInfo.gameAccountInfo.factionName = faction ~= '' and faction or nil
			accountInfo.gameAccountInfo.playerGuid = guid
			accountInfo.gameAccountInfo.wowProjectID = wowProjectID
			accountInfo.gameAccountInfo.realmID = realmID
			accountInfo.gameAccountInfo.realmDisplayName = realmName
			accountInfo.gameAccountInfo.realmName = realmName
			accountInfo.gameAccountInfo.areaName = zoneName
			accountInfo.gameAccountInfo.className = class
			accountInfo.gameAccountInfo.characterLevel = level
			accountInfo.gameAccountInfo.raceName = race
		else
			accountInfo.gameAccountInfo.characterName = nil
			accountInfo.gameAccountInfo.factionName = nil
			accountInfo.gameAccountInfo.playerGuid = nil
			accountInfo.gameAccountInfo.wowProjectID = nil
			accountInfo.gameAccountInfo.realmID = nil
			accountInfo.gameAccountInfo.realmDisplayName = nil
			accountInfo.gameAccountInfo.realmName = nil
			accountInfo.gameAccountInfo.areaName = nil
			accountInfo.gameAccountInfo.className = nil
			accountInfo.gameAccountInfo.characterLevel = nil
			accountInfo.gameAccountInfo.raceName = nil
		end

		return accountInfo
	else
		accountInfo = _G.C_BattleNet.GetFriendAccountInfo(friendIndex)

		if accountInfo and accountInfo.gameAccountInfo.wowProjectID == _G.WOW_PROJECT_CLASSIC then
			accountInfo.gameAccountInfo.realmDisplayName = PA.ClassicServerNameByID[accountInfo.gameAccountInfo.realmID] or accountInfo.gameAccountInfo.realmID
		end

		return accountInfo
	end
end

Azilroka's avatar
Azilroka committed
460 461 462 463 464 465 466 467 468 469
StaticPopupDialogs["PROJECTAZILROKA"] = {
	text = PA.ACL["A setting you have changed will change an option for this character only. This setting that you have changed will be uneffected by changing user profiles. Changing this setting requires that you reload your User Interface."],
	button1 = ACCEPT,
	button2 = CANCEL,
	OnAccept = ReloadUI,
	timeout = 0,
	whileDead = 1,
	hideOnEscape = false,
}

Azilroka's avatar
Azilroka committed
470 471 472 473 474 475 476 477 478 479
StaticPopupDialogs["PROJECTAZILROKA_RL"] = {
	text = PA.ACL["This setting requires that you reload your User Interface."],
	button1 = ACCEPT,
	button2 = CANCEL,
	OnAccept = ReloadUI,
	timeout = 0,
	whileDead = 1,
	hideOnEscape = false,
}

Azilroka's avatar
Azilroka committed
480 481
PA.Defaults = {
	profile = {
Merathilis's avatar
Merathilis committed
482 483
		Cooldown = {
			Enable = true,
Azilroka's avatar
Azilroka committed
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
			threshold = 3,
			hideBlizzard = false,
			useIndicatorColor = false,
			expiringColor = { r = 1, g = 0, b = 0 },
			secondsColor = { r = 1, g = 1, b = 0 },
			minutesColor = { r = 1, g = 1, b = 1 },
			hoursColor = { r = 0.4, g = 1, b = 1 },
			daysColor = { r = 0.4, g = 0.4, b = 1 },
			expireIndicator = { r = 1, g = 1, b = 1 },
			secondsIndicator = { r = 1, g = 1, b = 1 },
			minutesIndicator = { r = 1, g = 1, b = 1 },
			hoursIndicator = { r = 1, g = 1, b = 1 },
			daysIndicator = { r = 1, g = 1, b = 1 },
			hhmmColorIndicator = { r = 1, g = 1, b = 1 },
			mmssColorIndicator = { r = 1, g = 1, b = 1 },

			checkSeconds = false,
			hhmmColor = { r = 0.43, g = 0.43, b = 0.43 },
			mmssColor = { r = 0.56, g = 0.56, b = 0.56 },
			hhmmThreshold = -1,
			mmssThreshold = -1,

			fonts = {
				enable = false,
				font = 'PT Sans Narrow',
				fontOutline = 'OUTLINE',
				fontSize = 18,
			},
		}
	}
}
Azilroka's avatar
Azilroka committed
515

Azilroka's avatar
Azilroka committed
516
PA.Options = PA.ACH:Group(PA:Color(PA.Title), nil, 6)
Azilroka's avatar
Azilroka committed
517 518 519 520 521 522

function PA:GetOptions()
	PA.AceOptionsPanel.Options.args.ProjectAzilroka = PA.Options
end

function PA:BuildProfile()
Azilroka's avatar
Azilroka committed
523
	PA.data = PA.ADB:New('ProjectAzilrokaDB', PA.Defaults, true)
Azilroka's avatar
Azilroka committed
524 525 526 527 528 529 530 531 532 533 534 535

	PA.data.RegisterCallback(PA, 'OnProfileChanged', 'SetupProfile')
	PA.data.RegisterCallback(PA, 'OnProfileCopied', 'SetupProfile')

	PA.Options.args.profiles = LibStub('AceDBOptions-3.0'):GetOptionsTable(PA.data)
	PA.Options.args.profiles.order = -2

	PA.db = PA.data.profile
end

function PA:SetupProfile()
	PA.db = PA.data.profile
Azilroka's avatar
Azilroka committed
536 537

	for _, module in PA:IterateModules() do
Azilroka's avatar
Azilroka committed
538
		if module.UpdateSettings then module:UpdateSettings() end
Azilroka's avatar
Azilroka committed
539
	end
Azilroka's avatar
Azilroka committed
540 541
end

542
function PA:CallModuleFunction(module, func)
543 544 545
	local pass, err = pcall(func, module)
	if not pass and PA.Debug then
		error(err)
546 547 548
	end
end

Azilroka's avatar
Azilroka committed
549
function PA:PLAYER_LOGIN()
Azilroka's avatar
stAM  
Azilroka committed
550
	PA.Multiple = PA:GetUIScale()
Azilroka's avatar
Azilroka committed
551

Azilroka's avatar
Azilroka committed
552
	PA.AS = _G.AddOnSkins and _G.AddOnSkins[1]
Azilroka's avatar
Azilroka committed
553 554
	PA.EP = LibStub('LibElvUIPlugin-1.0', true)
	PA.AceOptionsPanel = PA.ElvUI and _G.ElvUI[1] or PA.EC
Azilroka's avatar
Azilroka committed
555

Azilroka's avatar
Azilroka committed
556 557
	PA.Options.childGroups = PA.EC and 'tab' or 'tree'

Azilroka's avatar
Azilroka committed
558
	for _, module in PA:IterateModules() do
559
		if module.BuildProfile then PA:CallModuleFunction(module, module.BuildProfile) end
Azilroka's avatar
Azilroka committed
560 561 562 563 564 565 566 567
	end

	PA:BuildProfile()

	if PA.EP then
		PA.EP:RegisterPlugin('ProjectAzilroka', PA.GetOptions)
	end

Azilroka's avatar
Azilroka committed
568 569
	PA:UpdateCooldownSettings('all')

Azilroka's avatar
Azilroka committed
570
	for _, module in PA:IterateModules() do
571 572 573 574 575 576
		if module.GetOptions then
			PA:CallModuleFunction(module, module.GetOptions)
		end
		if module.Initialize then
			PA:CallModuleFunction(module, module.Initialize)
		end
Azilroka's avatar
Azilroka committed
577 578 579
	end
end

Azilroka's avatar
Azilroka committed
580
PA:RegisterEvent('PLAYER_LOGIN')