//=============================================================================
// ChallengeOrdersMenu
//=============================================================================
class ChallengeOrdersMenu expands UnrealLongMenu
	localized;

var() localized string[32] OrderStrings[16];
var() localized name OrderNames[16];
var() localized string[32] CallSigns[16];
var() int NumOrders;
var localized string[32] HumanString;
var pawn TeamMates[16];
var int OrderOffset[16];
var int OrderChanged[16];

static function string[32] GetOrderStrings(int i)
{
	return Default.OrderStrings[i];
}

static function string[32] GetCallSigns(int i)
{
	return Default.CallSigns[i];
}

function MenuInit()
{
	local Pawn P;
	local int i;

	//find all teammates of this player
	MenuLength = 0;
	For (P=Level.PawnList; P!=None; P=P.nextPawn )
		if ( P.bIsPlayer && (P.PlayerReplicationInfo.Team == PlayerOwner.PlayerReplicationInfo.Team) )
		{
			TeamMates[MenuLength] = P;
			if ( P.IsA('Bot') )
			{
				OrderOffset[MenuLength] = 4; // Assume Freelance
				for ( i=0; i<NumOrders; i++ )
					if ( OrderNames[i] == BotReplicationInfo(P.PlayerReplicationInfo).RealOrders )
					{
						OrderOffset[MenuLength] = i;
						break;
					}
			}	
			MenuLength++;
			if ( MenuLength > 15 )
				break;
		}
	if ( MenuLength > 0 )
		Selection = 1;
}

function bool ProcessLeft()
{
	if ( !TeamMates[Selection-1].IsA('Bot') )
		return false;
	
	if ( OrderOffset[Selection-1] <= 0 )
		OrderOffset[Selection-1] = NumOrders - 1;
	else
		OrderOffset[Selection-1]--;	

	OrderChanged[Selection-1] = 1;
	return true;
}

function bool ProcessRight()
{
	if ( !TeamMates[Selection-1].IsA('Bot') )
		return false;
	
	if ( OrderOffset[Selection-1] >= NumOrders - 1 )
		OrderOffset[Selection-1] = 0;
	else
		OrderOffset[Selection-1]++;	

	OrderChanged[Selection-1] = 1;
	return true;
}

function SaveConfigs()
{
	local int i;

	for ( i=0; i<MenuLength; i++ )
		if ( OrderChanged[i] == 1 )
			PlayerOwner.SendVoiceMessage(PlayerOwner.PlayerReplicationInfo, TeamMates[i].PlayerReplicationInfo, 'ORDER', byte(OrderOffset[i]), 'TEAM');
}

function DrawMenu(canvas Canvas)
{
	local int i, StartX, StartY, Spacing;
	local vector DrawOffset;
	local rotator NewRot;

	DrawBackGround(Canvas, false);

	// Draw Title
	DrawTitle(Canvas);

	Spacing = Clamp(0.04 * Canvas.ClipY, 12, 32);
	StartX = Max(10, 0.5 * Canvas.ClipX - 115);
	StartY = Max(40, 0.5 * (Canvas.ClipY - MenuLength * Spacing - 128));

	for ( i=0; i<MenuLength; i++ )
		MenuList[i+1] = TeamMates[i].PlayerReplicationInfo.PlayerName$"("$CallSigns[TeamMates[i].PlayerReplicationInfo.TeamID]$")";

	DrawList(Canvas, false, Spacing, StartX, StartY);  

	for ( i=0; i<MenuLength; i++ )
	{
		if ( TeamMates[i].IsA('PlayerPawn') )
			MenuList[i+1] = HumanString;
		else
			MenuList[i+1] = OrderStrings[OrderOffset[i]];
	}
	DrawList(Canvas, false, Spacing, StartX + 160, StartY);  

	// Draw help panel
	//DrawHelpPanel(Canvas, Canvas.ClipY - 64, 228);
}

defaultproperties
{
     OrderStrings(0)="Defend"
     OrderStrings(1)="Hold"
     OrderStrings(2)="Attack"
     OrderStrings(3)="Support"
     OrderStrings(4)="Freelance"
     OrderNames(0)=Defend
     OrderNames(1)=Hold
     OrderNames(2)=Attack
     OrderNames(3)=Follow
     OrderNames(4)=FreeLance
     CallSigns(0)="Leader"
     CallSigns(1)="Abel"
     CallSigns(2)="Baker"
     CallSigns(3)="Charlie"
     CallSigns(4)="Dog"
     CallSigns(5)="Easy"
     CallSigns(6)="Fox"
     CallSigns(7)="Romeo"
     CallSigns(8)="Tango"
     CallSigns(9)="Victor"
     CallSigns(10)="Zulu"
     NumOrders=5
     HumanString="-Human-"
     MenuTitle="TEAM ORDERS"
}
