Your First Menu

EliotVU edited this page Apr 16, 2013 · 5 revisions
  • The most interesting and important part you would want to understand is the FComponent, this is the base class of all components which extends FObject which is just a basic abstract class.
  • The second bit is the FScene, this is the class that redirects all the events to the FComponents, whether it is hovered, selected or focused.
  • The third bit is the FController, this will give you an idea where it all starts, very simple redirecting to the FScene, don't like the FController? Wrap another class and redirect it to the FScene!
  • The fourth bit is the the FormsPlayerController Example, this is the class which will setup Forms, especially the FController, and Main or Escape(Pause) menu.
  • Once done with all of these, you'd have a basic idea of what's going on, though there's definitely still much to learn.
  • Check out the FStyle class, this is the class that holds images, state colors. This FStyle class can be configured within archetypes and UDKForms.ini
  • So that's pretty much it. Now of course you're still lost where to start, assuming you at least figured out how to setup your FormsPlayerController with a created MainMenu and UDKFrontEndMap.

Let's add a basic button to our MainMenu. MainMenu should be a FPage, this is set in your FormsPlayerController like:

begin object name=oMainMenu class=FPage
end object

Now change the part where it says class=FPage to your desired FPage, for example "MyMainMenu":

begin object name=oMainMenu class=MyMainMenu
end object

Let's create our "MyMainMenu" class:

// The MainMenu. Contains all the basic components such as inline pages and/or buttons.
class MyMainMenu extends FPage;

// A reference to our ExitButton, so that we could edit properties at run-time or identify delegate events.
var FButton ExitButton;

    // Relative position in percentage from parent(FScene(Canvas) in this case)
    // Relative size in percentage from parent(FScene(Canvas) in this case)

    // Let's add a button to exit the game.
    begin object name=oExitButton class=FButton
        // Caption(We use Text because FButton extends FLabel)
        // Delegate OnClick to OnExit, we'll add this function later, see below!

        // Relative position in percentage from parent(MyMainMenu in this case)
        // Relative size in percentage from parent(MyMainMenu in this case)
    end object
    // Assign this object to ExitButton, so that we can access it later at run-time.
    Components.Add(oExitButton) // We must add our button to the components list, so it can be processed and drawn.

Now we have to add a method to handle the OnClick/OnExit delegate:

function OnExit( FComponent sender, bool bRight )
    // Execute a console command named "Exit", we use sender so that it is executed in a instanced component instead of this archetype(where OnClick is assigned)

Congratulations, if you succeeded on all of those steps, you will now have a Menu covering half of your screen with a button to close the game! I recommend looking at more components and especially the FComponent to learn about more properties!