src/menu/options_menu.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Options menu
00020  *****************************************************************************/
00021 
00022 #include "options_menu.h"
00023 
00024 #include "../include/app.h"
00025 #include "../game/game_mode.h"
00026 #include "../game/config.h"
00027 #include "../graphic/video.h"
00028 #include "../graphic/font.h"
00029 #include "../map/maps_list.h"
00030 #include "../team/teams_list.h"
00031 #include "../tool/i18n.h"
00032 #include "../tool/string_tools.h"
00033 #include <sstream>
00034 
00035 const uint SOUND_X = 30;
00036 const uint SOUND_Y = 30;
00037 const uint SOUND_W = 530;
00038 const uint SOUND_H = 170;
00039 
00040 const uint GRAPHIC_X = 30;
00041 const uint GRAPHIC_Y = SOUND_Y + SOUND_H + 30;
00042 const uint GRAPHIC_W = 530;
00043 const uint GRAPHIC_H = 240;
00044 
00045 OptionMenu::OptionMenu() :
00046   Menu("menu/bg_option")
00047 {
00048   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);
00049   Rectanglei stdRect (0, 0, 140, 30);
00050 
00051   normal_font = Font::GetInstance(Font::FONT_NORMAL);
00052 
00053   /* Grapic options */
00054   Box * graphic_options = new HBox( Rectanglei(GRAPHIC_X, GRAPHIC_Y, GRAPHIC_W, GRAPHIC_H));
00055 
00056   graphic_options->AddWidget(new PictureWidget(Rectanglei(0,0,40,136), "menu/video_label"));
00057 
00058   Box * top_n_bottom_graphic_options = new VBox( Rectanglei(0, 0, GRAPHIC_W-40, GRAPHIC_H),false);
00059 
00060   Box * top_graphic_options = new HBox ( Rectanglei(GRAPHIC_X, GRAPHIC_Y, GRAPHIC_W, GRAPHIC_H/2 - 20), false);
00061   Box * bottom_graphic_options = new HBox ( Rectanglei(GRAPHIC_X, GRAPHIC_Y, GRAPHIC_W, GRAPHIC_H/2 - 20), false);
00062   top_graphic_options->SetMargin(25);
00063   bottom_graphic_options->SetMargin(25);
00064 
00065   opt_display_wind_particles = new PictureTextCBox(_("Wind particles?"), "menu/display_wind_particles", stdRect);
00066   top_graphic_options->AddWidget(opt_display_wind_particles);
00067 
00068   opt_display_energy = new PictureTextCBox(_("Player energy?"), "menu/display_energy", stdRect);
00069   top_graphic_options->AddWidget(opt_display_energy);
00070 
00071   opt_display_name = new PictureTextCBox(_("Player's name?"), "menu/display_name", stdRect);
00072   top_graphic_options->AddWidget(opt_display_name);
00073 
00074   full_screen = new PictureTextCBox(_("Fullscreen?"), "menu/fullscreen", stdRect);
00075   bottom_graphic_options->AddWidget(full_screen);
00076 
00077   opt_max_fps = new SpinButtonBig(_("Maximum FPS"), stdRect,
00078                                50, 5,
00079                                20, 120);
00080   bottom_graphic_options->AddWidget(opt_max_fps);
00081 
00082   lbox_video_mode = new ListBoxWithLabel(_("Resolution"), stdRect );
00083   bottom_graphic_options->AddWidget(lbox_video_mode);
00084 
00085   top_n_bottom_graphic_options->AddWidget(top_graphic_options);
00086   top_n_bottom_graphic_options->AddWidget(bottom_graphic_options);
00087   graphic_options->AddWidget(top_n_bottom_graphic_options);
00088 
00089   widgets.AddWidget(graphic_options);
00090 
00091   /* Sound options */
00092   Box * sound_options = new HBox( Rectanglei(SOUND_X, SOUND_Y, SOUND_W, SOUND_H));
00093   sound_options->AddWidget(new PictureWidget(Rectanglei(0,0,40,138), "menu/audio_label"));
00094 
00095   Box * all_sound_options = new HBox( Rectanglei(SOUND_X, SOUND_Y, SOUND_W, SOUND_H-20),false);
00096   all_sound_options->SetMargin(25);
00097   all_sound_options->SetBorder(Point2i(10,10));
00098 
00099   opt_music = new PictureTextCBox(_("Music?"), "menu/music_enable", stdRect);
00100   all_sound_options->AddWidget(opt_music);
00101 
00102   opt_sound_effects = new PictureTextCBox(_("Sound effects?"), "menu/sound_effects_enable", stdRect);
00103   all_sound_options->AddWidget(opt_sound_effects);
00104 
00105   lbox_sound_freq = new ListBoxWithLabel(_("Sound frequency"), stdRect );
00106   all_sound_options->AddWidget(lbox_sound_freq);
00107 
00108   sound_options->AddWidget(all_sound_options);
00109   widgets.AddWidget(sound_options);
00110 
00111   /* Center the widgets */
00112   AppWormux * app = AppWormux::GetInstance();
00113   uint center_x = app->video.window.GetWidth()/2;
00114 
00115   graphic_options->SetXY(center_x - graphic_options->GetSizeX()/2, graphic_options->GetPositionY());
00116   sound_options->SetXY(center_x - sound_options->GetSizeX()/2, sound_options->GetPositionY());
00117 
00118   // Values initialization
00119 
00120   // Get available video resolution
00121   std::list<Point2i>& video_res = app->video.GetAvailableConfigs();
00122   std::list<Point2i>::iterator mode;
00123 
00124   for(mode=video_res.begin(); mode!=video_res.end(); ++mode) {
00125       std::ostringstream ss;
00126       bool is_current;
00127       std::string text;
00128       ss << mode->GetX() << "x" << mode->GetY() ;
00129       text = ss.str();
00130       if (app->video.window.GetWidth() == mode->GetX() && app->video.window.GetHeight() == mode->GetY())
00131       {
00132           ss << " " << _("(current)");
00133           is_current = true;
00134       } else {
00135           is_current = false;
00136       }
00137       lbox_video_mode->AddItem(is_current, ss.str(), text);
00138   }
00139 
00140   // Generate sound mode list
00141   uint current_freq = jukebox.GetFrequency();
00142   lbox_sound_freq->AddItem (current_freq == 11025, "11 kHz", "11025");
00143   lbox_sound_freq->AddItem (current_freq == 22050, "22 kHz", "22050");
00144   lbox_sound_freq->AddItem (current_freq == 44100, "44 kHz", "44100");
00145 
00146   resource_manager.UnLoadXMLProfile( res);
00147 
00148   Config * config = Config::GetInstance();
00149 
00150   opt_max_fps->SetValue (app->video.GetMaxFps());
00151   opt_display_wind_particles->SetValue (config->GetDisplayWindParticles());
00152   opt_display_energy->SetValue (config->GetDisplayEnergyCharacter());
00153   opt_display_name->SetValue (config->GetDisplayNameCharacter());
00154   full_screen->SetValue (app->video.IsFullScreen());
00155 
00156 
00157   opt_music->SetValue( jukebox.UseMusic() );
00158   opt_sound_effects->SetValue( jukebox.UseEffects() );
00159 }
00160 
00161 OptionMenu::~OptionMenu()
00162 {
00163 }
00164 
00165 void OptionMenu::OnClic(const Point2i &mousePosition, int button)
00166 {
00167   widgets.Clic(mousePosition, button);
00168 }
00169 
00170 void OptionMenu::SaveOptions()
00171 {
00172   // Save values
00173   Config * config = Config::GetInstance();
00174   config->SetDisplayWindParticles(opt_display_wind_particles->GetValue());
00175   config->SetDisplayEnergyCharacter(opt_display_energy->GetValue());
00176   config->SetDisplayNameCharacter(opt_display_name->GetValue());
00177 
00178   AppWormux * app = AppWormux::GetInstance();
00179   app->video.SetMaxFps(opt_max_fps->GetValue());
00180   // Video mode
00181   std::string s_mode = lbox_video_mode->ReadValue();
00182   int w, h;
00183   sscanf(s_mode.c_str(),"%dx%d", &w, &h);
00184   app->video.SetConfig(w, h, full_screen->GetValue());
00185 
00186   uint x = app->video.window.GetWidth() / 2;
00187   uint y = app->video.window.GetHeight() - 50;
00188 
00189   SetActionButtonsXY(x, y);
00190 
00191   // Sound
00192   jukebox.ActiveMusic( opt_music->GetValue() );
00193   jukebox.ActiveEffects( opt_sound_effects->GetValue() );
00194   std::string sfreq = lbox_sound_freq->ReadValue();
00195   long freq;
00196   if (str2long(sfreq,freq)) jukebox.SetFrequency (freq);
00197 
00198   jukebox.Init(); // commit modification on sound options
00199 
00200   //Save options in XML
00201   config->Save();
00202 }
00203 
00204 void OptionMenu::__sig_ok()
00205 {
00206   SaveOptions();
00207 }
00208 
00209 void OptionMenu::__sig_cancel()
00210 {
00211   // Nothing to do
00212 }
00213 
00214 void OptionMenu::Draw(const Point2i &mousePosition)
00215 {
00216 }
00217 

Generated on Mon Jan 1 13:10:58 2007 for Wormux by  doxygen 1.4.7