00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022
00023 #include "SDL_events.h"
00024
00025 #include "Gamemenu_gump.h"
00026 #include "AudioOptions_gump.h"
00027 #include "VideoOptions_gump.h"
00028 #include "GameplayOptions_gump.h"
00029 #include "CombatOptions_gump.h"
00030 #include "Gump_button.h"
00031 #include "Yesno_gump.h"
00032 #include "gamewin.h"
00033 #include "Newfile_gump.h"
00034 #include "File_gump.h"
00035 #include "mouse.h"
00036 #include "exult.h"
00037 #include "exult_flx.h"
00038 #include "Text_button.h"
00039 #include "gameclk.h"
00040 #include "Gump_manager.h"
00041 #include <string>
00042
00043 using std::string;
00044
00045 static const int rowy[6] = { 4, 17, 30, 43, 56, 69 };
00046 static const int colx = 31;
00047
00048 static const char* loadsavetext = "Load/Save Game";
00049 static const char* videoopttext = "Video Options";
00050 static const char* audioopttext = "Audio Options";
00051 static const char* gameopttext = "Gameplay Options";
00052 static const char *combattext = "Combat Options";
00053 static const char* quitmenutext = "Quit to Menu";
00054 static const char* quittext = "Quit";
00055
00056 class Gamemenu_button : public Text_button {
00057 public:
00058 Gamemenu_button(Gump *par, string text, int px, int py)
00059 : Text_button(par, text, px, py, 108, 11)
00060 { }
00061
00062 virtual void activate();
00063 };
00064
00065 void Gamemenu_button::activate()
00066 {
00067 if (text == loadsavetext) {
00068 ((Gamemenu_gump*)parent)->loadsave();
00069 } else if (text == videoopttext) {
00070 ((Gamemenu_gump*)parent)->video_options();
00071 } else if (text == audioopttext) {
00072 ((Gamemenu_gump*)parent)->audio_options();
00073 } else if (text == gameopttext) {
00074 ((Gamemenu_gump*)parent)->gameplay_options();
00075 } else if (text == combattext) {
00076 ((Gamemenu_gump*)parent)->combat_options();
00077 } else if (text == quitmenutext) {
00078 ((Gamemenu_gump*)parent)->quit(true);
00079 } else if (text == quittext) {
00080 ((Gamemenu_gump*)parent)->quit(false);
00081 }
00082 }
00083
00084 Gamemenu_gump::Gamemenu_gump() : Modal_gump(0, EXULT_FLX_GAMEMENU_SHP, SF_EXULT_FLX)
00085 {
00086 set_object_area(Rectangle(0,0,0,0), 8, 82);
00087
00088 buttons[0] = new Gamemenu_button(this, loadsavetext, colx, rowy[0]);
00089 buttons[1] = new Gamemenu_button(this, videoopttext, colx, rowy[1]);
00090 buttons[2] = new Gamemenu_button(this, audioopttext, colx, rowy[2]);
00091 buttons[3] = new Gamemenu_button(this, gameopttext, colx, rowy[3]);
00092 buttons[4] = new Gamemenu_button(this, combattext, colx, rowy[4]);
00093 buttons[5] = new Gamemenu_button(this, quittext, colx, rowy[5]);
00094 }
00095
00096 Gamemenu_gump::~Gamemenu_gump()
00097 {
00098 for (int i=0; i<6; i++)
00099 delete buttons[i];
00100 }
00101
00102
00103 void Gamemenu_gump::quit(bool return_to_menu)
00104 {
00105 if (!Yesno_gump::ask("Do you really want to quit?"))
00106 return;
00107 quitting_time = QUIT_TIME_YES;
00108 done = 1;
00109 }
00110
00111
00112 void Gamemenu_gump::loadsave()
00113 {
00114
00115 Newfile_gump *fileio = new Newfile_gump();
00116 gumpman->do_modal_gump(fileio, Mouse::hand);
00117 if (fileio->restored_game())
00118 done = true;
00119 delete fileio;
00120 }
00121
00122 void Gamemenu_gump::video_options()
00123 {
00124 VideoOptions_gump *vid_opts = new VideoOptions_gump();
00125 gumpman->do_modal_gump(vid_opts, Mouse::hand);
00126
00127
00128 set_pos();
00129 gwin->paint();
00130 gwin->show();
00131 delete vid_opts;
00132
00133 gclock->set_palette();
00134 }
00135
00136 void Gamemenu_gump::audio_options()
00137 {
00138 AudioOptions_gump *aud_opts = new AudioOptions_gump();
00139 gumpman->do_modal_gump(aud_opts, Mouse::hand);
00140 delete aud_opts;
00141 }
00142
00143 void Gamemenu_gump::gameplay_options()
00144 {
00145 GameplayOptions_gump *gp_opts = new GameplayOptions_gump();
00146 gumpman->do_modal_gump(gp_opts, Mouse::hand);
00147 delete gp_opts;
00148 }
00149
00150 void Gamemenu_gump::combat_options()
00151 {
00152 CombatOptions_gump *cbt_opts = new CombatOptions_gump();
00153 gumpman->do_modal_gump(cbt_opts, Mouse::hand);
00154 delete cbt_opts;
00155 }
00156
00157 void Gamemenu_gump::paint()
00158 {
00159 Gump::paint();
00160 for (int i=0; i<6; i++)
00161 if (buttons[i])
00162 buttons[i]->paint();
00163 gwin->set_painted();
00164 }
00165
00166 void Gamemenu_gump::mouse_down(int mx, int my)
00167 {
00168 pushed = Gump::on_button(mx, my);
00169
00170
00171 if (!pushed)
00172 for (int i=0; i<6; i++)
00173 if (buttons[i] && buttons[i]->on_button(mx, my)) {
00174 pushed = buttons[i];
00175 break;
00176 }
00177
00178 if (pushed)
00179 {
00180 pushed->push();
00181 return;
00182 }
00183 }
00184
00185 void Gamemenu_gump::mouse_up(int mx, int my)
00186 {
00187 if (pushed)
00188 {
00189 pushed->unpush();
00190 if (pushed->on_button(mx, my))
00191 ((Gamemenu_button*)pushed)->activate();
00192 pushed = 0;
00193 }
00194 }
00195