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

ROInterface.ROUT2K4TabPanel_UnitSelection


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
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
class ROUT2K4TabPanel_UnitSelection extends UT2K4TabPanel;

const AUTO = 2;

var automated moCheckBox ch_Axis, ch_Allies, ch_Auto;
var automated GUIButton b_selectUnitButton;
var automated GUIScrollTextBox	sc_UnitDescription;
var automated GUISectionBackground i_UnitDescBG, i_UnitBG, i_CurrentUnitBG;
var automated GUILabel l_AxisName, l_AlliedName, l_AxisCount, l_AlliedCount;

var	localized	string		AutoInfoText;

var  ROGameReplicationInfo GRI;

var moCheckBox ch_currentSelection;

var	localized string Briefing[2];

//delgate called after valid team has been selected
delegate OnSelect(int teamIndex);
//------------------------------------------------------------------------------
//   Initialize components and set auto selection checkbox to default
//------------------------------------------------------------------------------
function InitComponent(GUIController MyController, GUIComponent MyOwner)
{
     super.InitComponent(MyController,MyOwner);

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

    GRI = ROGameReplicationInfo(PlayerOwner().GameReplicationInfo);
     loadBriefing();
     //default to auto and initilize current selection
     ch_Auto.Checked(True);
     updateAutoUnitInfoText();
     ch_currentSelection=ch_Auto;
     setCurrentUnitOption();

}
//------------------------------------------------------------------------------
// If player is already assigned to a side then set that checkbox.
// If side is current unassigned then set to auto.
//------------------------------------------------------------------------------
function setCurrentUnitOption()
{
   local ROPlayer lPlayer;
   local ROPlayerReplicationInfo lInfo;

   lPlayer = ROPlayer(PlayerOwner());

   if(lPlayer != none)
   {
	 if (GRI == None)
		GRI = ROGameReplicationInfo(lPlayer.GameReplicationInfo);

     lInfo = ROPlayerReplicationInfo( lPlayer.PlayerReplicationInfo );
     if(lInfo != none)
     {
        if(lInfo.Team != none)
        {
            switch(lInfo.Team.TeamIndex)
            {
               case 0 :  setAxisChecked();updateAxisUnitInfoText();  break;
               case 1 :  setAlliesChecked();updateAlliesUnitInfoText(); break;
               case 2 :  setAutoChecked();updateAutoUnitInfoText();  break;
            }
        }
     }
   }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function ShowPanel(bool bShow)
{
	Super.ShowPanel(bShow);
	//log("ROUT2K4TabPanel_UnitSelection::ShowPanel("$bShow$")");

	if (bShow)
	{
        loadBriefing();
		setCurrentUnitOption();
		SetTimer(0.1, true);
	}
	else
	{
		SetTimer(0.0, false);
	}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function Timer()
{
    local int teamIndex;

	if (GRI == None)
	{
		GRI = ROGameReplicationInfo(PlayerOwner().GameReplicationInfo);
        loadBriefing();
		setCurrentUnitOption();
        switch(ch_currentSelection)
        {
            case ch_Axis   : PlayerOwner().ChangeTeam(AXIS_TEAM_INDEX); teamIndex = AXIS_TEAM_INDEX; break;
            case ch_Allies : PlayerOwner().ChangeTeam(ALLIES_TEAM_INDEX); teamIndex = ALLIES_TEAM_INDEX; break;
            case ch_Auto   :  teamIndex = autoSelectTeam(); break;
        }
    }
    UpdateTeamCounts();

//    if(isValidTeam())
//       OnSelect(teamIndex);
}
//------------------------------------------------------------------------------
// When a checkbox is selected then deselect the previously selected
// checkbox. This is no allow the checkboxes to behave like radio buttons
// where only one can be selected.
//	Don't we want unit selection to be radio buttons? - ant
//------------------------------------------------------------------------------
function InternalOnChange(GUIComponent Sender)
{
   local moCheckBox selected;
   //log("ROUT2K4TabPanel_UnitSelection::InternalOnChange");
   selected = moCheckBox(Sender);

   if(selected != none)
   {
      if(selected == ch_currentSelection)
      {
        // selected.MyCheckBox.bChecked = true;
         return;
      }
      if(selected.IsChecked())
      {
          switch(selected)
          {
             case ch_Axis   : setAxisChecked();updateAxisUnitInfoText(); break;
             case ch_Allies : setAlliesChecked();updateAlliesUnitInfoText(); break;
             case ch_Auto   : setAutoChecked(); updateAutoUnitInfoText(); break;
          }
      }
   }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function bool InternalOnClick( GUIComponent Sender )
{
    local int teamIndex;
    switch(ch_currentSelection)
    {
         case ch_Axis   : PlayerOwner().ChangeTeam(AXIS_TEAM_INDEX); teamIndex = AXIS_TEAM_INDEX; break;
         case ch_Allies : PlayerOwner().ChangeTeam(ALLIES_TEAM_INDEX); teamIndex = ALLIES_TEAM_INDEX; break;
         case ch_Auto   :  teamIndex = autoSelectTeam(); break;
    }
    if(isValidTeam())
       OnSelect(teamIndex);

    return true;
}
//------------------------------------------------------------------------------
// @return true if player is on a valid team
//------------------------------------------------------------------------------
function bool isValidTeam()
{
   return (PlayerOwner().PlayerReplicationInfo != None &&
   PlayerOwner().PlayerReplicationInfo.Team != none
	&& PlayerOwner().PlayerReplicationInfo.Team.TeamIndex < NEUTRAL_TEAM_INDEX);
}
//------------------------------------------------------------------------------
// Very simple algo, simply add the player to the team with the
// least units.
//------------------------------------------------------------------------------
function int autoSelectTeam()
{
    local int axisCount, alliedCount;
    axisCount   = getTeamCount(AXIS_TEAM_INDEX);
    alliedCount = getTeamCount(ALLIES_TEAM_INDEX);
    if(axisCount < alliedCount)
    {
        PlayerOwner().ChangeTeam(AXIS_TEAM_INDEX);
        return AXIS_TEAM_INDEX;
    }
    else
    {
        PlayerOwner().ChangeTeam(ALLIES_TEAM_INDEX);
        return ALLIES_TEAM_INDEX;
    }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function int getTeamCount(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 &&
            GRI.PRIArray[i].Team != None &&
            GRI.PRIArray[i].Team.TeamIndex == index)
			count++;
	}
	return count;

}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function updateAxisUnitInfoText()
{
   sc_UnitDescription.SetContent(GRI.UnitName[AXIS_TEAM_INDEX]$"||"$Briefing[AXIS_TEAM_INDEX]);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function updateAlliesUnitInfoText()
{
   sc_UnitDescription.SetContent(GRI.UnitName[ALLIES_TEAM_INDEX]$"||"$Briefing[ALLIES_TEAM_INDEX]);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function updateAutoUnitInfoText()
{
   sc_UnitDescription.SetContent(AutoInfoText);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function setAxisChecked()
{
     ch_currentSelection.Checked(false);
     ch_currentSelection = ch_Axis;
     ch_currentSelection.Checked(true);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function setAlliesChecked()
{
    ch_currentSelection.Checked(false);
    ch_currentSelection = ch_Allies;
    ch_currentSelection.Checked(true);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function setAutoChecked()
{
    ch_currentSelection.Checked(false);
    ch_currentSelection = ch_Auto;
    ch_currentSelection.Checked(true);
}
//-----------------------------------------------------------------------------
// UpdateTeamCounts - Updates the number of players on each team
//-----------------------------------------------------------------------------
function UpdateTeamCounts()
{
    l_AxisCount.Caption = ""$getTeamCount(AXIS_TEAM_INDEX);
    l_AlliedCount.Caption = ""$getTeamCount(ALLIES_TEAM_INDEX);
}
//------------------------------------------------------------------------------
function loadBriefing()
{
//    local int Loc,i;
    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];
	}
}

defaultproperties
{
     Begin Object Class=moCheckBox Name=AxisCheckbox
         ComponentJustification=TXTA_Center
         CaptionWidth=0.100000
         Caption="Join Axis"
         OnCreateComponent=AxisCheckbox.InternalOnCreateComponent
         Hint="Join the Axis forces."
         WinTop=0.500000
         WinLeft=0.054219
         WinWidth=0.540000
         TabOrder=0
         OnChange=ROUT2K4TabPanel_UnitSelection.InternalOnChange
     End Object
     ch_Axis=moCheckBox'ROInterface.ROUT2K4TabPanel_UnitSelection.AxisCheckbox'

     Begin Object Class=moCheckBox Name=AlliesCheckbox
         ComponentJustification=TXTA_Center
         CaptionWidth=0.100000
         Caption="Join Allies"
         OnCreateComponent=AxisCheckbox.InternalOnCreateComponent
         Hint="Join the Allied forces."
         WinTop=0.550000
         WinLeft=0.054219
         WinWidth=0.540000
         TabOrder=1
         OnChange=ROUT2K4TabPanel_UnitSelection.InternalOnChange
     End Object
     ch_Allies=moCheckBox'ROInterface.ROUT2K4TabPanel_UnitSelection.AlliesCheckbox'

     Begin Object Class=moCheckBox Name=AutoCheckbox
         ComponentJustification=TXTA_Center
         CaptionWidth=0.100000
         Caption="Auto Selection"
         OnCreateComponent=AxisCheckbox.InternalOnCreateComponent
         Hint="Automatically select force."
         WinTop=0.600000
         WinLeft=0.054219
         WinWidth=0.540000
         TabOrder=2
         OnChange=ROUT2K4TabPanel_UnitSelection.InternalOnChange
     End Object
     ch_Auto=moCheckBox'ROInterface.ROUT2K4TabPanel_UnitSelection.AutoCheckbox'

     Begin Object Class=GUIButton Name=SelectButton
         Caption="Select"
         Hint="Select Force To Join."
         WinTop=0.900000
         WinLeft=0.796436
         WinWidth=0.139474
         WinHeight=0.052944
         TabOrder=3
         OnClick=ROUT2K4TabPanel_UnitSelection.InternalOnClick
         OnKeyEvent=SelectButton.InternalOnKeyEvent
     End Object
     b_selectUnitButton=GUIButton'ROInterface.ROUT2K4TabPanel_UnitSelection.SelectButton'

     Begin Object Class=GUIScrollTextBox Name=UnitDescriptionScroll
         CharDelay=0.002500
         EOLDelay=0.500000
         OnCreateComponent=UnitDescriptionScroll.InternalOnCreateComponent
         WinTop=0.130000
         WinLeft=0.042190
         WinWidth=0.570000
         WinHeight=0.160000
         TabOrder=9
     End Object
     sc_UnitDescription=GUIScrollTextBox'ROInterface.ROUT2K4TabPanel_UnitSelection.UnitDescriptionScroll'

     Begin Object Class=AltSectionBackground Name=PlayerSetupBG
         HeaderTop=Texture'InterfaceArt_tex.Menu.button_normal'
         HeaderBar=Texture'InterfaceArt_tex.Menu.button_normal'
         HeaderBase=Texture'InterfaceArt_tex.Menu.RODisplay'
         Caption="Unit Description"
         WinTop=0.055000
         WinLeft=0.024219
         WinWidth=0.600000
         WinHeight=0.300000
         OnPreDraw=PlayerSetupBG.InternalPreDraw
     End Object
     i_UnitDescBG=AltSectionBackground'ROInterface.ROUT2K4TabPanel_UnitSelection.PlayerSetupBG'

     Begin Object Class=AltSectionBackground Name=UnitSetupBG
         HeaderTop=Texture'InterfaceArt_tex.Menu.button_normal'
         HeaderBar=Texture'InterfaceArt_tex.Menu.button_normal'
         HeaderBase=Texture'InterfaceArt_tex.Menu.RODisplay'
         Caption="Unit Selection"
         WinTop=0.400000
         WinLeft=0.024219
         WinWidth=0.600000
         WinHeight=0.330000
         OnPreDraw=PlayerSetupBG.InternalPreDraw
     End Object
     i_UnitBG=AltSectionBackground'ROInterface.ROUT2K4TabPanel_UnitSelection.UnitSetupBG'

     Begin Object Class=AltSectionBackground Name=CurrentUnitSetupBG
         HeaderTop=Texture'InterfaceArt_tex.Menu.button_normal'
         HeaderBar=Texture'InterfaceArt_tex.Menu.button_normal'
         HeaderBase=Texture'InterfaceArt_tex.Menu.RODisplay'
         Caption="Current Units"
         WinTop=0.055000
         WinLeft=0.644219
         WinWidth=0.300000
         WinHeight=0.300000
         OnPreDraw=PlayerSetupBG.InternalPreDraw
     End Object
     i_CurrentUnitBG=AltSectionBackground'ROInterface.ROUT2K4TabPanel_UnitSelection.CurrentUnitSetupBG'

     Begin Object Class=GUILabel Name=AxisName
         Caption="Axis"
         StyleName="ROTextLabel"
         WinTop=0.140000
         WinLeft=0.684219
         WinWidth=0.854492
         WinHeight=0.050000
     End Object
     l_AxisName=GUILabel'ROInterface.ROUT2K4TabPanel_UnitSelection.AxisName'

     Begin Object Class=GUILabel Name=AlliedName
         Caption="Allies"
         StyleName="ROTextLabel"
         WinTop=0.200000
         WinLeft=0.684219
         WinWidth=0.854492
         WinHeight=0.050000
     End Object
     l_AlliedName=GUILabel'ROInterface.ROUT2K4TabPanel_UnitSelection.AlliedName'

     Begin Object Class=GUILabel Name=axisCount
         Caption="10"
         TextAlign=TXTA_Center
         StyleName="ROTextLabel"
         WinTop=0.140000
         WinLeft=0.462190
         WinWidth=0.854492
         WinHeight=0.050000
     End Object
     l_AxisCount=GUILabel'ROInterface.ROUT2K4TabPanel_UnitSelection.axisCount'

     Begin Object Class=GUILabel Name=alliedCount
         Caption="10"
         TextAlign=TXTA_Center
         StyleName="ROTextLabel"
         WinTop=0.200000
         WinLeft=0.462190
         WinWidth=0.854492
         WinHeight=0.050000
     End Object
     l_AlliedCount=GUILabel'ROInterface.ROUT2K4TabPanel_UnitSelection.alliedCount'

     AutoInfoText="* Selecting this option will automatically join the unit that needs you most."
     Briefing(0)="Axis briefing"
     Briefing(1)="Allied briefing"
     PanelCaption="Unit"
}

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:07.771 - Created with UnCodeX