src/menu/main_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  * Main_Menu du jeu permettant de lancer une partie, modifier les options, d'obtenir
00020  * des informations, ou encore quitter le jeu.
00021  *****************************************************************************/
00022 
00023 #include "main_menu.h"
00024 #include <string>
00025 #include "../game/config.h"
00026 #include "../game/time.h"
00027 #include "../graphic/effects.h"
00028 #include "../graphic/font.h"
00029 #include "../graphic/fps.h"
00030 #include "../include/app.h"
00031 #include "../include/constant.h"
00032 #include "../sound/jukebox.h"
00033 #include "../tool/i18n.h"
00034 #include "../tool/file_tools.h"
00035 #include "../tool/resource_manager.h"
00036 
00037 #ifndef WIN32
00038 #include <dirent.h>
00039 #endif
00040 
00041 // Position du texte de la version
00042 const int VERSION_DY = -40;
00043 
00044 const int DEFAULT_SCREEN_HEIGHT = 768 ;
00045 
00046 Main_Menu::~Main_Menu()
00047 {
00048   delete skin_left;
00049   delete skin_right;
00050   delete version_text;
00051   delete website_text;
00052 }
00053 
00054 Main_Menu::Main_Menu() :
00055     Menu("main_menu/bg_main", vNo)
00056 {
00057   int x_button;
00058   double y_scale;
00059 
00060   Font * normal_font = Font::GetInstance(Font::FONT_NORMAL);
00061   Font * large_font = Font::GetInstance(Font::FONT_LARGE);
00062 
00063   int button_width = 402;
00064   int button_height = 64;
00065 
00066   y_scale = (double)AppWormux::GetInstance()->video.window.GetHeight() / DEFAULT_SCREEN_HEIGHT ;
00067 
00068   x_button = AppWormux::GetInstance()->video.window.GetWidth()/2 - button_width/2;
00069 
00070   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);
00071 
00072   skin_left = new Sprite( resource_manager.LoadImage(res,"main_menu/skin_1"));
00073   skin_right = new Sprite( resource_manager.LoadImage(res,"main_menu/skin_2"));
00074 
00075   s_title = resource_manager.LoadImage(res,"main_menu/title");
00076   title = new PictureWidget(Rectanglei(AppWormux::GetInstance()->video.window.GetWidth()/2  - s_title.GetWidth()/2 + 10, 0, 648, 168));
00077   title->SetSurface(s_title);
00078 
00079   int y = int(290 * y_scale) ;
00080   const int y2 = AppWormux::GetInstance()->video.window.GetHeight() + VERSION_DY -20 - button_height;
00081 
00082   int dy = std::max((y2-y)/3, button_height);
00083   if(Config::GetInstance()->IsNetworkActivated())
00084     dy = std::max((y2-y)/4, button_height);
00085 
00086   play = new ButtonText(Point2i(x_button, y),
00087                         res, "main_menu/button",
00088                         _("Play"),
00089                         large_font);
00090   y += dy;
00091 
00092   if(Config::GetInstance()->IsNetworkActivated()) {
00093     network = new ButtonText( Point2i(x_button, y),
00094                               res, "main_menu/button",
00095                               _("Network Game"),
00096                               large_font );
00097     y += dy;
00098   } else {
00099     network = NULL;
00100   }
00101 
00102   options = new ButtonText(Point2i(x_button, y),
00103                            res, "main_menu/button",
00104                            _("Options"),
00105                            large_font);
00106   y += dy;
00107 
00108   infos =  new ButtonText(Point2i(x_button, y),
00109                           res, "main_menu/button",
00110                           _("Credits"),
00111                           large_font);
00112   y += dy;
00113 
00114   quit =  new ButtonText(Point2i(x_button, y),
00115                          res, "main_menu/button",
00116                          _("Quit"),
00117                          large_font);  
00118 
00119   widgets.AddWidget(play);
00120   if(Config::GetInstance()->IsNetworkActivated())
00121     widgets.AddWidget(network);
00122   widgets.AddWidget(options);
00123   widgets.AddWidget(infos);
00124   widgets.AddWidget(quit);
00125   widgets.AddWidget(title);
00126 
00127   resource_manager.UnLoadXMLProfile( res);
00128 
00129   std::string s("Version "+Constants::VERSION);
00130   version_text = new Text(s, green_color, normal_font, false);
00131 
00132   std::string s2(Constants::WEB_SITE);
00133   website_text = new Text(s2, green_color, normal_font, false);
00134 }
00135 
00136 void Main_Menu::button_clic()
00137 {
00138   jukebox.Play("share", "menu/clic");
00139 }
00140 
00141 void Main_Menu::OnClic(const Point2i &mousePosition, int button)
00142 {
00143   Widget* b = widgets.Clic(mousePosition,button);
00144   if(b == play)
00145   {
00146     choice = menuPLAY;
00147     close_menu = true;
00148     button_clic();
00149   }
00150   else if(b == network && Config::GetInstance()->IsNetworkActivated())
00151   {
00152     choice = menuNETWORK;
00153     close_menu = true;
00154     button_clic();
00155   }
00156   else if(b == options)
00157   {
00158     choice = menuOPTIONS;
00159     close_menu = true;
00160     button_clic();
00161   }
00162   else if(b == infos)
00163   {
00164     choice = menuCREDITS;
00165     close_menu = true;
00166     button_clic();
00167   }
00168   else if(b == quit)
00169   {
00170     choice = menuQUIT;
00171     close_menu = true;
00172     button_clic();
00173   }
00174 }
00175 
00176 menu_item Main_Menu::Run ()
00177 {
00178   choice = menuNULL;
00179 
00180   Menu::Run();
00181 
00182   assert( choice != menuNULL );
00183   return choice;
00184 }
00185 
00186 void Main_Menu::key_ok()
00187 {
00188   choice = menuPLAY;
00189   close_menu = true;
00190 }
00191 
00192 void Main_Menu::key_cancel()
00193 {
00194   choice = menuQUIT;
00195   close_menu = true;
00196 }
00197 
00198 void Main_Menu::__sig_cancel()
00199 {
00200   key_cancel();
00201 }
00202 
00203 void Main_Menu::__sig_ok()
00204 {
00205   key_ok();
00206 }
00207 
00208 void Main_Menu::DrawBackground(const Point2i &mousePosition)
00209 {
00210   Surface& window = AppWormux::GetInstance()->video.window;
00211 
00212   Menu::DrawBackground(mousePosition);
00213   skin_left->Blit(window, 0, window.GetHeight() - skin_left->GetHeight());
00214   skin_right->Blit(window, window.GetWidth()  - skin_right->GetWidth(),
00215                    window.GetHeight() - skin_right->GetHeight());
00216   
00217   version_text->DrawCenter( window.GetWidth()/2,
00218                             window.GetHeight() + VERSION_DY);
00219   website_text->DrawCenter( window.GetWidth()/2,
00220                             window.GetHeight() + VERSION_DY/2);
00221 
00222 }
00223 
00224 void Main_Menu::Redraw(const Rectanglei& rect, Surface &window)
00225 {
00226   Menu::Redraw(rect, window);
00227 
00228   // we never had to redraw texts
00229   // but sometimes we need to redraw the skins...
00230 
00231   Rectanglei dest(0, window.GetHeight() - skin_left->GetHeight(),
00232                   skin_left->GetWidth(), skin_left->GetHeight());
00233   dest.Clip(rect);
00234 
00235   Rectanglei src(rect.GetPositionX() - 0, 
00236                  rect.GetPositionY() - (window.GetHeight() - skin_left->GetHeight()), 
00237                  dest.GetSizeX(), dest.GetSizeY());
00238 
00239   skin_left->Blit(window, src, dest.GetPosition());
00240 
00241   Rectanglei dest2(window.GetWidth()  - skin_right->GetWidth(),
00242                    window.GetHeight() - skin_right->GetHeight(),
00243                    skin_right->GetWidth(), skin_right->GetHeight());
00244   dest2.Clip(rect);
00245          
00246   Rectanglei src2(dest2.GetPositionX() - (window.GetWidth()  - skin_right->GetWidth()), 
00247                   dest2.GetPositionY() - (window.GetHeight() - skin_right->GetHeight()), 
00248                   dest2.GetSizeX(), dest2.GetSizeY());
00249 
00250   skin_right->Blit(window, src2, dest2.GetPosition());
00251 
00252 
00253 }

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