Files
hide-coa-ui/HideCoA.lua
T

152 lines
3.6 KiB
Lua

HideCoA = {}
local f = CreateFrame("Frame")
HideCoA.CUSTOM_CLASSES = {
"NECROMANCER",
"PYROMANCER",
"CULTIST",
"STARCALLER",
"SUNCLERIC",
"TINKER",
"SPIRITMAGE",
"WILDWALKER",
"REAPER",
"PROPHET",
"CHRONOMANCER",
"SONOFARUGAL",
"GUARDIAN",
"STORMBRINGER",
"DEMONHUNTER",
"BARBARIAN",
"WITCHDOCTOR",
"WITCHHUNTER",
"FLESHWARDEN",
"MONK",
"RANGER",
}
HideCoA.FRAMES = {
"CoAResourceSegmentBar",
"CoAResourceOrb",
"CoAResourceBar",
}
local function ShouldHideForClass(playerClass, frameName)
local classSettings = HideCoADB.classSettings[playerClass]
if not classSettings or classSettings[frameName] == nil then
return true
end
return classSettings[frameName]
end
local hookedFrames = {}
local seenNaturalShow = {}
local function ApplySetting()
local _, playerClass = UnitClass("player")
for _, frameName in ipairs(HideCoA.FRAMES) do
local frame = _G[frameName]
if frame then
if not hookedFrames[frameName] then
frame:HookScript("OnShow", function(self)
seenNaturalShow[frameName] = true
local _, currentClass = UnitClass("player")
if ShouldHideForClass(currentClass, frameName) then
self:Hide()
end
end)
hookedFrames[frameName] = true
end
local hide = ShouldHideForClass(playerClass, frameName)
if hide then
frame:Hide()
elseif seenNaturalShow[frameName] then
-- The server never Show()s a frame the current class doesn't use,
-- so its data (powerType, maxValue, ...) is never populated. Forcing
-- Show() on it exposes that uninitialized state and crashes the
-- server's own OnUpdate handler. Only force-show a frame we've
-- already seen the game display naturally at least once.
frame:Show()
end
if frame.EnableMouse then
frame:EnableMouse(not hide)
end
end
end
end
HideCoA.ApplySetting = ApplySetting
f:RegisterEvent("ADDON_LOADED")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "HideCoA" then
if not HideCoADB then
HideCoADB = {}
end
if not HideCoADB.classSettings then
HideCoADB.classSettings = {}
end
for _, class in ipairs(HideCoA.CUSTOM_CLASSES) do
if type(HideCoADB.classSettings[class]) ~= "table" then
HideCoADB.classSettings[class] = {}
end
for _, frameName in ipairs(HideCoA.FRAMES) do
if HideCoADB.classSettings[class][frameName] == nil then
HideCoADB.classSettings[class][frameName] = true
end
end
end
if not HideCoADB.profiles then
HideCoADB.profiles = {}
end
if not HideCoADB.profiles["Default"] then
HideCoADB.profiles["Default"] = {}
end
local realmCharProfile = GetRealmName() .. " - " .. UnitName("player")
if not HideCoADB.profiles[realmCharProfile] then
HideCoADB.profiles[realmCharProfile] = {}
end
if not HideCoADB.selectedProfile then
HideCoADB.selectedProfile = "Default"
end
elseif event == "PLAYER_LOGIN" then
ApplySetting()
end
end)