Adding new tab to the character frame

I am looking to add a new tab to the character panel, I did some googling and found some code that supposedly added a tab to the collections journal, which I have amended to add the tab to the character panel instead, except unfortunately it doesn’t seem to work.

The code is as follows. Is there any error in this code somewhere? the game itself doesn’t report any errors.

local TabName="MyNewTab";
 
local TabID=CharacterFrame.numTabs+1;
local Tab=CreateFrame("Button","$parentTab"..TabID,CharacterFrame,"CharacterFrameTab",TabID);
PanelTemplates_SetNumTabs(CharacterFrame,TabID);
Tab:SetPoint("LEFT","$parentTab"..(TabID-1),"RIGHT",-16,0);
Tab:SetText(TabName);
 
local Panel=CreateFrame("Frame",nil,CharacterFrame);
Panel:SetAllPoints(CharacterFrame);
 
hooksecurefunc("CharacterFrame_UpdateSelectedTab",function(self)
    local selected=PanelTemplates_GetSelectedTab(self);
    if selected==TabID then CharacterFrameTitleText:SetText(TabName); end
    Panel:SetShown(selected==TabID);
end);

Heya, this is probably not the best approach to do this but it does what you want I think -
Also your code does produce errors, you should enable error messages when dealing with code
/run C_CVar.SetCVar("scriptErrors",1);ReloadUI()
or you can download BugGrabber and BugSack

So there is 2 issues with this code,
hooksecurefunc("CharacterFrame_UpdateSelectedTab",function(self)
is not a function and
CharacterFrameTab is not a template so that’s why it can’t create the Tab

You can view the Blizzard code for the CharacterFrame Tabs here:
https://github.com/Gethe/wow-ui-source/blob/live/Interface/FrameXML/CharacterFrame.lua

https://github.com/Gethe/wow-ui-source/blob/live/Interface/FrameXML/CharacterFrame.xml

Now as for the code I’ve added a ScrollFrame similar to the Reputation/Currency Tabs and added a background for demonstration how it renders.

local TabName = "MyNewTab";
 
local TabID = CharacterFrame.numTabs + 1;
local Tab = CreateFrame("Button", "$parentTab"..TabID, CharacterFrame, "CharacterFrameTabTemplate", TabID);
PanelTemplates_SetNumTabs(CharacterFrame, TabID);
Tab:SetPoint("LEFT", "$parentTab" .. (TabID-1), "RIGHT", -16, 0);
Tab:SetText(TabName);
 
local Panel = CreateFrame("Frame", nil, CharacterFrame);
Panel:SetAllPoints(CharacterFrame);

Panel.ScrollBox = CreateFrame("ScrollFrame", nil, Panel, "UIPanelScrollFrameTemplate")
Panel.ScrollBox:SetPoint("TOPLEFT", Panel, "TOPLEFT", 10, -64) --Left / Up
Panel.ScrollBox:SetPoint("BOTTOMRIGHT", Panel, "BOTTOMRIGHT", -30, 10) --Right / Down

Panel.Content = CreateFrame("Frame", nil, Panel)
Panel.Content:SetPoint("CENTER", 0, -25)
Panel.Content:SetSize(305, 351) -- Width / Height 
Panel.Content.Background = Panel.Content:CreateTexture(nil, "OVERLAY")
Panel.Content.Background:SetColorTexture(math.random(), math.random(), math.random(), 0.2)
Panel.Content.Background:SetAllPoints()

Tab:SetScript("OnClick", function(self, arg1)
	PanelTemplates_SetTab(CharacterFrame, TabID)
	if _G["HonorFrame"] ~= nil then
		_G["HonorFrame"]:Hide()
	end
	if _G["PaperDollFrame"] ~= nil then
		_G["PaperDollFrame"]:Hide()
	end
	if _G["PetPaperDollFrame"] ~= nil then
		_G["PetPaperDollFrame"]:Hide()
	end
	if _G["HonorFrame"] ~= nil then
		_G["HonorFrame"]:Hide()
	end
	if _G["SkillFrame"] ~= nil then
		_G["SkillFrame"]:Hide()
	end
	if _G["ReputationFrame"] ~= nil then
		_G["ReputationFrame"]:Hide()
	end
	if _G["TokenFrame"] ~= nil then
		_G["TokenFrame"]:Hide()
	end
	Panel:Show()
	Panel.ScrollBox:SetScrollChild(Panel.Content)
end)

hooksecurefunc("ToggleCharacter", function(tab, onlyShow)
	if Panel:IsShown() then
		Panel:Hide()
	end
end)

local Header = Panel.Content:CreateFontString()
Header:SetFont("Fonts\\FRIZQT__.TTF", 35, "GameFontHighlightSmall")
Header:SetPoint("TOP", 0, -10)
Header:SetTextColor(0, 1, 0, 1)
Header:SetText(TabName)

-- This is what extends the ScrollBox, it will auto extend as you position thing further down
local EndOfScrollFrame = Panel.Content:CreateFontString()
EndOfScrollFrame:SetFont("Fonts\\FRIZQT__.TTF", 20, "GameFontHighlightSmall")
EndOfScrollFrame:SetPoint("TOP", 0, -1000)
EndOfScrollFrame:SetTextColor(1, 0, 0, 1)
EndOfScrollFrame:SetText("End of ScrollFrame")
1 Like

I didn’t know there was such as thing as a scroll frame, how would I do the same as the lua using an XML file instead?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.