Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UTGame.UTUIScene_MessageBox


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
/**
 * Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
 *
 * Generic Message Box Scene for UT3
 */
class UTUIScene_MessageBox extends UTUIScene
	native(UI);
























































































































 



#linenumber 9

const MESSAGEBOX_MAX_POSSIBLE_OPTIONS = 4;

const CANCEL_BUTTON_MARKUP_STRING = "<Strings:UTGameUI.Generic.Cancel>";

// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)

/** Whether you want the message box's dialog and title to position itself to the center of the screen or not. */
var() bool bRepositionMessageToCenter;

/** Message box message. */
var transient UILabel					MessageLabel;

/** Message box title markup. */
var transient UILabel					TitleLabel;

/** Reference to the owning widget that has all of the content of the message box scene. */
var transient UIObject					BackgroundImage;

/** Reference to the scroll window that holds the message label. */
var transient UIObject					ScrollWindow;

/** References to the scene's buttonbar. */
var transient UTUIButtonBar				ButtonBar;

/** Array of potential options markup. */
var transient array<string>				PotentialOptions;

/** Arrays of key's that trigger each potential option. */
struct native PotentialOptionKeys
{
	var array<name>		Keys;
};

var transient array<PotentialOptionKeys>		PotentialOptionKeyMappings;

/** Whether or not the message box is fully visible. */
var transient bool								bFullyVisible;

/** Stores which option the user selected. */
var transient int						PreviouslySelectedOption;

/** Index of the player that selected the option. */
var transient int						SelectingPlayer;

/** Index of the option that is selected by default, valid for PC only. */
var transient int						DefaultOptionIdx;

/** The time the message box was fully displayed. */
var transient float						DisplayTime;

/** The minimum amount of time to display modal message boxes for. */
var transient float						MinimumDisplayTime;

/** How long to take to display/hide the message box. */
var transient float						FadeDuration;

/** Direction we are currently fading, positive is fade in, negative is fade out, 0 is not fading. */
var transient int						FadeDirection;

/** Time fading started. */
var transient float						FadeStartTime;

/** Flag that lets the dialog know it should hide itself. */
var transient bool						bHideOnNextTick;

/** Flag which is used natively to recalculate the dialog button positions */
var bool							bRepositionButtons;

/**
 * The user has made a selection of the choices available to them.
 */
delegate OnSelection(UTUIScene_MessageBox MessageBox, int SelectedOption, int PlayerIndex);

/** Delegate called after the message box has been competely closed. */
delegate OnClosed();

/** Delegate to trap any input to the message box. */
delegate bool OnMBInputKey( const out InputEventParameters EventParms );

event Initialized()
{
	Super.Initialized();

	// for some reason the scene's event component serialized the DisabledEventAliases array with 0 elements, so make sure that Closed is in the list
	EventProvider.DisabledEventAliases.AddItem('CloseScene');
}

/** Sets delegates for the scene. */
event PostInitialize()
{
	Super.PostInitialize();

	// Setup a key handling delegate.

	// Store references to key objects.
	MessageLabel = UILabel(FindChild('lblMessage',true));
	TitleLabel = UILabel(FindChild('lblTitle',true));
	ButtonBar = UTUIButtonBar(Findchild('pnlButtonBar', true));
	ScrollWindow = FindChild('pnlScrollFrame', true);
	BackgroundImage = FindChild('imgBackground', true);
}

/**
 * Sets the potential options for a message box.
 *
 * @param InPotentialOptions				Potential options the user has to choose from.
 * @param InPotentialOptionsKeyMappings		Button keys that map to the options specified, usually this can be left to defaults.
 */
function SetPotentialOptions(array<string> InPotentialOptions, optional array<PotentialOptionKeys> InPotentialOptionKeyMappings)
{
	PotentialOptions = InPotentialOptions;
}

/**
 * Sets the potential option key mappings for a message box, usually this can be left to defaults.
 *
 * @param InPotentialOptions				Potential options the user has to choose from.
 * @param InPotentialOptionsKeyMappings		Button keys that map to the options specified, usually this can be left to defaults.
 */
function SetPotentialOptionKeyMappings(array<PotentialOptionKeys> InPotentialOptionKeyMappings)
{
	PotentialOptionKeyMappings=InPotentialOptionKeyMappings;
}

/**
 * Changes the title for this messagebox.
 *
 * @param	NewTitle	the new title for the message box
 */
function SetTitle(string NewTitle)
{
	TitleLabel.SetDatastoreBinding(NewTitle);
}

/**
 * Sets the current message for this messagebox.
 *
 * @param NewMessage	New message for the messagebox.
 */
function SetMessage(string NewMessage)
{
	local int i;

	// NOTE: GetValue should return the processed string, i.e. without markups
	i = Len(MessageLabel.GetValue());

	MessageLabel.SetDatastoreBinding(NewMessage);

	// If the new label is bigger than the last, recalculate button positions (otherwise buttons may overlap text)
	if (Len(MessageLabel.GetValue()) > i)
		bRepositionButtons = True;
}

/**
 * Wrapper for setting the OnSelection delegate.
 */
function SetSelectionDelegate( delegate<OnSelection> InSelectionDelegate )
{
	OnSelection = InSelectionDelegate;
}

/**
 * Closes the message box, used for modal message boxes.
 *
 * @param	bSimulateCancel		specify TRUE to generate a cancel button press event; otherwise, whichever button is in
 *								the last slot (e.g. PotentialOptions[0]) will appear to have been pressed).
 * @param	PlayerIndex			the index of the player that generated the close event.
 */
function Close( optional bool bSimulateCancel, optional int PlayerIndex=GetBestPlayerIndex() )
{
	local int CancelButtonIndex;

	if ( bSimulateCancel )
	{
		CancelButtonIndex = Max(0, FindCancelButtonIndex());
		OptionSelected(CancelButtonIndex, PlayerIndex);
	}
	else
	{
		bHideOnNextTick = true;
	}
}

/**
 * Displays a message box that has the default button layout; useful when you may be reusing the same scene instance
 *
 * @param Message				Message for the message box.  Should be datastore markup.
 * @param Title					Title for the message box.  Should be datastore markup.
 * @param InSelectionDelegate	Delegate to call when the user dismisses the message box.
 */
function DisplayAcceptBox(string Message, optional string Title="", optional delegate<OnSelection> InSelectionDelegate)
{
	PotentialOptions = default.PotentialOptions;
	PotentialOptionKeyMappings = default.PotentialOptionKeyMappings;

	Display(Message,Title,InSelectionDelegate);
}

/**
 * Displays a message box that has a cancel button only.
 *
 * @param Message				Message for the message box.  Should be datastore markup.
 * @param Title					Title for the message box.  Should be datastore markup.
 * @param InSelectionDelegate	Delegate to call when the user dismisses the message box.
 */
function DisplayCancelBox(string Message, optional string Title="", optional delegate<OnSelection> InSelectionDelegate)
{
	if ( !bFullyVisible )
	{
		PotentialOptions.length = 1;
		PotentialOptions[0]=CANCEL_BUTTON_MARKUP_STRING;

		PotentialOptionKeyMappings.length = 1;
		PotentialOptionKeyMappings[0].Keys.length=2;
		PotentialOptionKeyMappings[0].Keys[0]='XboxTypeS_B';
		PotentialOptionKeyMappings[0].Keys[1]='Escape';

		Display(Message,Title,InSelectionDelegate);
	}
	else
	{
		if ( PotentialOptions.Length != 1
		||	PotentialOptions[0] != CANCEL_BUTTON_MARKUP_STRING )
		{
			PotentialOptions.length = 1;
			PotentialOptions[0]=CANCEL_BUTTON_MARKUP_STRING;

			PotentialOptionKeyMappings.length = 1;
			PotentialOptionKeyMappings[0].Keys.length=2;
			PotentialOptionKeyMappings[0].Keys[0]='XboxTypeS_B';
			PotentialOptionKeyMappings[0].Keys[1]='Escape';
			SetupButtonBar();
		}

		SetTitle(Title);
		SetMessage(Message);
		SetSelectionDelegate(InSelectionDelegate);
	}
}

/**
 * Displays a message box that has an accept and cancel button.
 *
 * @param Message				Message for the message box.  Should be datastore markup.
 * @param Title					Title for the message box.  Should be datastore markup.
 * @param InSelectionDelegate	Delegate to call when the user dismisses the message box.
 */
function DisplayAcceptCancelBox(string Message, optional string Title="", optional delegate<OnSelection> InSelectionDelegate)
{
	PotentialOptions.length = 2;
	PotentialOptions[0]="<strings:UTGameUI.Generic.OK>";
	PotentialOptions[1]=CANCEL_BUTTON_MARKUP_STRING;

	PotentialOptionKeyMappings.length = 2;
	PotentialOptionKeyMappings[0].Keys.length=1;
	PotentialOptionKeyMappings[0].Keys[0]='XboxTypeS_A';
	PotentialOptionKeyMappings[1].Keys.length=2;
	PotentialOptionKeyMappings[1].Keys[0]='XboxTypeS_B';
	PotentialOptionKeyMappings[1].Keys[1]='Escape';

	Display(Message, Title, InSelectionDelegate);
}


/** Displays a message box that has no buttons and must be closed by the scene that opened it. */
function DisplayModalBox(string Message, optional string Title="", optional float InMinDisplayTime=2.0f)
{
	// If we're not shown yet, do the fade in animation, otherwise just update the text.
	if ( !bFullyVisible )
	{
		// This is a ship requirement, we need to display modal dialogs for a minimum amount of time.
		MinimumDisplayTime = InMinDisplayTime;
		PotentialOptions.length = 0;
		PotentialOptionKeyMappings.length = 0;
		ButtonBar.SetVisibility(false);

		Display(Message,Title);
	}
	else
	{
		DefaultOptionIdx = INDEX_NONE;
		SetSelectionDelegate(None);

		SetTitle(Title);
		SetMessage(Message);

		if ( PotentialOptions.Length > 0 )
		{
			PotentialOptions.Length = 0;
			PotentialOptionKeyMappings.Length = 0;
			ButtonBar.SetVisibility(false);
			SetupButtonBar();
		}
	}
}


/**
 * Displays the message box.
 *
 * @param Message				Message for the message box.  Should be datastore markup.
 * @param Title					Title for the message box.  Should be datastore markup.
 * @param InSelectionDelegate	Delegate to call when the user dismisses the message box.
 */
function Display(string Message, optional string Title="", optional delegate<OnSelection> InSelectionDelegate, optional int InDefaultOptionIdx=INDEX_NONE)
{
	local int OptionIdx;

	LogInternal(Name$"::"$GetFuncName()@"Message:'"$Message$"'"@"Title:'"$Title$"'"@"DelegateValid:'"$InSelectionDelegate!=None$"'"@"InDefaultOptionIdx:'"$InDefaultOptionIdx$"'",'DevUI');

	SetTitle(Title);
	SetMessage(Message);
	SetSelectionDelegate(InSelectionDelegate);
	DefaultOptionIdx = InDefaultOptionIdx;

	SetupButtonBar();

	// Set focus to the default option
	if(PotentialOptions.length > 0)
	{
		OptionIdx = PotentialOptions.Length - 1 - Max(0, DefaultOptionIdx);
		ButtonBar.Buttons[OptionIdx].SetFocus(none);
	}

	// Start showing the scene.

	// only call BlockUIInput if we aren't already performing a fade animation; otherwise, the number of calls to BeginShow
	// won't match the number of calls to OnShowComplete, so we end up blocking more than we unblock
	if ( FadeDirection == 0 )
	{
		GetUTInteraction().BlockUIInput(true);
	}

	BeginShow();
}

/**
 * Sets up the buttons that should be visible in the bar across the bottom of the scene.
 */
function SetupButtonBar()
{
	local int OptionIdx;

	// Setup buttons.  We only show enough buttons to cover each of the options the user specified.
	ButtonBar.Clear();
	for(OptionIdx=0;  OptionIdx<MESSAGEBOX_MAX_POSSIBLE_OPTIONS && OptionIdx<PotentialOptions.length; OptionIdx++)
	{
		// Reverse the index when displaying buttons so cancel is always shown to the far left.
		ButtonBar.AppendButton(PotentialOptions[PotentialOptions.length-OptionIdx-1], OnOptionButton_Clicked);
	}
}

/**
 * Provides a hook for unrealscript to respond to input using actual input key names (i.e. Left, Tab, etc.)
 *
 * Called when an input key event is received which this widget responds to and is in the correct state to process.  The
 * keys and states widgets receive input for is managed through the UI editor's key binding dialog (F8).
 *
 * This delegate is called BEFORE kismet is given a chance to process the input.
 *
 * @param	EventParms	information about the input event.
 *
 * @return	TRUE to indicate that this input key was processed; no further processing will occur on this input key event.
 */
function bool HandleInputKey( const out InputEventParameters EventParms )
{
	local bool bResult;
	local int OptionIdx;
	local int ButtonIdx;
	local array<name> KeyMappings;

	bResult=false;

	if(bFullyVisible)
	{
		// Give the mb delegate first chance at input
		bResult = OnMBInputKey(EventParms);

		if( !bResult )
		{
			if(EventParms.EventType==IE_Released)
			{
				// See if the key pressed is mapped to any of the potential options.
				for(OptionIdx=0; OptionIdx<PotentialOptions.length && OptionIdx<MESSAGEBOX_MAX_POSSIBLE_OPTIONS && OptionIdx<PotentialOptionKeyMappings.length && bResult==false; OptionIdx++)
				{
					KeyMappings=PotentialOptionKeyMappings[OptionIdx].Keys;

					for(ButtonIdx=0; ButtonIdx<KeyMappings.length; ButtonIdx++)
					{
						if(EventParms.InputKeyName==KeyMappings[ButtonIdx])
						{
							OptionSelected(OptionIdx, EventParms.PlayerIndex);
							bResult = true;
							break;
						}
					}
				}
			}
		}
	}

	return bResult;
}

/** Starts showing the message box. */
native function BeginShow();

/** Called when the dialog has finished showing itself. */
event OnShowComplete()
{
	//`Log("UTUIMessageBox::OnShowComplete() - Finished showing messagebox");

	GetUTInteraction().BlockUIInput(false);
	bFullyVisible = true;
	FadeDirection = 0;
}

/** Starts hiding the message box. */
native function BeginHide();

/** Called when the dialog is finished hiding itself. */
event OnHideComplete()
{
	//`Log("UTUIMessageBox::OnHideComplete() - Finished hiding messagebox");

	FadeDirection = 0;

	// Close ourselves.
	CloseScene(self, true);

	// Fire the OnClosed delegate
	OnClosed();

	// and clear it
	OnClosed = None;

	// Fire the OnSelection delegate
	OnSelection(Self, PreviouslySelectedOption, SelectingPlayer);
}

/**
 * Callback for the OnClicked event.
 *
 * @param EventObject	Object that issued the event.
 * @param PlayerIndex	Player that performed the action that issued the event.
 *
 * @return	return TRUE to prevent the kismet OnClick event from firing.
 */
function bool OnOptionButton_Clicked(UIScreenObject EventObject, int PlayerIndex)
{
	local int OptionIdx;

	if(bFullyVisible)
	{
		for(OptionIdx=0; OptionIdx<MESSAGEBOX_MAX_POSSIBLE_OPTIONS; OptionIdx++)
		{
			if(EventObject==ButtonBar.Buttons[OptionIdx])
			{
				// Need to reverse the index
				OptionSelected(PotentialOptions.length-OptionIdx-1, PlayerIndex);
				break;
			}
		}
	}

	return false;
}

/**
 * Called when a user has chosen one of the possible options available to them.
 * Begins hiding the dialog and calls the On
 *
 * @param OptionIdx		Index of the selection option.
 * @param PlayerIndex	Index of the player that selected the option.
 */
function OptionSelected(int OptionIdx, int PlayerIndex)
{
	PreviouslySelectedOption=OptionIdx;
	SelectingPlayer=PlayerIndex;
	bHideOnNextTick = true;
}

/**
 * Determines the index of the button corresponding to the cancel button.
 *
 * @param	CancelButtonMarkupString	if a custom markup string was used for the cancel button, it can be specified here;
 *										otherwise the default markup string for the cancel button is used.
 *
 * @return	the index of the button used to cancel this dialog, or INDEX_NONE if a cancel button wasn't found.
 */
function int FindCancelButtonIndex( optional string CancelButtonMarkupString )
{
	if ( CancelButtonMarkupString == "" )
	{
		CancelButtonMarkupString = CANCEL_BUTTON_MARKUP_STRING;
	}

	return PotentialOptions.Find(CancelButtonMarkupString);
}

// Reposition buttons upon resolution change
function OnResolutionChanged(const out Vector2D OldViewportsize, const out Vector2D NewViewportSize)
{
	bRepositionButtons = True;
}

defaultproperties
{
   bRepositionMessageToCenter=True
   bRenderParentScenes=True
   bPauseGameWhileActive=False
   DefaultContextMenuClass=Class'Engine.UIContextMenu'
   SceneRenderMode=SPLITRENDER_Fullscreen
   Begin Object Class=UIComp_Event Name=WidgetEventComponent ObjName=WidgetEventComponent Archetype=UIComp_Event'Engine.Default__UIComp_Event'
      DisabledEventAliases(0)="CloseScene"
      Name="WidgetEventComponent"
      ObjectArchetype=UIComp_Event'Engine.Default__UIComp_Event'
   End Object
   EventProvider=WidgetEventComponent
   __OnRawInputKey__Delegate=Default__UTUIScene_MessageBox.HandleInputKey
   __NotifyResolutionChanged__Delegate=Default__UTUIScene_MessageBox.OnResolutionChanged
   Name="Default__UTUIScene_MessageBox"
   ObjectArchetype=UTUIScene'UTGame.Default__UTUIScene'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: tr 31-1-2018 17:18:26.000 - Creation time: sk 18-3-2018 10:01:27.364 - Created with UnCodeX