Files

265 lines
15 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Survival card, fixed book width and card layout. Never replace the native formatter: its callers must retain their
-- original execution context.
WoWHybridUI = WoWHybridUI or {};
local state = WoWHybridUI;
-- #105/#113 (2026-11-26): the third primary spell button (Turtle master smiths: Artisan + Weaponsmith + Master) is now
-- part of Blizzard's own PrimaryProfessionTemplate (content d6e928ae). The addon-made button tainted the book.
-- GetProfessions has fixed returns for Cooking, Fishing and First Aid.
-- The Source profession is skill line 142, independent of those indices.
local survivalSkillID = 142;
-- Layout (owner: bigger window is fine, one fixed width, no empty strip). Native secondary cards are 225x275 with 6px
-- overlaps; four of them need 4*225 - 3*6 = 882px. The Camelot ProfessionsFrame is natively 782px wide; it is now always
-- BOOK_FRAME_WIDTH (900px) and the recipes page fills the extra width (see ApplyFixedWidth). Every card keeps its native
-- size, art, text and bar (no scaling, no stretching). The two 664px primary cards are centred over the 882px row.
-- Revision 3 squeezed all cards to 170px with stretched art; revision 4 scaled them to 0.753 (small text).
local NATIVE_CARD_WIDTH, NATIVE_OVERLAP, PRIMARY_WIDTH, CONTENT_LEFT = 225, 6, 664, 5;
local ROW_WIDTH = 4 * NATIVE_CARD_WIDTH - 3 * NATIVE_OVERLAP; -- 882
local BOOK_FRAME_WIDTH = CONTENT_LEFT + ROW_WIDTH + 13; -- 900
local PRIMARY_OFFSET = math.floor((ROW_WIDTH - PRIMARY_WIDTH) / 2); -- 109
local PRIMARY_BAR_EXTRA = 200; -- native rank bar 441px -> 641px on the 882px primary card
-- Survival has no native card art. Reuse the native outdoor secondary card at its own size, desaturated so it
-- does not read as a second Fishing card.
local SURVIVAL_CARD_ATLAS = "Profession-overview-card-generic-fishing";
local function LearnedSurvival()
local query = C_SkillInfo and C_SkillInfo.GetSkillLineInfoByID;
local skill = query and query(survivalSkillID);
if skill and skill.skillID == survivalSkillID and not skill.isHeader
and type(skill.rank) == "number" and skill.rank > 0
and type(skill.maxRank) == "number" and skill.maxRank > 0 then
return skill;
end
end
local function CanOpenRecipes()
return type(ProfessionsFrame_LoadUI) == "function" and C_TradeSkillUI
and type(C_TradeSkillUI.OpenTradeSkill) == "function";
end
local function OpenSurvivalRecipes()
if not LearnedSurvival() or not CanOpenRecipes() or not ProfessionsFrame_LoadUI() then return; end
local current = C_TradeSkillUI.GetBaseProfessionInfo();
if not current or current.professionID ~= survivalSkillID then
-- OpenProfessionUIToSkillLine changes tabs even when OpenTradeSkill
-- rejects a custom line. Keep the book open on that result.
if not C_TradeSkillUI.OpenTradeSkill(survivalSkillID) then
UIErrorsFrame:AddMessage("Survival recipes are unavailable.", 1, 0.2, 0.2);
return;
end
end
ProfessionsFrame:SetTab(ProfessionsFrame.recipesTabID);
ShowUIPanel(ProfessionsFrame);
end
-- Prefer complete trade-skill ranks. A learned Survival line has a positive rank and cap,
-- even when its profession record supplies only one of them.
local function SurvivalProfessionInfo(skill)
local info = C_TradeSkillUI and C_TradeSkillUI.GetProfessionInfoBySkillLineID
and C_TradeSkillUI.GetProfessionInfoBySkillLineID(survivalSkillID);
local result = {};
if type(info) == "table" then for key, value in pairs(info) do result[key] = value; end end
if (result.skillLevel or 0) <= 0 or (result.maxSkillLevel or 0) <= 0 then
result.skillLevel = skill.rank;
result.maxSkillLevel = skill.maxRank;
result.skillModifier = skill.modifier or 0;
end
result.skillModifier = result.skillModifier or 0;
result.professionName = result.professionName or skill.name;
-- ProfessionsRankBarMixin:Update sets the fill atlas only when info.profession changes; Survival has none, so the
-- bar stayed black (owner 2026-11-26). Use the outdoor Skinning kit (fill + flare art) when the line carries none.
if result.profession == nil and Enum and Enum.Profession then result.profession = Enum.Profession.Skinning; end
return result;
end
-- Spellbook slot of the Survival trade-skill spell (same name as the skill line), so the card can use the native
-- ProfessionButtonTemplate exactly like the Cooking/Fishing/First Aid cards do.
local function SurvivalSpellSlot(name)
local book = C_SpellBook; if not book or not name or not book.GetNumSpellBookSkillLines then return; end
local bank = Enum.SpellBookSpellBank.Player;
for line = 1, book.GetNumSpellBookSkillLines() do
local info = book.GetSpellBookSkillLineInfo(line);
if info and not info.shouldHide then
for i = info.itemIndexOffset + 1, info.itemIndexOffset + info.numSpellBookItems do
local item = book.GetSpellBookItemInfo(i, bank);
if item and item.name == name and not item.isPassive then return i; end
end
end
end
end
local function UpdateSurvival(book)
local card = book.ProfessionsContentFrame.SecondaryProfession4;
if not card then return; end
local skill = LearnedSurvival();
card.missingHeader:SetShown(not skill);
card.missingText:SetShown(not skill);
card.ProfessionName:SetText(skill and skill.name or "");
local slot = skill and SurvivalSpellSlot(skill.name);
local spellButton = card.SpellButton1;
if slot and spellButton and spellButton.UpdateButton then
card.professionInitialized = true; card.skillName = skill.name; card.skillLine = survivalSkillID;
card.spellOffset = slot - 1;
spellButton.OutlineMask:Show(); spellButton:SetID(1); spellButton:UpdateButton(); spellButton:Show();
card.RecipeButton:Hide();
else
if spellButton then spellButton:Hide(); end
card.RecipeButton:SetShown(skill ~= nil and CanOpenRecipes());
end
if skill then
card.StatusBar:Update(SurvivalProfessionInfo(skill));
card.StatusBar:Show();
else
card.StatusBar:Hide();
end
end
local function PrepareSecondaryCards(book)
local content = book.ProfessionsContentFrame;
if not content.SecondaryProfession3 or content.SecondaryProfession4 then return; end
local card = CreateFrame("Frame", nil, content, "SecondaryProfessionTemplate");
content.SecondaryProfession4 = card;
card:SetPoint("TOPLEFT", content.SecondaryProfession3, "TOPRIGHT", -NATIVE_OVERLAP, 0);
card.Background:SetAtlas(SURVIVAL_CARD_ATLAS, true);
card.Background:SetDesaturated(true);
card.Background:SetVertexColor(0.92, 0.86, 0.72);
card.missingHeader:SetText("Survival");
card.missingText:SetText("Survival outlines come from trainers, quests, and monsters.");
for _, button in ipairs(card.spellButtons) do button:Hide(); end
-- #77 (2026-11-26): ProfessionsRankBarTemplate gives Rank an absolute frameLevel 5. On XML-built cards the bar is
-- also level 5, but this runtime card's HIGH-strata bar lands at ~103, so the fill covered "Survival" in the label.
local bar = card.StatusBar;
if bar and bar.Rank then bar.Rank:SetFrameLevel(bar:GetFrameLevel() + 2); end
local recipes = CreateFrame("Button", nil, card, "UIPanelButtonTemplate");
card.RecipeButton = recipes;
recipes:SetSize(150, 26);
recipes:SetPoint("BOTTOM", 0, 25);
recipes:SetText(RECIPES or "Recipes");
recipes:SetScript("OnClick", OpenSurvivalRecipes);
hooksecurefunc(book, "Update", UpdateSurvival);
UpdateSurvival(book);
end
-- Revision 6 (owner: one fixed width, no empty strip): the whole profession window is always BOOK_FRAME_WIDTH (900px)
-- on every page. The recipes page fills the extra 118px instead of leaving a strip: the recipe list gains RECIPE_LIST_EXTRA
-- (longer recipe names visible) and the recipe/schematic panel gains the rest. Native widths are read once and grown by a
-- fixed delta, so repeated page switches never accumulate.
local NATIVE_FRAME_WIDTH = 782;
local EXTRA = BOOK_FRAME_WIDTH - NATIVE_FRAME_WIDTH; -- 118
local RECIPE_LIST_EXTRA = 110; -- owner 11-28: scrollbar nearer the middle, more symmetric split
local FORM_RIGHT_INSET = 9;
local function ApplyFixedWidth()
local frame = ProfessionsFrame;
if not frame then return; end
if InCombatLockdown() then state.professionBookWidthPending = true; return; end
state.professionBookWidthPending = nil;
if (frame:GetWidth() or 0) ~= BOOK_FRAME_WIDTH then
frame:SetWidth(BOOK_FRAME_WIDTH);
-- No UpdateUIPanelPositions here: called from addon code it stores the panel manager's slot state as tainted,
-- and every later CharacterFrame show/hide then fails comparing secret bar values (owner 2026-11-22 errors).
end
local page = frame.CraftingPage;
if page and page.RecipeList and page.SchematicForm then
local list, form = page.RecipeList, page.SchematicForm;
if not state.professionRecipesWidened then
list:SetWidth((list:GetWidth() or 304) + RECIPE_LIST_EXTRA);
state.professionRecipesWidened = true;
end
-- Revision 10 (owner 11-28 screenshot "NOK"): a fixed delta left a 181px strip because the form's own width is
-- not the native one when first read. Size the form from its real left edge to the window's right inset instead.
local left, right = form:GetLeft(), frame:GetRight();
if left and right and right - FORM_RIGHT_INSET - left > 100 then
state.professionFormBase = state.professionFormBase or form:GetWidth();
local width = right - FORM_RIGHT_INSET - left;
form:SetWidth(width);
-- Text blocks have fixed native widths; grow them with the pane so text runs to the window edge.
local grow = width - state.professionFormBase;
state.professionTextBase = state.professionTextBase or {};
for _, key in ipairs({ "Description", "RequiredTools", "OutputSubText", "Cooldown" }) do
local text = form[key];
if text and text.SetWidth then
state.professionTextBase[key] = state.professionTextBase[key] or text:GetWidth();
text:SetWidth(state.professionTextBase[key] + math.max(0, grow));
end
end
end
end
end
local WidenForBook, RestoreWidth = ApplyFixedWidth, ApplyFixedWidth;
local function PrepareBook(book)
if not book or not book.ProfessionsContentFrame then return; end
if InCombatLockdown() then state.professionBookPending = true; return; end
local content = book.ProfessionsContentFrame;
PrepareSecondaryCards(book);
if not state.professionBookWidthHooked and content.SecondaryProfession1 then
-- Centre the 664px primary cards over the 882px secondary row. PrimaryProfession2 follows PrimaryProfession1 via
-- its native anchor; the first secondary card is pulled back to the content edge, the rest follow natively.
-- Revision 10 (owner 11-28): the primary cards span the full 882px row like the secondary cards below them, and
-- their rank bar grows with all of its textures (see below).
content.PrimaryProfession1:ClearAllPoints();
content.PrimaryProfession1:SetPoint("TOPLEFT", CONTENT_LEFT, -41);
for _, card in ipairs({ content.PrimaryProfession1, content.PrimaryProfession2 }) do
card:SetWidth(ROW_WIDTH);
-- The rank bar is a 441px frame of fixed-width textures (Background/Fill/Mask/Border, one anchor each); the
-- mask decides how much fill shows. Grow every part by the same amount so it reaches towards the name
-- (owner 11-28: empty gap) and the fill stays proportional. Flare is positioned by the mixin.
local bar = card.StatusBar;
if bar and not bar.wowHybridWidened then
bar:SetWidth(bar:GetWidth() + PRIMARY_BAR_EXTRA);
for _, key in ipairs({ "Background", "Fill", "Mask", "Border" }) do
local part = bar[key];
if part and part.SetWidth then part:SetWidth(part:GetWidth() + PRIMARY_BAR_EXTRA); end
end
bar.wowHybridWidened = true;
end
end
content.SecondaryProfession1:ClearAllPoints();
content.SecondaryProfession1:SetPoint("TOPLEFT", content.PrimaryProfession2, "BOTTOMLEFT", 0, 4);
book:HookScript("OnShow", WidenForBook);
book:HookScript("OnHide", RestoreWidth);
-- every native width change (tab switch / maximise) is followed by the fixed width again
if ProfessionsFrame then
for _, method in ipairs({ "SetTab", "ApplyDesiredWidth" }) do
if type(ProfessionsFrame[method]) == "function" then hooksecurefunc(ProfessionsFrame, method, ApplyFixedWidth); end
end
end
-- The schematic form has no left edge until the page is laid out; re-apply one frame after each show.
local function deferred() C_Timer.After(0, ApplyFixedWidth); end
if ProfessionsFrame then
ProfessionsFrame:HookScript("OnShow", deferred);
if ProfessionsFrame.CraftingPage then ProfessionsFrame.CraftingPage:HookScript("OnShow", deferred); end
end
state.professionBookWidthHooked = true;
end
WidenForBook();
state.professionBookPending = nil;
end
local function InstallProfessionBookCompatibility()
if state.professionBookInstalled then return true; end
local mixin = ProfessionsBookFrameMixin;
if not mixin or type(mixin.OnLoad) ~= "function" then return false; end
-- The dependency loads before the page is created. A secure post-hook
-- prepares its controls before first OnShow without replacing UI methods.
hooksecurefunc(mixin, "OnLoad", PrepareBook);
local book = ProfessionsFrame and ProfessionsFrame.BookPage;
if book then PrepareBook(book); end
state.professionBookInstalled = true;
state.professionBookRevision = 10;
return true;
end
local events = CreateFrame("Frame");
events:RegisterEvent("ADDON_LOADED");
events:RegisterEvent("PLAYER_REGEN_ENABLED");
events:SetScript("OnEvent", function(_, event)
if InstallProfessionBookCompatibility() then events:UnregisterEvent("ADDON_LOADED"); end
if event == "PLAYER_REGEN_ENABLED" then
if state.professionBookPending then PrepareBook(ProfessionsFrame and ProfessionsFrame.BookPage); end
if state.professionBookWidthPending then WidenForBook(); end
if state.professionBookRestorePending then RestoreWidth(); end
end
end);
InstallProfessionBookCompatibility();