multi lang support
This commit is contained in:
@@ -37,9 +37,6 @@ Director::Director(std::string path)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Carga recursos
|
||||
loadConfigFile();
|
||||
|
||||
// Inicializa el resto de variables
|
||||
init();
|
||||
}
|
||||
@@ -65,9 +62,21 @@ Director::~Director()
|
||||
// Inicia las variables necesarias para arrancar el programa
|
||||
void Director::init()
|
||||
{
|
||||
// Carga el fichero de configuración
|
||||
if (!loadConfigFile())
|
||||
{
|
||||
mOptions->fullScreenMode = 0;
|
||||
mOptions->windowSize = 3;
|
||||
mOptions->language = en_UK;
|
||||
}
|
||||
|
||||
// Sección
|
||||
mSection.name = PROG_SECTION_LOGO;
|
||||
mSection.subsection = 0;
|
||||
|
||||
// Textos
|
||||
initTextStrings(mTextStrings, mOptions->language);
|
||||
|
||||
// Teclado
|
||||
mInput->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||
mInput->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||
@@ -291,6 +300,11 @@ bool Director::checkFileList()
|
||||
// Carga el fichero de configuración
|
||||
bool Director::loadConfigFile()
|
||||
{
|
||||
// Pone unos valores por defecto
|
||||
mOptions->fullScreenMode = 0;
|
||||
mOptions->windowSize = 3;
|
||||
mOptions->language = en_UK;
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
|
||||
@@ -303,20 +317,18 @@ bool Director::loadConfigFile()
|
||||
{
|
||||
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||
|
||||
// Creamos el fichero para escritura
|
||||
// Crea el fichero para escritura
|
||||
file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("New file (%s) created!\n", filename.c_str());
|
||||
|
||||
// Inicializamos los datos
|
||||
mOptions->fullScreenMode = 0;
|
||||
// Escribe los datos
|
||||
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||
|
||||
mOptions->windowSize = 3;
|
||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||
|
||||
// Cerramos el fichero
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
else
|
||||
@@ -332,10 +344,22 @@ bool Director::loadConfigFile()
|
||||
printf("Reading file %s\n", filename.c_str());
|
||||
SDL_RWread(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||
SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||
SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||
|
||||
// Normaliza los valores
|
||||
if (!((mOptions->fullScreenMode == 0) ||
|
||||
(mOptions->fullScreenMode == SDL_WINDOW_FULLSCREEN) ||
|
||||
(mOptions->fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)))
|
||||
mOptions->fullScreenMode = 0;
|
||||
if ((mOptions->windowSize < 1) || (mOptions->windowSize > 4))
|
||||
mOptions->windowSize = 3;
|
||||
if ((mOptions->language < 0) || (mOptions->language > MAX_LANGUAGES))
|
||||
mOptions->language = en_UK;
|
||||
|
||||
// Aplica las opciones
|
||||
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
|
||||
SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize);
|
||||
initTextStrings(mTextStrings, mOptions->language);
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
@@ -356,6 +380,7 @@ bool Director::saveConfigFile()
|
||||
// Guarda los datos
|
||||
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(Uint32), 1);
|
||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(Uint8), 1);
|
||||
SDL_RWwrite(file, &mOptions->language, sizeof(Uint8), 1);
|
||||
|
||||
printf("Writing file %s\n", filename.c_str());
|
||||
|
||||
@@ -402,35 +427,27 @@ void Director::runLogo()
|
||||
|
||||
void Director::runIntro()
|
||||
{
|
||||
mIntro = new Intro(mRenderer, mFileList);
|
||||
mIntro = new Intro(mRenderer, mFileList, mTextStrings);
|
||||
setSection(mIntro->run());
|
||||
delete mIntro;
|
||||
}
|
||||
|
||||
void Director::runTitle()
|
||||
{
|
||||
mTitle = new Title(mWindow, mRenderer, mInput, mFileList, mOptions);
|
||||
mTitle = new Title(mWindow, mRenderer, mInput, mFileList, mOptions, mTextStrings);
|
||||
setSection(mTitle->run(mSection.subsection));
|
||||
delete mTitle;
|
||||
}
|
||||
|
||||
void Director::runGame()
|
||||
{
|
||||
mGame = new Game(mRenderer, mFileList, mInput, false);
|
||||
mGame = new Game(mRenderer, mFileList, mTextStrings, mInput, false);
|
||||
setSection(mGame->run());
|
||||
delete mGame;
|
||||
}
|
||||
|
||||
void Director::run()
|
||||
{
|
||||
//for (int i = 0; i < 100; i++)
|
||||
//{
|
||||
// Game *test = new Game(mRenderer, mFileList, mInput, true);
|
||||
// delete test;
|
||||
// printf("%i\n", i);
|
||||
//}
|
||||
//mSection.name = PROG_SECTION_QUIT;
|
||||
|
||||
// Bucle principal
|
||||
while (!(getSection() == PROG_SECTION_QUIT))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user