View difference between Paste ID: S8S4SW8g and Z6BuyStU
SHOW: | | - or go back to the newest paste.
1
local Core = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
2
local Module = Core:NewModule("Unitframes", "AceEvent-3.0")
3
4
----------------
5
-- Unitframes --
6
----------------
7
8
local CUSTOM_FACTION_BAR_COLORS = {
9
	[1] = {r = 1, g = 0, b = 0},
10
	[2] = {r = 1, g = 0, b = 0},
11
	[3] = {r = 1, g = 1, b = 0},
12
	[4] = {r = 1, g = 1, b = 0},
13
	[5] = {r = 0, g = 1, b = 0},
14
	[6] = {r = 0, g = 1, b = 0},
15
	[7] = {r = 0, g = 1, b = 0},
16
	[8] = {r = 0, g = 1, b = 0},
17
}
18
19-
function Module:UpdatePlayerFrame()
19+
-- Font Style
20-
	local db = Core.db.profile
20+
local shorts = {
21
	{ 1e10, 1e9, "%.0fB" }, --  10b+ as  12b
22-
	if db.unitframes.player.enable ~= true then return end
22+
	{  1e9, 1e9, "%.1fB" }, --   1b+ as 8.3b
23
	{  1e7, 1e6, "%.0fM" }, --  10m+ as  14m
24-
	local PlayerEventFrame = CreateFrame("Frame")
24+
	{  1e6, 1e6, "%.1fM" }, --   1m+ as 7.4m
25-
	PlayerEventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
25+
	{  1e5, 1e3, "%.0fK" }, -- 100k+ as 840k
26-
	PlayerEventFrame:SetScript("OnEvent", function(self, event, ...)
26+
	{  1e3, 1e3, "%.1fK" }, --   1k+ as 2.5k
27-
		if UnitAffectingCombat("player") then return end
27+
	{    0,   1,    "%d" }, -- < 1k  as  974
28-
		
28+
29-
		if event == "PLAYER_ENTERING_WORLD" then
29+
for i = 1, #shorts do
30-
			PlayerFrame:SetScale(db.unitframes.player.scale);
30+
	shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
31-
			PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE");
31+
32-
			PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE");
32+
33-
			PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE");
33+
------------------------------------------------------------------------
34-
			PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE");
34+
35-
			PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE");
35+
local db, enabled
36
37-
			return
37+
38
	db = Core.db.profile
39
40
	if enabled or not db.unitframes.enable then return end
41-
		
41+
	enabled = true -- since most of this stuff is non-undoable (eg. hooksecurefunc)
42-
function Module:UpdateTargetFrame()
42+
43-
	local db = Core.db.profile
43+
44
	for unit, func in pairs(self.UnitFunctions) do
45-
	if db.unitframes.target.enable ~= true then return end
45+
		if db.unitframes[unit].enable then
46
			func(self)
47-
	local TargetEventFrame = CreateFrame("Frame")
47+
48-
	TargetEventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")	
48+
49-
	TargetEventFrame:SetScript("OnEvent", function(self, event, ...)
49+
50-
		if UnitAffectingCombat("player") then return end
50+
	-- Change other frames' name backgrounds to match player frame
51-
		
51+
52-
		if event == "PLAYER_ENTERING_WORLD" then
52+
53-
			TargetFrame:SetScale(db.unitframes.target.scale);
53+
54-
			TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE");
54+
55-
			TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE");
55+
56
		Boss3TargetFrameNameBackground,
57-
			return
57+
58
	}) do
59
		region:SetTexture(0, 0, 0, 0.5)
60
	end
61
	
62-
function Module:UpdateFocusFrame()
62+
63-
	local db = Core.db.profile
63+
64
		if value == 0 then
65-
	if db.unitframes.focus.enable ~= true then return end
65+
66
		end
67-
	local FocusEventFrame = CreateFrame("Frame")
67+
68-
	FocusEventFrame:RegisterEvent("PLAYER_FOCUS_CHANGED")
68+
69-
	FocusEventFrame:SetScript("OnEvent", function(self, event, ...)
69+
70-
		if UnitAffectingCombat("player") then return end
70+
71-
		
71+
72-
		if event == "PLAYER_FOCUS_CHANGED" then
72+
73-
			FocusFrame:SetScale(db.unitframes.focus.scale);
73+
74-
			FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE");
74+
75-
			FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE");
75+
76
					return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
77-
			return
77+
78
					if value < valueMax then
79
						for j = 1, #shorts do
80
							local v = shorts[j]
81
							if valueMax >= v[1] then
82-
function Module:UpdatePartyMembersFrame()
82+
83-
	local db = Core.db.profile
83+
84
						end
85-
	if db.unitframes.party.enable ~= true then return end
85+
86
					return fontString:SetFormattedText(t[3], value / t[2])
87-
	local PartyMembersEventFrame = CreateFrame("Frame")
87+
88-
	PartyMembersEventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
88+
89-
	PartyMembersEventFrame:SetScript("OnEvent", function(self, event, ...)
89+
90-
		if UnitAffectingCombat("player") then return end
90+
91
92-
		if event == "GROUP_ROSTER_UPDATE" then
92+
	-- Font Color
93-
			for i = 1, MAX_PARTY_MEMBERS do	
93+
94-
				local partyFrame = "PartyMemberFrame"..i			
94+
95-
				_G[partyFrame]:SetScale(db.unitframes.party.scale);
95+
96-
				_G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
96+
97-
				_G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
97+
98
		if UnitPlayerControlled(unit) then
99
			if UnitIsPlayer(unit) then
100-
			return
100+
101
				color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
102
			else
103
				color = PET_COLOR
104
			end
105-
function Module:UpdateArenaFrame()
105+
106-
	local db = Core.db.profile
106+
107
		else
108-
	if db.unitframes.arena.enable ~= true then return end
108+
109
		end
110-
	local ArenaEventFrame = CreateFrame("Frame")
110+
111-
	ArenaEventFrame:RegisterEvent("BATTLEFIELDS_SHOW")
111+
112-
	ArenaEventFrame:SetScript("OnEvent", function(self, event, ...)
112+
113-
		if UnitAffectingCombat("player") then return end
113+
114
115-
		if event == "BATTLEFIELDS_SHOW" then
115+
116-
			for i = 1, MAX_ARENA_ENEMIES do
116+
117-
				arenaFrame = "ArenaEnemyFrame"..i
117+
118-
				_G[arenaFrame]:SetScale(db.unitframes.arena.scale);
118+
119-
				_G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE");
119+
120-
				_G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE");
120+
121
122
------------------------------------------------------------------------
123-
			return
123+
124
Module.UnitFunctions = {
125
126
	player = function(self)
127
		PlayerFrame:SetScale(db.unitframes.player.scale)
128-
function Module:UpdateBossFrame()
128+
		PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE")
129-
	local db = Core.db.profile
129+
		PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE")
130
		PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE")
131-
	if db.unitframes.boss.enable ~= true then return end 
131+
132
		PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE")
133-
	local BossEventFrame = CreateFrame("Frame");
133+
		PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE")
134-
	BossEventFrame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT");
134+
135-
	BossEventFrame:SetScript("OnEvent", function(self, event, ...)
135+
		-- Disable healing/damage spam over player/pet frame:
136-
		if UnitAffectingCombat("player") then return end
136+
		PlayerHitIndicator:SetText(nil)
137-
		
137+
		PlayerHitIndicator.SetText = function() end
138-
		if event == "INSTANCE_ENCOUNTER_ENGAGE_UNIT" then
138+
		PetHitIndicator:SetText(nil)
139-
			for i = 1, MAX_BOSS_FRAMES do
139+
		PetHitIndicator.SetText = function() end
140-
				local bossFrame = "Boss"..i.."TargetFrame"
140+
	end,
141-
				_G[bossFrame]:SetScale(db.unitframes.boss.scale);			
141+
142
	target = function(self)
143
		TargetFrame:SetScale(db.unitframes.target.scale)
144-
			return
144+
		TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE")
145
		TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE")
146
	end,
147-
end	
147+
148
	focus = function(self)
149-
local function SetUnitFontStyle()
149+
		FocusFrame:SetScale(db.unitframes.focus.scale)
150
		FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE")
151
		FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE")
152
	end,
153-
		-- Font Style
153+
154-
	local shorts = {
154+
	party = function(self)
155-
		{ 1e10, 1e9, "%.0fB" }, --  10b+ as  12b
155+
		for i = 1, MAX_PARTY_MEMBERS do
156-
		{  1e9, 1e9, "%.1fB" }, --   1b+ as 8.3b
156+
			local partyFrame = "PartyMemberFrame"..i
157-
		{  1e7, 1e6, "%.0fM" }, --  10m+ as  14m
157+
			_G[partyFrame]:SetScale(db.unitframes.party.scale)
158-
		{  1e6, 1e6, "%.1fM" }, --   1m+ as 7.4m
158+
			_G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE")
159-
		{  1e5, 1e3, "%.0fK" }, -- 100k+ as 840k
159+
			_G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE")
160-
		{  1e3, 1e3, "%.1fK" }, --   1k+ as 2.5k
160+
161-
		{    0,   1,    "%d" }, -- < 1k  as  974
161+
	end,
162-
	}
162+
163-
	for i = 1, #shorts do
163+
	arena = function(self)
164-
		shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
164+
		for i = 1, MAX_ARENA_ENEMIES do
165
			local prepFrame = "ArenaPrepFrame"..i
166
			_G[prepFrame]:SetScale(db.unitframes.arena.scale)
167
			_G[prepFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE")
168
			_G[prepFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE")
169
170
			local arenaFrame = "ArenaEnemyFrame"..i
171
			_G[arenaFrame]:SetScale(db.unitframes.arena.scale)
172
			_G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE")
173
			_G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE")
174
		end
175
	end,
176
177
	boss = function(self)
178
		for i = 1, MAX_BOSS_FRAMES do
179
			local bossFrame = "Boss"..i.."TargetFrame"
180
			_G[bossFrame]:SetScale(db.unitframes.boss.scale)
181
		end
182
	end,
183
184
}