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
199 lines (179 loc) · 8.79 KB
/
EllesmereUI_Startup.lua
File metadata and controls
199 lines (179 loc) · 8.79 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
196
197
198
199
-------------------------------------------------------------------------------
-- 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.
-- If migrating from old system, convert and apply.
-- 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 pendingScale = nil -- scale to apply once the world is ready
local function ApplyScaleSafe(scale)
if InCombatLockdown() then
-- Defer until combat ends — UIParent:SetScale is protected in combat
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_REGEN_ENABLED")
f:SetScript("OnEvent", function(self)
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
UIParent:SetScale(scale)
-- UI_SCALE_CHANGED may not fire if scale didn't change; update mult directly
if EllesmereUI and EllesmereUI.PP and EllesmereUI.PP.UpdateMult then
EllesmereUI.PP.UpdateMult()
end
end)
else
UIParent:SetScale(scale)
-- UI_SCALE_CHANGED only fires when the value actually changes.
-- Always update mult so PP.Scale() stays correct even when the
-- scale was already set to this value.
if EllesmereUI and EllesmereUI.PP and EllesmereUI.PP.UpdateMult then
EllesmereUI.PP.UpdateMult()
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
-- Migration from old percentage-based blizzUIScale
if EllesmereUIDB.ppUIScale == nil and EllesmereUIDB.blizzUIScale then
EllesmereUIDB.ppUIScale = PixelBestSize()
EllesmereUIDB.ppUIScaleAuto = true
end
-- Apply saved scale immediately for non-migration cases
-- (returning users who already have ppUIScale set)
if EllesmereUIDB.ppUIScale then
pendingScale = EllesmereUIDB.ppUIScale
ApplyScaleSafe(pendingScale)
end
elseif event == "PLAYER_LOGIN" then
self:UnregisterEvent("PLAYER_LOGIN")
-- Update PP.mult before child addon OnEnable handlers run.
-- Child addons (UnitFrames, ActionBars) call PP.Scale/Size/Point
-- during OnEnable (which fires on PLAYER_LOGIN). If PP.mult is
-- still the file-load value at that point, all pixel-snapped
-- geometry is wrong until the next reload.
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 ADDON_LOADED hasn't fired yet (shouldn't happen, but safety)
if not dbReady then return end
if not EllesmereUIDB then EllesmereUIDB = {} 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
pendingScale = clamped
end
-- Re-apply scale now that the world is loaded, then again
-- after a short delay to beat any Blizzard resets
local scale = EllesmereUIDB.ppUIScale
if scale then
-- Update PP.mult immediately so any frames built between now
-- and the timer passes use the correct pixel multiplier.
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
-- Always update PP.mult — UI_SCALE_CHANGED only fires when
-- the scale value changes, so if Blizzard reset and re-set
-- the same value the event never fires and mult stays stale.
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)
-- Second pass: catch any borders created late (e.g. lazy-init frames)
C_Timer.After(5, function()
if InCombatLockdown() then return end
if EllesmereUIDB and EllesmereUIDB.ppUIScale then
ApplyScaleSafe(EllesmereUIDB.ppUIScale)
end
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)
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
-- Migrate old media path if needed
if EllesmereUIDB and EllesmereUIDB.fctFont and type(EllesmereUIDB.fctFont) == "string" then
EllesmereUIDB.fctFont = EllesmereUIDB.fctFont:gsub("\\media\\Expressway", "\\media\\fonts\\Expressway")
end
local function ApplyCombatTextFont()
local saved = EllesmereUIDB and EllesmereUIDB.fctFont
if not saved or type(saved) ~= "string" or saved == "" then return end
_G.DAMAGE_TEXT_FONT = saved
if _G.CombatTextFont then
_G.CombatTextFont:SetFont(saved, 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 register if nothing else has claimed it
if not SlashCmdList["RL"] then
SlashCmdList["RL"] = function() ReloadUI() end
SLASH_RL1 = "/rl"
end