-- UI Scaler Addon - Improved Version -- Slash commands SLASH_UISRESET1 = "/uis-reset" SlashCmdList.UISRESET = function() SetCVar("uiScale", 1.0) UIParent:SetScale(1.0) if UIScalerDB then UIScalerDB.savedScale = 1.0 end end SLASH_UIS1 = "/uis" SlashCmdList.UIS = function() -- MainFrame local UIConfig = CreateFrame("Frame", "UIScale", UIParent, "BasicFrameTemplateWithInset") UIConfig:SetSize(500, 200) UIConfig:SetPoint("CENTER", UIParent, "CENTER") UIConfig:SetScale(0.9) -- Movable UIConfig:SetMovable(true) UIConfig:SetClampedToScreen(true) UIConfig:SetScript("OnMouseDown", function(self, button) if button == "LeftButton" then self:StartMoving() end end) UIConfig:SetScript("OnMouseUp", UIConfig.StopMovingOrSizing) -- Title UIConfig.title = UIConfig:CreateFontString(nil, "OVERLAY") UIConfig.title:SetFontObject("GameFontHighlight") UIConfig.title:SetPoint("CENTER", UIConfig.TitleBg, "CENTER", 5, 0) UIConfig.title:SetText("UI Scaler Options") -- Description UIConfig.description = UIConfig:CreateFontString(nil, "OVERLAY") UIConfig.description:SetFontObject("GameFontHighlight") UIConfig.description:SetPoint("CENTER", UIConfig, "TOP", 0, -40) UIConfig.description:SetText("Number between 0.001 to 1.0") -- TextBox UIConfig.editFrame = CreateFrame("EditBox", nil, UIConfig, "InputBoxTemplate") UIConfig.editFrame:SetPoint("CENTER", UIConfig, "TOP", 0, -60) UIConfig.editFrame:SetWidth(180) UIConfig.editFrame:SetHeight(400) UIConfig.editFrame:SetAutoFocus(false) UIConfig.editFrame:SetMaxLetters(18) UIConfig.editFrame:SetText(UIScalerDB and UIScalerDB.savedScale or GetCVar("uiScale")) -- Auto Button UIConfig.saveButton = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate") UIConfig.saveButton:SetPoint("LEFT", UIConfig, "LEFT", 40, -45) UIConfig.saveButton:SetSize(140, 40) UIConfig.saveButton:SetText("Auto") UIConfig.saveButton:SetNormalFontObject("GameFontNormalLarge") UIConfig.saveButton:SetHighlightFontObject("GameFontHighlightLarge") UIConfig.saveButton:SetScript("OnMouseDown", function(self, button) local screenHeight = select(2, GetPhysicalScreenSize()) local newScale = 768 / screenHeight Scale(newScale) UIConfig.editFrame:SetText(UIScalerDB and UIScalerDB.savedScale or GetCVar("uiScale")) end) -- Save Button UIConfig.autoButton = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate") UIConfig.autoButton:SetPoint("RIGHT", UIConfig, "RIGHT", -40, -45) UIConfig.autoButton:SetSize(140, 40) UIConfig.autoButton:SetText("Save") UIConfig.autoButton:SetNormalFontObject("GameFontNormalLarge") UIConfig.autoButton:SetHighlightFontObject("GameFontHighlightLarge") UIConfig.autoButton:SetScript("OnMouseDown", function(self, button) local newScale = UIConfig.editFrame:GetText() or 1.0 if (newScale == 0) then newScale = 1 end Scale(newScale) UIConfig.editFrame:SetText(UIScalerDB and UIScalerDB.savedScale or GetCVar("uiScale")) end) end -- Enhanced Scale function with persistence function Scale(scaleNumber) local numberedScale = tonumber(scaleNumber) if (type(numberedScale) == "number") then if (numberedScale == 0 or numberedScale > 1) then numberedScale = 1.0 scaleNumber = 1.0 end -- Save to both CVar and our saved variables SetCVar("uiScale", scaleNumber) UIParent:SetScale(numberedScale) -- Initialize saved variables if needed if not UIScalerDB then UIScalerDB = {} end UIScalerDB.savedScale = numberedScale end end -- Enhanced event handling local UIScalerFrame = CreateFrame("Frame", "UIScalerEventFrame", UIParent) -- Register multiple events for better persistence UIScalerFrame:RegisterEvent("ADDON_LOADED") UIScalerFrame:RegisterEvent("PLAYER_ENTERING_WORLD") UIScalerFrame:RegisterEvent("PLAYER_LOGIN") UIScalerFrame:RegisterEvent("UI_SCALE_CHANGED") UIScalerFrame:RegisterEvent("LOADING_SCREEN_DISABLED") UIScalerFrame:RegisterEvent("VARIABLES_LOADED") -- Timer for delayed application (helps with timing issues) local scaleTimer local loginTimer local function ApplyDelayedScale() if UIScalerDB and UIScalerDB.savedScale then -- Multiple delayed attempts to overcome WoW's late scaling C_Timer.After(0.5, function() Scale(UIScalerDB.savedScale) end) C_Timer.After(2.0, function() Scale(UIScalerDB.savedScale) end) C_Timer.After(5.0, function() Scale(UIScalerDB.savedScale) end) end end local function ForceScaleOnFullLogin() if UIScalerDB and UIScalerDB.savedScale then -- Very aggressive reapplication for full game restarts for i = 1, 10 do C_Timer.After(i * 1.0, function() local currentScale = tonumber(GetCVar("uiScale")) if math.abs(currentScale - UIScalerDB.savedScale) > 0.001 then Scale(UIScalerDB.savedScale) end end) end end end UIScalerFrame:SetScript("OnEvent", function(self, event, addonName) if event == "ADDON_LOADED" and addonName == "!UIScale" then -- Initialize saved variables if not UIScalerDB then UIScalerDB = { savedScale = tonumber(GetCVar("uiScale")) or 1.0 } end elseif event == "VARIABLES_LOADED" then -- This fires when saved variables are fully loaded ApplyDelayedScale() elseif event == "PLAYER_ENTERING_WORLD" then -- Apply saved scale with slight delay ApplyDelayedScale() elseif event == "PLAYER_LOGIN" then -- This only fires on full login (not character switch) ForceScaleOnFullLogin() elseif event == "LOADING_SCREEN_DISABLED" then -- Apply scale when loading screen finishes ApplyDelayedScale() elseif event == "UI_SCALE_CHANGED" then -- If WoW changes the scale, reapply ours after a short delay if scaleTimer then scaleTimer:Cancel() end scaleTimer = C_Timer.NewTimer(1.0, function() if UIScalerDB and UIScalerDB.savedScale then local currentScale = tonumber(GetCVar("uiScale")) if math.abs(currentScale - UIScalerDB.savedScale) > 0.001 then Scale(UIScalerDB.savedScale) end end end) end end) -- Force scale application slash command for testing SLASH_UISFORCE1 = "/uis-force" SlashCmdList.UISFORCE = function() if UIScalerDB and UIScalerDB.savedScale then Scale(UIScalerDB.savedScale) end end