I love the smell of UnrealEd crashing in the morning. – tarquin


From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

Note: If you create a subclass of GUIPage you must have bAllowedAsLast set to true to stop it from exiting to the main menu when you have closed your custom GUIPage.

Using GUIPage To Make a GUI[edit]

The general need for a GUI is to provide some level of interaction with the player. If you just want to display something, chance are you want to use the ScoreBoard or some other Canvas-aimed class. So let's start with something simple: a button. It will call the SetupStuff() function in the player.

The first thing you'll need to do is create a Subobject in your default properties (this isn't mandatory, but it fits perfectly with the purpose.) It looks like this:

    Begin Object Class=GUIButton Name=SetupButton
        Caption   = "Setup Stuff";
        //Size of this button
        WinTop    = 0.800;  //NOTE!! This is 0-1, with 0 being the *top* of the screen.
        WinLeft   = 0.100;
        WinWidth  = 0.300;
        WinHeight = 0.040;
        StyleName = "RoundButton";
        OnClick   = InternalOnClick;
    End Object
    Controls[0] = GUIButton'SetupButton';

Notice the OnClick delegate function assignment. There are numerous delegate functions in the GUIComponent class and the important thing to remember is that whatever function you assign it to, it has the same arguments. In the case of the delegate OnClick, right here, we are passed a GUIComponent, which will be the component clicked. We can use this function to check what was clicked and act on it, like so:

function bool InternalOnClick(GUIComponent Sender)
    //My custom player controller that needs to be set up.
    local myPlayerController PC;    
    //Check to see if our SetupButton was what was clicked
    if( Sender == Controls[0] )
        //ViewportOwner comes from Interaction, which
        //our GUIController (the dude who manages this)
        //is a subclass of
        PC = myPlayerController(Controller.ViewportOwner);
        //Always check!
        if( PC == none )
            return false;
        //Set up our player's stuff!
        return true;
    return false;

So we first check to see if it was our button that called the function (sometimes you'll have several you want to differentiate between.) Then we get our playercontroller and call the function on it. Simple!

You can use a lot besides buttons, just check out the GUI Class Hierarchy.

A special note: This is in fact client side which means that if you want it to affect things on the server you must use proper replication. For instance, if you want SetupStuff() to set health and armor data, you would want to replicate that function to the server.

How to Change the Music Played at the Main Menu[edit]

One of the common things a Mod Maker will want to do is alter the Music played during the main menu. The easiest way to do this is by adding this simple piece of code to your GUIPage (could even use different music for difference pages in theory).

function InitComponent(GUIController MyController, GUIComponent MyOwner)
    Super.InitComponent(MyController, MyOwner);
    Controller.ViewPortOwner.Actor.GetEntryLevel().Song = "UMS_Main_Menu_Music";

The other way of achieving this is to use a custom Entry.ut2 map. This map is always loaded even when playing other maps, so for performance reasons it is best to keep this simple. When making your own Entry.ut2 map, it's recommended to place this in a separate directory (eg. UT2003/MyMod/Maps). You can use all manner of mapping tools here, such a matinee sequences. It's easy enough to set the level music for this map. To make use of this, your mod would need to use it's own .ini file. Find the Core.System and place your ../MyMod/Maps/*.ut2 entry above the existing Maps entry.

 Paths= ...

Using this method Unreal will find your custom Entry.ut2 map before the default one and use that. Just keep in mind this map is always loaded, so keep it fairly simple.

Adding Music to a UT2004 MOD's MainMenu[edit]

In your GUIPage you'll want to do something along the lines of what's below to play a .ogg file:

function InternalOnOpen()
        // "theme" in the line below corresponds to a "theme.ogg" file
        // in the music folder
        // you can find more MTRAN settings in the Actor enums

Haral: I decided to make something of a practical GUI guide here. If I just missed someone else's, it sucks, or something of that nature delete it, move it, or whatever.

Wormbo: We definately have a Category:Legacy To Do here. Wiki class header, properties, methods and known subclasses like on other class pages should be added.

Daemonica: I've added some knowledge I've picked up about changing the music played during maps. This can be found at Daemonica/Previous Problems, hope it's helpful.

Kungfu Hampster: I'd like to see some stuff about making ingame menus as well...as well as other GUI related stuff ;)

SimEnzo: I added a little section about adding music to the main menu of a UT2004 mod.

Flavius: How can I "spawn" the page? For example I want to display a map, when user presses a key - I saw Show method in GuiComponent, but actually I don't know, where to create the new instance of MyGuiPage...