From 4ea0223f34bd993a3e74ba6392dc26bc3cc4964e Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sun, 18 Oct 2026 23:54:14 -0500 Subject: [PATCH] feat(xml): read inherits as a template list, and CreateFrame's id 4.3.4 reads `inherits` as a list. CSimpleFrame::LoadXML tokenizes it on " ," and loads each template, left to right, before the node's own content, so later templates override earlier ones; FindParent walks the same list for a `parent`. Vanilla's frame loader, child-frames builder and builder parent walk each look the whole string up as one name, so XML `inherits="A, B"` failed with "Couldn't find inherited node". Each of the three steps now takes a list the same way: every name in order through the engine's own step, then the node itself. A single name keeps the engine's path untouched. Textures and font strings keep one template, as in 4.3.4. CreateFrame is now 4.3.4's Script_CreateFrame on vanilla's builder: - every name in a template list must resolve, or it raises the engine's "Couldn't find inherited node" error; the whole list goes on the request node, so the frame is built through the list path above with all templates applied before OnLoad. The old hook built with the first template and grafted the rest after OnLoad, and it skipped missing names. - the 5th argument `id` is set on the node, so GetID() in OnLoad returns it. The id has to be on the request node before the builder runs, and vanilla builds and frees that node in its own body, so the function is replaced, with the engine's node constructor, attribute setter, builder, status object and error strings. Verified in-game (1.12.1 via VanillaFixes) with a throwaway test addon: XML and CreateFrame lists apply left to right (B's size over A's), both templates' regions and children exist when the last template's OnLoad runs, a missing name is skipped in XML and an error in CreateFrame, a space-separated list takes its parent from a template, CreateFrame's id reaches OnLoad, and CreateFrame("Cooldown") still reports "Cooldown". --- README.md | 4 +- docs/API.md | 41 +++++ src/Offsets.h | 64 ++++++-- src/frame/CreateFrame.cpp | 331 ++++++++++++-------------------------- src/xml/FrameLoad.cpp | 8 +- src/xml/FrameLoad.h | 6 +- src/xml/Inherits.cpp | 215 +++++++++++++++++++++++++ src/xml/Inherits.h | 53 ++++++ 8 files changed, 479 insertions(+), 243 deletions(-) create mode 100644 src/xml/Inherits.cpp create mode 100644 src/xml/Inherits.h diff --git a/README.md b/README.md index f1b2d884..939131bf 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ The flagship feature: run modern Lua 5.1 addon code on 1.12's Lua 5.0 VM. |---------|--------| | Inline textures | Draws inline texture markup (`\|T…\|t`) and atlas markup (`\|A…\|a`) as icons in FontStrings, chat, and tooltips. This covers item and spell icons, raid-target markers, and the coin icons in money strings. `GetStringWidth` and `GetStringHeight` count the icons, so measured width and text wrapping stay correct. Done in pure C++ by hooking the engine's text pipeline — no addon. | | Tooltip line cap | Lifts `GameTooltip`'s hard 30-line limit to 60 for every `GameTooltipTemplate` frame (`GameTooltip`, `ShoppingTooltip1/2`, `ItemRefTooltip`, AtlasLoot, …). Stat-heavy tooltips and comparison blocks (e.g. pfUI's eqcompare) no longer have their extra lines silently dropped. Done in pure C++ by growing the engine's FontString pool at tooltip-creation time. | -| [XML attributes](docs/API.md#parentkey-in-xml) | More XML attributes work: `parentKey="Name"` makes `parent.Name` point to a frame, texture or font string, `` uses a global function as a script handler, and a button's `` sets its font. | +| [XML attributes](docs/API.md#parentkey-in-xml) | More XML attributes work: `parentKey="Name"` makes `parent.Name` point to a frame, texture or font string, `` uses a global function as a script handler, a button's `` sets its font, and `inherits="A, B"` applies more than one template. | | [Macro conditions](docs/API.md#more-commands-with-conditions) | `[conditions]` and `@unit` work on 38 slash commands, from `/cast` and `/use` to `/target`, `/follow`, `/cancelaura` and the `/pet` family. With `/cast [@mouseover,harm][] Fireball`, the spell goes to the mouseover unit. With no mouseover unit, it goes to your target. `@cursor` places a ground-target spell or item under the mouse and `@player` places it at your feet. A character name works where a unit token does (`[target=Feral]`). Addons read the same rules through `SecureCmdOptionParse`. | | [`#showtooltip`](docs/API.md#showtooltip-and-show) | A macro button shows what the macro does. The icon, tooltip, cooldown, range, usable state and auto-repeat glow all follow the spell or item that the directive resolves to, conditions included. They update as the conditions change. The result goes into the engine field that action-bar addons already read, so they need no code of their own. An addon with its own macro parser can publish its result through `C_Macro.SetMacroDisplay`. It then does not need to replace the action globals. | | [Event-driven nameplates](docs/API.md#nameplate) | The modern `C_NamePlate` API, driven by real events. `NAME_PLATE_UNIT_ADDED` / `NAME_PLATE_UNIT_REMOVED` fire as plates appear and vanish, `nameplate1`..`nameplateN` tokens resolve with every `UnitX` function (and fire `UNIT_HEALTH`, `UNIT_AURA`, … as `arg1 == "nameplateN"`), and `C_NamePlate.GetNamePlateForUnit` / `GetNamePlates` hand back the live frames. | @@ -81,7 +81,7 @@ reference in **[docs/API.md](docs/API.md)**. | [Expansion](docs/API.md#expansion) | `ClassicExpansionAtLeast`, `ClassicExpansionAtMost`, `GetClassicExpansionLevel` | | [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByID`, `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.IsFactionActive`, `C_Reputation.IsFactionActiveByID`, `C_Reputation.IsFactionInactive`, `C_Reputation.SetFactionActive`, `C_Reputation.SetFactionActiveByID`, `C_Reputation.SetFactionInactive`, `C_Reputation.SetFactionInactiveByID`, `C_Reputation.SetSelectedFaction`, `C_Reputation.SetSelectedFactionByID`, `C_Reputation.SetWatchedFactionByID`, `C_Reputation.ToggleFactionAtWar`, `C_Reputation.ToggleFactionAtWarByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` | | [Focus](docs/API.md#focus) | `ClearFocus`, `FocusUnit` | -| [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `CreateFrame("Cooldown")`, `cooldown:SetCooldown`, `cooldown:SetReverse`, `cooldown:GetReverse`, `cooldown:SetDrawEdge`, `cooldown:GetDrawEdge`, `frame:SetShown`, `frame:SetClampRectInsets`, `frame:GetClampRectInsets`, `smf:SetHyperlinksEnabled`, `smf:GetHyperlinksEnabled`, `editBox:SetCountInvisibleLetters`, `editBox:IsCountInvisibleLetters`, `fontstring:GetStringHeight`, `fontstring:GetUnboundedStringWidth`, `fontstring:GetWrappedWidth`, `fontstring:GetNumLines`, `fontstring:GetLineHeight`, `fontstring:IsTruncated`, `fontstring:SetMaxLines`, `fontstring:GetMaxLines`, `fontstring:SetFormattedText`, `texture:SetRotation`, `texture:GetRotation`, `texture:SetVertexOffset`, `texture:GetVertexOffset`, `texture:SetColorTexture`, `texture:SetAtlas`, `texture:GetAtlas`, `texture:ResetTexCoord`, `texture:SetSpriteSheetCell`, `texture:SetDesaturation`, `texture:GetDesaturation`, `texture:SetMask`, `frame:CreateMaskTexture`, `texture:AddMaskTexture`, `texture:RemoveMaskTexture`, `texture:GetNumMaskTextures`, `texture:GetMaskTexture`, `fontstring:SetRotation`, `fontstring:GetRotation`, `editBox:SetCursorPosition`, `editBox:GetCursorPosition`, `editBox:GetUTF8CursorPosition`, `editBox:ClearHighlightText`, `editBox:HasFocus`, `editBox:HasText`, `editBox:SetHighlightColor`, `editBox:GetHighlightColor`, `editBox:ClearHistory`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsProtected`, `button:SetNormalFontObject`, `button:GetNormalFontObject`, `frame:IsEventRegistered`, `frame:RegisterUnitEvent`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs`, `PreClick` (script), `PostClick` (script), `button:RegisterForClicks("AnyUp"/"AnyDown")`, `GetClickFrame` | +| [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `CreateFrame` template lists and `id`, `CreateFrame("Cooldown")`, `cooldown:SetCooldown`, `cooldown:SetReverse`, `cooldown:GetReverse`, `cooldown:SetDrawEdge`, `cooldown:GetDrawEdge`, `frame:SetShown`, `frame:SetClampRectInsets`, `frame:GetClampRectInsets`, `smf:SetHyperlinksEnabled`, `smf:GetHyperlinksEnabled`, `editBox:SetCountInvisibleLetters`, `editBox:IsCountInvisibleLetters`, `fontstring:GetStringHeight`, `fontstring:GetUnboundedStringWidth`, `fontstring:GetWrappedWidth`, `fontstring:GetNumLines`, `fontstring:GetLineHeight`, `fontstring:IsTruncated`, `fontstring:SetMaxLines`, `fontstring:GetMaxLines`, `fontstring:SetFormattedText`, `texture:SetRotation`, `texture:GetRotation`, `texture:SetVertexOffset`, `texture:GetVertexOffset`, `texture:SetColorTexture`, `texture:SetAtlas`, `texture:GetAtlas`, `texture:ResetTexCoord`, `texture:SetSpriteSheetCell`, `texture:SetDesaturation`, `texture:GetDesaturation`, `texture:SetMask`, `frame:CreateMaskTexture`, `texture:AddMaskTexture`, `texture:RemoveMaskTexture`, `texture:GetNumMaskTextures`, `texture:GetMaskTexture`, `fontstring:SetRotation`, `fontstring:GetRotation`, `editBox:SetCursorPosition`, `editBox:GetCursorPosition`, `editBox:GetUTF8CursorPosition`, `editBox:ClearHighlightText`, `editBox:HasFocus`, `editBox:HasText`, `editBox:SetHighlightColor`, `editBox:GetHighlightColor`, `editBox:ClearHistory`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsProtected`, `button:SetNormalFontObject`, `button:GetNormalFontObject`, `frame:IsEventRegistered`, `frame:RegisterUnitEvent`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs`, `PreClick` (script), `PostClick` (script), `button:RegisterForClicks("AnyUp"/"AnyDown")`, `GetClickFrame` | | [FriendList](docs/API.md#friendlist) | `C_FriendList.GetFriendInfo`, `C_FriendList.GetFriendInfoByIndex`, `C_FriendList.GetNumFriends`, `C_FriendList.GetNumOnlineFriends`, `C_FriendList.GetNumWhoResults`, `C_FriendList.GetWhoInfo`, `C_FriendList.IsFriend`, `C_FriendList.IsIgnored`, `C_FriendList.IsIgnoredByGuid`, `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName`, `C_FriendList.SetFriendNotes`, `C_FriendList.SetFriendNotesByIndex` | | [GameObject](docs/API.md#gameobject) | `C_GameObjectInfo.GetGameObjectInfoByID`, `C_GameObjectInfo.RequestLoadGameObjectByID`, `ClosestGameObjectPosition` | | [Glue](docs/API.md#glue) | `C_Glue.IsOnGlueScreen` | diff --git a/docs/API.md b/docs/API.md index 6e29ca09..9c9a6ac9 100644 --- a/docs/API.md +++ b/docs/API.md @@ -235,6 +235,7 @@ build instructions. - [`region:GetRect()`](#regiongetrect) - [`region:IsDragging()`](#regionisdragging) - [`GetMouseFoci()`](#getmousefoci) + - [`CreateFrame(frameType [, name, parent, template, id])`](#createframeframetype--name-parent-template-id) - [`CreateFrame("Cooldown" [, name, parent, template])`](#createframecooldown--name-parent-template) - [`frame:SetShown(shown)`](#framesetshownshown) - [A frame moved to a new parent takes its children along](#a-frame-moved-to-a-new-parent-takes-its-children-along) @@ -841,6 +842,7 @@ build instructions. - [`C_XMLUtil.GetTemplates()`](#c_xmlutilgettemplates) - [`C_XMLUtil.GetTemplateInfo(name)`](#c_xmlutilgettemplateinfoname) - [`C_XMLUtil.DoesTemplateExist(name)`](#c_xmlutildoestemplateexistname) + - [`inherits` with more than one template](#inherits-with-more-than-one-template) - [`parentKey` in XML](#parentkey-in-xml) - [`function` on XML script handlers](#function-on-xml-script-handlers) - [`style` on button font elements](#style-on-button-font-elements) @@ -5715,6 +5717,26 @@ for i = 1, table.getn(foci) do end ``` +### `CreateFrame(frameType [, name, parent, template, id])` + +`template` can be a list of templates. Commas or spaces divide the names. +The templates apply from left to right, so a later template overrides an +earlier one. All of the templates apply before the frame's `OnLoad` runs. + +```lua +local b = CreateFrame("Button", nil, UIParent, + "UIPanelButtonTemplate, MyButtonTemplate", 3) +b:GetID() -- 3 +``` + +Each name in the list must be a template. If one name is not a template, +`CreateFrame` gives the error +`CreateFrame(): Couldn't find inherited node ""`. + +`id` is a number or a string. It sets the frame ID before `OnLoad` runs. +As a result, `self:GetID()` in `OnLoad` returns this value. The frame +ignores a negative `id`. + ### `CreateFrame("Cooldown" [, name, parent, template])` Creates a cooldown frame. The frame shows a cooldown sweep. @@ -20026,6 +20048,25 @@ end Case-insensitive, resolved through the same registry as `inherits=`. +### `inherits` with more than one template + +A frame element can name a list of templates in `inherits`. Commas or +spaces divide the names. The templates apply from left to right, so a +later template overrides an earlier one. The element's own attributes and +children apply last. + +```xml +