//--------------------------------------------------------------------------------------
// 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.
//--------------------------------------------------------------------------------------
// Settings.c
//--------------------------------------------------------------------------------------
#include "dxstdafx.h"
#include "Settings.h"
#include "XMLIO.h"
#include "3DSoundMng.h"
#include "GUI.h"

//--------------------------------------------------------------------------------------
// Variables Globales
//--------------------------------------------------------------------------------------
CSettings               *g_Settings;       // Instancia para las opciones
extern C3DSoundMng      *g_3DSoundMng;     // Instancia externa para manejar sonidos 3D (3DSoundMng.cpp)
extern CGUI             *g_GUI;            // Instancia externa para el GUI (GUI.cpp)

//--------------------------------------------------------------------------------------
// Funciones globales
//--------------------------------------------------------------------------------------
/// Retorna las cadenas correspondientes a cada elemento de configuración del GUI
LPWSTR Setting2WSTR(int nameSettings)
{
    switch (nameSettings)
    {
    // Display
    case GUI_TYPE_SETT_DISPLAY:     return L"display";
    case GUI_CMBBX_SETT_QUALITY:    return L"quality";
    case GUI_CMBBX_SETT_WINFULL:    return L"winfull";
    case GUI_CMBBX_SETT_STADISTICS: return L"stadistics";
    case GUI_CMBBX_SETT_RESOLUTION: return L"resolution";
    case GUI_CMBBX_SETT_FILTER:     return L"filter";
    case GUI_CMBBX_SETT_MIPMAPPING: return L"mipmapping";

    // Sound
    case GUI_TYPE_SETT_SOUND:       return L"sound";
    case GUI_SLIDER_SETT_EFFECTS:   return L"effects";

    // Game
    case GUI_TYPE_SETT_GAME:        return L"game";
    case GUI_EDITBOX_SETT_NAME:     return L"player";

    default:                        return L"Unknown";
    }
}

//--------------------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------------------
CSettings::CSettings()
{
    // Inicializamos variables
    m_bChanges = false;
    m_bChangesFile = false;

    // Se carga la nueva instancia de CXMLIO
    m_pXMLIO = new CXMLIO;
    assert(m_pXMLIO != NULL);

    // Cargamos la configuración del fichero
    LoadFile();
}

//--------------------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------------------
CSettings::~CSettings()
{
    // Guardamos el fichero si estaba pendiente
    if(m_bChangesFile) SaveFile();

    // Liberamos el parseador de XML
    SAFE_DELETE(m_pXMLIO);
}

//--------------------------------------------------------------------------------------
// Para cargar los datos de configuración del fichero externo
//--------------------------------------------------------------------------------------
void CSettings::LoadFile(void)
{
    WCHAR value[MAX_STRING+1];
    int v_int1, v_int2;

	//--------------------------------------------------------------------------------------
    // Cargamos los datos por defecto
    // Display
    m_DataSettings.m_iQuality = SETTINGS_DFL_QUALITY;
    m_DataSettings.m_iWinFull = SETTINGS_DFL_WINFULL;
    m_DataSettings.m_iStadistics = SETTINGS_DFL_STADISTICS;
    m_DataSettings.m_ulResolution = SETTINGS_DFL_RESOLUTION;
    m_DataSettings.m_iFilter = SETTINGS_DFL_FILTER;
    m_DataSettings.m_iMipMapping = SETTINGS_DFL_MIPMAPPING;

    // Sound
    m_DataSettings.m_iEffects = SETTINGS_DFL_EFFECTS;

    // Game
    lstrcpynW(m_DataSettings.m_awNomPlayer, SETTINGS_DFL_NOMPLAYER, MAX_STRING);

	//--------------------------------------------------------------------------------------
    // Cargamos los datos del fichero de configuracion
    if(m_pXMLIO->LoadFile(SETTINGS_FILE))
    {
        // Display
        if(m_pXMLIO->MoveSubElement(Setting2WSTR(GUI_TYPE_SETT_DISPLAY)))
        {
            if(m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_QUALITY), L"type", value))
            {
                v_int1 = _wtoi(value);
                if(v_int1 >= 0 && v_int1 <= SETTINGS_Q_LOW)
                    m_DataSettings.m_iQuality = v_int1;
            }
            if(m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_WINFULL), L"enabled", value))
            {
                v_int1 = _wtoi(value);
                if(v_int1 == 0 || v_int1 == 1)
                    m_DataSettings.m_iWinFull = v_int1;
            }
            if(m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_STADISTICS), L"enabled", value))
            {
                v_int1 = _wtoi(value);
                if(v_int1 == 0 || v_int1 == 1)
                    m_DataSettings.m_iStadistics = v_int1;
            }
            if(m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_RESOLUTION), L"width", value))
            {
                v_int1 = _wtoi(value);
                if(m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_RESOLUTION), L"height", value))
                {
                    v_int2 = _wtoi(value);
                    if(v_int1 > 0 && v_int2 > 0)
                        m_DataSettings.m_ulResolution = MAKELONG(v_int1, v_int2);
                }
            }
            if(m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_FILTER), L"type", value))
            {
                v_int1 = _wtoi(value);
                if(v_int1 >= 0 && v_int1 <= SETTINGS_F_ANISOT)
                    m_DataSettings.m_iFilter = v_int1;
            }
            if(m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_MIPMAPPING), L"enabled", value))
            {
                v_int1 = _wtoi(value);
                if(v_int1 == 0 || v_int1 == 1)
                    m_DataSettings.m_iMipMapping = v_int1;
            }

            m_pXMLIO->MoveParent();
        }

        // Sound
        if(m_pXMLIO->MoveSubElement(Setting2WSTR(GUI_TYPE_SETT_SOUND)))
        {
            if(m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_SLIDER_SETT_EFFECTS), L"volume", value))
            {
                v_int1 = _wtoi(value);
                if(v_int1 >= 0 && v_int1 <= 100)
                    m_DataSettings.m_iEffects = v_int1;
            }

            m_pXMLIO->MoveParent();
        }

        // Game
        if(m_pXMLIO->MoveSubElement(Setting2WSTR(GUI_TYPE_SETT_GAME)))
        {
            m_pXMLIO->GetSubAttribute(Setting2WSTR(GUI_EDITBOX_SETT_NAME), L"name", m_DataSettings.m_awNomPlayer);

            m_pXMLIO->MoveParent();
        }

    }

    // Si no existe el fichero o hubo errores los datos por defecto quedan pendientes de aplicarse al fichero
    else m_bChangesFile = true;

    // Los nuevos datos quedan pendientes de aplicarse en la aplicación
    m_bChanges = true;
}

//--------------------------------------------------------------------------------------
// Para guardar los datos de configuración del fichero externo
//--------------------------------------------------------------------------------------
void CSettings::SaveFile(void)
{
    // Cargamos los datos del fichero de configuracion
    if(m_pXMLIO->CreateFile(SETTINGS_FILE, L"settings") && m_pXMLIO->LoadFile(SETTINGS_FILE))
    {
        WCHAR value[MAX_STRING+1];

        // Display
        m_pXMLIO->MoveRoot();
		m_pXMLIO->SetSubElement(Setting2WSTR(GUI_TYPE_SETT_DISPLAY), L"");
		m_pXMLIO->MoveSubElement(Setting2WSTR(GUI_TYPE_SETT_DISPLAY));

        _itow(m_DataSettings.m_iQuality, value, 10);
        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_QUALITY), L"type", value);
        _itow(m_DataSettings.m_iWinFull, value, 10);
        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_WINFULL), L"enabled", value);
        _itow(m_DataSettings.m_iStadistics, value, 10);
        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_STADISTICS), L"enabled", value);
        _itow(getWidth(), value, 10);
        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_RESOLUTION), L"width", value);
        _itow(getHeigth(), value, 10);
        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_RESOLUTION), L"height", value);
        _itow(m_DataSettings.m_iFilter, value, 10);
        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_FILTER), L"type", value);
        _itow(m_DataSettings.m_iMipMapping, value, 10);
        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_CMBBX_SETT_MIPMAPPING), L"enabled", value);

        // Sound
        m_pXMLIO->MoveRoot();
		m_pXMLIO->SetSubElement(Setting2WSTR(GUI_TYPE_SETT_SOUND), L"");
		m_pXMLIO->MoveSubElement(Setting2WSTR(GUI_TYPE_SETT_SOUND));

        _itow(m_DataSettings.m_iEffects, value, 10);
        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_SLIDER_SETT_EFFECTS), L"volume", value);

        // Game
        m_pXMLIO->MoveRoot();
		m_pXMLIO->SetSubElement(Setting2WSTR(GUI_TYPE_SETT_GAME), L"");
		m_pXMLIO->MoveSubElement(Setting2WSTR(GUI_TYPE_SETT_GAME));

        m_pXMLIO->SetSubAttribute(Setting2WSTR(GUI_EDITBOX_SETT_NAME), L"name", m_DataSettings.m_awNomPlayer);

		// Salvamos el fichero
        m_pXMLIO->SaveFile(SETTINGS_FILE);
        m_bChangesFile = false;
    }
}

//--------------------------------------------------------------------------------------
// Aplica la configuración establecida
//--------------------------------------------------------------------------------------
void CSettings::Apply(int Section)
{
    if(!m_bChanges) return;

    switch(Section)
    {
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_DISPLAY:
    {
        IDirect3DDevice9* pDevice = DXUTGetD3DDevice();
        DXUTDeviceSettings deviceSettings = DXUTGetDeviceSettings();
        CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
        if(!pD3DEnum) return;
        CD3DEnumAdapterInfo* adapterInfo = pD3DEnum->GetAdapterInfo(deviceSettings.AdapterOrdinal);
        if(!adapterInfo) return;

        // GUI_CMBBX_SETT_QUALITY
        DWORD loWidth=0, loHeight=0, mdWidth=0, mdHeight=0, hiWidth=0, hiHeight=0;
        bool nextMid = false;
        for(int i = 0; i < adapterInfo->displayModeList.GetSize(); i++)
        {
            D3DDISPLAYMODE DisplayMode = adapterInfo->displayModeList.GetAt(i);
            if(i == adapterInfo->displayModeList.GetSize() / 2)
                nextMid = true;
            if(DisplayMode.Format == deviceSettings.AdapterFormat)
            {
                if(DisplayMode.Width > hiWidth)
                {
                    hiWidth = DisplayMode.Width;
                    hiHeight = DisplayMode.Height;
                }
                if(DisplayMode.Width < loWidth)
                {
                    loWidth = DisplayMode.Width;
                    loHeight = DisplayMode.Height;
                }
                if(nextMid)
                {
                    mdWidth = DisplayMode.Width;
                    mdHeight = DisplayMode.Height;
                }
            }
        }
        switch(m_DataSettings.m_iQuality)
        {
        case SETTINGS_Q_HIGH:
            m_DataSettings.m_ulResolution = MAKELONG(hiWidth, hiHeight);
            m_DataSettings.m_iFilter = 2;
            m_DataSettings.m_iMipMapping = 0;
            break;
        case SETTINGS_Q_NORMAL:
            m_DataSettings.m_ulResolution = MAKELONG(mdWidth, mdHeight);
            m_DataSettings.m_iFilter = 0;
            m_DataSettings.m_iMipMapping = 0;
            break;
        case SETTINGS_Q_LOW:
            m_DataSettings.m_ulResolution = MAKELONG(loWidth, loHeight);
            m_DataSettings.m_iFilter = 0;
            m_DataSettings.m_iMipMapping = 1;
            break;
        }

        // GUI_CMBBX_SETT_WINFULL
        if( (deviceSettings.pp.Windowed && m_DataSettings.m_iWinFull) ||
            (!deviceSettings.pp.Windowed && !m_DataSettings.m_iWinFull) )
        {
            DXUTToggleFullScreen();
            deviceSettings = DXUTGetDeviceSettings();
        }

        // GUI_CMBBX_SETT_STADISTICS
        g_GUI->setStadistics(m_DataSettings.m_iStadistics==1);

        // GUI_CMBBX_SETT_RESOLUTION
        deviceSettings.pp.BackBufferWidth = min(getWidth(), hiWidth);
        deviceSettings.pp.BackBufferHeight = min(getHeigth(), hiHeight);
        deviceSettings.pp.FullScreen_RefreshRateInHz = 0;

        // Aplicamos la configuración
        DXUTCreateDeviceFromSettings(&deviceSettings);
        m_bChanges = false;

        // GUI_CMBBX_SETT_FILTER
        switch(m_DataSettings.m_iFilter)
        {
        case SETTINGS_F_POINT:
            pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
            pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
            break;
        case SETTINGS_F_LINEAR:
            pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
            pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
            break;
        case SETTINGS_F_ANISOT:
            pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
            pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
            pDevice->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 4);
            break;
        }

        // GUI_CMBBX_SETT_MIPMAPPING
        if(m_DataSettings.m_iMipMapping)
            pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
        else
            pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
        break;
    }
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_SOUND:

        // GUI_SLIDER_SETT_EFFECTS
        g_3DSoundMng->setVolume(m_DataSettings.m_iEffects);

        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_GAME:

        // GUI_EDITBOX_SETT_NAME
        // No hacen falta cambios, el GUI toma estos valores de la clase

        break;
    //----------------------------------------------------------------------------------
    case 0:
    default:
        Apply(GUI_TYPE_SETT_DISPLAY);
        Apply(GUI_TYPE_SETT_SOUND);
        Apply(GUI_TYPE_SETT_GAME);
        break;
    //----------------------------------------------------------------------------------
    }

}

//--------------------------------------------------------------------------------------
// Para recargar el GUI con los datos
//--------------------------------------------------------------------------------------
void CSettings::RefreshControls(int Section)
{
    switch(Section)
    {
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_DISPLAY:
    {
        DXUTDeviceSettings deviceSettings = DXUTGetDeviceSettings();
        CD3DEnumeration* pD3DEnum = DXUTGetEnumeration();
        if(!pD3DEnum) return;
        CD3DEnumAdapterInfo* adapterInfo = pD3DEnum->GetAdapterInfo(deviceSettings.AdapterOrdinal);
        if(!adapterInfo) return;

        CDXUTComboBox* pComboBox;

        // GUI_CMBBX_SETT_QUALITY
        pComboBox = g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_QUALITY);
        pComboBox->RemoveAllItems();
        pComboBox->AddItem(L"CUSTOM", g_GUI->getIndex(0));
        pComboBox->AddItem(L"HIGH", g_GUI->getIndex(1));
        pComboBox->AddItem(L"NORMAL", g_GUI->getIndex(2));
        pComboBox->AddItem(L"LOW", g_GUI->getIndex(3));
        pComboBox->SetSelectedByIndex(m_DataSettings.m_iQuality);

        // GUI_CMBBX_SETT_WINFULL
        pComboBox = g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_WINFULL);
        pComboBox->RemoveAllItems();
        pComboBox->AddItem(L"WINDOWED", g_GUI->getIndex(0));
        pComboBox->AddItem(L"FULLSCREEN", g_GUI->getIndex(1));
        pComboBox->SetSelectedByIndex(m_DataSettings.m_iWinFull);

        // GUI_CMBBX_SETT_STADISTICS
        pComboBox = g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_STADISTICS);
        pComboBox->RemoveAllItems();
        pComboBox->AddItem(L"DON'T SHOW IT", g_GUI->getIndex(0));
        pComboBox->AddItem(L"SHOW IT", g_GUI->getIndex(1));
        pComboBox->SetSelectedByIndex(m_DataSettings.m_iStadistics);

        // GUI_CMBBX_SETT_RESOLUTION
        pComboBox = g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_RESOLUTION);
        pComboBox->RemoveAllItems();
        WCHAR strResolution[50];
        for(int i = 0; i < adapterInfo->displayModeList.GetSize(); i++)
        {
            D3DDISPLAYMODE DisplayMode = adapterInfo->displayModeList.GetAt(i);
            if(DisplayMode.Format == deviceSettings.AdapterFormat)
            {
                DWORD dwResolutionData = MAKELONG(DisplayMode.Width, DisplayMode.Height);
                if(DisplayMode.Width < MIN_WIDTH || DisplayMode.Height < MIN_HEIGHT)
                    continue;
                _snwprintf( strResolution, 50, L"%d x %d\0", DisplayMode.Width, DisplayMode.Height);
                if( !pComboBox->ContainsItem(strResolution) )
                    pComboBox->AddItem(strResolution, ULongToPtr(dwResolutionData));
            }
        }
        pComboBox->SetSelectedByData( ULongToPtr(m_DataSettings.m_ulResolution) );

        // GUI_CMBBX_SETT_FILTER
        pComboBox = g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_FILTER);
        pComboBox->RemoveAllItems();
        pComboBox->AddItem(L"POINT", g_GUI->getIndex(0));
        pComboBox->AddItem(L"LINEAR", g_GUI->getIndex(1));
        pComboBox->AddItem(L"ANISOTROPIC", g_GUI->getIndex(2));
        pComboBox->SetSelectedByIndex(m_DataSettings.m_iFilter);

        // GUI_CMBBX_SETT_MIPMAPPING
        pComboBox = g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_MIPMAPPING);
        pComboBox->RemoveAllItems();
        pComboBox->AddItem(L"DON'T USE IT", g_GUI->getIndex(0));
        pComboBox->AddItem(L"USE IT", g_GUI->getIndex(1));
        pComboBox->SetSelectedByIndex(m_DataSettings.m_iMipMapping);

        break;
    }
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_SOUND:

        // GUI_SLIDER_SETT_EFFECTS
        g_GUI->getGUI()->GetSlider(GUI_SLIDER_SETT_EFFECTS)->SetValue(m_DataSettings.m_iEffects);

        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_GAME:

        // GUI_EDITBOX_SETT_NAME
        g_GUI->getGUI()->GetEditBox(GUI_EDITBOX_SETT_NAME)->SetText(m_DataSettings.m_awNomPlayer);

        break;
    //----------------------------------------------------------------------------------
    case 0:
    default:
        RefreshControls(GUI_TYPE_SETT_DISPLAY);
        RefreshControls(GUI_TYPE_SETT_SOUND);
        RefreshControls(GUI_TYPE_SETT_GAME);
        break;
    //----------------------------------------------------------------------------------
    }

}

//--------------------------------------------------------------------------------------
// Para recargar los datos con el GUI
//--------------------------------------------------------------------------------------
void CSettings::RefreshData(int Section)
{
    int new_int;
    LPCWSTR new_str;
    DWORD new_ulong;

    switch(Section)
    {
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_DISPLAY:

        // GUI_CMBBX_SETT_QUALITY
        new_int = *((int *)(g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_QUALITY)->GetSelectedData()));
        if(new_int != m_DataSettings.m_iQuality)
        {
            m_bChanges = true;
            m_DataSettings.m_iQuality = new_int;
        }

        // GUI_CMBBX_SETT_WINFULL
        new_int = *((int *)(g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_WINFULL)->GetSelectedData()));
        if(new_int != m_DataSettings.m_iWinFull)
        {
            m_bChanges = true;
            m_DataSettings.m_iWinFull = new_int;
        }

        // GUI_CMBBX_SETT_STADISTICS
        new_int = *((int *)(g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_STADISTICS)->GetSelectedData()));
        if(new_int != m_DataSettings.m_iStadistics)
        {
            m_bChanges = true;
            m_DataSettings.m_iStadistics = new_int;
        }

        // GUI_CMBBX_SETT_RESOLUTION
        new_ulong = PtrToUlong(g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_RESOLUTION)->GetSelectedData());
        if(new_ulong != m_DataSettings.m_ulResolution)
        {
            m_bChanges = true;
            m_DataSettings.m_ulResolution = new_ulong;
        }

        // GUI_CMBBX_SETT_FILTER
        new_int = *((int *)(g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_FILTER)->GetSelectedData()));
        if(new_int != m_DataSettings.m_iFilter)
        {
            m_bChanges = true;
            m_DataSettings.m_iFilter = new_int;
        }

        // GUI_CMBBX_SETT_MIPMAPPING
        new_int = *((int *)(g_GUI->getGUI()->GetComboBox(GUI_CMBBX_SETT_MIPMAPPING)->GetSelectedData()));
        if(new_int != m_DataSettings.m_iMipMapping)
        {
            m_bChanges = true;
            m_DataSettings.m_iMipMapping = new_int;
        }

        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_SOUND:

        // GUI_SLIDER_SETT_EFFECTS
        new_int = g_GUI->getGUI()->GetSlider(GUI_SLIDER_SETT_EFFECTS)->GetValue();
        if(new_int != m_DataSettings.m_iEffects)
        {
            m_bChanges = true;
            m_DataSettings.m_iEffects = new_int;
        }

        break;
    //----------------------------------------------------------------------------------
    case GUI_TYPE_SETT_GAME:

        // GUI_EDITBOX_SETT_NAME
        new_str = g_GUI->getGUI()->GetEditBox(GUI_EDITBOX_SETT_NAME)->GetText();
        if(lstrcmpW(m_DataSettings.m_awNomPlayer, new_str) != 0)
        {
            m_bChanges = true;
            lstrcpynW(m_DataSettings.m_awNomPlayer, new_str, MAX_STRING);
        }

        break;
    //----------------------------------------------------------------------------------
    case 0:
    default:
        RefreshData(GUI_TYPE_SETT_DISPLAY);
        RefreshData(GUI_TYPE_SETT_SOUND);
        RefreshData(GUI_TYPE_SETT_GAME);
        break;
    //----------------------------------------------------------------------------------
    }

    // La escritura en el fichero de disco se hará al salir de la aplicación
    if(m_bChanges)
        m_bChangesFile = true;
}
