mirror of
https://codeberg.org/Duvelcorp/MetaHunt.git
synced 2026-10-03 13:00:02 +00:00
First version
This commit is contained in:
@@ -0,0 +1,508 @@
|
||||
-- MAX_SPELLS = 1024
|
||||
|
||||
local function ZSpellButton_ApplySavedVisibility(parent, foundCount)
|
||||
if not parent then
|
||||
return
|
||||
end
|
||||
|
||||
local shouldShow = true
|
||||
if foundCount and tonumber(foundCount) then
|
||||
if tonumber(foundCount) <= 0 then
|
||||
shouldShow = false
|
||||
end
|
||||
end
|
||||
|
||||
if type(MTH_ZH_GetSavedTable) == "function" and parent.name then
|
||||
local saved = MTH_ZH_GetSavedTable(parent.name)
|
||||
if saved then
|
||||
if saved["enabled"] == false or saved["enabled"] == 0 then
|
||||
shouldShow = false
|
||||
end
|
||||
if saved["parent"] and saved["parent"]["hide"] then
|
||||
shouldShow = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if shouldShow then
|
||||
parent:Show()
|
||||
else
|
||||
parent:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ZSpellButton_SetButtons(parent, spells)
|
||||
--DEFAULT_CHAT_FRAME:AddMessage(" Parent = "..parent.name, 0, 1, 1)
|
||||
if not (parent and parent.count and parent.name and spells) then return end
|
||||
parent.spells = spells
|
||||
|
||||
if type(parent.customSetButtons) == "function" then
|
||||
local customFound = parent.customSetButtons(parent, spells)
|
||||
ZSpellButton_ApplySavedVisibility(parent, customFound)
|
||||
return customFound
|
||||
end
|
||||
|
||||
if not GetSpellName(1, "spell") then
|
||||
parent:RegisterEvent("SPELLS_CHANGED")
|
||||
return -1
|
||||
end
|
||||
local spell, finished, temp
|
||||
local info = {}
|
||||
-- Find All Spell IDs
|
||||
for i=1, MAX_SPELLS do
|
||||
spell = GetSpellName(i, "spell")
|
||||
if not spell or finished then
|
||||
break
|
||||
end
|
||||
finished = 1
|
||||
for i2=1, table.getn(spells) do
|
||||
if not info[i2] then
|
||||
finished = nil
|
||||
if spells[i2] == spell then
|
||||
temp = i
|
||||
while spells[i2] == spell do
|
||||
temp = temp + 1
|
||||
spell = GetSpellName(temp, "spell")
|
||||
end
|
||||
info[i2] = (temp-1)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Hide All Children
|
||||
for i=1, parent.count do
|
||||
local child = getglobal(parent.name..i)
|
||||
child:Hide()
|
||||
child.id = nil
|
||||
child.icon = nil
|
||||
child.isspell = nil
|
||||
end
|
||||
local button
|
||||
local count = 1
|
||||
-- Set Children IDs
|
||||
for i, v in info do
|
||||
if count > parent.count then break end
|
||||
button = getglobal(parent.name..count)
|
||||
button.id = v
|
||||
button.isspell=1
|
||||
ZSpellButton_UpdateButton(button)
|
||||
button:Show()
|
||||
-- Set The Parent To The First Spell
|
||||
if count == 1 then
|
||||
parent.id = v
|
||||
parent.isspell=1
|
||||
ZSpellButton_UpdateButton(parent)
|
||||
parent:Enable()
|
||||
end
|
||||
count = count + 1
|
||||
end
|
||||
local foundCount = count - 1
|
||||
ZSpellButton_ApplySavedVisibility(parent, foundCount)
|
||||
return foundCount
|
||||
end
|
||||
|
||||
local function ZHunterMod_UpdateButtonCount(parent, found)
|
||||
return
|
||||
end
|
||||
|
||||
function ZSpellButton_SetExpandDirection(parent, direction)
|
||||
local button = getglobal(parent.name.."1")
|
||||
local offset = parent:GetWidth() / 36
|
||||
local circleVisible = true
|
||||
if type(MTH_ZH_GetSavedTable) == "function" and parent and parent.name then
|
||||
local saved = MTH_ZH_GetSavedTable(parent.name)
|
||||
if saved and saved["parent"] and saved["parent"]["circle"] ~= nil then
|
||||
circleVisible = saved["parent"]["circle"] and true or false
|
||||
end
|
||||
end
|
||||
if parent and parent.circle then
|
||||
if circleVisible then
|
||||
parent.circle:Show()
|
||||
else
|
||||
parent.circle:Hide()
|
||||
end
|
||||
end
|
||||
if circleVisible then
|
||||
offset = offset * 5
|
||||
else
|
||||
offset = offset * 3
|
||||
end
|
||||
button:ClearAllPoints()
|
||||
if direction == "TOP" then
|
||||
button:SetPoint("BOTTOM", parent, "TOP", 0, offset)
|
||||
elseif direction == "BOTTOM" then
|
||||
button:SetPoint("TOP", parent, "BOTTOM", 0, -1 * offset)
|
||||
elseif direction == "LEFT" then
|
||||
button:SetPoint("RIGHT", parent, "LEFT", -1 * offset, 0)
|
||||
elseif direction == "RIGHT" then
|
||||
button:SetPoint("LEFT", parent, "RIGHT", offset, 0)
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_ArrangeChildren(parent, rows, count, horizontal, vertical)
|
||||
if not (parent and parent.count and parent.name) then return end
|
||||
local left, right, top, bottom = "LEFT", "RIGHT", "TOP", "BOTTOM"
|
||||
local xoffset = parent:GetWidth() / 36
|
||||
xoffset = xoffset * 3
|
||||
local yoffset = -1 * xoffset
|
||||
if horizontal then
|
||||
left, right = "RIGHT", "LEFT"
|
||||
xoffset = xoffset * -1
|
||||
end
|
||||
if vertical then
|
||||
top, bottom = "BOTTOM", "TOP"
|
||||
yoffset = yoffset * -1
|
||||
end
|
||||
if count > parent.count then
|
||||
count = parent.count
|
||||
end
|
||||
local cols = ceil(count / rows)
|
||||
local temp = 1
|
||||
local button
|
||||
for i=2, parent.count do
|
||||
button = getglobal(parent.name..i)
|
||||
if i > count then
|
||||
button:Hide()
|
||||
else
|
||||
if button.id then
|
||||
button:Show()
|
||||
end
|
||||
button:ClearAllPoints()
|
||||
if temp >= cols then
|
||||
button:SetPoint(top, getglobal(parent.name..(i-temp)), bottom, 0, yoffset)
|
||||
temp = 1
|
||||
else
|
||||
button:SetPoint(left, getglobal(parent.name..(i-1)), right, xoffset, 0)
|
||||
temp = temp + 1
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_SetSize(parent, size, setChildren)
|
||||
local bgscale = 64 / 36
|
||||
local cdscale = 0.75 / 36
|
||||
if setChildren then
|
||||
local button
|
||||
for i=1, parent.count do
|
||||
button = getglobal(parent.name..i)
|
||||
button:SetHeight(size)
|
||||
button:SetWidth(size)
|
||||
button.background:SetWidth(size * bgscale)
|
||||
button.background:SetHeight(size * bgscale)
|
||||
button.cooldown:SetModelScale(size * cdscale)
|
||||
end
|
||||
else
|
||||
local cscale = 100/36
|
||||
local cxscale = 20 / 36
|
||||
local cyscale = -22 / 36
|
||||
local circleVisible = true
|
||||
if type(MTH_ZH_GetSavedTable) == "function" and parent and parent.name then
|
||||
local saved = MTH_ZH_GetSavedTable(parent.name)
|
||||
if saved and saved["parent"] and saved["parent"]["circle"] ~= nil then
|
||||
circleVisible = saved["parent"]["circle"] and true or false
|
||||
end
|
||||
end
|
||||
parent:SetHeight(size)
|
||||
parent:SetWidth(size)
|
||||
parent.background:SetWidth(size * bgscale)
|
||||
parent.background:SetHeight(size * bgscale)
|
||||
parent.cooldown:SetModelScale(size * cdscale)
|
||||
parent.circle:SetWidth(size * cscale)
|
||||
parent.circle:SetHeight(size * cscale)
|
||||
parent.circle:SetPoint("CENTER", size * cxscale, size * cyscale)
|
||||
if circleVisible then
|
||||
parent.circle:Show()
|
||||
else
|
||||
parent.circle:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_UpdateButton(button)
|
||||
local texture
|
||||
if not button then
|
||||
button = this
|
||||
end
|
||||
if not (button.id and button.icontexture) then
|
||||
return
|
||||
end
|
||||
texture = button.icon or GetSpellTexture(button.id, "spell")
|
||||
button.icontexture:SetTexture(texture)
|
||||
button.icontexture:Show()
|
||||
end
|
||||
|
||||
function ZSpellButton_UpdateCooldown(button)
|
||||
if not button then
|
||||
button = this
|
||||
end
|
||||
if not button.id or not button.isspell then return end
|
||||
local start, duration, enable = GetSpellCooldown(button.id, "spell")
|
||||
CooldownFrame_SetTimer(button.cooldown, start, duration, enable)
|
||||
if not button.customcolor then
|
||||
local r, g, b = 1.0, 1.0, 1.0
|
||||
if enable ~= 1 then
|
||||
r, g, b = 0.4, 0.4, 0.4
|
||||
end
|
||||
button.icontexture:SetVertexColor(r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_CreateChildren(parent, name, count)
|
||||
if not (parent and name and count) then return end
|
||||
parent.children = CreateFrame("Frame", parent:GetName().."Children", UIParent)
|
||||
parent.count = count
|
||||
parent.name = name
|
||||
local button
|
||||
for i=1, count do
|
||||
button = CreateFrame("CheckButton", parent.name..i, parent.children, "ZSpellButtonChildTemplate")
|
||||
button.parent = parent
|
||||
end
|
||||
if type(ZSpellButton_ApplyChildrenExpanded) == "function" then
|
||||
ZSpellButton_ApplyChildrenExpanded(parent)
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_OnLoad()
|
||||
this:RegisterEvent("SPELL_UPDATE_COOLDOWN")
|
||||
this:RegisterForClicks("LeftButtonUp", "RightButtonUp")
|
||||
local name = this:GetName()
|
||||
this.icontexture = getglobal(name.."IconTexture")
|
||||
this.cooldown = getglobal(name.."Cooldown")
|
||||
this.background = getglobal(name.."Background")
|
||||
end
|
||||
|
||||
function ZSpellButton_OnEvent()
|
||||
if event == "SPELL_UPDATE_COOLDOWN" then
|
||||
ZSpellButton_UpdateCooldown()
|
||||
end
|
||||
end
|
||||
|
||||
local function ZSpellButton_EnsureParentFlags(parent)
|
||||
if not (parent and parent.name) then
|
||||
return
|
||||
end
|
||||
local saved = MTH_ZH_GetSavedTable(parent.name)
|
||||
if parent.tooltip == nil and saved["tooltip"] ~= nil then
|
||||
parent.tooltip = saved["tooltip"] and true or false
|
||||
end
|
||||
if parent.hideonclick == nil and saved["children"] and saved["children"]["hideonclick"] ~= nil then
|
||||
parent.hideonclick = saved["children"]["hideonclick"] and true or false
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_GetChildrenExpanded(parent)
|
||||
if not (parent and parent.name) then
|
||||
return true
|
||||
end
|
||||
local saved = MTH_ZH_GetSavedTable(parent.name)
|
||||
if not saved["children"] then
|
||||
saved["children"] = {}
|
||||
end
|
||||
if saved["children"]["expanded"] == nil then
|
||||
saved["children"]["expanded"] = 1
|
||||
end
|
||||
local expanded = saved["children"]["expanded"] ~= false and saved["children"]["expanded"] ~= 0
|
||||
return expanded
|
||||
end
|
||||
|
||||
function ZSpellButton_SetChildrenExpanded(parent, expanded)
|
||||
if not (parent and parent.name) then
|
||||
return
|
||||
end
|
||||
local saved = MTH_ZH_GetSavedTable(parent.name)
|
||||
if not saved["children"] then
|
||||
saved["children"] = {}
|
||||
end
|
||||
if expanded then
|
||||
saved["children"]["expanded"] = 1
|
||||
if parent.children then
|
||||
parent.children:Show()
|
||||
end
|
||||
else
|
||||
saved["children"]["expanded"] = 0
|
||||
if parent.children then
|
||||
parent.children:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_ApplyChildrenExpanded(parent)
|
||||
if not (parent and parent.children) then
|
||||
return
|
||||
end
|
||||
if ZSpellButton_GetChildrenExpanded(parent) then
|
||||
parent.children:Show()
|
||||
else
|
||||
parent.children:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_OnEnter()
|
||||
ZSpellButton_EnsureParentFlags(this.parent)
|
||||
if this.parent.tooltip then
|
||||
GameTooltip:SetOwner(this, "ANCHOR_TOPRIGHT")
|
||||
if this.isspell then
|
||||
GameTooltip:SetSpell(this.id, "spell")
|
||||
else
|
||||
GameTooltip:SetText(this.ammocount .. " x "..this.ammolink, 1, 1, 1)
|
||||
--GameTooltip:AddLine("Q="..this.ammocount)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButton_OnClick()
|
||||
ZSpellButton_EnsureParentFlags(this.parent)
|
||||
this:SetChecked(0)
|
||||
if type(this.parent.beforeclick) == "function" then
|
||||
if this.parent.beforeclick(this) then
|
||||
return
|
||||
end
|
||||
end
|
||||
if this.isspell then
|
||||
CastSpell(this.id, "spell")
|
||||
else
|
||||
PickupContainerItem(this.ammobag,this.ammoslot)
|
||||
EquipCursorItem(0)
|
||||
|
||||
-- Update parent button immediately to show newly equipped ammo
|
||||
if not this.isspell then
|
||||
this.parent.id = this.ammoid
|
||||
this.parent.icon = this.icon
|
||||
this.parent.isspell = nil
|
||||
this.parent.ammoname = this.ammoname
|
||||
this.parent.ammobrol = this.ammobrol
|
||||
this.parent.ammoqual = this.ammoqual
|
||||
this.parent.ammolvl = this.ammolvl
|
||||
this.parent.ammotype = this.ammotype
|
||||
this.parent.ammobag = this.ammobag
|
||||
this.parent.ammoslot = this.ammoslot
|
||||
this.parent.ammoid = this.ammoid
|
||||
this.parent.ammolink = this.ammolink
|
||||
this.parent.ammocount = this.ammocount
|
||||
if type(this.parent.customUpdateButton) == "function" then
|
||||
this.parent.customUpdateButton(this.parent)
|
||||
else
|
||||
ZSpellButton_UpdateButton(this.parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
if type(this.parent.afterclick) == "function" then
|
||||
if this.parent.afterclick(this) then
|
||||
return
|
||||
end
|
||||
end
|
||||
if this.parent.hideonclick then
|
||||
if type(ZSpellButton_SetChildrenExpanded) == "function" then
|
||||
ZSpellButton_SetChildrenExpanded(this.parent, false)
|
||||
elseif this.parent.children then
|
||||
this.parent.children:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButtonParent_OnLoad()
|
||||
this:RegisterEvent("SPELL_UPDATE_COOLDOWN")
|
||||
this:RegisterEvent("LEARNED_SPELL_IN_TAB")
|
||||
this:RegisterForDrag("LeftButton")
|
||||
this:RegisterForClicks("LeftButtonUp", "RightButtonUp")
|
||||
local name = this:GetName()
|
||||
this.icontexture = getglobal(name.."IconTexture")
|
||||
this.cooldown = getglobal(name.."Cooldown")
|
||||
this.background = getglobal(name.."Background")
|
||||
this.circle = getglobal(name.."Circle")
|
||||
-- Keep enabled so empty buttons can be moved on low-level characters.
|
||||
this:Enable()
|
||||
end
|
||||
|
||||
function ZSpellButtonParent_OnEvent()
|
||||
if event == "SPELL_UPDATE_COOLDOWN" then
|
||||
ZSpellButton_UpdateCooldown()
|
||||
elseif event == "LEARNED_SPELL_IN_TAB" then
|
||||
if this.name and this.count and this.spells then
|
||||
local found = ZSpellButton_SetButtons(this, this.spells)
|
||||
ZHunterMod_UpdateButtonCount(this, found)
|
||||
end
|
||||
elseif event == "SPELLS_CHANGED" then
|
||||
this.found = ZSpellButton_SetButtons(this, this.spells)
|
||||
ZHunterMod_UpdateButtonCount(this, this.found)
|
||||
if this.found == 0 then
|
||||
this:Hide()
|
||||
end
|
||||
if this.found > -1 then
|
||||
this:UnregisterEvent("SPELLS_CHANGED")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButtonParent_OnEnter(frame)
|
||||
if not frame then
|
||||
frame = this
|
||||
end
|
||||
ZSpellButton_EnsureParentFlags(frame)
|
||||
if frame.tooltip and frame.id then
|
||||
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
|
||||
local msg, rank
|
||||
|
||||
if frame.isspell then
|
||||
msg, rank = GetSpellName(frame.id, "spell")
|
||||
if string.len(rank) > 0 then
|
||||
msg = msg.." ("..rank..")"
|
||||
end
|
||||
else
|
||||
msg = frame.ammoname
|
||||
end
|
||||
|
||||
GameTooltip:SetText(msg, 1, 1, 1)
|
||||
GameTooltip:AddLine("Alt+Drag To Move This Button")
|
||||
GameTooltip:Show()
|
||||
end
|
||||
end
|
||||
|
||||
function ZSpellButtonParent_OnClick()
|
||||
ZSpellButton_EnsureParentFlags(this)
|
||||
this:SetChecked(0)
|
||||
if arg1 == "RightButton" then
|
||||
local showChildren = not this.children:IsVisible()
|
||||
if type(ZSpellButton_SetChildrenExpanded) == "function" then
|
||||
ZSpellButton_SetChildrenExpanded(this, showChildren)
|
||||
elseif showChildren then
|
||||
this.children:Show()
|
||||
else
|
||||
this.children:Hide()
|
||||
end
|
||||
else
|
||||
if type(this.beforeclick) == "function" then
|
||||
if this.beforeclick(this) then
|
||||
return
|
||||
end
|
||||
end
|
||||
if this.isspell then
|
||||
if not this.id then
|
||||
return
|
||||
end
|
||||
CastSpell(this.id, "spell")
|
||||
else
|
||||
if not (this.ammobag and this.ammoslot) then
|
||||
return
|
||||
end
|
||||
PickupContainerItem(this.ammobag,this.ammoslot)
|
||||
EquipCursorItem(0)
|
||||
end
|
||||
if type(this.afterclick) == "function" then
|
||||
if this.afterclick(this) then
|
||||
return
|
||||
end
|
||||
end
|
||||
if this.hideonclick then
|
||||
if type(ZSpellButton_SetChildrenExpanded) == "function" then
|
||||
ZSpellButton_SetChildrenExpanded(this, false)
|
||||
elseif this.children then
|
||||
this.children:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user