// Tools_Overlay_DynamicMusic.h
// Thomas Young - 13.08.08
// Copyright (C) 2008 Rebellion, All Rights Reserved.

// F I L E   W R A P P E R ///////////////////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __TOOLS_OVERLAY_DYNAMICMUSIC_H__
#define __TOOLS_OVERLAY_DYNAMICMUSIC_H__

#ifdef ASURA_SUPPORT_DYNAMIC_MUSIC_SYSTEM

// I N C L U D E S ///////////////////////////////////////////////////////////

#include "Core/Asura_Handle.h"
#include "Core/Asura_HeapArray.h"
#include "Sound/Asura_Dynamic_Music_System.h"
#include "Interface/Asura_Channel_Graph_Dialog.h"
#include "Interface/Asura_Dialog.h"

// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////

class Asura_StringTree;
class Asura_Dynamic_Music_TrackData;
class Asura_WAVAlign_Dialog;

// C L A S S   D E C L A R A T I O N S //////////////////////////////////////

class Tools_Overlay_DynamicMusic
{
	public:
		friend class Tools_Entity_DynamicMusicTrigger_Object;

		Tools_Overlay_DynamicMusic		( );
		~Tools_Overlay_DynamicMusic		( );

		static void Initialise			( );
		static void Shutdown			( );
		static void Update				( );

		static void ToggleOverlay		( );
		static void OpenOverlay			( );
		static void CloseOverlay		( );
		static bool IsOverlayOpen		( );
		static bool OverlayShouldBeOpen ( )		{ return s_bOverlayShouldBeOpen; }

		static bool IsModified			( );
		
		static void TriggersHaveChanged	( );

	private:
	
		enum Overlays
		{
			DM_OVERLAY_MAIN			= 0	,
			DM_OVERLAY_TRACK_LIST	,
			DM_OVERLAY_TRACK		,
			DM_OVERLAY_TRIGGER_LIST	,
			DM_OVERLAY_TRIGGER_EDIT	,

			DM_NUM_OVERLAYS
		};

		// ------------- general -------------

		static void TransferModeData			( const int iMode );

		static void CreateOverlay_Main			( );
		static void CreateOverlay_TrackList		( );
		static void CreateOverlay_Track			( );
		static void CreateOverlay_TriggerList	( );
		static void CreateOverlay_SingleTrigger	( );

		static void ValidateTriggers			( );	// Scrap this at some point

		static Asura_Vector_2					s_axOverlayPositions[ DM_NUM_OVERLAYS ];

		static bool								s_bMainOverlayOpen;
		static bool								s_bIgnore;
		static bool								s_bOverlayShouldBeOpen;

		static Asura_Dialog*					s_apxLayerNameButtons[ ASURA_DYNAMIC_MUSIC_SYSTEM_NUM_LAYERS ];

		// ------------- main overlay -------------

		static void Button_Main_ShowTrackListOverlay		( );
		static void Button_Main_CreateDynamicMusicTrigger	( );
		static void Button_Main_SaveClose					( );
		static void Button_Main_SetLayerName				( int iLayer );
		static void Button_Main_ShowTriggerList				( );

		// ------------- track list -----------------

		static void CreateTrackListArray 			( );
		static void DeleteTrackListArray 			( );

		static void Button_TrackList_NewTrack		( );
		static void Button_TrackList_EditTrack		( );
		static void Button_TrackList_DeleteTrack	( );
		static void Button_TrackList_CloseOverlay	( );

		static int		s_iTrackListArraySize;
		static char**	s_ppszTrackListNames;

		static int		s_iTrackListSelectionIndex;
		static bool		s_bTrackListSelectionChanged;

		// ------------- track -----------------

		static void Button_Track_Rename				( );	
		static void Button_Track_SelectSample		( int iLayer );
		static void Button_Track_ClearSample		( int iLayer );
		static void Button_Track_Play				( int iPos );
		static void Button_Track_Stop				( );
		static void Button_Track_CloseOverlay		( );

		static bool	Enabled_Track_Play				( );
		static bool Enabled_Track_Stop				( );

		static bool	PromptAndSetMusicTrack			( Asura_Dynamic_Music_TrackData* pxTrack, int iTrack );

		static void	UpdateIntroOutroDialogs			( );
		
		static bool 					s_bTrackModified;
		static bool 					s_bForceTrackOverlayOpen;
		static int						s_iIntroEnd_Numeric;
		static int						s_iOutroStart_Numeric;
		static bool						s_bChangedIntroOutro_Numeric;

		static Asura_Numerical_Dialog*	s_pxIntroOutroDialogs[2];
		static Asura_Dialog*			s_apxLayerFilesDialogs[ASURA_DYNAMIC_MUSIC_SYSTEM_NUM_LAYERS];
		static Asura_Dialog*			s_apxLayerClearDialogs[ASURA_DYNAMIC_MUSIC_SYSTEM_NUM_LAYERS];
		static Asura_WAVAlign_Dialog*	s_pxWAVAlignDialog;

		// ---------- trigger list ------------

		static void CreateTriggerListArray 			( );
		static void DeleteTriggerListArray 			( );

		static void Button_TrigList_CreateCodeTrigger( );
		static void Button_TrigList_TestTrigger		( );
		static void Button_TrigList_JumpToTrig		( );
		static void Button_TrigList_ShowTrigProps	( );
		static void Button_TrigList_RenameTrigger	( );
		static void Button_TrigList_DeleteTrigger	( );
		static void Button_TrigList_CloseOverlay	( );

		static Asura_Hash_ID GetSelectedTriggerHash	( );
		static char**							s_ppszEntityTriggerListNames;
		static int								s_iEntityTriggerListSelectionIndex;
		static Asura_HeapArray<Asura_Hash_ID>	s_xEntityTriggerHashList;	// Hash ID's of trigger data. Index matches s_ppszEntityTriggerListNames.

		static char**							s_ppszCodeTriggerListNames;
		static int								s_iCodeTriggerListSelectionIndex;
		static Asura_HeapArray<Asura_Hash_ID>	s_xCodeTriggerHashList;		// Hash ID's of trigger data. Index matches s_ppszCodeTriggerListNames.

		// ---------- single trigger ------------

		static void AddTriggerOverlayControls(class Asura_Overlay* pxOverlay, class Asura_Vector_2& xOffset, Asura_Hash_ID uTriggerHash);

		//Overlay controls for the different trigger types
		static void		AddTriggerOverlayControls_Trans		(Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset, Asura_Dynamic_Music_Trigger_Data* pxData);
		static void		AddTriggerOverlayControls_Play		(Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset, Asura_Dynamic_Music_Trigger_Data* pxData);
		static void		AddTriggerOverlayControls_Stop		(Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset, Asura_Dynamic_Music_Trigger_Data* pxData);
		static void		AddTriggerOverlayControls_JoinRel	(Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset, Asura_Dynamic_Music_Trigger_Data* pxData);

		static void		Button_TrigEdit_TestTrigger	();
		static bool		Enabled_TestTrigger ();

		static void		Button_TrigEdit_HaltPlayback ();
		static bool		Enabled_HaltPlayback ();

		// Transition trigger
		static void		Button_TRANS_SelectTrack ();
		static void		Button_TRANS_ClearTrack	();
		static void		Button_TRANS_ReduceTime	();
		static void		Button_TRANS_IncreaseTime ();

		// Play trigger
		static void		Button_PLAY_SelectTrack ();

		static Asura_Hash_ID PromptForDynamicMusicTrack	();
		static void		ClearOverlayControlPointers ();
		static void		CloseTriggerEditOverlay ();
		static void		RecreateOverlay ();

		// per frame update functions (when code trigger overlay is active)
		// return value means overlay 'needs re-creating'
		static bool		UpdateTriggerEditOverlay ();
		static bool		UpdateTriggerEditOverlay_Trans (Asura_Dynamic_Music_Trigger_Data* pxData);
		static bool		UpdateTriggerEditOverlay_Play (Asura_Dynamic_Music_Trigger_Data* pxData);
		static bool		UpdateTriggerEditOverlay_Stop (Asura_Dynamic_Music_Trigger_Data* pxData);
		static bool		UpdateTriggerEditOverlay_JoinRel (Asura_Dynamic_Music_Trigger_Data* pxData);

		enum CHANNELS
		{
			CHANNEL_PREVIOUS_TRACK	= 0,
			CHANNEL_NEXT_TRACK		= 1,

			NUM_CHANNELS
		};

		enum CHANNEL_BLOCKS
		{
			CHANNEL_BLOCK_PREV_BODY		= 0,
			CHANNEL_BLOCK_PREV_OUTRO	= 1,
			CHANNEL_BLOCK_NEXT_INTRO	= 2,
			CHANNEL_BLOCK_NEXT_BODY		= 3,

			NUM_CHANNEL_BLOCKS
		};

		static Asura_Hash_ID				s_uSelectedTriggerHash;

		static Asura_Dialog*				s_pxTRANS_TrackNameDialog;
		static Asura_Dialog*				s_pxTRANS_UseIntroTick;
		static Asura_Channel_Graph_Dialog*	s_pxTRANS_ChannelDialog;
		static bool							s_bTRANS_HasTrackToTransition;
		static bool							s_bTRANS_UseIntroTick;

		static Asura_Channel_Graph_Channel*	s_apxTRANS_Channels				[NUM_CHANNELS];
		static Asura_Channel_Graph_Block*	s_apxTRANS_ChannelBlocks		[NUM_CHANNEL_BLOCKS];
		static bool							s_bTRANS_ChannelDialogModified;

		// Stop trigger

		static Asura_Channel_Graph_Dialog*	s_pxSTOP_ChannelDialog;
		static Asura_Channel_Graph_Block*	s_pxSTOP_ChannelDialogOutroBlock;
		static bool							s_bSTOP_ChannelDialogModified;
		static bool							s_bSTOP_JustOutroTick;

		// Join release trigger

		static Asura_Channel_Graph_Dialog*	s_apxJOINREL_ChannelDialog			[ASURA_DYNAMIC_MUSIC_SYSTEM_NUM_LAYERS];
		static bool							s_abJOINREL_ChannelDialogModified	[ASURA_DYNAMIC_MUSIC_SYSTEM_NUM_LAYERS];

		static int							s_aiJOINREL_ActionTypeIndex			[ASURA_DYNAMIC_MUSIC_SYSTEM_NUM_LAYERS];
		static bool							s_abJOINREL_ActionTypeChanged		[ASURA_DYNAMIC_MUSIC_SYSTEM_NUM_LAYERS];

		static bool							s_bTriggerTypeChanged;
		static int							s_iTriggerTypeSelectionIndex;
		static bool							s_bGenericChangeRequiringSave;
};


#endif //ASURA_SUPPORT_DYNAMIC_MUSIC_SYSTEM

#endif //__TOOLS_MODE_DYNAMICMUSIC_H__

//eof
