//=============================================================================
// UnrealWeaponMenu
//=============================================================================
class UnrealWeaponMenu expands UnrealMenu;

var int Slot[21];

function PostBeginPlay()
{
	local int i,j;

	CallParent.PostBeginPlay();
	j = 1;
	MenuLength = 0;
	for ( i=19; i>=0; i-- )
	{
		if ( PlayerOwner.WeaponPriority[i] != '' )
		{
			MenuLength++;
			Slot[j] = i;
			j++;
		}
	}
}

function bool ProcessLeft()
{
	local name temp;

	if ( Selection > 1 )
	{
		temp = PlayerOwner.WeaponPriority[Slot[Selection]];
		PlayerOwner.WeaponPriority[Slot[Selection]] = PlayerOwner.WeaponPriority[Slot[Selection - 1]];
		PlayerOwner.WeaponPriority[Slot[Selection - 1]] = temp;
		Selection--;
	}
	else 
		return false;

	return true;
}

function bool ProcessRight()
{
	local name temp;

	if ( Selection < MenuLength )
	{
		temp = PlayerOwner.WeaponPriority[Slot[Selection]];
		PlayerOwner.WeaponPriority[Slot[Selection]] = PlayerOwner.WeaponPriority[Slot[Selection + 1]];
		PlayerOwner.WeaponPriority[Slot[Selection + 1]] = temp;
		Selection++;
	}
	else
		return false;

	return true;
}

function SaveConfigs()
{
	local inventory Inv;

	PlayerOwner.WeaponPr0 = PlayerOwner.WeaponPriority[0];
	PlayerOwner.WeaponPr1 = PlayerOwner.WeaponPriority[1];
	PlayerOwner.WeaponPr2 = PlayerOwner.WeaponPriority[2];
	PlayerOwner.WeaponPr3 = PlayerOwner.WeaponPriority[3];
	PlayerOwner.WeaponPr4 = PlayerOwner.WeaponPriority[4];
	PlayerOwner.WeaponPr5 = PlayerOwner.WeaponPriority[5];
	PlayerOwner.WeaponPr6 = PlayerOwner.WeaponPriority[6];
	PlayerOwner.WeaponPr7 = PlayerOwner.WeaponPriority[7];
	PlayerOwner.WeaponPr8 = PlayerOwner.WeaponPriority[8];
	PlayerOwner.WeaponPr9 = PlayerOwner.WeaponPriority[9];
	PlayerOwner.WeaponPr10 = PlayerOwner.WeaponPriority[10];
	PlayerOwner.WeaponPr11 = PlayerOwner.WeaponPriority[11];
	PlayerOwner.WeaponPr12 = PlayerOwner.WeaponPriority[12];
	PlayerOwner.WeaponPr13 = PlayerOwner.WeaponPriority[13];
	PlayerOwner.WeaponPr14 = PlayerOwner.WeaponPriority[14];
	PlayerOwner.WeaponPr15 = PlayerOwner.WeaponPriority[15];
	PlayerOwner.WeaponPr16 = PlayerOwner.WeaponPriority[16];
	PlayerOwner.WeaponPr17 = PlayerOwner.WeaponPriority[17];
	PlayerOwner.WeaponPr18 = PlayerOwner.WeaponPriority[18];
	PlayerOwner.WeaponPr19 = PlayerOwner.WeaponPriority[19];

	PlayerOwner.SaveConfig('PlayerPawn');
	For ( Inv=PlayerOwner.Inventory; Inv!=None; Inv=Inv.Inventory )
		if ( Inv.IsA('Weapon') )
			Weapon(Inv).SetSwitchPriority(PlayerOwner); 
}

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

	// Draw Title
	StartX = Max(16, 0.5 * Canvas.ClipX - 144);
	Canvas.Font = Font'LargeFont';
	Canvas.SetPos(StartX, 4 );
	Canvas.DrawText("WEAPON PRIORITIES", False);
		
	// Draw Weapon Priorities
		
	Spacing = Clamp(Canvas.ClipY/20, 10, 32);
	StartX = Max(48, 0.5 * Canvas.ClipX - 64);
	StartY = Max(40, 0.5 * (Canvas.ClipY - MenuLength * Spacing));
	Canvas.Font = Font'MedFont';

	j = 1;
	MenuLength = 0;
	for ( i=19; i>=0; i-- )
	{
		if ( PlayerOwner.WeaponPriority[i] != '' )
		{
			MenuLength++;
			Slot[j] = i;
			Canvas.SetPos(StartX, StartY + (j-1) * Spacing );
			j++;
			Canvas.DrawText(PlayerOwner.WeaponPriority[i], false);
			if ( MenuLength > Canvas.ClipY/Spacing - 1 )
				break;
		}
	}

	// show selection
	Canvas.SetPos( StartX - 20, StartY + Spacing * (Selection - 1));
	Canvas.DrawText("[]", false);	

}

