home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / GUI / Classes / ExtendedConsole.uc next >
Text File  |  2003-06-30  |  9KB  |  469 lines

  1. // ====================================================================
  2. // (C) 2002, Epic Games
  3. // ====================================================================
  4.  
  5. class ExtendedConsole extends Console;
  6.  
  7. #exec OBJ LOAD FILE=GUIContent.utx
  8.  
  9. // Visible Console stuff
  10.  
  11. var globalconfig int MaxScrollbackSize;
  12.  
  13. var array<string> Scrollback;
  14. var int SBHead, SBPos;    // Where in the scrollback buffer are we
  15. var bool bCtrl;
  16. var bool bConsoleHotKey;
  17.  
  18. var float   ConsoleSoundVol;
  19.  
  20. var localized string AddedCurrentHead;
  21. var localized string AddedCurrentTail;
  22.  
  23.  
  24. var config EInputKey    LetterKeys[10];
  25. var        EInputKey    NumberKeys[10];
  26.  
  27. var config bool bSpeechMenuUseLetters;
  28. var config bool bSpeechMenuUseMouseWheel;
  29.  
  30. var int HighlightRow;
  31.  
  32. ////// End Speech Menu
  33.  
  34. struct StoredPassword
  35. {
  36.     var config string    Server,
  37.                         Password;
  38. };
  39.  
  40. var config array<StoredPassword>    SavedPasswords;
  41. var config string                    PasswordPromptMenu;
  42. var string                            LastConnectedServer,
  43.                                     LastURL;
  44.  
  45.  
  46. struct ChatStruct
  47. {
  48.     var string    Message;
  49.     var int        team;
  50. };
  51.  
  52.  
  53. event ConnectFailure(string FailCode,string URL)
  54. {
  55.     local string            Server;
  56.     local int                Index;
  57.  
  58.     LastURL = URL;
  59.     Server = Left(URL,InStr(URL,"/"));
  60.  
  61.     if(FailCode == "NEEDPW")
  62.     {
  63.         for(Index = 0;Index < SavedPasswords.Length;Index++)
  64.         {
  65.             if(SavedPasswords[Index].Server == Server)
  66.             {
  67.                 ViewportOwner.Actor.ClearProgressMessages();
  68.                 ViewportOwner.Actor.ClientTravel(URL$"?password="$SavedPasswords[Index].Password,TRAVEL_Absolute,false);
  69.                 return;
  70.             }
  71.         }
  72.  
  73.         LastConnectedServer = Server;
  74.         ViewportOwner.Actor.ClientOpenMenu(
  75.             PasswordPromptMenu,
  76.             false,
  77.             URL,
  78.             ""
  79.             );
  80.         return;
  81.     }
  82.     else if(FailCode == "WRONGPW")
  83.     {
  84.         ViewportOwner.Actor.ClearProgressMessages();
  85.  
  86.         for(Index = 0;Index < SavedPasswords.Length;Index++)
  87.         {
  88.             if(SavedPasswords[Index].Server == Server)
  89.             {
  90.                 SavedPasswords.Remove(Index,1);
  91.                 SaveConfig();
  92.             }
  93.         }
  94.  
  95.         LastConnectedServer = Server;
  96.         ViewportOwner.Actor.ClientOpenMenu(
  97.             PasswordPromptMenu,
  98.             false,
  99.             URL,
  100.             ""
  101.             );
  102.         return;
  103.     }
  104. }
  105.  
  106.  
  107. event NotifyLevelChange()
  108. {
  109.     Super.NotifyLevelChange();
  110. //    GUIController(ViewportOwner.GUIController).CloseAll(false);
  111. }
  112.  
  113.  
  114. ////// End Speech Menu
  115.  
  116. exec function CLS()
  117. {
  118.     SBHead = 0;
  119.     ScrollBack.Remove(0,ScrollBack.Length);
  120. }
  121.  
  122. function PostRender( canvas Canvas );    // Subclassed in state
  123.  
  124. event Message( coerce string Msg, float MsgLife)
  125. {
  126.     if (ScrollBack.Length==MaxScrollBackSize)    // if full, Remove Entry 0
  127.     {
  128.         ScrollBack.Remove(0,1);
  129.         SBHead = MaxScrollBackSize-1;
  130.     }
  131.     else
  132.         SBHead++;
  133.  
  134.     ScrollBack.Length = ScrollBack.Length + 1;
  135.  
  136.     Scrollback[SBHead] = Msg;
  137.     Super.Message(Msg,MsgLife);
  138. }
  139.  
  140. event bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
  141. {
  142.     if (Key==ConsoleKey)
  143.     {
  144.         if(Action==IST_Release)
  145.             ConsoleOpen();
  146.         return true;
  147.     }
  148.  
  149.     return Super.KeyEvent(Key,Action,Delta);
  150. }
  151.  
  152.  
  153. function PlayConsoleSound(Sound S)
  154. {
  155.     if(ViewportOwner == None || ViewportOwner.Actor == None || ViewportOwner.Actor.Pawn == None)
  156.         return;
  157.  
  158.     ViewportOwner.Actor.ClientPlaySound(S);//,true,ConsoleSoundVol);
  159. }
  160.  
  161. //-----------------------------------------------------------------------------
  162. // State used while typing a command on the console.
  163.  
  164. event NativeConsoleOpen()
  165. {
  166.     ConsoleOpen();
  167. }
  168.  
  169. exec function ConsoleOpen()
  170. {
  171.     TypedStr = "";
  172.     GotoState('ConsoleVisible');
  173. }
  174.  
  175. exec function ConsoleClose()
  176. {
  177.     TypedStr="";
  178.     if( GetStateName() == 'ConsoleVisible' )
  179.     {
  180.         GotoState( '' );
  181.     }
  182. }
  183.  
  184. exec function ConsoleToggle()
  185. {
  186.     if( GetStateName() == 'ConsoleVisible' )
  187.         ConsoleClose();
  188.     else
  189.         ConsoleOpen();
  190. }
  191.  
  192. state ConsoleVisible
  193. {
  194.     function bool KeyType( EInputKey Key, optional string Unicode )
  195.     {
  196.         local PlayerController PC;
  197.  
  198.         if (bIgnoreKeys || bConsoleHotKey)
  199.             return true;
  200.  
  201.         if (ViewportOwner != none)
  202.             PC = ViewportOwner.Actor;
  203.  
  204.         if (bCtrl && PC != none)
  205.         {
  206.             if (Key == 3) //copy
  207.             {
  208.                 PC.CopyToClipboard(TypedStr);
  209.                 return true;
  210.             }
  211.             else if (Key == 22) //paste
  212.             {
  213.                 TypedStr = TypedStr$PC.PasteFromClipboard();
  214.                 return true;
  215.             }
  216.             else if (Key == 24) // cut
  217.             {
  218.                 PC.CopyToClipboard(TypedStr);
  219.                 TypedStr="";
  220.                 return true;
  221.             }
  222.         }
  223.  
  224.         if( Key>=0x20 )
  225.         {
  226.             if( Unicode != "" )
  227.                 TypedStr = TypedStr $ Unicode;
  228.             else
  229.                 TypedStr = TypedStr $ Chr(Key);
  230.             return( true );
  231.         }
  232.  
  233.         return( true );
  234.     }
  235.  
  236.     function bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
  237.     {
  238.         local string Temp;
  239.  
  240.         if( Key==IK_Ctrl )
  241.         {
  242.             if (Action == IST_Press)
  243.                 bCtrl = true;
  244.             else if (Action == IST_Release)
  245.                 bCtrl = false;
  246.         }
  247.  
  248.         if (Action== IST_PRess)
  249.         {
  250.             bIgnoreKeys = false;
  251.         }
  252.  
  253.         if(Key == ConsoleKey)
  254.         {
  255.             if(Action == IST_Press)
  256.                 bConsoleHotKey = true;
  257.             else if(Action == IST_Release && bConsoleHotKey)
  258.                 ConsoleClose();
  259.             return true;
  260.         }
  261.         else if (Key==IK_Escape)
  262.         {
  263.             if (Action==IST_Release)
  264.             {
  265.                 if (TypedStr!="")
  266.                 {
  267.                     TypedStr="";
  268.                     HistoryCur = HistoryTop;
  269.                 }
  270.                 else
  271.                 {
  272.                     ConsoleClose();
  273.                     return true;
  274.                 }
  275.             }
  276.             return true;
  277.         }
  278.         else if( Action != IST_Press )
  279.             return( true );
  280.  
  281.         else if( Key==IK_Enter )
  282.         {
  283.             if( TypedStr!="" )
  284.             {
  285.                 // Print to console.
  286.  
  287.                 History[HistoryTop] = TypedStr;
  288.                 HistoryTop = (HistoryTop+1) % ArrayCount(History);
  289.  
  290.                 if ( ( HistoryBot == -1) || ( HistoryBot == HistoryTop ) )
  291.                     HistoryBot = (HistoryBot+1) % ArrayCount(History);
  292.  
  293.                 HistoryCur = HistoryTop;
  294.  
  295.                 // Make a local copy of the string.
  296.                 Temp=TypedStr;
  297.                 TypedStr="";
  298.  
  299.                 if( !ConsoleCommand( Temp ) )
  300.                     Message( Localize("Errors","Exec","Core"), 6.0 );
  301.  
  302.                 Message( "", 6.0 );
  303.             }
  304.  
  305.             return( true );
  306.         }
  307.         else if( Key==IK_Up )
  308.         {
  309.             if ( HistoryBot >= 0 )
  310.             {
  311.                 if (HistoryCur == HistoryBot)
  312.                     HistoryCur = HistoryTop;
  313.                 else
  314.                 {
  315.                     HistoryCur--;
  316.                     if (HistoryCur<0)
  317.                         HistoryCur = ArrayCount(History)-1;
  318.                 }
  319.  
  320.                 TypedStr = History[HistoryCur];
  321.             }
  322.             return( true );
  323.         }
  324.         else if( Key==IK_Down )
  325.         {
  326.             if ( HistoryBot >= 0 )
  327.             {
  328.                 if (HistoryCur == HistoryTop)
  329.                     HistoryCur = HistoryBot;
  330.                 else
  331.                     HistoryCur = (HistoryCur+1) % ArrayCount(History);
  332.  
  333.                 TypedStr = History[HistoryCur];
  334.             }
  335.  
  336.         }
  337.         else if( Key==IK_Backspace || Key==IK_Left )
  338.         {
  339.             if( Len(TypedStr)>0 )
  340.                 TypedStr = Left(TypedStr,Len(TypedStr)-1);
  341.             return( true );
  342.         }
  343.  
  344.         else if ( Key==IK_PageUp || key==IK_MouseWheelUp )
  345.         {
  346.             if (SBPos<ScrollBack.Length-1)
  347.             {
  348.                 if (bCtrl)
  349.                     SBPos+=5;
  350.                 else
  351.                     SBPos++;
  352.  
  353.                 if (SBPos>=ScrollBack.Length)
  354.                   SBPos = ScrollBack.Length-1;
  355.             }
  356.  
  357.             return true;
  358.         }
  359.         else if ( Key==IK_PageDown || key==IK_MouseWheelDown)
  360.         {
  361.             if (SBPos>0)
  362.             {
  363.                 if (bCtrl)
  364.                     SBPos-=5;
  365.                 else
  366.                     SBPos--;
  367.  
  368.                 if (SBPos<0)
  369.                     SBPos = 0;
  370.             }
  371.         }
  372.  
  373.         return( true );
  374.     }
  375.  
  376.     function BeginState()
  377.     {
  378.         SBPos = 0;
  379.         bVisible= true;
  380.         bIgnoreKeys = true;
  381.         bConsoleHotKey = false;
  382.         HistoryCur = HistoryTop;
  383.         bCtrl = false;
  384.     }
  385.     function EndState()
  386.     {
  387.         bVisible = false;
  388.         bCtrl = false;
  389.         bConsoleHotKey = false;
  390.     }
  391.  
  392.     function PostRender( canvas Canvas )
  393.     {
  394.  
  395.         local float fw,fh;
  396.         local float yclip,y;
  397.         local int idx;
  398.  
  399.         Canvas.Font = class'HUD'.static.GetConsoleFont(Canvas); //Changed by Demiurge (Runtime)
  400.  
  401.         yclip = canvas.ClipY*0.5;
  402.         Canvas.StrLen("X",fw,fh);
  403.  
  404.         Canvas.SetPos(0,0);
  405.         Canvas.SetDrawColor(255,255,255,200);
  406.         Canvas.Style=4;
  407.         Canvas.DrawTileStretched(material'ConsoleBack',Canvas.ClipX,yClip);
  408.         Canvas.Style=1;
  409.  
  410.         Canvas.SetPos(0,yclip-1);
  411.         Canvas.SetDrawColor(255,255,255,255);
  412.         Canvas.DrawTile(texture 'GUIContent.Menu.BorderBoxA',Canvas.ClipX,2,0,0,64,2);
  413.  
  414.         Canvas.SetDrawColor(255,255,255,255);
  415.  
  416.         Canvas.SetPos(0,yclip-5-fh);
  417.         Canvas.DrawText("(>"@TypedStr$"_");
  418.  
  419.         idx = SBHead - SBPos;
  420.         y = yClip-y-5-(fh*2);
  421.  
  422.         if (ScrollBack.Length==0)
  423.             return;
  424.  
  425.         Canvas.SetDrawColor(255,255,255,255);
  426.         while (y>fh && idx>=0)
  427.         {
  428.             Canvas.SetPos(0,y);
  429.             Canvas.DrawText(Scrollback[idx],false);
  430.             idx--;
  431.             y-=fh;
  432.         }
  433.     }
  434. }
  435.  
  436.  
  437. defaultproperties
  438. {
  439.     ConsoleSoundVol=0.3
  440.  
  441.     MaxScrollbackSize=128
  442.     bSpeechMenuUseMouseWheel=True
  443.     bSpeechMenuUseLetters=False
  444.  
  445.     LetterKeys(0)=IK_Q
  446.     LetterKeys(1)=IK_W
  447.     LetterKeys(2)=IK_E
  448.     LetterKeys(3)=IK_R
  449.     LetterKeys(4)=IK_A
  450.     LetterKeys(5)=IK_S
  451.     LetterKeys(6)=IK_D
  452.     LetterKeys(7)=IK_F
  453.     LetterKeys(8)=IK_Z
  454.     LetterKeys(9)=IK_X
  455.  
  456.     NumberKeys(0)=IK_0
  457.     NumberKeys(1)=IK_1
  458.     NumberKeys(2)=IK_2
  459.     NumberKeys(3)=IK_3
  460.     NumberKeys(4)=IK_4
  461.     NumberKeys(5)=IK_5
  462.     NumberKeys(6)=IK_6
  463.     NumberKeys(7)=IK_7
  464.     NumberKeys(8)=IK_8
  465.     NumberKeys(9)=IK_9
  466.  
  467.     AddedCurrentHead="Added Server:"
  468.     AddedCurrentTail="To Favorites!"
  469. }