Difference between revisions of "UWindow Menus"

From Oldunreal-Wiki
Jump to navigation Jump to search
(Fixed formating)
Line 5: Line 5:
<br>
<br>
First off we need a framed window for our menu, so start by adding a class 'ExampleFramedWin.uc':<br>
First off we need a framed window for our menu, so start by adding a class 'ExampleFramedWin.uc':<br>
  class ExampleFramedWin extends UWindowFramedWindow;
class ExampleFramedWin extends UWindowFramedWindow;
    
    
  // Put this function here if you want the menu to automatically close on map change.
// Put this function here if you want the menu to automatically close on map change.
  function NotifyBeforeLevelChange()
function NotifyBeforeLevelChange()
  {
{
    Super.NotifyBeforeLevelChange();
Super.NotifyBeforeLevelChange();
    Close();
Close();
  }
}
  defaultproperties
defaultproperties
  {
{
    ClientClass=Class'ExampleClientWin' // Our next class...
ClientClass=Class'ExampleClientWin' // Our next class...
    WindowTitle="Example menu" // Window title
WindowTitle="Example menu" // Window title
    bLeaveOnscreen=True // Important: Show this menu even when UWindow menu isn't active (UMenu escape menu)
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
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
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
MinWinWidth=300 // Minimum width size of this menu if its sizeable
    MinWinHeight=200 // Same...
MinWinHeight=200 // Same...
  }
}
<br>
<br>
== Child window ==
== Child window ==
Line 28: Line 28:
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':<br>
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':<br>


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


<br>
<br>
Line 70: Line 71:
<br>
<br>
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':<br>
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':<br>
  class MenuProj extends DispersionAmmo;
class MenuProj extends DispersionAmmo;
    
    
  simulated function ProcessTouch(Actor Other, Vector HitLocation)
simulated function ProcessTouch(Actor Other, Vector HitLocation)
  {
{
    // First make sure impact is on our local client.
// First make sure impact is on our local client.
    if( PlayerPawn(Other)!=None && PlayerPawn(Other).Player!=None && PlayerPawn(Other).Player.Console!=None )
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.
// 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:
// Now tell it to open up our menu:
      WindowConsole(PlayerPawn(Other).Player.Console).OpenUWindowMenu(Class'ExampleFramedWin',0.3,0.4,0.4,0.25);
WindowConsole(PlayerPawn(Other).Player.Console).OpenUWindowMenu(Class'ExampleFramedWin',0.3,0.4,0.4,0.25);
    }
}
    Super.ProcessTouch(Other,HitLocation);
Super.ProcessTouch(Other,HitLocation);
  }
}
<br>
<br>
Now you have a projectile which will ask kindly if you wish to die if you get hit by it.
Now you have a projectile which will ask kindly if you wish to die if you get hit by it.

Revision as of 06:57, 28 August 2009

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.