forked from EllesmereGaming/EllesmereUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllesmereUI_Startup.lua
More file actions
195 lines (173 loc) · 7.67 KB
/
EllesmereUI_Startup.lua
File metadata and controls
195 lines (173 loc) · 7.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
-------------------------------------------------------------------------------
-- EllesmereUI_Startup.lua
-- Runs as early as possible (first file after the Lite framework).
-- Applies settings that the WoW engine caches at login time, before
-- other addon files or PLAYER_LOGIN handlers have a chance to run.
-------------------------------------------------------------------------------
local ADDON_NAME = ...
-------------------------------------------------------------------------------
-- Pixel-Perfect UI Scale
--
-- SavedVariables (EllesmereUIDB) aren't available at file scope — they load
-- at ADDON_LOADED. So we use events:
-- ADDON_LOADED -> DB is available. If we have a saved scale, apply it.
-- PLAYER_ENTERING_WORLD -> Blizzard has applied the user's CVar scale.
-- If no saved scale yet (first install / reset), snapshot
-- the user's current Blizzard scale and save it.
-------------------------------------------------------------------------------
do
local GetPhysicalScreenSize = GetPhysicalScreenSize
local dbReady = false
local scaleKnown = false -- true when ppUIScale was already saved
local function ApplyScaleSafe(scale)
if InCombatLockdown() then
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_REGEN_ENABLED")
f:SetScript("OnEvent", function(self)
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
UIParent:SetScale(scale)
if EllesmereUI and EllesmereUI.PP and EllesmereUI.PP.UpdateMult then
EllesmereUI.PP.UpdateMult()
end
end)
else
UIParent:SetScale(scale)
if EllesmereUI and EllesmereUI.PP and EllesmereUI.PP.UpdateMult then
EllesmereUI.PP.UpdateMult()
end
end
end
local function SyncMultOnly()
if EllesmereUI and EllesmereUI.PP then
if EllesmereUI.PP.UpdateMult then EllesmereUI.PP.UpdateMult() end
if EllesmereUI.PP.ResnapAllBorders then EllesmereUI.PP.ResnapAllBorders() end
end
end
local scaleFrame = CreateFrame("Frame")
scaleFrame:RegisterEvent("ADDON_LOADED")
scaleFrame:RegisterEvent("PLAYER_LOGIN")
scaleFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
scaleFrame:SetScript("OnEvent", function(self, event, addonName)
if event == "ADDON_LOADED" then
if addonName ~= ADDON_NAME then return end
self:UnregisterEvent("ADDON_LOADED")
dbReady = true
if not EllesmereUIDB then EllesmereUIDB = {} end
local _, physH = GetPhysicalScreenSize()
local perfect = 768 / physH
local function PixelBestSize()
return max(0.4, min(perfect, 1.15))
end
if EllesmereUIDB.ppUIScale then
-- Migrate 0.53 to exact pixel-perfect 0.5333...
if EllesmereUIDB.ppUIScale == 0.53 then
EllesmereUIDB.ppUIScale = 0.5333333333
end
scaleKnown = true
end
elseif event == "PLAYER_LOGIN" then
self:UnregisterEvent("PLAYER_LOGIN")
if scaleKnown and EllesmereUIDB.ppUIScale then
-- Returning user: single SetScale at PLAYER_LOGIN.
-- No timers, no repeated calls.
ApplyScaleSafe(EllesmereUIDB.ppUIScale)
return
end
-- First-time path: just sync mult for child addon OnEnable
if EllesmereUI and EllesmereUI.PP and EllesmereUI.PP.UpdateMult then
EllesmereUI.PP.UpdateMult()
end
elseif event == "PLAYER_ENTERING_WORLD" then
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
if not dbReady then return end
if not EllesmereUIDB then EllesmereUIDB = {} end
-- Returning user: scale was applied once at PLAYER_LOGIN,
-- nothing else needed.
if scaleKnown then return end
-- First install or reset: snapshot the user's Blizzard scale
if EllesmereUIDB.ppUIScale == nil then
local blizzScale = UIParent:GetScale()
local clamped = max(0.4, min(blizzScale, 1.15))
EllesmereUIDB.ppUIScale = clamped
EllesmereUIDB.ppUIScaleAuto = false
end
local scale = EllesmereUIDB.ppUIScale
if not scale then return end
-- First-time install: apply scale with safety net.
-- Apply scale multiple times to guarantee it sticks even on
-- slow machines where Blizzard may reset it during init.
if EllesmereUI and EllesmereUI.PP and EllesmereUI.PP.UpdateMult then
EllesmereUI.PP.UpdateMult()
end
ApplyScaleSafe(scale)
C_Timer.After(2, function()
if InCombatLockdown() then return end
if EllesmereUIDB and EllesmereUIDB.ppUIScale then
ApplyScaleSafe(EllesmereUIDB.ppUIScale)
end
SyncMultOnly()
end)
C_Timer.After(5, function()
if InCombatLockdown() then return end
if EllesmereUIDB and EllesmereUIDB.ppUIScale then
ApplyScaleSafe(EllesmereUIDB.ppUIScale)
end
SyncMultOnly()
end)
end
end)
end
-- Apply the saved combat text font immediately at file scope.
-- DAMAGE_TEXT_FONT must be set before the engine caches it at login.
-- CombatTextFont may not exist yet here, so we also hook ADDON_LOADED
-- to catch it as soon as it becomes available.
do
local function ApplyCombatTextFont()
local saved = EllesmereUIDB and EllesmereUIDB.fctFont
if not saved or type(saved) ~= "string" or saved == "" then return end
-- Resolve "smf:" prefixed SharedMedia font keys to actual paths
local fontPath = saved
local smName = saved:match("^smf:(.+)")
if smName then
local LSM = LibStub and LibStub("LibSharedMedia-3.0", true)
local fetched = LSM and LSM:Fetch("font", smName)
-- If the SM addon is missing or hasn't loaded yet, skip entirely
-- so Blizzard's default combat text font stays intact.
if not fetched then return end
fontPath = fetched
end
_G.DAMAGE_TEXT_FONT = fontPath
if _G.CombatTextFont then
_G.CombatTextFont:SetFont(fontPath, 120, "")
end
end
-- Apply immediately (sets DAMAGE_TEXT_FONT before engine caches it)
ApplyCombatTextFont()
-- Re-apply on ADDON_LOADED (our addon or Blizzard_CombatText), PLAYER_LOGIN,
-- and PLAYER_ENTERING_WORLD to cover all timing windows where the engine
-- may cache or reset the combat text font.
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:RegisterEvent("PLAYER_LOGIN")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event, addonName)
if event == "ADDON_LOADED" then
if addonName ~= ADDON_NAME and addonName ~= "Blizzard_CombatText" then
return
end
end
ApplyCombatTextFont()
if event == "PLAYER_LOGIN" then
self:UnregisterEvent("PLAYER_LOGIN")
elseif event == "PLAYER_ENTERING_WORLD" then
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
elseif event == "ADDON_LOADED" then
self:UnregisterEvent("ADDON_LOADED")
end
end)
end
-- /rl reload shortcut -- only
if not SlashCmdList["RL"] then
SlashCmdList["RL"] = function() ReloadUI() end
SLASH_RL1 = "/rl"
end