//
// Tools_EffectVolume_FSFXOverlay.cpp
//
// Created by Emil Popovic - 12/1/2009
// 
// Copyright (C) 2008 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_FSFX

//////////////////////////////////////////////////////////////////////////////
//
// includes
//
//////////////////////////////////////////////////////////////////////////////

// core
#include "Core/Asura.h"

// header
#include "Entity/EffectVolume/Tools_EffectVolume_FSFXOverlay.h"

// asura
#include "Core/Asura_UserInput.h"

// tools
#include "Tools_System.h"
#include "FSFX/Tools_FSFX_DropDownList_Dialog.h"





Asura_Hash_ID	Tools_EffectVolume_FSFXOverlay::s_uFSFXHash;
float			Tools_EffectVolume_FSFXOverlay::s_fFSFXIntensity;
bool			Tools_EffectVolume_FSFXOverlay::s_bFSFXChanged;


Tools_EffectVolume_FSFXOverlay::Tools_EffectVolume_FSFXOverlay( Asura_EffectVolume_Effect_FSFX* pxFsfx )
:Tools_Modal_Overlay("Modify FSFX Values")
, m_bReturnValue( false )
, m_pxCurrentFsfx( pxFsfx )
{
	s_bFSFXChanged   = false;
	s_uFSFXHash		 = m_pxCurrentFsfx->GetParameters().GetTemplateHash();
	s_fFSFXIntensity = m_pxCurrentFsfx->GetParameters().GetStrength();
}

Tools_EffectVolume_FSFXOverlay::~Tools_EffectVolume_FSFXOverlay()
{
}

void Tools_EffectVolume_FSFXOverlay::InitialiseOverlay(class Asura_Overlay* pxOverlay)
{
	Asura_Dialog* pxDialog = NULL;

	Asura_Vector_2 xOffset = Asura_Vector_2(1.0f,3.0f);


	xOffset.y += Asura_Dialog::LargeSpacing() - Asura_Dialog::DefaultSpacing();
	pxDialog = new Tools_FSFX_DropDownList_Dialog(xOffset,8,&s_uFSFXHash,&s_bFSFXChanged,"FSFX");
	//	pxDialog->SetIsEnabledFunction(IsFSFXControlEnabled);
	pxDialog->SetHelpText("Sets the current FSFX template to be used");
	pxOverlay->AddDialog(pxDialog);

	xOffset.x = pxDialog->m_xMaxCoord.x + 1.0f;
	pxDialog = new Asura_Numerical_Dialog("Intensity",xOffset, &s_fFSFXIntensity, 0.0f, 1.0f, 0.05f, "%.2f",&s_bFSFXChanged);
	//	pxDialog->SetIsEnabledFunction(IsFSFXControlEnabled);
	pxDialog->SetHelpText("Sets the intensity of the FSFX effect");
	pxOverlay->AddDialog(pxDialog);
	xOffset.x = 1.0f;
	xOffset.y += Asura_Dialog::LargeSpacing();




	// OK and CANCEL button.
	pxDialog= new Asura_Function_Dialog( "Okay", xOffset, OkayPressed, reinterpret_cast< int >( this ), &pxOverlay->m_bShouldClose );
	pxOverlay->AddDialog( pxDialog );
	xOffset.x += 7.0f;

	pxDialog= new Asura_Function_Dialog( "Cancel", xOffset, CancelPressed, reinterpret_cast< int >( this ), &pxOverlay->m_bShouldClose );
	pxOverlay->AddDialog( pxDialog );
}

void Tools_EffectVolume_FSFXOverlay::Update()
{
	// Preview current effect
	Asura_FSFX_Template* const pxTemplate = Asura_FSFX_System::FindTemplate(s_uFSFXHash);

	if( pxTemplate )
	{
		Tools_FSFX_System::SetOverrideFSFX(pxTemplate, s_fFSFXIntensity );
		Tools_FSFX_System::ResetHandler();
	}

	//allow escape to be used for cancel
	if(Asura_UserInput::DebouncedKeyPressed(ASURA_KEYID_ESCAPE))
	{
		GetOverlay()->m_bShouldClose = true;			
		Tools_System::CancelModeChange();
	}

	PARENT::Update();
}

bool Tools_EffectVolume_FSFXOverlay::DoModal()
{
	m_bReturnValue = false;
	ShowOverlay();
	return m_bReturnValue;
}

void Tools_EffectVolume_FSFXOverlay::OkayPressed( int iUserData )
{
	Tools_EffectVolume_FSFXOverlay* pxThis = reinterpret_cast< Tools_EffectVolume_FSFXOverlay* >( iUserData );
	pxThis->m_bReturnValue = true;

	pxThis->m_pxCurrentFsfx->GetParameters().SetTemplateHash( s_uFSFXHash );
	pxThis->m_pxCurrentFsfx->GetParameters().SetStrength( s_fFSFXIntensity );
}

void Tools_EffectVolume_FSFXOverlay::CancelPressed( int iUserData )
{
	Tools_EffectVolume_FSFXOverlay* pxThis = reinterpret_cast< Tools_EffectVolume_FSFXOverlay* >( iUserData );
	pxThis->m_bReturnValue = false;
}



#endif //ASURA_USE_FSFX




