## XIDInterf
Class XIIIMenuLoadGameWindow

source: C:\XIII\XIDInterf\Classes\XIIIMenuLoadGameWindow.uc

    Core.Object
       |
       +--GUI.GUI
          |
          +--GUI.GUIComponent
             |
             +--GUI.GUIMultiComponent
                |
                +--GUI.GUIPage
                   |
                   +--XIDInterf.XIIIWindow
                      |
                      +--XIDInterf.XIIIWindowMainMenu
                         |
                         +--XIDInterf.XIIIMenuLoadGameWindow

Direct Known Subclasses:None

class XIIIMenuLoadGameWindow
extends XIDInterf.XIIIWindowMainMenu

    //============================================================================
    // Load saved games
    //============================================================================

Variables
`OldPage,` | `CurSlot`
`string` | `DisplayedText`
`string` | `EmptySlotErrorMsg`
`string` | `EmptySlotErrorTitle`
`string` | `EmptySlotText`
`int` | `IsEmpty` to be used with save game device
`string` | `LoadGameResultTile`
`Hour,` | `Min` to be used with save game device
`string` | `PageText`
`int` | `ReturnCode` to be used with save game device
`LeftArrow,` | `RightArrow`
`array` | `SaveSlots`
`string` | `SaveSlotsInfo[10]`
`string` | `SlotDesc` to be used with save game device
`int` | `SlotNumberToLoadFrom` to be used with save game device
`string` | `TitleText`
`int` | `Year` to be used with save game device
`bool` | `bIgnoreKeys` to be used with save game device
`bool` | `bMemoryCardDetected` to be used with save game device
`bool` | `bRunning` to be used with save game device
`array` | `bSaveSlotEmpty`
`int` | `i` to be used with save game device
`msgbox,` | `msgbox2`
`string` | `sBackground[3]`
`Texture` | `tBackGround[3]`

States
LoadFromSlot, GetSlotDescription

Function Summary
`void` | `Created()`
    //============================================================================
`bool` | `InternalOnKeyEvent(out byte, out byte, float delta)`
`void` | `InternalOnOpen()`
`void` | `PageSwitch()`
`void` | `Paint(Canvas C, float X, float Y)`

State LoadFromSlot Function Summary

State GetSlotDescription Function Summary

Source Code

    00001	//============================================================================
    00002	// Load saved games
    00003	//============================================================================
    00004	class XIIIMenuLoadGameWindow extends XIIIWindowMainMenu;
    00005
    00006	var localized string TitleText;
    00007	var localized string EmptySlotText;
    00008	var localized string EmptySlotErrorTitle;
    00009	var localized string EmptySlotErrorMsg;
    00010	var localized string LoadGameResultTile;
    00011	var localized string PageText;
    00012
    00013	var int  MaxMenu, onPage, MaxSlots, MaxViewable, NbPages, OldPage, CurSlot;
    00014	var string DisplayedText;
    00015
    00016	var array<XIIIbutton> SaveSlots;
    00017	//var array<string> SaveSlotsInfo;
    00018	var string SaveSlotsInfo[10];
    00019	var array<byte> bSaveSlotEmpty;
    00020
    00021	var XIIIArrowButton LeftArrow, RightArrow;
    00022
    00023	var XIIIMsgBox msgbox, msgbox2;
    00024
    00025	var texture tBackGround[3];
    00026	var string sBackground[3];
    00027
    00028	var int ReturnCode;       // to be used with save game device
    00029	var int IsEmpty;
    00030	var int i;
    00031	var int SlotNumberToLoadFrom;
    00032
    00033	var int Year;
    00034	var byte Month, Day, Hour, Min;
    00035
    00036	var string SlotDesc;
    00037
    00038	var bool bRunning;
    00039	var bool bMemoryCardDetected;
    00040	var bool bIgnoreKeys;
    00041
    00042
    00043
    00044	//============================================================================
    00045	function Created()
    00046	{
    00047	    local int i;
    00048
    00049	    CurSlot = 0;
    00050
    00051	    Super.Created();
    00052
    00053	    for (i=0; i<3; i++)
    00054	        tBackGround[i] = texture(DynamicLoadObject(sBackGround[i], class'Texture'));
    00055
    00056	    MaxSlots = myRoot.GetMaxNumberOfSavingSlots();
    00057	    if (MaxSlots > 0)
    00058	    {
    00059	        // displayed per page
    00060	        NbPages = ( MaxSlots - 1 )/MaxViewable + 1;
    00061	        if (NbPages > 0)
    00062			{
    00063	            OnPage = 1;
    00064				OldPage = 1;
    00065			}
    00066
    00067	        LeftArrow = XIIIArrowButton(CreateControl(class'XIIIArrowButton', 50/*264*/, 134*fScaleTo, 16, 16));
    00068	        LeftArrow.bLeftOrient = true;
    00069	        RightArrow = XIIIArrowButton(CreateControl(class'XIIIArrowButton', 50+320/*420*/, 134*fScaleTo, 16, 16));
    00070
    00071	        // arrows don't gain focus
    00072	        LeftArrow.bNeverFocus = true;
    00073	        RightArrow.bNeverFocus = true;
    00074
    00075			Controls[0] = LeftArrow;
    00076	        Controls[1] = RightArrow;
    00077
    00078	        for(i=0; i<MaxViewable; i++)
    00079	        {
    00080	            SaveSlots[i] = XIIIbutton(CreateControl(class'XIIIbutton', 50, 160 + (i%MaxViewable)*40*fScaleTo, 320, 30*fScaleTo));
    00081	            SaveSlots[i].text = EmptySlotText;
    00082	 			SaveSlots[i].bNeverFocus = true;
    00083				SaveSlots[i].bVisible = false;
    00084	            bSaveSlotEmpty[i] = 1;
    00085	            // add a page control
    00086	            Controls[i+2] = SaveSlots[i];
    00087	        }
    00088
    00089	        //PageSwitch();
    00090	    }
    00091
    00092	    bShowBCK = true;
    00093	    bShowSEL = true;
    00094
    00095		OnReOpen = InternalOnOpen;
    00096
    00097		GetPlayerOwner().PlayMenu(hSoundLoadMenu);
    00098
    00099	    bMemoryCardDetected = myRoot.bSavingPossible;
    00100	    GotoState('GetSlotDescription');
    00101	}
    00102
    00103
    00104	function InternalOnOpen()
    00105	{
    00106		GetPlayerOwner().PlayMenu(hSoundLoadMenu);
    00107	}
    00108
    00109
    00110	event Tick(float deltatime)
    00111	{
    00112	    if ( !bRunning )
    00113		{
    00114			if ( bMemoryCardDetected )
    00115			{
    00116				if (!myRoot.bSavingPossible)
    00117				{
    00118					log("LOAD : no memory card detected");
    00119					bMemoryCardDetected = false;
    00120					for(i=0; i<MaxViewable; i++)
    00121					{
    00122						SaveSlots[i].text = EmptySlotText;
    00123						SaveSlots[i].bNeverFocus = false;
    00124						SaveSlots[i].bVisible = true;
    00125						bSaveSlotEmpty[i] = 1;
    00126					}
    00127				}
    00128			}
    00129			else
    00130			{
    00131				if ( myRoot.bSavingPossible )
    00132				{
    00133					log("LOAD : memory card detected");
    00134					bMemoryCardDetected = true;
    00135					for(i=0; i<MaxViewable; i++)
    00136					{
    00137						SaveSlots[i].bNeverFocus = true;
    00138						SaveSlots[i].bVisible = false;
    00139					}
    00140					GotoState('GetSlotDescription');
    00141				}
    00142			}
    00143		}
    00144	}
    00145
    00146
    00147	function Paint(Canvas C, float X, float Y)
    00148	{
    00149	     local int i;//, oldpage;
    00150	     local float W, H;
    00151		 LOCAL string strTemp;
    00152
    00153	     Super.Paint(C, X, Y);
    00154
    00155	     C.bUseBorder = true;
    00156		 DrawStretchedTexture(C, 36*fRatioX, 33*fScaleTo*fRatioY, 348*fRatioX, 393*fScaleTo*fRatioY, tBackGround[0]);
    00157	     C.bUseBorder = false;
    00158		 DrawStretchedTexture(C, 342*fRatioX, 49*fScaleTo*fRatioY, 256*fRatioX, 128*fScaleTo*fRatioY, tBackGround[1]);
    00159	     DrawStretchedTexture(C, 342*fRatioX, 177*fScaleTo*fRatioY, 256*fRatioX, 256*fScaleTo*fRatioY, tBackGround[2]);
    00160
    00161	    // slots for save game
    00162	    C.DrawColor = WhiteColor;
    00163	    // if not on first page, display arrows
    00164	    if (OnPage > 1)     Controls[0].bVisible = true;
    00165	    else                Controls[0].bVisible = false;
    00166
    00167	    if (OnPage < NbPages)     Controls[1].bVisible = true;
    00168	    else                        Controls[1].bVisible = false;
    00169
    00170	    C.bUseBorder = true;
    00171	    DrawStretchedTexture(C, 0, 40*fRatioY, 170*fRatioX, 40*fRatioY, myRoot.FondMenu);
    00172	    C.TextSize(TitleText, W, H);
    00173	    C.DrawColor = BlackColor;
    00174	    C.SetPos((160-W)*fRatioX, (60-H/2)*fRatioY);
    00175		C.DrawText(TitleText, false);
    00176	    C.bUseBorder = false;
    00177	    C.DrawColor = WhiteColor;
    00178
    00179		// only selected control has a border
    00180		if ( !bRunning )
    00181		{
    00182	    for (i=0; i<MaxViewable; i++)
    00183	        XIIIbutton(Controls[i + 2]).bUseBorder = false;
    00184	    if (( FindComponentIndex(FocusedControl) != 0 ) || ( FindComponentIndex(FocusedControl) != 1 ))
    00185	        XIIIbutton(Controls[FindComponentIndex(FocusedControl)]).bUseBorder = true;
    00186		}
    00187
    00188	    C.DrawColor = BlackColor;
    00189		strTemp = PageText@OnPage$"/"$NbPages;
    00190		C.TextSize( strTemp, W, H );
    00191		C.SetPos( 210-W*0.5, 134*fScaleTo );
    00192		C.DrawText( strTemp );
    00193	    C.DrawColor = WhiteColor;
    00194		C.SetPos( 209-W*0.5, 133*fScaleTo );
    00195		C.DrawText( strTemp );
    00196
    00197	}
    00198
    00199
    00200	function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
    00201	{
    00202	    if ( !bIgnoreKeys )
    00203		{
    00204			if (State==1)// IST_Press // to avoid auto-repeat
    00205			{
    00206				if ((Key==0x0D/*IK_Enter*/) || (Key==0x01))
    00207				{
    00208				   if (FindComponentIndex(FocusedControl) > 1)
    00209					{   // slot
    00210						CurSlot = FindComponentIndex(FocusedControl) - 2;
    00211
    00212						// if selected slot empty, error
    00213						if (bSaveSlotEmpty[CurSlot]==1)
    00214						{
    00215							myRoot.OpenMenu("XIDInterf.XIIIMsgBox");
    00216							msgbox = XIIIMsgBox(myRoot.ActivePage);
    00217							msgbox.InitBox(220*fRatioX, 130*fRatioY*fScaleTo, 10, 10, 220*fRatioX, 230*fRatioY*fScaleTo);
    00218							DisplayedText = msgbox.Replace(EmptySlotErrorMsg, "NbSlot", string(CurSlot + (OnPage - 1)*MaxViewable));
    00219							msgbox.SetupQuestion(DisplayedText, QBTN_Ok, QBTN_Ok,EmptySlotErrorTitle);
    00220						}
    00221						else
    00222						{   // Load
    00223							SlotNumberToLoadFrom = CurSlot + (OnPage - 1)*MaxViewable;
    00224							GotoState('LoadFromSlot');
    00225						}
    00226
    00227						return true;
    00228					}
    00229					else
    00230					{   // arrow
    00231						OldPage = OnPage;
    00232						if (FindComponentIndex(FocusedControl)==0) OnPage--;
    00233						if (FindComponentIndex(FocusedControl)==1) OnPage++;
    00234						OnPage = Clamp(OnPage,1,NbPages);
    00235						if (OnPage != OldPage)
    00236							PageSwitch();
    00237					}
    00238				}
    00239
if ((Key==0x08/*IK_Backspace*/)|| (Key==0x1B)) 00240 { 00241 myRoot.CloseMenu(true); 00242 return true; 00243 } 00244 if (Key==0x26/*IK_Up*/) 00245 { 00246 PrevControl(FocusedControl); 00247 return true; 00248 } 00249 if (Key==0x28/*IK_Down*/) 00250 { 00251 NextControl(FocusedControl); 00252 return true; 00253 } 00254 if ((Key==0x25/*IK_Left*/) || (Key==0x27/*IK_Right*/)) 00255 { 00256 if (NbPages > 1) 00257 { 00258 OldPage = OnPage; 00259 if (Key==0x25) OnPage--; 00260 if (Key==0x27) OnPage++; 00261 OnPage = Clamp(OnPage,1,NbPages); 00262 if (OnPage != OldPage) 00263 PageSwitch(); 00264 } 00265 return true; 00266 } 00267 } 00268 } 00269 return super.InternalOnKeyEvent(Key, state, delta); 00270 } 00271 00272 00273 function PageSwitch() 00274 { 00275 local int i; 00276 00277 for(i=0; i<MaxViewable; i++) 00278 { 00279 SaveSlots[i].text = EmptySlotText; 00280 bSaveSlotEmpty[i] = 1; 00281 if ( SaveSlotsInfo[i + (OnPage - 1)*MaxViewable] != "" ) 00282 { 00283 SaveSlots[i].text = SaveSlotsInfo[i + (OnPage - 1)*MaxViewable]; 00284 bSaveSlotEmpty[i] = 0; 00285 } 00286 } 00287 } 00288 00289 State GetSlotDescription 00290 { 00291 Begin: 00292 bRunning = true; 00293 00294 if ( myRoot.bSavingPossible ) 00295 { 00296 for (i=0; i<MaxSlots; i++) 00297 { 00298 if (!myRoot.RequestIsSlotEmpty(i)) 00299 { 00300 log("Slot "$i$": Error: unable to access"); 00301 } 00302 else 00303 { 00304 while (!myRoot.IsSlotEmptyFinished(ReturnCode, IsEmpty)) 00305 { 00306 Sleep(0.01); 00307 } 00308 if (ReturnCode < 0) 00309 { 00310 log("Slot "$i$": Error2: access failed"); 00311 } 00312 else 00313 { 00314 if (!bool(IsEmpty)) 00315 { 00316 bSaveSlotEmpty[i] = 0; 00317 if (!myRoot.RequestGetSlotContentDescription(i)) 00318 { 00319 log("Slot "$i$": Error3: not empty, but unable to get the description"); 00320 } 00321 else 00322 { 00323 while (!myRoot.IsGetSlotContentDescriptionFinished(ReturnCode, SlotDesc)) 00324 { 00325 Sleep(0.01); 00326 } 00327 if (ReturnCode < 0) 00328 { 00329 log("Slot "$i$": Error4: get description failed"); 00330 } 00331 else 00332 { 00333 if (!myRoot.RequestGetSlotContentDateAndTime(i)) 00334 { 00335 log("Slot "$i$": Error5: not empty, but unable to get the date and time"); 00336 } 00337 else 00338 { 00339 while (!myRoot.IsGetSlotContentDateAndTimeFinished(ReturnCode, Year, Month, Day, Hour, Min)) 00340 { 00341 Sleep(0.01); 00342 } 00343 if (ReturnCode < 0) 00344 { 00345 log("Slot "$i$": Error6: get date and time failed"); 00346 } 00347 else 00348 { 00349 SlotDesc = SlotDesc$" "$Hour$":"; 00350 if (Min<10) SlotDesc = SlotDesc$"0"; 00351 SlotDesc = SlotDesc$Min$" "$Month$"/"$Day$"/"$Year; 00352 SaveSlotsInfo[i] = SlotDesc; 00353 } 00354 } 00355 } 00356 } 00357 } 00358 } 00359 } 00360 } 00361 } 00362 00363 bRunning = false; 00364 for(i=0; i<MaxViewable; i++) 00365 { 00366 SaveSlots[i].bNeverFocus = false; 00367 SaveSlots[i].bVisible = true; 00368 } 00369 SaveSlots[0].FocusFirst(self,true); 00370 PageSwitch(); 00371 GotoState(''); 00372 } 00373 00374 00375 State LoadFromSlot // slot to use is in SlotNumberToLoadFrom 00376 { 00377 Begin: 00378 bIgnoreKeys = true; 00379 if (!myRoot.RequestReadSlot(SlotNumberToLoadFrom)) 00380 { 00381 log("Unable to load from slot "$SlotNumberToLoadFrom); 00382 } 00383 else 00384 { 00385 while (!myRoot.IsReadSlotFinished(ReturnCode)) 00386 { 00387 Sleep(0.01); 00388 } 00389 00390 if ( ReturnCode >= 0 ) 00391 { 00392 myRoot.CloseAll(true); 00393 myRoot.gotostate(''); 00394 } 00395 } 00396 bIgnoreKeys = false; 00397 GotoState(''); 00398 } 00399 00400 00401 00402 00403 defaultproperties 00404 { 00405 TitleText="Load Game" 00406 EmptySlotText="-- empty slot --" 00407 EmptySlotErrorTitle="Slot Empty" 00408 EmptySlotErrorMsg="Slot %NbSlot% Empty" 00409 LoadGameResultTile="Save Game" 00410 PageText="Page" 00411 MaxViewable=5 00412 sBackground(0)="XIIIMenuStart.vignette_fond" 00413 sBackground(1)="XIIIMenuStart.XIII_Buste" 00414 sBackground(2)="XIIIMenuStart.XIII_Jambes" 00415 bDoStoreInSaveMenuStack=False 00416 }

End Source Code