DopingControl v0.6.4
This commit is contained in:
+202
-12
@@ -44,6 +44,88 @@ W.SOLID_BACKDROP = {
|
||||
|
||||
W.WHITE = { r = 1, g = 1, b = 1 }
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Cell-box fallback palette: variant name -> (bg, border) color reference,
|
||||
-- used ONLY when ui/cellsheet.lua's baked sheet is unavailable (see
|
||||
-- W.HasCellSheet below). `border` is a DC.COLORS key, or a number that
|
||||
-- indexes DC.QUALITY -- same convention as DC_Cells.VARIANTS in
|
||||
-- ui/cellsheet.lua, which this table intentionally mirrors: colors are
|
||||
-- pulled LIVE from DC.COLORS/DC.QUALITY (core/const.lua, already loaded --
|
||||
-- ui/cellsheet.lua only bakes that same palette into a texture, it does
|
||||
-- not own it), so nothing here duplicates a color VALUE. The pairing
|
||||
-- itself (which key goes with which variant) can't be derived
|
||||
-- mechanically -- it is the one piece of information that has to exist
|
||||
-- twice given the failure mode this guards (ui/cellsheet.lua not loaded
|
||||
-- at all). tools/luatests/test_widgets.lua cross-checks every entry
|
||||
-- against the real DC_Cells.VARIANTS so the two cannot silently drift.
|
||||
W.CELL_FALLBACK_VARIANTS = {
|
||||
HAS = { bg = "hatBg", border = "hatBorder" },
|
||||
MISSING = { bg = "fehltBg", border = "fehltBorder" },
|
||||
UNKNOWN = { bg = "unbekBg", border = "unbekBorder" },
|
||||
SKIP = { bg = "skip", border = "skipBorder" },
|
||||
NEUTRAL = { bg = "theadBg", border = "line" },
|
||||
ITEM_HAS = { bg = "theadBg", border = "hatBorder" },
|
||||
ITEM_MISSING = { bg = "theadBg", border = "fehltBorder" },
|
||||
Q_RARE = { bg = "theadBg", border = "rareBorder" },
|
||||
Q_EPIC = { bg = "theadBg", border = "epicBorder" },
|
||||
Q_0 = { bg = "theadBg", border = 0 },
|
||||
Q_1 = { bg = "theadBg", border = 1 },
|
||||
Q_2 = { bg = "theadBg", border = 2 },
|
||||
Q_5 = { bg = "theadBg", border = 5 },
|
||||
Q_6 = { bg = "theadBg", border = 6 },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- DC_Cells fallback shim -- covers a mid-session /reload where THIS file
|
||||
-- (ui/widgets.lua, an EXISTING file whose new content /reload happily
|
||||
-- re-executes) deploys, but ui/cellsheet.lua (a NEW file added in the same
|
||||
-- change) does not: 1.12's /reload re-runs existing files but never loads
|
||||
-- a file that was not already part of the running session (verified
|
||||
-- in-game). Left alone, DC_Cells stays nil, and it is not only
|
||||
-- W.MakeCell/W.SetCellBox below that touch it -- ui/matrix.lua calls
|
||||
-- DC_Cells.VariantFor(...) directly at two paint sites (M.PaintItemTile
|
||||
-- and the legacy trinket path, ui/matrix.lua ~2182/2381 -- out of scope
|
||||
-- for this change) and would error on the very first painted item/trinket
|
||||
-- cell regardless of anything done here.
|
||||
--
|
||||
-- The shim supplies ONLY the pure classification function -- state/kind/
|
||||
-- quality -> variant NAME string -- no sheet, no texture, no coordinate
|
||||
-- math, because none of that can work without ui/cellsheet.lua's baked
|
||||
-- sheet file. It is a verbatim copy of DC_Cells.VariantFor's logic (see
|
||||
-- ui/cellsheet.lua); test_widgets.lua cross-checks the two stay in sync.
|
||||
-- Installs only when DC_Cells does not already exist, so the normal
|
||||
-- (full-restart) load path -- where ui/cellsheet.lua runs before this file
|
||||
-- per DopingControl.toc and sets the real DC_Cells -- is untouched.
|
||||
if not DC_Cells then
|
||||
DC_Cells = {
|
||||
VariantFor = function(state, kind, quality)
|
||||
if kind == "ench" or kind == "trinket" then
|
||||
if quality == 3 then return "Q_RARE" end
|
||||
if quality == 4 then return "Q_EPIC" end
|
||||
if quality ~= nil then return "Q_" .. quality end
|
||||
if kind == "trinket" then
|
||||
return "Q_1"
|
||||
end
|
||||
if state == "HAS" then return "ITEM_HAS" end
|
||||
if state == "MISSING" then return "ITEM_MISSING" end
|
||||
return "NEUTRAL"
|
||||
end
|
||||
if state == "HAS" then return "HAS" end
|
||||
if state == "MISSING" then return "MISSING" end
|
||||
if state == "UNKNOWN" then return "UNKNOWN" end
|
||||
return "SKIP"
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- Whether ui/cellsheet.lua's baked sheet is actually available (as
|
||||
-- opposed to the shim above, which never sets .SHEET). One seam shared by
|
||||
-- W.MakeCell and W.SetCellBox, and directly testable offline without
|
||||
-- CreateFrame (unlike W.MakeCell itself).
|
||||
function W.HasCellSheet()
|
||||
return DC_Cells ~= nil and DC_Cells.SHEET ~= nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Font helper (we keep OUR pixel
|
||||
-- size -- the matrix layout depends on it -- and only take pfUI's font
|
||||
@@ -125,28 +207,117 @@ end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Cell factory: 30x23 state cell (the 30x23 size is part of the fixed
|
||||
-- visual layout). Carries one texture region (check/cross glyph OR trinket
|
||||
-- item icon) and one FontString (?, skip dot, trinket monogram); the
|
||||
-- matrix paint code shows exactly one of them per state.
|
||||
-- visual layout). The box (background + 1px border) is one texture region
|
||||
-- sampled from the baked sheet in ui/cellsheet.lua -- SetBackdrop with an
|
||||
-- edgeFile costs NINE texture regions per cell, this costs one. The icon
|
||||
-- (check/cross glyph OR trinket item icon) and FontString (?, skip dot,
|
||||
-- trinket monogram) are created on demand via W.CellIcon / W.CellText;
|
||||
-- the matrix paint code shows exactly one of them per state.
|
||||
-- Pool children stay anonymous (documented factory exception).
|
||||
-- ------------------------------------------------------------------
|
||||
function W.MakeCell(parent, name, w, h)
|
||||
local c = CreateFrame("Frame", name, parent)
|
||||
c:SetWidth(w or 30)
|
||||
c:SetHeight(h or 23)
|
||||
c:SetBackdrop(W.SOLID_BACKDROP)
|
||||
c:EnableMouse(true)
|
||||
c.icon = c:CreateTexture(nil, "ARTWORK")
|
||||
c.icon:SetPoint("CENTER", c, "CENTER", 0, 0)
|
||||
c.icon:SetWidth(16)
|
||||
c.icon:SetHeight(16)
|
||||
c.icon:Hide()
|
||||
c.text = c:CreateFontString(nil, "OVERLAY")
|
||||
W.ApplyFont(c.text, 9)
|
||||
c.text:SetPoint("CENTER", c, "CENTER", 0, 0)
|
||||
c.dcW = w or 30
|
||||
if W.HasCellSheet() then
|
||||
-- The state box (background + 1px border) comes from one baked sheet:
|
||||
-- SetBackdrop with an edgeFile costs NINE texture regions per cell,
|
||||
-- this costs one. See ui/cellsheet.lua.
|
||||
c.boxTex = c:CreateTexture(nil, "BACKGROUND")
|
||||
c.boxTex:SetAllPoints(c)
|
||||
c.boxTex:SetTexture(DC_Cells.SHEET.path)
|
||||
-- Without an initial texcoord the region would show the WHOLE sheet
|
||||
-- stretched across the cell until the first paint. Start on NEUTRAL.
|
||||
local l, r, t, b = DC_Cells.Coords("NEUTRAL", c.dcW)
|
||||
if l then
|
||||
c.boxTex:SetTexCoord(l, r, t, b)
|
||||
c.dcBoxVariant = "NEUTRAL"
|
||||
c.dcBoxW = c.dcW
|
||||
end
|
||||
else
|
||||
-- Fallback: ui/cellsheet.lua did not load this session (see
|
||||
-- W.HasCellSheet above) -- pre-refactor SetBackdrop path (no
|
||||
-- boxTex region at all) so the matrix still draws instead of
|
||||
-- erroring on a nil DC_Cells.SHEET. W.SetBackdropG and
|
||||
-- W.SOLID_BACKDROP are untouched by the sprite refactor, so this
|
||||
-- is exactly what W.MakeCell did before it.
|
||||
c:SetBackdrop(W.SOLID_BACKDROP)
|
||||
W.SetCellBox(c, "NEUTRAL")
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
-- Icon and FontString on demand: a cell shows one or the other, and in 1.12
|
||||
-- eagerly created regions cost even while hidden.
|
||||
function W.CellIcon(cell)
|
||||
if not cell.icon then
|
||||
cell.icon = cell:CreateTexture(nil, "ARTWORK")
|
||||
cell.icon:SetPoint("CENTER", cell, "CENTER", 0, 0)
|
||||
cell.icon:SetWidth(16)
|
||||
cell.icon:SetHeight(16)
|
||||
cell.icon:Hide()
|
||||
end
|
||||
return cell.icon
|
||||
end
|
||||
|
||||
function W.CellText(cell)
|
||||
if not cell.text then
|
||||
cell.text = cell:CreateFontString(nil, "OVERLAY")
|
||||
W.ApplyFont(cell.text, 9)
|
||||
cell.text:SetPoint("CENTER", cell, "CENTER", 0, 0)
|
||||
end
|
||||
return cell.text
|
||||
end
|
||||
|
||||
-- Guards on variant AND width (cell.dcBoxW, the width the box was last
|
||||
-- painted at) -- NOT variant alone. ui/matrix.lua resizes a pooled cell in
|
||||
-- place when its column width changes (trinket columns are 34, normal
|
||||
-- cells 30: see ui/matrix.lua's column-layout path around SetWidth(col.w))
|
||||
-- and only ever writes cell.dcW; it has no notion of dcBoxVariant and isn't
|
||||
-- expected to invalidate it. If this guard only checked variant, a cell
|
||||
-- that kept its variant across such a resize would keep a stale texcoord
|
||||
-- sized for the OLD width -- the baked border would sit off the new cell
|
||||
-- edge. Tracking dcBoxW here keeps the guard self-contained: correctness
|
||||
-- does not depend on any caller convention.
|
||||
function W.SetCellBox(cell, variant)
|
||||
if not W.HasCellSheet() then
|
||||
-- Fallback: same pre-refactor SetBackdrop recipe, colors pulled
|
||||
-- LIVE from DC.COLORS/DC.QUALITY via W.CELL_FALLBACK_VARIANTS
|
||||
-- above. Never touches cell.boxTex -- a fallback cell (see
|
||||
-- W.MakeCell) does not have one. W.SetBackdropG already
|
||||
-- change-guards by table reference, so no separate
|
||||
-- dcBoxVariant/dcBoxW bookkeeping is needed here.
|
||||
local v = W.CELL_FALLBACK_VARIANTS[variant]
|
||||
if not v then
|
||||
return
|
||||
end
|
||||
local bg = DC.COLORS[v.bg]
|
||||
local border = v.border
|
||||
if type(border) == "number" then
|
||||
border = DC.QUALITY[border]
|
||||
else
|
||||
border = DC.COLORS[border]
|
||||
end
|
||||
if not bg or not border then
|
||||
return
|
||||
end
|
||||
W.SetBackdropG(cell, bg, border)
|
||||
return
|
||||
end
|
||||
if cell.dcBoxVariant == variant and cell.dcBoxW == cell.dcW then
|
||||
return
|
||||
end
|
||||
local l, r, t, b = DC_Cells.Coords(variant, cell.dcW)
|
||||
if not l then
|
||||
return
|
||||
end
|
||||
cell.dcBoxVariant = variant
|
||||
cell.dcBoxW = cell.dcW
|
||||
cell.boxTex:SetTexCoord(l, r, t, b)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Pill factory (ready pill, coverage pill): bordered mini frame with a
|
||||
-- centered FontString; width is adjusted by the caller to fit the text.
|
||||
@@ -247,6 +418,21 @@ function W.TipDouble(left, right, c, cr)
|
||||
GameTooltip:AddDoubleLine(left, right, r, g, b, r2, g2, b2)
|
||||
end
|
||||
|
||||
-- W.dcTipOwner: our own record of which of OUR frames currently owns
|
||||
-- GameTooltip. WoW 1.12's GameTooltip has no "GetOwner" method (confirmed
|
||||
-- against FrameXML-1.12.1: zero real hits -- the only "GetOwner" match
|
||||
-- anywhere in that tree is the unrelated global function
|
||||
-- GetOwnerAuctionItems). Every caller in this addon that ever needs "who
|
||||
-- currently owns the tooltip" goes through W.AttachTooltip to open one in
|
||||
-- the first place, so this is the single place that needs to record it.
|
||||
-- Set right after SetOwner
|
||||
-- (matching order: SetOwner, then the builder runs, then Show -- a builder
|
||||
-- that itself re-SetOwner()s the SAME frame, like M.CellTooltip's
|
||||
-- ANCHOR_LEFT override, does not change who owns it). Cleared in OnLeave,
|
||||
-- guarded on identity so a late/out-of-order OnLeave can never clobber a
|
||||
-- newer owner.
|
||||
W.dcTipOwner = nil
|
||||
|
||||
function W.AttachTooltip(frame, builder, anchor)
|
||||
frame.dcTipBuilder = builder
|
||||
frame.dcTipAnchor = anchor or "ANCHOR_LEFT"
|
||||
@@ -258,6 +444,7 @@ function W.AttachTooltip(frame, builder, anchor)
|
||||
end
|
||||
if GameTooltip and this.dcTipBuilder then
|
||||
GameTooltip:SetOwner(this, this.dcTipAnchor)
|
||||
W.dcTipOwner = this
|
||||
this.dcTipBuilder(this)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
@@ -266,6 +453,9 @@ function W.AttachTooltip(frame, builder, anchor)
|
||||
if this.dcOldLeave then
|
||||
this.dcOldLeave()
|
||||
end
|
||||
if W.dcTipOwner == this then
|
||||
W.dcTipOwner = nil
|
||||
end
|
||||
if GameTooltip then
|
||||
GameTooltip:Hide()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user