This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: How would I create a new menu?  (Read 911 times)

Kobiesan

  • Registred Member
  • Wiki Incarnate
  • *****
  • Posts: 161
    • View Profile
How would I create a new menu?
« on: December 09, 2017, 05:45:15 am »
I want to create a new menu called "Collection" or something like that and put it next to the mounts/pets tabs. How would I go about making something like that?

Grymskvll

  • Registred Member
  • Polygonshifter
  • *****
  • Posts: 65
    • View Profile
Re: How would I create a new menu?
« Reply #1 on: December 12, 2017, 04:45:20 pm »
Look at Blizzard's XML+Lua to get an idea of how it's done.

It might be a little easier to make it a standalone frame, rather than making it part of CharacterFrame. It's understandable if you want to make it part of CharacterFrame, but consider that (in WotLK) there's no room left under the frame for another tab.

If you're talking about changing CharacterFrame, look at these files for a start:

Code: [Select]
Interface\FrameXML\CharacterFrame.xml
Interface\FrameXML\CharacterFrame.lua
Interface\FrameXML\CharacterFrameTemplates.xml

CharacterFrame.xml sets up the frames, CharacterFrame.lua handles the logic and CharacterFrameTemplates.xml has the template for tab buttons.

Taking a quick look at CharacterFrame.lua, there's this function that handles switching tabs:
Code: [Select]
function CharacterFrameTab_OnClick (self, button)
local name = self:GetName();

if ( name == "CharacterFrameTab1" ) then
ToggleCharacter("PaperDollFrame");
elseif ( name == "CharacterFrameTab2" ) then
ToggleCharacter("PetPaperDollFrame");
elseif ( name == "CharacterFrameTab3" ) then
ToggleCharacter("ReputationFrame");
elseif ( name == "CharacterFrameTab4" ) then
ToggleCharacter("SkillFrame");
elseif ( name == "CharacterFrameTab5" ) then
ToggleCharacter("TokenFrame");
end
PlaySound("igCharacterInfoTab");
end

You could overwrite this, or just have a new function handle the OnClick for your new tab, but then you can't use the same tab button template (or you have to overwrite the onclick script).

The actual contents of the tabs are just child frames of CharacterFrame.

function ToggleCharacter (tab) is defined in CharacterFrame.lua, and calls this function:
Code: [Select]
function CharacterFrame_ShowSubFrame (frameName)
for index, value in pairs(CHARACTERFRAME_SUBFRAMES) do
if ( value == frameName ) then
getglobal(value):Show()
else
getglobal(value):Hide();
end
end
end

CHARACTERFRAME_SUBFRAMES is defined right at the top, it's just a list of string names of the subframes:
Code: [Select]
CHARACTERFRAME_SUBFRAMES = { "PaperDollFrame", "PetPaperDollFrame", "SkillFrame", "ReputationFrame", "TokenFrame" };
I don't know what kind of collections you had in mind, but if you intend to ask the server for data you can use AIO to give the client a way to do it.

For example, in Blizzard_TokenUI.lua (which handles the logic for the currency tab of CharacterFrame):
Code: [Select]
TokenFrameHonorFrameHonor:SetText(GetHonorCurrency());
TokenFrameHonorFrameArena:SetText(GetArenaCurrency());

You can add functions similar to GetHonorCurrency and GetArenaCurrency to the client, but for whatever you're trying to ask the server about. You could make a GetCollection function to the client which gets called when your frames are done setting up which asks the server to get your character's collection info and sends it back. Then the client listens for a message back, and when it's received you can populate/update your menu. You'll need to set up a table for all characters' collection info in your CharDB and put it in memory using Eluna's CharDBQuery on server start, and save changes using CharDBExecute.

Eluna supports database queries.
Look at the PingPong.lua example in AIO for back-and-forth communication.