src/menu/game_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  * Game menu
00020  *****************************************************************************/
00021 
00022 #include "game_menu.h"
00023 #include "map_selection_box.h"
00024 #include "teams_selection_box.h"
00025 
00026 #include "../game/game.h"
00027 #include "../game/config.h"
00028 #include "../game/game_mode.h"
00029 #include "../graphic/video.h"
00030 #include "../graphic/font.h"
00031 #include "../include/app.h"
00032 #include "../tool/i18n.h"
00033 #include "../tool/string_tools.h"
00034 
00035 #include <iostream>
00036 const uint MARGIN_TOP    = 5;
00037 const uint MARGIN_SIDE   = 5;
00038 const uint MARGIN_BOTTOM = 70;
00039 
00040 const uint TEAMS_BOX_H = 170;
00041 const uint OPTIONS_BOX_H = 150;
00042 
00043 const uint NBR_VER_MIN = 1;
00044 const uint NBR_VER_MAX = 10;
00045 const uint TPS_TOUR_MIN = 10;
00046 const uint TPS_TOUR_MAX = 120;
00047 const uint TPS_FIN_TOUR_MIN = 1;
00048 const uint TPS_FIN_TOUR_MAX = 10;
00049 
00050 
00051 
00052 // ################################################
00053 // ##  GAME MENU CLASS
00054 // ################################################
00055 GameMenu::GameMenu() :
00056   Menu("menu/bg_play")
00057 {
00058   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml",false);
00059   Rectanglei rectZero(0, 0, 0, 0);
00060   Rectanglei stdRect (0, 0, 130, 30);
00061 
00062   Surface window = AppWormux::GetInstance()->video.window;
00063 
00064   // Calculate main box size
00065   uint mainBoxWidth = window.GetWidth() - 2*MARGIN_SIDE;
00066   uint mapBoxHeight = (window.GetHeight() - MARGIN_TOP - MARGIN_BOTTOM - 2*MARGIN_SIDE) 
00067     - TEAMS_BOX_H - OPTIONS_BOX_H;
00068 
00069   // ################################################
00070   // ##  TEAM SELECTION
00071   // ################################################
00072   team_box = new TeamsSelectionBox(Rectanglei(MARGIN_SIDE, MARGIN_TOP,
00073                                               mainBoxWidth, TEAMS_BOX_H));
00074 
00075   widgets.AddWidget(team_box);
00076 
00077   // ################################################
00078   // ##  MAP SELECTION
00079   // ################################################
00080   map_box = new MapSelectionBox( Rectanglei(MARGIN_SIDE, team_box->GetPositionY()+team_box->GetSizeY()+ MARGIN_SIDE,
00081                                             mainBoxWidth, mapBoxHeight),
00082                                  false);
00083 
00084   widgets.AddWidget(map_box);
00085 
00086   // ################################################
00087   // ##  GAME OPTIONS
00088   // ################################################
00089   game_options = new HBox( Rectanglei(MARGIN_SIDE, map_box->GetPositionY()+map_box->GetSizeY()+ MARGIN_SIDE,
00090                                             mainBoxWidth/2, OPTIONS_BOX_H), true);
00091   game_options->AddWidget(new PictureWidget(Rectanglei(0,0,39,128), "menu/mode_label"));
00092 
00093   game_options->SetMargin(50);
00094 
00095   opt_duration_turn = new SpinButtonWithPicture(_("Duration of a turn"), "menu/timing_turn",
00096                                                 stdRect,
00097                                                 TPS_TOUR_MIN, 5,
00098                                                 TPS_TOUR_MIN, TPS_TOUR_MAX);
00099   game_options->AddWidget(opt_duration_turn);
00100 
00101   opt_energy_ini = new SpinButtonWithPicture(_("Initial energy"), "menu/energy",
00102                                              stdRect,
00103                                              100, 5,
00104                                              50, 200);
00105   game_options->AddWidget(opt_energy_ini);
00106 
00107   opt_scroll_on_border = new PictureTextCBox(_("Scroll on border"), "menu/scroll_on_border", stdRect);
00108   game_options->AddWidget(opt_scroll_on_border);
00109 
00110   game_options->AddWidget(new NullWidget(Rectanglei(0,0,50,10)));
00111 
00112   widgets.AddWidget(game_options);
00113 
00114 
00115   // Values initialization
00116 
00117   // Load game options
00118   GameMode * game_mode = GameMode::GetInstance();
00119   opt_duration_turn->SetValue(game_mode->duration_turn);
00120   opt_energy_ini->SetValue(game_mode->character.init_energy);
00121   opt_scroll_on_border->SetValue(Config::GetInstance()->GetScrollOnBorder());
00122 
00123   resource_manager.UnLoadXMLProfile(res);
00124 }
00125 
00126 GameMenu::~GameMenu()
00127 {
00128 }
00129 
00130 void GameMenu::OnClic(const Point2i &mousePosition, int button)
00131 {
00132   widgets.Clic(mousePosition, button);
00133 }
00134 
00135 void GameMenu::SaveOptions()
00136 {
00137   // Map
00138   map_box->ValidMapSelection();
00139 
00140   // teams
00141   team_box->ValidTeamsSelection();
00142 
00143   //Save options in XML
00144   Config::GetInstance()->SetScrollOnBorder(opt_scroll_on_border->GetValue());
00145   Config::GetInstance()->Save();
00146 
00147   GameMode * game_mode = GameMode::GetInstance();
00148   game_mode->duration_turn = opt_duration_turn->GetValue() ;
00149   game_mode->character.init_energy = opt_energy_ini->GetValue() ;
00150 
00151 }
00152 
00153 void GameMenu::__sig_ok()
00154 {
00155   SaveOptions();
00156   Game::GetInstance()->Start();
00157 }
00158 
00159 void GameMenu::__sig_cancel()
00160 {
00161   // Nothing to do
00162 }
00163 
00164 void GameMenu::Draw(const Point2i &mousePosition)
00165 {
00166 
00167 }
00168 

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