83 lines
4.6 KiB
Lua
83 lines
4.6 KiB
Lua
local _, P = ...
|
|
|
|
-- Presentation only: never replace Blizzard's secure button mixins or scripts.
|
|
-- Modern action templates expose named regions even when a texture getter is
|
|
-- absent. Copying only the getter left the pet extensions with a generic glow.
|
|
local defaults = {
|
|
Normal = "UI-HUD-ActionBar-IconFrame",
|
|
Pushed = "UI-HUD-ActionBar-IconFrame-Down",
|
|
Highlight = "UI-HUD-ActionBar-IconFrame-Mouseover",
|
|
Checked = "UI-HUD-ActionBar-IconFrame-Mouseover",
|
|
}
|
|
|
|
local function region(frame, kind)
|
|
if not frame then return end
|
|
local getter = frame["Get" .. kind .. "Texture"]
|
|
-- The getter is the region the widget actually draws; a named XML region
|
|
-- may survive a later replacement. Older templates expose only the name.
|
|
return (type(getter) == "function" and getter(frame)) or frame[kind .. "Texture"]
|
|
end
|
|
|
|
function P.StyleActionButton(button, prototype)
|
|
for _, kind in ipairs({"Normal", "Pushed", "Highlight", "Checked"}) do
|
|
local source = region(prototype, kind)
|
|
local atlas = source and source:GetAtlas()
|
|
local texture = source and source:GetTexture()
|
|
if not atlas and not texture then atlas = defaults[kind] end
|
|
-- CheckButton has SetCheckedTexture, but not SetCheckedAtlas on this
|
|
-- client. Register a texture with the widget, then apply the atlas to
|
|
-- that texture. The atlas file ID alone renders the whole sprite sheet.
|
|
button["Set" .. kind .. "Texture"](button, texture or "Interface\\Buttons\\UI-Quickslot2")
|
|
local target = region(button, kind)
|
|
if target then
|
|
if atlas then target:SetAtlas(atlas) end
|
|
target:ClearAllPoints()
|
|
-- Native small buttons anchor the art at TOPLEFT, not CENTER.
|
|
-- Match its size relative to the icon at any pet/UI scale.
|
|
local point, relative, relativePoint, x, y
|
|
if source and source.GetPoint then point, relative, relativePoint, x, y = source:GetPoint(1) end
|
|
if point and (relative == prototype or relative == prototype.icon) then
|
|
local ratio = button:GetWidth() / prototype:GetWidth()
|
|
target:SetPoint(point, button, relativePoint, (x or 0) * ratio, (y or 0) * ratio)
|
|
else target:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0) end
|
|
local w, h = button:GetWidth(), button:GetHeight()
|
|
if source and prototype:GetWidth() > 0 and prototype:GetHeight() > 0 then
|
|
target:SetSize(source:GetWidth() / prototype:GetWidth() * w,
|
|
source:GetHeight() / prototype:GetHeight() * h)
|
|
-- SetAtlas owns the subregion coordinates. File-backed native
|
|
-- artwork still needs its explicit cropping copied.
|
|
if not atlas then target:SetTexCoord(source:GetTexCoord()) end
|
|
if source.GetBlendMode and target.SetBlendMode then target:SetBlendMode(source:GetBlendMode()) end
|
|
if source.GetDrawLayer and target.SetDrawLayer then target:SetDrawLayer(source:GetDrawLayer()) end
|
|
else target:SetSize(w * 46 / 45, h) end
|
|
-- Do not inherit the prototype's transient attack-flash alpha.
|
|
if target.SetAlpha then target:SetAlpha(1) end
|
|
end
|
|
end
|
|
if prototype and prototype.Flash then
|
|
local source = prototype.Flash
|
|
if not button.Flash then button.Flash = button:CreateTexture(nil, "OVERLAY"); button.Flash:Hide() end
|
|
local flash = button.Flash
|
|
if source:GetAtlas() and flash.SetAtlas then flash:SetAtlas(source:GetAtlas()) else flash:SetTexture(source:GetTexture()) end
|
|
flash:ClearAllPoints(); flash:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0)
|
|
flash:SetSize(source:GetWidth() / prototype:GetWidth() * button:GetWidth(),
|
|
source:GetHeight() / prototype:GetHeight() * button:GetHeight())
|
|
end
|
|
end
|
|
|
|
function P.SetActionButtonSelected(button, selected, attack)
|
|
-- Pass an engine value straight to the widget; do not inspect secret values.
|
|
button:SetChecked(selected)
|
|
local checked = region(button, "Checked")
|
|
if checked and checked.SetAlpha then checked:SetAlpha(attack and .5 or 1) end
|
|
if button.Flash and UIFrameFlash and UIFrameFlashStop then
|
|
local flashing = false
|
|
if not (issecretvalue and issecretvalue(selected)) then flashing = attack and selected or false end
|
|
if flashing ~= button.ruenAttackFlashing then
|
|
if flashing then UIFrameFlash(button.Flash, .5, .5, -1, false)
|
|
else UIFrameFlashStop(button.Flash); button.Flash:Hide() end
|
|
button.ruenAttackFlashing = flashing
|
|
end
|
|
end
|
|
end
|