mirror of
https://codeberg.org/Duvelcorp/MetaHunt.git
synced 2026-09-30 11:30:03 +00:00
v1.1.0
This commit is contained in:
@@ -14,6 +14,71 @@ BINDING_HEADER_ZToysHeader = "ZToys Buttons"
|
||||
ZHunterModTooltip = CreateFrame("GameTooltip", "ZHunterModScan", nil, "GameTooltipTemplate")
|
||||
ZHunterModTooltipTextLeft1 = getglobal("ZHunterModScanTextLeft1")
|
||||
|
||||
MTH_ZH_TRACE_ENABLED = false
|
||||
|
||||
local function MTH_ZH_DescribePoint(frame)
|
||||
if not (frame and frame.GetPoint) then
|
||||
return "<no-frame>"
|
||||
end
|
||||
local point, relTo, relPoint, x, y = frame:GetPoint()
|
||||
local relName = "nil"
|
||||
if type(relTo) == "table" and relTo.GetName then
|
||||
relName = tostring(relTo:GetName() or "<anon>")
|
||||
elseif relTo then
|
||||
relName = tostring(relTo)
|
||||
end
|
||||
return tostring(point or "nil")
|
||||
.. "->" .. relName
|
||||
.. ":" .. tostring(relPoint or "nil")
|
||||
.. " @(" .. tostring(x) .. "," .. tostring(y) .. ")"
|
||||
end
|
||||
|
||||
function MTH_ZH_Trace(msg)
|
||||
if not MTH_ZH_TRACE_ENABLED then
|
||||
return
|
||||
end
|
||||
if MTH and MTH.Print then
|
||||
MTH:Print("[ZHTRACE] " .. tostring(msg), "debug")
|
||||
elseif DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.AddMessage then
|
||||
DEFAULT_CHAT_FRAME:AddMessage("[ZHTRACE] " .. tostring(msg))
|
||||
end
|
||||
end
|
||||
|
||||
function MTH_ZH_TraceButtonPoint(frame, reason)
|
||||
if not MTH_ZH_TRACE_ENABLED then
|
||||
return
|
||||
end
|
||||
if not frame then
|
||||
MTH_ZH_Trace("point " .. tostring(reason or "") .. " frame=nil")
|
||||
return
|
||||
end
|
||||
local name = frame.GetName and frame:GetName() or "<unnamed>"
|
||||
MTH_ZH_Trace("point " .. tostring(reason or "") .. " " .. tostring(name) .. " " .. MTH_ZH_DescribePoint(frame))
|
||||
end
|
||||
|
||||
function MTH_ZH_TraceAllButtonPoints(reason)
|
||||
if not MTH_ZH_TRACE_ENABLED then
|
||||
return
|
||||
end
|
||||
local names = {
|
||||
"zButtonAspect",
|
||||
"zButtonAmmo",
|
||||
"zButtonTrack",
|
||||
"zButtonTrap",
|
||||
"zButtonRanged",
|
||||
"zButtonPet",
|
||||
"zButtonMounts",
|
||||
"zButtonCompanions",
|
||||
"zButtonToys",
|
||||
}
|
||||
MTH_ZH_Trace("snapshot begin reason=" .. tostring(reason or ""))
|
||||
for i = 1, table.getn(names) do
|
||||
local frame = getglobal(names[i])
|
||||
MTH_ZH_TraceButtonPoint(frame, tostring(reason or "") .. ":" .. tostring(names[i]))
|
||||
end
|
||||
MTH_ZH_Trace("snapshot end reason=" .. tostring(reason or ""))
|
||||
end
|
||||
|
||||
function MTH_ZH_IsModuleEnabled()
|
||||
if not (MTH and MTH.IsModuleEnabled) then
|
||||
return true
|
||||
@@ -105,6 +170,7 @@ function MTH_ZH_HandleDisabledSlash(message, tableKey, fieldKey)
|
||||
end
|
||||
|
||||
function ZHunterMod_AlignButtons()
|
||||
MTH_ZH_TraceAllButtonPoints("AlignButtons:before")
|
||||
zButtonAmmo:ClearAllPoints()
|
||||
zButtonAmmo:SetPoint("TOP", zButtonAspect, "BOTTOM", 0, -15)
|
||||
zButtonTrack:ClearAllPoints()
|
||||
@@ -123,6 +189,7 @@ function ZHunterMod_AlignButtons()
|
||||
AutoStripDisplay:ClearAllPoints()
|
||||
AutoStripDisplay:SetPoint("TOP", zButtonToys, "BOTTOM", 0, -10)
|
||||
end
|
||||
MTH_ZH_TraceAllButtonPoints("AlignButtons:after")
|
||||
end
|
||||
|
||||
function ZMarkTarget()
|
||||
|
||||
@@ -377,6 +377,94 @@ function ZSpellButton_ApplyChildrenExpanded(parent)
|
||||
ZSpellButton_SetChildrenExpanded(parent, ZSpellButton_GetChildrenExpanded(parent))
|
||||
end
|
||||
|
||||
local function ZSpellButton_SaveParentPosition(parent)
|
||||
if not (parent and parent.GetPoint) then
|
||||
return
|
||||
end
|
||||
if type(MTH_ZH_GetSavedTable) ~= "function" then
|
||||
return
|
||||
end
|
||||
local key = parent.name
|
||||
if (type(key) ~= "string" or key == "") and parent.GetName then
|
||||
key = parent:GetName()
|
||||
end
|
||||
if type(key) ~= "string" or key == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local saved = MTH_ZH_GetSavedTable(key)
|
||||
if type(saved) ~= "table" then
|
||||
return
|
||||
end
|
||||
if type(saved["parent"]) ~= "table" then
|
||||
saved["parent"] = {}
|
||||
end
|
||||
|
||||
local point, _, relPoint, x, y = parent:GetPoint()
|
||||
x = tonumber(x)
|
||||
y = tonumber(y)
|
||||
if not (point and relPoint and x and y) then
|
||||
return
|
||||
end
|
||||
|
||||
saved["parent"]["point"] = tostring(point)
|
||||
saved["parent"]["relativePoint"] = tostring(relPoint)
|
||||
saved["parent"]["x"] = math.floor(x + 0.5)
|
||||
saved["parent"]["y"] = math.floor(y + 0.5)
|
||||
if type(MTH_ZH_Trace) == "function" then
|
||||
MTH_ZH_Trace("persist-parent-position key=" .. tostring(key)
|
||||
.. " point=" .. tostring(saved["parent"]["point"])
|
||||
.. " rel=" .. tostring(saved["parent"]["relativePoint"])
|
||||
.. " x=" .. tostring(saved["parent"]["x"])
|
||||
.. " y=" .. tostring(saved["parent"]["y"]))
|
||||
end
|
||||
end
|
||||
|
||||
local function ZSpellButton_RestoreParentPosition(parent)
|
||||
if not (parent and parent.ClearAllPoints and parent.SetPoint) then
|
||||
return false
|
||||
end
|
||||
if type(MTH_ZH_GetSavedTable) ~= "function" then
|
||||
return false
|
||||
end
|
||||
local key = parent.name
|
||||
if (type(key) ~= "string" or key == "") and parent.GetName then
|
||||
key = parent:GetName()
|
||||
end
|
||||
if type(key) ~= "string" or key == "" then
|
||||
return false
|
||||
end
|
||||
|
||||
local saved = MTH_ZH_GetSavedTable(key)
|
||||
if type(saved) ~= "table" or type(saved["parent"]) ~= "table" then
|
||||
return false
|
||||
end
|
||||
|
||||
local parentSaved = saved["parent"]
|
||||
local px = tonumber(parentSaved["x"])
|
||||
local py = tonumber(parentSaved["y"])
|
||||
local point = parentSaved["point"]
|
||||
local relPoint = parentSaved["relativePoint"]
|
||||
if not (px and py and type(point) == "string" and point ~= "") then
|
||||
return false
|
||||
end
|
||||
|
||||
if type(relPoint) ~= "string" or relPoint == "" then
|
||||
relPoint = point
|
||||
end
|
||||
|
||||
parent:ClearAllPoints()
|
||||
parent:SetPoint(point, UIParent, relPoint, px, py)
|
||||
if type(MTH_ZH_Trace) == "function" then
|
||||
MTH_ZH_Trace("restore-parent-position key=" .. tostring(key)
|
||||
.. " point=" .. tostring(point)
|
||||
.. " rel=" .. tostring(relPoint)
|
||||
.. " x=" .. tostring(px)
|
||||
.. " y=" .. tostring(py))
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function ZSpellButton_OnEnter()
|
||||
ZSpellButton_EnsureParentFlags(this.parent)
|
||||
if this.parent.tooltip then
|
||||
@@ -479,6 +567,46 @@ function ZSpellButtonParent_OnLoad()
|
||||
this.circle = getglobal(name.."Circle")
|
||||
-- Keep enabled so empty buttons can be moved on low-level characters.
|
||||
this:Enable()
|
||||
ZSpellButton_RestoreParentPosition(this)
|
||||
if this.SetScript then
|
||||
this:SetScript("OnDragStart", function(self)
|
||||
self = self or this
|
||||
if IsAltKeyDown() then
|
||||
if type(MTH_ZH_TraceButtonPoint) == "function" then
|
||||
MTH_ZH_TraceButtonPoint(self, "drag-start")
|
||||
end
|
||||
self:StartMoving()
|
||||
self.isMoving = true
|
||||
end
|
||||
end)
|
||||
this:SetScript("OnDragStop", function(self)
|
||||
self = self or this
|
||||
if not self then
|
||||
return
|
||||
end
|
||||
if self.StopMovingOrSizing then
|
||||
self:StopMovingOrSizing()
|
||||
end
|
||||
ZSpellButton_SaveParentPosition(self)
|
||||
self.isMoving = false
|
||||
if type(MTH_ZH_TraceButtonPoint) == "function" then
|
||||
MTH_ZH_TraceButtonPoint(self, "drag-stop")
|
||||
end
|
||||
end)
|
||||
this:SetScript("OnMouseUp", function(self)
|
||||
self = self or this
|
||||
if self and self.isMoving then
|
||||
if self.StopMovingOrSizing then
|
||||
self:StopMovingOrSizing()
|
||||
end
|
||||
ZSpellButton_SaveParentPosition(self)
|
||||
self.isMoving = false
|
||||
if type(MTH_ZH_TraceButtonPoint) == "function" then
|
||||
MTH_ZH_TraceButtonPoint(self, "mouse-up-stop")
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButtonParent_OnEvent()
|
||||
|
||||
@@ -8,7 +8,7 @@ MTH_ZH_MANAGED_HOOKS = true
|
||||
local MTH_ZHunter = {
|
||||
name = "zhunter",
|
||||
enabled = true,
|
||||
version = "1.0.6",
|
||||
version = "1.1.0",
|
||||
events = {
|
||||
"VARIABLES_LOADED",
|
||||
"PLAYER_ENTERING_WORLD",
|
||||
@@ -31,6 +31,12 @@ local function MTH_ZH_Log(msg)
|
||||
MTH:Print("[ZH MODULE] " .. tostring(msg), "debug")
|
||||
end
|
||||
|
||||
local function MTH_ZH_TraceLocal(msg)
|
||||
if type(MTH_ZH_Trace) == "function" then
|
||||
MTH_ZH_Trace(msg)
|
||||
end
|
||||
end
|
||||
|
||||
local MTH_ZH_PostLoginRestoreFrame = nil
|
||||
local MTH_ZH_BootstrapFrame = nil
|
||||
local MTH_ZH_SyncSavedVariables
|
||||
@@ -105,7 +111,6 @@ function MTH_ZH_OnDeferredInitComplete()
|
||||
return
|
||||
end
|
||||
MTH_ZH_SyncSavedVariables()
|
||||
MTH_ZH_ApplyDefaultWidgetSpawnLayoutOnce()
|
||||
MTH_ZH_RestoreRuntimeFeatureFlags()
|
||||
MTH_ZH_QueuePostLoginRestore("deferred-init")
|
||||
end
|
||||
@@ -132,6 +137,9 @@ MTH_ZH_QueuePostLoginRestore = function(tag)
|
||||
|
||||
MTH_ZH_SyncSavedVariables()
|
||||
MTH_ZH_RestoreRuntimeFeatureFlags()
|
||||
if type(MTH_ZH_TraceAllButtonPoints) == "function" then
|
||||
MTH_ZH_TraceAllButtonPoints("post-login-restore:" .. tostring(tag))
|
||||
end
|
||||
MTH_ZH_Log("post-login restore applied: " .. tostring(tag))
|
||||
end)
|
||||
end
|
||||
@@ -170,10 +178,17 @@ local function MTH_ZH_EnsureBootstrapRestoreFrame()
|
||||
end
|
||||
|
||||
MTH_ZH_ApplyEnabledRuntimeState = function(source)
|
||||
MTH_ZH_TraceLocal("apply-enabled-runtime-state source=" .. tostring(source or ""))
|
||||
if type(MTH_ZH_TraceAllButtonPoints) == "function" then
|
||||
MTH_ZH_TraceAllButtonPoints("apply-enabled:before:" .. tostring(source or ""))
|
||||
end
|
||||
MTH_ZH_SyncSavedVariables()
|
||||
MTH_ZH_SetButtonsVisible(true)
|
||||
MTH_ZH_SetAuxFramesVisible(true)
|
||||
MTH_ZH_RestoreRuntimeFeatureFlags()
|
||||
if type(MTH_ZH_TraceAllButtonPoints) == "function" then
|
||||
MTH_ZH_TraceAllButtonPoints("apply-enabled:after:" .. tostring(source or ""))
|
||||
end
|
||||
end
|
||||
|
||||
MTH_ZH_SyncSavedVariables = function()
|
||||
@@ -182,17 +197,22 @@ MTH_ZH_SyncSavedVariables = function()
|
||||
end
|
||||
|
||||
local moduleStore = MTH:GetModuleCharSavedVariables("zhunter")
|
||||
MTH_ZH_TraceLocal("sync-saved begin zhuntermod_saved=" .. tostring(type(ZHunterMod_Saved)))
|
||||
|
||||
if type(ZHunterMod_Saved) == "table" then
|
||||
if MTH_CharSavedVariables and MTH_CharSavedVariables.modules then
|
||||
MTH_CharSavedVariables.modules.zhunter = ZHunterMod_Saved
|
||||
MTH_ZH_TraceLocal("sync-saved wrote ZHunterMod_Saved -> MTH_CharSavedVariables.modules.zhunter")
|
||||
end
|
||||
elseif type(moduleStore) == "table" then
|
||||
ZHunterMod_Saved = moduleStore
|
||||
MTH_ZH_TraceLocal("sync-saved loaded moduleStore -> ZHunterMod_Saved")
|
||||
end
|
||||
MTH_ZH_TraceLocal("sync-saved end")
|
||||
end
|
||||
|
||||
MTH_ZH_SetButtonsVisible = function(visible)
|
||||
MTH_ZH_TraceLocal("set-buttons-visible visible=" .. tostring(visible and true or false))
|
||||
local buttonNames = {
|
||||
"zButtonAspect",
|
||||
"zButtonTrack",
|
||||
@@ -274,12 +294,18 @@ MTH_ZH_SetButtonsVisible = function(visible)
|
||||
for _, buttonName in ipairs(buttonNames) do
|
||||
local button = getglobal(buttonName)
|
||||
if button then
|
||||
if type(MTH_ZH_TraceButtonPoint) == "function" then
|
||||
MTH_ZH_TraceButtonPoint(button, "set-buttons-visible:before:" .. tostring(buttonName))
|
||||
end
|
||||
MTH_ZH_SetChildButtonsVisible(button, buttonName, visible)
|
||||
if visible then
|
||||
button:Show()
|
||||
else
|
||||
button:Hide()
|
||||
end
|
||||
if type(MTH_ZH_TraceButtonPoint) == "function" then
|
||||
MTH_ZH_TraceButtonPoint(button, "set-buttons-visible:after:" .. tostring(buttonName))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -358,6 +384,7 @@ function MTH_ZHunter:init()
|
||||
end
|
||||
|
||||
function MTH_ZHunter:setEnabled(enabled)
|
||||
MTH_ZH_TraceLocal("module setEnabled enabled=" .. tostring(enabled and true or false))
|
||||
MTH_ZH_SyncSavedVariables()
|
||||
if enabled then
|
||||
MTH_ZH_EnsureBootstrapRestoreFrame()
|
||||
@@ -366,8 +393,14 @@ function MTH_ZHunter:setEnabled(enabled)
|
||||
else
|
||||
MTH_ZH_ClearRuntimeFeatureFlags()
|
||||
MTH_ZH_SetAdjustmentHandlersActive(false)
|
||||
if type(MTH_ZH_TraceAllButtonPoints) == "function" then
|
||||
MTH_ZH_TraceAllButtonPoints("setEnabled:false:before-hide")
|
||||
end
|
||||
MTH_ZH_SetButtonsVisible(false)
|
||||
MTH_ZH_SetAuxFramesVisible(false)
|
||||
if type(MTH_ZH_TraceAllButtonPoints) == "function" then
|
||||
MTH_ZH_TraceAllButtonPoints("setEnabled:false:after-hide")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -30,13 +30,14 @@ local ZHUNTER_AMMO_MAX_COUNT = math.max(table.getn(MTH_AMMO_ARROWS or {}), table
|
||||
local zButtonAmmo_Cache = {}
|
||||
local zButtonAmmo_LastCacheSignature = nil
|
||||
local zButtonAmmo_LastRefreshAt = 0
|
||||
local zButtonAmmo_MinRefreshInterval = 0.20
|
||||
local zButtonAmmo_MinRefreshInterval = 0.50
|
||||
local zButtonAmmo_MinBagRefreshInterval = 0.75
|
||||
local zButtonAmmo_KnownAmmoTypes = nil
|
||||
local zButtonAmmo_AmmoBags = {}
|
||||
local zButtonAmmo_LastFullScanAt = 0
|
||||
local zButtonAmmo_MinUnknownBagScanInterval = 5.0
|
||||
local zButtonAmmo_EmptyScanStreak = 0
|
||||
local zButtonAmmo_LastEquippedAmmoSeen = nil
|
||||
local zButtonAmmo_GetKnownAmmoTypes
|
||||
|
||||
local function zButtonAmmo_BagHasAmmoNow(bagId)
|
||||
@@ -947,6 +948,14 @@ function zButtonAmmoAdjustment_OnEvent()
|
||||
|
||||
if event == "UNIT_INVENTORY_CHANGED" or event == "BAG_UPDATE" or event == "PLAYER_ALIVE" or event == "PLAYER_UNGHOST" then
|
||||
local now = GetTime and GetTime() or 0
|
||||
if event == "UNIT_INVENTORY_CHANGED" then
|
||||
local equippedNow = zButtonAmmo_GetEquippedAmmoName()
|
||||
if equippedNow == zButtonAmmo_LastEquippedAmmoSeen and now > 0 and zButtonAmmo_LastRefreshAt > 0 and (now - zButtonAmmo_LastRefreshAt) < 1.0 then
|
||||
zButtonAmmo_UpdateParentCountFast()
|
||||
return
|
||||
end
|
||||
zButtonAmmo_LastEquippedAmmoSeen = equippedNow
|
||||
end
|
||||
local bagIsAmmoRelated = false
|
||||
if event == "BAG_UPDATE" and arg1 ~= nil then
|
||||
local bagId = tonumber(arg1)
|
||||
@@ -1070,6 +1079,7 @@ function zButtonAmmoAdjustment_OnEvent()
|
||||
-- Save the currently equipped ammo for restoration on next reload
|
||||
if equippedAmmoName then
|
||||
zButtonAmmo_SaveEquippedAmmo(equippedAmmoName)
|
||||
zButtonAmmo_LastEquippedAmmoSeen = equippedAmmoName
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user