## Engine
Class InteractionMaster

source: C:\XIII\Engine\Classes\InteractionMaster.uc

    Core.Object
       |
       +--Engine.Interactions
          |
          +--Engine.InteractionMaster

Direct Known Subclasses:None

class InteractionMaster
extends Engine.Interactions

    // ====================================================================
    //  Class:  Engine.InteractionMaster
    //
    //  The InteractionMaster controls the entire interaction system.  It's
    //  job is to take input and Pre/PostRender call and route them to individual
    //  Interactions and/or viewports.
    //
    // 	The stubs here in script are for just the GlobalInteracations as those
    // 	are the only Interactions the IM routes directly too.  A new stub is
    // 	created in order to limit the number of C++ -> Uscript switches.
    //
    // (c) 2001, Epic Games, Inc.  All Rights Reserved
    // ====================================================================

Variables
`Interaction` | `BaseMenu` Holds a pointer to the base menu system
`Client` | `CLient`
`Interaction` | `Console` Holds the special Interaction that acts as the console
`float` | `DelayOfGlobalInputInactivityBeforeTimeOut` after this delay (in seconds), with no input from the user, the time out will be launched
`array` | `GlobalInteractions` Holds a listing of all global Interactions
`bool` | `GlobalTimeOutArmed` if true, the global time out system is used
`float` | `TimeOfLastInput` after this delay (in seconds), with no input from the user, the time out will be launched

Function Summary
`void` | `Travel(string URL)`

Source Code

    00001	// ====================================================================
    00002	//  Class:  Engine.InteractionMaster
    00003	//
    00004	//  The InteractionMaster controls the entire interaction system.  It's
    00005	//  job is to take input and Pre/PostRender call and route them to individual
    00006	//  Interactions and/or viewports.
    00007	//
    00008	// 	The stubs here in script are for just the GlobalInteracations as those
    00009	// 	are the only Interactions the IM routes directly too.  A new stub is
    00010	// 	created in order to limit the number of C++ -> Uscript switches.
    00011	//
    00012	// (c) 2001, Epic Games, Inc.  All Rights Reserved
    00013	// ====================================================================
    00014
    00015	class InteractionMaster extends Interactions
    00016		    transient
    00017			Native;
    00018
    00019	var transient Client CLient;
    00020
    00021	var transient const Interaction BaseMenu;	// Holds a pointer to the base menu system
    00022	var transient const Interaction Console;	// Holds the special Interaction that acts as the console
    00023	var transient array<Interaction> GlobalInteractions;	// Holds a listing of all global Interactions
    00024
    00025
    00026	// Global time out system: whether in menu or game, if there is no user input for too long, a time out is launched (event InputTimeOut() is called)
    00027	var bool GlobalTimeOutArmed;                               // if true, the global time out system is used
    00028	var float DelayOfGlobalInputInactivityBeforeTimeOut;       // after this delay (in seconds), with no input from the user, the time out will be launched
    00029	var const float TimeOfLastInput;
    00030
    00031	native function Travel(string URL);	// Setup a travel to a new map
    00032
    00033	// ====================================================================
    00034	// Control functions
    00035	// ====================================================================
    00036
    00037	event Interaction AddInteraction(string InteractionName, optional Player AttachTo) 	// Adds an Interaction
    00038	{
    00039		local Interaction NewInteraction;
    00040		local class<Interaction> NewInteractionClass;
    00041
    00042		NewInteractionClass = class<Interaction>(DynamicLoadObject(InteractionName, class'Class'));
    00043
    00044		if (NewInteractionClass!=None)
    00045		{
    00046			NewInteraction = new NewInteractionClass;
    00047			if (NewInteraction != None)
    00048			{
    00049
    00050				// Place the Interaction in the proper array
    00051
    00052				if (AttachTo != None)	// Handle location Interactions
    00053				{
    00054					AttachTo.LocalInteractions.Length = AttachTo.LocalInteractions.Length + 1;
    00055					AttachTo.LocalInteractions[AttachTo.LocalInteractions.Length-1] = NewInteraction;
    00056					NewInteraction.ViewportOwner = AttachTo;
    00057				}
    00058				else	// Handle Global Interactions
    00059				{
    00060					GlobalInteractions.Length = GlobalInteractions.Length + 1;
    00061					GlobalInteractions[GlobalInteractions.Length-1] = NewInteraction;
    00062				}
    00063
    00064				// Initialize the Interaction
    00065
    00066				NewInteraction.Initialize();
    00067				NewInteraction.Master = Self;
    00068
    00069				return NewInteraction;
    00070
    00071			}
    00072			else
    00073	  			Log("Could not create interaction ["$InteractionName$"]",'IMaster');
    00074
    00075		}
    00076		else
    00077			Log("Could not load interaction ["$InteractionName$"]",'IMaster');
    00078
    00079		return none;
    00080
    00081	} // AddInteraction
    00082
    00083	event RemoveInteraction(interaction RemoveMe)			// Removes a Interaction
    00084	{
    00085		local int Index;
    00086
    00087
    00088		if (RemoveMe.ViewportOwner != None)
    00089		{
    00090			for (Index = 0; Index < RemoveMe.ViewPortOwner.LocalInteractions.Length; Index++)
    00091			{
    00092				if ( RemoveMe.ViewPortOwner.LocalInteractions[Index] == RemoveMe )
    00093				{
    00094					RemoveMe.ViewPortOwner.LocalInteractions.Remove(Index,1);
    00095					return;
    00096				}
    00097			}
    00098		}
    00099		else
    00100		{
    00101			for (Index = 0; Index < GlobalInteractions.Length; Index++)
    00102			{
    00103				if ( GlobalInteractions[Index] == RemoveMe )
    00104				{
    00105					GlobalInteractions.Remove(Index,1);
    00106					return;
    00107				}
    00108			}
    00109		}
    00110
    00111		Log("Could not remove interaction ["$RemoveMe$"] (Not Found)", 'IMaster');
    00112
    00113	} // RemoveInteraction
    00114
    00115	// ====================================================================
    00116	// SetFocusTo - This function will cause a window to adjust it's position
    00117	// in it's array so that it processes input first and displays last.
    00118	// ====================================================================
    00119
    00120	event SetFocusTo(Interaction Inter, optional Player ViewportOwner)
    00121	{
    00122		local array<Interaction> InteractionArray;
    00123		local Interaction temp;
    00124		local int i,iIndex;
    00125
    00126
    00127		if (ViewportOwner != none)
    00128			InteractionArray = ViewportOwner.LocalInteractions;
    00129		else
    00130			InteractionArray = GlobalInteractions;
    00131
    00132		if (InteractionArray.Length == 0)
    00133		{
    00134			Log("Attempt to SetFocus on an empty Array.",'IMaster');
    00135			return;
    00136		}
    00137
    00138		// Search for the Interaction
    00139
    00140		iIndex = -1;
    00141		for ( i=0; i<InteractionArray.Length; i++ )
    00142		{
    00143			if (InteractionArray[i] == Inter)
    00144			{
    00145				iIndex = i;
    00146				break;
    00147			}
    00148		}
    00149
    00150		// Was it found?
    00151
    00152		if (iIndex<0)
    00153		{
    00154			log("Interaction "$Inter$" is not in "$ViewportOwner$".",'IMaster');
    00155			return;
    00156		}
    00157		else if (iIndex==0)
    00158			return;					// Already has focus
    00159
    00160
    00161		// Move it to the top.
    00162
    00163		temp = InteractionArray[iIndex];
    00164		for ( i=0; i<iIndex; i++)
    00165			InteractionArray[i+1] = InteractionArray[i];
    00166
    00167		InteractionArray[0] = temp;
    00168		InteractionArray[0].bActive = true;		// Give it Input
    00169		InteractionArray[0].bVisible = true;	// Make it visible
    00170
    00171	    // bug fix proposed by Josh Adams 30/May/2002, confirmed by Joe Wilcox the same day
    00172	    if (ViewportOwner != none)
    00173		    ViewportOwner.LocalInteractions = InteractionArray;
    00174	    else
    00175		    GlobalInteractions = InteractionArray;
    00176	} // SetFocusTo
    00177
    00178
    00179
    00180	// ====================================================================
    00181	// Input Functions
    00182	//
    00183	// The Process functions are here to limit the # of switches from C++ to Script.
    00184	// ====================================================================
    00185	/* --> Become a 100% C++ function
    00186	event bool Process_KeyType( array<Interaction> InteractionArray, out EInputKey Key ) // Process a single key press
    00187	{
    00188		local int Index;
    00189
    00190		// Chain through the Interactions
    00191
    00192		for ( Index=0; Index<InteractionArray.Length; Index++)
    00193		{
    00194			// Give each Interaction the chance to process the key event
    00195
    00196			if ( ( InteractionArray[Index].bActive ) && (!InteractionArray[Index].bNativeEvents) && ( InteractionArray[Index].KeyType(key,Unicode) ) )
    00197				return true;				// and break the chain if processed
    00198
    00199		}
    00200		return false;	// Keep processing
    00201
    00202	} // Process_KeyType
    00203	*/
    00204
    00205	/* --> Become a 100% C++ function
    00206	event bool Process_KeyEvent( array<Interaction> InteractionArray,
    00207					out EInputKey Key, out EInputAction Action, FLOAT Delta ) // Process the range of input events
    00208	{
    00209		local int Index;
    00210
    00211		// Chain through the Interactions
    00212
    00213		for ( Index=0; Index<InteractionArray.Length; Index++)
    00214		{
    00215			// Give each Interaction the chance to process the key event
    00216
    00217			if ( ( InteractionArray[Index].bActive ) && (!InteractionArray[Index].bNativeEvents) && ( InteractionArray[Index].KeyEvent(Key, Action, Delta ) ) )
    00218			{
    00219				return true;						// and break the chain if processed
    00220			}
    00221
    00222		}
    00223		return false;
    00224
    00225	} // Process_KeyEvent
    00226	*/
    00227
    00228	// ====================================================================
    00229	// Render functions only occure on local interactions.  The process
    00230	// the array in reverse order so that the objects that have focus
    00231	// are drawn last.
    00232	// ====================================================================
    00233	/* --> Become a 100% C++ function
    00234
    00235	event Process_PreRender( array<Interaction> InteractionArray, canvas Canvas )
    00236	{
    00237		local int index;
    00238
    00239		// Chain through the Interactions
    00240
    00241		for ( Index=InteractionArray.Length; Index>0; Index--)	// Give each Interaction PreRender time
    00242		{
    00243			if ( (InteractionArray[Index-1].bVisible ) && (!InteractionArray[Index-1].bNativeEvents) )
    00244				InteractionArray[Index-1].PreRender(canvas);
    00245
} 00246 00247 } // Process_PreRender 00248 */ 00249 00250 /* --> Become a 100% C++ function 00251 event Process_PostRender( array<Interaction> InteractionArray, canvas Canvas ) 00252 { 00253 local int index; 00254 00255 // Chain through the Interactions 00256 00257 for ( Index=InteractionArray.Length; Index>0; Index--) // Give each Interaction PreRender time 00258 { 00259 if ( (InteractionArray[Index-1].bVisible ) && (!InteractionArray[Index-1].bNativeEvents) ) 00260 InteractionArray[Index-1].PostRender(canvas); 00261 } 00262 00263 } // Process_PostRender 00264 */ 00265 00266 // ==================================================================== 00267 // Tick - Interactions can request access to be ticked. 00268 // ==================================================================== 00269 /* --> Become a 100% C++ function 00270 event Process_Tick( array<Interaction> InteractionArray, float DeltaTime ) 00271 { 00272 local int Index; 00273 00274 // Chain through the Interactions 00275 00276 for ( Index=0; Index<InteractionArray.Length; Index++) 00277 { 00278 // Give each Interaction that requires it tick 00279 00280 if ( (InteractionArray[Index].bRequiresTick ) && (!InteractionArray[Index].bNativeEvents) ) 00281 InteractionArray[Index].Tick(DeltaTime); 00282 } 00283 } 00284 */ 00285 00286 // ==================================================================== 00287 // Message - The IM is responsible for sending Message events to all 00288 // interactions. 00289 // ==================================================================== 00290 /* --> Become a 100% C++ function 00291 event Process_Message( coerce string Msg, float MsgLife, array<Interaction> InteractionArray) 00292 { 00293 local int Index; 00294 00295 // Chain through the Interactions 00296 00297 for ( Index=0; Index<InteractionArray.Length; Index++) 00298 { 00299 // Give each Interaction the message 00300 00301 InteractionArray[Index].Message(Msg, MsgLife); 00302 } 00303 00304 } // Message 00305 */ 00306 00307 00308 // This event is called if 'GlobalTimeOutArmed' is true, and if no input from the user 00309 // occurred since 'DelayOfGlobalInputInactivityBeforeTimeOut' seconds 00310 event InputTimeOut() 00311 { 00312 log("Time out !!!!!"); 00313 //Console.ConsoleCommand("Exit"); 00314 } 00315 00316 defaultproperties 00317 { 00318 DelayOfGlobalInputInactivityBeforeTimeOut=30.000000 00319 }

End Source Code