Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Core = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
- local Module = Core:NewModule("Unitframes", "AceEvent-3.0")
- ----------------
- -- Unitframes --
- ----------------
- local CUSTOM_FACTION_BAR_COLORS = {
- [1] = {r = 1, g = 0, b = 0},
- [2] = {r = 1, g = 0, b = 0},
- [3] = {r = 1, g = 1, b = 0},
- [4] = {r = 1, g = 1, b = 0},
- [5] = {r = 0, g = 1, b = 0},
- [6] = {r = 0, g = 1, b = 0},
- [7] = {r = 0, g = 1, b = 0},
- [8] = {r = 0, g = 1, b = 0},
- }
- function Module:UpdatePlayerFrame()
- local db = Core.db.profile
- if db.unitframes.player.enable ~= true then return end
- local PlayerEventFrame = CreateFrame("Frame")
- PlayerEventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
- PlayerEventFrame:SetScript("OnEvent", function(self, event, ...)
- if UnitAffectingCombat("player") then return end
- if event == "PLAYER_ENTERING_WORLD" then
- PlayerFrame:SetScale(db.unitframes.player.scale);
- PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE");
- PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE");
- PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE");
- PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE");
- PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE");
- else
- return
- end
- end)
- end
- function Module:UpdateTargetFrame()
- local db = Core.db.profile
- if db.unitframes.target.enable ~= true then return end
- local TargetEventFrame = CreateFrame("Frame")
- TargetEventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
- TargetEventFrame:SetScript("OnEvent", function(self, event, ...)
- if UnitAffectingCombat("player") then return end
- if event == "PLAYER_ENTERING_WORLD" then
- TargetFrame:SetScale(db.unitframes.target.scale);
- TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE");
- TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE");
- else
- return
- end
- end)
- end
- function Module:UpdateFocusFrame()
- local db = Core.db.profile
- if db.unitframes.focus.enable ~= true then return end
- local FocusEventFrame = CreateFrame("Frame")
- FocusEventFrame:RegisterEvent("PLAYER_FOCUS_CHANGED")
- FocusEventFrame:SetScript("OnEvent", function(self, event, ...)
- if UnitAffectingCombat("player") then return end
- if event == "PLAYER_FOCUS_CHANGED" then
- FocusFrame:SetScale(db.unitframes.focus.scale);
- FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE");
- FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE");
- else
- return
- end
- end)
- end
- function Module:UpdatePartyMembersFrame()
- local db = Core.db.profile
- if db.unitframes.party.enable ~= true then return end
- local PartyMembersEventFrame = CreateFrame("Frame")
- PartyMembersEventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
- PartyMembersEventFrame:SetScript("OnEvent", function(self, event, ...)
- if UnitAffectingCombat("player") then return end
- if event == "GROUP_ROSTER_UPDATE" then
- for i = 1, MAX_PARTY_MEMBERS do
- local partyFrame = "PartyMemberFrame"..i
- _G[partyFrame]:SetScale(db.unitframes.party.scale);
- _G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
- _G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
- end
- else
- return
- end
- end)
- end
- function Module:UpdateArenaFrame()
- local db = Core.db.profile
- if db.unitframes.arena.enable ~= true then return end
- local ArenaEventFrame = CreateFrame("Frame")
- ArenaEventFrame:RegisterEvent("BATTLEFIELDS_SHOW")
- ArenaEventFrame:SetScript("OnEvent", function(self, event, ...)
- if UnitAffectingCombat("player") then return end
- if event == "BATTLEFIELDS_SHOW" then
- for i = 1, MAX_ARENA_ENEMIES do
- arenaFrame = "ArenaEnemyFrame"..i
- _G[arenaFrame]:SetScale(db.unitframes.arena.scale);
- _G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE");
- _G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE");
- end
- else
- return
- end
- end)
- end
- function Module:UpdateBossFrame()
- local db = Core.db.profile
- if db.unitframes.boss.enable ~= true then return end
- local BossEventFrame = CreateFrame("Frame");
- BossEventFrame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT");
- BossEventFrame:SetScript("OnEvent", function(self, event, ...)
- if UnitAffectingCombat("player") then return end
- if event == "INSTANCE_ENCOUNTER_ENGAGE_UNIT" then
- for i = 1, MAX_BOSS_FRAMES do
- local bossFrame = "Boss"..i.."TargetFrame"
- _G[bossFrame]:SetScale(db.unitframes.boss.scale);
- end
- else
- return
- end
- end)
- end
- local function SetUnitFontStyle()
- -- Font Style / Color thanks to Phanx from WoWinterface.
- -- Font Style
- local shorts = {
- { 1e10, 1e9, "%.0fB" }, -- 10b+ as 12b
- { 1e9, 1e9, "%.1fB" }, -- 1b+ as 8.3b
- { 1e7, 1e6, "%.0fM" }, -- 10m+ as 14m
- { 1e6, 1e6, "%.1fM" }, -- 1m+ as 7.4m
- { 1e5, 1e3, "%.0fK" }, -- 100k+ as 840k
- { 1e3, 1e3, "%.1fK" }, -- 1k+ as 2.5k
- { 0, 1, "%d" }, -- < 1k as 974
- }
- for i = 1, #shorts do
- shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
- end
- hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
- if value == 0 then
- return fontString:SetText("")
- end
- local style = GetCVar("statusTextDisplay")
- if style == "PERCENT" then
- return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
- end
- for i = 1, #shorts do
- local t = shorts[i]
- if value >= t[1] then
- if style == "BOTH" then
- return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
- else
- if value < valueMax then
- for j = 1, #shorts do
- local v = shorts[j]
- if valueMax >= v[1] then
- return fontString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2])
- end
- end
- end
- return fontString:SetFormattedText(t[3], value / t[2])
- end
- end
- end
- end)
- -- Font Color
- hooksecurefunc("UnitFrame_Update", function(self, isParty)
- if not self.name or not self:IsShown() then return end
- local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
- local unit, color = self.unit
- if UnitPlayerControlled(unit) then
- if UnitIsPlayer(unit) then
- local _, class = UnitClass(unit)
- color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
- else
- color = PET_COLOR
- end
- elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
- color = GRAY_FONT_COLOR
- else
- color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
- end
- if not color then
- color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
- end
- self.name:SetTextColor(color.r, color.g, color.b)
- if isParty then
- self.name:SetText(GetUnitName(self.overrideName or unit))
- end
- end)
- end
- function Module:OnEnable()
- local db = Core.db.profile
- if db.unitframes.enable ~= true then return end
- -- Update Unit Frames
- self:UpdatePlayerFrame();
- self:UpdateTargetFrame();
- self:UpdateFocusFrame();
- self:UpdatePartyMembersFrame();
- self:UpdateArenaFrame();
- self:UpdateBossFrame();
- -- Set the Font for Unit Frames
- SetUnitFontStyle();
- -- Change other Texture to match player frame
- for _, region in pairs({
- TargetFrameNameBackground,
- FocusFrameNameBackground,
- Boss1TargetFrameNameBackground,
- Boss2TargetFrameNameBackground,
- Boss3TargetFrameNameBackground,
- Boss4TargetFrameNameBackground,
- }) do
- region:SetTexture([[Interface\DialogFrame\UI-DialogBox-Background]])
- end
- -- Disable healing/damage spam over player/pet frame:
- PlayerHitIndicator:SetText(nil)
- PlayerHitIndicator.SetText = function() end
- PetHitIndicator:SetText(nil)
- PetHitIndicator.SetText = function() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement