Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# TribesGUI.TribesMPGameSummaryMenu

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

    // ====================================================================
    //  Class:  TribesGui.TribesMPGameSummaryMenu
    //
    //  Menu to load map from entry screen.
    // ====================================================================

    class TribesMPGameSummaryMenu extends TribesGUIPage
         ;

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

    var(TribesGui) private EditInline Config GUILabel		    TitleLabel "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGui) private EditInline Config GUILabel		    TeamOneLabel "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGui) private EditInline Config GUILabel		    TeamTwoLabel "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGui) private EditInline Config GUILabel		    TeamOneScoreLabel "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGui) private EditInline Config GUILabel		    TeamTwoScoreLabel "A component of this page which has its behavior defined in the code for this page's class.";

    var(TribesGui) private EditInline Config GUIButton		    ResumeButton "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGui) private EditInline Config GUIMultiColumnListBox    TeamOnePlayerList "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGui) private EditInline Config GUIMultiColumnListBox    TeamTwoPlayerList "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGui) private EditInline Config GUIMultiColumnListBox    StatList "A component of this page which has its behavior defined in the code for this page's class.";
    var(TribesGui) private EditInline Config GUIMultiColumnListBox    AwardList "A component of this page which has its behavior defined in the code for this page's class.";

    var localized string wonString;
    var localized string lostString;
    var localized string tiedString;

    var(TribesGui) private EditInline Config GUIImage	ChatWindowBackground;	// background for chat window
    var(TribesGui) private EditInline Config GUIEditBox	ChatEntryBox;			// text edit box for chat entry
    var HUDMessageWindow	ChatWindow;											// actual HUD display element for the chat output

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

        OnActivate=InternalOnActivate;
    	OnDeActivate=InternalOnDeActivate;

        ResumeButton.OnClick=InternalOnClick;

    	ChatEntryBox.OnEntryCompleted = OnChatEntryCompleted;
    }

    // Paul: Added PreLevelChange callback for cleanup purposes
    function OnPreLevelChange(String DestURL, LevelSummary NewSummary)
    {
    	super.OnPreLevelChange(DestURL, NewSummary);

    	// have to None-ify the chat window reference
    	ChatWindow = None;
    }

    function InternalOnClick(GUIComponent Sender)
    {
    	switch (Sender)
    	{
    		case ResumeButton:
    			Controller.CloseAll();
    			break;
    	}
    }

    function InternalOnActivate()
    {
    	// Request stat updates
    	tribesReplicationInfo(PlayerOwner().playerReplicationInfo).requestStatInit();
    	tribesReplicationInfo(PlayerOwner().playerReplicationInfo).requestStatUpdates();
    	Update();
    	SetTimer(1, true);
    }

    function InternalOnDeActivate()
    {
    	// Stop requesting stat updates
    	SetTimer(0, false);
    }

    function Update()
    {
    	//Log("GAME SUMMARY UPDATE called");
    	UpdateTeamScores();
    	UpdatePlayerList();
    	UpdateStatList();
    	UpdateAwardList();
    }

    function Timer()
    {
    	tribesReplicationInfo(PlayerOwner().playerReplicationInfo).requestStatUpdates();
    	Update();
    }

    function UpdateTeamScores()
    {
    	local Array<int> scoreVals;
    	local Array<string> scoreNames;
    	local int i;
    	local TeamInfo team, ownerTeam;

    	// Don't show team stuff if there's only one team
    	if (TribesGameReplicationinfo(PlayerOwner().GameReplicationInfo).numTeams < 2)
    	{
    		TeamOneLabel.Hide();
    		TeamTwoLabel.Hide();
    		TeamOneScoreLabel.Hide();
    		TeamTwoScoreLabel.Hide();
    		TitleLabel.Hide();
    		return;
    	}

    	TeamOneLabel.Show();
    	TeamTwoLabel.Show();
    	TeamOneScoreLabel.Show();
    	TeamTwoScoreLabel.Show();
    	TitleLabel.Show();

    	ownerTeam = TribesReplicationInfo(PlayerOwner().PlayerReplicationInfo).team;

    	// Sort teams by score
    	ForEach PlayerOwner().Level.AllActors(class'TeamInfo', team)
    	{
    		i = 0;
    		if ( scoreVals.length > 0 )
    			while ( i < scoreVals.length && scoreVals[i] > team.Score )
    				i++;

    		scoreVals.Insert(i, 1);
    		scoreVals[i] = team.Score;
    		scoreNames.Insert(i, 1);
    		scoreNames[i] = team.localizedName;
    	}

    	// Hard-coded update for two teams for now
    	TeamOneLabel.Caption = scoreNames[0];
    	TeamTwoLabel.Caption = scoreNames[1];
    	TeamOneScoreLabel.Caption = string(scoreVals[0]);
    	TeamTwoScoreLabel.Caption = string(scoreVals[1]);

    	// Update title
    	if (ownerTeam != None)
    	{
    		if (scoreVals[0] == scoreVals[1])
    			TitleLabel.Caption = tiedString;
    		else if (ownerTeam.localizedName == scoreNames[0])
    			TitleLabel.Caption = wonString;
    		else
    			TitleLabel.Caption = lostString;
    	}

    	for (i = 0; i < scoreVals.Length; i++)
    	{
    		//if (scoreNames[i] == string(char.team().Label))
    		//	C.SetDrawColor(255, 0, 0);
    		//else
    		//	C.SetDrawColor(255, 255, 255);

    		//drawJustifiedShadowedText(C, scoreNames[i], x + (0.8 * C.ClipX * 0.0), y, x + (0.8 * C.ClipX * 0.7), y + 0.03 * C.ClipY, 0);
    		//drawJustifiedShadowedText(C, string(scoreVals[i]), x + (0.8 * C.ClipX * 0.22), y, x + (0.8 * C.ClipX * 1.0), y + 0.03 * C.ClipY, 0);

    		//y += 0.03 * C.ClipY;
    	}
    }

    function UpdatePlayerList()
    {
    	local Array<int> scoreVals;
    	local Array<TribesReplicationInfo> sortedTRIList;
    	local PlayerReplicationInfo P;
    	local int i,j;
    	local GUIMultiColumnListBox PlayerList;

    	// Sort players by score
    	for (j = 0; j < PlayerOwner().GameReplicationInfo.PRIArray.Length; j++)
    	{
    		P = tribesReplicationInfo(PlayerOwner().GameReplicationInfo.PRIArray[j]);
    		if (P == None || P.playerName == "" || tribesReplicationInfo(P).team == None)
    			continue;

    		i = 0;
    		if ( scoreVals.length > 0 )
    			while ( i < scoreVals.length && scoreVals[i] > P.Score )
    				i++;

    		sortedTRIList.Insert(i, 1);
    		sortedTRIList[i] = tribesReplicationInfo(P);
    		scoreVals.Insert(i, 1);
    		scoreVals[i] = P.Score;
    	}

    	// Update the tables
    	TeamOnePlayerList.Clear();
    	TeamTwoPlayerList.Clear();
    	for (i=0; i<sortedTRIList.Length; i++)
    	{
    		if (sortedTRIList[i].team.localizedName == teamOneLabel.Caption)
    			PlayerList = TeamOnePlayerList;
    		else
    			PlayerList = TeamTwoPlayerList;

    	    PlayerList.AddNewRowElement( "Name",,  TribesGUIController(Controller).EncodePlayerName(self, sortedTRIList[i]) );
    		PlayerList.AddNewRowElement( "Score",, string(int(sortedTRIList[i].Score)) );
    		PlayerList.AddNewRowElement( "O",, string(sortedTRIList[i].offenseScore) );
    		PlayerList.AddNewRowElement( "D",, string(sortedTRIList[i].defenseScore) );
    		PlayerList.AddNewRowElement( "S",, string(sortedTRIList[i].styleScore) );
    		PlayerList.PopulateRow( "Name" );
    	}

    	TeamOnePlayerList.SetIndex(-1);
    	TeamTwoPlayerList.SetIndex(-1);
    }

    function UpdateStatList()
    {
    	local tribesReplicationInfo TRI;
    	local int i;

    	TRI = tribesReplicationInfo(PlayerOwner().playerReplicationInfo);

    	if (TRI == None)
    		return;

    	StatList.Clear();

    	for (i=0; i < TRI.statDataList.Length; i++)
    	{
    		if (TRI.statDataList[i].statClass.default.Description != "")
    			StatList.AddNewRowElement( "Stat",, TRI.statDataList[i].statClass.default.Description);
    		else
    			continue;
    		//	StatList.AddNewRowElement( "Stat",, TRI.statDataList[i].statClass.default.acronym);
    		StatList.AddNewRowElement( "Value",, string(TRI.statDataList[i].amount));
    		StatList.PopulateRow( "Stat");
    	}

    	StatList.SetIndex(-1);
    }

    function UpdateAwardList()
    {
    	local tribesReplicationInfo TRI;
    	local tribesReplicationInfo awardWinnerTRI;
    	local int i;

    	// Use own TRI to cycle through stats and find award winners
    	TRI = tribesReplicationInfo(PlayerOwner().playerReplicationInfo);

    	if (TRI == None)
    		return;

    	AwardList.Clear();

    	for (i=0; i < TRI.statDataList.Length; i++)
    	{
    		if (TRI.statDataList[i].statClass.default.awardDescription != "")
    		{
    			awardWinnerTRI = getAwardWinnerTRI(i);
    			AwardList.AddNewRowElement("Award",,TRI.statDataList[i].statClass.default.awardDescription);

    			if (awardWinnerTRI != None)
    			{
    				//Log("Awarding "$awardWinnerTRI.PlayerName$" for "$TRI.statDataList[i]);
    				AwardList.AddNewRowElement("Winner",,TribesGUIController(Controller).EncodePlayerName(self, awardWinnerTRI));
    				AwardList.AddNewRowElement("Value",,string(awardWinnerTRI.statDataList[i].amount));
    			}
    			else
    			{
    				AwardList.AddNewRowElement("Winner",,"-");
    				AwardList.AddNewRowElement("Value",,"-");
    			}
    			AwardList.PopulateRow( "Award");
    		}
    	}

    	AwardList.SetIndex(-1);
    }

    function TribesReplicationInfo getAwardWinnerTRI(int statDataIndex)
    {
    	local TribesReplicationInfo TRI;
    	local TribesReplicationInfo highestTRI;

    	ForEach PlayerOwner().Level.DynamicActors(class'TribesReplicationInfo', TRI)
    	{
    		if (highestTRI == None)
    			highestTRI = TRI;
    		else if (TRI.statDataList[statDataIndex].amount > highestTRI.statDataList[statDataIndex].amount)
    			highestTRI = TRI;
    	}

    	// Don't give an award if amount was 0
    	if (highestTRI.statDataList[statDataIndex].amount == 0)
    		return None;

    	return highestTRI;
    }

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

    function string getColoredPlayerName(TribesReplicationInfo TRI)
    {
    	local string PlayerName, TeamTag;

    	// Team tag
    	if (TRI.teamTag != "")
    	{
    		TeamTag = MakeColorCode(TRI.team.TeamHighlightColor) $ TRI.teamTag;
    	}

    	PlayerName = stripCodes(TRI.PlayerName);
    	// Highlight own name
    	if (PlayerOwner().PlayerReplicationInfo == TRI)
    		PlayerName = MakeColorCode(TRI.team.TeamHighlightColor) $ PlayerName;
    	else
    		PlayerName = MakeColorCode(TRI.team.TeamColor) $ PlayerName;

    	// Simply add it to front of name for now
    	// TODO:  Use delimeter to control how tag looks
    	return TeamTag $ PlayerName;
    }

    //
    //
    //
    function OnChatEntryCompleted(GUIComponent edit)
    {
    	local PlayerCharacterController CharacterController;

    	CharacterController = PlayerCharacterController(PlayerOwner());
    	CharacterController.Say(ChatEntryBox.GetText());
    	ChatEntryBox.SetText("");
    }

    //
    // Override OnDraw in order to render the chat window text
    // into the area we have supplied for it
    //
    function OnClientDraw(Canvas canvas)
    {
    	local PlayerCharacterController CharacterController;

    	// initialise the chat window
    	if(ChatWindow == None)
    		ChatWindow = HUDMessageWindow(class'HUDElement'.static.StaticCreateHUDElement(class'HUDMessageWindow', "default_MessageWindow"));

    	CharacterController = PlayerCharacterController(PlayerOwner());

    	if(CharacterController != None)
    	{
    		ChatWindow.ForcedMaxVisibleLines = (ChatWindowBackground.ActualHeight() / ChatWindow.GetLineHeight(canvas));
    		ChatWindow.DoLayout(canvas);
    		ChatWindow.PosX = ChatWindowBackground.ActualLeft();
    		ChatWindow.PosY = ChatWindowBackground.ActualTop();
    		ChatWindow.Width = ChatWindowBackground.ActualWidth();
    		ChatWindow.Height = ChatWindowBackground.ActualHeight();

    		canvas.SetOrigin(ChatWindow.PosX, ChatWindow.PosY);
    		canvas.SetClip(ChatWindow.Width, ChatWindow.Height);
    		ChatWindow.UpdateData(CharacterController.clientSideChar);
    		ChatWindow.Render(canvas);
    	}
    }

    defaultproperties
    {
        OnKeyEvent=InternalOnKeyEvent;
    	wonString = "Your team won!"
    	lostString = "Your team lost..."
    	tiedString = "The match ended in a tie!"
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
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.608 - Created with UnCodeX