//=============================================================================
// ChallengeDMOptionsMenu
//=============================================================================
class ChallengeDMOptionsMenu expands UnrealLongMenu
	config
	localized;

var() localized string[64] AdvancedString;
var() localized string[128] AdvancedHelp;
var() localized string[32] GameStyle[4];
var() config bool bCanModifyGore;
var() class<GameInfo> GameClass;
var	  GameInfo	GameType;
var   int GameIndex;

function Destroyed()
{
	Super.Destroyed();
	if ( GameType != Level.Game )
		GameType.Destroy();
}

function PostBeginPlay()
{
	Super.PostBeginPlay();
	if ( Level.Game.Class == GameClass )
		GameType = Level.Game;
	else
		GameType = Spawn(GameClass);

	if (DeathMatchPlus(GameType).bNoviceMode)
		GameIndex = 0;
	else if (DeathMatchPlus(GameType).bMegaSpeed)
		GameIndex = 3;
	else if (DeathMatchPlus(GameType).bHardCoreMode)
		GameIndex = 2;
	else
		GameIndex = 1;
}

function MenuProcessInput( byte KeyNum, byte ActionNum )
{
	Super.MenuProcessInput(KeyNum, ActionNum);
	if ( !bCanModifyGore )
	{
		if ( KeyNum == EInputKey.IK_Up )
		{
			if ( Selection == 2 )
				Selection = 1;
		}
		else if ( KeyNum == EInputKey.IK_Down )
		{
			if ( Selection == 2 )
				Selection = 3;
		}
	}
}

function bool ProcessYes()
{
	if ( Selection == 7 )
		DeathMatchPlus(GameType).bCoopWeaponMode = True;		
	else if ( Selection == 9 )
		DeathMatchPlus(GameType).bUseTranslocator = true;
	else if ( Selection == 10 )
		DeathMatchPlus(GameType).bJumpMatch = true;
	else if ( Selection == 11 )
		DeathMatchPlus(GameType).bTournament = true;
	else if ( Selection == 13 )
		GameType.bClassicDeathmessages = true;
	else 
		return false;

	return true;
}

function bool ProcessNo()
{
	if ( Selection == 7 )
		DeathMatchPlus(GameType).bCoopWeaponMode = False;		
	else if ( Selection == 9 )
		DeathMatchPlus(GameType).bUseTranslocator = false;
	else if ( Selection == 10 )
		DeathMatchPlus(GameType).bJumpMatch = false;
	else if ( Selection == 11 )
		DeathMatchPlus(GameType).bTournament = false;
	else if ( Selection == 13 )
		GameType.bClassicDeathmessages = false;
	else 
		return false;

	return true;
}

function bool ProcessLeft()
{
	if ( Selection == 1 )
		GameType.SetGameSpeed(FMax(0.5, Level.TimeDilation - 0.1));
	else if ( (Selection == 2) && bCanModifyGore )
		GameType.bLowGore = !GameType.bLowGore;
	else if ( Selection == 3 )
		DeathMatchPlus(GameType).FragLimit = FMax(0, DeathMatchPlus(GameType).FragLimit - 5);
	else if ( Selection == 4 )
	{
		if (TeamGamePlus(GameType) != None)
			TeamGamePlus(GameType).GoalTeamScore = FMax(0, TeamGamePlus(GameType).GoalTeamScore - 5);
	}
	else if ( Selection == 5 )
		DeathMatchGame(GameType).TimeLimit = FMax(0, DeathMatchGame(GameType).TimeLimit - 5);
	else if ( Selection == 6 )
		DeathMatchGame(GameType).MaxPlayers = Max(1, DeathMatchGame(GameType).MaxPlayers - 1);
	else if ( Selection == 7 )
		DeathMatchGame(GameType).bCoopWeaponMode = !DeathMatchGame(GameType).bCoopWeaponMode;		
	else if ( Selection == 9 )
		DeathMatchPlus(GameType).bUseTranslocator = !DeathMatchPlus(GameType).bUseTranslocator;
	else if ( Selection == 10 )
		DeathMatchPlus(GameType).bJumpMatch = !DeathMatchPlus(GameType).bJumpMatch;
	else if ( Selection == 11 )
		DeathMatchPlus(GameType).bTournament = !DeathMatchPlus(GameType).bTournament;
	else if ( Selection == 12 )
	{
		GameIndex--;
		if (GameIndex < 0)
			GameIndex = 3;
		switch (GameIndex)
		{
			case 0:
				DeathMatchPlus(GameType).bNoviceMode = true;
				DeathMatchPlus(GameType).bMegaSpeed = false;
				DeathMatchPlus(GameType).bHardCoreMode = false;
				break;
			case 1:
				DeathMatchPlus(GameType).bNoviceMode = false;
				DeathMatchPlus(GameType).bMegaSpeed = false;
				DeathMatchPlus(GameType).bHardCoreMode = false;
				break;
			case 2:
				DeathMatchPlus(GameType).bNoviceMode = false;
				DeathMatchPlus(GameType).bMegaSpeed = false;
				DeathMatchPlus(GameType).bHardCoreMode = true;
				break;
			case 3:
				DeathMatchPlus(GameType).bNoviceMode = false;
				DeathMatchPlus(GameType).bMegaSpeed = true;
				DeathMatchPlus(GameType).bHardCoreMode = true;
				break;
		}
	}
	else if ( Selection == 13 )
		GameType.bClassicDeathmessages = !GameType.bClassicDeathmessages;
	else 
		return false;

	return true;
}

function bool ProcessRight()
{
	if ( Selection == 1 )
		GameType.SetGameSpeed(FMin(2.0, Level.TimeDilation + 0.1));
	else if ( (Selection == 2) && bCanModifyGore )
		GameType.bLowGore = !GameType.bLowGore;
	else if ( Selection == 3 )
		DeathMatchGame(GameType).FragLimit = FMin(1000, DeathMatchGame(GameType).FragLimit + 5);
	else if ( Selection == 4 )
	{
		if (TeamGamePlus(GameType) != None)
			TeamGamePlus(GameType).GoalTeamScore = FMin(1000, TeamGamePlus(GameType).GoalTeamScore + 5);
	}
	else if ( Selection == 5 )
		DeathMatchGame(GameType).TimeLimit += 5;
	else if ( Selection == 6 )
		DeathMatchGame(GameType).MaxPlayers = Min(16, DeathMatchGame(GameType).MaxPlayers + 1);
	else if ( Selection == 7 )
		DeathMatchGame(GameType).bCoopWeaponMode = !DeathMatchGame(GameType).bCoopWeaponMode;		
	else if ( Selection == 9 )
		DeathMatchPlus(GameType).bUseTranslocator = !DeathMatchPlus(GameType).bUseTranslocator;
	else if ( Selection == 10 )
		DeathMatchPlus(GameType).bJumpMatch = !DeathMatchPlus(GameType).bJumpMatch;
	else if ( Selection == 11 )
		DeathMatchPlus(GameType).bTournament = !DeathMatchPlus(GameType).bTournament;
	else if ( Selection == 12 )
	{
		GameIndex++;
		if (GameIndex > 3)
			GameIndex = 0;
		switch (GameIndex)
		{
			case 0:
				DeathMatchPlus(GameType).bNoviceMode = true;
				DeathMatchPlus(GameType).bMegaSpeed = false;
				DeathMatchPlus(GameType).bHardCoreMode = false;
				break;
			case 1:
				DeathMatchPlus(GameType).bNoviceMode = false;
				DeathMatchPlus(GameType).bMegaSpeed = false;
				DeathMatchPlus(GameType).bHardCoreMode = false;
				break;
			case 2:
				DeathMatchPlus(GameType).bNoviceMode = false;
				DeathMatchPlus(GameType).bMegaSpeed = false;
				DeathMatchPlus(GameType).bHardCoreMode = true;
				break;
			case 3:
				DeathMatchPlus(GameType).bNoviceMode = false;
				DeathMatchPlus(GameType).bMegaSpeed = true;
				DeathMatchPlus(GameType).bHardCoreMode = true;
				break;
		}
	}
	else if ( Selection == 13 )
		GameType.bClassicDeathmessages = !GameType.bClassicDeathmessages;
	else 
		return false;

	return true;
}

function bool ProcessSelection()
{
	local Menu ChildMenu;

	if ( (Selection == 2) && bCanModifyGore )
		Level.Game.bLowGore = !Level.Game.bLowGore;
	else if ( Selection == 7 )
		DeathMatchGame(GameType).bCoopWeaponMode = !DeathMatchGame(GameType).bCoopWeaponMode;		
	else if ( Selection == 8 )
	{
		ChildMenu = spawn(class'ChallengeBotConfigMenu', owner);
		UnrealBotConfigMenu(ChildMenu).InitConfig(GameType);
	}
	else if ( Selection == 9 )
		DeathMatchPlus(GameType).bUseTranslocator = !DeathMatchPlus(GameType).bUseTranslocator;
	else if ( Selection == 10 )
		DeathMatchPlus(GameType).bJumpMatch = !DeathMatchPlus(GameType).bJumpMatch;
	else if ( Selection == 11 )
		DeathMatchPlus(GameType).bTournament = !DeathMatchPlus(GameType).bTournament;
	else if ( Selection == 13 )
		GameType.bClassicDeathmessages = !GameType.bClassicDeathmessages;
	else
		return false;

	if ( ChildMenu != None )
	{
		HUD(Owner).MainMenu = ChildMenu;
		ChildMenu.ParentMenu = self;
		ChildMenu.PlayerOwner = PlayerOwner;
	}
	return true;
}

function SaveConfigs()
{
	if ( GameType != None )
		GameType.SaveConfig();
	PlayerOwner.SaveConfig();
	//PlayerOwner.PlayerReplicationInfo.SaveConfig();
}

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

	for ( i=3; i<=MenuLength; i++ )
		MenuList[i] = Default.MenuList[i];

	MenuList[1] = Default.MenuList[1];
	if ( bCanModifyGore )
		MenuList[2] = Default.MenuList[2];
	else
		MenuList[2] = "";

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

function DrawValues(canvas Canvas, int StartX, int StartY, int Spacing)
{
	local int s;
	local DeathMatchPlus DMGame;

	DMGame = DeathMatchPlus(GameType);

	// draw text
	MenuList[3] = string(DMGame.FragLimit);
	if (TeamGamePlus(GameType) != None)
		MenuList[4] = string(int(TeamGamePlus(DMGame).GoalTeamScore));
	else
		MenuList[4] = "N/A";
	MenuList[5] = string(DMGame.TimeLimit);
	MenuList[6] = string(DMGame.MaxPlayers);
	MenuList[7] = string(DMGame.bCoopWeaponMode);
	MenuList[8] = "";
	MenuList[9] = string(DMGame.bUseTranslocator);
	MenuList[10] = string(DMGame.bJumpMatch);
	MenuList[11] = string(DMGame.bTournament);
	MenuList[12] = GameStyle[GameIndex];
	if ( DMGame.bClassicDeathmessages )
		MenuList[13] = "Classic";
	else
		MenuList[13] = "Weapon Based";

	s = 10 * (GameType.GameSpeed + 0.02);
	MenuList[1] = (""$(10 * s)$"%");
	if ( bCanModifyGore )
		MenuList[2] = string(GameType.bLowGore);
	else
		MenuList[2] = "";

	DrawList(Canvas, false, Spacing, StartX + 160, StartY);  
}

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

	DrawBackGround(Canvas, false);

	StartX = Max(40, 0.5 * Canvas.ClipX - 115);

	if ( (MenuLength < 6) || (Canvas.ClipY > 240) )
	{
		DrawTitle(Canvas);
		Spacing = Clamp(0.04 * Canvas.ClipY, 12, 32);
		StartY = Max(40, 0.5 * (Canvas.ClipY - MenuLength * Spacing - 128));
	}
	else
	{
		Spacing = Clamp(0.04 * Canvas.ClipY, 10, 32);
		StartY = Max(4, 0.5 * (Canvas.ClipY - MenuLength * Spacing - 128));
	}
	DrawOptions(Canvas, StartX, StartY, Spacing);
	DrawValues(Canvas, StartX, StartY, Spacing);		
	DrawHelpPanel(Canvas, StartY + MenuLength * Spacing + 4, 228);
}

defaultproperties
{
     AdvancedString="Advanced Options"
     AdvancedHelp="Edit advanced game configuration options."
     bCanModifyGore=True
     GameClass=Class'BotPack.DeathMatchPlus'
     MenuLength=13
     HelpMessage(1)="Adjust the speed at which time passes in the game."
     HelpMessage(2)="If true, reduces the gore in the game."
     HelpMessage(3)="Number of frags scored by leading player to end game.  If 0, there is no limit."
	 HelpMessage(4)="Number of frags scored by a team to end game.  If 0, there is no limit."
     HelpMessage(5)="Time limit (in minutes) to end game.  If 0, there is no limit."
     HelpMessage(6)="Maximum number of players allowed in the game."
     HelpMessage(7)="If Weapons Stay is enabled, weapons respawn instantly, but can only be picked up once by a given player."
     HelpMessage(8)="Configure bot game and individual parameters."
     HelpMessage(9)="Everyone gets a translocator."
     HelpMessage(10)="Use bots when playing with other people."
     HelpMessage(11)="If enabled, you must set MaxPlayers to actual number of players."
     HelpMessage(12)="Novice: Bots are slower and less damaging. Hardcore: Game speed is faster and weapons do more damage than normal. Turbo: Hardcore with really fast movement."
	 HelpMessage(13)="Classic or new style (weapon based) deathmessages."
     MenuList(1)="Game Speed"
     MenuList(2)="Reduced Gore"
     MenuList(3)="Frag Limit"
	 MenuList(4)="Team Score Limit"
     MenuList(5)="Time Limit"
     MenuList(6)="Max Players"
     MenuList(7)="Weapons Stay"
     MenuList(8)="Configure Bots"
     MenuList(9)="Use Translocator"
     MenuList(10)="JumpMatch"
     MenuList(11)="Tournament Mode"
     MenuList(12)="Game Style"
	 MenuList(13)="DeathMessages"
     MenuTitle="GAME OPTIONS"
	 GameStyle(0)="Novice"
	 GameStyle(1)="Normal"
	 GameStyle(2)="Hardcore"
	 GameStyle(3)="Turbo"
}
