Thread Tools Display Modes
04-26-23, 05:28 AM   #1
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
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 a post here which mentioned how to add a new 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.

Code:
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);
  Reply With Quote
04-26-23, 09:29 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Lua Code:
  1. local TabName="MyNewTab";
  2. local TabID=CharacterFrame.numTabs+1;
  3. local Tab=CreateFrame("Button" ,"$parentTab"..TabID, CharacterFrame, "CharacterFrameTabTemplate");
  4. PanelTemplates_SetNumTabs(CharacterFrame,TabID);
  5. Tab:SetPoint("LEFT","$parentTab"..(TabID-1),"RIGHT",-16,0);
  6. Tab:SetText(TabName);
  7. Tab:SetID(TabID)
  8.  
  9. local Panel=CreateFrame("Frame", "A_Test_Panel", CharacterFrame);
  10. tinsert(CHARACTERFRAME_SUBFRAMES, "A_Test_Panel")
  11. Panel:Hide()
  12. Panel:SetAllPoints(CharacterFrame);
  13. Panel.Text = Panel:CreateFontString()
  14. Panel.Text:SetFontObject(GameFontNormal)
  15. Panel.Text:SetText("My character panel!")
  16. Panel.Text:SetPoint("CENTER")
  17.  
  18. hooksecurefunc("CharacterFrameTab_OnClick",function(self, button)
  19.     if self:GetID() == TabID then
  20.         ToggleCharacter("A_Test_Panel")
  21.     end
  22. end);
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-26-23, 11:08 AM   #3
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
That works great thank you!

I added some comments, so I'd remember what does what in the future when I need to look at it again.

I do have a question if I wanted to add stuff to the new Frame from an xml file how would I do that.

The below sort of works in that it creates a new frame which is great, but it doesn't add to the tab on the character frame, instead it creates a standalone frame over the top of character pane, but slightly offset, this new frame does open when I click on my new tab.

Also for my new tab is it possible to change the icon that is in the top left corner of my new tab to something else?

Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ http://wowprogramming.com/FrameXML/UI.xsd">
	<Frame name="OuterContent" parent="A_Test_Panel" frameStrata="HIGH" enableMouse="true" movable="true">
		<Size x="205" y="512"/>
		<Anchors>
			<Anchor point="CENTER" relativePoint="CENTER" relativeTo="A_Test_Panel"/>
		</Anchors>
		<Frames>
			<Frame name="InnerContent" parent="OuterContent">
				My character panel!
			</Frame>
			<Button name="Button1" inherits="UIPanelButtonTemplate" text="Button1">
				<Size x="109" y="22"/>
				<Anchors>
					<Anchor point="BOTTOMLEFT" x="-127" y="83"/>
				</Anchors>
			</Button>
			<Button name="Button2" inherits="UIPanelButtonTemplate" text="Button2">
				<Size x="100" y="22"/>
				<Anchors>
					<Anchor point="BOTTOMLEFT" x="95" y="83"/>
				</Anchors>
			</Button>
			<Button name="ButtonTab" inherits="PanelTopTabButtonTemplate" text="ButtonTab" id="1">
				<Anchors>
					<Anchor point="BOTTOMLEFT" x="98" y="440"/>
				</Anchors>
				<ButtonText parentKey="Text">
					<Size x="0" y="10"/>
					<Anchors>
						<Anchor point="CENTER" x="0" y="-8"/>
					</Anchors>
				</ButtonText>
			</Button>
		</Frames>
		<Layers>
			<Layer level="BORDER">
				<Texture file="Interface\LFGFRAME\UI-FRAME-THREEBUTTON-BLANK">
					<Anchors>
						<Anchor point="CENTER"/>
					</Anchors>
				</Texture>
			</Layer>
			<Layer level="BACKGROUND">
				<Texture name="$parent_Portrait" parentKey="portrait" file="Interface\ICONS\INV_Misc_Book_12">
					<Size x="65" y="65"/>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="-144" y="-4"/>
						</Anchor>
					</Anchors>
				</Texture>
			</Layer>
			<Layer level="OVERLAY">
				<FontString name="$parent_Title" parentKey="title" inherits="GameFontNormal" text="MyNewTab">
					<Anchors>
						<Anchor point="TOP">
							<Offset x="-60" y="-18"/>
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>
	</Frame>
</Ui>

Last edited by AeroMaxxD : 04-26-23 at 11:10 AM.
  Reply With Quote
04-26-23, 11:21 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Create the whole "Panel" frame in XML and use whatever name you give it in the

Code:
	<Frame name="AeroMaxxDCharacterFrame" parent="CharacterFrame" frameStrata="HIGH" enableMouse="true" setallpoints="true" id="4">
		<Frames>
			<Frame name="OuterContent" frameStrata="HIGH" enableMouse="true" movable="true">
			...
		</Frames>
	</Frame>
in lua:
Code:
tinsert(CHARACTERFRAME_SUBFRAMES, "AeroMaxxDCharacterFrame") -- or whatever name you gave it in XML
Because frame names are global, make sure it is unique to you/your addon. To do this with all the other frames, add $parent to the names
Code:
<Frame name="$parentOuterContent" parentKey="OuterContent"...>
the game will replace $parent with the parent frame's name.

and/or use the parentKey and in code you can use it as
[code]AeroMaxxDCharacterFrame.OuterContent[C/ODE]
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-26-23 at 11:33 AM.
  Reply With Quote
04-26-23, 02:21 PM   #5
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Ok awesome I have some stuff on my new tab from the xml after lots of trial and error.

I do have something I can't figure when I the code below to the Frame that is the New tab on my character frame. A new frame shows up above the new tab frame, and it is slightly offset higher and more to the left.

Code:
		<Layers>
			<Layer level="BORDER">
				<Texture file="Interface\LFGFRAME\UI-FRAME-THREEBUTTON-BLANK">
					<Anchors>
						<Anchor point="CENTER"/>
					</Anchors>
				</Texture>
			</Layer>
		</Layers>
This is the code

Code:
	<Frame name="AMD_CharacterFrame" parent="CharacterFrame" frameStrata="HIGH" enableMouse="true" setallpoints="true" id="4">
		<Frames>
			<Frame name="AMD_OuterContent" frameStrata="HIGH" enableMouse="true" movable="true">
			</Frame>
		</Frames>
		<Layers>
			<Layer level="BORDER">
				<Texture file="Interface\LFGFRAME\UI-FRAME-THREEBUTTON-BLANK">
					<Anchors>
						<Anchor point="CENTER"/>
					</Anchors>
				</Texture>
			</Layer>
		</Layers>
	</Frame>
  Reply With Quote
04-26-23, 02:30 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
It's impossible to tell without all the code/xml.

If you type /fstack and place the mouse over the frame, you might get an idea of what it is (/fstack again to hide the tooltip).

AMD_OuterContent has no size and is not anchored to anything so it doesn't seem to have a purpose unless it's moved/sized in code.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-27-23, 01:19 AM   #7
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
I've made some small changes, the code below is the most current version, I've tried setting a size to the main frame, tried changing the anchor settings for the layer but it's never in the right place it's always offset a little.

I created a paste for you here. https://paste.ee/p/zzGka

The XML code is on one tab and the LUA Code on another tab.

Lua Code:
  1. local TabName="AMD";
  2. local TabID=CharacterFrame.numTabs+1;
  3. local Tab=CreateFrame("Button", "$parentTab"..TabID, CharacterFrame, "CharacterFrameTabTemplate");
  4. PanelTemplates_SetNumTabs(CharacterFrame, TabID);
  5. Tab:SetPoint("LEFT", "$parentTab"..(TabID-1), "RIGHT", -16, 0);
  6. Tab:SetText(TabName);
  7. Tab:SetID(TabID);
  8.  
  9. tinsert(CHARACTERFRAME_SUBFRAMES, "AMD_TabOnCharacterFrame");
  10.  
  11. hooksecurefunc("CharacterFrameTab_OnClick", function(self, button)
  12.     if self:GetID() == TabID then
  13.         ToggleCharacter("AMD_TabOnCharacterFrame")
  14.     end
  15. end)
  Reply With Quote
04-27-23, 10:20 AM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
In your XML, you're using:
Lua Code:
  1. <Layers>
  2.             <Layer level="BORDER">
  3.                 <Texture file="Interface\LFGFRAME\UI-FRAME-THREEBUTTON-BLANK">
  4.                     <Anchors>
  5.                         <Anchor point="LEFT"/>
  6.                     </Anchors>
  7.                 </Texture>
  8.             </Layer>
  9.         </Layers>

Which is just a texture image of a standard game frame border with a portrait circle at the top left. You don't really need it as it's just the same as the Character Frame. Get rid of that section from the xml or if you have to use it, you will need to adjust the texture anchor to move it where you want.
eg.
Lua Code:
  1. <Layers>
  2.             <Layer level="BORDER">
  3.                 <Texture file="Interface\LFGFRAME\UI-FRAME-THREEBUTTON-BLANK">
  4.                     <Anchors>
  5.                         <Anchor point="LEFT" x="-16" y="-33"/>
  6.                     </Anchors>
  7.                 </Texture>
  8.             </Layer>
  9.         </Layers>
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-27-23 at 10:26 AM.
  Reply With Quote
04-27-23, 10:44 AM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Probably better yet would be to get rid of the texture and if you need it, set your main panel frame to inherit the proper template, eg. the same as the CharacterFrame

Lua Code:
  1. <Frame name="AMD_TabOnCharacterFrame" parent="CharacterFrame" frameStrata="HIGH" enableMouse="true" movable="true" setallpoints="true" id="4" inherits="ButtonFrameTemplate">
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-27-23, 11:52 AM   #10
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Yeah, your right, I don't need it I just liked the three buttons part at the bottom of the frame, but I have ditched it.

Would you happen to know where I can find out about what other templates I can use?
  Reply With Quote
04-27-23, 12:11 PM   #11
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
You could add your own (or a game) texture to the bottom of your panel frame as a button background.

Originally Posted by AeroMaxxD View Post
Would you happen to know where I can find out about what other templates I can use?
The game has a ton of them for all sorts of different things. You can export all the game UI code (and artwork) to peruse at your pleasure (it has all the templates as well). It's a lot to chew on
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-27-23 at 12:14 PM.
  Reply With Quote
04-27-23, 03:58 PM   #12
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Would you happen to know why there is a gold vertical line on this tab?

https://imgur.com/a/5FiQzbl

XML is here. https://paste.ee/p/zzGka

Code:
<Button name="$parent_Options" inherits="PanelTopTabButtonTemplate" text="Options">
				<Anchors>
					<Anchor point="BOTTOMLEFT" x="98" y="440"/>
				</Anchors>
				<ButtonText parentKey="Text">
					<Size x="0" y="10"/>
					<Anchors>
						<Anchor point="CENTER" x="0" y="-8"/>
					</Anchors>
				</ButtonText>
			</Button>
  Reply With Quote
04-27-23, 04:41 PM   #13
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Originally Posted by AeroMaxxD View Post
Would you happen to know why there is a gold vertical line on this tab?
It's one of the textures used by the PanelTopTabButtonTemplate the button is inheriting.

In your code you can (assuming I have the frame/tab name right):
Lua Code:
  1. AMD_TabOnCharacterFrameOptions.MiddleActive:Hide()

But that will look worse
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-28-23, 12:04 AM   #14
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
That didn't seem to work.

This is the button xml code.

Code:
<Button name="$parent_Options" inherits="PanelTopTabButtonTemplate" text="Options">
This is the main frame the button is nested inside.

Code:
<Frame name="AMD_TabOnCharacterFrame" parent="CharacterFrame" frameStrata="HIGH" enableMouse="true" movable="true" setallpoints="true" id="4">
I tried the following, but the gold vertical line remained.

Lua Code:
  1. AMD_TabOnCharacterFrame.MiddleActive:Hide()
  2. AMD_TabOnCharacterFrame_Options.MiddleActive:Hide()

Edit: Actually they do seem to work, they don't get rid of the gold vertical line, they do however remove some text I had put on the frame.

Last edited by AeroMaxxD : 04-28-23 at 12:30 AM.
  Reply With Quote
04-28-23, 12:18 AM   #15
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
I didn't see the underscore so
Code:
AMD_TabOnCharacterFrame_Options.MiddleActive:Hide()
Should work.

Depending on where you put this in your code, you might need to make sure your .xml file is listed above your .lua file in the .toc (the files get loaded in order and the frame in the .xml file is created when the file is loaded).

It's not going to look the way you want though as hiding the MiddleActive texture carves a notch in the top of the tab.

You either need to live with the gold line or make a texture to replace the one being used for MiddleActive or create your own tab button and textures.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-28-23, 06:46 AM   #16
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Originally Posted by Fizzlemizz View Post
Depending on where you put this in your code, you might need to make sure your .xml file is listed above your .lua file in the .toc (the files get loaded in order and the frame in the .xml file is created when the file is loaded).
Oh I didn't know that, I will put it above now and see if it works.

Originally Posted by Fizzlemizz View Post
It's not going to look the way you want though as hiding the MiddleActive texture carves a notch in the top of the tab.
Oh that is disappointing, I am not really sure why is even there. I can't seem to see anywhere that template is used in Blizzard own UI. I'm guessing they don't use it.

Originally Posted by Fizzlemizz View Post
You either need to live with the gold line or make a texture to replace the one being used for MiddleActive or create your own tab button and textures.
If I did create my own tab button and textures, how would I reference them? Is it possible to edit the tab template and textures and then use the edited versions, how would I edit them? is it the blp files that I need to be looking at?

Addon development for a newbie/novice is a very long-winded process!
  Reply With Quote
04-28-23, 08:23 AM   #17
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
With some more digging, instead of hiding the MiddleActive texture, you should be able to use PanelTemplates functions to control the tab:

Change:
Lua Code:
  1. AMD_TabOnCharacterFrame_Options.MiddleActive:Hide()

To:

Lua Code:
  1. PanelTemplates_SetNumTabs(AMD_TabOnCharacterFrame, 1) -- assumes you only have 1 tab
  2. PanelTemplates_SetTab(AMD_TabOnCharacterFrame, 1) -- select the 1 tab

I don't know if you have more tabs buttons on the frame so the code may need to change if you have more.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-30-23, 01:59 AM   #18
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Originally Posted by Fizzlemizz View Post
I didn't see the underscore so
Lua Code:
  1. PanelTemplates_SetNumTabs(AMD_TabOnCharacterFrame, 1) -- assumes you only have 1 tab
  2. PanelTemplates_SetTab(AMD_TabOnCharacterFrame, 1) -- select the 1 tab

I don't know if you have more tabs buttons on the frame so the code may need to change if you have more.
I just have one tab, but what if another user who used the addon had more tabs?
  Reply With Quote
04-30-23, 02:07 AM   #19
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Also, the tab I was using to set options for the addon itself, but I am trying to use the Interface Options within the escape menu instead.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Adding new tab to the character frame


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off