Difference between revisions of "UWindow Menus"

From Oldunreal-Wiki
Jump to navigation Jump to search
(Created)
 
(Fixed formatting)
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>
<code>class ExampleFramedWin extends UWindowFramedWindow;<br>
  class ExampleFramedWin extends UWindowFramedWindow;
<br>
 
// Put this function here if you want the menu to automatically close on map change.<br>
  // Put this function here if you want the menu to automatically close on map change.
function NotifyBeforeLevelChange()<br>
  function NotifyBeforeLevelChange()
{<br>
  {
  Super.NotifyBeforeLevelChange();<br>
    Super.NotifyBeforeLevelChange();
  Close();<br>
    Close();
}<br>
  }
defaultproperties<br>
  defaultproperties
{<br>
  {
  ClientClass=Class'ExampleClientWin' // Our next class...<br>
    ClientClass=Class'ExampleClientWin' // Our next class...
  WindowTitle="Example menu" // Window title<br>
    WindowTitle="Example menu" // Window title
  bLeaveOnscreen=True // Important: Show this menu even when UWindow menu isn't active (UMenu escape menu)<br>
    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<br>
    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<br>
    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<br>
    MinWinWidth=300 // Minimum width size of this menu if its sizeable
  MinWinHeight=200 // Same...<br>
    MinWinHeight=200 // Same...
}</code>
  }
<br>
<br>
== Child window ==
== Child window ==
<br>
<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>
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>
<br>
 
<code>class ExampleClientWin extends UWindowDialogClientWindow;<br>
  class ExampleClientWin extends UWindowDialogClientWindow;
<br>
 
var UWindowSmallButton SuicideButton; // Our example button.<br>
  var UWindowSmallButton SuicideButton; // Our example button.
<br>
 
function Created()<br>
  function Created()
{<br>
  {
  // Best place to add our contents to the menu:<br>
    // Best place to add our contents to the menu:
  Super.Created();<br>
    Super.Created();
<br>
 
  // On CreateWindow we have: class of our component, start X position, start Y position, X size, Y size<br>
    // 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<br>
    // 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));<br>
    SuicideButton = UWindowSmallButton(CreateWindow(class'UWindowSmallButton', WinWidth/2-60, WinHeight/2-8, 120, 16));
  SuicideButton.SetText("Die!"); // Set the text dialogue shown on the button<br>
    SuicideButton.SetText("Die!"); // Set the text dialogue shown on the button
  SuicideButton.Register(Self); // We must register this button<br>
    SuicideButton.Register(Self); // We must register this button
}<br>
  }
// Use this to render a BLACK background on our menu, if you want default color, remove this.<br>
  // 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>
{<br>
  {
  DrawStretchedTexture(C, 0, 0, WinWidth, WinHeight, Texture'BlackTexture'); // Black background<br>
    DrawStretchedTexture(C, 0, 0, WinWidth, WinHeight, Texture'BlackTexture'); // Black background
}<br>
  }
// Window was resized so now we must update the position of our button<br>
  // Window was resized so now we must update the position of our button
function Resized()<br>
  function Resized()
{<br>
  {
  SuicideButton.WinLeft = WinWidth/2-60;
    SuicideButton.WinLeft = WinWidth/2-60;
  SuicideButton.WinTop = WinHeight/2-8;
    SuicideButton.WinTop = WinHeight/2-8;
}<br>
  }
// Called whenever some event has occurred with any of our buttons<br>
  // Called whenever some event has occurred with any of our buttons
function Notify(UWindowDialogControl C, byte E)<br>
  function Notify(UWindowDialogControl C, byte E)
{<br>
  {
  if( E==DE_Click && C==SuicideButton ) // We want to make sure it was a click and happened on our button.<br>
    if( E==DE_Click && C==SuicideButton ) // We want to make sure it was a click and happened on our button.
  {<br>
    {
    GetPlayerOwner().Suicide(); // We execute our event by finding our player actor and forcing it to suicide.<br>
      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>
      OwnerWindow.Close(); // After that we close this menu.
   }<br>
    }
}</code><br>
   }
 
<br>
<br>
== Opening our menu (in 227f only) ==
== Opening our menu (in 227f only) ==
<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>
<code>class MenuProj extends DispersionAmmo;<br>
  class MenuProj extends DispersionAmmo;
<br>
 
simulated function ProcessTouch(Actor Other, Vector HitLocation)<br>
  simulated function ProcessTouch(Actor Other, Vector HitLocation)
{<br>
  {
  // First make sure impact is on our local client.<br>
    // First make sure impact is on our local client.
  if( PlayerPawn(Other)!=None && PlayerPawn(Other).Player!=None && PlayerPawn(Other).Player.Console!=None )<br>
    if( PlayerPawn(Other)!=None && PlayerPawn(Other).Player!=None && PlayerPawn(Other).Player.Console!=None )
  {<br>
    {
    // OpenUWindowMenu parameters: class of our menu, X start scaling (relative to screen resolution), Y start, X size, Y size.<br>
      // 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:<br>
      // Now tell it to open up our menu:
    WindowConsole(PlayerPawn(Other).Player.Console).OpenUWindowMenu(Class'ExampleFramedWin',0.3,0.4,0.4,0.25);<br>
      WindowConsole(PlayerPawn(Other).Player.Console).OpenUWindowMenu(Class'ExampleFramedWin',0.3,0.4,0.4,0.25);
  }<br>
    }
  Super.ProcessTouch(Other,HitLocation);<br>
    Super.ProcessTouch(Other,HitLocation);
}</code><br>
  }
<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 12:29, 2 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) { 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.