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

ROInterface.ROGUITeamSelection


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
//=============================================================================
// ROGUITeamSelection
//=============================================================================
// The Team Selection menu.
//=============================================================================
// Red Orchestra Source
// Copyright (C) 2005 Mathieu Mallet
//=============================================================================

class ROGUITeamSelection extends UT2K4GUIPage;

// Controls
var automated GUILabel                      l_TeamCount[2];
var automated GUIScrollTextBox              l_TeamBriefing[2];

var automated GUIButton                     b_TeamSelect[2];
var automated GUIButton                     b_Spectate, b_AutoSelect;

var automated BackgroundImage               bg_Background;


// Variables
var             ROGameReplicationInfo       GRI;
var	localized   string                      Briefing[2];
var localized   string                      TeamJoinText[2];
var localized   string                      TeamJoinHint[2];
var localized   string                      UnitsText;
var             int                         selectedTeam;


function InitComponent(GUIController MyController, GUIComponent MyOwner)
{
    local int i;

    Super.InitComponent(MyController, MyOwner);

    //class'ROInterfaceUtil'.static.SetROStyle(MyController, Controls);

    GRI = ROGameReplicationInfo(PlayerOwner().GameReplicationInfo);
    loadBriefing();

    // Set initial values
    l_TeamBriefing[0].SetContent(GRI.UnitName[AXIS_TEAM_INDEX]$"||"$Briefing[AXIS_TEAM_INDEX]);
    l_TeamBriefing[1].SetContent(GRI.UnitName[ALLIES_TEAM_INDEX]$"||"$Briefing[ALLIES_TEAM_INDEX]);

    for (i = 0; i < 2; i++)
    {
        b_TeamSelect[i].Caption = TeamJoinText[i];
        b_TeamSelect[i].SetHint(TeamJoinHint[i]);
    }

    Timer();
	SetTimer(0.1, true);
}

/*function loadBriefing()
{
    local int Loc;
    local string PackageName;
    local string MapName;

    if (PlayerOwner().Level.DecoTextName != "")
	{
		Loc = InStr(PlayerOwner().Level.DecoTextName, ".");

		if (Loc == -1)
		{
			PackageName = "ROMaps";
			MapName = PlayerOwner().Level.DecoTextName;
		}
		else
		{
			PackageName = Left(PlayerOwner().Level.DecoTextName, Loc);
			MapName = Mid(PlayerOwner().Level.DecoTextName, Loc + 1);
		}

		Briefing[ALLIES_TEAM_INDEX] = Controller.LoadDecoText(PackageName, MapName $ "Allies");
		Briefing[AXIS_TEAM_INDEX] = Controller.LoadDecoText(PackageName, MapName $ "Axis");
	}
	else
	{
		Briefing[ALLIES_TEAM_INDEX] = Controller.LoadDecoText("ROMaps", "Default");
		Briefing[AXIS_TEAM_INDEX] = Briefing[ALLIES_TEAM_INDEX];
	}
}*/

function loadBriefing()
{
    local ROLevelInfo levelinfo;

    // Find levelinfO
   	foreach PlayerOwner().AllActors(class'ROLevelInfo', levelinfo)
	    break;

	if (levelinfo != none)
	{
	    Briefing[ALLIES_TEAM_INDEX] = levelinfo.AlliesUnitDescription;
        Briefing[AXIS_TEAM_INDEX] = levelinfo.AxisUnitDescription;
	}
}

// Used to update team counts
function Timer()
{
    UpdateTeamCounts();
}

function UpdateTeamCounts()
{
    l_TeamCount[AXIS_TEAM_INDEX].Caption = ""$getTeamCount(AXIS_TEAM_INDEX) $ UnitsText;
    l_TeamCount[ALLIES_TEAM_INDEX].Caption = ""$getTeamCount(ALLIES_TEAM_INDEX) $ UnitsText;
}

function int getTeamCount(int index)
{
    return getTeamCountStatic(GRI, PlayerOwner(), index);
}

function SetButtonsState(bool bDisabled)
{
    if (bDisabled)
    {
        b_AutoSelect.MenuStateChange(MSAT_Disabled);
        b_Spectate.MenuStateChange(MSAT_Disabled);
        b_TeamSelect[0].MenuStateChange(MSAT_Disabled);
        b_TeamSelect[1].MenuStateChange(MSAT_Disabled);
    }
    else
    {
        b_AutoSelect.MenuStateChange(MSAT_Blurry);
        b_Spectate.MenuStateChange(MSAT_Blurry);
        b_TeamSelect[0].MenuStateChange(MSAT_Blurry);
        b_TeamSelect[1].MenuStateChange(MSAT_Blurry);
    }
}

function static int getTeamCountStatic(ROGameReplicationInfo GRI, PlayerController controller, int index)
{
    local int i, count;

    if (GRI == none)
        return 0;

    // Find the number of players on each team
    for (i = 0; i < GRI.PRIArray.Length; i++)
    {
		if (ROPlayerReplicationInfo(GRI.PRIArray[i]) != None &&
				ROPlayerReplicationInfo(GRI.PRIArray[i]).RoleInfo != none &&
                GRI.PRIArray[i].Team != none &&
                GRI.PRIArray[i].Team.TeamIndex == index)
        {
            //if (controller != none && GRI.PRIArray[i] != controller.PlayerReplicationInfo) // Don't count self
                //if (!GRI.PRIArray[i].bBot) // Don't count bots
                    count++;
        }
    }

    return count;
}

function InternalOnClose(optional bool bCancelled)
{
    if (!bCancelled)
        SetTimer(0.0, false);
}

function bool InternalOnClick( GUIComponent Sender )
{
//    local int team1, team2;

    switch (Sender)
    {
        case b_AutoSelect:
            /*team1 = getTeamCount(AXIS_TEAM_INDEX);
            team2 = getTeamCount(ALLIES_TEAM_INDEX);
            if (team1 < team2)
                SelectTeam(AXIS_TEAM_INDEX);
            else if (team1 > team2)
                SelectTeam(ALLIES_TEAM_INDEX);
            else
                SelectTeam(Rand(2));*/
            SelectTeam(-2);
            break;

        case b_Spectate:
            SelectTeam(-1);
            break;

        case b_TeamSelect[AXIS_TEAM_INDEX]:
            SelectTeam(AXIS_TEAM_INDEX);
            break;

        case b_TeamSelect[ALLIES_TEAM_INDEX]:
            SelectTeam(ALLIES_TEAM_INDEX);
            break;
    }
    return true;
}

/*
 team = 0 -- select axis
 team = 1 -- select allies
 team = -1 -- select spectator
 team = -2 -- auto select
*/
function SelectTeam(int team)
{
    selectedTeam = team;
    /*if (team != -1)
    {
        if (PlayerOwner().PlayerReplicationInfo != none &&
            PlayerOwner().PlayerReplicationInfo.bOnlySpectator)
        {
            PlayerOwner().BecomeActivePlayer();
        }
        PlayerOwner().ChangeTeam(team);
        //Controller.OpenMenu("ROInterface.ROGUIRoleSelection");
    }
    else
        PlayerOwner().BecomeSpectator();
    */

    if (ROPlayer(PlayerOwner()) == none)
    {
        warn("Unable to cast PlayerOwner() to ROPlayer! Unable to change teams.");
        return;
    }

    SetButtonsState(true);

    if (team == -1)
        ROPlayer(PlayerOwner()).ServerChangePlayerInfo(254, 255, 0, 0);
    else if (team == -2)
        ROPlayer(PlayerOwner()).ServerChangePlayerInfo(250, 255, 0, 0);
    else
        ROPlayer(PlayerOwner()).ServerChangePlayerInfo(team, 255, 0, 0);
}

function SelectTeamSuccessfull()
{
    if (selectedTeam != -1)
    {
        // hax! player team hasn't been replicated by the time this has been
        // called -- so we force the role select menu to show a specific team
        if (ROPlayer(PlayerOwner()) != none)
            ROPlayer(PlayerOwner()).ForcedTeamSelectOnRoleSelectPage = selectedTeam;

        Controller.OpenMenu("ROInterface.ROGUIRoleSelection");
    }
    else
        class'ROGUIRoleSelection'.static.CheckNeedForFadeFromBlackEffect(PlayerOwner());

    Controller.RemoveMenu(self);
}

function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
{
    if (key == 0x1B)
    {
        Controller.CloseMenu();
        return true;
    }

    return false;
}

function InternalOnMessage(coerce string Msg, float MsgLife)
{
    local int result;
    local string error_msg;

    if (msg == "notify_gui_role_selection_page")
    {
        // Received success/failure message from server.

        result = int(MsgLife);

        switch (result)
        {
            case 0: // Team change successfull!
                SelectTeamSuccessfull();
                return;

            case 97: // Succesfully picked axis team
                selectedTeam = AXIS_TEAM_INDEX;
                SelectTeamSuccessfull();
                return;

            case 98: // Successfully picked allies team
                selectedTeam = ALLIES_TEAM_INDEX;
                SelectTeamSuccessfull();
                return;

            default: // Couldn't change teams: get error msg
                error_msg = class'ROGUIRoleSelection'.static.getErrorMessageForId(result);
        }

        SetButtonsState(false);

        if (Controller != none)
        {
            Controller.OpenMenu(Controller.QuestionMenuClass);
            GUIQuestionPage(Controller.TopPage()).SetupQuestion(error_msg, QBTN_Ok, QBTN_Ok);
        }
    }
}

defaultproperties
{
     Begin Object Class=GUILabel Name=TeamsCount
         Caption="? units"
         TextAlign=TXTA_Center
         StyleName="TextLabel"
         WinTop=0.415000
         WinLeft=0.096250
         WinWidth=0.300000
         WinHeight=0.040000
     End Object
     l_TeamCount(0)=GUILabel'ROInterface.ROGUITeamSelection.TeamsCount'

     Begin Object Class=GUILabel Name=TeamsCount2
         Caption="? units"
         TextAlign=TXTA_Center
         StyleName="TextLabel"
         WinTop=0.871667
         WinLeft=0.096250
         WinWidth=0.300000
         WinHeight=0.040000
     End Object
     l_TeamCount(1)=GUILabel'ROInterface.ROGUITeamSelection.TeamsCount2'

     Begin Object Class=GUIScrollTextBox Name=TeamsBriefing
         bNoTeletype=True
         OnCreateComponent=TeamsBriefing.InternalOnCreateComponent
         StyleName="TextLabel"
         WinTop=0.078333
         WinLeft=0.503750
         WinWidth=0.446250
         WinHeight=0.342498
     End Object
     l_TeamBriefing(0)=GUIScrollTextBox'ROInterface.ROGUITeamSelection.TeamsBriefing'

     Begin Object Class=GUIScrollTextBox Name=TeamsBriefing2
         bNoTeletype=True
         OnCreateComponent=TeamsBriefing2.InternalOnCreateComponent
         StyleName="TextLabel"
         WinTop=0.530000
         WinLeft=0.503750
         WinWidth=0.446250
         WinHeight=0.342498
     End Object
     l_TeamBriefing(1)=GUIScrollTextBox'ROInterface.ROGUITeamSelection.TeamsBriefing2'

     Begin Object Class=GUIButton Name=JoinTeamButton
         StyleName="SelectButton"
         WinTop=0.370000
         WinLeft=0.118750
         WinWidth=0.250000
         WinHeight=0.050000
         TabOrder=1
         OnClick=ROGUITeamSelection.InternalOnClick
         OnKeyEvent=ROGUITeamSelection.InternalOnKeyEvent
     End Object
     b_TeamSelect(0)=GUIButton'ROInterface.ROGUITeamSelection.JoinTeamButton'

     Begin Object Class=GUIButton Name=JoinTeamButton2
         StyleName="SelectButton"
         WinTop=0.823333
         WinLeft=0.118750
         WinWidth=0.250000
         WinHeight=0.050000
         TabOrder=2
         OnClick=ROGUITeamSelection.InternalOnClick
         OnKeyEvent=ROGUITeamSelection.InternalOnKeyEvent
     End Object
     b_TeamSelect(1)=GUIButton'ROInterface.ROGUITeamSelection.JoinTeamButton2'

     Begin Object Class=GUIButton Name=Spectate
         Caption="Spectate"
         StyleName="SelectTab"
         Hint="Join the game as a spectator"
         WinTop=0.920000
         WinLeft=0.550000
         WinWidth=0.250000
         WinHeight=0.050000
         TabOrder=4
         OnClick=ROGUITeamSelection.InternalOnClick
         OnKeyEvent=ROGUITeamSelection.InternalOnKeyEvent
     End Object
     b_Spectate=GUIButton'ROInterface.ROGUITeamSelection.Spectate'

     Begin Object Class=GUIButton Name=AutoSelect
         Caption="Auto-select"
         StyleName="SelectTab"
         Hint="Join the team with the fewest players"
         WinTop=0.920000
         WinLeft=0.250000
         WinWidth=0.250000
         WinHeight=0.050000
         TabOrder=3
         OnClick=ROGUITeamSelection.InternalOnClick
         OnKeyEvent=ROGUITeamSelection.InternalOnKeyEvent
     End Object
     b_AutoSelect=GUIButton'ROInterface.ROGUITeamSelection.AutoSelect'

     Begin Object Class=BackgroundImage Name=PageBackground
         Image=Texture'InterfaceArt_tex.SelectMenus.Teamselect'
         ImageStyle=ISTY_Scaled
         ImageRenderStyle=MSTY_Alpha
         X1=0
         Y1=0
         X2=1023
         Y2=1023
     End Object
     bg_Background=BackgroundImage'ROInterface.ROGUITeamSelection.PageBackground'

     Briefing(0)="Axis briefing"
     Briefing(1)="Allied briefing"
     TeamJoinText(0)="JOIN AXIS"
     TeamJoinText(1)="JOIN ALLIES"
     TeamJoinHint(0)="Join Axis forces"
     TeamJoinHint(1)="Join Allies forces"
     UnitsText=" units"
     bRenderWorld=True
     bAllowedAsLast=True
     OnClose=ROGUITeamSelection.InternalOnClose
     OnMessage=ROGUITeamSelection.InternalOnMessage
     OnKeyEvent=ROGUITeamSelection.InternalOnKeyEvent
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Fri 13-10-2023 03:17:28.000 - Creation time: Fri 13-10-2023 03:19:06.975 - Created with UnCodeX