XIDInterf
Class XIIIMenuSelectProfile

source: C:\XIII\XIDInterf\Classes\XIIIMenuPlayersSetupClient.uc
Core.Object
   |
   +--GUI.GUI
      |
      +--GUI.GUIComponent
         |
         +--GUI.GUIMultiComponent
            |
            +--GUI.GUIPage
               |
               +--XIDInterf.XIIIWindow
                  |
                  +--XIDInterf.XIIIWindowMainMenu
                     |
                     +--XIDInterf.XIIIMenuSelectProfile
Direct Known Subclasses:None

class XIIIMenuSelectProfile
extends XIDInterf.XIIIWindowMainMenu

//============================================================================ // Select Profile menu. // //============================================================================
Variables
 NewProfileText, ConfirmCreateText
 XIIIButton CreateButton
 string CreateText
 XIIIEditCtrl NewProfileButton
 XIIIComboControl ProfileCombo
 MaxProfiles, ProfileIdx
 array ProfileNameList
 string ProfileText
 int ReturnCode
           to be used with profile device
 int ReturnFreeBlock
           number of free block on DD
 string TitleText
 int i
           number of free block on DD
 XIIIMsgBox msgbox
 string sBackGround[4]
 Texture tBackGround[4]

States
UseProfile, OverwriteProfile, CreateProfile, InitProfile

Function Summary
 void Created()
     
//============================================================================
 bool InternalOnKeyEvent(out byte, out byte, float delta)
 void Paint(Canvas C, float X, float Y)
 void ProfileList()
 void ReturnMsgBoxMaxNumberOfProfileReach(byte bButton)
 void ReturnMsgBoxNotEnoughSpaceOnDD(byte bButton)
 void ReturnMsgBoxProfileCorrupted(byte bButton)
 void ReturnMsgBoxUseExitingProfile(byte bButton)
 void Tick(float DeltaTime)
 void VirtualKeyboardReturn(byte bButton)


State UseProfile Function Summary


State OverwriteProfile Function Summary


State CreateProfile Function Summary


State InitProfile Function Summary



Source Code


00001	//============================================================================
00002	// Select Profile menu.
00003	//
00004	//============================================================================
00005	class XIIIMenuSelectProfile extends XIIIWindowMainMenu;
00006	
00007	var localized string TitleText;
00008	var localized string ProfileText;
00009	var localized string CreateText;
00010	
00011	var XIIIComboControl ProfileCombo;
00012	var int MaxProfiles, ProfileIdx;
00013	
00014	var array<string> ProfileNameList;
00015	
00016	var XIIIButton CreateButton;
00017	var XIIIEditCtrl NewProfileButton;
00018	
00019	var XIIIMsgBox msgbox;
00020	var localized string ProfileErrorTitle, ProfileErrorText, NoProfileText, ProfileDiskFull, ProfileMaxNumberCreated, ProfileAlreadyExistText,  ProfileCorrupted, ProfileInitText, NewProfileText, ConfirmCreateText;
00021	
00022	var string sBackGround[4];
00023	var texture tBackGround[4];
00024	
00025	var int ReturnCode;       // to be used with profile device
00026	var int ReturnFreeBlock;  // number of free block on DD
00027	var int i;
00028	
00029	//============================================================================
00030	function Created()
00031	{
00032	    local int i;
00033	
00034	    Super.Created();
00035	
00036		ReturnFreeBlock = -1;
00037	    MaxProfiles = -1;
00038	    ProfileIdx = 0;
00039	    
00040	    for (i=0; i<4; i++)
00041	        tBackGround[i] = texture(DynamicLoadObject(sBackGround[i], class'Texture'));
00042	
00043	    ProfileCombo = XIIIComboControl(CreateControl(class'XIIIComboControl', 160, 228, 350, 32));
00044	    ProfileCombo.Text = ProfileText;
00045	    ProfileCombo.bArrows = true;
00046	    ProfileCombo.bGlassLook = true;
00047	    ProfileCombo.bVisible = false;
00048	    ProfileCombo.bNeverFocus = true;
00049		
00050	    CreateButton = XIIIbutton(CreateControl(class'XIIIbutton', 210, 296, 220, 32));
00051	    CreateButton.Text = CreateText;
00052	    CreateButton.bGlassLook = true;
00053	
00054		NewProfileButton = XIIIEditCtrl(CreateControl(class'XIIIEditCtrl',50, 296, 500, 32));
00055		NewProfileButton.TitleText = NewProfileText;
00056		NewProfileButton.bVisible = false;
00057		NewProfileButton.bNeverFocus = true;
00058		NewProfileButton.MaxWidth	 = 12;
00059		NewProfileButton.bCapsOnly = true;
00060	
00061	    Controls[0] = ProfileCombo; 
00062	    Controls[1] = CreateButton;
00063		Controls[2] = NewProfileButton;
00064	    
00065	    bShowSEL = true;
00066	
00067	    GotoState('InitProfile');
00068	}
00069	
00070	function Tick(float DeltaTime)
00071	{
00072	}
00073	
00074	function Paint(Canvas C, float X, float Y)
00075	{
00076	    local float W, H;
00077	    local int i;
00078	
00079	    Super.Paint(C,X,Y);
00080	
00081	    // background
00082	    // 293 is (640-27*2)/2
00083	    DrawStretchedTexture(C, 32*fRatioX, 24*fRatioY*fScaleTo, 288*fRatioX, 216*fRatioY*fScaleTo, tBackGround[0]);
00084	    DrawStretchedTexture(C, 320*fRatioX, 24*fRatioY*fScaleTo, 288*fRatioX, 216*fRatioY*fScaleTo, tBackGround[1]);
00085	    DrawStretchedTexture(C, 32*fRatioX, 240*fRatioY*fScaleTo, 288*fRatioX, 216*fRatioY*fScaleTo, tBackGround[2]);
00086	    DrawStretchedTexture(C, 320*fRatioX, 240*fRatioY*fScaleTo, 288*fRatioX, 216*fRatioY*fScaleTo, tBackGround[3]);
00087	
00088	    // page title
00089	    C.bUseBorder = true;
00090	    C.DrawColor = WhiteColor;
00091	    C.TextSize(Caps(TitleText), W, H);
00092	    DrawStretchedTexture(C, 400, 80*fRatioY, 400*fRatioX, (H+10)*fScaleTo*fRatioY, myRoot.FondMenu);
00093	    C.DrawColor = BlackColor;
00094	    C.SetPos(440*fRatioX, 80*fRatioY+H/4);
00095	    C.DrawText(TitleText, false);
00096	    
00097	    // restore old param
00098		C.DrawColor = WhiteColor;
00099	    C.DrawColor.A = 255; C.Style = 1; C.bUseBorder = false;
00100	}
00101	
00102	function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
00103	{
00104	    local XIIIMenuVirtualKeyboard msgbox;
00105	
00106		if (State==1)// IST_Press // to avoid auto-repeat
00107	    {
00108	        if ((Key==0x0D/*IK_Enter*/) || (Key==0x01)/*IK_LeftMouse*/)
00109		    {
00110				if (FocusedControl == Controls[0])
00111				{
00112					myRoot.SelectedProfileName = ProfileCombo.GetValue();
00113					GotoState('UseProfile');				
00114				}
00115	
00116				if (FocusedControl == Controls[1])
00117				{
00118					NewProfileButton.SetText("");
00119					myRoot.OpenMenu("XIDInterf.XIIIMenuVirtualKeyboardProfile");
00120					msgbox = XIIIMenuVirtualKeyboardProfile(myRoot.ActivePage);
00121					msgbox.InitVK( NewProfileButton );
00122				}
00123	
00124				return true;
00125		    }
00126		    if (Key==0x26/*IK_Up*/)
00127		    {
00128	  	        PrevControl(FocusedControl);
00129	    	    return true;
00130		    }
00131		    if (Key==0x28/*IK_Down*/)
00132		    {
00133	            NextControl(FocusedControl);
00134	    	    return true;
00135		    }
00136		    if ((Key==0x25/*IK_Left*/) || (Key==0x27/*IK_Right*/))
00137		    {
00138	            if (FocusedControl == Controls[0])
00139		        {
00140	                if (Key==0x25) ProfileIdx--;
00141	                if (Key==0x27) ProfileIdx++;
00142	                if (ProfileIdx < 0) ProfileIdx = 0;
00143	                if (ProfileIdx > MaxProfiles-1) ProfileIdx = MaxProfiles - 1;
00144	                ProfileCombo.SetSelectedIndex(ProfileIdx);
00145	            }
00146	            return true;
00147	        }
00148	    }
00149	    return super.InternalOnKeyEvent(Key, state, delta);
00150	}
00151	
00152	
00153	function VirtualKeyboardReturn(byte bButton)
00154	{
00155		log("VirtualKeyboardReturn - Texte="$NewProfileButton.Text);
00156		if (NewProfileButton.Text != "" )
00157		{
00158			myRoot.SelectedProfileName = NewProfileButton.Text;
00159			GotoState('CreateProfile');
00160		}
00161		else
00162		{
00163			ProfileList();
00164		}
00165	}
00166	
00167	
00168	function ReturnMsgBoxNotEnoughSpaceOnDD(byte bButton)
00169	{
00170		ProfileList();    
00171	}
00172	
00173	function ReturnMsgBoxMaxNumberOfProfileReach(byte bButton)
00174	{
00175		ProfileList();    
00176	}
00177	
00178	function ReturnMsgBoxProfileCorrupted(byte bButton)
00179	{
00180	    if ((bButton & QBTN_Yes) != 0)       // ok to overwrite
00181	    {
00182	        GotoState('OverwriteProfile');
00183	    }
00184	    else
00185	    {
00186	        ProfileList();    
00187	    }
00188	}
00189	
00190	function ReturnMsgBoxUseExitingProfile(byte bButton)
00191	{
00192	    if ((bButton & QBTN_Yes) != 0)       // ok to overwrite
00193	    {
00194	        GotoState('OverwriteProfile');
00195	    }
00196	    else
00197	    {
00198	        ProfileList();    
00199	    }
00200	}
00201	
00202	function ProfileList()
00203	{
00204	    ProfileCombo.Clear();
00205		MaxProfiles = ProfileNameList.Length; 
00206	    for( i=0;i < MaxProfiles ; i++ )
00207	    {
00208	        ProfileCombo.AddItem(ProfileNameList[i]);
00209	    }
00210	    // never go there if MaxProfile=0 and no space on DD
00211	    if (MaxProfiles>0)
00212	    {
00213	        ProfileCombo.bVisible = true;
00214	        ProfileCombo.bNeverFocus = false;
00215	        Controls[0].FocusFirst(self,true);
00216	        ProfileCombo.SetSelectedIndex(0);
00217	    }
00218	    else
00219	    {
00220	        Controls[1].FocusFirst(self,true);
00221	    }
00222		GotoState('');
00223	}
00224	
00225	State InitProfile
00226	{
00227	Begin:
00228		if (myRoot.bMusicPlay) 
00229	    {   
00230			// start the music
00231			MusicValue = int( GetPlayerOwner().ConsoleCommand("get HXAudio.HXAudioSubsystem MusicSliderPos") );
00232			if ( MusicValue != 0 )
00233				MusicValue = 2;
00234			GetPlayerOwner().StopMusic();
00235			GetPlayerOwner().SetMusicSliderPos(MusicValue);
00236			GetPlayerOwner().PlayMusic(menuzik);
00237	        myRoot.bMusicPlay = false;
00238	    }
00239	
00240	    if (!myRoot.RequestGetProfileList())
00241	    {
00242	        log("Unable to read profile list -");
00243	    }
00244	    else
00245	    {
00246	      while (!myRoot.IsGetProfileListFinished(ReturnFreeBlock, ProfileNameList))
00247	      {
00248	          Sleep(0.01);
00249	      }
00250		  // ReturnCode code represente le nombre de block restant sur le DD
00251	      if ((ReturnFreeBlock < 4)&&(ProfileNameList.Length==0))
00252	      {
00253			  myRoot.bSavingPossible=false;
00254			  myRoot.OpenMenu("XIDInterf.XIIIMenuFreeBlock",false,string(4-ReturnFreeBlock));
00255		  }
00256	      else
00257	      {
00258			ProfileList();
00259	      }
00260	    }
00261	  GotoState('');
00262	}
00263	
00264	State CreateProfile
00265	{
00266	Begin:
00267		for( i=0;i < MaxProfiles ; i++ )
00268		{
00269			if (ProfileNameList[i]==myRoot.SelectedProfileName)
00270			{
00271				log("profile already define");
00272				myRoot.OpenMenu("XIDInterf.XIIIMsgBox");
00273				msgbox = XIIIMsgBox(myRoot.ActivePage);
00274				msgbox.InitBox(220, 130*fScaleTo, 10, 10, 220, 230*fScaleTo);
00275				msgbox.SetupQuestion(ProfileAlreadyExistText, QBTN_YesNo, QBTN_No, ProfileErrorTitle);
00276				msgbox.OnButtonClick=ReturnMsgBoxUseExitingProfile;
00277				GotoState('');
00278			}
00279		}
00280	
00281		if (ReturnFreeBlock < 4) // can't create new profile not enough space on DD
00282		{
00283			myRoot.OpenMenu("XIDInterf.XIIIMsgBox");
00284			msgbox = XIIIMsgBox(myRoot.ActivePage);
00285			msgbox.InitBox(220, 130*fScaleTo, 10, 10, 220, 230*fScaleTo);
00286		    ProfileDiskFull = msgbox.Replace(ProfileDiskFull, "nbblocks", string(4-ReturnFreeBlock));
00287			msgbox.SetupQuestion(ProfileDiskFull, QBTN_Ok, QBTN_Ok, ProfileErrorTitle);
00288			msgbox.OnButtonClick=ReturnMsgBoxNotEnoughSpaceOnDD;
00289	        GotoState('');
00290		}
00291		else
00292		if (MaxProfiles==20)
00293		{
00294			myRoot.OpenMenu("XIDInterf.XIIIMsgBox");
00295			msgbox = XIIIMsgBox(myRoot.ActivePage);
00296			msgbox.InitBox(220, 130*fScaleTo, 10, 10, 220, 230*fScaleTo);
00297			msgbox.SetupQuestion(ProfileMaxNumberCreated, QBTN_Ok, QBTN_Ok, ProfileErrorTitle);
00298			msgbox.OnButtonClick=ReturnMsgBoxMaxNumberOfProfileReach;
00299			GotoState('');
00300		}
00301	
00302		if (!myRoot.RequestCreateProfile(myRoot.SelectedProfileName))
00303		{
00304			log("Unable to create profile"@myRoot.SelectedProfileName);
00305			GotoState('');
00306		}
00307		else
00308		{
00309			while (!myRoot.IsCreateProfileFinished(ReturnCode))
00310			{
00311				Sleep(0.01);
00312			}
00313			if (ReturnCode<0) 
00314			{
00315				// Unable to create the profile
00316				log("Failed to create the profile");
00317				GotoState('');
00318			}
00319			else
00320			{
00321				ReturnFreeBlock = ReturnFreeBlock - 4;
00322				ProfileCombo.AddItem(myRoot.SelectedProfileName);
00323				ProfileNameList[MaxProfiles] = myRoot.SelectedProfileName;
00324				MaxProfiles ++;
00325				ProfileIdx = MaxProfiles - 1;
00326				ProfileCombo.bVisible = true;
00327				ProfileCombo.bNeverFocus = false;
00328				Controls[0].FocusFirst(self,true);
00329				ProfileCombo.SetSelectedIndex(ProfileIdx);
00330				NewProfileButton.SetText("");
00331				GotoState('');
00332			}
00333		}
00334	}
00335	
00336	
00337	State OverwriteProfile
00338	{
00339	Begin:
00340		log("overwrite the profile");
00341		if (!myRoot.RequestCreateProfile(myRoot.SelectedProfileName))
00342		{
00343			log("Unable to create profile"@myRoot.SelectedProfileName);
00344			GotoState('');
00345		}
00346		else
00347		{
00348			while (!myRoot.IsCreateProfileFinished(ReturnCode))
00349			{
00350				Sleep(0.01);
00351			}
00352			if (ReturnCode<0) 
00353			{
00354				// Unable to create the profile
00355				log("Failed to overwrite the profile");
00356				GotoState('');
00357			}
00358			else
00359			{
00360				for( i=0;i < MaxProfiles ; i++ )
00361					if (ProfileNameList[i]==myRoot.SelectedProfileName)
00362					{
00363						ProfileIdx = i;
00364						break;				
00365					}
00366				Controls[0].FocusFirst(self,true);
00367				ProfileCombo.SetSelectedIndex(ProfileIdx);
00368				NewProfileButton.SetText("");
00369				GotoState('');
00370			}
00371		}
00372	}
00373	
00374	
00375	
00376	State UseProfile        // slot to use is in SlotNumberToSaveIn
00377	{
00378	Begin:
00379	    if (!myRoot.RequestUseProfile(myRoot.SelectedProfileName))
00380	    {
00381	        log("Unable to use profile "@myRoot.SelectedProfileName);
00382	        GotoState('');
00383	    }
00384	    else
00385	    {
00386	        while (!myRoot.IsUseProfileFinished(ReturnCode))
00387	        {
00388	            Sleep(0.01);
00389	        }
00390	        if (ReturnCode < 0)
00391	        {
00392	            myRoot.OpenMenu("XIDInterf.XIIIMsgBox");
00393	            msgbox = XIIIMsgBox(myRoot.ActivePage);
00394	            msgbox.InitBox(220, 130*fScaleTo, 10, 10, 220, 230*fScaleTo);
00395		        ProfileCorrupted = msgbox.Replace(ProfileCorrupted, "name", myRoot.SelectedProfileName);
00396	            msgbox.SetupQuestion(ProfileCorrupted, QBTN_YesNo, QBTN_Yes, "");
00397	            msgbox.OnButtonClick=ReturnMsgBoxProfileCorrupted;
00398	
00399	            GotoState('');
00400	        }
00401	        else
00402	        {
00403	            myRoot.bProfileSelected=true;
00404	            myRoot.OpenMenu("XIDInterf.XIIIMenu");
00405	        }
00406	    }
00407	    GotoState('');
00408	}
00409	
00410	
00411	
00412	defaultproperties
00413	{
00414	     ClassText="Sabotage class"
00415	     TeamText="Team"
00416	     BlueTeam="Blue"
00417	     RedTeam="Red"
00418	     PlayerText="Player"
00419	     sBackground="XIIIMenuStart.vignette_fond"
00420	     sHighlight="XIIIMenuStart.barreselectmenuoptadv"
00421	     bUseDefaultBackground=False
00422	}

End Source Code