//=============================================================================
// UnrealSlotMenu
//=============================================================================
class UnrealSlotMenu expands UnrealMenu
	config;

var string[64] SlotNames[9];
var config string[64] SlotName0, SlotName1, SlotName2, SlotName3, SlotName4,
						 SlotName5, SlotName6, SlotName7, SlotName8;
var bool bSaveMenu;
var bool bMoved;
var int StartSelection;

function BeginPlay()
{
	local int i;

	CallParent.BeginPlay();
	SlotNames[0] = SlotName0;
	SlotNames[1] = SlotName1;
	SlotNames[2] = SlotName2;
	SlotNames[3] = SlotName3;
	SlotNames[4] = SlotName4;
	SlotNames[5] = SlotName5;
	SlotNames[6] = SlotName6;
	SlotNames[7] = SlotName7;
	SlotNames[8] = SlotName8;
	For (i=0; i<9; i++ )
		if (SlotNames[i] ~= "..Empty.." )
		{
			Selection = i + 1;
			break;
		}
	StartSelection = Selection;
}


function bool ProcessSelection()
{
	local Menu ChildMenu;

	if ( bSaveMenu )
	{
		SlotNames[Selection - 1] = (Level.Title$"_"$Level.Minute$"\:"$Level.Second);
		SlotName0 = SlotNames[0];
		SlotName1 = SlotNames[1];
		SlotName2 = SlotNames[2];
		SlotName3 = SlotNames[3];
		SlotName4 = SlotNames[4];
		SlotName5 = SlotNames[5];
		SlotName6 = SlotNames[6];
		SlotName7 = SlotNames[7];
		SlotName8 = SlotNames[8];
		SaveConfig();
		bExitAllMenus = true;
		PlayerOwner.DelayedCommand = "SaveGame "$(Selection - 1);
		return true;
	}
	else
	{
		if ( SlotNames[Selection - 1] ~= "<Empty>" )
			return false;
		bExitAllMenus = true;
		PlayerOwner.ClientLinkToURL("..\\save\\save"$(Selection - 1)$".usa", false);
		return true;
	}
}

function DrawSlots(canvas Canvas)
{
	local int StartX, StartY, Spacing, i;
		
	Spacing = Clamp(0.05 * Canvas.ClipY, 12, 32);
	StartX = Max(48, 0.5 * Canvas.ClipX - 120);
	StartY = Max(40, 0.5 * (Canvas.ClipY - MenuLength * Spacing));
	Canvas.Font = Font'MedFont';

	// draw text
	Canvas.SetPos(StartX, StartY );
	Canvas.DrawText("SLOT", False);

	For ( i=1; i<10; i++ )
	{
		Canvas.SetPos(StartX, StartY + i * Spacing );
		Canvas.DrawText(" "$i$"   "$SlotNames[i-1], False);
	}

	// show selection
	bMoved = bMoved || (Selection != StartSelection);
	if ( !bMoved && !bSaveMenu )
	{
		Selection = 1;
		StartSelection = 1;
	}
	Canvas.SetPos( StartX - 20, StartY + Spacing * Selection);
	Canvas.DrawText("[]", false);	
}


function DrawMenu(canvas Canvas)
{
	local int StartX, StartY, Spacing, i;

	// Draw Title
	StartX = Max(16, 0.5 * Canvas.ClipX - 96);
	Canvas.Font = Font'LargeFont';
	Canvas.SetPos(StartX, 4 );
	if ( bSaveMenu )
		Canvas.DrawText("SAVE GAME", False);
	else
		Canvas.DrawText("LOAD GAME", False);
		
	// Draw Slots
	DrawSlots(Canvas);	
}
