home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / user / preferences.cpp next >
Encoding:
C/C++ Source or Header  |  2008-08-23  |  18.4 KB  |  643 lines

  1. /***************************************************************************
  2.  * preferences.cpp  -  Game settings handler
  3.  *
  4.  * Copyright (C) 2003 - 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #include "../user/preferences.h"
  17. #include "../audio/audio.h"
  18. #include "../video/video.h"
  19. #include "../core/game_core.h"
  20. #include "../core/camera.h"
  21. #include "../input/joystick.h"
  22. #include "../gui/hud.h"
  23. #include "../level/level_manager.h"
  24. #include "../core/i18n.h"
  25. // boost filesystem
  26. #include "boost/filesystem/convenience.hpp"
  27. namespace fs = boost::filesystem;
  28.  
  29.  
  30. /* *** *** *** *** *** *** *** cPreferences *** *** *** *** *** *** *** *** *** *** */
  31.  
  32. cPreferences :: cPreferences( void )
  33. {
  34.     Default();
  35. }
  36.  
  37. cPreferences :: ~cPreferences( void )
  38. {
  39.     //
  40. }
  41.  
  42. bool cPreferences :: Load( string filename /* = "" */ )
  43. {
  44.     Default();
  45.     
  46.     // if config file is given
  47.     if( filename.length() )
  48.     {
  49.         config_filename = filename;
  50.     }
  51.     
  52.     // prefer local config file
  53.     if( File_Exists( config_filename ) )
  54.     {
  55.         printf( "Using local preferences file : %s\n", config_filename.c_str() );
  56.     }
  57.     // user dir
  58.     else
  59.     {
  60.         config_filename.insert( 0, user_data_dir );
  61.  
  62.         // does not exist in user dir
  63.         if( !File_Exists( config_filename ) )
  64.         {
  65.             // only print warning if file is given
  66.             if( !filename.empty() )
  67.             {
  68.                 printf( "Couldn't open preferences file : %s\n", config_filename.c_str() );
  69.             }
  70.             return 0;
  71.         }
  72.     }
  73.  
  74.     try
  75.     {
  76.         CEGUI::System::getSingleton().getXMLParser()->parseXMLFile( *this, config_filename.c_str(), DATA_DIR "/" GAME_SCHEMA_DIR "/Config.xsd", "" );
  77.     }
  78.     // catch CEGUI Exceptions
  79.     catch( CEGUI::Exception &ex )
  80.     {
  81.         printf( "Preferences Loading CEGUI Exception %s\n", ex.getMessage().c_str() );
  82.         debugdisplay->Set_Text( _("Preferences Loading failed : ") + (string)ex.getMessage().c_str() );
  83.     }
  84.  
  85.     // if user data dir is set
  86.     if( !force_user_data_dir.empty() )
  87.     {
  88.         user_data_dir = force_user_data_dir;
  89.     }
  90.  
  91.     return 1;
  92. }
  93.  
  94. void cPreferences :: Save( void )
  95. {
  96.     Update();
  97.  
  98.     ofstream file( config_filename.c_str(), ios::out );
  99.  
  100.     if( !file.is_open() )
  101.     {
  102.         printf( "Error : couldn't open config file for saving. Is the file read-only ?" );
  103.         return;
  104.     }
  105.  
  106.     // xml info
  107.     file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
  108.     // begin preferences
  109.     file << "<Preferences>" << std::endl;
  110.     // Game
  111.     file << "\t<Item Name=\"game_language\" Value=\"" << language << "\" />" << std::endl;
  112.     file << "\t<Item Name=\"game_version\" Value=\"" << smc_version << "\" />" << std::endl;
  113.     file << "\t<Item Name=\"user_data_dir\" Value=\"" << force_user_data_dir << "\" />" << std::endl;
  114.     file << "\t<Item Name=\"camera_hor_speed\" Value=\"" << camera_hor_speed << "\" />" << std::endl;
  115.     file << "\t<Item Name=\"camera_ver_speed\" Value=\"" << camera_ver_speed << "\" />" << std::endl;
  116.     // Video
  117.     file << "\t<Item Name=\"video_fullscreen\" Value=\"" << video_fullscreen << "\" />" << std::endl;
  118.     file << "\t<Item Name=\"video_screen_w\" Value=\"" << video_screen_w << "\" />" << std::endl;
  119.     file << "\t<Item Name=\"video_screen_h\" Value=\"" << video_screen_h << "\" />" << std::endl;
  120.     file << "\t<Item Name=\"video_screen_bpp\" Value=\"" << static_cast<int>(video_screen_bpp) << "\" />" << std::endl;
  121.     file << "\t<Item Name=\"video_vsync\" Value=\"" << video_vsync << "\" />" << std::endl;
  122.     file << "\t<Item Name=\"video_geometry_detail\" Value=\"" << pVideo->geometry_detail << "\" />" << std::endl;
  123.     file << "\t<Item Name=\"video_texture_detail\" Value=\"" << pVideo->texture_detail << "\" />" << std::endl;
  124.     // Audio
  125.     file << "\t<Item Name=\"audio_music\" Value=\"" << audio_music << "\" />" << std::endl;
  126.     file << "\t<Item Name=\"audio_sound\" Value=\"" << audio_sound << "\" />" << std::endl;
  127.     file << "\t<Item Name=\"audio_music_volume\" Value=\"" << static_cast<int>(pAudio->music_volume) << "\" />" << std::endl;
  128.     file << "\t<Item Name=\"audio_sound_volume\" Value=\"" << static_cast<int>(pAudio->sound_volume) << "\" />" << std::endl;
  129.     file << "\t<Item Name=\"audio_hz\" Value=\"" << audio_hz << "\" />" << std::endl;
  130.     // Keyboard
  131.     file << "\t<Item Name=\"keyboard_key_up\" Value=\"" << key_up << "\" />" << std::endl;
  132.     file << "\t<Item Name=\"keyboard_key_down\" Value=\"" << key_down << "\" />" << std::endl;
  133.     file << "\t<Item Name=\"keyboard_key_left\" Value=\"" << key_left << "\" />" << std::endl;
  134.     file << "\t<Item Name=\"keyboard_key_right\" Value=\"" << key_right << "\" />" << std::endl;
  135.     file << "\t<Item Name=\"keyboard_key_jump\" Value=\"" << key_jump << "\" />" << std::endl;
  136.     file << "\t<Item Name=\"keyboard_key_shoot\" Value=\"" << key_shoot << "\" />" << std::endl;
  137.     file << "\t<Item Name=\"keyboard_key_action\" Value=\"" << key_action << "\" />" << std::endl;
  138.     file << "\t<Item Name=\"keyboard_scroll_speed\" Value=\"" << scroll_speed << "\" />" << std::endl;
  139.     // Joystick/Gamepad
  140.     file << "\t<Item Name=\"joy_enabled\" Value=\"" << joy_enabled << "\" />" << std::endl;
  141.     file << "\t<Item Name=\"joy_name\" Value=\"" << string_to_xml_string( joy_name ) << "\" />" << std::endl;
  142.     file << "\t<Item Name=\"joy_analog_jump\" Value=\"" << joy_analog_jump << "\" />" << std::endl;
  143.     file << "\t<Item Name=\"joy_axis_hor\" Value=\"" << joy_axis_hor << "\" />" << std::endl;
  144.     file << "\t<Item Name=\"joy_axis_ver\" Value=\"" << joy_axis_ver << "\" />" << std::endl;
  145.     file << "\t<Item Name=\"joy_axis_threshold\" Value=\"" << joy_axis_threshold << "\" />" << std::endl;
  146.     file << "\t<Item Name=\"joy_button_jump\" Value=\"" << static_cast<int>(joy_button_jump) << "\" />" << std::endl;
  147.     file << "\t<Item Name=\"joy_button_item\" Value=\"" << static_cast<int>(joy_button_item) << "\" />" << std::endl;
  148.     file << "\t<Item Name=\"joy_button_shoot\" Value=\"" << static_cast<int>(joy_button_shoot) << "\" />" << std::endl;
  149.     file << "\t<Item Name=\"joy_button_action\" Value=\"" << static_cast<int>(joy_button_action) << "\" />" << std::endl;
  150.     file << "\t<Item Name=\"joy_button_exit\" Value=\"" << static_cast<int>(joy_button_exit) << "\" />" << std::endl;
  151.     // Special
  152.     file << "\t<Item Name=\"always_run\" Value=\"" << always_run << "\" />" << std::endl;
  153.     file << "\t<Item Name=\"level_background_images\" Value=\"" << level_background_images << "\" />" << std::endl;
  154.     file << "\t<Item Name=\"image_cache_enabled\" Value=\"" << image_cache_enabled << "\" />" << std::endl;
  155.     // Leveleditor
  156.     file << "\t<Item Name=\"editor_mouse_auto_hide\" Value=\"" << editor_mouse_auto_hide << "\" />" << std::endl;
  157.     // end preferences
  158.     file << "</Preferences>" << std::endl;
  159.  
  160.     file.close();
  161. }
  162.  
  163. void cPreferences :: Default( void )
  164. {
  165.     // Game
  166.     language = "";
  167.     force_user_data_dir.clear();
  168.     game_version = smc_version;
  169.     camera_hor_speed = 0.3f;
  170.     camera_ver_speed = 0.2f;
  171.  
  172.     // Video
  173.     video_screen_w = 1024;
  174.     video_screen_h = 768;
  175.     video_screen_bpp = 32;
  176.     /* disable by default because of possible bad drivers
  177.      * which can't handle visual sync
  178.     */
  179.     video_vsync = 0;
  180.  
  181. #ifdef _DEBUG
  182.     video_fullscreen = 0;
  183. #else
  184.     video_fullscreen = 1;
  185. #endif
  186.  
  187.     // Audio
  188.     audio_music = 1;
  189.     audio_sound = 1;
  190.     audio_hz = 44100;
  191.  
  192.     // Keyboard
  193.     key_up = SDLK_UP;
  194.     key_down = SDLK_DOWN;
  195.     key_left = SDLK_LEFT;
  196.     key_right = SDLK_RIGHT;
  197.     key_jump = SDLK_LALT;
  198.     key_shoot = SDLK_SPACE;
  199.     key_action = SDLK_LCTRL;
  200.     scroll_speed = 1;
  201.  
  202.     // Joystick
  203.     joy_enabled = 1;
  204.     // axes
  205.     joy_axis_hor = 0;
  206.     joy_axis_ver = 1;
  207.     // axis threshold
  208.     joy_axis_threshold = 10000;
  209.     // buttons
  210.     joy_button_jump = 0;
  211.     joy_button_shoot = 1;
  212.     joy_button_item = 3;
  213.     joy_button_action = 2;
  214.     joy_button_exit = 4;
  215.  
  216.     // Special
  217.     always_run = 0;
  218.     joy_name.clear();
  219.     joy_analog_jump = 0;
  220.     level_background_images = 1;
  221.     image_cache_enabled = 1;
  222.  
  223.     // editor
  224.     editor_mouse_auto_hide = 0;
  225.  
  226.     // filename
  227.     config_filename = "config.xml";
  228. }
  229.  
  230. void cPreferences :: Update( void )
  231. {
  232.     camera_hor_speed = pLevel_Manager->camera->hor_offset_speed;
  233.     camera_ver_speed = pLevel_Manager->camera->ver_offset_speed;
  234.  
  235.     audio_music = pAudio->music_enabled;
  236.     audio_sound = pAudio->sound_enabled;
  237.  
  238.     // if not default joy used
  239.     if( pJoystick->cur_stick > 0 )
  240.     {
  241.         joy_name = pJoystick->Get_Name();
  242.     }
  243.     // using default joy
  244.     else
  245.     {
  246.         joy_name.clear();
  247.     }
  248. }
  249.  
  250. void cPreferences :: Apply( void )
  251. {
  252.     pLevel_Manager->camera->hor_offset_speed = camera_hor_speed;
  253.     pLevel_Manager->camera->ver_offset_speed = camera_ver_speed;
  254.     
  255.     // disable joystick if the joystick initialization failed
  256.     if( pVideo->joy_init_failed )
  257.     {
  258.         joy_enabled = 0;
  259.     }
  260. }
  261.  
  262. void cPreferences :: Apply_Video( Uint16 screen_w, Uint16 screen_h, Uint8 screen_bpp, bool fullscreen, bool vsync, float geometry_detail, float texture_detail )
  263. {
  264.     /* if resolution, bpp, vsync or texture detail changed
  265.      * a texture reload is necessary
  266.     */
  267.     if( video_screen_w != screen_w || video_screen_h != screen_h || video_screen_bpp != screen_bpp || video_vsync != vsync || pVideo->texture_detail != texture_detail )
  268.     {
  269.         // new settings
  270.         video_screen_w = screen_w;
  271.         video_screen_h = screen_h;
  272.         video_screen_bpp = screen_bpp;
  273.         video_vsync = vsync;
  274.         video_fullscreen = fullscreen;
  275.         pVideo->texture_detail = texture_detail;
  276.         pVideo->geometry_detail = geometry_detail;
  277.  
  278.         // reinitialize video and reload textures from file
  279.         pVideo->Init_Video( 1 );
  280.     }
  281.     // no texture reload necessary
  282.     else
  283.     {
  284.         // geometry detail changed
  285.         if( pVideo->geometry_detail != geometry_detail )
  286.         {
  287.             pVideo->geometry_detail = geometry_detail;
  288.             pVideo->Init_Geometry();
  289.         }
  290.  
  291.         // fullscreen changed
  292.         if( video_fullscreen != fullscreen )
  293.         {
  294.             // toggle fullscreen and switches video_fullscreen itself
  295.             pVideo->Toggle_Fullscreen();
  296.         }
  297.     }
  298. }
  299.  
  300. void cPreferences :: Apply_Audio( bool sound, bool music )
  301. {
  302.     // disable sound and music if the audio initialization failed
  303.     if( pVideo->audio_init_failed )
  304.     {
  305.         audio_sound = 0;
  306.         audio_music = 0;
  307.         return;
  308.     }
  309.  
  310.     audio_sound = sound;
  311.     audio_music = music;
  312.  
  313.     // init audio settings
  314.     pAudio->Init();
  315. }
  316.  
  317. // XML element start
  318. void cPreferences :: elementStart( const CEGUI::String &element, const CEGUI::XMLAttributes &attributes )
  319. {
  320.     if( element == "Item" )
  321.     {
  322.         handle_item( attributes );
  323.     }
  324. }
  325.  
  326. // XML element end
  327. void cPreferences :: elementEnd( const CEGUI::String &element )
  328. {
  329.     
  330. }
  331.  
  332. void cPreferences :: handle_item( const CEGUI::XMLAttributes& attributes )
  333. {
  334.     string name = attributes.getValueAsString( "Name" ).c_str();
  335.  
  336.     // Game
  337.     if( name.compare( "game_language" ) == 0 )
  338.     {
  339.         language = attributes.getValueAsString( "Value" ).c_str();
  340.     }
  341.     else if( name.compare( "game_version" ) == 0 )
  342.     {
  343.         game_version = attributes.getValueAsFloat( "Value" );
  344.     }
  345.     else if( name.compare( "user_data_dir" ) == 0 )
  346.     {
  347.         force_user_data_dir = attributes.getValueAsString( "Value" ).c_str();
  348.  
  349.         // if user data dir is set
  350.         if( !force_user_data_dir.empty() ) 
  351.         {
  352.             Convert_Path_Separators( force_user_data_dir );
  353.  
  354.             // add trailing slash if missing
  355.             if( *(force_user_data_dir.end() - 1) != '/' )
  356.             {
  357.                 force_user_data_dir.insert( force_user_data_dir.length(), "/" );
  358.             }
  359.         }
  360.     }
  361.     else if( name.compare( "camera_hor_speed" ) == 0 )
  362.     {
  363.         camera_hor_speed = attributes.getValueAsFloat( "Value" );
  364.     }
  365.     else if( name.compare( "camera_ver_speed" ) == 0 )
  366.     {
  367.         camera_ver_speed = attributes.getValueAsFloat( "Value" );
  368.     }
  369.     // Video
  370.     else if( name.compare( "Screen_H" ) == 0 || name.compare( "video_screen_h" ) == 0 )
  371.     {
  372.         int val = attributes.getValueAsInteger( "Value" );
  373.  
  374.         if( val < 200 )
  375.         {
  376.             val = 200;
  377.         }
  378.         else if( val > 2560 )
  379.         {
  380.             val = 2560;
  381.         }
  382.         
  383.         video_screen_h = val;
  384.     }
  385.     else if( name.compare( "Screen_W" ) == 0 || name.compare( "video_screen_w" ) == 0 )
  386.     {
  387.         int val = attributes.getValueAsInteger( "Value" );
  388.  
  389.         if( val < 200 )
  390.         {
  391.             val = 200;
  392.         }
  393.         else if( val > 2560 )
  394.         {
  395.             val = 2560;
  396.         }
  397.  
  398.         video_screen_w = val;
  399.     }
  400.     else if( name.compare( "Screen_Bpp" ) == 0 || name.compare( "video_screen_bpp" ) == 0 )
  401.     {
  402.         int val = attributes.getValueAsInteger( "Value" );
  403.  
  404.         if( val < 8 )
  405.         {
  406.             val = 8;
  407.         }
  408.         else if( val > 32 )
  409.         {
  410.             val = 32;
  411.         }
  412.  
  413.         video_screen_bpp = val;
  414.     }
  415.     else if( name.compare( "vsync" ) == 0 || name.compare( "video_vsync" ) == 0 )
  416.     {
  417.         video_vsync = attributes.getValueAsBool( "Value" );
  418.     }
  419.     else if( name.compare( "Fullscreen" ) == 0 || name.compare( "video_fullscreen" ) == 0 )
  420.     {
  421.         video_fullscreen = attributes.getValueAsBool( "Value" );
  422.     }
  423.     else if( name.compare( "video_geometry_detail" ) == 0 )
  424.     {
  425.         pVideo->geometry_detail = attributes.getValueAsFloat( "Value" );
  426.     }
  427.     else if( name.compare( "video_texture_detail" ) == 0 )
  428.     {
  429.         pVideo->texture_detail = attributes.getValueAsFloat( "Value" );
  430.     }
  431.     // Audio
  432.     else if( name.compare( "Music" ) == 0 || name.compare( "audio_music" ) == 0 )
  433.     {
  434.         audio_music = attributes.getValueAsBool( "Value" );
  435.     }
  436.     else if( name.compare( "Sounds" ) == 0 || name.compare( "audio_sound" ) == 0 )
  437.     {
  438.         audio_sound = attributes.getValueAsBool( "Value" );
  439.     }
  440.     if( name.compare( "music_volume" ) == 0 || name.compare( "audio_music_volume" ) == 0 )
  441.     {
  442.         int val = attributes.getValueAsInteger( "Value" );
  443.  
  444.         if( val >= 0 && val <= MIX_MAX_VOLUME )
  445.         {
  446.             pAudio->music_volume = val;
  447.         }
  448.     }
  449.     else if( name.compare( "sound_volume" ) == 0 || name.compare( "audio_sound_volume" ) == 0 )
  450.     {
  451.         int val = attributes.getValueAsInteger( "Value" );
  452.  
  453.         if( val >= 0 && val <= MIX_MAX_VOLUME )
  454.         {
  455.             pAudio->sound_volume = val;
  456.         }
  457.     }
  458.     else if( name.compare( "audio_hz" ) == 0 )
  459.     {
  460.         int val = attributes.getValueAsInteger( "Value" );
  461.  
  462.         if( val >= 0 && val <= 44800 )
  463.         {
  464.             audio_hz = val;
  465.         }
  466.     }
  467.     // Keyboard
  468.     else if( name.compare( "Key_up" ) == 0 || name.compare( "keyboard_key_up" ) == 0 )
  469.     {
  470.         int val = attributes.getValueAsInteger( "Value" );
  471.  
  472.         if( val >= 0 && val <= 1000 )
  473.         {
  474.             key_up = static_cast<SDLKey>(val);
  475.         }
  476.     }
  477.     else if( name.compare( "Key_down" ) == 0 || name.compare( "keyboard_key_down" ) == 0 )
  478.     {
  479.         int val = attributes.getValueAsInteger( "Value" );
  480.  
  481.         if( val >= 0 && val <= 1000 )
  482.         {
  483.             key_down = static_cast<SDLKey>(val);
  484.         }
  485.     }
  486.     else if( name.compare( "Key_left" ) == 0 || name.compare( "keyboard_key_left" ) == 0 )
  487.     {
  488.         int val = attributes.getValueAsInteger( "Value" );
  489.  
  490.         if( val >= 0 && val <= 1000 )
  491.         {
  492.             key_left = static_cast<SDLKey>(val);
  493.         }
  494.     }
  495.     else if( name.compare( "Key_right" ) == 0 || name.compare( "keyboard_key_right" ) == 0 )
  496.     {
  497.         int val = attributes.getValueAsInteger( "Value" );
  498.  
  499.         if( val >= 0 && val <= 1000 )
  500.         {
  501.             key_right = static_cast<SDLKey>(val);
  502.         }
  503.     }
  504.     else if( name.compare( "Key_jump" ) == 0 || name.compare( "keyboard_key_jump" ) == 0 )
  505.     {
  506.         int val = attributes.getValueAsInteger( "Value" );
  507.  
  508.         if( val >= 0 && val <= 1000 )
  509.         {
  510.             key_jump = static_cast<SDLKey>(val);
  511.         }
  512.     }
  513.     else if( name.compare( "Key_shoot" ) == 0 || name.compare( "keyboard_key_shoot" ) == 0 )
  514.     {
  515.         int val = attributes.getValueAsInteger( "Value" );
  516.  
  517.         if( val >= 0 && val <= 1000 )
  518.         {
  519.             key_shoot = static_cast<SDLKey>(val);
  520.         }
  521.     }
  522.     else if( name.compare( "Key_action" ) == 0 || name.compare( "keyboard_key_action" ) == 0 )
  523.     {
  524.         int val = attributes.getValueAsInteger( "Value" );
  525.  
  526.         if( val >= 0 && val <= 1000 )
  527.         {
  528.             key_action = static_cast<SDLKey>(val);
  529.         }
  530.     }
  531.     // scroll speed
  532.     else if( name.compare( "keyboard_scroll_speed" ) == 0 )
  533.     {
  534.         scroll_speed = attributes.getValueAsFloat( "Value" );
  535.     }
  536.     // Joypad
  537.     else if( name.compare( "Joypad_enabled" ) == 0 || name.compare( "joy_enabled" ) == 0 )
  538.     {
  539.         joy_enabled = attributes.getValueAsBool( "Value" );
  540.     }
  541.     else if( name.compare( "joy_name" ) == 0 )
  542.     {
  543.         joy_name = attributes.getValueAsString( "Value" ).c_str();
  544.     }
  545.     else if( name.compare( "joy_analog_jump" ) == 0 )
  546.     {
  547.         joy_analog_jump = attributes.getValueAsBool( "Value" );
  548.     }
  549.     else if( name.compare( "joy_axis_hor" ) == 0 )
  550.     {
  551.         int val = attributes.getValueAsInteger( "Value" );
  552.  
  553.         if( val >= 0 && val <= 15 )
  554.         {
  555.             joy_axis_hor = val;
  556.         }
  557.     }
  558.     else if( name.compare( "joy_axis_ver" ) == 0 )
  559.     {
  560.         int val = attributes.getValueAsInteger( "Value" );
  561.  
  562.         if( val >= 0 && val <= 15 )
  563.         {
  564.             joy_axis_ver = val;
  565.         }
  566.     }
  567.     else if( name.compare( "joy_axis_threshold" ) == 0 )
  568.     {
  569.         int val = attributes.getValueAsInteger( "Value" );
  570.  
  571.         if( val >= 0 && val <= 32000 )
  572.         {
  573.             joy_axis_threshold = val;
  574.         }
  575.     }
  576.     else if( name.compare( "Joypad_jump" ) == 0 || name.compare( "joy_button_jump" ) == 0 )
  577.     {
  578.         int val = attributes.getValueAsInteger( "Value" );
  579.  
  580.         if( val >= 0 && val <= 256 )
  581.         {
  582.             joy_button_jump = val;
  583.         }
  584.     }
  585.     else if( name.compare( "Joypad_item" ) == 0 || name.compare( "joy_button_item" ) == 0 )
  586.     {
  587.         int val = attributes.getValueAsInteger( "Value" );
  588.  
  589.         if( val >= 0 && val <= 256 )
  590.         {
  591.             joy_button_item = val;
  592.         }
  593.     }
  594.     else if( name.compare( "Joypad_shoot" ) == 0 || name.compare( "joy_button_shoot" ) == 0 )
  595.     {
  596.         int val = attributes.getValueAsInteger( "Value" );
  597.  
  598.         if( val >= 0 && val <= 256 )
  599.         {
  600.             joy_button_shoot = val;
  601.         }
  602.     }
  603.     else if( name.compare( "Joypad_action" ) == 0 || name.compare( "joy_button_action" ) == 0 )
  604.     {
  605.         int val = attributes.getValueAsInteger( "Value" );
  606.  
  607.         if( val >= 0 && val <= 256 )
  608.         {
  609.             joy_button_action = val;
  610.         }
  611.     }
  612.     else if( name.compare( "Joypad_exit" ) == 0 || name.compare( "joy_button_exit" ) == 0 )
  613.     {
  614.         int val = attributes.getValueAsInteger( "Value" );
  615.  
  616.         if( val >= 0 && val <= 256 )
  617.         {
  618.             joy_button_exit = val;
  619.         }
  620.     }
  621.     // Special
  622.     else if( name.compare( "always_run" ) == 0 )
  623.     {
  624.         always_run = attributes.getValueAsBool( "Value" );
  625.     }
  626.     else if( name.compare( "background_images" ) == 0 || name.compare( "level_background_images" ) == 0 )
  627.     {
  628.         level_background_images = attributes.getValueAsBool( "Value" );
  629.     }
  630.     else if( name.compare( "editor_mouse_auto_hide" ) == 0 )
  631.     {
  632.         editor_mouse_auto_hide = attributes.getValueAsBool( "Value" );
  633.     }
  634.     else if( name.compare( "image_cache_enabled" ) == 0 )
  635.     {
  636.         image_cache_enabled = attributes.getValueAsBool( "Value" );
  637.     }
  638. }
  639.  
  640. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  641.  
  642. cPreferences *pPreferences = NULL;
  643.