home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / Engine / Classes / Console.uc < prev    next >
Text File  |  2003-08-27  |  6KB  |  246 lines

  1. //=============================================================================
  2. // Console - A quick little command line console that accepts most commands.
  3.  
  4. //=============================================================================
  5. class Console extends Interaction;
  6.     
  7. #exec new TrueTypeFontFactory PACKAGE="Engine" Name=ConsoleFont FontName="Verdana" Height=12 AntiAlias=1 CharactersPerPage=256
  8. // Removed by Demiurge (Runtime)
  9. //#exec TEXTURE IMPORT NAME=ConsoleBK FILE=..\UWindow\TEXTURES\Black.PCX    
  10. //#exec TEXTURE IMPORT NAME=ConsoleBdr FILE=..\UWindow\TEXTURES\White.PCX    
  11.     
  12. // Constants.
  13. const MaxHistory=16;        // # of command histroy to remember.
  14.  
  15. // Variables
  16.  
  17. var globalconfig byte ConsoleKey;            // Key used to bring up the console
  18.  
  19. var int HistoryTop, HistoryBot, HistoryCur;
  20. var string TypedStr, History[MaxHistory];     // Holds the current command, and the history
  21. var bool bTyping;                            // Turn when someone is typing on the console
  22. var bool bIgnoreKeys;                        // Ignore Key presses until a new KeyDown is received                            
  23.  
  24. event NativeConsoleOpen()
  25. {
  26. }
  27.  
  28. //-----------------------------------------------------------------------------
  29. // Exec functions accessible from the console and key bindings.
  30.  
  31. // Begin typing a command on the console.
  32. exec function Type()
  33. {
  34.     TypedStr="";
  35.     GotoState( 'Typing' );
  36. }
  37.  
  38. exec function Talk()
  39. {
  40.     TypedStr="Say ";
  41.     GotoState( 'Typing' );
  42. }
  43.  
  44. exec function TeamTalk()
  45. {
  46.     TypedStr="TeamSay ";
  47.     GotoState( 'Typing' );
  48. }
  49.  
  50. event NotifyLevelChange()
  51. {
  52. }
  53.  
  54. //-----------------------------------------------------------------------------
  55. // Message - By default, the console ignores all output.
  56. //-----------------------------------------------------------------------------
  57.  
  58. event Message( coerce string Msg, float MsgLife);
  59.  
  60. //-----------------------------------------------------------------------------
  61. // Check for the console key.
  62.  
  63. function bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
  64. {
  65.     if( Action!=IST_Press )
  66.         return false;
  67.     else if( Key==ConsoleKey )
  68.     {
  69.         GotoState('Typing');
  70.         return true;
  71.     }
  72.     else 
  73.         return false;
  74.  
  75.  
  76. //-----------------------------------------------------------------------------
  77. // State used while typing a command on the console.
  78.  
  79. state Typing
  80. {
  81.     exec function Type()
  82.     {
  83.         TypedStr="";
  84.         gotoState( '' );
  85.     }
  86.     function bool KeyType( EInputKey Key, optional string Unicode )
  87.     {
  88.         if (bIgnoreKeys)        
  89.             return true;
  90.     
  91.         if( Key>=0x20 && Key<0x100 && Key!=Asc("~") && Key!=Asc("`") )
  92.         {
  93.             if( Unicode != "" )
  94.                 TypedStr = TypedStr $ Unicode;
  95.             else
  96.                 TypedStr = TypedStr $ Chr(Key);
  97.             return true;
  98.         }
  99.     }
  100.     function bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
  101.     {
  102.         local string Temp;
  103.  
  104.         if (Action== IST_PRess)
  105.         {
  106.             bIgnoreKeys=false;
  107.         }
  108.     
  109.         if( Key==IK_Escape )
  110.         {
  111.             if( TypedStr!="" )
  112.             {
  113.                 TypedStr="";
  114.                 HistoryCur = HistoryTop;
  115.                 return true;
  116.             }
  117.             else
  118.             {
  119.                 GotoState( '' );
  120.             }
  121.         }
  122.         else if( global.KeyEvent( Key, Action, Delta ) )
  123.         {
  124.             return true;
  125.         }
  126.         else if( Action != IST_Press )
  127.         {
  128.             return false;
  129.         }
  130.         else if( Key==IK_Enter )
  131.         {
  132.             if( TypedStr!="" )
  133.             {
  134.                 // Print to console.
  135.                 Message( TypedStr, 6.0 );
  136.  
  137.                 History[HistoryTop] = TypedStr;
  138.                 HistoryTop = (HistoryTop+1) % MaxHistory;
  139.                 
  140.                 if ( ( HistoryBot == -1) || ( HistoryBot == HistoryTop ) )
  141.                     HistoryBot = (HistoryBot+1) % MaxHistory;
  142.  
  143.                 HistoryCur = HistoryTop;
  144.  
  145.                 // Make a local copy of the string.
  146.                 Temp=TypedStr;
  147.                 TypedStr="";
  148.                 
  149.                 if( !ConsoleCommand( Temp ) )
  150.                     Message( Localize("Errors","Exec","Core"), 6.0 );
  151.                     
  152.                 Message( "", 6.0 );
  153.                 GotoState('');
  154.             }
  155.             else
  156.                 GotoState('');
  157.                 
  158.             return true;
  159.         }
  160.         else if( Key==IK_Up )
  161.         {
  162.             if ( HistoryBot >= 0 )
  163.             {
  164.                 if (HistoryCur == HistoryBot)
  165.                     HistoryCur = HistoryTop;
  166.                 else
  167.                 {
  168.                     HistoryCur--;
  169.                     if (HistoryCur<0)
  170.                         HistoryCur = MaxHistory-1;
  171.                 }
  172.                 
  173.                 TypedStr = History[HistoryCur];
  174.             }
  175.             return True;
  176.         }
  177.         else if( Key==IK_Down )
  178.         {
  179.             if ( HistoryBot >= 0 )
  180.             {
  181.                 if (HistoryCur == HistoryTop)
  182.                     HistoryCur = HistoryBot;
  183.                 else
  184.                     HistoryCur = (HistoryCur+1) % MaxHistory;
  185.                     
  186.                 TypedStr = History[HistoryCur];
  187.             }            
  188.  
  189.         }
  190.         else if( Key==IK_Backspace || Key==IK_Left )
  191.         {
  192.             if( Len(TypedStr)>0 )
  193.                 TypedStr = Left(TypedStr,Len(TypedStr)-1);
  194.             return true;
  195.         }
  196.         return true;
  197.     }
  198.     
  199.     function PostRender(Canvas Canvas)
  200.     {
  201.         local float xl,yl;
  202.         local string OutStr;
  203.  
  204.         // Blank out a space
  205.  
  206.         Canvas.Style = 1;
  207.         
  208.         Canvas.Font     = font'ConsoleFont';
  209.         OutStr = "(>"@TypedStr$"_";
  210.         Canvas.Strlen(OutStr,xl,yl);
  211.  
  212.         Canvas.SetPos(0,Canvas.ClipY-6-yl);
  213.         //Canvas.DrawTile( texture 'ConsoleBk', Canvas.ClipX, yl+6,0,0,32,32); Commented out by Demiurge (Runtime)
  214.  
  215.         Canvas.SetPos(0,Canvas.ClipY-8-yl);    
  216.         Canvas.SetDrawColor(0,255,0);
  217.         // Canvas.DrawTile( texture 'ConsoleBdr', Canvas.ClipX, 2,0,0,32,32); Commented out by Demiurge (Runtime)
  218.  
  219.         Canvas.SetPos(0,Canvas.ClipY-3-yl);
  220.         Canvas.bCenter = False;
  221.         Canvas.DrawText( OutStr, false );
  222.     }
  223.     
  224.     function BeginState()
  225.     {
  226.         bTyping = true;
  227.         bVisible= true;
  228.         bIgnoreKeys = true;
  229.         HistoryCur = HistoryTop;
  230.     }
  231.     function EndState()
  232.     {
  233.         bTyping = false;
  234.         bVisible = false;
  235.     }
  236. }
  237.  
  238.  
  239. defaultproperties
  240. {
  241.     bActive=True
  242.     bVisible=False
  243.     bRequiresTick=True
  244.     HistoryBot=-1
  245. }