UWindow
Class WindowConsole

source: c:\runehov\UWindow\Classes\WindowConsole.uc
Core.Object
   |
   +--Engine.Console
      |
      +--UWindow.WindowConsole
Direct Known Subclasses:RuneConsole, UBrowserConsole

class WindowConsole
extends Engine.Console

//============================================================================= // WindowConsole - console replacer to implement UWindow UI System //=============================================================================
Variables
 class ConsoleClass
 byte ConsoleKey
 UWindowConsoleWindow ConsoleWindow
 float MenuTranslucency
 float MouseScale
 float MouseX
 float MouseY
 float OldClipX
 float OldClipY
 string OldLevel
 UWindowRootWindow Root
 string RootWindow
 bool ShowDesktop
 EInputKey UWindowKey
 bool bBlackout
 bool bCreatedRoot
 bool bLevelChange
 bool bLocked
 bool bQuickKeyEnable
 bool bShowConsole
 bool bUWindowActive
 bool bUWindowType

States
UWindow

Function Summary
 void CloseUWindow()
 void CreateRootWindow(Canvas Canvas)
 void HideConsole()
 void HistoryDown()
 void HistoryUp()
 void LaunchUWindow()
 void NotifyLevelChange()
 void RenderUWindow(Canvas Canvas)
 void ResetUWindow()
 void ShowConsole()
 void ToggleUWindow()
 void UpdateHistory()


State UWindow Function Summary



Source Code


00001	//=============================================================================
00002	// WindowConsole - console replacer to implement UWindow UI System
00003	//=============================================================================
00004	class WindowConsole extends Console;
00005	
00006	var UWindowRootWindow	Root;
00007	var() config string		RootWindow;
00008	
00009	var float				OldClipX;
00010	var float				OldClipY;
00011	var bool				bCreatedRoot;
00012	var float				MouseX;
00013	var float				MouseY;
00014	
00015	var class<UWindowConsoleWindow> ConsoleClass;
00016	var config float		MouseScale;
00017	var config bool			ShowDesktop;
00018	var config bool			bShowConsole;
00019	var config float		MenuTranslucency;
00020	var bool				bBlackout;
00021	var bool				bUWindowType;
00022	
00023	var bool				bUWindowActive;
00024	var bool				bQuickKeyEnable;
00025	var bool				bLocked;
00026	var bool				bLevelChange;
00027	var string				OldLevel;
00028	var globalconfig byte	ConsoleKey;
00029	
00030	var config EInputKey	UWindowKey;
00031	
00032	var UWindowConsoleWindow ConsoleWindow;
00033	
00034	function ResetUWindow()
00035	{
00036		if(Root != None)
00037			Root.Close();
00038		Root = None;
00039		bCreatedRoot = False;
00040		ConsoleWindow = None;
00041		bShowConsole = False;
00042		CloseUWindow();
00043	}
00044	
00045	event bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
00046	{
00047		local byte k;
00048		k = Key;
00049		switch(Action)
00050		{
00051		case IST_Press:
00052			switch(k)
00053			{
00054			case EInputKey.IK_Escape:
00055				if (bLocked)
00056					return true;
00057	
00058				Root.GetPlayerOwner().RendMap = 0;
00059				bQuickKeyEnable = False;
00060				LaunchUWindow();
00061				return true;
00062			case ConsoleKey:
00063				if (bLocked)
00064					return true;
00065	
00066				bQuickKeyEnable = True;
00067				LaunchUWindow();
00068				if(!bShowConsole)
00069					ShowConsole();
00070				return true;
00071			}
00072			break;
00073		}
00074	
00075		return False; 
00076		//!! because of ConsoleKey
00077		//!! return Super.KeyEvent(Key, Action, Delta);
00078	}
00079	
00080	function ShowConsole()
00081	{
00082		bShowConsole = true;
00083		if(bCreatedRoot)
00084			ConsoleWindow.ShowWindow();
00085	}
00086	
00087	function HideConsole()
00088	{
00089		ConsoleLines = 0;
00090		bShowConsole = false;
00091		if (ConsoleWindow != None)
00092			ConsoleWindow.HideWindow();
00093	}
00094	
00095	event Tick( float Delta )
00096	{
00097		Super.Tick(Delta);
00098	
00099		if(bLevelChange && Root != None && string(Viewport.Actor.Level) != OldLevel)
00100		{
00101			OldLevel = string(Viewport.Actor.Level);
00102			// if this is Entry, we could be falling through to another level...
00103			if(Viewport.Actor.Level != Viewport.Actor.GetEntryLevel())
00104				bLevelChange = False;
00105			Root.NotifyAfterLevelChange();
00106		}
00107	}
00108	
00109	state UWindow
00110	{
00111		event EndState()
00112		{
00113			Root.GetPlayerOwner().RendMap = 5;
00114		}
00115	
00116		event Tick( float Delta )
00117		{
00118			Global.Tick(Delta);
00119			if(Root != None)
00120				Root.DoTick(Delta);
00121		}
00122	
00123		event PostRender( canvas Canvas )
00124		{
00125			if( bTimeDemo )
00126			{	
00127				TimeDemoCalc();
00128				TimeDemoRender( Canvas );
00129			}
00130	
00131			if(Root != None)
00132				Root.bUWindowActive = True;
00133			RenderUWindow( Canvas );
00134		}
00135	
00136		event bool KeyType( EInputKey Key )
00137		{
00138			if (Root != None)
00139				Root.WindowEvent(WM_KeyType, None, MouseX, MouseY, Key);
00140			return True;
00141		}
00142	
00143		event bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
00144		{
00145			local byte k;
00146			k = Key;
00147	
00148			switch (Action)
00149			{
00150			case IST_Release:
00151				switch (k)
00152				{
00153				case EInputKey.IK_LeftMouse:
00154					if(Root != None) 
00155						Root.WindowEvent(WM_LMouseUp, None, MouseX, MouseY, k);
00156					break;
00157				case EInputKey.IK_RightMouse:
00158					if(Root != None)
00159						Root.WindowEvent(WM_RMouseUp, None, MouseX, MouseY, k);
00160					break;
00161				case EInputKey.IK_MiddleMouse:
00162					if(Root != None)
00163						Root.WindowEvent(WM_MMouseUp, None, MouseX, MouseY, k);
00164					break;
00165				default:
00166					if(Root != None)
00167						Root.WindowEvent(WM_KeyUp, None, MouseX, MouseY, k);
00168					break;
00169				}
00170				break;
00171	
00172			case IST_Press:
00173				switch (k)
00174				{
00175				case EInputKey.IK_F9:	// Screenshot
00176					return Global.KeyEvent(Key, Action, Delta);
00177					break;
00178				case ConsoleKey:
00179					if (bShowConsole)
00180					{
00181						HideConsole();
00182						if(bQuickKeyEnable)
00183							CloseUWindow();
00184					}
00185					else
00186					{
00187						if(Root.bAllowConsole)
00188							ShowConsole();
00189						else
00190							Root.WindowEvent(WM_KeyDown, None, MouseX, MouseY, k);
00191					}
00192					break;
00193				case EInputKey.IK_Escape:
00194					if(Root != None)
00195						Root.CloseActiveWindow();
00196					break;
00197				case EInputKey.IK_LeftMouse:
00198					if(Root != None)
00199						Root.WindowEvent(WM_LMouseDown, None, MouseX, MouseY, k);
00200					break;
00201				case EInputKey.IK_RightMouse:
00202					if(Root != None)
00203						Root.WindowEvent(WM_RMouseDown, None, MouseX, MouseY, k);
00204					break;
00205				case EInputKey.IK_MiddleMouse:
00206					if(Root != None)
00207						Root.WindowEvent(WM_MMouseDown, None, MouseX, MouseY, k);
00208					break;
00209				default:
00210					if(Root != None)
00211						Root.WindowEvent(WM_KeyDown, None, MouseX, MouseY, k);
00212					break;
00213				}
00214				break;
00215			case IST_Axis:
00216				switch (Key)
00217				{
00218				case IK_MouseX:
00219					MouseX = MouseX + (MouseScale * Delta);
00220					break;
00221				case IK_MouseY:
00222					MouseY = MouseY - (MouseScale * Delta);
00223					break;					
00224				}
00225			default:
00226				break;
00227			}
00228	
00229			return true;
00230		}
00231	
00232	Begin:
00233	}
00234	
00235	function ToggleUWindow()
00236	{
00237	}
00238	
00239	function LaunchUWindow()
00240	{
00241		local int i;
00242	
00243		Root.GetPlayerOwner().Typing(true);	//RUNE: Now typing
00244	
00245		Viewport.bSuspendPrecaching = True;
00246		bUWindowActive = !bQuickKeyEnable;
00247		Viewport.bShowWindowsMouse = True;
00248	
00249		if(bQuickKeyEnable)
00250			bNoDrawWorld = False;
00251		else
00252		{
00253			if(Viewport.Actor.Level.NetMode == NM_Standalone)
00254				Viewport.Actor.SetPause( True );
00255			bNoDrawWorld = ShowDesktop;
00256		}
00257		if(Root != None)
00258			Root.bWindowVisible = True;
00259	
00260		GotoState('UWindow');
00261	}
00262	
00263	function CloseUWindow()
00264	{
00265		Root.GetPlayerOwner().Typing(false);	//RUNE: Not typing
00266	
00267		if(!bQuickKeyEnable)
00268			Viewport.Actor.SetPause( False );
00269	
00270		bNoDrawWorld = False;
00271		bQuickKeyEnable = False;
00272		bUWindowActive = False;
00273		Viewport.bShowWindowsMouse = False;
00274	
00275		if(Root != None)
00276			Root.bWindowVisible = False;
00277		GotoState('');
00278		Viewport.bSuspendPrecaching = False;
00279	}
00280	
00281	function CreateRootWindow(Canvas Canvas)
00282	{
00283		local int i;
00284	
00285		if(Canvas != None)
00286		{
00287			OldClipX = Canvas.ClipX;
00288			OldClipY = Canvas.ClipY;
00289		}
00290		else
00291		{
00292			OldClipX = 0;
00293			OldClipY = 0;
00294		}
00295		
00296	//	Log("Creating root window: "$RootWindow);
00297		
00298		Root = New(None) class<UWindowRootWindow>(DynamicLoadObject(RootWindow, class'Class'));
00299	
00300		Root.BeginPlay();
00301		Root.WinTop = 0;
00302		Root.WinLeft = 0;
00303	
00304		if(Canvas != None)
00305		{
00306			Root.WinWidth = Canvas.ClipX / Root.GUIScale;
00307			Root.WinHeight = Canvas.ClipY / Root.GUIScale;
00308			Root.RealWidth = Canvas.ClipX;
00309			Root.RealHeight = Canvas.ClipY;
00310		}
00311		else
00312		{
00313			Root.WinWidth = 0;
00314			Root.WinHeight = 0;
00315			Root.RealWidth = 0;
00316			Root.RealHeight = 0;
00317		}
00318	
00319		Root.ClippingRegion.X = 0;
00320		Root.ClippingRegion.Y = 0;
00321		Root.ClippingRegion.W = Root.WinWidth;
00322		Root.ClippingRegion.H = Root.WinHeight;
00323	
00324		Root.Console = Self;
00325	
00326		Root.bUWindowActive = bUWindowActive;
00327	
00328		Root.Created();
00329		bCreatedRoot = True;
00330	
00331		// Create the console window.
00332		ConsoleWindow = UWindowConsoleWindow(Root.CreateWindow(ConsoleClass, 100, 100, 200, 200));
00333		if(!bShowConsole)
00334			HideConsole();
00335	
00336		UWindowConsoleClientWindow(ConsoleWindow.ClientArea).TextArea.AddText(" ");
00337		for (I=0; I<4; I++)
00338			UWindowConsoleClientWindow(ConsoleWindow.ClientArea).TextArea.AddText(MsgText[I]);
00339	}
00340	
00341	function RenderUWindow( canvas Canvas )
00342	{
00343		local UWindowWindow NewFocusWindow;
00344	
00345		Canvas.bNoSmooth = True;
00346		Canvas.Z = 1;
00347		Canvas.Style = 1;
00348		Canvas.DrawColor.r = 255;
00349		Canvas.DrawColor.g = 255;
00350		Canvas.DrawColor.b = 255;
00351	
00352		if(Viewport.bWindowsMouseAvailable && Root != None)
00353		{
00354			MouseX = Viewport.WindowsMouseX/Root.GUIScale;
00355			MouseY = Viewport.WindowsMouseY/Root.GUIScale;
00356		}
00357	
00358		if(!bCreatedRoot) 
00359			CreateRootWindow(Canvas);
00360	
00361		Root.bWindowVisible = True;
00362		Root.bUWindowActive = bUWindowActive;
00363		Root.bQuickKeyEnable = bQuickKeyEnable;
00364	
00365		if(Canvas.ClipX != OldClipX || Canvas.ClipY != OldClipY)
00366		{
00367			OldClipX = Canvas.ClipX;
00368			OldClipY = Canvas.ClipY;
00369	
00370			// RUNE: Explicitly set scale when changing resolution
00371			Root.ComputeGuiScale(Canvas.ClipX, Canvas.ClipY);
00372			
00373			Root.WinTop = 0;
00374			Root.WinLeft = 0;
00375			Root.WinWidth = Canvas.ClipX / Root.GUIScale;
00376			Root.WinHeight = Canvas.ClipY / Root.GUIScale;
00377	
00378			Root.RealWidth = Canvas.ClipX;
00379			Root.RealHeight = Canvas.ClipY;
00380	
00381			Root.ClippingRegion.X = 0;
00382			Root.ClippingRegion.Y = 0;
00383			Root.ClippingRegion.W = Root.WinWidth;
00384			Root.ClippingRegion.H = Root.WinHeight;
00385	
00386			Root.Resized();
00387		}
00388	
00389		if(MouseX > Root.WinWidth) MouseX = Root.WinWidth;
00390		if(MouseY > Root.WinHeight) MouseY = Root.WinHeight;
00391		if(MouseX < 0) MouseX = 0;
00392		if(MouseY < 0) MouseY = 0;
00393	
00394	
00395		// Check for keyboard focus
00396		NewFocusWindow = Root.CheckKeyFocusWindow();
00397	
00398		if(NewFocusWindow != Root.KeyFocusWindow)
00399		{
00400			Root.KeyFocusWindow.KeyFocusExit();		
00401			Root.KeyFocusWindow = NewFocusWindow;
00402			Root.KeyFocusWindow.KeyFocusEnter();
00403		}
00404	
00405	
00406		Root.MoveMouse(MouseX, MouseY);
00407		Root.WindowEvent(WM_Paint, Canvas, MouseX, MouseY, 0);
00408		if(bUWindowActive || bQuickKeyEnable) 
00409			Root.DrawMouse(Canvas);
00410	}
00411	
00412	event Message( PlayerReplicationInfo PRI, coerce string Msg, name N )
00413	{
00414		local string OutText;
00415	
00416		Super.Message( PRI, Msg, N );
00417	
00418		if ( Viewport.Actor == None )
00419			return;
00420	
00421		if( Msg!="" )
00422		{
00423			if (( MsgType[TopLine] == 'Say' ) || ( MsgType[TopLine] == 'TeamSay' ))
00424				OutText = MsgPlayer[TopLine].PlayerName$": "$MsgText[TopLine];
00425			else
00426				OutText = MsgText[TopLine];
00427			if (ConsoleWindow != None)
00428				UWindowConsoleClientWindow(ConsoleWindow.ClientArea).TextArea.AddText(OutText);
00429		}
00430	}
00431	
00432	event AddString( coerce string Msg )
00433	{
00434		Super.AddString( Msg );
00435	
00436		if( Msg!="" )
00437		{
00438			if (ConsoleWindow != None)
00439				UWindowConsoleClientWindow(ConsoleWindow.ClientArea).TextArea.AddText(Msg);
00440		}
00441	}
00442	
00443	function UpdateHistory()
00444	{
00445		// Update history buffer.
00446		History[HistoryCur++ % MaxHistory] = TypedStr;
00447		if( HistoryCur > HistoryBot )
00448			HistoryBot++;
00449		if( HistoryCur - HistoryTop >= MaxHistory )
00450			HistoryTop = HistoryCur - MaxHistory + 1;
00451	}
00452	
00453	function HistoryUp()
00454	{
00455		if( HistoryCur > HistoryTop )
00456		{
00457			History[HistoryCur % MaxHistory] = TypedStr;
00458			TypedStr = History[--HistoryCur % MaxHistory];
00459		}
00460	}
00461	
00462	function HistoryDown()
00463	{
00464		History[HistoryCur % MaxHistory] = TypedStr;
00465		if( HistoryCur < HistoryBot )
00466			TypedStr = History[++HistoryCur % MaxHistory];
00467		else
00468			TypedStr="";
00469	}
00470	
00471	function NotifyLevelChange()
00472	{
00473		Super.NotifyLevelChange();
00474		bLevelChange = True;
00475		if(Root != None)
00476			Root.NotifyBeforeLevelChange();
00477	}
00478	
00479	defaultproperties
00480	{
00481	     RootWindow="UWindow.UWindowRootWindow"
00482	     ConsoleClass=Class'UWindow.UWindowConsoleWindow'
00483	     MouseScale=0.600000
00484	     MenuTranslucency=1.000000
00485	     ConsoleKey=192
00486	}

End Source Code