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

TribesGUI.TribesSPEscapeMenu


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
// ====================================================================
//  Class:  TribesGui.TribesSPEscapeMenu
//
//  Menu to load map from entry screen.
// ====================================================================

class TribesSPEscapeMenu extends TribesGUIPage
     ;

import enum EInputKey from Engine.Interactions;
import enum EInputAction from Engine.Interactions;

var(TribesGui) private EditInline Config GUIButton		    RestartButton "A component of this page which has its behavior defined in the code for this page's class.";
var(TribesGui) private EditInline Config GUIButton		    LoadButton "A component of this page which has its behavior defined in the code for this page's class.";
var(TribesGui) private EditInline Config GUIButton		    SaveButton "A component of this page which has its behavior defined in the code for this page's class.";
var(TribesGui) private EditInline Config GUIButton		    OptionsButton "A component of this page which has its behavior defined in the code for this page's class.";
var(TribesGui) private EditInline Config GUIButton		    QuitButton "A component of this page which has its behavior defined in the code for this page's class.";
var(TribesGui) private EditInline Config GUIButton		    ReturnButton "A component of this page which has its behavior defined in the code for this page's class.";
var(TribesGui) private EditInline Config GUIButton		    ExitGameButton "A component of this page which has its behavior defined in the code for this page's class.";

var(TribesGui) private EditInline Config localized string   SaveConfirmText;
var(TribesGui) private EditInline Config localized string   ExitConfirmText;
var(TribesGui) private EditInline Config localized string   EndGameConfirmText;

var bool bHasSaved;

function InitComponent(GUIComponent MyOwner)
{
	Super.InitComponent(MyOwner);

    RestartButton.OnClick=OnRestartClick;
    LoadButton.OnClick=OnLoadClick;
	SaveButton.OnClick=OnSaveClick;
	OptionsButton.OnClick=OnOptionsClick;
	QuitButton.OnClick=OnQuitClick;
	ReturnButton.OnClick=OnReturnClick;
	ExitGameButton.OnClick=OnExitGameClick;

	OnShow=InternalOnShow;
	OnActivate=InternalOnActivate;
	OnDlgReturned=InternalOnDlgReturned;
}

function PauseGame(bool bPause)
{
	if (bPause && PlayerOwner().Level.Pauser == None)
	{
		// Pause
		PlayerOwner().ConsoleCommand( "PAUSE" );
	}
	else if (!bPause && PlayerOwner().Level.Pauser != None)
	{
		// Unpause
		PlayerOwner().ConsoleCommand( "PAUSE" );
	}

}

function InternalOnShow()
{
	// Pause the game
	PauseGame(true);
	bHasSaved = false;
}

function InternalOnActivate()
{
	if (SingleplayerGameInfo(PlayerOwner().Level.Game).ReturnToGameAllowed())
		ReturnButton.EnableComponent();
	else
		ReturnButton.DisableComponent();

	if (PlayerOwner().Level.Game.SaveAllowed())
		SaveButton.EnableComponent();
	else
		SaveButton.DisableComponent();
}

function OnRestartClick(GUIComponent Sender)
{
	// Restart game here
	PlayerOwner().ConsoleCommand( "OPEN ?RESTART" );
}

function OnLoadClick(GUIComponent Sender)
{
	// Load game here
	Controller.OpenMenu("TribesGui.TribesLoadGameMenu", "TribesLoadGameMenu", "TribesSPEscapeMenu");
}

function OnSaveClick(GUIComponent Sender)
{
	// Save game here
	Controller.OpenMenu("TribesGui.TribesSaveGameMenu", "TribesSaveGameMenu", "TribesSPEscapeMenu");
}

function OnSaved()
{
	bHasSaved = true;
}

function InternalOnDlgReturned( int Selection, optional string Passback )
{
	if (passback == "confirmexit")
	{
		if ( Selection == QBTN_Yes )
		{
			DoExitGame();
		}
	}
	else if (passback == "confirmendgame")
	{
		if ( Selection == QBTN_Yes )
		{
			DoQuitToMainMenu();
		}
	}
	else
	{
		if ( Selection == QBTN_Yes )
		{
			Controller.OpenMenu("TribesGui.TribesSaveGameMenu", "TribesSaveGameMenu", "TribesSPEScapeMenu");
			TribesSaveGameMenu(Controller.ActivePage).OnUserSaved = OnSaved;
		}
		else if ( Selection == QBTN_No )
		{
			if (passback == "exit")
			{
				DoExitGame();
			}
			else if (passback == "endgame")
			{
				DoQuitToMainMenu();
			}
		}
	}
}

function OnOptionsClick(GUIComponent Sender)
{
	Controller.OpenMenu("TribesGui.TribesOptionsMenu", "TribesOptionsMenu", "TribesSPEscapeMenu");
}

function OnQuitClick(GUIComponent Sender)
{
	if (!bHasSaved && PlayerOwner().Level.Game.SaveAllowed())
		OpenDlg(SaveConfirmText, QBTN_YesNoCancel, "endgame");
	else
	{
		if (PlayerOwner().Pawn == None || PlayerOwner().Pawn.Health <= 0)
			OpenDlg(EndGameConfirmText, QBTN_YesNo, "confirmendgame");
		else
			DoQuitToMainMenu();
	}
}

function DoExitGame()
{
	Quit();
}

function DoQuitToMainMenu()
{
	// Unpause
	PauseGame(false);
	TribesGuiController(Controller).PlayerDisconnect(); 
	Controller.CloseMenu();
	Controller.OpenMenu(class'GameEngine'.default.MainMenuClass);
}

function OnReturnClick(GUIComponent Sender)
{
	// Unpause
	PauseGame(false);
	Controller.CloseAll();
}

function OnExitGameClick(GUIComponent Sender)
{
	if (!bHasSaved && PlayerOwner().Level.Game.SaveAllowed())
	{
		OpenDlg(SaveConfirmText, QBTN_YesNoCancel, "exit");
	}
	else
	{
		if (PlayerOwner().Pawn == None || PlayerOwner().Pawn.Health <= 0)
			OpenDlg(ExitConfirmText, QBTN_YesNo, "confirmexit");
		else
			DoExitGame();
	}
}

function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
{
    if( bVisible && bActiveInput &&
        Key == EInputKey.IK_Escape && State == EInputAction.IST_Press && PlayerOwner().Level.Game.SaveAllowed() )
    {
		// Unpause
		PauseGame(false);
        Controller.CloseAll();
        return true;
    }
    return false;
}

defaultproperties
{
    OnKeyEvent=InternalOnKeyEvent;
	SaveConfirmText="Do you wish to save the game before exiting?"
	ExitConfirmText="Are you sure you wish to exit? Unsaved progress will be lost."
	EndGameConfirmText="Are you sure you wish to end the current game? Unsaved progress will be lost."
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: st 16.4.2014 10:20:44.000 - Creation time: st 23.5.2018 00:10:48.860 - Created with UnCodeX