/**
*
* \file Tools_Level_Export_UI.cpp
*
* Created by Kevin Lea - 29/11/2002 11:23:31
* Splitted into separate file 12/11/2008
*
* Copyright (C) 2002 Rebellion, All Rights Reserved.
*
* \brief
*
**/
#include "Core/Asura.h"
#include "Load&Save/LevelExport/Tools_Level_Export.h"

// Asura
#include "Core/Asura_LocalisedText.h"
#include "Interface/Asura_Overlay.h"
#include "Interface/Asura_Overlay_System.h"

// Tools
#include "Lighting/Tools_LightSets.h"
#include "Load&Save/Tools_SaveAsura.h"
#include "Tools_Overlays.h"

// G L O B A L S ////////////////////////////////////////
extern bool g_bAskAboutInvalidLighting;

void Tools_Level_Export::CreateOverlay()
{
	Asura_Assert(This,"");
    // Don't allow character export and level export dialogs to co-exist.
	if(Asura_Overlay_System::DoesOverlayExist(TOOLS_OVERLAY_LEVELEXPORT)) return;
    if( Asura_Overlay_System::DoesOverlayExist(TOOLS_OVERLAY_CHAREXPORT) ) { return; }

	Asura_Overlay* pxOverlay;
	pxOverlay = new Asura_Overlay("Export Level",false);
	
	Asura_Dialog* pxDialog;
	Asura_Vector_2 xOffset = Asura_Vector_2(1.0f,3.0f);

	bool bAddedProjectOverlayControls = false;

	//Set up Tabs

	Asura_Tabs_Dialog* pxTabsDialog = new Asura_Tabs_Dialog(xOffset,0,0);
	pxOverlay->AddDialog(pxTabsDialog);
	xOffset.y += Asura_Dialog::LargeSpacing();
	pxOverlay->SetCurrentParentDialog(pxTabsDialog);

	float fTabsStartY = xOffset.y;
	float fTabsEndY = xOffset.y;

	
	//Main tab
	//Contains the main level export buttons.
	//If the default ones aren't being used for a project , then shove in
	//whatever project specific controls there are instead

	pxTabsDialog->AddTab("Main");

	if (This->ShowAllExportOptions())
	{
		//AddPlatformExportDialogs(pxOverlay, xOffset, ExportLevel);
		AddPlatformExportTickboxes(pxOverlay, xOffset);

		#ifndef TOOLS_DISABLE_SEPARATE_MISSION_EXPORT
		if(Tools_SaveAsura::IsEditingMission())
		{
			pxDialog = new Asura_Tickbox_Dialog("Environment", xOffset, &s_bMission_ShouldExportEnvironment);
			pxDialog->SetHelpText("Export the file containing the environment mesh that is shared between the mission");
			pxOverlay->AddDialog(pxDialog);
			xOffset.y+=Asura_Dialog::DefaultSpacing();

			pxDialog = new Asura_Tickbox_Dialog("Mission", xOffset, &s_bMission_ShouldExportMission);
			pxDialog->SetHelpText("Export the file containing data specific to this mission");
			pxOverlay->AddDialog(pxDialog);
			xOffset.y+=Asura_Dialog::LargeSpacing();
		}
		#endif
	}
	else
	{
		This->AddOverlayControls(pxOverlay,xOffset);
		bAddedProjectOverlayControls = true;
	}

	pxDialog = new Asura_Tickbox_Dialog("Quick Export (Update old file)",xOffset,&s_bUpdateExistingFile);
	pxDialog->SetIsEnabledFunction(IsEnabled_ExportLevel);
	pxDialog->SetHelpText("Updates the lighting , placed sound , navigation , module linking , skybox , cutsene and entity files in a previously exported level.\n Any skins , animations , textures , sounds , and meshes will be left alone.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();


	if(xOffset.y > fTabsEndY) fTabsEndY = xOffset.y;

	//Advanced Tab... contains all the other options
	pxTabsDialog->AddTab("Advanced");
	xOffset.y = fTabsStartY;

	AddAdvanceOptionsOverlayControls(pxOverlay,xOffset);

	if(xOffset.y > fTabsEndY) fTabsEndY = xOffset.y;

	//Language tab
	pxTabsDialog->AddTab("Language");
	xOffset.y = fTabsStartY;
	
	AddLanguageOverlayControls(pxOverlay,xOffset);

	//end of language tab
	if(xOffset.y > fTabsEndY) fTabsEndY = xOffset.y;
	
	//Light sets tab
	if(Tools_LightSets::IsUsingLightSets())
	{
		pxTabsDialog->AddTab("Light Sets");
		xOffset.y = fTabsStartY;

		//add a tickbox for each light set
		for(u_int i=0;i<TOOLS_MAX_LIGHT_SETS;i++)
		{
			if(!Tools_LightSets::IsUsedLightSetIndex(i)) continue;
			const char* szSetName = Tools_LightSets::GetLightSetNameByIndex(i);
			if(!szSetName) continue;

			if(!Tools_LightSets::ShouldIncludeLightSetIndexInExportUI(i)) continue;

			pxDialog = new Asura_FlagTickbox_Dialog(szSetName,xOffset,&s_uLightSetsToExport,1<<i);
			pxDialog->SetHelpText("Determines whether an export will be done for this light set.");
			pxOverlay->AddDialog(pxDialog);
			xOffset.y+=Asura_Dialog::DefaultSpacing();
		}
		xOffset.y += Asura_Dialog::LargeSpacing()-Asura_Dialog::DefaultSpacing();
	
		//and a couple of buttons for enabling/disabling all of them
		pxDialog = new Asura_Function_Dialog("All",xOffset,EnableAllLightSetsForExport);
		pxDialog->SetHelpText("Ticks all the light sets");
		pxOverlay->AddDialog(pxDialog);
		xOffset.y+=Asura_Dialog::DefaultSpacing();

		pxDialog = new Asura_Function_Dialog("None",xOffset,DisableAllLightSetsForExport);
		pxDialog->SetHelpText("Unticks all the light sets");
		pxOverlay->AddDialog(pxDialog);
		xOffset.y+=Asura_Dialog::DefaultSpacing();



		//end of light sets tab
		if(xOffset.y > fTabsEndY) fTabsEndY = xOffset.y;
	}

	
	//End of tabs
	xOffset.y = fTabsEndY + 1.0f;
	pxOverlay->SetCurrentParentDialog(0);
	pxTabsDialog->SelectTab(0);


	//Add project specific controls here , if they weren't already put in the main tab
	if(!bAddedProjectOverlayControls)
	{
		This->AddOverlayControls(pxOverlay,xOffset);
	}

	if (This->ShowAllExportOptions())
	{
		xOffset.y += Asura_Dialog::LargeSpacing()-Asura_Dialog::DefaultSpacing();

		//add the main export level option
		pxDialog = new Asura_Function_Dialog("Export Level",xOffset,ExportLevelForEachPlatform,&pxOverlay->m_bShouldClose);
		pxDialog->SetIsEnabledFunction(IsEnabled_ExportLevel);
		pxDialog->SetHelpText("Starts the level export with the selected options");
		pxOverlay->AddDialog(pxDialog);
		xOffset.y+=Asura_Dialog::DefaultSpacing();
	}


	pxOverlay->m_uID = TOOLS_OVERLAY_LEVELEXPORT;

	Asura_Overlay_System::SubmitNewOverlay(pxOverlay);

}

void Tools_Level_Export::CreateAnimationOverlay()
{
	Asura_Assert(This,"");

    // Don't allow character export and level export dialogs to co-exist.
	if(Asura_Overlay_System::DoesOverlayExist(TOOLS_OVERLAY_LEVELEXPORT)) return;
    if( Asura_Overlay_System::DoesOverlayExist(TOOLS_OVERLAY_CHAREXPORT) ) { return; }

	Asura_Overlay*	pxOverlay	= new Asura_Overlay("Export Character Files",false);
	Asura_Vector_2	xOffset(1.0f,3.0f);
	
	This->AddCharacterExportOverlayControls(pxOverlay, xOffset);

	Asura_Overlay_System::SubmitNewOverlay(pxOverlay);
}


void Tools_Level_Export::AddAdvanceOptionsOverlayControls(class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset)
{
	Asura_Dialog* pxDialog;

	//	pxDialog = new Tools_LightSet_Dialog(xOffset,&s_uLightSetToExport,0,"Light Set");
	//	pxDialog->SetHelpText("The lighting to be used for this level export.");
	//	pxOverlay->AddDialog(pxDialog);
	//	xOffset.y+=Asura_Dialog::DefaultSpacing();


	pxDialog = new Asura_Tickbox_Dialog("Subdivide Meshes (PS2)",xOffset,&s_bSubdivideMeshes);
	pxDialog->SetHelpText("Subdivide environment meshes before exporting.\nPC ignores this and subdivides regardless.\nPSP never subdivides.\n");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Numerical_Dialog("Subdivide Size (Flat)",xOffset,&s_fFlatSubdivideSize,0,100,0.01f,"%.2f");
	pxDialog->SetHelpText("Size on screen (in not very meaningful units) at which a flat polygon should be subdivided.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Numerical_Dialog("Subdivide Size (Curved)",xOffset,&s_fCurveSubdivideSize,0,100,0.01f,"%.2f");
	pxDialog->SetHelpText("Size on screen (in not very meaningful units) at which a curved polygon should be subdivided.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog("Prelight Subdivided Meshes",xOffset,&s_bRecalculatePrelighting);
	pxDialog->SetHelpText("Recalculates lighting on subdivided mesh , instead of using interpolated values.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog("Swizzle Tims (PS2)",xOffset,&s_bSwizzleTims);
	pxDialog->SetHelpText("Causes the Tim2 files to be exported in a format that is better for the PS2.\nHowever the files won't be properly viewable in the Tim2 viewer.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog("Don't Include Cutscene Files",xOffset,&s_bDontExportCutscenes);
	pxDialog->SetHelpText("Prevents skins and animations for cutscenes being included in the export.\nSome cutscenes may be flagged to ignore this however.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();


	pxDialog = new Asura_Tickbox_Dialog( "Multiplayer export (PS2)", xOffset, &s_bPS2MultiplayerExport );
	pxDialog->SetHelpText("Exports level for splitscreen , using lower resolution textures.");
	pxOverlay->AddDialog( pxDialog );
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog( "Include dual texturing data in export", xOffset, &s_bIncludeDualTexturingData );
	//  pxDialog->SetHelpText( "" );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog( "Full Bright", xOffset, &s_bFullBrightPrelighting );
	pxDialog->SetHelpText( "Ignores the prelighting and makes all modules full bright instead." );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog( "Exclude Entities By Type", xOffset, &s_bFilterEntityExport );
	pxDialog->SetHelpText( "This allows entities to be excluded from export based on their type.\nIf enabled then a dialog will be shown to select the types to be affected." );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog( "Debug colour sub-strips (PSP)", xOffset, &s_bDebugColourSubstrips );
	pxDialog->SetHelpText( "Randomly colours sub-strips on PSP, so you can see where potentially wasteful numbers of degenerates triangles are occurring." );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog( "Force Texture Generation (VERY SLOW)", xOffset, &s_bForceTextureGeneration );
	pxDialog->SetHelpText( "Force all textures in this export to be re-generated before being used." );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog("Use new NVidia texture gen (CUDA if hardware supported)", xOffset, &s_bUseNewNVidiaExport);
	pxDialog->SetHelpText("");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y += Asura_Dialog::DefaultSpacing();

	xOffset.y += 0.5f;
	pxDialog = new Asura_Tickbox_Dialog("Override Animation Frame Removal",xOffset,&s_bOverrideFrameRemovalSettings);
	pxDialog->SetHelpText("Override default settings for animation keyframe removal.");
	pxOverlay->AddDialog(pxDialog);
	pxDialog->SetEnabled(false);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Numerical_Dialog("Position Tolerance. (m)",xOffset,&s_fAnimPositionTolerance,0,1.0f,0.0001f,"%.4f");
	pxDialog->SetHelpText("Tolerance level in metres when considering whether a 'middle' frame is close enough to interpolated value so that it can be removed.");
	pxDialog->m_iControlID = DialogID_PositionTolerance;
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Numerical_Dialog("Angle Tolerance. (deg)",xOffset,&s_fAnimAngleTolerance,0,180.0f,0.01f,"%.2f");
	pxDialog->SetHelpText("Tolerance level in degrees when considering whether a 'middle' frame is close enough to interpolated value so that it can be removed.");
	pxDialog->m_iControlID = DialogID_AngleTolerance;
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::LargeSpacing();

	pxDialog = new Asura_Numerical_Dialog("Minimum texture resolution (GC)",xOffset,&s_fMinGCTexRes,64,1024,64, "%4.0f");
	pxDialog->SetHelpText("This appears to be the maximum texture size for GC/Wii textures.\nAny textures larger than this will be halved until small enough.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Numerical_Dialog("Maximum mipmap drops (GC/PSP)",xOffset,&s_fMaxMipDrops,0,6,1, "%1.0f");
	pxDialog->SetHelpText("For GC/Wii this appears to be the maximum number of times the above halving process will be done.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::LargeSpacing();

	pxDialog = new Asura_Tickbox_Dialog("",xOffset,&s_bUseMaximumTextureSize);
	pxDialog->SetHelpText("Determines whether the maximum texture size setting should be used.\n");
	pxOverlay->AddDialog(pxDialog);

	xOffset.x += 3.0f;
	pxDialog = new Asura_Numerical_Dialog("Maximum texture size",xOffset,&s_uMaximumTextureSize,64,4096,1, "%d");
	pxDialog->SetIsEnabledFunction(IsEnabled_MaximumTextureSize);
	pxDialog->SetHelpText("For temporarily clamping texture sizes.\nTextures will be halved in size until their width and height is smaller than this value.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.x = 1.0f;
	xOffset.y+=Asura_Dialog::DefaultSpacing();
}

void Tools_Level_Export::AddLanguageOverlayControls(Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset)
{
	Asura_Assert(This,"Tools_Level_Export not initialised");

	Asura_Dialog* pxDialog;
	//add a tickbox for each allowable language
	for(int i=0;i<ASURA_LT_L_NUM_LANGUAGES; i++)
	{
		if(This->IsLanguageAllowed(i))
		{
			const char* szName = Asura_LocalisedText::GetNameForLang((Asura_LocalisedText_Language)i);

			pxDialog = new Asura_Tickbox_Dialog(szName, xOffset, &s_abExportLanguage[i]);
			pxDialog->SetHelpText("Determines if a localised file will be created for this language (if required by dialogue events).");
			pxOverlay->AddDialog(pxDialog);
			xOffset.y+=Asura_Dialog::DefaultSpacing();
		}
	}
	xOffset.y += Asura_Dialog::LargeSpacing()-Asura_Dialog::DefaultSpacing();

	//and a couple of buttons for enabling/disabling all of them
	pxDialog = new Asura_Function_Dialog("All",xOffset,EnableAllLanguagesForExport);
	pxDialog->SetHelpText("Ticks all the languages");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Function_Dialog("None",xOffset,DisableAllLanguagesForExport);
	pxDialog->SetHelpText("Unticks all the languages");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();
	
}

void Tools_Level_Export::AddPlatformExportDialogs(Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset, void(*pfnCallback)(int))
{
	Asura_Dialog*	pxDialog;
	char			szText[100];

	xOffset.y	+= Asura_Dialog::DefaultSpacing();
	pxDialog	 = new Asura_Divider_Dialog (xOffset);
	xOffset.y	+= Asura_Dialog::DefaultSpacing();
	pxOverlay->AddDialog(pxDialog);

	//character export buttons for each platform
	for(int i=0;i<ExportType_NumPlatforms;i++)
	{
		Asura_PrintfToBfr(szText,"%s Export",sizeof(szText),true,GetPlatformName(i));

		pxDialog = new Asura_Function_Dialog(szText,xOffset,pfnCallback,i,&pxOverlay->m_bShouldClose);
		pxDialog->SetEnabled(This->IsPlatformAllowed((EXPORT_TYPE)i));
		pxOverlay->AddDialog(pxDialog);
		xOffset.y+=Asura_Dialog::LargeSpacing();
	}

	pxDialog	 = new Asura_Divider_Dialog (xOffset);
	pxOverlay->AddDialog(pxDialog);
	xOffset.y	+= Asura_Dialog::DefaultSpacing();
}

void Tools_Level_Export::AddPlatformExportTickboxes(Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset)
{
	Asura_Dialog*	pxDialog;
	char			szText[100];

//	xOffset.y	+= Asura_Dialog::DefaultSpacing();
//	pxDialog	 = new Asura_Divider_Dialog (xOffset);
//	xOffset.y	+= Asura_Dialog::DefaultSpacing();
//	pxOverlay->AddDialog(pxDialog);


	//tickbox for each allowed platform
	for(int i=0;i<ExportType_NumPlatforms;i++)
	{
		Asura_PrintfToBfr(szText,"%s Export",sizeof(szText),true,GetPlatformName(i));

		if(This->IsPlatformAllowed((EXPORT_TYPE)i))
		{
			pxDialog = new Asura_FlagTickbox_Dialog(GetPlatformName(i),xOffset,&s_uPlatformsToExport,1<<i);
			pxDialog->SetHelpText("Determines whether an export should be done for this platform");
			pxOverlay->AddDialog(pxDialog);
			xOffset.y+=Asura_Dialog::DefaultSpacing();
		}
	}

	xOffset.y += Asura_Dialog::LargeSpacing()-Asura_Dialog::DefaultSpacing();


	//and a couple of buttons for enabling/disabling all of them
	pxDialog = new Asura_Function_Dialog("All",xOffset,EnableAllPlatformsForExport);
	pxDialog->SetHelpText("Ticks all the platforms");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Function_Dialog("None",xOffset,DisableAllPlatformsForExport);
	pxDialog->SetHelpText("Unticks all the platforms");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::LargeSpacing();


//	pxDialog	 = new Asura_Divider_Dialog (xOffset);
//	pxOverlay->AddDialog(pxDialog);
//	xOffset.y	+= Asura_Dialog::DefaultSpacing();

	pxDialog	= new Asura_Divider_Dialog (xOffset);
	pxOverlay->AddDialog(pxDialog);
	xOffset.y	+= Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog( "Compression Disabled", xOffset, &s_bCompressionDisabled );
	pxDialog->SetIsEnabledFunction(IsEnabled_ExportLevel);
	pxDialog->SetHelpText( "Allows the export to be compressed (if appropriate for the project AND platform)." );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::LargeSpacing();
}

void Tools_Level_Export::AddCharacterExportOverlayControls(Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset)
{
	Asura_Dialog* pxDialog;

	//Set up Tabs
	static const char* s_aszTabs[2] = {"Main","Advanced"};

	Asura_Tabs_Dialog* pxTabsDialog = new Asura_Tabs_Dialog(xOffset,s_aszTabs,2);
	pxOverlay->AddDialog(pxTabsDialog);
	xOffset.y += Asura_Dialog::LargeSpacing();
	pxOverlay->SetCurrentParentDialog(pxTabsDialog);

	float fTabsStartY = xOffset.y;
	float fTabsEndY = xOffset.y;


	//Main tab
	//Contains the main level export buttons.
	pxTabsDialog->SelectTab(0);

	pxDialog = new Asura_Tickbox_Dialog( "Multiplayer export (PS2)", xOffset, &s_bPS2MultiplayerExport );
	pxDialog->SetHelpText("Exports with lower resolution textures for multiplayer splitscreen.");
	pxOverlay->AddDialog( pxDialog );
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Tickbox_Dialog( "Export All Characters", xOffset, &s_bExportAllCharacters );
	pxDialog->SetHelpText("Causes export to create all character files.\nIf not ticked then a single directory will be requested when the export starts.");
	pxOverlay->AddDialog( pxDialog );
	xOffset.y+=Asura_Dialog::LargeSpacing();


	AddPlatformExportDialogs(pxOverlay, xOffset, ExportCharacters);

	if(xOffset.y > fTabsEndY) fTabsEndY = xOffset.y;

	//Advanced Tab... contains all the other options
	pxTabsDialog->SelectTab(1);
	xOffset.y = fTabsStartY;

	pxDialog = new Asura_Tickbox_Dialog("Swizzle Tims (PS2)",xOffset,&s_bSwizzleTims);
	pxDialog->SetHelpText("Causes the Tim2 files to be exported in a format that is better for the PS2.\nHowever the files won't be properly viewable in the Tim2 viewer.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();


	pxDialog = new Asura_Tickbox_Dialog("Override Animation Frame Removal",xOffset,&s_bOverrideFrameRemovalSettings);
	pxDialog->SetHelpText("Override default settings for animation keyframe removal.");
	pxOverlay->AddDialog(pxDialog);
	pxDialog->SetEnabled(false);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Numerical_Dialog("Position Tolerance. (m)",xOffset,&s_fAnimPositionTolerance,0,1.0f,0.0001f,"%.4f");
	pxDialog->SetHelpText("Tolerance level in metres when considering whether a 'middle' frame is close enough to interpolated value so that it can be removed.");
	pxDialog->m_iControlID = DialogID_PositionTolerance;
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Numerical_Dialog("Angle Tolerance. (deg)",xOffset,&s_fAnimAngleTolerance,0,180.0f,0.01f,"%.2f");
	pxDialog->SetHelpText("Tolerance level in degrees when considering whether a 'middle' frame is close enough to interpolated value so that it can be removed.");
	pxDialog->m_iControlID = DialogID_AngleTolerance;
	pxOverlay->AddDialog(pxDialog);
	xOffset.y+=Asura_Dialog::LargeSpacing();

	if(xOffset.y > fTabsEndY) fTabsEndY = xOffset.y;

	//End of tabs
	xOffset.y = fTabsEndY + 1.0f;
	pxOverlay->SetCurrentParentDialog(0);
	pxTabsDialog->SelectTab(0);


	pxOverlay->m_uID = TOOLS_OVERLAY_CHAREXPORT;
}

void Tools_Level_Export::Update()
{
	//upadte overlay controls (if it exists)
	Asura_Overlay* pxOverlay = Asura_Overlay_System::GetOverlay(TOOLS_OVERLAY_LEVELEXPORT);
	if(!pxOverlay) pxOverlay = Asura_Overlay_System::GetOverlay(TOOLS_OVERLAY_CHAREXPORT);
	if(pxOverlay)
	{
		Asura_Dialog* pxDialog;

		//pxDialog = pxOverlay->GetDialog(DialogID_CreateSeperateCutsceneSkinFiles);
		//if(pxDialog)
		//{
		//	pxDialog->SetEnabled(!s_bDontExportCutscenes);
		//}

		// KJL - 26/04/2003 17:16:38 - now I've come up with some reasonable values for this I'm 
		// going to disable the changing of the tolerances. This may want to be a project specific
		// thing, so for now I'll grey things out rather than deleting them from the menus
		s_bOverrideFrameRemovalSettings = false;

		//Enable/Disable tolerance settings depending on whether frame removal is enabled
		pxDialog = pxOverlay->GetDialog(DialogID_PositionTolerance);
		if(pxDialog) pxDialog->SetEnabled(s_bOverrideFrameRemovalSettings);

		pxDialog = pxOverlay->GetDialog(DialogID_AngleTolerance);
		if(pxDialog) pxDialog->SetEnabled(s_bOverrideFrameRemovalSettings);


		// KJL - 26/04/2003 17:04:44 - if frame removal is off, set to sensible defaults
		if (!s_bOverrideFrameRemovalSettings)
		{
			s_fAnimPositionTolerance = TOOLS_DEFAULT_ANIM_POSITION_TOLERANCE;
			s_fAnimAngleTolerance = TOOLS_DEFAULT_ANIM_ANGLE_TOLERANCE;
		}
	}

	//The result of the Yes/No/All overlay for accepting invalid lighting only lasts for one batch of exports , 
	//so ask again next time an export is done , since a new frame in the main loop has been done
	//RAR 07/01/2008
	g_bAskAboutInvalidLighting = true;
}
/// End of file. ///
