local MyrroUI = LibStub("AceAddon-3.0"):NewAddon("MyrroUI", "AceConsole-3.0", "AceEvent-3.0", "LibUtilities-1.0")
MyrroUI:SetDefaultModuleLibraries("AceConsole-3.0", "AceEvent-3.0", "LibUtilities-1.0")
local L = LibStub("AceLocale-3.0"):GetLocale("MyrroUI", true)
local version = GetAddOnMetadata("MyrroUI", "Version")
-- if SVN checkout, replace version text --------
if version:match("@") then
version = L["Developer"]
end
-- upvalues & calculations ----------------------
local installerWidth = UIParent:GetWidth() / 2
local installerHeight = UIParent:GetHeight() / 2
local addonName = "MyrroUI " .. version
-- load additional libraries --------------------
local LSM = LibStub("LibSharedMedia-3.0")
local LDB = LibStub("LibDataBroker-1.1")
local DBI = LibStub("LibDBIcon-1.0")
local LWD = LibStub("LibWindow-1.1")
-- register Roman font with SharedMedia ---------
LSM:Register("font", "Roman", "Interface\\AddOns\\MyrroUI\\Fonts\\Roman SD.ttf")
-- create defaults ------------------------------
local defaults = {
profile = {
enabled = true,
firstRun = true,
uiScale = 1,
modules = {
["**"] = {
enabled = true
}
},
installer = {
x = 0,
y = 0,
scale = 1
}
},
global = {
pixelPerfect = false,
minimap = {
hide = false,
lock = false,
minimapPos = 205,
radius = 80
}
}
}
-- run with OnInitialize ------------------------
local function SetUglyScale()
SetCVar("useUiScale", "1")
SetCVar("uiScale", "1")
UIParent:SetScale(1)
end
function MyrroUI:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("MyrroUI_DB", defaults, true)
self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
-- set enabled state for MyrroUI and any modules
self:SetEnabledState(self.db.profile.enabled)
self.options = self:OptionsTable() -- see MUI_Options.lua
self.options.args.profilesTab = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
self.options.args.profilesTab.order = 1
-- Register your options with AceConfigRegistry
LibStub("AceConfig-3.0"):RegisterOptionsTable("MyrroUI", self.options, {"mui", "myrroui"})
-- slash commands ---------------------------
self:RegisterChatCommand("mui", "SlashHandler")
self:RegisterChatCommand("myrroui", "SlashHandler")
-- Add your options to the Blizz options window using AceConfigDialog
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyrroUI", "MyrroUI")
-- support for LibAboutPanel
self.optionsFrame[L["About"]] = LibStub("LibAboutPanel").new("MyrroUI", "MyrroUI")
-- create Data Broker -----------------------
local MyrroUIBroker = LDB:NewDataObject("MyrroUI", {
type = "launcher",
label = "MyrroUI",
icon = "Interface\\AddOns\\MyrroUI\\Icons\\CogWheel.tga",
OnClick = function(_, button)
if button == "LeftButton" then
if LibStub("AceConfigDialog-3.0").OpenFrames["MyrroUI"] then
LibStub("AceConfigDialog-3.0"):Close("MyrroUI")
else
LibStub("AceConfigDialog-3.0"):Open("MyrroUI")
end
elseif button == "RightButton" then
if self.installer:IsShown() then
self.installer:Hide()
else
self.installer:Show()
end
end
end,
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then return end
tooltip:AddLine("MyrroUI")
tooltip:AddLine(L["Left click to open options."])
tooltip:AddLine(L["Right click to show/hide installer."])
end,
})
DBI:Register("MyrroUI", MyrroUIBroker, self.db.global.minimap)
-- compliments of Phanx ---------------------
-- auto expand the sub panels ---------------
do
self.optionsFrame:HookScript("OnShow", function(self)
if InCombatLockdown() then return end
local target = self.parent or self.name
local i = 1
local button = _G["InterfaceOptionsFrameAddOnsButton"..i]
while button do
local element = button.element
if element.name == target then
if element.hasChildren and element.collapsed then
_G["InterfaceOptionsFrameAddOnsButton"..i.."Toggle"]:Click()
end
return
end
i = i + 1
button = _G["InterfaceOptionsFrameAddOnsButton"..i]
end
end)
local function OnClose(self)
if InCombatLockdown() then return end
local target = self.parent or self.name
local i = 1
local button = _G["InterfaceOptionsFrameAddOnsButton"..i]
while button do
local element = button.element
if element.name == target then
if element.hasChildren and not element.collapsed then
local selection = InterfaceOptionsFrameAddOns.selection
if not selection or selection.parent ~= target then
_G["InterfaceOptionsFrameAddOnsButton"..i.."Toggle"]:Click()
end
end
return
end
i = i + 1
button = _G["InterfaceOptionsFrameAddOnsButton"..i]
end
end
hooksecurefunc(self.optionsFrame, "okay", OnClose)
hooksecurefunc(self.optionsFrame, "cancel", OnClose)
end
self.installer = self.installer or self:CreateInstaller()
self.installer:Hide()
LWD.SavePosition(self.installer)
SetCVar("useUiScale", "1")
end
function MyrroUI:OnEnable()
-- set ugly ass UI pixel so it purposely looks bad
-- will fix it very soon!
if self.db.profile.firstRun then
SetUglyScale()
self.installer:Show()
self.db.profile.firstRun = false
else
SetCVar("uiScale", tostring(self.db.profile.uiScale))
end
for name, module in self:IterateModules() do
module:SetEnabledState(self.db.profile.modules["**"].enabled)
end
-- LibWindow stuff --------------------------
LWD.RegisterConfig(self.installer, self.db.profile.installer)
LWD.SetScale(self.installer, self.db.profile.installer.scale)
LWD.MakeDraggable(self.installer)
LWD.EnableMouseOnAlt(self.installer)
local p = self.db.profile.installer
if not p.libWindowed then
p.x = p.x / UIParent:GetScale()
p.y = p.y / UIParent:GetScale()
p.libWindowed = true
end
LWD.RestorePosition(self.installer)
end
function MyrroUI:OnDisable()
for name, module in self:IterateModules() do
module:SetEnabledState(false)
end
self.installer:Hide()
LWD.SavePosition(self.installer)
end
-- profile callbacks ----------------------------
function MyrroUI:RefreshConfig()
LWD.RegisterConfig(self.installer, self.db.profile.installer)
LWD.RestorePosition(self.installer)
end
-- slash commands -------------------------------
function MyrroUI:SlashHandler(input)
if InCombatLockdown() then
self:Print(L["Cannot access options during combat."])
return
end
if not input or input:trim() == "" then
LibStub("AceConfigDialog-3.0"):Open("MyrroUI")
else
LibStub("AceConfigCmd-3.0").HandleCommand(MyrroUI, "mui", "myrroui", input)
end
end
function MyrroUI:Pixel()
if self.db.global.pixelPerfect then
return
end
local uiScale, resX, resY = self:VisualData()
self.db.profile.uiScale = uiScale
self.db.profile.resX = resX
self.db.profile.resY = resY
SetCVar("uiScale", tostring(uiScale))
SetCVar("useUiScale", "1")
-- WoW's scale doesn't go below 0.64 --------
-- so we force the issue on larger screens --
if resY >= 1200 then
UIParent:SetScale(uiScale)
end
LWD.SetScale(self.installer, uiScale)
LWD.SavePosition(self.installer)
--LWD.RestorePosition(self.installer)
self.db.global.pixelPerfect = true
end