//--------------------------------------------------------------------------------------
// Copyright (C) 2008 http://shift.delblanco.es
//--------------------------------------------------------------------------------------
// SHIFT Videogame is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
//--------------------------------------------------------------------------------------
// GUI.cpp
//--------------------------------------------------------------------------------------
#include "dxstdafx.h"

#include <string>
#include "GUI.h"
#include "Menu.h"
#include "Settings.h"

//--------------------------------------------------------------------------------------
// Espacio de nombres
//--------------------------------------------------------------------------------------
using namespace std;

//--------------------------------------------------------------------------------------
// Variables Globales
//--------------------------------------------------------------------------------------
CGUI              *g_GUI;            // Instancia para el GUI
extern CMenu      *g_Menu;           // Instancia externa para el menú 3D (Menu.cpp)
extern CSettings  *g_Settings;       // Instancia externa para las opciones (Settings.cpp)
extern bool       g_bCreated;        // Para saber si se creó el dispositivo (Main.cpp)
extern float      g_TimeGame;        // Tiempo de juego (Game.cpp)

//--------------------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------------------
CGUI::CGUI()
{
    // Inicializamos punteros
    m_pDevice = NULL;
    m_pFont = NULL;
    m_pTextSprite = NULL;
    m_pGUI = NULL;

    // Inicializamos el vector de índices de comboboxes
    for(int i = 0 ; i < GUI_MAX_ITEMS_COMBOBOX ; i++)
        m_piIndex[i] = i;

    // Inicializamos variables
    m_iType = 0;
    m_iTypeGame = 0;
    m_iTypeArena = 0;
    m_iTypeVehicle = 0;
    m_iArena = 0;
    m_iVehicle1 = 0;
    m_iVehicle2 = 0;
    m_inumArenas = 0;
    m_inumVehicles = 0;

    m_bInit = false;
    m_bStadistics = false;
    m_bPaused = false;
    m_bGamming = false;
}

//--------------------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------------------
CGUI::~CGUI()
{
    Release();
}

//--------------------------------------------------------------------------------------
// Inicia el GUI ante un CreateDevice
//--------------------------------------------------------------------------------------
bool CGUI::initialize()
{
    // Salimos si ya se ha inicializado
    if(m_bInit) return false;
    m_bInit = true;

    // Tomamos el dispositivo
    m_pDevice = DXUTGetD3DDevice();
    assert(m_pDevice != NULL);
    m_pDevice->AddRef();

    // Inicializamos el GUI
    m_pGUI = new CDXUTDialog();
    if(!m_pGUI) return false;
    m_aCtrls.clear();

    // Inicializamos la fuente de texto
    if( FAILED(D3DXCreateFont( m_pDevice, 14, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, 
                               OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, 
                               L"Arial", &m_pFont ) ) ) return false;

    // Inicializamos los parametros basicos por defecto
    m_pGUI->SetCallback( OnGUIEvent );

    // Tomamos la resolución actual
    m_uHeight = DXUTGetPresentParameters().BackBufferHeight;
    m_uWidth = DXUTGetPresentParameters().BackBufferWidth;
    m_uMidW = m_uWidth/2;
    m_uMidH = m_uHeight/2;

    // Creamos las fuentes
    m_pGUI->SetFont(GUI_FONT_MENU, L"Arial", 16, FW_BOLD);
    m_pGUI->SetFont(GUI_FONT_TITLE, L"Arial", 120, FW_EXTRABOLD);
    m_pGUI->SetFont(GUI_FONT_TITLE_2, L"Arial", 90, FW_EXTRABOLD);
    m_pGUI->SetFont(GUI_FONT_WARNING, L"Arial", 90, FW_EXTRABOLD);
    m_pGUI->SetFont(GUI_FONT_CREDITS, L"Arial", 14, FW_BOLD);
    m_pGUI->SetFont(GUI_FONT_INFO, L"Arial", 20, FW_BOLD);
    m_pGUI->SetFont(GUI_FONT_INFO_2, L"Arial", 16, FW_BOLD);
    m_pGUI->SetFont(GUI_FONT_INFO_3, L"Arial", 16, FW_EXTRABOLD);
    m_pGUI->SetFont(GUI_FONT_COUNTER, L"Courier New", 80, FW_EXTRABOLD);
    m_pGUI->SetFont(GUI_FONT_DESCRIPTION, L"Arial", 15, FW_SEMIBOLD);
    m_pGUI->SetFont(GUI_FONT_MAP, L"Arial", 25, FW_EXTRABOLD);

    //----------------------------------------------------------------------------------
    // Creamos el texto de los créditos (esquinas superior e inferior derecha)
    m_pGUI->AddListBox(GUI_LISTBOX_CREDITS_UP, -50,             0, m_uWidth + 100, 20);
    m_aCtrls.push_back(m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_UP));
	CDXUTListBox *pListBox1 = m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_UP);
	pListBox1->SetEnabled(false);
	pListBox1->SetScrollBarWidth(0);

    m_pGUI->AddListBox(GUI_LISTBOX_CREDITS_DW, -50, m_uWidth - 20, m_uWidth + 100, 20);
    m_aCtrls.push_back(m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_DW));
	CDXUTListBox *pListBox2 = m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_DW);
	pListBox2->SetEnabled(false);
	pListBox2->SetScrollBarWidth(0);

    //----------------------------------------------------------------------------------
    // Elementos varios que se utilizan en diferentes tipos de GUI
    m_pGUI->AddStatic(GUI_STATIC_TITULO_2, L"", m_uMidW - 400, 30, 800, 200);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_TITULO_2));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(80, 200, 200, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_CENTER|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_TITLE_2;

    m_pGUI->AddStatic(GUI_STATIC_INFO, L"", m_uMidW - 400, 120, 800, 100);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_INFO));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(100, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_CENTER|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO;

    m_pGUI->AddStatic(GUI_STATIC_INFO_2, L"", m_uMidW - 400, 150, 800, 40);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_INFO_2));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(100, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_CENTER|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO;

    m_pGUI->AddButton(GUI_BTN_ACCEPT, L"OK", m_uMidW + GUI_BTN_W_SPACE, m_uHeight - (GUI_BTN_H_2 + 20), GUI_BTN_W_2, GUI_BTN_H_2);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_ACCEPT));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    m_pGUI->AddButton(GUI_BTN_CANCEL, L"Cancel", m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uHeight - (GUI_BTN_H_2 + 20), GUI_BTN_W_2, GUI_BTN_H_2);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_CANCEL));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    m_pGUI->AddStatic(GUI_STATIC_COUNTER, L"", m_uMidW - 100, m_uMidH + 80, 200, 150);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_COUNTER));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(70, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_CENTER|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_COUNTER;

    m_pGUI->AddStatic(GUI_STATIC_RANK, L"", m_uMidW - 400, m_uMidH - 150, 500, 300);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_RANK));
    m_aCtrls.back()->SetTextColor( D3DCOLOR_ARGB( 90, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO;

    m_pGUI->AddStatic(GUI_STATIC_WARNING, L"", m_uMidW - 400, m_uMidH - 150, 800, 300);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_WARNING));
    m_aCtrls.back()->SetTextColor( D3DCOLOR_ARGB( 60, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_CENTER|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_WARNING;

    m_pGUI->AddListBox(GUI_LISTBOX_CONTROLS1, m_uMidW - 193, m_uMidH + 8, 185, 140, 1);
    m_aCtrls.push_back(m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1));
	pListBox1 = m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1);
	pListBox1->RemoveAllItems(); int i1 = 0;
	pListBox1->AddItem(L"PLAYER 1", getIndex(i1)); i1++;
	pListBox1->AddItem(L"----------------------------------------", getIndex(i1)); i1++;
	pListBox1->AddItem(L"UP CURSOR..........speed up", getIndex(i1)); i1++;
	pListBox1->AddItem(L"DOWN CURSOR....brake", getIndex(i1)); i1++;
	pListBox1->AddItem(L"LEFT CURSOR.......turn left", getIndex(i1)); i1++;
	pListBox1->AddItem(L"RIGHT CURSOR.....turn right", getIndex(i1)); i1++;
	pListBox1->AddItem(L"SPACE BAR..........use handbrake", getIndex(i1)); i1++;
	pListBox1->AddItem(L"RIGHT CONTROL...launch rocket", getIndex(i1)); i1++;
	pListBox1->AddItem(L"RIGHT SHIFT..........drop mine", getIndex(i1)); i1++;
	pListBox1->SetEnabled(false);
	pListBox1->SetScrollBarWidth(0);

    m_pGUI->AddListBox(GUI_LISTBOX_CONTROLS2, m_uMidW + 8, m_uMidH + 8, 185, 140, 1);
    m_aCtrls.push_back(m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS2));
	pListBox2 = m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS2);
	pListBox2->RemoveAllItems(); int i2 = 0;
	pListBox2->AddItem(L"PLAYER 2", getIndex(i2)); i2++;
	pListBox2->AddItem(L"----------------------------------------", getIndex(i2)); i2++;
	pListBox2->AddItem(L"W KEY..................speed up", getIndex(i2)); i2++;
	pListBox2->AddItem(L"S KEY...................brake", getIndex(i2)); i2++;
	pListBox2->AddItem(L"A KEY...................turn left", getIndex(i2)); i2++;
	pListBox2->AddItem(L"D KEY...................turn right", getIndex(i2)); i2++;
	pListBox2->AddItem(L"CAPS LOCK..........use handbrake", getIndex(i2)); i2++;
	pListBox2->AddItem(L"LEFT CONTROL....launch rocket", getIndex(i2)); i2++;
	pListBox2->AddItem(L"LEFT SHIFT...........drop mine", getIndex(i2)); i2++;
	pListBox2->SetEnabled(false);
	pListBox2->SetScrollBarWidth(0);

    //----------------------------------------------------------------------------------
    // Creamos GUI del menú inicial (GUI_TYPE_MENU_INIT)
    m_pGUI->AddStatic(GUI_STATIC_TITULO, L"SHIFT", m_uMidW - 400, 20, 800, 200);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_TITULO));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB( 80, 200, 200, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_CENTER|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_TITLE;

    m_pGUI->AddButton(GUI_BTN_NEWGAME, L"New Game", m_uMidW - GUI_BTN_W/2, m_uMidH + GUI_BTN_H_SPACE, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_NEWGAME));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    m_pGUI->AddButton(GUI_BTN_SETT, L"Options", m_uMidW - GUI_BTN_W/2, m_uMidH, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_SETT));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    m_pGUI->AddButton(GUI_BTN_EXIT, L"Exit", m_uMidW - GUI_BTN_W/2, m_uMidH - GUI_BTN_H_SPACE, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_EXIT));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    //----------------------------------------------------------------------------------
    // Creamos GUI de opciones (GUI_TYPE_SETT)
    // Texto común
    m_pGUI->AddStatic(GUI_STATIC_SETT, L"", m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI - 12, GUI_SETT_W, 500);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_SETT));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(120, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;

    m_pGUI->AddButton(GUI_BTN_SETT_DISPLAY, L"Display options", m_uMidW - GUI_BTN_W/2, m_uMidH - GUI_BTN_H_SPACE, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_SETT_DISPLAY));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    m_pGUI->AddButton(GUI_BTN_SETT_SOUND, L"Sound Options", m_uMidW - GUI_BTN_W/2, m_uMidH, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_SETT_SOUND));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    m_pGUI->AddButton(GUI_BTN_SETT_GAME, L"Game Options", m_uMidW - GUI_BTN_W/2, m_uMidH + GUI_BTN_H_SPACE, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_SETT_GAME));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    //----------------------------------------------------------------------------------
    // Creamos GUI de opciones de video (GUI_TYPE_SETT_DISPLAY)
    m_pGUI->AddComboBox(GUI_CMBBX_SETT_QUALITY, m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*0, GUI_SETT_W, GUI_SETT_H);
    m_pGUI->GetComboBox(GUI_CMBBX_SETT_QUALITY)->SetDropHeight(50);
    m_aCtrls.push_back(m_pGUI->GetComboBox(GUI_CMBBX_SETT_QUALITY));

    m_pGUI->AddComboBox(GUI_CMBBX_SETT_WINFULL, m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*1, GUI_SETT_W, GUI_SETT_H);
    m_pGUI->GetComboBox(GUI_CMBBX_SETT_WINFULL)->SetDropHeight(20);
    m_aCtrls.push_back(m_pGUI->GetComboBox(GUI_CMBBX_SETT_WINFULL));

    m_pGUI->AddComboBox(GUI_CMBBX_SETT_STADISTICS, m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*2, GUI_SETT_W, GUI_SETT_H);
    m_pGUI->GetComboBox(GUI_CMBBX_SETT_STADISTICS)->SetDropHeight(20);
    m_aCtrls.push_back(m_pGUI->GetComboBox(GUI_CMBBX_SETT_STADISTICS));

    m_pGUI->AddComboBox(GUI_CMBBX_SETT_RESOLUTION, m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*4, GUI_SETT_W, GUI_SETT_H);
    m_pGUI->GetComboBox(GUI_CMBBX_SETT_RESOLUTION)->SetDropHeight(50);
    m_aCtrls.push_back(m_pGUI->GetComboBox(GUI_CMBBX_SETT_RESOLUTION));

    m_pGUI->AddComboBox(GUI_CMBBX_SETT_FILTER, m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*5, GUI_SETT_W, GUI_SETT_H);
    m_pGUI->GetComboBox(GUI_CMBBX_SETT_FILTER)->SetDropHeight(35);
    m_aCtrls.push_back(m_pGUI->GetComboBox(GUI_CMBBX_SETT_FILTER));

    m_pGUI->AddComboBox(GUI_CMBBX_SETT_MIPMAPPING, m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*6, GUI_SETT_W, GUI_SETT_H);
    m_pGUI->GetComboBox(GUI_CMBBX_SETT_MIPMAPPING)->SetDropHeight(20);
    m_aCtrls.push_back(m_pGUI->GetComboBox(GUI_CMBBX_SETT_MIPMAPPING));

    //----------------------------------------------------------------------------------
    // Creamos GUI de opciones de sonido (GUI_TYPE_SETT_SOUND)
    m_pGUI->AddSlider(GUI_SLIDER_SETT_MUSIC, m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*0 + 5, 200, 20, 1, 100, 20);
    m_aCtrls.push_back(m_pGUI->GetSlider(GUI_SLIDER_SETT_MUSIC));

    m_pGUI->AddSlider(GUI_SLIDER_SETT_EFFECTS, m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*2 + 5, 200, 20, 1, 100, 20);
    m_aCtrls.push_back(m_pGUI->GetSlider(GUI_SLIDER_SETT_EFFECTS));

    //----------------------------------------------------------------------------------
    // Creamos GUI de opciones de juego (GUI_TYPE_SETT_GAME)
    m_pGUI->AddEditBox(GUI_EDITBOX_SETT_NAME, L"", m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*0 + 5, GUI_SETT_W, 30);
    m_aCtrls.push_back(m_pGUI->GetEditBox(GUI_EDITBOX_SETT_NAME));

    //----------------------------------------------------------------------------------
    // Creamos GUI de nuevo juego (GUI_TYPE_NEW_GAME)
    m_pGUI->AddButton(GUI_BTN_1PLAYER, L"One player", m_uMidW - GUI_BTN_W/2, m_uMidH - GUI_BTN_H_SPACE, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_1PLAYER));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    m_pGUI->AddButton(GUI_BTN_2PLAYER, L"Two players", m_uMidW - GUI_BTN_W/2, m_uMidH, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_2PLAYER));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    //----------------------------------------------------------------------------------
    // Creamos GUI de nuevo juego para dos jugadores (GUI_TYPE_NEW_GAME2)
    m_pGUI->AddButton(GUI_BTN_2PLAYER_FIGHT, L"Fight", m_uMidW - GUI_BTN_W/2, m_uMidH - GUI_BTN_H_SPACE, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_2PLAYER_FIGHT));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    m_pGUI->AddButton(GUI_BTN_2PLAYER_OBJS, L"Objectives", m_uMidW - GUI_BTN_W/2, m_uMidH, GUI_BTN_W, GUI_BTN_H);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_2PLAYER_OBJS));
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MENU;
    m_aCtrls.back()->GetElement(1)->iFont = GUI_FONT_MENU;

    //----------------------------------------------------------------------------------
    // Creamos GUI de seleccionar la arena (GUI_TYPE_SELECT_ARENA)
    // Creamos GUI de seleccionar el vehículo del jugador 1 (GUI_TYPE_SELECT_VEHICLE1)
    // Creamos GUI de seleccionar el vehículo del jugador 2 (GUI_TYPE_SELECT_VEHICLE2)
    m_pGUI->AddButton(GUI_BTN_SELECT_PRIOR, L"<<", m_uMidW, m_uHeight - 100, 50, GUI_BTN_H_3);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_SELECT_PRIOR));

    m_pGUI->AddButton(GUI_BTN_SELECT_NEXT, L">>", m_uMidW + GUI_BTN_W_3 + 5, m_uHeight - 100, 50, GUI_BTN_H_3);
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_SELECT_NEXT));

    m_pGUI->AddListBox(GUI_LISTBOX_SELECT_ARENA, 50, m_uMidH - m_uMidH/2 + 25, 200, m_uMidH/2);
    m_aCtrls.push_back(m_pGUI->GetListBox(GUI_LISTBOX_SELECT_ARENA));

    m_pGUI->AddListBox(GUI_LISTBOX_SELECT_VEHI1, 50, m_uMidH - m_uMidH/2 + 25, 200, m_uMidH/2);
    m_aCtrls.push_back(m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI1));

    m_pGUI->AddListBox(GUI_LISTBOX_SELECT_VEHI2, 50, m_uMidH - m_uMidH/2 + 25, 200, m_uMidH/2);
    m_aCtrls.push_back(m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI2));

    m_pGUI->AddStatic(GUI_STATIC_ARENA_INFO, L"", 50, m_uMidH + 35, 400, 200);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_ARENA_INFO));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(120, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_DESCRIPTION;

    m_pGUI->AddStatic(GUI_STATIC_ARENA_MINFO, L"", 100, 100, 400, 200);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_ARENA_MINFO));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(90, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_DESCRIPTION;

    m_pGUI->AddStatic(GUI_STATIC_VEHICLE_INFO, L"", 50, m_uMidH + 35, 400, 200);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_VEHICLE_INFO));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(120, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_DESCRIPTION;

    m_pGUI->AddStatic(GUI_STATIC_VEHICLE_MINFO, L"", 100, 100, 400, 200);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_VEHICLE_MINFO));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(90, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_DESCRIPTION;

    m_pGUI->AddStatic(GUI_STATIC_GAME_INFO, L"", m_uMidW - 200, m_uMidH - 35, 400, 200);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_GAME_INFO));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(120, 255, 255, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_DESCRIPTION;

    //----------------------------------------------------------------------------------
    // Creamos GUI del interfaz de juego (GUI_TYPE_INTERFAZ_GAME)
    m_pGUI->AddButton(GUI_BTN_GAME_PAUSE, L"Pause (P)", m_uWidth - (GUI_BTN_W_3 + 5), m_uHeight - 70, GUI_BTN_W_3, GUI_BTN_H_3, L'P');
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_GAME_PAUSE));

    m_pGUI->AddStatic(GUI_STATIC_P1_TITLE, L"Player 1", 5, 25, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P1_TITLE));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(180, 180, 180, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_3;

    m_pGUI->AddStatic(GUI_STATIC_P1_HEALTH, L"", 5, 40, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P1_HEALTH));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    m_pGUI->AddStatic(GUI_STATIC_P1_ROCKETS, L"", 5, 55, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P1_ROCKETS));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    m_pGUI->AddStatic(GUI_STATIC_P1_MINES, L"", 5, 70, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P1_MINES));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    m_pGUI->AddStatic(GUI_STATIC_P1_OBJECTIVES, L"", 5, 85, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P1_OBJECTIVES));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    m_pGUI->AddStatic(GUI_STATIC_P2_TITLE, L"Player 2", 5, 100, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P2_TITLE));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(180, 180, 180, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_3;

    m_pGUI->AddStatic(GUI_STATIC_P2_HEALTH, L"", 5, 115, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P2_HEALTH));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    m_pGUI->AddStatic(GUI_STATIC_P2_ROCKETS, L"", 5, 130, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P2_ROCKETS));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    m_pGUI->AddStatic(GUI_STATIC_P2_MINES, L"", 5, 145, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P2_MINES));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    m_pGUI->AddStatic(GUI_STATIC_P2_OBJECTIVES, L"", 5, 160, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_P2_OBJECTIVES));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    m_pGUI->AddStatic(GUI_STATIC_TOTAL_TIME, L"", 5, 175, 400, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_TOTAL_TIME));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(100, 220, 220, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_INFO_2;

    //----------------------------------------------------------------------------------
    // Elementos para el mini-mapa
    m_pGUI->AddEditBox(GUI_EDITBOX_MAP, L"", 0, m_uHeight - 20 - 60, 60, 60);
    m_aCtrls.push_back(m_pGUI->GetEditBox(GUI_EDITBOX_MAP));

    m_pGUI->AddStatic(GUI_STATIC_MAP_OBJ, L".", -100, -100, 20, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_MAP_OBJ));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 0, 0, 255));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MAP;

    m_pGUI->AddStatic(GUI_STATIC_MAP_P1, L".", -100, -100, 20, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_MAP_P1));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 0, 0, 0));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MAP;

    m_pGUI->AddStatic(GUI_STATIC_MAP_P2, L".", -100, -100, 20, 20);
    m_aCtrls.push_back(m_pGUI->GetStatic(GUI_STATIC_MAP_P2));
    m_aCtrls.back()->SetTextColor(D3DCOLOR_ARGB(150, 0, 0, 0));
    m_aCtrls.back()->GetElement(0)->dwTextFormat = DT_LEFT|DT_TOP;
    m_aCtrls.back()->GetElement(0)->iFont = GUI_FONT_MAP;

	//----------------------------------------------------------------------------------
    // Creamos GUI del menú durante el juego (GUI_TYPE_PAUSE_GAME)
    m_pGUI->AddButton(GUI_BTN_GAME_OPTIONS, L"Options (O)", m_uWidth - GUI_BTN_W_3, m_uHeight - 100, GUI_BTN_W_3, GUI_BTN_H_3, L'O');
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_GAME_OPTIONS));

    m_pGUI->AddButton(GUI_BTN_GAME_EXIT, L"Exit (X)", m_uWidth - GUI_BTN_W_3, m_uHeight - 80, GUI_BTN_W_3, GUI_BTN_H_3, L'X');
    m_aCtrls.push_back(m_pGUI->GetButton(GUI_BTN_GAME_EXIT));

    return 1;
}

//--------------------------------------------------------------------------------------
// Renderiza el GUI ante un FrameRender
//--------------------------------------------------------------------------------------
void CGUI::render()
{
    // Salimos si no se ha inicializado
    if(!m_bInit) return;

    // Renderizamos el GUI
    m_pGUI->OnRender(DXUTGetElapsedTime());

    // Imprimimos la versión del programa
    CDXUTTextHelper txtVersion(m_pFont, m_pTextSprite, 14);
    txtVersion.Begin();
    txtVersion.SetInsertionPos(m_uWidth - 125, 3);
    txtVersion.SetForegroundColor(D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.5f));
	txtVersion.DrawTextLine(L"SHIFT Videogame v1.0");
    txtVersion.End();

    // Imprimimos la versión del programa
    CDXUTTextHelper txtURL(m_pFont, m_pTextSprite, 14);
    txtURL.Begin();
    txtURL.SetInsertionPos(m_uWidth - 132, m_uHeight - 16);
    txtURL.SetForegroundColor(D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.5f));
	txtURL.DrawTextLine(L"http://shift.delblanco.es");
    txtURL.End();

    // Imprimimos las estadísticas
    if(m_bStadistics)
    {
        CDXUTTextHelper txtStadistics(m_pFont, m_pTextSprite, 14);
        txtStadistics.Begin();
        txtStadistics.SetInsertionPos(5, 3);
        txtStadistics.SetForegroundColor(D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.5f));
        txtStadistics.DrawTextLine(DXUTGetFrameStats());
        txtStadistics.End();
    }

}

//--------------------------------------------------------------------------------------
// Actualiza el GUI ante un FrameMove
//--------------------------------------------------------------------------------------
void CGUI::update()
{
    // No es necesario realizar ninguna tarea de actualización
}

//--------------------------------------------------------------------------------------
// Restaura objetos ante un ResetDevice
//--------------------------------------------------------------------------------------
void CGUI::restore()
{
    // Salimos si no se ha inicializado
    if(!m_bInit) return;

    // Restauramos el texto
    m_pFont->OnResetDevice();

    // Creamos el sprite para cuando hay varias líneas de texto
    D3DXCreateSprite(m_pDevice, &m_pTextSprite);
}

//--------------------------------------------------------------------------------------
// Libera objetos ante un LostDevice
//--------------------------------------------------------------------------------------
void CGUI::free()
{
    // Salimos si no se ha inicializado
    if(!m_bInit) return;

    // Liberamos el texto
    m_pFont->OnLostDevice();
    SAFE_RELEASE(m_pTextSprite);

    // Tomamos la resolución actual
    m_uHeight = DXUTGetPresentParameters().BackBufferHeight;
    m_uWidth = DXUTGetPresentParameters().BackBufferWidth;
    m_uMidW = m_uWidth/2;
    m_uMidH = m_uHeight/2;

    // Modificamos los objetos
    setTypeGUI(m_iType);
}

//--------------------------------------------------------------------------------------
// Libera el GUI
//--------------------------------------------------------------------------------------
void CGUI::Release()
{
    // Salimos si no se ha inicializado
    if(!m_bInit) return;
    m_bInit = false;

    // Liberamos el dispositivo
    SAFE_RELEASE(m_pDevice);

    // Liberamos otras estructuras
    SAFE_RELEASE(m_pFont);
    SAFE_RELEASE(m_pTextSprite);
    SAFE_DELETE(m_pGUI);
}

//--------------------------------------------------------------------------------------
// Para inicializar algunas variables y elementos de la configuración del juego
//--------------------------------------------------------------------------------------
void CGUI::iniGameConfig(void)
{
    // Inicializamos algunas veriables de juego por defecto
    m_iTypeGame=0;
    m_iTypeArena=0;
    m_iTypeVehicle=0;

    // Cargamos los controles de juego con la configuración por defecto
    g_Settings->RefreshControls(GUI_TYPE_SETT_GAME);
}

//--------------------------------------------------------------------------------------
// Función para ocultar todos los elementos del GUI
//--------------------------------------------------------------------------------------
void CGUI::HideAll(void)
{
    // Recorremos la lista de componentes del GUI y ocultamos todos ellos
    for(vector<CDXUTControl *>::iterator itr = m_aCtrls.begin() ; itr != m_aCtrls.end() ; itr++)
        (*itr)->m_bVisible = false;
}

//--------------------------------------------------------------------------------------
// Establece la arena con el índice dado, cargando todas antes si fuese necesario
//--------------------------------------------------------------------------------------
bool CGUI::setArena(int dIndex)
{
    // Comprobamos si ya tenemos cargada la arena, entonces no cargamos nada
    if( (dIndex == m_iArena || (dIndex < 0 && m_inumArenas)) &&
        (g_Menu->getMArena()) )
    {
        g_Menu->setTypeMenu(MENU_TYPE_SELECT_ARENA, NULL);
        return true;
    }

    // En otro caso tomamos la nueva arena
    if(dIndex >= 0)
        m_iArena = dIndex;

    // Comprobamos si aún no hemos listado el directorio
    CDXUTListBox *pListBox = m_pGUI->GetListBox(GUI_LISTBOX_SELECT_ARENA);
    if(!m_inumArenas)
    {
        // Preparamos la órden de búsqueda OBJARENA_DIR + "*.xml"
        basic_string<wchar_t> Search = OBJARENA_DIR + (basic_string<wchar_t>)L"*.xml";

        // Cargamos los nombres de los ficheros del directorio
        WIN32_FIND_DATA pFile;
        HANDLE pHandle = INVALID_HANDLE_VALUE;
        DWORD dwError;

        // Cargamos los nombres de los ficheros en el GUI
        pHandle = FindFirstFile(Search.c_str(), &pFile);
        if (pHandle == INVALID_HANDLE_VALUE) return false;
        pListBox->RemoveAllItems();
		basic_string<wchar_t> Text = pFile.cFileName;
        pListBox->AddItem(Text.substr(0,Text.size()-4).c_str(), getIndex(0));
        m_inumArenas = 1;
        while(FindNextFile(pHandle, &pFile) != 0)
        {
			basic_string<wchar_t> Text = pFile.cFileName;
            pListBox->AddItem(Text.substr(0,Text.size()-4).c_str(), getIndex(m_inumArenas));
            m_inumArenas++;
        }

        dwError = GetLastError();
        FindClose(pHandle);
        if (dwError != ERROR_NO_MORE_FILES) return false;
    }

    // Si hay items cargados mostramos/actualizamos el menú
    if(!g_Menu->setTypeMenu(MENU_TYPE_SELECT_ARENA, pListBox->GetItem(m_iArena)->strText))
        return false;

	// Vamos a mostrar información relativa a la arena
    WCHAR value[MAX_STRING+1];
    C3DObjArena *Arena = g_Menu->getMArena();
    _snwprintf(value, MAX_STRING, L"NAME...\n  %s\nDESCRIPTION...\n  %s", Arena->getName(), Arena->getDescription());
    setText(value, GUI_STATIC_ARENA_INFO);
	setText(Arena->getRankTxt(), GUI_STATIC_ARENA_MINFO);

    // Se selecciona el item en el ListBox
    pListBox->SelectItem(m_iArena);
    return true;
}

//--------------------------------------------------------------------------------------
// Establece el vehículo con el índice dado, cargando todos antes si fuese necesario
//--------------------------------------------------------------------------------------
bool CGUI::setVehicle(int numPlayer, int dIndex)
{
    // Comprobamos si ya tenemos cargado el vehículo, entonces no cargamos nada
	if (numPlayer == 1)
	{
		if( (dIndex == m_iVehicle1 || (dIndex < 0 && m_inumVehicles)) && (g_Menu->getMVehicle1()))
		{
			g_Menu->setTypeMenu(MENU_TYPE_SELECT_VEHICLE1, NULL);
			return true;
		}
	    if(dIndex >= 0) m_iVehicle1 = dIndex;
	}
	else
	{
		if( (dIndex == m_iVehicle2 || (dIndex < 0 && m_inumVehicles)) && (g_Menu->getMVehicle2()))
		{
			g_Menu->setTypeMenu(MENU_TYPE_SELECT_VEHICLE2, NULL);
			return true;
		}
	    if(dIndex >= 0) m_iVehicle2 = dIndex;
	}

    // Comprobamos si aún no hemos listado el directorio
    if(!m_inumVehicles)
    {
		// Tomamos los dos listbox
	    CDXUTListBox *pListBox1 = m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI1);
	    CDXUTListBox *pListBox2 = m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI2);
        pListBox1->RemoveAllItems();
        pListBox2->RemoveAllItems();

        // Preparamos la órden de búsqueda OBJVEHICLE_DIR + "*.xml"
        basic_string<wchar_t> Search = OBJVEHICLE_DIR + (basic_string<wchar_t>)L"*.xml";

        // Cargamos los nombres de los ficheros del directorio
        WIN32_FIND_DATA pFile;
        HANDLE pHandle = INVALID_HANDLE_VALUE;
        DWORD dwError;

        // Cargamos los nombres de los ficheros en el GUI
        pHandle = FindFirstFile(Search.c_str(), &pFile);
        if (pHandle == INVALID_HANDLE_VALUE) return false;
		basic_string<wchar_t> Text = pFile.cFileName;
        pListBox1->AddItem(Text.substr(0,Text.size()-4).c_str(), getIndex(0));
        pListBox2->AddItem(Text.substr(0,Text.size()-4).c_str(), getIndex(0));
        m_inumVehicles = 1;
        while(FindNextFile(pHandle, &pFile) != 0)
        {
			basic_string<wchar_t> Text = pFile.cFileName;
            pListBox1->AddItem(Text.substr(0,Text.size()-4).c_str(), getIndex(m_inumVehicles));
            pListBox2->AddItem(Text.substr(0,Text.size()-4).c_str(), getIndex(m_inumVehicles));
            m_inumVehicles++;
        }

        dwError = GetLastError();
        FindClose(pHandle);
        if (dwError != ERROR_NO_MORE_FILES) return false;
    }

    // Tomamos listbox y vehículo
    CDXUTListBox *pListBox;
    C3DObjVehicle *Vehicle;
	if (numPlayer == 1)
	{
		pListBox = m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI1);
		pListBox->SetEnabled(false);
	    pListBox->SelectItem(m_iVehicle1);
		pListBox->SetEnabled(true);
		if(!g_Menu->setTypeMenu(MENU_TYPE_SELECT_VEHICLE1, pListBox->GetItem(m_iVehicle1)->strText))
			return false;
		Vehicle = g_Menu->getMVehicle1();
	}
	else
	{
		pListBox = m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI2);
		pListBox->SetEnabled(false);
	    pListBox->SelectItem(m_iVehicle2);
		pListBox->SetEnabled(true);
		if(!g_Menu->setTypeMenu(MENU_TYPE_SELECT_VEHICLE2, pListBox->GetItem(m_iVehicle2)->strText))
			return false;
		Vehicle = g_Menu->getMVehicle2();
	}

    // Mostramos las características propias del vehículo
    WCHAR value[MAX_STRING+1];
    _snwprintf(value, MAX_STRING, L"NAME...\n  %s\nDESCRIPTION...\n  %s", Vehicle->getName(), Vehicle->getDescription());
    setText(value, GUI_STATIC_VEHICLE_INFO);
    _snwprintf(value, MAX_STRING, L"FEATURES...\n  Capacity  %.1f\n  Health     %.1f\n  Speed     %.1f\n  Accel.      %.1f",
        Vehicle->getMaxCapacity(),
        Vehicle->getMaxHealth(),
        Vehicle->getMaxSpeed(),
        Vehicle->getMaxAcceleration());
	setText(value, GUI_STATIC_VEHICLE_MINFO);

	return true;
}

//--------------------------------------------------------------------------------------
// Para cambiar el marcador indicado con el número indicado
//--------------------------------------------------------------------------------------
void CGUI::setMarcador(int num, int marcador)
{
    // Ponemos el número dado en el componente STATIC indicado
    WCHAR texto[10];
    _itow(num, texto, 10);
    m_pGUI->GetStatic(marcador)->SetText(texto);
}

//--------------------------------------------------------------------------------------
// Para cambiar el texto del aviso
//--------------------------------------------------------------------------------------
void CGUI::setText(LPCWSTR txt, int m_iType)
{
    // Ponemos el texto dado en el componente STATIC indicado
    m_pGUI->GetStatic(m_iType)->SetText(txt);
}

//--------------------------------------------------------------------------------------
// Para lanzar un evento
//--------------------------------------------------------------------------------------
void CGUI::throwEvent(int ID)
{
    // Para externamente provocar eventos del GUI, como por ejemplo pulsar un botón
    OnGUIEvent(0, ID, NULL);
}

//--------------------------------------------------------------------------------------
// Para cambiar el tipo de GUI
//--------------------------------------------------------------------------------------
void CGUI::setTypeGUI(int dType)
{
    // Tomamos el nuevo tipo
    m_ioldType = m_iType;
    m_iType = dType;

    // Ocultamos todos los elementos
    if(m_ioldType != m_iType) HideAll();

    // Elementos fijos en todos los tipos de GUI
    m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_UP)->SetSize(m_uWidth + 100, 20);
    m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_DW)->SetSize(m_uWidth + 100, 20);
    m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_DW)->SetLocation(-50, m_uHeight - 20);
    m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_UP)->m_bVisible = true;
    m_pGUI->GetListBox(GUI_LISTBOX_CREDITS_DW)->m_bVisible = true;

    // Elementos propios del tipo de GUI
    switch(m_iType)    
    {
    //----------------------------------------------------------------------------------
    case GUI_TYPE_MENU_INIT:
        m_bGamming = false;

        m_pGUI->GetStatic(GUI_STATIC_TITULO)->SetLocation(m_uMidW - 400, 20);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 120);
        setText(L"... select an option ...", GUI_STATIC_INFO);

        m_pGUI->GetButton(GUI_BTN_NEWGAME)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH - GUI_BTN_H_SPACE);
        m_pGUI->GetButton(GUI_BTN_SETT)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH);
        m_pGUI->GetButton(GUI_BTN_EXIT)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH + GUI_BTN_H_SPACE);
        m_pGUI->GetButton(GUI_BTN_NEWGAME)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_SETT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_EXIT)->m_bVisible = true;

        m_pGUI->GetStatic(GUI_STATIC_TITULO)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT:
        if(!m_bGamming)
        {
            m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
            setText(L"OPTIONS", GUI_STATIC_TITULO_2);
            m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);
            setText(L"... select available options ...", GUI_STATIC_INFO);
            m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
            m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        }
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW - GUI_BTN_W_2/2, m_uHeight - (GUI_BTN_H_2 + 20));

        m_pGUI->GetButton(GUI_BTN_SETT_DISPLAY)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH - GUI_BTN_H_SPACE);
        m_pGUI->GetButton(GUI_BTN_SETT_SOUND)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH);
        m_pGUI->GetButton(GUI_BTN_SETT_GAME)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH + GUI_BTN_H_SPACE);
        m_pGUI->GetButton(GUI_BTN_SETT_DISPLAY)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_SETT_SOUND)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_SETT_GAME)->m_bVisible = true;

        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_DISPLAY:
    {
        int selQLT;

        if(!m_bGamming)
        {
            m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
            m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);
            setText(L"... display options ...", GUI_STATIC_INFO);
            m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
            m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        }
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetStatic(GUI_STATIC_SETT)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI - 10);
        setText(L"Device Quality\n\nWindowed or FullScreen\n\nDevice Stadistics\n\n\n\nResolution\n\nTexture Filter\n\nMipmapping", GUI_STATIC_SETT);

        m_pGUI->GetComboBox(GUI_CMBBX_SETT_QUALITY)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*0);
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_WINFULL)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*1);
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_STADISTICS)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*2);
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_RESOLUTION)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*4);
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_FILTER)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*5);
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_MIPMAPPING)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*6);

        // Activamos o no varios de los controles respecto del resto
        selQLT = *((int *)(m_pGUI->GetComboBox(GUI_CMBBX_SETT_QUALITY)->GetSelectedData()));
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_RESOLUTION)->SetEnabled(selQLT==0);
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_FILTER)->SetEnabled(selQLT==0);
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_MIPMAPPING)->SetEnabled(selQLT==0);

        m_pGUI->GetComboBox(GUI_CMBBX_SETT_QUALITY)->m_bVisible = true;
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_WINFULL)->m_bVisible = true;
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_STADISTICS)->m_bVisible = true;
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_RESOLUTION)->m_bVisible = true;
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_FILTER)->m_bVisible = true;
        m_pGUI->GetComboBox(GUI_CMBBX_SETT_MIPMAPPING)->m_bVisible = true;

        m_pGUI->GetStatic(GUI_STATIC_SETT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
    }
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_SOUND:
        if(!m_bGamming)
        {
            m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
            m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);
            setText(L"... sound options ...", GUI_STATIC_INFO);
            m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
            m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        }
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetStatic(GUI_STATIC_SETT)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI - 10);

        setText(L"Sound volume", GUI_STATIC_SETT);
        m_pGUI->GetSlider(GUI_SLIDER_SETT_EFFECTS)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*0 + 5);
		m_pGUI->GetStatic(GUI_STATIC_COUNTER)->SetLocation(m_uMidW - 100, GUI_SETT_H_INI + GUI_SETT_H_SEP*0 + 20);

        m_pGUI->GetSlider(GUI_SLIDER_SETT_EFFECTS)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_COUNTER)->m_bVisible = true;
        setMarcador(m_pGUI->GetSlider(GUI_SLIDER_SETT_EFFECTS)->GetValue(), GUI_STATIC_COUNTER);

        m_pGUI->GetStatic(GUI_STATIC_SETT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_GAME:
        if(!m_bGamming)
        {
            m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
            m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);
            setText(L"... game options ...", GUI_STATIC_INFO);
            m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
            m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        }
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetStatic(GUI_STATIC_SETT)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI - 10);
        m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1)->SetLocation(m_uMidW - 193, m_uMidH + 8);
        m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS2)->SetLocation(m_uMidW + 8, m_uMidH + 8);

		setText(L"Default player's name\n\n\n\nControls:\n  - C KEY.........to change camera view\n  - P KEY..........to pause", GUI_STATIC_SETT);
        m_pGUI->GetEditBox(GUI_EDITBOX_SETT_NAME)->SetLocation(m_uMidW - GUI_SETT_W/2, GUI_SETT_H_INI + GUI_SETT_H_SEP*0 + 5);
        m_pGUI->GetEditBox(GUI_EDITBOX_SETT_NAME)->m_bVisible = true;

        m_pGUI->GetStatic(GUI_STATIC_SETT)->m_bVisible = true;
        m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1)->m_bVisible = true;
        m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS2)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
	//----------------------------------------------------------------------------------
    case GUI_TYPE_NEW_GAME:
        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
        setText(L"NEW GAME", GUI_STATIC_TITULO_2);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);

		setText(L"... select one or two players ...", GUI_STATIC_INFO);
        m_pGUI->GetButton(GUI_BTN_1PLAYER)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH - GUI_BTN_H_SPACE);
        m_pGUI->GetButton(GUI_BTN_2PLAYER)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH);
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - GUI_BTN_W_2/2, m_uHeight - (GUI_BTN_H_2 + 20));

        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_1PLAYER)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_2PLAYER)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
	//----------------------------------------------------------------------------------
    case GUI_TYPE_NEW_GAME2:
        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
        setText(L"NEW GAME", GUI_STATIC_TITULO_2);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);

		setText(L"... select the mission for two players game ...", GUI_STATIC_INFO);
        m_pGUI->GetButton(GUI_BTN_2PLAYER_FIGHT)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH - GUI_BTN_H_SPACE);
        m_pGUI->GetButton(GUI_BTN_2PLAYER_OBJS)->SetLocation(m_uMidW - GUI_BTN_W/2, m_uMidH);
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - GUI_BTN_W_2/2, m_uHeight - (GUI_BTN_H_2 + 20));

        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_2PLAYER_FIGHT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_2PLAYER_OBJS)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SELECT_ARENA:
        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);
        switch(m_iTypeGame)
        {
        case GAME_1PLAYER:       setText(L"... one player - select the arena ...", GUI_STATIC_INFO); break;
        case GAME_2PLAYER_FIGHT: setText(L"... two players by fight - select the arena ...", GUI_STATIC_INFO); break;
        case GAME_2PLAYER_OBJS:  setText(L"... two players by objectives - select the arena ...", GUI_STATIC_INFO); break;
        }
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uHeight - (GUI_BTN_H_2 + 20));

        m_pGUI->GetButton(GUI_BTN_SELECT_PRIOR)->SetLocation(m_uMidW, m_uHeight - 100);
        m_pGUI->GetButton(GUI_BTN_SELECT_NEXT)->SetLocation(m_uMidW + GUI_BTN_W_3 + 5, m_uHeight - 100);
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_ARENA)->SetLocation(50, m_uMidH - m_uMidH/2 + 25);
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_ARENA)->SetSize(200, m_uMidH/2);
        m_pGUI->GetStatic(GUI_STATIC_ARENA_INFO)->SetLocation(50, m_uMidH + 35);
        m_pGUI->GetStatic(GUI_STATIC_ARENA_MINFO)->SetLocation(50, m_uMidH + 95);

        m_pGUI->GetButton(GUI_BTN_SELECT_PRIOR)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_SELECT_NEXT)->m_bVisible = true;
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_ARENA)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_ARENA_INFO)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_ARENA_MINFO)->m_bVisible = true;

        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SELECT_VEHICLE1:
        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);
        switch(m_iTypeGame)
        {
        case GAME_1PLAYER:       setText(L"... one player - select a vehicle ...", GUI_STATIC_INFO); break;
        case GAME_2PLAYER_FIGHT: setText(L"... two players by fight - select a vehicle for player one ...", GUI_STATIC_INFO); break;
        case GAME_2PLAYER_OBJS:  setText(L"... two players by objectives - select a vehicle for player one ...", GUI_STATIC_INFO); break;
        }
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uHeight - (GUI_BTN_H_2 + 20));

        m_pGUI->GetButton(GUI_BTN_SELECT_PRIOR)->SetLocation(m_uMidW, m_uHeight - 100);
        m_pGUI->GetButton(GUI_BTN_SELECT_NEXT)->SetLocation(m_uMidW + GUI_BTN_W_3 + 5, m_uHeight - 100);
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI1)->SetLocation(50, m_uMidH - m_uMidH/2 + 25);
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI1)->SetSize(200, m_uMidH/2);
        m_pGUI->GetStatic(GUI_STATIC_VEHICLE_INFO)->SetLocation(50, m_uMidH + 35);
        m_pGUI->GetStatic(GUI_STATIC_VEHICLE_MINFO)->SetLocation(50, m_uMidH + 95);

        m_pGUI->GetButton(GUI_BTN_SELECT_PRIOR)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_SELECT_NEXT)->m_bVisible = true;
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI1)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_VEHICLE_INFO)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_VEHICLE_MINFO)->m_bVisible = true;

        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SELECT_VEHICLE2:
        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uMidW - 400, 30);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, 105);
        switch(m_iTypeGame)
        {
        case GAME_1PLAYER:       setText(L"... one player - select a vehicle ...", GUI_STATIC_INFO); break;
        case GAME_2PLAYER_FIGHT: setText(L"... two players by fight - select a vehicle for player two ...", GUI_STATIC_INFO); break;
        case GAME_2PLAYER_OBJS:  setText(L"... two players by objectives - select a vehicle for player two ...", GUI_STATIC_INFO); break;
        }
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uHeight - (GUI_BTN_H_2 + 20));
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uHeight - (GUI_BTN_H_2 + 20));

        m_pGUI->GetButton(GUI_BTN_SELECT_PRIOR)->SetLocation(m_uMidW, m_uHeight - 100);
        m_pGUI->GetButton(GUI_BTN_SELECT_NEXT)->SetLocation(m_uMidW + GUI_BTN_W_3 + 5, m_uHeight - 100);
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI2)->SetLocation(50, m_uMidH - m_uMidH/2 + 25);
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI2)->SetSize(200, m_uMidH/2);
        m_pGUI->GetStatic(GUI_STATIC_VEHICLE_INFO)->SetLocation(50, m_uMidH + 35);
        m_pGUI->GetStatic(GUI_STATIC_VEHICLE_MINFO)->SetLocation(50, m_uMidH + 95);

        m_pGUI->GetButton(GUI_BTN_SELECT_PRIOR)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_SELECT_NEXT)->m_bVisible = true;
        m_pGUI->GetListBox(GUI_LISTBOX_SELECT_VEHI2)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_VEHICLE_INFO)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_VEHICLE_MINFO)->m_bVisible = true;

        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_INTERFAZ_PREGAME:
	{
		TCHAR txt[MAX_STRING+1];

        m_bPaused = true;
        m_bGamming = false;

        m_pGUI->GetStatic(GUI_STATIC_WARNING)->SetLocation(m_uMidW - 400, m_uMidH - 210);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, m_uMidH - 130);
        m_pGUI->GetStatic(GUI_STATIC_GAME_INFO)->SetLocation(m_uMidW - 130, m_uMidH - 25);
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW - GUI_BTN_W_2/2, m_uMidH + 180);

        switch(m_iTypeGame)
        {
        case GAME_1PLAYER:
	        m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1)->SetLocation(m_uMidW - 92, m_uMidH + 28);
			m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1)->m_bVisible = true;
			setText(L"Controls:\n  - C KEY.........to change camera view\n  - P KEY..........to pause", GUI_STATIC_GAME_INFO);
			wsprintf(txt, L"Capture all the %d blue objectives in time\nand without damaging the vehicle\n\nYou'll start with %d seconds and\n%d seconds more per objective", (int)(g_Menu->getMGame()->getArena()->getNumObj()), (int)(g_Menu->getMGame()->getArena()->getTimeIni()), (int)(g_Menu->getMGame()->getArena()->getTimeObj()));
			break;
        case GAME_2PLAYER_FIGHT:
	        m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1)->SetLocation(m_uMidW - 193, m_uMidH + 28);
		    m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS2)->SetLocation(m_uMidW + 8, m_uMidH + 28);
			m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1)->m_bVisible = true;
			m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS2)->m_bVisible = true;
			setText(L"\nControls:\n  - P KEY..........to pause", GUI_STATIC_GAME_INFO);
			wsprintf(txt, L"Wins the last player alive so be carefull\ndriving the vehicle and using the weapons\n\nThere is no timer in this game");
			break;
        case GAME_2PLAYER_OBJS:
	        m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1)->SetLocation(m_uMidW - 193, m_uMidH + 28);
		    m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS2)->SetLocation(m_uMidW + 8, m_uMidH + 28);
			m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS1)->m_bVisible = true;
			m_pGUI->GetListBox(GUI_LISTBOX_CONTROLS2)->m_bVisible = true;
			setText(L"\nControls:\n  - P KEY..........to pause", GUI_STATIC_GAME_INFO);
			wsprintf(txt, L"Wins the first player who captures all the %d blue objectives\nin time and without damaging the vehicle\n\nYou'll start with %d seconds and\n%d seconds more per objective", (int)(g_Menu->getMGame()->getArena()->getNumObj()), (int)(g_Menu->getMGame()->getArena()->getTimeIni()), (int)(g_Menu->getMGame()->getArena()->getTimeObj()));
			break;
        }

		setText(g_Menu->getMGame()->getArena()->getName(), GUI_STATIC_WARNING);
		setText(txt, GUI_STATIC_INFO);

		m_pGUI->GetStatic(GUI_STATIC_WARNING)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_GAME_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        break;
	}
    //----------------------------------------------------------------------------------
    case GUI_TYPE_INTERFAZ_GAME:
	{
        m_bPaused = false;
        m_bGamming = true;

        // Guardamos la configuración por defecto con los controles de juego
        g_Settings->RefreshData(GUI_TYPE_SETT_GAME);

        m_pGUI->GetButton(GUI_BTN_GAME_PAUSE)->SetLocation(m_uWidth - GUI_BTN_W_3, m_uHeight - 50);
        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->SetLocation(m_uWidth-450, 10);
		int size = (int)(g_Menu->getMGame()->getArena()->getSize());
		m_pGUI->GetEditBox(GUI_EDITBOX_MAP)->SetSize(size+6, size+6);
		m_pGUI->GetEditBox(GUI_EDITBOX_MAP)->SetLocation(-2, m_uHeight - 24 - size);
        m_pGUI->GetStatic(GUI_STATIC_MAP_OBJ)->SetLocation(-100, -100);

        switch(m_iTypeGame)
        {
        case GAME_1PLAYER:
			m_pGUI->GetStatic(GUI_STATIC_P1_HEALTH)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_ROCKETS)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_MINES)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_OBJECTIVES)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_TOTAL_TIME)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_HEALTH)->SetLocation(5, 25);
			m_pGUI->GetStatic(GUI_STATIC_P1_ROCKETS)->SetLocation(5, 40);
			m_pGUI->GetStatic(GUI_STATIC_P1_MINES)->SetLocation(5, 55);
			m_pGUI->GetStatic(GUI_STATIC_P1_OBJECTIVES)->SetLocation(5, 70);
			m_pGUI->GetStatic(GUI_STATIC_TOTAL_TIME)->SetLocation(5, 90);
		    m_pGUI->GetStatic(GUI_STATIC_MAP_P1)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_MAP_P1)->SetLocation(-100, -100);
			break;
        case GAME_2PLAYER_FIGHT:
			m_pGUI->GetStatic(GUI_STATIC_P1_TITLE)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_HEALTH)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_ROCKETS)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_MINES)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_TITLE)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_HEALTH)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_ROCKETS)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_MINES)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_TOTAL_TIME)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_TITLE)->SetLocation(5, 25);
			m_pGUI->GetStatic(GUI_STATIC_P1_HEALTH)->SetLocation(8, 40);
			m_pGUI->GetStatic(GUI_STATIC_P1_ROCKETS)->SetLocation(8, 55);
			m_pGUI->GetStatic(GUI_STATIC_P1_MINES)->SetLocation(8, 70);
			m_pGUI->GetStatic(GUI_STATIC_P2_TITLE)->SetLocation(5, 90);
			m_pGUI->GetStatic(GUI_STATIC_P2_HEALTH)->SetLocation(8, 105);
			m_pGUI->GetStatic(GUI_STATIC_P2_ROCKETS)->SetLocation(8, 120);
			m_pGUI->GetStatic(GUI_STATIC_P2_MINES)->SetLocation(8, 135);
			m_pGUI->GetStatic(GUI_STATIC_TOTAL_TIME)->SetLocation(5, 155);
			m_pGUI->GetStatic(GUI_STATIC_MAP_P1)->m_bVisible = true;
	        m_pGUI->GetStatic(GUI_STATIC_MAP_P2)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_MAP_P1)->SetLocation(-100, -100);
			m_pGUI->GetStatic(GUI_STATIC_MAP_P2)->SetLocation(-100, -100);
			break;
        case GAME_2PLAYER_OBJS:
			m_pGUI->GetStatic(GUI_STATIC_P1_TITLE)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_HEALTH)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_ROCKETS)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_MINES)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_OBJECTIVES)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_TITLE)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_HEALTH)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_ROCKETS)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_MINES)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P2_OBJECTIVES)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_TOTAL_TIME)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_P1_TITLE)->SetLocation(5, 25);
			m_pGUI->GetStatic(GUI_STATIC_P1_HEALTH)->SetLocation(8, 40);
			m_pGUI->GetStatic(GUI_STATIC_P1_ROCKETS)->SetLocation(8, 55);
			m_pGUI->GetStatic(GUI_STATIC_P1_MINES)->SetLocation(8, 70);
			m_pGUI->GetStatic(GUI_STATIC_P1_OBJECTIVES)->SetLocation(8, 85);
			m_pGUI->GetStatic(GUI_STATIC_P2_TITLE)->SetLocation(5, 105);
			m_pGUI->GetStatic(GUI_STATIC_P2_HEALTH)->SetLocation(8, 120);
			m_pGUI->GetStatic(GUI_STATIC_P2_ROCKETS)->SetLocation(8, 135);
			m_pGUI->GetStatic(GUI_STATIC_P2_MINES)->SetLocation(8, 150);
			m_pGUI->GetStatic(GUI_STATIC_P2_OBJECTIVES)->SetLocation(8, 165);
			m_pGUI->GetStatic(GUI_STATIC_TOTAL_TIME)->SetLocation(5, 185);
			m_pGUI->GetStatic(GUI_STATIC_MAP_P1)->m_bVisible = true;
	        m_pGUI->GetStatic(GUI_STATIC_MAP_P2)->m_bVisible = true;
			m_pGUI->GetStatic(GUI_STATIC_MAP_P1)->SetLocation(-100, -100);
			m_pGUI->GetStatic(GUI_STATIC_MAP_P2)->SetLocation(-100, -100);
			break;
        }
        m_pGUI->GetButton(GUI_BTN_GAME_PAUSE)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_TITULO_2)->m_bVisible = true;
		m_pGUI->GetEditBox(GUI_EDITBOX_MAP)->m_bVisible = true;
		m_pGUI->GetStatic(GUI_STATIC_MAP_OBJ)->m_bVisible = true;
        break;
	}
    //----------------------------------------------------------------------------------
    case GUI_TYPE_PAUSE_GAME:
        m_bPaused = true;

		m_pGUI->GetStatic(GUI_STATIC_WARNING)->SetLocation(m_uMidW - 400, m_uMidH - 120);
        m_pGUI->GetButton(GUI_BTN_GAME_PAUSE)->SetLocation(m_uWidth - GUI_BTN_W_3, m_uHeight - 50);
        m_pGUI->GetButton(GUI_BTN_GAME_OPTIONS)->SetLocation(m_uWidth - GUI_BTN_W_3, m_uHeight - 100);
        m_pGUI->GetButton(GUI_BTN_GAME_EXIT)->SetLocation(m_uWidth - GUI_BTN_W_3, m_uHeight - 80);

		setText(L"PAUSED", GUI_STATIC_WARNING);

		m_pGUI->GetStatic(GUI_STATIC_WARNING)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_GAME_PAUSE)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_GAME_OPTIONS)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_GAME_EXIT)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_WARNING:
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, m_uMidH - 50);
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW - GUI_BTN_W_2/2, m_uMidH + 20);

        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_WARNING_EXIT:
        m_pGUI->GetStatic(GUI_STATIC_WARNING)->SetLocation(m_uMidW - 400, m_uMidH - 80);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, m_uMidH);
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uMidH + 70);
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uMidH + 70);

		setText(L"SURE?", GUI_STATIC_WARNING);
		setText(L"... you'll miss the current game ...\n\nare you sure?", GUI_STATIC_INFO);

		m_pGUI->GetStatic(GUI_STATIC_WARNING)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_WARNING_WIN:
	{
		TCHAR txt[MAX_STRING+1];

        m_pGUI->GetStatic(GUI_STATIC_WARNING)->SetLocation(m_uMidW - 400, m_uMidH - 120);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, m_uMidH - 40);

        switch(m_iTypeGame)
        {
        case GAME_1PLAYER:
			setText(L"YOU WIN", GUI_STATIC_WARNING);
			wsprintf(txt, L"Congratulations\n... all objectives have been caught in %d seconds ...\n\n... write your name ...", (int)(g_TimeGame));
			setText(txt, GUI_STATIC_INFO);
	        m_pGUI->GetEditBox(GUI_EDITBOX_SETT_NAME)->SetLocation(m_uMidW - GUI_SETT_W/2, m_uMidH + 40);
	        m_pGUI->GetEditBox(GUI_EDITBOX_SETT_NAME)->m_bVisible = true;
			m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW - GUI_BTN_W_2/2, m_uMidH + 100);
			m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
			break;
        case GAME_2PLAYER_OBJS:
			if (g_Menu->getMGame()->getLocalPlayer1()->getObjectives() >= g_Menu->getMGame()->getArena()->getNumObj())
				setText(L"PLAYER 1 WINS", GUI_STATIC_WARNING);
			else
				setText(L"PLAYER 2 WINS", GUI_STATIC_WARNING);
			wsprintf(txt, L"Congratulations\n... all objectives have been caught in %d seconds ...\n\n\nplay again?", (int)(g_TimeGame));
			setText(txt, GUI_STATIC_INFO);
			m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uMidH + 90);
			m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uMidH + 90);
			m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
			m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
			break;
        }

		m_pGUI->GetStatic(GUI_STATIC_WARNING)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        break;
	}
    //----------------------------------------------------------------------------------
    case GUI_TYPE_WARNING_RANK:
        m_pGUI->GetStatic(GUI_STATIC_WARNING)->SetLocation(m_uMidW - 400, m_uMidH - 120);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, m_uMidH + 110);
        m_pGUI->GetStatic(GUI_STATIC_RANK)->SetLocation(m_uMidW - 170, m_uMidH - 20);
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uMidH + 150);
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uMidH + 150);

		// Insertamos el nuevo elemento del ranking
		Rank R;
		wcscpy(R.m_Player, m_pGUI->GetEditBox(GUI_EDITBOX_SETT_NAME)->GetText());
		wcscpy(R.m_Vehicle, g_Menu->getMGame()->getLocalPlayer1()->getVehicle()->getName());
		R.m_Time = g_TimeGame;
		g_Menu->getMGame()->getArena()->addRanking(R);

		setText(L"RANKING", GUI_STATIC_WARNING);
		setText(g_Menu->getMGame()->getArena()->getRankTxt(), GUI_STATIC_RANK);
		setText(L"play again?", GUI_STATIC_INFO);

		m_pGUI->GetStatic(GUI_STATIC_WARNING)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_RANK)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_WARNING_LOST:
	{
		TCHAR txt[MAX_STRING+1];

        m_pGUI->GetStatic(GUI_STATIC_WARNING)->SetLocation(m_uMidW - 400, m_uMidH - 80);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, m_uMidH);
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uMidH + 90);
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uMidH + 90);

        switch(m_iTypeGame)
        {
        case GAME_1PLAYER:
			setText(L"YOU LOSE", GUI_STATIC_WARNING);
			wsprintf(txt, L"... the time is out ...\n... after %d seconds and %d of %d objectives ...\n\nplay again?",
				(int)(g_TimeGame),
				(int)(g_Menu->getMGame()->getLocalPlayer1()->getObjectives()),
				(int)(g_Menu->getMGame()->getArena()->getNumObj()) );
			setText(txt, GUI_STATIC_INFO);
			break;
        case GAME_2PLAYER_OBJS:
			setText(L"BOTH LOSE", GUI_STATIC_WARNING);
			wsprintf(txt, L"... the time is out ...\n... after %d seconds ...\n\nplay again?",
				(int)(g_TimeGame) );
			setText(txt, GUI_STATIC_INFO);
			break;
        }

		m_pGUI->GetStatic(GUI_STATIC_WARNING)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
	}
    //----------------------------------------------------------------------------------
    case GUI_TYPE_WARNING_DIE:
	{
		TCHAR txt[MAX_STRING+1];

        m_pGUI->GetStatic(GUI_STATIC_WARNING)->SetLocation(m_uMidW - 400, m_uMidH - 80);
        m_pGUI->GetStatic(GUI_STATIC_INFO)->SetLocation(m_uMidW - 400, m_uMidH);
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->SetLocation(m_uMidW + GUI_BTN_W_SPACE, m_uMidH + 90);
        m_pGUI->GetButton(GUI_BTN_CANCEL)->SetLocation(m_uMidW - (GUI_BTN_W_2 + GUI_BTN_W_SPACE), m_uMidH + 90);

        switch(m_iTypeGame)
        {
        case GAME_1PLAYER:
			setText(L"YOU LOSE", GUI_STATIC_WARNING);
			wsprintf(txt, L"... your vehicle is damaged ...\n... after %d seconds and %d of %d objectives ...\n\nplay again?",
				(int)(g_TimeGame),
				(int)(g_Menu->getMGame()->getLocalPlayer1()->getObjectives()),
				(int)(g_Menu->getMGame()->getArena()->getNumObj()) );
			setText(txt, GUI_STATIC_INFO);
			break;
        case GAME_2PLAYER_FIGHT:
        case GAME_2PLAYER_OBJS:
			if (g_Menu->getMGame()->getLocalPlayer1()->getHealth() <= 0.0f)
			{
				setText(L"PLAYER 2 WINS", GUI_STATIC_WARNING);
				wsprintf(txt, L"... the vehicle of player 1 is damaged ...\n... after %d seconds ...\n\nplay again?",
					(int)(g_TimeGame) );
				setText(txt, GUI_STATIC_INFO);
			}
			else
			{
				setText(L"PLAYER 1 WINS", GUI_STATIC_WARNING);
				wsprintf(txt, L"... the vehicle of player 2 is damaged ...\n... after %d seconds ...\n\nplay again?",
					(int)(g_TimeGame) );
				setText(txt, GUI_STATIC_INFO);
			}
			break;
        }

		m_pGUI->GetStatic(GUI_STATIC_WARNING)->m_bVisible = true;
        m_pGUI->GetStatic(GUI_STATIC_INFO)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_ACCEPT)->m_bVisible = true;
        m_pGUI->GetButton(GUI_BTN_CANCEL)->m_bVisible = true;
        break;
	}
    //----------------------------------------------------------------------------------
    }
}

//--------------------------------------------------------------------------------------
// Establece la siguiente arena de la lista
//--------------------------------------------------------------------------------------
bool CGUI::nextArena(void)
{
	if(m_iArena+1>m_inumArenas-1)
		return setArena(0);
	return setArena(m_iArena+1);
}

//--------------------------------------------------------------------------------------
// Establece la anterior arena de la lista
//--------------------------------------------------------------------------------------
bool CGUI::priorArena(void)
{
	if(m_iArena-1<0)
		return setArena(m_inumArenas-1);
	return setArena(m_iArena-1);
}

//--------------------------------------------------------------------------------------
// Establece el siguiente vehículo de la lista
//--------------------------------------------------------------------------------------
bool CGUI::nextVehicle(void)
{
	if (getTypeGUI() == GUI_TYPE_SELECT_VEHICLE1)
	{
		if(m_iVehicle1 + 1 > m_inumVehicles - 1)
			return setVehicle(1, 0);
		return setVehicle(1, m_iVehicle1+1);
	}
	else
	{
		if(m_iVehicle2 + 1 > m_inumVehicles - 1)
			return setVehicle(2, 0);
		return setVehicle(2, m_iVehicle2 + 1);
	}
}

//--------------------------------------------------------------------------------------
// Establece el anterior vehículo de la lista
//--------------------------------------------------------------------------------------
bool CGUI::priorVehicle(void)
{
	if (getTypeGUI() == GUI_TYPE_SELECT_VEHICLE1)
	{
		if(m_iVehicle1 - 1 < 0)
			return setVehicle(1, m_inumVehicles - 1);
		return setVehicle(1, m_iVehicle1 - 1);
	}
	else
	{
		if(m_iVehicle2 - 1 < 0)
			return setVehicle(2, m_inumVehicles - 1);
		return setVehicle(2, m_iVehicle2 - 1);
	}
}

//--------------------------------------------------------------------------------------
// Para manejar los eventos del GUI
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl )
{
    if(g_bCreated)
    switch( nControlID )
    {

    //----------------------------------------------------------------------------------
    case GUI_BTN_ACCEPT:
    //----------------------------------------------------------------------------------
        switch(g_GUI->getTypeGUI())
        {
        case GUI_TYPE_WARNING:
			g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
            break;
        case GUI_TYPE_WARNING_EXIT:
            g_Menu->setTypeMenu(MENU_TYPE_MENU);
            g_GUI->setTypeGUI(GUI_TYPE_MENU_INIT);
            break;
		case GUI_TYPE_WARNING_RANK:
        case GUI_TYPE_WARNING_LOST:
        case GUI_TYPE_WARNING_DIE:
		{
            // Creamos el juego
            g_Menu->setTypeMenu(MENU_TYPE_GAME, g_GUI->getLocalPlayerName(), g_GUI->getTypeGame());
            // Mostramos la información de partida
            g_GUI->setTypeGUI(GUI_TYPE_INTERFAZ_PREGAME);
            g_Menu->setTypeMenu(MENU_TYPE_PREGAME);
			// Actualizamos los jugadores
			CPlayerLocal *Player1 = g_Menu->getMGame()->getLocalPlayer1();
			CPlayerLocal *Player2 = g_Menu->getMGame()->getLocalPlayer2();
			if (Player1) Player1->update();
			if (Player2) Player2->update();
            break;
		}
        case GUI_TYPE_WARNING_WIN:
			// Según el tipo de juego
			switch(g_GUI->getTypeGame())
			{
			case GAME_1PLAYER:
				g_GUI->setTypeGUI(GUI_TYPE_WARNING_RANK);
				break;
			case GAME_2PLAYER_OBJS:
				{
					// Creamos el juego
					g_Menu->setTypeMenu(MENU_TYPE_GAME, g_GUI->getLocalPlayerName(), g_GUI->getTypeGame());
					// Mostramos la información de partida
					g_GUI->setTypeGUI(GUI_TYPE_INTERFAZ_PREGAME);
					g_Menu->setTypeMenu(MENU_TYPE_PREGAME);
					// Actualizamos los jugadores
					CPlayerLocal *Player1 = g_Menu->getMGame()->getLocalPlayer1();
					CPlayerLocal *Player2 = g_Menu->getMGame()->getLocalPlayer2();
					if (Player1) Player1->update();
					if (Player2) Player2->update();
					break;
				}
			}
            break;
        case GUI_TYPE_SETT:
            if(g_GUI->getGamming())  g_GUI->setTypeGUI(GUI_TYPE_PAUSE_GAME);
            else                     g_GUI->setTypeGUI(GUI_TYPE_MENU_INIT);
            break;
        case GUI_TYPE_SETT_DISPLAY:
            g_Settings->RefreshData(GUI_TYPE_SETT_DISPLAY);
            g_Settings->Apply(GUI_TYPE_SETT_DISPLAY);
            g_GUI->setTypeGUI(GUI_TYPE_SETT);
            break;
        case GUI_TYPE_SETT_SOUND:
            g_Settings->RefreshData(GUI_TYPE_SETT_SOUND);
            g_Settings->Apply(GUI_TYPE_SETT_SOUND);
            g_GUI->setTypeGUI(GUI_TYPE_SETT);
            break;
        case GUI_TYPE_SETT_GAME:
            if(g_GUI->getGUI()->GetEditBox(GUI_EDITBOX_SETT_NAME)->GetTextLength() == 0)
            {
                g_GUI->setText(L"INVALID PLAYER'S NAME\ninsert a valid player's name to continue\n...press OK to return to the dialog...", GUI_STATIC_INFO);
                g_GUI->setTypeGUI(GUI_TYPE_WARNING);
            }
            else
            {
                g_Settings->RefreshData(GUI_TYPE_SETT_GAME);
                g_Settings->Apply(GUI_TYPE_SETT_GAME);
                g_GUI->setTypeGUI(GUI_TYPE_SETT);
            }
            break;
        case GUI_TYPE_SELECT_ARENA:
            g_GUI->setTypeGUI(GUI_TYPE_SELECT_VEHICLE1);
			if(!g_GUI->setVehicle(1, -1)) g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
            break;
        case GUI_TYPE_SELECT_VEHICLE1:
		{
			// Si hemos elegido sólo un jugador, comenzamos la partida
			if (g_GUI->getTypeGame() == GAME_1PLAYER)
			{
				// Creamos el juego
				g_Menu->setTypeMenu(MENU_TYPE_GAME, g_GUI->getLocalPlayerName(), g_GUI->getTypeGame());
				// Mostramos la información de partida
				g_GUI->setTypeGUI(GUI_TYPE_INTERFAZ_PREGAME);
				g_Menu->setTypeMenu(MENU_TYPE_PREGAME);
				// Actualizamos los jugadores
				CPlayerLocal *Player1 = g_Menu->getMGame()->getLocalPlayer1();
				CPlayerLocal *Player2 = g_Menu->getMGame()->getLocalPlayer2();
				if (Player1) Player1->update();
				if (Player2) Player2->update();
			}
			// Si hemos elegido dos jugadores, elegimos el vehículo del segundo
			else
			{
				g_GUI->setTypeGUI(GUI_TYPE_SELECT_VEHICLE2);
				if(!g_GUI->setVehicle(2, -1)) g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
			}
            break;
		}
        case GUI_TYPE_SELECT_VEHICLE2:
		{
            // Creamos el juego
            g_Menu->setTypeMenu(MENU_TYPE_GAME, g_GUI->getLocalPlayerName(), g_GUI->getTypeGame());
            // Mostramos la información de partida
            g_GUI->setTypeGUI(GUI_TYPE_INTERFAZ_PREGAME);
            g_Menu->setTypeMenu(MENU_TYPE_PREGAME);
			// Actualizamos los jugadores
			CPlayerLocal *Player1 = g_Menu->getMGame()->getLocalPlayer1();
			CPlayerLocal *Player2 = g_Menu->getMGame()->getLocalPlayer2();
			if (Player1) Player1->update();
			if (Player2) Player2->update();
            break;
		}
		case GUI_TYPE_INTERFAZ_PREGAME:
		{
			// Mostramos el juego
            g_GUI->setTypeGUI(GUI_TYPE_INTERFAZ_GAME);
            g_Menu->setTypeMenu(MENU_TYPE_GAME);
            break;
		}
        case GUI_TYPE_PAUSE_GAME:
			// Mostramos el juego
            g_GUI->setTypeGUI(GUI_TYPE_INTERFAZ_GAME);
            break;
        }
        break;

    //----------------------------------------------------------------------------------
    case GUI_BTN_CANCEL:
    //----------------------------------------------------------------------------------
        switch(g_GUI->getTypeGUI())
        {
        case GUI_TYPE_WARNING_EXIT:
            g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
            break;
		case GUI_TYPE_WARNING_RANK:
        case GUI_TYPE_WARNING_LOST:
        case GUI_TYPE_WARNING_DIE:
            g_Menu->setTypeMenu(MENU_TYPE_MENU);
            g_GUI->setTypeGUI(GUI_TYPE_MENU_INIT);
            break;
        case GUI_TYPE_WARNING_WIN:
			// Según el tipo de juego
			switch(g_GUI->getTypeGame())
			{
			case GAME_2PLAYER_OBJS:
				g_Menu->setTypeMenu(MENU_TYPE_MENU);
				g_GUI->setTypeGUI(GUI_TYPE_MENU_INIT);
				break;
			}
            break;
        case GUI_TYPE_SETT_DISPLAY:    g_GUI->setTypeGUI(GUI_TYPE_SETT);break;
        case GUI_TYPE_SETT_SOUND:      g_GUI->setTypeGUI(GUI_TYPE_SETT);break;
        case GUI_TYPE_SETT_GAME:       g_GUI->setTypeGUI(GUI_TYPE_SETT);break;
        case GUI_TYPE_NEW_GAME:        g_GUI->setTypeGUI(GUI_TYPE_MENU_INIT);break;
        case GUI_TYPE_NEW_GAME2:       g_GUI->setTypeGUI(GUI_TYPE_NEW_GAME);break;
        case GUI_TYPE_SELECT_ARENA:
			g_Menu->getMArena()->setEnabled(false);
			if (g_GUI->getTypeGame() == GAME_1PLAYER)
				g_GUI->setTypeGUI(GUI_TYPE_NEW_GAME);
			else
				g_GUI->setTypeGUI(GUI_TYPE_NEW_GAME2);
			g_Menu->setTypeMenu(MENU_TYPE_MENU);
            break;
        case GUI_TYPE_SELECT_VEHICLE1:
            g_GUI->setTypeGUI(GUI_TYPE_SELECT_ARENA);
			if(!g_GUI->setArena(-1)) g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
            break;
        case GUI_TYPE_SELECT_VEHICLE2:
			g_GUI->setTypeGUI(GUI_TYPE_SELECT_VEHICLE1);
			if(!g_GUI->setVehicle(1, -1)) g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
            break;
        case GUI_TYPE_PAUSE_GAME:
			// Mostramos el juego
			g_GUI->setTypeGUI(GUI_TYPE_INTERFAZ_GAME);
			break;
        }
        break;

    //----------------------------------------------------------------------------------
    case GUI_BTN_NEWGAME:
        // Inicializamos algunas variables y elementos de la configuración del juego
        g_GUI->iniGameConfig();
        // Comenzamos el asistente del nuevo juego
        g_GUI->setTypeGUI(GUI_TYPE_NEW_GAME);
        break;
    case GUI_BTN_1PLAYER:
        g_GUI->setTypeGame(GAME_1PLAYER);
        g_GUI->setTypeGUI(GUI_TYPE_SELECT_ARENA);
		if(!g_GUI->setArena(-1)) g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
        break;
    case GUI_BTN_2PLAYER:
        g_GUI->setTypeGUI(GUI_TYPE_NEW_GAME2);
        break;
    case GUI_BTN_2PLAYER_FIGHT:
        g_GUI->setTypeGame(GAME_2PLAYER_FIGHT);
        g_GUI->setTypeGUI(GUI_TYPE_SELECT_ARENA);
		if(!g_GUI->setArena(-1)) g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
        break;
    case GUI_BTN_2PLAYER_OBJS:
        g_GUI->setTypeGame(GAME_2PLAYER_OBJS);
        g_GUI->setTypeGUI(GUI_TYPE_SELECT_ARENA);
		if(!g_GUI->setArena(-1)) g_GUI->setTypeGUI(g_GUI->getOldTypeGUI());
        break;
    case GUI_CMBBX_SETT_QUALITY:
    case GUI_CMBBX_SETT_WINFULL:
        g_GUI->setTypeGUI(g_GUI->getTypeGUI());
        break;
    case GUI_SLIDER_SETT_EFFECTS:
        g_GUI->setMarcador(g_GUI->getGUI()->GetSlider(nControlID)->GetValue(), GUI_STATIC_COUNTER);
        break;
    case GUI_BTN_GAME_PAUSE:
		// Pausamos o mostramos el juego
        if(g_GUI->getPaused())
        {
            g_GUI->setTypeGUI(GUI_TYPE_INTERFAZ_GAME);
            g_Menu->setTypeMenu(MENU_TYPE_GAME);
        }
        else
        {
            g_GUI->setTypeGUI(GUI_TYPE_PAUSE_GAME);
            g_Menu->setTypeMenu(MENU_TYPE_PAUSE);
        }
        break;
    case GUI_BTN_GAME_OPTIONS:
        if(g_GUI->getTypeGUI() == GUI_TYPE_PAUSE_GAME)
            g_GUI->setTypeGUI(GUI_TYPE_SETT);
        break;
    case GUI_BTN_GAME_EXIT:
        if(g_GUI->getTypeGUI() == GUI_TYPE_PAUSE_GAME)
			g_GUI->setTypeGUI(GUI_TYPE_WARNING_EXIT);
        break;

    //----------------------------------------------------------------------------------
    // Navegación por arenas y por coches en SELECT_ARENA y SELECT_VEHICLE
    case GUI_BTN_SELECT_NEXT:
        switch(g_GUI->getTypeGUI())
        {
        case GUI_TYPE_SELECT_ARENA:
			g_GUI->nextArena();
			break;
        case GUI_TYPE_SELECT_VEHICLE1:
        case GUI_TYPE_SELECT_VEHICLE2:
			g_GUI->nextVehicle();
			break;
        }
        break;
    case GUI_BTN_SELECT_PRIOR:
        switch(g_GUI->getTypeGUI())
        {
        case GUI_TYPE_SELECT_ARENA:
			g_GUI->priorArena();
			break;
        case GUI_TYPE_SELECT_VEHICLE1:
        case GUI_TYPE_SELECT_VEHICLE2:
			g_GUI->priorVehicle();
			break;
        }
        break;
    case GUI_LISTBOX_SELECT_ARENA:
        g_GUI->setArena(g_GUI->getGUI()->GetListBox(GUI_LISTBOX_SELECT_ARENA)->GetSelectedIndex());
        break;
    case GUI_LISTBOX_SELECT_VEHI1:
		if (g_GUI->getGUI()->GetListBox(GUI_LISTBOX_SELECT_VEHI1)->GetEnabled())
			g_GUI->setVehicle(1, g_GUI->getGUI()->GetListBox(GUI_LISTBOX_SELECT_VEHI1)->GetSelectedIndex());
        break;
    case GUI_LISTBOX_SELECT_VEHI2:
		if (g_GUI->getGUI()->GetListBox(GUI_LISTBOX_SELECT_VEHI2)->GetEnabled())
			g_GUI->setVehicle(2, g_GUI->getGUI()->GetListBox(GUI_LISTBOX_SELECT_VEHI2)->GetSelectedIndex());
        break;
    //----------------------------------------------------------------------------------
    case GUI_BTN_SETT:
        g_GUI->setTypeGUI(GUI_TYPE_SETT);
        break;
    case GUI_BTN_SETT_DISPLAY:
        g_Settings->RefreshControls(GUI_TYPE_SETT_DISPLAY);
        g_GUI->setTypeGUI(GUI_TYPE_SETT_DISPLAY);
        break;
    case GUI_BTN_SETT_SOUND:
        g_Settings->RefreshControls(GUI_TYPE_SETT_SOUND);
        g_GUI->setTypeGUI(GUI_TYPE_SETT_SOUND);
        break;
    case GUI_BTN_SETT_GAME:
        g_Settings->RefreshControls(GUI_TYPE_SETT_GAME);
        g_GUI->setTypeGUI(GUI_TYPE_SETT_GAME);
        break;
    //----------------------------------------------------------------------------------
    case GUI_BTN_EXIT:
        SendMessage( DXUTGetHWND(), WM_CLOSE, 0, 0 );
        break;
    }
}
