//////////////////////////////////////////////////////////////////////////////
//
// Asura_LocalisedText.h
//
// Copyright (c) 2003 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_LOCALISEDTEXT_H___
#define ___ASURA_LOCALISEDTEXT_H___ 1

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

#include "Core/Asura_PlatformBasics.h"
#include "Core/Asura_Hash.h"
#ifdef ASURA_TOOLS
#include "Core/Asura_String.h"
#endif

// M A C R O S ///////////////////////////////////////////////////////////////

// (MP - 07.07.2003) You can override this limit in your project's /
// platform's Asura_EngineConfiguration.h.
#ifndef ASURA_LOCALISEDTEXT_PAGE_STORAGE_SIZE
    // This is the maximum number of localised text pages. Setting this to a
    // prime number may improve performance. Set to 0 to disable page support.
    #define ASURA_LOCALISEDTEXT_PAGE_STORAGE_SIZE (0)
#endif

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

class Asura_LocalisedText_Page;

// T Y P E S /////////////////////////////////////////////////////////////////

enum Asura_LocalisedText_Language
{
    ASURA_LT_L_ENGLISH,
    ASURA_LT_L_FRENCH,
    ASURA_LT_L_GERMAN,
    ASURA_LT_L_ITALIAN,
    ASURA_LT_L_SPANISH,
    ASURA_LT_L_RUSSIAN,
	ASURA_LT_L_AMERICAN,
	ASURA_LT_L_JAPANESE,
	ASURA_LT_L_DUTCH,
	ASURA_LT_L_PORTUGUESE,
    ASURA_LT_L_DANISH,
    ASURA_LT_L_FINNISH,
    ASURA_LT_L_NORWEGIAN,
    ASURA_LT_L_NUM_LANGUAGES,
};

// C L A S S E S /////////////////////////////////////////////////////////////

class Asura_LocalisedText
{
	friend class Asura_LocalisedText_Page;

	public:

        // T Y P E S /////////////////////////////////////////////////////////

        enum PAGERESETGROUP
        {
            PAGERESETGROUP_RESETTABLE,      // Default resettable pool.
            PAGERESETGROUP_PERMANENT,       // Only deallocated at final shutdown.
            PAGERESETGROUP_CUTSCENE_DATA,   // Removed when going to/from separately loaded cutscenes.
			PAGERESETGROUP_PS2_DNAS,		// removed when DNAS authentication is complete.
            // (MP - 23.04.2003) TODO: May want to make some provision for project-
            // specific groups...
        };

        // C L A S S   M E T H O D S /////////////////////////////////////////

		static void Initialise( u_int uLanguage );
		static void Initialise( const char* szTextFile, u_int uLanguage );
		static void Shutdown( void );
		
		static const Asura_UnicodeChar* GetString(int textID);
#ifdef ASURA_TOOLS
		static u_int GetNumLoadedStrings( void );
#endif
		static bool  IsOperational(void) { return s_bLocalisedTextOperational; }
        static Asura_LocalisedText_Language GetCurrentLanguage();
        static const char* GetTwoCharCodeForCurLang( void );
        static const char* GetTwoCharCodeForLang( Asura_LocalisedText_Language eLang );
		static const char* GetNameForCurLang();
		static const char* GetNameForLang( Asura_LocalisedText_Language eLang );

		//gets array of language names
		static const char* const* GetLanguageNames();

#if ASURA_LOCALISEDTEXT_PAGE_STORAGE_SIZE > 0

#ifdef ASURA_TOOLS
		static u_int GetNumLoadedPages( void );
        static void TraverseLoadedPages( void(*pfnCallback)(const Asura_LocalisedText_Page*) );
#endif
		static const Asura_LocalisedText_Page* GetPage( Asura_Hash_ID uPageID );
		static const Asura_UnicodeChar* GetString( int iTextID, Asura_Hash_ID uPageID );

        static void SetPageResetGroup( PAGERESETGROUP eGroup );
        static PAGERESETGROUP GetCurPageResetGroup( void );
        static void ResetPages( PAGERESETGROUP eGroup = PAGERESETGROUP_RESETTABLE );

#else

        static void ResetPages( PAGERESETGROUP eGroup = PAGERESETGROUP_RESETTABLE ) { }

#endif
				
	private:

        // (MP - 13.09.2002) To allow the chunk access to the functions below
        // for loading in the strings...
        friend class Asura_Chunk_LocalText;
		friend class Asura_Chunk_LocalText_Page;
	
		static bool s_bLocalisedTextOperational;

		static char* AllocateStringBuffer( u_int uNumBytes );
        static bool AllocateStringPtrArray( u_int uNumEntries );
		static bool AddString( int iTextID, Asura_UnicodeChar* wszString );		

#if ASURA_LOCALISEDTEXT_PAGE_STORAGE_SIZE > 0
		static Asura_LocalisedText_Page* AddPage( Asura_Hash_ID uNewID, u_int uNumStrings, u_int uNumBytesForStrings );
#endif

};


#if ASURA_LOCALISEDTEXT_PAGE_STORAGE_SIZE > 0

class Asura_LocalisedText_Page
{
    
    public:

        Asura_LocalisedText_Page( Asura_Hash_ID uID, u_int uNumStrings, u_int uNumBytesForStrings );
        ~Asura_LocalisedText_Page( void );

	    Asura_Hash_ID GetPageID( void ) const { return m_uID; }
        u_int GetNumLoadedStrings( void ) const { return m_uNumStrings; }
	    const Asura_UnicodeChar* GetString( int iTextID ) const;
        Asura_LocalisedText::PAGERESETGROUP GetResetGroup( void ) const { return m_eResetGroup; }

#ifdef ASURA_TOOLS	
	    Asura_String m_xToolsName;
#endif

    private:

        // For access to AddString().
        friend class Asura_Chunk_LocalText_Page;

		char* GetStringBuffer( void ) { return m_pcStringBuffer; }
		bool AddString( int iTextID, Asura_UnicodeChar* wszString );

	    Asura_Hash_ID                       m_uID;
        Asura_LocalisedText::PAGERESETGROUP m_eResetGroup;
	    Asura_UnicodeChar**                 m_pwszLocalisedText;
		char*								m_pcStringBuffer;
        u_int                               m_uNumStrings;

};

#endif // #if ASURA_LOCALISEDTEXT_PAGE_STORAGE_SIZE > 0

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

#endif // #ifndef ___ASURA_LOCALISEDTEXT_H___

