// Game Options Handler.
// Worthless Bums 2012.


function initializeGameOptions ()
{//echo("initializeGameOptions()");
	AutoEndTurnsToggle.setValue($Game::AutoEndTurns);
	AutoSwitchCharactersToggle.setValue($Game::AutoSwitchCharacters);
	AutoEndTurnSwitchCharactersToggle.setValue($Game::AutoEndTurnSwitchCharacters);
	FadingFogOfWarToggle.setValue($Game::FadingFogOfWarToggle);
	EnemyCameraLockToggle.setValue($Game::EnemyCameraLock);
	AutoLootToggle.setValue($Game::AutoLoot);
	FacingCostsAPToggle.setValue($Game::FacingCostsAP);
	AutoFacingToggle.setValue($Game::AutoFacing);
	AutoLockToggle.setValue($Game::AutoLock);
	AlwaysShowCursorToggle.setValue($Game::AlwaysShowCursor);
	AlwaysShowMoveIndicatorToggle.setValue($Game::AlwaysShowMoveIndicator);
	//LargeFontToggle.setValue($Game::LargeFont);
}
function updateGameplayOptions ()
{//echo("updateGameplayOptions()");
	// Update camera track speed.
	$Game::CameraTrackSpeed = 4;
	CameraTrackSpeed.setValue($Game::CameraTrackSpeed);
	updateCameraTrackSpeed(CameraTrackSpeed.value);
	
	// Update monster turn speed.
	$Game::MonsterTurnSpeed = MonsterTurnSpeed.value;
	$monsterStepDelay = getScaledMonsterStepDelay();	// Not option editable since monster turn changes!
	
	// Update auto-end turn toggle.
	$Game::AutoEndTurns = 1;
	$autoEndTurns = $Game::AutoEndTurns;
	AutoEndTurnsToggle.setValue($Game::AutoEndTurns);
	
	// Update auto-switch squad members.
	$Game::AutoSwitchCharacters = 1;
	$autoSwitchCharacters = $Game::AutoSwitchCharacters;
	AutoSwitchCharactersToggle.setValue($Game::AutoSwitchCharacters);
	
	// Update auto-switch squad members at the end of turns.
	$Game::AutoEndTurnSwitchCharacters = 1;
	$autoEndTurnSwitchCharacters = $Game::AutoEndTurnSwitchCharacters;
	AutoEndTurnSwitchCharactersToggle.setValue($Game::AutoEndTurnSwitchCharacters);
	
	// Update fading fog of war.
	$Game::FadingFogOfWarToggle = 0;
	$FadingFogOfWarToggle = $Game::FadingFogOfWarToggle;
	FadingFogOfWarToggle.setValue($Game::FadingFogOfWarToggle);
	
	// Update enemy camera lock.
	$Game::EnemyCameraLock = 1;
	$EnemyCameraLockToggle = $Game::EnemyCameraLock;
	EnemyCameraLockToggle.setValue($Game::EnemyCameraLock);
	
	// Update Auto Loot.
	$Game::AutoLoot = 1;
	$AutoLootToggle = $Game::AutoLoot;
	AutoLootToggle.setValue($Game::AutoLoot);
	
	// Update Facing Costs AP.
	$Game::FacingCostsAP = 1;
	$FacingCostsAP = $Game::FacingCostsAP;
	FacingCostsAPToggle.setValue($Game::FacingCostsAP);
	
	// Update Auto Facing.
	$Game::AutoFacing = 1;
	$AutoFacing = $Game::AutoFacing;
	AutoFacingToggle.setValue($Game::AutoFacing);
	
	// Update Auto Lock.
	$Game::AutoLock = 0;
	$AutoLock = $Game::AutoLock;
	AutoLockToggle.setValue($Game::AutoLock);	// BUG: Need to remount camera if the player sets this to false while auto-targeting a monster!
	
	// Update Always Show Cursor.
	$Game::AlwaysShowCursor = 0;
	$AlwaysShowCursor = $Game::AlwaysShowCursor;
	AlwaysShowCursorToggle.setValue($Game::AlwaysShowCursor);
	
	// Update Show Move Indicator.
	$Game::AlwaysShowMoveIndicator = 0;
	$AlwaysShowMoveIndicator = $Game::AlwaysShowMoveIndicator;
	AlwaysShowMoveIndicatorToggle.setValue($Game::AlwaysShowMoveIndicator);
	
	// Updated AI Delay.
	$Game::MonsterTurnSpeed = 4;
	$monsterStepDelay = getScaledMonsterStepDelay();
	MonsterTurnSpeed.setValue($Game::MonsterTurnSpeed);
	
	// Update game font size.
	//$Game::LargeFont = LargeFontToggle.getValue();
	//$largeFont = $Game::LargeFont;
	
	// Pop Options Dialog.
	//Canvas.popDialog(OptionsDlg);
	// Push Options Dialog.
	//Canvas.pushDialog(OptionsDlg);
}

// Updates game option settings.
function updateGameOptions ()
{//echo("updateGameOptions()");
	// Update camera track speed.
	updateCameraTrackSpeed(CameraTrackSpeed.value);
	
	// Update monster turn speed.
	$Game::MonsterTurnSpeed = MonsterTurnSpeed.value;
	$monsterStepDelay = getScaledMonsterStepDelay();	// Not option editable since monster turn changes!
	
	// Update auto-end turn toggle.
	$Game::AutoEndTurns = AutoEndTurnsToggle.getValue();
	$autoEndTurns = $Game::AutoEndTurns;
	
	// Update auto-switch squad members.
	$Game::AutoSwitchCharacters = AutoSwitchCharactersToggle.getValue();
	$autoSwitchCharacters = $Game::AutoSwitchCharacters;
	
	// Update auto-switch squad members at the end of turns.
	$Game::AutoEndTurnSwitchCharacters = AutoEndTurnSwitchCharactersToggle.getValue();
	$autoEndTurnSwitchCharacters = $Game::AutoEndTurnSwitchCharacters;
	
	// Update fading fog of war.
	$Game::FadingFogOfWarToggle = FadingFogOfWarToggle.getValue();
	$FadingFogOfWarToggle = $Game::FadingFogOfWarToggle;
	
	// Update fading fog of war.
	$Game::EnemyCameraLock = EnemyCameraLockToggle.getValue();
	$EnemyCameraLock = $Game::EnemyCameraLock;
	
	// Update Auto Loot.
	$Game::AutoLoot = AutoLootToggle.getValue();
	$AutoLoot = $Game::AutoLoot;
	
	// Update Facing Costs AP.
	$Game::FacingCostsAP = FacingCostsAPToggle.getValue();
	$FacingCostsAP = $Game::FacingCostsAP;
	
	// Update Auto Facing.
	$Game::AutoFacing = AutoFacingToggle.getValue();
	$AutoFacing = $Game::AutoFacing;
	
	// Update Auto Lock.
	$Game::AutoLock = AutoLockToggle.getValue();
	$AutoLock = $Game::AutoLock;
	
	// Update Auto Lock.
	$Game::AlwaysShowCursor = AlwaysShowCursorToggle.getValue();
	$AlwaysShowCursor = $Game::AlwaysShowCursor;
	
	// Update Auto Lock.
	$Game::AlwaysShowMoveIndicator = AlwaysShowMoveIndicatorToggle.getValue();
	$AlwaysShowMoveIndicator = $Game::AlwaysShowMoveIndicator;
	
	// Updated AI Delay.
	$Game::MonsterTurnSpeed = MonsterTurnSpeed.getValue();
	$monsterStepDelay = getScaledMonsterStepDelay();
	
	// Update game font size.
	$Game::LargeFont = LargeFontToggle.getValue();
	$largeFont = $Game::LargeFont;
	// Set font size.
	/*if ($largeFont)
	{
		InventoryTabTextProfile.fontSize = $largeFontSize;
		ScrollableEventsProfile.fontSize = $largeFontSize;
	}
	else
	{
		InventoryTabTextProfile.fontSize = $smallFontSize;
		ScrollableEventsProfile.fontSize = $smallFontSize;
	}*/
	// Reset Inventory Tab and Scrolling Event Log text to apply new font size.
	inventoryTabMainPanelReadout.setText(inventoryTabMainPanelReadout.getText());
	drawTextLog();
	
	// Pop Options Dialog.
	Canvas.popDialog(OptionsDlg);
}
function getScaledMonsterStepDelay ()
{//echo("getScaledMonsterStepDelay()");
	%monsterStepDelay = 1250;
	switch ($Game::MonsterTurnSpeed)
	{
		case 1: 	%monsterStepDelay = 500;
		case 2: 	%monsterStepDelay = 750;
		case 3: 	%monsterStepDelay = 1000;
		case 4: 	%monsterStepDelay = 1250;
		case 5: 	%monsterStepDelay = 1500;
		case 7: 	%monsterStepDelay = 1750;
		case 8:		%monsterStepDelay = 2000;
		case 9:		%monsterStepDelay = 2250;
		case 10:	%monsterStepDelay = 2500;
	}
	return %monsterStepDelay;
}