• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Adding Tabs to Esc Menu - More Interaction Fun

scary ghost

Grizzled Veteran
Sep 13, 2010
899
316
California
While working on another mutator, I came across the same issue I had with GameStatsTab and KFStatsX, namely, multiple mutators adding their own tabs in the esc menu. The simple solution is to create a third party class that has the tabs from each mutator loaded in. This does work but I know of 4 mutators off hand (including ServerPerks and ScrnBalance) that have their own tabs, and there could be many more. Creating a third party class to provide compatibility for all similar mutators just isn't feasible. Instead, I came up with a way to simply append the desired tab to the end of the tab list when the menu is opened. This alternative method allows the tab list to dynamically expand as need and does not require a custom InvasionLoginMenu class. You will need to be familiar with interactions in order to utilize this method.

Code
This code to do this is given below. It can be used by multiple interactions and the tab order will be the order in which the interactions are added.
Code:
class AddTabInteraction extends Interaction;

var GUI.GUITabItem newTab;

event NotifyLevelChange() {
    Master.RemoveInteraction(self);
}

function bool KeyEvent(EInputKey Key, EInputAction Action, float Delta ) {
    local string alias;
    local MidGamePanel panel;

    alias= ViewportOwner.Actor.ConsoleCommand("KEYBINDING"@ViewportOwner.Actor.ConsoleCommand("KEYNAME"@Key));
    if (Action == IST_Press && alias ~= "showmenu") {
        if (KFGUIController(ViewportOwner.GUIController).ActivePage == None) {
            ViewportOwner.Actor.ShowMenu();
        }
        if (KFInvasionLoginMenu(KFGUIController(ViewportOwner.GUIController).ActivePage) != none && 
                KFInvasionLoginMenu(KFGUIController(ViewportOwner.GUIController).ActivePage).c_Main.TabIndex(newTab.caption) == -1) {
            panel= MidGamePanel(KFInvasionLoginMenu(KFGUIController(ViewportOwner.GUIController).ActivePage).c_Main.AddTabItem(newTab));
            if (panel != none) {
                panel.ModifiedChatRestriction= KFInvasionLoginMenu(KFGUIController(ViewportOwner.GUIController).ActivePage).UpdateChatRestriction;
            }
        }
    }
    return false;
}

defaultproperties {
    bActive= true
    newTab=(ClassName="YourPackageName.SuperAwesomePanel",Caption="Tab",Hint="View my super awesome panel")
}
}
Explanation
What this interaction does is:

  1. Wait for the user to open the esc menu
  2. Grab the current active page and add the desired tab to the tab controller
There are a few if statements in the code used for type checking, ensuring ShowMenu function isn't called for every interaction that is using this code, and not attempting to add the same tab multiple times. While the AddTabItem function stops this, it does output a log message about duplicate tabs.


As mentioned above, this interaction can be added multiple times and it will simply append the tabs to the end of the list. The only gotcha is that the tab captions must be unique and are checked using a case insensitive compare. If tabs with the same caption are attempted to be added, your log file will be filled with this message:
"A tab with the caption"@InCaption@"already exists."
 
Last edited:
For some reason, when the menu is opened for the first time, the tab button doesn't have a hint. This can be fixed by setting the hint manually:
Spoiler!

To note something about the default tabs, they don't have a base class, which means all the code that adds the standard buttons (Settings, Spectate, Exit Game etc.) is copy-pasted. They also calculate these buttons' positions based on the total number of buttons among their components, so adding your own messes up the layout. Here is a blank panel class that can be extended; it has only the standard buttons at the bottom and arranges them separately from other components.
Download
Spoiler!
 
Last edited:
Upvote 0