exultmenu.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018  
00019 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 #include "menulist.h"
00024 #include "exultmenu.h"
00025 #include "exult.h"
00026 #include "mouse.h"
00027 #include "gamewin.h"
00028 #include "ibuf8.h"
00029 #include "game.h"
00030 #include "bggame.h"
00031 #include "sigame.h"
00032 #include "Audio.h"
00033 #include "font.h"
00034 #include "cheat.h"
00035 #include "Configuration.h"
00036 #include "txtscroll.h"
00037 #include "data/exult_flx.h"
00038 #include "palette.h"
00039 #include "shapeid.h"
00040 
00041 static bool get_play_intro(void);
00042 static void set_play_intro(bool);
00043 static bool get_play_1st_scene(void);
00044 static void set_play_1st_scene(bool);
00045 
00046 ExultMenu::ExultMenu(Game_window *gw)
00047 {
00048   gwin = gw;
00049   ibuf = gwin->get_win()->get_ib8();
00050   calc_win();
00051   fontManager.add_font("CREDITS_FONT", "<DATA>/exult.flx", EXULT_FLX_FONT_SHP, 1);
00052   exult_flx.load("<DATA>/exult.flx");
00053 }
00054 
00055 ExultMenu::~ExultMenu()
00056 {
00057 }
00058 
00059 void ExultMenu::calc_win()
00060 {
00061   topx = (gwin->get_width()-320)/2;
00062   topy = (gwin->get_height()-200)/2;
00063   centerx = gwin->get_width()/2;
00064   centery = gwin->get_height()/2;
00065   menuy = topy+120;
00066 }
00067 
00068 
00069 void ExultMenu::setup()
00070 {
00071   Palette *gpal = gwin->get_pal();
00072   Font *font = fontManager.get_font("CREDITS_FONT");
00073   MenuList menu;
00074 
00075   int menuypos = menuy-44;
00076   
00077   MenuChoice *scalemethod = new MenuChoice(exult_flx.get_shape(EXULT_FLX_SCALING_METHOD_SHP,1),
00078             exult_flx.get_shape(EXULT_FLX_SCALING_METHOD_SHP,0),
00079             centerx, menuypos, font);
00080   for (int i = 0; i < Image_window::NumScalers; i++)
00081     scalemethod->add_choice(Image_window::get_name_for_scaler(i));
00082   scalemethod->set_choice(gwin->get_win()->get_scaler());
00083   menu.add_entry(scalemethod);
00084   menuypos+=11;
00085   
00086   MenuChoice *palfades = new MenuChoice(exult_flx.get_shape(EXULT_FLX_PALETTE_FADES_SHP,1),
00087             exult_flx.get_shape(EXULT_FLX_PALETTE_FADES_SHP,0),
00088             centerx, menuypos, font);
00089   palfades->add_choice("Off");
00090   palfades->add_choice("On");
00091   palfades->set_choice(gwin->get_pal()->get_fades_enabled()?1:0);
00092   menu.add_entry(palfades);
00093   menuypos+=11;
00094 
00095   MenuChoice *midiconv = 0;
00096 #ifdef ENABLE_MIDISFX
00097   MenuChoice *sfxconv = 0;
00098 #endif
00099 
00100 
00101   if (Audio::get_ptr()->get_midi()) {
00102     midiconv = new MenuChoice(exult_flx.get_shape(EXULT_FLX_MIDI_CONVERSION_SHP,1),
00103           exult_flx.get_shape(EXULT_FLX_MIDI_CONVERSION_SHP,0),
00104           centerx, menuypos, font);
00105 
00106     midiconv->add_choice("None");
00107     midiconv->add_choice("GM");
00108     midiconv->add_choice("GS");
00109     midiconv->add_choice("GS127");
00110 
00111     midiconv->set_choice(Audio::get_ptr()->get_midi()->get_music_conversion());
00112     menu.add_entry(midiconv);
00113     menuypos+=11;
00114 
00115 #ifdef ENABLE_MIDISFX 
00116     MenuChoice *sfxconv = new MenuChoice(exult_flx.get_shape(EXULT_FLX_SFX_CONVERSION_SHP,1),
00117                exult_flx.get_shape(EXULT_FLX_SFX_CONVERSION_SHP,0),
00118                centerx, menuypos, font);
00119     sfxconv->add_choice("None");
00120     sfxconv->add_choice("GS");
00121     sfxconv->set_choice(Audio::get_ptr()->get_midi()->get_effects_conversion()==XMIDI_CONVERT_GS127_TO_GS?1:0);
00122 
00123     menu.add_entry(sfxconv);
00124     menuypos+=11;
00125 #endif
00126   }
00127   
00128   MenuChoice *playintro = new MenuChoice(exult_flx.get_shape(EXULT_FLX_PLAY_INTRO_SHP,1),
00129             exult_flx.get_shape(EXULT_FLX_PLAY_INTRO_SHP,0),
00130             centerx, menuypos, font);
00131   playintro->add_choice("Off");
00132   playintro->add_choice("On");
00133   playintro->set_choice(get_play_intro()?1:0);
00134   menu.add_entry(playintro);
00135   menuypos+=11;
00136 
00137   
00138   MenuChoice *playscene = new MenuChoice(exult_flx.get_shape(EXULT_FLX_PLAY_1ST_SCENE_SHP,1),
00139             exult_flx.get_shape(EXULT_FLX_PLAY_1ST_SCENE_SHP,0),
00140             centerx, menuypos, font);
00141   playscene->add_choice("Off");
00142   playscene->add_choice("On");
00143   playscene->set_choice(get_play_1st_scene()?1:0);
00144   menu.add_entry(playscene);
00145   menuypos+=11;
00146 
00147 
00148   MenuChoice *fullscreen = new MenuChoice(exult_flx.get_shape(EXULT_FLX_FULL_SCREEN_SHP,1),
00149             exult_flx.get_shape(EXULT_FLX_FULL_SCREEN_SHP,0),
00150             centerx, menuypos, font);
00151   fullscreen->add_choice("Off");
00152   fullscreen->add_choice("On");
00153   fullscreen->set_choice(gwin->get_win()->is_fullscreen()?1:0);
00154   menu.add_entry(fullscreen);
00155   menuypos+=11;
00156 
00157   MenuChoice *cheating = new MenuChoice(exult_flx.get_shape(EXULT_FLX_CHEATING_SHP,1),
00158               exult_flx.get_shape(EXULT_FLX_CHEATING_SHP,0),
00159               centerx, menuypos, font);
00160   cheating->add_choice("Off");
00161   cheating->add_choice("On");
00162   cheating->set_choice(cheat()?1:0);
00163   menu.add_entry(cheating);
00164   menuypos+=11;
00165 
00166   MenuEntry *ok = new MenuEntry(exult_flx.get_shape(EXULT_FLX_OK_SHP,1),
00167           exult_flx.get_shape(EXULT_FLX_OK_SHP,0),
00168           centerx-64, menuy+55);
00169   int ok_button = menu.add_entry(ok);
00170   
00171   MenuEntry *cancel = new MenuEntry(exult_flx.get_shape(EXULT_FLX_CANCEL_SHP,1),
00172        exult_flx.get_shape(EXULT_FLX_CANCEL_SHP,0),
00173        centerx+64, menuy+55);
00174   int cancel_button = menu.add_entry(cancel);
00175   
00176   menu.set_selection(0);
00177   gwin->clear_screen(true);
00178   for(;;) {
00179     gpal->apply();
00180     int entry = menu.handle_events(gwin,menu_mouse);
00181     if(entry==ok_button) {
00182       gpal->fade_out(c_fade_out_time);
00183       gwin->clear_screen(true);
00184       // Scaling Method
00185       int scaler = scalemethod->get_choice();
00186       if(scaler!=gwin->get_win()->get_scaler()) {
00187         gwin->resized(
00188           gwin->get_win()->get_width(),
00189           gwin->get_win()->get_height(),
00190           gwin->get_win()->get_scale(),
00191           scalemethod->get_choice()
00192         );
00193         if (scaler > Image_window::NoScaler && scaler < Image_window::NumScalers)
00194           config->set("config/video/scale_method",Image_window::get_name_for_scaler(scaler),true);
00195       }
00196       // Palette fades
00197       gpal->set_fades_enabled(
00198             palfades->get_choice()==1);
00199       config->set("config/video/disable_fades",
00200         gpal->get_fades_enabled()?"no":"yes",true);
00201 
00202       if (Audio::get_ptr()->get_midi()) {
00203         if (midiconv) {
00204           // Midi Conversion
00205           Audio::get_ptr()->get_midi()->set_music_conversion(midiconv->get_choice());
00206         }
00207 #ifdef ENABLE_MIDISFX
00208         if (sfxconv) {
00209         // SFX Conversion
00210           Audio::get_ptr()->get_midi()->set_effects_conversion(sfxconv->get_choice()==1?XMIDI_CONVERT_GS127_TO_GS:XMIDI_CONVERT_NOCONVERSION);
00211         }
00212 #endif
00213       }
00214       // Play Intro
00215       set_play_intro(playintro->get_choice()==1);
00216       // Play 1st scene
00217       set_play_1st_scene(playscene->get_choice()==1);
00218       // Full screen
00219       if(((fullscreen->get_choice()==0)&&(gwin->get_win()->is_fullscreen()))||
00220          ((fullscreen->get_choice()==1)&&(!gwin->get_win()->is_fullscreen())))
00221         gwin->get_win()->toggle_fullscreen();
00222       config->set("config/video/fullscreen",gwin->get_win()->is_fullscreen()?"yes":"no",true);
00223       // Cheating
00224       cheat.set_enabled(cheating->get_choice()==1);
00225       calc_win();
00226       return;
00227     } else if (entry==cancel_button) {
00228       gpal->fade_out(c_fade_out_time);
00229       gwin->clear_screen(true);
00230       return;
00231     }
00232   }
00233 }
00234 
00235 Exult_Game ExultMenu::run()
00236 {
00237   Palette *gpal = gwin->get_pal();
00238 
00239   Shape_manager *sman = Shape_manager::get_instance();
00240   Font *font = fontManager.get_font("CREDITS_FONT");
00241   // Check for the games in the designated directories.
00242   bool bg_installed = BG_Game::is_installed();
00243   bool si_installed = SI_Game::is_installed();
00244 
00245   if(!bg_installed && !si_installed) {
00246     gpal->load("<DATA>/exult.flx",EXULT_FLX_EXULT0_PAL);
00247     font->center_text(gwin->get_win()->get_ib8(),
00248           centerx, topy+20, "WARNING");
00249     font->center_text(gwin->get_win()->get_ib8(),
00250           centerx, topy+40, "Could not find the data files for either");
00251     font->center_text(gwin->get_win()->get_ib8(),
00252           centerx, topy+50, "\"The Black Gate\" or \"Serpent Isle\".");
00253     font->center_text(gwin->get_win()->get_ib8(),
00254           centerx, topy+60, "Please edit the configuration file");
00255     font->center_text(gwin->get_win()->get_ib8(),
00256           centerx, topy+70, "and restart Exult");
00257     gpal->apply();
00258     while(!wait_delay(200))
00259       ; 
00260     throw quit_exception(1);
00261 
00262   }
00263   ExultDataSource *midi_data = new ExultDataSource("<DATA>/exult.flx", EXULT_FLX_MEDITOWN_MID);
00264   XMIDI midfile(midi_data, XMIDI_CONVERT_NOCONVERSION);
00265   
00266   if(Audio::get_ptr()->audio_enabled)   //Must check this or it will crash as midi 
00267                       //may not be initialised
00268   {
00269     if(Audio::get_ptr()->get_midi()->get_output_driver_type() == MIDI_DRIVER_OGG)
00270       Audio::get_ptr()->start_music(99,true);
00271     else
00272       Audio::get_ptr()->start_music(midfile.GetEventList(0), true);
00273   }
00274   
00275   ExultDataSource mouse_data("<DATA>/exult.flx", EXULT_FLX_POINTERS_SHP);
00276   menu_mouse = new Mouse(gwin, mouse_data);
00277   
00278   sman->paint_shape(topx,topy,exult_flx.get_shape(EXULT_FLX_EXULT_LOGO_SHP, 0));
00279   gpal->load("<DATA>/exult.flx",EXULT_FLX_EXULT0_PAL);
00280   gpal->fade_in(c_fade_in_time);
00281   wait_delay(2000);
00282   MenuList *menu = new MenuList();
00283     
00284   int menuchoices[] = { 
00285     EXULT_FLX_BLACK_GATE_SHP,
00286     EXULT_FLX_SERPENT_ISLE_SHP,
00287     EXULT_FLX_SETUP_SHP,
00288     EXULT_FLX_EXULT_CREDITS_SHP,
00289     EXULT_FLX_EXULT_QUOTES_SHP,
00290     EXULT_FLX_EXIT_SHP 
00291   };
00292   int num_choices = sizeof(menuchoices)/sizeof(int);
00293   int *menuentries = new int[num_choices];
00294   int entries = 0;
00295   int sfx_bg_ypos = -1, sfx_si_ypos = -1;
00296   
00297   int ypos = menuy-24;
00298   for(int i=0; i<num_choices; i++) {
00299     if((i==0 && bg_installed)||(i==1 && si_installed)||i>1) {
00300       menu->add_entry(new MenuEntry(exult_flx.get_shape(menuchoices[i],1),
00301                   exult_flx.get_shape(menuchoices[i],0),
00302                   centerx, ypos));
00303       if(i==0)
00304         sfx_bg_ypos = ypos;
00305       if(i==1)
00306         sfx_si_ypos = ypos;
00307       ypos += exult_flx.get_shape(menuchoices[i],0)->get_height()+2;
00308       menuentries[entries++]=i;
00309     }
00310     if(i<2)
00311       ypos+=5;
00312   }
00313   menu->set_selection(0);
00314   Exult_Game sel_game = NONE;
00315   
00316   do {
00317     sman->paint_shape(topx,topy,exult_flx.get_shape(EXULT_FLX_EXULT_LOGO_SHP, 1));
00318     font->draw_text(gwin->get_win()->get_ib8(), 
00319           topx+320-font->get_text_width(VERSION), topy+190, VERSION);
00320     if (sfx_bg_ypos >= 0)
00321       sman->paint_shape(centerx-80,sfx_bg_ypos, exult_flx.get_shape(EXULT_FLX_SFX_ICON_SHP, Audio::get_ptr()->can_sfx("blackgate")?1:0));
00322     if (sfx_si_ypos >= 0)
00323       sman->paint_shape(centerx-80,sfx_si_ypos,exult_flx.get_shape(EXULT_FLX_SFX_ICON_SHP, Audio::get_ptr()->can_sfx("serpentisle")?1:0));
00324     int choice = menu->handle_events(gwin, menu_mouse);
00325     switch(choice<0?choice:menuentries[choice]) {
00326     case 5:
00327     case -1: // Exit
00328       gpal->fade_out(c_fade_out_time);
00329       Audio::get_ptr()->stop_music();
00330       throw quit_exception();
00331     case 0: // Black Gate
00332       gpal->fade_out(c_fade_out_time);
00333       sel_game = BLACK_GATE;
00334       break;
00335     case 1: // Serpent Isle
00336       gpal->fade_out(c_fade_out_time);
00337       sel_game = SERPENT_ISLE;
00338       break;
00339     case 2: // Setup
00340       gpal->fade_out(c_fade_out_time);
00341       setup();
00342       gpal->apply();
00343       break;
00344     case 3: // Exult Credits
00345       {
00346         gpal->fade_out(c_fade_out_time);
00347         TextScroller credits("<DATA>/exult.flx", EXULT_FLX_CREDITS_TXT, 
00348                  fontManager.get_font("CREDITS_FONT"),
00349                  exult_flx.extract_shape(EXULT_FLX_EXTRAS_SHP));
00350         credits.run(gwin);
00351         gwin->clear_screen(true);
00352         gpal->apply();
00353       }
00354       break;
00355     case 4: // Exult Quotes
00356       {
00357         gpal->fade_out(c_fade_out_time);
00358         TextScroller quotes("<DATA>/exult.flx", EXULT_FLX_QUOTES_TXT, 
00359                 fontManager.get_font("CREDITS_FONT"),
00360                     exult_flx.extract_shape(EXULT_FLX_EXTRAS_SHP));
00361         quotes.run(gwin);
00362         gwin->clear_screen(true);
00363         gpal->apply();
00364       }
00365       break;
00366     default:
00367       break;
00368     }
00369   } while(sel_game==NONE);
00370   delete[] menuentries;
00371   delete menu;
00372   
00373   gwin->clear_screen(true);
00374   Audio::get_ptr()->stop_music();
00375   delete menu_mouse;
00376   delete midi_data;
00377   return sel_game;
00378 }
00379 
00380 bool get_play_intro (void)
00381 {
00382   std::string yn;
00383   config->value("config/gameplay/skip_splash", yn, "no");
00384   return(yn=="no");
00385 }
00386 
00387 void set_play_intro (bool play)
00388 {
00389   config->set("config/gameplay/skip_splash", play?"no":"yes", true);
00390 }
00391 
00392 bool get_play_1st_scene (void)
00393 {
00394   std::string yn;
00395   config->value("config/gameplay/skip_intro", yn, "no");
00396   return(yn=="no");
00397 }
00398 
00399 void set_play_1st_scene (bool play)
00400 {
00401   config->set("config/gameplay/skip_intro", play?"no":"yes", true);
00402 }

Generated on Mon Jul 9 14:42:45 2007 for ExultEngine by  doxygen 1.5.1