UWindow Menus

From Oldunreal-Wiki
Jump to navigation Jump to search

This is a tutorial to create a basic UWindow menu.
Note: It explanes how to do it using UCC make commandlet and not within UnrealEd.

Getting started


First off we need a framed window for our menu, so start by adding a class 'ExampleFramedWin.uc':

class ExampleFramedWin extends UWindowFramedWindow;
 
// Put this function here if you want the menu to automatically close on map change.
function NotifyBeforeLevelChange()
{
	Super.NotifyBeforeLevelChange();
	Close();
}
defaultproperties
{
	ClientClass=Class'ExampleClientWin' // Our next class...
	WindowTitle="Example menu" // Window title
	bLeaveOnscreen=True // Important: Show this menu even when UWindow menu isn't active (UMenu escape menu)
	bSizable=true // In case you want to allow this menu to be scaleable
	bStatusBar=false // Optional: If you want to give user hints you can enable this
	MinWinWidth=300 // Minimum width size of this menu if its sizeable
	MinWinHeight=200 // Same...
}


Child window


This is our actual contents of the menu, that above was just the frame around the window. So now we need another class 'ExampleClientWin.uc':

class ExampleClientWin extends UWindowDialogClientWindow;
 
var UWindowSmallButton SuicideButton; // Our example button.
 
function Created()
{
	// Best place to add our contents to the menu:
	Super.Created();
 
	// On CreateWindow we have: class of our component, start X position, start Y position, X size, Y size
	// So now we add our button to the menu around center of the window
	SuicideButton = UWindowSmallButton(CreateWindow(class'UWindowSmallButton', WinWidth/2-60, WinHeight/2-8, 120, 16));
	SuicideButton.SetText("Die!"); // Set the text dialogue shown on the button
	SuicideButton.Register(Self); // We must register this button
}
// Use this to render a BLACK background on our menu, if you want default color, remove this.
function Paint(Canvas C, float X, float Y)
{ DrawStretchedTexture(C, 0, 0, WinWidth, WinHeight, Texture'BlackTexture'); // Black background } // Window was resized so now we must update the position of our button function Resized() { SuicideButton.WinLeft = WinWidth/2-60; SuicideButton.WinTop = WinHeight/2-8; } // Called whenever some event has occurred with any of our buttons function Notify(UWindowDialogControl C, byte E) { /* Click types: DE_Created, DE_Change, DE_Click, DE_Enter, DE_Exit, DE_MClick, DE_RClick, DE_EnterPressed, DE_MouseMove, DE_MouseLeave, DE_LMouseDown, DE_DoubleClick, DE_MouseEnter, DE_HelpChanged, DE_WheelUpPressed, DE_WheelDownPressed. */ if( E==DE_Click && C==SuicideButton ) // We want to make sure it was a click and happened on our button. { GetPlayerOwner().Suicide(); // We execute our event by finding our player actor and forcing it to suicide. OwnerWindow.Close(); // After that we close this menu. } }


Opening our menu (in 227f only)


First off we need to make sure it happens in client side so if its some server event you may want to make sure the request is somehow sent to client, but in this case we use a projectile that opens this menu on impact 'MenuProj.uc':

class MenuProj extends DispersionAmmo;
 
simulated function ProcessTouch(Actor Other, Vector HitLocation)
{
	// First make sure impact is on our local client.
	if( PlayerPawn(Other)!=None && PlayerPawn(Other).Player!=None && PlayerPawn(Other).Player.Console!=None )
	{
		// OpenUWindowMenu parameters: class of our menu, X start scaling (relative to screen resolution), Y start, X size, Y size.
		// Now tell it to open up our menu:
		WindowConsole(PlayerPawn(Other).Player.Console).OpenUWindowMenu(Class'ExampleFramedWin',0.3,0.4,0.4,0.25);
	}
	Super.ProcessTouch(Other,HitLocation);
}


Now you have a projectile which will ask kindly if you wish to die if you get hit by it.