/**
* Stripped down version of Pirates' GameSWFLocalization.
*/
#ifndef __GAMESWF_LOCALIZATION__
#define __GAMESWF_LOCALIZATION__
#include "GameSWF/swf/character_handle.h"
#include "RKList.h"
#include "RKSingleton.h"
namespace gameswf
{
class FlashFX;
}
class GameSWFLocalization : public RKSingleton<GameSWFLocalization>
{
GameSWFLocalization(const GameSWFLocalization&);
GameSWFLocalization& operator=(const GameSWFLocalization&);
public:
GameSWFLocalization();
/// \brief Updates CharacterHandles stored in m_localizationHandles with the currently assigned language
void UpdateLanguage();
/// \brief Remove localized CharacterHandles from the flash file
/* \note Poorly implemented/expensive. Iterates over every CharacterHandle in the file. Ideal rework would use
* ActionScript events to correctly call onUnload, prompting only localized elements to remove themselves.
*/
void RemoveLocalizedElements(const gameswf::FlashFX* a_pFx);
private: // Functionality
/// \brief Returns the Localized String to flash
static void NativeGetLocalizedString(const gameswf::FunctionCall& fn);
/// \brief Returns the Localized formatted string to flash.
/// \note Accepted types are Number (cast to float) and string. Numbers are rounded to one decimal place (ie. 2.06 will display as "2.1", and 2.04 will display as "2")
/// \note "null" and "undefined" arguments will throw an RKLOGt under the "ui" logType.
/// \note Up to 16 parameters are supported
static void NativeGetLocalizedFormattedString(const gameswf::FunctionCall& fn);
/// \brief Returns the Localized time string to flash.
/// \note Time value is assumed to be argument 0, passed in as a float in seconds
static void NativeGetLocalizedTimeString(const gameswf::FunctionCall& fn);
/// \brief Returns an integer number with localized digit groupings. (ie. 1,000,000 vs 1.000.000 from an input of 1000000)
/// \note Number is taken as an int
static void NativeGetLocalizedNumberString(const gameswf::FunctionCall& fn);
/// \brief Returns the games language as an int 0-9 as defined in Stringpack.h to flash
static void NativeGetLanguage(const gameswf::FunctionCall& fn);
/// \brief Adds a CharacterHandle to m_localizationHandles to update on language changes
static void NativeAddToLocalizationList(const gameswf::FunctionCall& fn);
/// \brief Removes a CharacterHandle from m_localizationHandles. It will no longer be updated on language changes.
static void NativeRemoveFromLocalizationList(const gameswf::FunctionCall& fn);
/// \brief Recursively removes CharacterHandles/their children from the list of m_localizationHandles
void RecursiveRemoveLocalizedElements(gameswf::CharacterHandle a_hChar);
private: // Members
typedef RKList<gameswf::CharacterHandle> Handles;
Handles m_localizationHandles; //!< A list of CharacterHandles to update on language changes
};
#endif // __GAMESWF_LOCALIZATION__