## XIDInterf
Class XIIIMenuSave

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

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

Direct Known Subclasses:None

class XIIIMenuSave
extends XIDInterf.XIIIWindow

    //============================================================================
    // Save Game menu.
    //
    //============================================================================

Variables
`oldPage,` | `CurSlot`
`string` | `DisplayedText`
`string` | `EmptySlotText`
`string` | `FullSlotErrorMsg`
`string` | `FullSlotErrorTitle`
`int` | `IsEmpty` to be used with save game device
`Hour,` | `Min` to be used with save game device
`string` | `PageText` to be used with save game device
`int` | `ReturnCode` to be used with save game device
`LeftArrow,` | `RightArrow`
`string` | `SaveFailed`
`string` | `SaveGameResultTile`
`string` | `SaveOk`
`array` | `SaveSlots`
`int` | `SlotNumberToSaveIn` to be used with save game device
`string` | `TitleText`
`int` | `Year` to be used with save game device
`array` | `bSaveSlotEmpty`
`int` | `i` to be used with save game device
`msgbox,` | `msgbox2`

States
SaveInSlot, GetSlotDescription

Function Summary
`void` | `Created()`
`bool` | `InternalOnKeyEvent(out byte, out byte, float delta)`
`void` | `OnTickMsgBox(float deltatime)`
`void` | `PageSwitch()`
`void` | `Paint(Canvas C, float X, float Y)`
`void` | `ReturnMsgBox(byte bButton)`

State SaveInSlot Function Summary

State GetSlotDescription Function Summary

Source Code

    00001	//============================================================================
    00002	// Save Game menu.
    00003	//
    00004	//============================================================================
    00005	class XIIIMenuSave extends XIIIWindow;
    00006
    00007	var localized string TitleText;
    00008	var localized string SaveOk;
    00009	var localized string SaveFailed;
    00010	var localized string EmptySlotText;
    00011	var localized string FullSlotErrorTitle;
    00012	var localized string FullSlotErrorMsg;
    00013	var localized string SaveGameResultTile;
    00014
    00015	var array<XIIIbutton> SaveSlots;
    00016	var array<byte> bSaveSlotEmpty;
    00017	var XIIIArrowButton LeftArrow, RightArrow;
    00018
    00019	var XIIIMsgBox msgbox, msgbox2;
    00020
    00021	var int  MaxMenu, onPage, MaxSlots, MaxViewable, NbPages, oldPage, CurSlot;
    00022	var string DisplayedText;
    00023
    00024	var int ReturnCode;       // to be used with save game device
    00025	var int IsEmpty;
    00026	var int i;
    00027	var int SlotNumberToSaveIn;
    00028
    00029	var int Year;
    00030	var byte Month, Day, Hour, Min;
    00031	var localized string PageText;
    00032
    00033	function Created()
    00034	{
    00035	    local int i;
    00036
    00037	    OnMenu = 0;
    00038	    oldPage = 0;
    00039	    OnPage = 0;
    00040	    NbPages = 0;
    00041	    CurSlot = 0;
    00042
    00043	    Super.Created();
    00044
    00045	    MaxSlots = myRoot.GetMaxNumberOfSavingSlots();
    00046	    if (MaxSlots>0)
    00047	    {
    00048	        // total number of slots for a player
    00049	        MaxMenu = MaxSlots;
    00050	        // displayed per page
    00051	        NbPages = (MaxSlots-1)/MaxViewable+1;
    00052	        if (NbPages>0)
    00053	            OnPage = 1;
    00054
    00055	        LeftArrow = XIIIArrowButton(CreateControl(class'XIIIArrowButton', (320-100), 134, 16, 16));
    00056	        LeftArrow.bLeftOrient = true;
    00057	        RightArrow = XIIIArrowButton(CreateControl(class'XIIIArrowButton', (320+100), 134, 16, 16));
    00058	        Controls[0] = LeftArrow;
    00059	        Controls[1] = RightArrow;
    00060	        // arrows don't gain focus
    00061	        LeftArrow.bNeverFocus = true;
    00062	        RightArrow.bNeverFocus = true;
    00063
    00064	        for(i=0; i<MaxSlots; i++)
    00065	        {
    00066	            //SaveSlots[i] = XIIIbutton(CreateControl(class'XIIIbutton', 230, 160 + (i%MaxViewable)*40*fScaleTo, 200, 30*fScaleTo));
    00067	            SaveSlots[i] = XIIIbutton(CreateControl(class'XIIIbutton', 120, (160 + (i%MaxViewable)*40)*fScaleTo, 400, 30*fScaleTo));
    00068	            SaveSlots[i].bUseBorder = false;
    00069	            SaveSlots[i].bNeverFocus = true;
    00070	            SaveSlots[i].text = EmptySlotText;
    00071	            bSaveSlotEmpty[i] = 1;
    00072	            // add a page control
    00073	            Controls[i+2] = SaveSlots[i];
    00074	            Controls[i+2].bVisible = false;
    00075	        }
    00076
    00077	        PageSwitch();
    00078	    }
    00079
    00080	    bShowBCK = true;
    00081	    bShowSEL = true;
    00082
    00083	    GotoState('GetSlotDescription');
    00084	}
    00085	event Tick(float deltatime)
    00086	{
    00087	    if (!myRoot.bSavingPossible)
    00088	        myRoot.CloseMenu(true);
    00089	}
    00090
    00091	function OnTickMsgBox(float deltatime)
    00092	{
    00093	    if (!myRoot.bSavingPossible)
    00094	        myRoot.CloseMenu(true);
    00095	}
    00096
    00097	function Paint(Canvas C, float X, float Y)
    00098	{
    00099	    local float W, H;
    00100	    local int i;
    00101		 LOCAL string strTemp;
    00102
    00103	    Super.Paint(C,X,Y);
    00104
    00105	    // main design
    00106	    if (!myRoot.GetLevel().bCineFrame)
    00107		{
    00108			C.DrawMsgboxBackground(false, 110*fRatioX, 130*fRatioY*fScaleTo, 10, 10, 420*fRatioX, 250*fRatioY*fScaleTo);
    00109		}
    00110	    else
    00111	    {
    00112			C.DrawMsgboxBackground(false, 0.09*C.ClipX*fRatioX, 0.2*C.ClipY*fRatioY*fScaleTo, 10, 10, 0.82*C.ClipX*fRatioX, 0.6*C.ClipY*fRatioY*fScaleTo);
    00113	    }
    00114
    00115	    // slots for save game
    00116	    C.DrawColor = WhiteColor;
    00117	    // if not on first page, display arrows
    00118	    if (OnPage > 1)     Controls[0].bVisible = true;
    00119	    else                Controls[0].bVisible = false;
    00120
    00121	    if (OnPage < NbPages)     Controls[1].bVisible = true;
    00122	    else                        Controls[1].bVisible = false;
    00123
    00124	    // only selected control has a border
    00125	    for (i=(onPage-1)*MaxViewable; i < onPage*MaxViewable; i++)
    00126	        XIIIbutton(Controls[2+i]).bUseBorder = false;
    00127	    if (FindComponentIndex(FocusedControl)!= -1)
    00128	        XIIIbutton(Controls[FindComponentIndex(FocusedControl)]).bUseBorder = true;
    00129
    00130	    CurSlot = FindComponentIndex(FocusedControl)-2;
    00131
    00132	    // page title
    00133	    C.bUseBorder = true;
    00134	    C.TextSize(/*Caps(*/TitleText/*)*/, W, H);
    00135	    DrawStretchedTexture(C, (640-W-64)*0.5*fRatioX, 70*fRatioY, (W+64)*fRatioX, 40*fScaleTo*fRatioY, myRoot.FondMenu);
    00136	    C.DrawColor = BlackColor;
    00137	    C.SetPos((320-W/2)*fRatioX, (90*fScaleTo*fRatioY)-H/2);
    00138	    C.DrawText( TitleText, false);
    00139
    00140	    // restore old param
    00141		C.DrawColor = WhiteColor;
    00142	    C.DrawColor.A = 255; C.Style = 1; C.bUseBorder = false;
    00143
    00144	    C.DrawColor = BlackColor;
    00145		strTemp = PageText@OnPage$"/"$NbPages;
    00146		C.TextSize( strTemp, W, H );
    00147		C.SetPos( 320*fRatioX-W*0.5, 130*fScaleTo );
    00148		C.DrawText( strTemp );
    00149		C.DrawColor = WhiteColor;
    00150	}
    00151
    00152	function ReturnMsgBox(byte bButton)
    00153	{
    00154	    if ((bButton & QBTN_Ok) != 0)       // ok to overwrite
    00155	    {
    00156	        GotoState('SaveInSlot');
    00157	    }
    00158	}
    00159
    00160	function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
    00161	{
    00162	    if (State==1)// IST_Press // to avoid auto-repeat
    00163	    {
    00164	        if ((Key==0x0D/*IK_Enter*/) || (Key==0x01)/*IK_LeftMouse*/)
    00165		    {
    00166		        if (FindComponentIndex(FocusedControl) > 1)
    00167		        {   // slot
    00168	                CurSlot = FindComponentIndex(FocusedControl)-2;
    00169
    00170	                // Whether empty of not, memorize that it is this slot that we should save !
    00171	                SlotNumberToSaveIn = CurSlot;
    00172
    00173	                // if selected slot empty, save
    00174	                if (bSaveSlotEmpty[CurSlot]==1)
    00175	                {
    00176	                    GotoState('SaveInSlot');
    00177	                }
    00178	                else
    00179	                {   // confirm erase
    00180	                    myRoot.OpenMenu("XIDInterf.XIIIMsgBox");
    00181	                    msgbox = XIIIMsgBox(myRoot.ActivePage);
    00182	                    msgbox.InitBox(220*fRatioX, 130*fRatioY*fScaleTo, 10, 10, 220*fRatioX, 230*fRatioY*fScaleTo);
    00183	                    DisplayedText = msgbox.Replace(FullSlotErrorMsg, "NbSlot", string(CurSlot));
    00184	                    msgbox.SetupQuestion(DisplayedText, QBTN_Ok | QBTN_Cancel, QBTN_Cancel,FullSlotErrorTitle);
    00185	                    msgbox.OnButtonClick=ReturnMsgBox;
    00186	                    msgbox.OnTick=OnTickMsgBox;
    00187	                }
    00188
    00189	                return true;
    00190	            }
    00191	            else
    00192	            {   // arrow
    00193	                OldPage = OnPage;
    00194	                if (FindComponentIndex(FocusedControl)==0) OnPage--;
    00195	                if (FindComponentIndex(FocusedControl)==1) OnPage++;
    00196	                PageSwitch();
    00197	            }
    00198		    }
    00199		    else if ((Key==0x08/*IK_Backspace*/)|| (Key==0x1B) /*IK_Escape*/)
    00200		    {
    00201		        myRoot.CloseMenu(true);
    00202	    	    return true;
    00203		    }
    00204	        if (Key==0x26/*IK_Up*/)
    00205		    {
    00206	            PrevControl(FocusedControl);
    00207	    	    return true;
    00208		    }
    00209		    if (Key==0x28/*IK_Down*/)
    00210		    {
    00211	            NextControl(FocusedControl);
    00212	    	    return true;
    00213		    }
    00214		    if ((Key==0x25/*IK_Left*/) || (Key==0x27/*IK_Right*/))
    00215		    {
    00216		        if (NbPages > 1)
    00217	            {
    00218	                OldPage = OnPage;
    00219	                if (Key==0x25) OnPage--;
    00220	                if (Key==0x27) OnPage++;
    00221	                PageSwitch();
    00222	            }
    00223	            return true;
    00224	        }
    00225	    }
    00226	    return super.InternalOnKeyEvent(Key, state, delta);
    00227	}
    00228
    00229	function PageSwitch()
    00230	{
    00231	    local int i, j;
    00232
    00233	    if (OnPage < 1)
    00234	        OnPage = 1;
    00235	    else if (OnPage > NbPages)
    00236	        OnPage = NbPages;
    00237	    if (OnPage != OldPage)
    00238	    {
    00239
if (0 != OldPage) 00240 { // hide oldpage's controls 00241 for (i=(OldPage-1)*MaxViewable;i<OldPage*MaxViewable; i++) 00242 { 00243 Controls[2+i].bVisible = false; 00244 XIIIbutton(Controls[2+i]).bNeverFocus = true; 00245 XIIIbutton(Controls[2+i]).bUseBorder = false; 00246 } 00247 } 00248 // show current page controls 00249 for (i=(onPage-1)*MaxViewable; i < onPage*MaxViewable; i++) 00250 { 00251 Controls[2+i].bVisible = true; 00252 XIIIbutton(Controls[2+i]).bNeverFocus = false; 00253 XIIIbutton(Controls[2+i]).bUseBorder = false; 00254 } 00255 CurSlot = FindComponentIndex(Controls[(onPage-1)*MaxViewable+2])-2; 00256 SetFocus(Controls[CurSlot+2]); 00257 } 00258 } 00259 00260 00261 00262 State GetSlotDescription 00263 { 00264 Begin: 00265 for (i=0; i<MaxSlots; i++) 00266 { 00267 if (!myRoot.RequestIsSlotEmpty(i)) 00268 { 00269 log("Slot "$i$": Error: unable to access"); 00270 } 00271 else 00272 { 00273 while (!myRoot.IsSlotEmptyFinished(ReturnCode, IsEmpty)) 00274 { 00275 Sleep(0.01); 00276 } 00277 if (ReturnCode < 0) 00278 { 00279 log("Slot "$i$": Error2: access failed"); 00280 } 00281 else 00282 { 00283 if (!bool(IsEmpty)) 00284 { 00285 bSaveSlotEmpty[i] = 0; 00286 if (!myRoot.RequestGetSlotContentDescription(i)) 00287 { 00288 log("Slot "$i$": Error3: not empty, but unable to get the description"); 00289 } 00290 else 00291 { 00292 while (!myRoot.IsGetSlotContentDescriptionFinished(ReturnCode, SaveSlots[i].text)) 00293 { 00294 Sleep(0.01); 00295 } 00296 if (ReturnCode < 0) 00297 { 00298 log("Slot "$i$": Error4: get description failed"); 00299 } 00300 else 00301 { 00302 if (!myRoot.RequestGetSlotContentDateAndTime(i)) 00303 { 00304 log("Slot "$i$": Error5: not empty, but unable to get the date and time"); 00305 } 00306 else 00307 { 00308 while (!myRoot.IsGetSlotContentDateAndTimeFinished(ReturnCode, Year, Month, Day, Hour, Min)) 00309 { 00310 Sleep(0.01); 00311 } 00312 if (ReturnCode < 0) 00313 { 00314 log("Slot "$i$": Error6: get date and time failed"); 00315 } 00316 else 00317 { 00318 SaveSlots[i].text = SaveSlots[i].text$" "$Hour$":"; 00319 if (Min<10) SaveSlots[i].text = SaveSlots[i].text$"0"; 00320 SaveSlots[i].text = SaveSlots[i].text$Min$" "$Month$"/"$Day$"/"$Year; 00321 } 00322 } 00323 } 00324 } 00325 } 00326 } 00327 } 00328 } 00329 GotoState(''); 00330 } 00331 00332 State SaveInSlot // slot to use is in SlotNumberToSaveIn 00333 { 00334 Begin: 00335 if (!myRoot.RequestWriteSlot(SlotNumberToSaveIn)) 00336 { 00337 log("Unable to save in slot "$SlotNumberToSaveIn); 00338 } 00339 else 00340 { 00341 while (!myRoot.IsWriteSlotFinished(ReturnCode)) 00342 { 00343 Sleep(0.01); 00344 } 00345 00346 myRoot.OpenMenu("XIDInterf.XIIIMsgBox",true); 00347 msgbox2 = XIIIMsgBox(myRoot.ActivePage); 00348 msgbox2.InitBox(220*fRatioX, 130*fRatioY*fScaleTo, 10, 10, 220*fRatioX, 230*fRatioY*fScaleTo); 00349 if (ReturnCode < 0) 00350 { 00351 DisplayedText = SaveFailed; 00352 } 00353 else 00354 { 00355 DisplayedText = saveok; 00356 } 00357 msgbox2.SetupQuestion(DisplayedText, QBTN_Ok, QBTN_Ok, SaveGameResultTile); 00358 00359 } 00360 GotoState(''); 00361 } 00362 00363 00364 00365 00366 defaultproperties 00367 { 00368 TitleText="Save game" 00369 EmptySlotText="-- empty slot --" 00370 FullSlotErrorTitle="Slot Full" 00371 FullSlotErrorMsg="Slot %NbSlot% already exists|Do you want to overwrite it ?" 00372 SaveGameResultTile="Save Game" 00373 QuickSavePrefix="QS :" 00374 MaxViewable=5 00375 PageText="Page" 00376 bForceHelp=True 00377 Background=None 00378 }

End Source Code