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 | -- Font Style | |
| 20 | local shorts = {
| |
| 21 | { 1e10, 1e9, "%.0fB" }, -- 10b+ as 12b
| |
| 22 | { 1e9, 1e9, "%.1fB" }, -- 1b+ as 8.3b
| |
| 23 | { 1e7, 1e6, "%.0fM" }, -- 10m+ as 14m
| |
| 24 | { 1e6, 1e6, "%.1fM" }, -- 1m+ as 7.4m
| |
| 25 | { 1e5, 1e3, "%.0fK" }, -- 100k+ as 840k
| |
| 26 | { 1e3, 1e3, "%.1fK" }, -- 1k+ as 2.5k
| |
| 27 | { 0, 1, "%d" }, -- < 1k as 974
| |
| 28 | } | |
| 29 | for i = 1, #shorts do | |
| 30 | shorts[i][4] = shorts[i][3] .. " (%.0f%%)" | |
| 31 | end | |
| 32 | ||
| 33 | ------------------------------------------------------------------------ | |
| 34 | ||
| 35 | local db, enabled | |
| 36 | ||
| 37 | function Module:OnEnable() | |
| 38 | if InCombatLockdown() then | |
| 39 | return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
| |
| 40 | end | |
| 41 | self:UnregisterEvent("PLAYER_REGEN_ENABLED")
| |
| 42 | ||
| 43 | db = Core.db.profile | |
| 44 | ||
| 45 | if enabled or not db.unitframes.enable then return end | |
| 46 | enabled = true -- since most of this stuff is non-undoable (eg. hooksecurefunc) | |
| 47 | ||
| 48 | -- Update Unit Frames | |
| 49 | for unit, func in pairs(self.UnitFunctions) do | |
| 50 | if db.unitframes[unit].enable then | |
| 51 | func(self) | |
| 52 | end | |
| 53 | end | |
| 54 | ||
| 55 | -- Change other frames' name backgrounds to match player frame | |
| 56 | for _, region in pairs({
| |
| 57 | TargetFrameNameBackground, | |
| 58 | FocusFrameNameBackground, | |
| 59 | Boss1TargetFrameNameBackground, | |
| 60 | Boss2TargetFrameNameBackground, | |
| 61 | Boss3TargetFrameNameBackground, | |
| 62 | Boss4TargetFrameNameBackground, | |
| 63 | }) do | |
| 64 | region:SetTexture(0, 0, 0, 0.5) | |
| 65 | end | |
| 66 | ||
| 67 | -- Font Style / Color thanks to Phanx from WoWinterface. | |
| 68 | hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
| |
| 69 | if value == 0 then | |
| 70 | return fontString:SetText("")
| |
| 71 | end | |
| 72 | ||
| 73 | local style = GetCVar("statusTextDisplay")
| |
| 74 | if style == "PERCENT" then | |
| 75 | return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
| |
| 76 | end | |
| 77 | for i = 1, #shorts do | |
| 78 | local t = shorts[i] | |
| 79 | if value >= t[1] then | |
| 80 | if style == "BOTH" then | |
| 81 | return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100) | |
| 82 | else | |
| 83 | if value < valueMax then | |
| 84 | for j = 1, #shorts do | |
| 85 | local v = shorts[j] | |
| 86 | if valueMax >= v[1] then | |
| 87 | return fontString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2]) | |
| 88 | end | |
| 89 | end | |
| 90 | end | |
| 91 | return fontString:SetFormattedText(t[3], value / t[2]) | |
| 92 | end | |
| 93 | end | |
| 94 | end | |
| 95 | end) | |
| 96 | ||
| 97 | -- Font Color | |
| 98 | hooksecurefunc("UnitFrame_Update", function(self, isParty)
| |
| 99 | if not self.name or not self:IsShown() then return end | |
| 100 | ||
| 101 | local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
| |
| 102 | local unit, color = self.unit | |
| 103 | if UnitPlayerControlled(unit) then | |
| 104 | if UnitIsPlayer(unit) then | |
| 105 | local _, class = UnitClass(unit) | |
| 106 | color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class] | |
| 107 | else | |
| 108 | color = PET_COLOR | |
| 109 | end | |
| 110 | elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then | |
| 111 | color = GRAY_FONT_COLOR | |
| 112 | else | |
| 113 | color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5] | |
| 114 | end | |
| 115 | ||
| 116 | if not color then | |
| 117 | color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"] | |
| 118 | end | |
| 119 | ||
| 120 | self.name:SetTextColor(color.r, color.g, color.b) | |
| 121 | if isParty then | |
| 122 | self.name:SetText(GetUnitName(self.overrideName or unit)) | |
| 123 | end | |
| 124 | end) | |
| 125 | end | |
| 126 | ||
| 127 | ------------------------------------------------------------------------ | |
| 128 | ||
| 129 | Module.UnitFunctions = {
| |
| 130 | ||
| 131 | player = function(self) | |
| 132 | PlayerFrame:SetScale(db.unitframes.player.scale) | |
| 133 | PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE") | |
| 134 | PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE") | |
| 135 | PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE") | |
| 136 | ||
| 137 | PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE") | |
| 138 | PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE") | |
| 139 | ||
| 140 | -- Disable healing/damage spam over player/pet frame: | |
| 141 | PlayerHitIndicator:SetText(nil) | |
| 142 | PlayerHitIndicator.SetText = function() end | |
| 143 | PetHitIndicator:SetText(nil) | |
| 144 | PetHitIndicator.SetText = function() end | |
| 145 | end, | |
| 146 | ||
| 147 | target = function(self) | |
| 148 | TargetFrame:SetScale(db.unitframes.target.scale) | |
| 149 | TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE") | |
| 150 | TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE") | |
| 151 | end, | |
| 152 | ||
| 153 | focus = function(self) | |
| 154 | FocusFrame:SetScale(db.unitframes.focus.scale) | |
| 155 | FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE") | |
| 156 | FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE") | |
| 157 | end, | |
| 158 | ||
| 159 | party = function(self) | |
| 160 | for i = 1, MAX_PARTY_MEMBERS do | |
| 161 | local partyFrame = "PartyMemberFrame"..i | |
| 162 | _G[partyFrame]:SetScale(db.unitframes.party.scale) | |
| 163 | _G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE") | |
| 164 | _G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE") | |
| 165 | end | |
| 166 | end, | |
| 167 | ||
| 168 | arena = function(self) | |
| 169 | for i = 1, MAX_ARENA_ENEMIES do | |
| 170 | local prepFrame = "ArenaPrepFrame"..i | |
| 171 | _G[prepFrame]:SetScale(db.unitframes.arena.scale) | |
| 172 | _G[prepFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE") | |
| 173 | _G[prepFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE") | |
| 174 | ||
| 175 | local arenaFrame = "ArenaEnemyFrame"..i | |
| 176 | _G[arenaFrame]:SetScale(db.unitframes.arena.scale) | |
| 177 | _G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE") | |
| 178 | _G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE") | |
| 179 | end | |
| 180 | end, | |
| 181 | ||
| 182 | boss = function(self) | |
| 183 | for i = 1, MAX_BOSS_FRAMES do | |
| 184 | local bossFrame = "Boss"..i.."TargetFrame" | |
| 185 | _G[bossFrame]:SetScale(db.unitframes.boss.scale) | |
| 186 | end | |
| 187 | end, | |
| 188 | ||
| 189 | } |