2026-11-21 12:10:42 -06:00
|
|
|
local _, P = ...
|
|
|
|
|
|
|
|
|
|
-- Use Blizzard's collection, session selector and localized view menus. No
|
|
|
|
|
-- combat-log parser, secure handler replacement or per-frame layout polling.
|
|
|
|
|
local owns, place, edge, put, queue
|
|
|
|
|
local busy, queued, managed, hooked = false, false, nil, {}
|
|
|
|
|
|
|
|
|
|
local function editing()
|
|
|
|
|
return EditModeManagerFrame and EditModeManagerFrame:IsShown()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function mode()
|
2026-11-21 16:24:58 -06:00
|
|
|
return (RuenUICharacter and RuenUICharacter.damageMeterMode) or (RuenUIDB and RuenUIDB.damageMeterMode) or "auto"
|
2026-11-21 12:10:42 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function P.WantsDamageMeters()
|
|
|
|
|
if mode() == "off" then return false end
|
|
|
|
|
if mode() == "show" then return true end
|
|
|
|
|
local inside, kind = IsInInstance()
|
|
|
|
|
return inside and (kind == "party" or kind == "raid") or false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function snapshot(meter)
|
|
|
|
|
local old = {visibility = meter.visibility,
|
|
|
|
|
layout = EditModeManagerFrame.layoutInfo.activeLayout,
|
|
|
|
|
width = meter:GetWidth(), height = meter:GetHeight(), points = {}}
|
|
|
|
|
for i = 1, meter:GetNumPoints() do old.points[i] = {meter:GetPoint(i)} end
|
|
|
|
|
return old
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Never assign meter.visibility/systemInfo or call its Lua refresh methods.
|
|
|
|
|
-- Even out of combat, those writes taint the later native session timer.
|
|
|
|
|
-- Serialize a detached layout through the engine; Blizzard applies the resulting
|
|
|
|
|
-- EDIT_MODE_LAYOUTS_UPDATED event in its own clean execution context.
|
|
|
|
|
local function setVisibility(value)
|
|
|
|
|
local info = P.CopyEditModeLayouts()
|
|
|
|
|
local layout = info.layouts and info.layouts[info.activeLayout]
|
|
|
|
|
if not P.IsOurLayout(layout) then return false end
|
|
|
|
|
for _, system in ipairs(layout.systems or {}) do
|
|
|
|
|
if system.system == Enum.EditModeSystem.DamageMeter then
|
|
|
|
|
local key = Enum.EditModeDamageMeterSetting.Visibility
|
|
|
|
|
local setting
|
|
|
|
|
for _, item in ipairs(system.settings or {}) do
|
|
|
|
|
if item.setting == key then setting = item; break end
|
|
|
|
|
end
|
|
|
|
|
if setting and setting.value == value then return true end
|
|
|
|
|
if setting then setting.value = value else
|
|
|
|
|
system.settings = system.settings or {}
|
|
|
|
|
system.settings[#system.settings + 1] = {setting = key, value = value}
|
|
|
|
|
end
|
|
|
|
|
P.SaveEditModeLayouts(info)
|
|
|
|
|
return true, true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function release()
|
|
|
|
|
local meter, old = DamageMeter, managed
|
|
|
|
|
managed = nil
|
|
|
|
|
if not meter or not old then return end
|
|
|
|
|
-- A different layout may have already supplied its own anchors/settings.
|
|
|
|
|
local manager = EditModeManagerFrame
|
|
|
|
|
local sameLayout = manager.layoutInfo.activeLayout == old.layout
|
|
|
|
|
and P.IsOurLayout(manager:GetActiveLayoutInfo())
|
|
|
|
|
if sameLayout then
|
|
|
|
|
meter:SetSize(old.width, old.height)
|
|
|
|
|
local clear, set = meter.ClearAllPointsBase or meter.ClearAllPoints, meter.SetPointBase or meter.SetPoint
|
|
|
|
|
clear(meter)
|
|
|
|
|
for _, p in ipairs(old.points) do set(meter, unpack(p)) end
|
|
|
|
|
if not editing() and old.visibility ~= nil then setVisibility(old.visibility) end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function hookMeter(meter)
|
|
|
|
|
if hooked[meter] then return end
|
|
|
|
|
hooked[meter] = true
|
|
|
|
|
-- Native Edit Mode can reapply visibility/geometry at login or on layout
|
|
|
|
|
-- changes. Reconcile later, outside its call stack; never rewrite systemInfo.
|
|
|
|
|
for _, method in ipairs({"UpdateSystemSettingVisibility", "OnUpdateSystem"}) do
|
|
|
|
|
if meter[method] then hooksecurefunc(meter, method, queue) end
|
|
|
|
|
end
|
|
|
|
|
meter:HookScript("OnSizeChanged", queue)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function P.PositionDamageMeters()
|
|
|
|
|
local meter = DamageMeter
|
|
|
|
|
if not meter or not managed or InCombatLockdown() or editing() then return end
|
|
|
|
|
local obstacles = {}
|
|
|
|
|
for _, r in ipairs(P.OverlayObstacles(false)) do
|
|
|
|
|
if r.name ~= "DamageMeter" then obstacles[#obstacles + 1] = r end
|
|
|
|
|
end
|
|
|
|
|
-- Preserve the central play field. Prefer the right edge above utility
|
|
|
|
|
-- buttons, then the nearest genuinely free rectangle in the existing HUD.
|
|
|
|
|
local x = (edge(P.UtilityTop(), "GetRight") or UIParent:GetWidth() - 22) - 260
|
|
|
|
|
local y = (edge(P.UtilityTop(), "GetTop") or 260) + 12
|
|
|
|
|
local target, width, height
|
|
|
|
|
for _, size in ipairs({{260, 172}, {240, 152}, {220, 132}}) do
|
|
|
|
|
width, height = size[1], size[2]
|
|
|
|
|
target = P.FindOverlayPosition(width, height, x, y, obstacles, UIParent:GetWidth(), UIParent:GetHeight())
|
|
|
|
|
if target then break end
|
|
|
|
|
end
|
|
|
|
|
if not target then
|
|
|
|
|
-- Never cover an action or unit frame if an exceptionally crowded
|
|
|
|
|
-- layout cannot fit even the compact window. Retry after layout events.
|
|
|
|
|
RuenUICharacter.damageMeterStatus.reason = "no free space"
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
local ratio = meter:GetEffectiveScale() / UIParent:GetEffectiveScale()
|
|
|
|
|
local changed = math.abs(meter:GetWidth() * ratio - width) > .5
|
|
|
|
|
or math.abs(meter:GetHeight() * ratio - height) > .5
|
|
|
|
|
if changed then meter:SetSize(width / ratio, height / ratio) end
|
|
|
|
|
local left, bottom = edge(meter, "GetLeft"), edge(meter, "GetBottom")
|
|
|
|
|
if not left or not bottom or math.abs(left - target.left) > .5 or math.abs(bottom - target.bottom) > .5 then
|
|
|
|
|
place(meter, "BOTTOMLEFT", UIParent, "BOTTOMLEFT", target.left, target.bottom)
|
|
|
|
|
end
|
|
|
|
|
RuenUICharacter.damageMeterStatus.rect = target
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function P.RefreshDamageMeters()
|
|
|
|
|
if busy or not owns then return end
|
|
|
|
|
if InCombatLockdown() then
|
|
|
|
|
P.damageMeterListener:RegisterEvent("PLAYER_REGEN_ENABLED")
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
busy = true
|
|
|
|
|
local meter = DamageMeter
|
|
|
|
|
if not owns() or editing() then
|
|
|
|
|
release()
|
|
|
|
|
elseif meter and Enum.DamageMeterVisibility and C_DamageMeter then
|
|
|
|
|
hookMeter(meter)
|
|
|
|
|
if not managed then managed = snapshot(meter) end
|
|
|
|
|
local want = P.WantsDamageMeters()
|
|
|
|
|
if want and C_CVar.GetCVar("damageMeterEnabled") ~= "1" then
|
|
|
|
|
RuenUIDB.results = RuenUIDB.results or {}
|
|
|
|
|
put("damageMeterEnabled", 1)
|
|
|
|
|
end
|
|
|
|
|
local available, reason = C_DamageMeter.IsDamageMeterAvailable()
|
|
|
|
|
RuenUICharacter.damageMeterStatus = {mode = mode(), requested = want, available = available, reason = reason}
|
|
|
|
|
local show = want and available and P.PositionDamageMeters()
|
|
|
|
|
local ready, changed = setVisibility(show and Enum.DamageMeterVisibility.Always or Enum.DamageMeterVisibility.Hidden)
|
|
|
|
|
if not ready then
|
|
|
|
|
RuenUICharacter.damageMeterStatus.reason = "native layout not ready"
|
|
|
|
|
end
|
|
|
|
|
-- Selecting the serialized layout can also restore its saved anchors.
|
|
|
|
|
if changed and show then P.PositionDamageMeters() end
|
|
|
|
|
RuenUICharacter.damageMeterStatus.shown = meter:IsShown()
|
|
|
|
|
if issecurevariable then
|
|
|
|
|
RuenUICharacter.damageMeterStatus.nativeVisibilitySecure = issecurevariable(meter, "visibility")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
RuenUICharacter.damageMeterStatus = {mode = mode(), reason = "native meter unavailable"}
|
|
|
|
|
end
|
|
|
|
|
busy = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function P.StopDamageMeters()
|
|
|
|
|
if InCombatLockdown() then return end
|
|
|
|
|
busy = true
|
|
|
|
|
release()
|
|
|
|
|
busy = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function P.DamageMeterCommand(argument)
|
|
|
|
|
if argument == "auto" or argument == "show" or argument == "off" then
|
2026-11-21 16:24:58 -06:00
|
|
|
RuenUICharacter.damageMeterMode = argument
|
2026-11-21 12:10:42 -06:00
|
|
|
P.RefreshDamageMeters()
|
|
|
|
|
end
|
|
|
|
|
return P.Localized("Damage meter: ", "Счётчик урона: ") .. mode() .. P.Localized(
|
|
|
|
|
". /ruen meters auto (dungeons/raids), show (everywhere), off. Changes during combat wait until it ends.",
|
|
|
|
|
". /ruen meters auto (подземелья/рейды), show (везде), off (скрыть). Изменения в бою применяются после боя.")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function P.InitializeDamageMeters(isOurs, placeFrame, frameEdge, setCVar)
|
|
|
|
|
owns, place, edge, put = isOurs, placeFrame, frameEdge, setCVar
|
|
|
|
|
if P.damageMeterListener then return end
|
|
|
|
|
local listener = CreateFrame("Frame")
|
|
|
|
|
P.damageMeterListener = listener
|
|
|
|
|
queue = function()
|
|
|
|
|
if busy or queued then return end
|
|
|
|
|
queued = true
|
|
|
|
|
C_Timer.After(.2, function()
|
|
|
|
|
queued = false
|
|
|
|
|
P.RefreshDamageMeters()
|
|
|
|
|
if P.PositionOverlayFrames then P.PositionOverlayFrames() end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
for _, event in ipairs({"PLAYER_ENTERING_WORLD", "ZONE_CHANGED_NEW_AREA", "GROUP_ROSTER_UPDATE",
|
|
|
|
|
"PLAYER_REGEN_ENABLED", "ADDON_LOADED", "EDIT_MODE_LAYOUTS_UPDATED", "DISPLAY_SIZE_CHANGED", "UI_SCALE_CHANGED", "PLAYER_LEVEL_UP"}) do
|
|
|
|
|
listener:RegisterEvent(event)
|
|
|
|
|
end
|
|
|
|
|
listener:SetScript("OnEvent", queue)
|
|
|
|
|
if EditModeManagerFrame then
|
|
|
|
|
EditModeManagerFrame:HookScript("OnShow", queue)
|
|
|
|
|
EditModeManagerFrame:HookScript("OnHide", queue)
|
|
|
|
|
end
|
|
|
|
|
queue()
|
|
|
|
|
end
|