DragonOverlay.lua 8.48 KB
Newer Older
Azilroka's avatar
Azilroka committed
1 2 3 4 5 6 7 8 9
local PA = _G.ProjectAzilroka
local DO = PA:NewModule('DragonOverlay', 'AceEvent-3.0')
PA.DO, _G.DragonOverlay = DO, DO

local _G = _G
local pairs, tinsert, select, unpack = pairs, tinsert, select, unpack
local strfind, strsub = strfind, strsub
local UnitIsPlayer, UnitClass, UnitClassification = UnitIsPlayer, UnitClass, UnitClassification

Azilroka's avatar
Azilroka committed
10 11
DO.Title = 'Dragon Overlay'
DO.Header = PA.ACL['|cFF16C3F2Dragon|r |cFFFFFFFFOverlay|r']
12
DO.Description = PA.ACL['Provides an overlay on UnitFrames for Boss, Elite, Rare and RareElite']
Azilroka's avatar
Azilroka committed
13
DO.Authors = 'Azilroka    NihilisticPandemonium'
Azilroka's avatar
Azilroka committed
14
DO.ImageCredits = 'Codeblake    Kkthnxbye    Narley    Durandil'
Azilroka's avatar
Azilroka committed
15
DO.isEnabled = false
Azilroka's avatar
Azilroka committed
16

Azilroka's avatar
Cleanup  
Azilroka committed
17
local MediaPath = 'Interface/AddOns/ProjectAzilroka/Media/DragonOverlay/'
Azilroka's avatar
Azilroka committed
18
local CLASS_ICON_TCOORDS = CLASS_ICON_TCOORDS
Azilroka's avatar
Azilroka committed
19 20

DO.Textures = {
Azilroka's avatar
Azilroka committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
	Azure = MediaPath..'Azure',
	Chromatic = MediaPath..'Chromatic',
	Crimson = MediaPath..'Crimson',
	Golden = MediaPath..'Golden',
	Jade = MediaPath..'Jade',
	Onyx = MediaPath..'Onyx',
	HeavenlyBlue = MediaPath..'HeavenlyBlue',
	HeavenlyCrimson = MediaPath..'HeavenlyCrimson',
	HeavenlyGolden = MediaPath..'HeavenlyGolden',
	HeavenlyJade = MediaPath..'HeavenlyJade',
	HeavenlyOnyx = MediaPath..'HeavenlyOnyx',
	ClassicElite = MediaPath..'ClassicElite',
	ClassicRareElite = MediaPath..'ClassicRareElite',
	ClassicRare = MediaPath..'ClassicRare',
	ClassicBoss = MediaPath..'ClassicBoss',
Azilroka's avatar
Azilroka committed
36 37 38
}

function DO:SetOverlay()
Azilroka's avatar
Azilroka committed
39
	local Points
Azilroka's avatar
Azilroka committed
40

Azilroka's avatar
Azilroka committed
41 42 43 44
	if UnitIsPlayer('target') and DO.db['ClassIcon'] then
		DO.frame:SetSize(DO.db.IconSize, DO.db.IconSize)
		DO.frame.Texture:SetTexture('Interface/WorldStateFrame/Icons-Classes')
		DO.frame.Texture:SetTexCoord(unpack(CLASS_ICON_TCOORDS[select(2, UnitClass('target'))]))
Azilroka's avatar
Azilroka committed
45 46
		Points = 'ClassIconPoints'
	else
Azilroka's avatar
Azilroka committed
47 48 49
		DO.frame:SetSize(DO.db.Width, DO.db.Height)
		DO.frame.Texture:SetTexture(DO.Textures[DO.db[UnitClassification('target')]])
		DO.frame.Texture:SetTexCoord(DO.db['FlipDragon'] and 1 or 0, DO.db['FlipDragon'] and 0 or 1, 0, 1)
Azilroka's avatar
Azilroka committed
50
		Points = 'DragonPoints'
Azilroka's avatar
Azilroka committed
51 52
	end

Azilroka's avatar
Azilroka committed
53 54 55 56 57 58
	if _G[DO.db[Points]['relativeTo']] then
		DO.frame:ClearAllPoints()
		DO.frame:SetPoint(DO.db[Points]['point'], _G[DO.db[Points]['relativeTo']].Health, DO.db[Points]['relativePoint'], DO.db[Points]['xOffset'], DO.db[Points]['yOffset'])
		DO.frame:SetParent(DO.db[Points]['relativeTo'])
		DO.frame:SetFrameStrata(strsub(DO.db['Strata'], 3))
		DO.frame:SetFrameLevel(DO.db['Level'])
Azilroka's avatar
Azilroka committed
59
	end
Azilroka's avatar
Azilroka committed
60 61 62
end

function DO:GetOptions()
Azilroka's avatar
Azilroka committed
63 64 65 66 67
	PA.Options.args.DragonOverlay = PA.ACH:Group(DO.Title, DO.Description, nil, nil, function(info) return DO.db[info[#info]] end)
	PA.Options.args.DragonOverlay.args.Header = PA.ACH:Header(DO.Header, 0)
	PA.Options.args.DragonOverlay.args.Enable = PA.ACH:Toggle(PA.ACL['Enable'], nil, 1, nil, nil, nil, nil, function(info, value) DO.db[info[#info]] = value if not DO.isEnabled then DO:Initialize() else _G.StaticPopup_Show('PROJECTAZILROKA_RL') end end)

	PA.Options.args.DragonOverlay.args.General = PA.ACH:Group(PA.ACL['General'], nil, 2, nil, nil, function(info, value) DO.db[info[#info]] = value DO:SetOverlay() end)
Azilroka's avatar
Azilroka committed
68
	PA.Options.args.DragonOverlay.args.General.inline = true
Azilroka's avatar
Azilroka committed
69 70 71 72 73 74 75 76 77 78

	PA.Options.args.DragonOverlay.args.General.args.ClassIcon = PA.ACH:Toggle(PA.ACL['Class Icon'], nil, 1)
	PA.Options.args.DragonOverlay.args.General.args.FlipDragon = PA.ACH:Toggle(PA.ACL['Flip Dragon'], nil, 2)
	PA.Options.args.DragonOverlay.args.General.args.Strata = PA.ACH:Select(PA.ACL['Frame Strata'], nil, 3, { BACKGROUND = 'BACKGROUND', LOW = 'LOW', MEDIUM = 'MEDIUM', HIGH = 'HIGH', DIALOG = 'DIALOG', FULLSCREEN = 'FULLSCREEN', FULLSCREEN_DIALOG = 'FULLSCREEN_DIALOG', TOOLTIP = 'TOOLTIP' })
	PA.Options.args.DragonOverlay.args.General.args.Level = PA.ACH:Range(PA.ACL['Frame Level'], nil, 4, { min = 0, max = 255, step = 1 })
	PA.Options.args.DragonOverlay.args.General.args.IconSize = PA.ACH:Range(PA.ACL['Icon Size'], nil, 5, { min = 0, max = 256, step = 1 })
	PA.Options.args.DragonOverlay.args.General.args.Width = PA.ACH:Range(PA.ACL['Width'], nil, 6, { min = 1, max = 256, step = 1 })
	PA.Options.args.DragonOverlay.args.General.args.Height = PA.ACH:Range(PA.ACL['Height'], nil, 7, { min = 1, max = 256, step = 1 })

	PA.Options.args.DragonOverlay.args.General.args.Dragons = PA.ACH:Group(PA.ACL['Dragons'], nil, -6)
Azilroka's avatar
Azilroka committed
79
	PA.Options.args.DragonOverlay.args.General.args.Dragons.inline = true
Azilroka's avatar
Azilroka committed
80 81

	PA.Options.args.DragonOverlay.args.General.args.Textures = PA.ACH:Group(PA.ACL['Preview'], nil, -5)
Azilroka's avatar
Azilroka committed
82
	PA.Options.args.DragonOverlay.args.General.args.Textures.inline = true
Azilroka's avatar
Azilroka committed
83

Azilroka's avatar
Azilroka committed
84
	for Option, Name in pairs({ ClassIconPoints = PA.ACL['Class Icon Points'], DragonPoints = PA.ACL['Dragon Points'] }) do
Azilroka's avatar
Azilroka committed
85
		PA.Options.args.DragonOverlay.args.General.args[Option] = PA.ACH:Group(Name, nil, nil, nil, function(info) return DO.db[Option][info[#info]] end, function(info, value) DO.db[Option][info[#info]] = value DO:SetOverlay() end)
Azilroka's avatar
Azilroka committed
86
		PA.Options.args.DragonOverlay.args.General.args[Option].inline = true
Azilroka's avatar
Azilroka committed
87 88 89 90 91
		PA.Options.args.DragonOverlay.args.General.args[Option].args.point = PA.ACH:Select(PA.ACL['Anchor Point'], nil, 1, PA.AllPoints)
		PA.Options.args.DragonOverlay.args.General.args[Option].args.relativeTo = PA.ACH:Select(PA.ACL['Relative Frame'], nil, 2, {})
		PA.Options.args.DragonOverlay.args.General.args[Option].args.relativePoint = PA.ACH:Select(PA.ACL['Relative Point'], nil, 3, PA.AllPoints)
		PA.Options.args.DragonOverlay.args.General.args[Option].args.xOffset = PA.ACH:Range(PA.ACL['X Offset'], nil, 4, { min = -350, max = 350, step = 1 })
		PA.Options.args.DragonOverlay.args.General.args[Option].args.yOffset = PA.ACH:Range(PA.ACL['Y Offset'], nil, 5, { min = -350, max = 350, step = 1 })
Azilroka's avatar
Azilroka committed
92 93 94 95

		local UnitFrameParents = { oUF_PetBattleFrameHider }

		if PA.Tukui then
Azilroka's avatar
Azilroka committed
96
			tinsert(UnitFrameParents, _G.Tukui[1].PetHider)
Azilroka's avatar
Azilroka committed
97 98 99
		end

		if PA.ElvUI then
Azilroka's avatar
Azilroka committed
100
			tinsert(UnitFrameParents, _G.ElvUF_Parent)
Azilroka's avatar
Azilroka committed
101 102 103 104
		end

		for _, Parent in pairs(UnitFrameParents) do
			for _, UnitFrame in pairs({Parent:GetChildren()}) do
Azilroka's avatar
Azilroka committed
105
				if _G.SecureButton_GetUnit(UnitFrame) == 'target' then
Azilroka's avatar
Azilroka committed
106
					PA.Options.args.DragonOverlay.args.General.args[Option].args.relativeTo.values[UnitFrame:GetName()] = UnitFrame:GetName()
Azilroka's avatar
Azilroka committed
107 108 109 110 111
				end
			end
		end
	end

Azilroka's avatar
Azilroka committed
112
	PA.Options.args.DragonOverlay.args.General.args.ClassIconPoints.disabled = function() return (not DO.db.ClassIcon) end
Azilroka's avatar
Azilroka committed
113

Azilroka's avatar
Azilroka committed
114 115 116
	local textures = {}
	for texture in pairs(DO.Textures) do textures[texture] = texture:gsub('(%l)(%u%l)','%1 %2') end

Azilroka's avatar
Azilroka committed
117
	for Option, Name in pairs({ elite = PA.ACL['Elite'], rare = PA.ACL['Rare'],	rareelite = PA.ACL['Rare Elite'], worldboss = PA.ACL['World Boss'] }) do
Azilroka's avatar
Azilroka committed
118 119
		PA.Options.args.DragonOverlay.args.General.args.Dragons.args[Option] = PA.ACH:Select(Name, nil, nil, textures)
		PA.Options.args.DragonOverlay.args.General.args.Textures.args[Option] = PA.ACH:Execute(Name, nil, nil, nil, function() return DO.Textures[DO.db[Option]], strfind(DO.db[Option], 'Classic') and 32 or 128, 32 end)
Azilroka's avatar
Azilroka committed
120
	end
Azilroka's avatar
Azilroka committed
121 122 123 124 125

	PA.Options.args.DragonOverlay.args.AuthorHeader = PA.ACH:Header(PA.ACL['Authors:'], -4)
	PA.Options.args.DragonOverlay.args.Authors = PA.ACH:Description(DO.Authors, -3, 'large')
	PA.Options.args.DragonOverlay.args.CreditsHeader = PA.ACH:Header(PA.ACL['Image Credits:'], -2)
	PA.Options.args.DragonOverlay.args.Credits = PA.ACH:Description(DO.ImageCredits, -1, 'large')
Azilroka's avatar
Azilroka committed
126 127 128
end

function DO:BuildProfile()
Azilroka's avatar
Azilroka committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
	PA.Defaults.profile.DragonOverlay = {
		Enable = true,
		Strata = '3-MEDIUM',
		Level = 12,
		IconSize = 32,
		Width = 128,
		Height = 64,
		worldboss = 'Chromatic',
		elite = 'HeavenlyGolden',
		rare = 'Onyx',
		rareelite = 'HeavenlyOnyx',
		ClassIcon = false,
		FlipDragon = false,
		ClassIconPoints = {
			point = 'CENTER',
			relativeTo = 'oUF_Target',
			relativePoint = 'TOP',
			xOffset = 0,
			yOffset = 5,
Azilroka's avatar
Azilroka committed
148
		},
Azilroka's avatar
Azilroka committed
149 150 151 152 153 154
		DragonPoints = {
			point = 'CENTER',
			relativeTo = 'oUF_Target',
			relativePoint = 'TOP',
			xOffset = 0,
			yOffset = 5,
Azilroka's avatar
Azilroka committed
155
		},
Azilroka's avatar
Azilroka committed
156 157 158 159
	}

	for _, Option in pairs({ 'ClassIconPoints', 'DragonPoints' }) do
		if PA.Tukui then
Azilroka's avatar
Azilroka committed
160
			PA.Defaults.profile.DragonOverlay[Option].relativeTo = 'oUF_TukuiTarget'
Azilroka's avatar
Azilroka committed
161 162
		end
		if PA.ElvUI then
Azilroka's avatar
Azilroka committed
163
			PA.Defaults.profile.DragonOverlay[Option].relativeTo = 'ElvUF_Target'
Azilroka's avatar
Azilroka committed
164
		end
165 166
		if PA.NUI then
			PA.Defaults.profile.DragonOverlay[Option].relativeTo = 'NihilistUF_Target'
Azilroka's avatar
Azilroka committed
167 168
		end
		if PA.AzilUI then
Azilroka's avatar
Azilroka committed
169
			PA.Defaults.profile.DragonOverlay[Option].relativeTo = 'oUF_AzilUITarget'
Azilroka's avatar
Azilroka committed
170 171 172 173
		end
	end
end

Azilroka's avatar
Cleanup  
Azilroka committed
174
function DO:UpdateSettings()
Azilroka's avatar
Azilroka committed
175
	DO.db = PA.db.DragonOverlay
Azilroka's avatar
Cleanup  
Azilroka committed
176 177 178 179
end

function DO:Initialize()
	DO:UpdateSettings()
Azilroka's avatar
Azilroka committed
180

Azilroka's avatar
Azilroka committed
181 182 183 184
	if DO.db.Enable ~= true then
		return
	end

Azilroka's avatar
Azilroka committed
185 186
	DO.isEnabled = true

Azilroka's avatar
Azilroka committed
187
	local frame = _G.CreateFrame("Frame", 'DragonOverlayFrame', _G.UIParent)
Azilroka's avatar
Azilroka committed
188 189 190 191 192
	frame.Texture = frame:CreateTexture(nil, 'ARTWORK')
	frame.Texture:SetAllPoints()
	DO.frame = frame

	DO:RegisterEvent('PLAYER_TARGET_CHANGED', 'SetOverlay')
Azilroka's avatar
Cleanup  
Azilroka committed
193
end