gamedialog.cpp

Go to the documentation of this file.
00001 //
00002 // C++ Implementation: gamedialog
00003 //
00004 // Description:
00005 //
00006 //
00007 // Author: Kevin Hirschmann <hirsch@dhcppc0>, (C) 2005
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 #include <sstream>
00013 #include <pgimage.h>
00014 #include <pglistboxitem.h>
00015 #include <pgpopupmenu.h>
00016 
00017 
00018 #include "gamedialog.h"
00019 // #include "gamedlg.h"
00020 #include "guidimension.h"
00021 #include "sdl/sound.h"
00022 #include "misc.h"
00023 #include "dialogs/selectionwindow.h"
00024 #include "dialogs/fileselector.h"
00025 #include "dialogs/soundsettings.h"
00026 #include "dialogs/newgame.h"
00027 #include "dialogs/editgameoptions.h"
00028 #include "dialog.h"
00029 #include "sigc++/retype.h"
00030 #include "iconrepository.h"
00031 #include "sg.h"
00032 #include "loaders.h"
00033 #include "spfst.h"
00034 #include "spfst-legacy.h"
00035 #include "networksupervisor.h"
00036 
00037 const int GameDialog::xSize = 450;
00038 const int GameDialog::ySize = 550;
00039 const int GameDialog::buttonIndent = 150;
00040 GameDialog* GameDialog::instance = 0;
00041 
00042 GameDialog::GameDialog():  ASC_PG_Dialog(NULL, PG_Rect( -1, -1, xSize, ySize ), "Game", SHOW_CLOSE ) {
00043     singlePlayerButton = new PG_Button(this, PG_Rect(buttonIndent, GuiDimension::getTopOffSet()*2, 150, GuiDimension::getButtonHeight()), "New Game", 90);
00044     singlePlayerButton->sigClick.connect( SigC::slot( *this, &GameDialog::newGame));
00045 
00046     PG_Point p = ScreenToClient(singlePlayerButton->x, singlePlayerButton->y);
00047     multiPlayerButton = new PG_Button(this, PG_Rect(p.x, p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() , 150, GuiDimension::getButtonHeight()), "Continue Mail Game", 90);
00048     multiPlayerButton->sigClick.connect( SigC::slot( *this, &GameDialog::multiGame));
00049 
00050     p = ScreenToClient(multiPlayerButton->x, multiPlayerButton->y);
00051     loadGameButton = new PG_Button(this, PG_Rect(p.x, p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() , 150, GuiDimension::getButtonHeight()), "Load Game", 90);
00052     loadGameButton->sigClick.connect( SigC::slot( *this, &GameDialog::loadGame));
00053 
00054     p = ScreenToClient(loadGameButton->x, loadGameButton->y);
00055     saveGameButton = new PG_Button(this, PG_Rect(p.x, p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() , 150, GuiDimension::getButtonHeight()), "Save Game", 90);
00056     saveGameButton->sigClick.connect( SigC::slot( *this, &GameDialog::saveGame));
00057 
00058     p = ScreenToClient(loadGameButton->x, saveGameButton->y);
00059     PG_Button* superViseButton= new PG_Button(this, PG_Rect(p.x, p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() , 150, GuiDimension::getButtonHeight()), "Supervise Net Game", 90);
00060     superViseButton->sigClick.connect( SigC::slot( *this, &GameDialog::supervise));
00061 
00062 
00063     p = ScreenToClient(superViseButton->x, superViseButton->y);
00064     optionsButton = new PG_Button(this, PG_Rect(p.x, p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() , 150, GuiDimension::getButtonHeight()), "Options", 90);
00065     optionsButton->sigClick.connect( SigC::slot( *this, &GameDialog::showOptions));
00066 
00067 
00068     p = ScreenToClient(optionsButton->x, optionsButton->y);
00069     exitButton  = new PG_Button(this, PG_Rect(p.x, p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() , 150, GuiDimension::getButtonHeight()), "Quit Game", 90);
00070     exitButton->sigClick.connect( SigC::slot( *this, &GameDialog::exitGame));
00071 
00072     if ( actmap ) {
00073       p = ScreenToClient(exitButton->x, exitButton->y);
00074       continueButton = new PG_Button(this, PG_Rect(p.x, p.y + GuiDimension::getButtonHeight() + 2 * GuiDimension::getTopOffSet() , 150, GuiDimension::getButtonHeight()), "Return to Game", 90);
00075       continueButton->sigClick.connect( SigC::slot( *this, &GameDialog::closeWindow ));
00076     }
00077 
00078     sigClose.connect( SigC::slot( *this, &GameDialog::closeWindow ));    
00079     SetInputFocus();
00080 }
00081 
00082 
00083 
00084 GameDialog::~GameDialog() {
00085 }
00086 bool GameDialog::eventKeyDown (const SDL_KeyboardEvent *key) {    
00087 
00088    int mod = SDL_GetModState() & ~(KMOD_NUM | KMOD_CAPS | KMOD_MODE);
00089 
00090    if(key->keysym.sym == SDLK_ESCAPE) {
00091         closeWindow();
00092     }
00093 
00094    if ( mod == 0 ) {
00095       switch ( key->keysym.sym ) {
00096             case SDLK_F3:
00097                executeUserAction ( ua_continuenetworkgame );
00098                QuitModal();
00099                return true;
00100 
00101             case SDLK_F4:
00102                executeUserAction ( ua_networksupervisor );
00103                QuitModal();
00104                return true;
00105             default:;
00106       }
00107    }
00108 
00109 
00110    if ( (mod & KMOD_SHIFT) && (mod & KMOD_CTRL)) {
00111       switch ( key->keysym.sym ) {
00112             case SDLK_l:
00113                executeUserAction ( ua_loadrecentgame );
00114                QuitModal();
00115                return true;
00116             default:;
00117       }
00118    }
00119 
00120 
00121 
00122    if ( mod & KMOD_CTRL ) {
00123       switch ( key->keysym.sym ) {
00124             case SDLK_l:
00125                executeUserAction ( ua_loadgame );
00126                QuitModal();
00127                return true;
00128             default:;
00129       }
00130    }
00131 
00132    if ( mod & KMOD_SHIFT ) {
00133       switch ( key->keysym.sym ) {
00134             case SDLK_F3:
00135                executeUserAction ( ua_continuerecentnetworkgame );
00136                QuitModal();
00137                return true;
00138             default:;
00139       }
00140    }
00141 
00142    
00143     return true;
00144 }
00145 
00146 
00147 
00148 bool GameDialog::closeWindow() {
00149     quitModalLoop(1);
00150 
00151     return true;
00152 }
00153 
00154 bool GameDialog::exitGame(PG_Button* button) {
00155     Hide();
00156     if (choice_dlg( "do you really want to quit ?", "~y~es","~n~o") == 1) {
00157        getPGApplication().Quit();
00158     }
00159     quitModalLoop(1);
00160     return true;
00161 }
00162 
00163 
00164 bool GameDialog::supervise(PG_Button* button) {
00165    networksupervisor();
00166     return true;
00167 }
00168 
00169 
00170 
00171 
00172 bool GameDialog::showOptions(PG_Button* button) {
00173     Hide();
00174     OptionsDialog::optionsDialog(this);
00175     Show();
00176     return true;
00177 }
00178 
00179 bool GameDialog::saveGame(PG_Button* button) {
00180     Hide();
00181     ::saveGame(true);
00182     Show();
00183     return true;
00184 }
00185 
00186 bool GameDialog::loadGame(PG_Button* button) {
00187    if ( ::loadGame(false)) 
00188       QuitModal();
00189       
00190     return true;
00191 }
00192 
00193 bool GameDialog::newGame(PG_Button* button)
00194 {
00195    Hide();
00196    if ( startMultiplayerGame() ) {
00197       hookGuiToMap(actmap);
00198       QuitModal();
00199       
00200    } else
00201       Show();
00202    return true;
00203 }
00204 
00205 
00206 bool GameDialog::singleGame(PG_Button* button) {
00207     Hide();
00208     SinglePlayerDialog::singlePlayerDialog(this);
00209     Show();
00210     return true;
00211 }
00212 
00213 bool GameDialog::multiGame(PG_Button* button) {
00214     Hide();
00215     // MultiPlayerDialog::multiPlayerDialog(this);
00216     if ( continueAndStartMultiplayerGame( false ) ) {
00217        QuitModal();
00218     } else
00219       Show();
00220     return true;
00221 }
00222 
00223 
00224 bool GameDialog::gameDialog() {
00225    GameDialog gd;
00226    gd.Show();
00227    gd.RunModal();
00228    /*
00229         GameDialog* gd = new GameDialog();
00230         instance = gd;
00231         gd->Show();
00232         gd->RunModal();
00233         delete gd;
00234         GameDialog::instance = 0;
00235     }
00236     */
00237     return true;
00238 }
00239 
00240 
00241 //*******************************************************************************************************************+
00242 const int ConfirmExitDialog::xSize = 450;
00243 const int ConfirmExitDialog::ySize = 120;
00244 
00245 
00246 ConfirmExitDialog::ConfirmExitDialog(PG_MessageObject* c): ASC_PG_Dialog(NULL, PG_Rect( 200, 100, xSize, ySize ), "End Game", MODAL ) {
00247 
00248     okButton = new PG_Button(this, PG_Rect(80, GuiDimension::getTopOffSet()*2, 150, GuiDimension::getButtonHeight()), "OK", 90);
00249     okButton->sigClick.connect( SigC::slot( *this, &ConfirmExitDialog::exitGame ));
00250 
00251     PG_Point p = ScreenToClient(okButton->x, okButton->y);
00252     cancelButton = new PG_Button(this, PG_Rect(p.x + 150 + 10, p.y, 150, GuiDimension::getButtonHeight()), "Cancel", 90);
00253     cancelButton->sigClick.connect( SigC::slot( *this, &ConfirmExitDialog::closeWindow ));
00254 }
00255 
00256 
00257 ConfirmExitDialog::~ConfirmExitDialog() {
00258 }
00259 
00260 bool ConfirmExitDialog::closeWindow() {
00261     quitModalLoop(1);
00262 
00263     return true;
00264 }
00265 
00266 bool ConfirmExitDialog::exitGame(PG_Button* button) {
00267     // throw ThreadExitException();
00268     quitModalLoop(1);
00269     getPGApplication().Quit();
00270     return true;
00271 }
00272 
00273 void ConfirmExitDialog::confirmExitDialog(PG_MessageObject* caller) {
00274     ConfirmExitDialog ced(caller);
00275     ced.Show();
00276     ced.RunModal();
00277 }
00278 
00279 //*******************************************************************************************************************+
00280 
00281 const int SinglePlayerDialog::xSize = 450;
00282 const int SinglePlayerDialog::ySize = 250;
00283 const int SinglePlayerDialog::buttonIndent = 150;
00284 SinglePlayerDialog* SinglePlayerDialog::instance = 0;
00285 
00286 SinglePlayerDialog::SinglePlayerDialog( PG_MessageObject * c): ASC_PG_Dialog(NULL, PG_Rect( 200, 100, xSize, ySize ), "Single Player", SHOW_CLOSE ) {
00287 
00288     campaignButton = new PG_Button(this, PG_Rect(buttonIndent, GuiDimension::getTopOffSet()*2, 150, GuiDimension::getButtonHeight()), "Campaign", 90);
00289     campaignButton->sigClick.connect( SigC::slot( *this, &SinglePlayerDialog::campaign ));
00290 
00291     PG_Point p = ScreenToClient(campaignButton->x, campaignButton->y);
00292     singleLevelButton = new PG_Button(this, PG_Rect(p.x,  p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet(), 150, GuiDimension::getButtonHeight()), "Single Level", 90);
00293     singleLevelButton->sigClick.connect( SigC::slot( *this, &SinglePlayerDialog::singleLevel ));
00294 
00295     p = ScreenToClient(singleLevelButton->x, singleLevelButton->y);
00296     cancelButton = new PG_Button(this, PG_Rect(p.x,  p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() * 2, 150, GuiDimension::getButtonHeight()), "Cancel", 90);
00297     cancelButton->sigClick.connect( SigC::slot( *this, &SinglePlayerDialog::closeWindow ));
00298 
00299     sigClose.connect( SigC::slot( *this, &SinglePlayerDialog::closeWindow ));
00300     caller = c;
00301     SetInputFocus();
00302 }
00303 
00304 
00305 SinglePlayerDialog::~SinglePlayerDialog() {
00306 }
00307 
00308 bool SinglePlayerDialog::closeWindow() {
00309     quitModalLoop(1);
00310     caller->SetInputFocus();
00311     return true;
00312 }
00313 
00314 bool SinglePlayerDialog::campaign(PG_Button* button) {
00315     Hide();
00316 
00317     Show();
00318     return true;
00319 }
00320 
00321 bool SinglePlayerDialog::singleLevel(PG_Button* button) {
00322     Hide();
00323 
00324     Show();
00325     return true;
00326 }
00327 
00328 
00329 void SinglePlayerDialog::singlePlayerDialog(PG_MessageObject* caller) {
00330     if(SinglePlayerDialog::instance == 0) {
00331         SinglePlayerDialog* spd = new SinglePlayerDialog(caller);
00332         SinglePlayerDialog::instance = spd;
00333         spd->Show();
00334         spd->RunModal();
00335         delete spd;
00336         SinglePlayerDialog::instance = 0;
00337     }
00338 }
00339 
00340 //*******************************************************************************************************************+
00341 
00342 const int MultiPlayerDialog::xSize = 450;
00343 const int MultiPlayerDialog::ySize = 350;
00344 const int MultiPlayerDialog::buttonIndent = 140;
00345 
00346 MultiPlayerDialog::MultiPlayerDialog(PG_MessageObject* c): ASC_PG_Dialog(NULL, PG_Rect( 200, 100, xSize, ySize ), "Multi Player", SHOW_CLOSE ) {
00347 
00348     continueGameButton = new PG_Button(this, PG_Rect(buttonIndent, GuiDimension::getTopOffSet()*2, GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Continue Network Game", 90);
00349     continueGameButton->sigClick.connect( SigC::slot( *this, &MultiPlayerDialog::continueGame ));
00350 
00351     PG_Point p = ScreenToClient(continueGameButton->x, continueGameButton->y);
00352     superViseButton = new PG_Button(this, PG_Rect(p.x,  p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet(), GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Supervise Network Game", 90);
00353     superViseButton->sigClick.connect( SigC::slot( *this, &MultiPlayerDialog::superVise ));
00354 
00355     p = ScreenToClient(superViseButton->x, superViseButton->y);
00356     setupNWButton = new PG_Button(this, PG_Rect(p.x,  p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet(), GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Setup Network Game", 90);
00357     setupNWButton->sigClick.connect( SigC::slot( *this, &MultiPlayerDialog::closeWindow ));
00358     
00359      p = ScreenToClient(setupNWButton->x, setupNWButton->y);
00360     changeMapPasswordButton = new PG_Button(this, PG_Rect(p.x,  p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet(), GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Change Password", 90);
00361     changeMapPasswordButton->sigClick.connect( SigC::slot( *this, &MultiPlayerDialog::changeMapPassword ));
00362 
00363     p = ScreenToClient(changeMapPasswordButton->x, changeMapPasswordButton->y);
00364     cancelButton = new PG_Button(this, PG_Rect(p.x,  p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() * 2, GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Cancel", 90);
00365     cancelButton->sigClick.connect( SigC::slot( *this, &MultiPlayerDialog::closeWindow ));
00366 
00367     cancelButton->sigClick.connect( SigC::slot( *this, &MultiPlayerDialog::closeWindow ));
00368 
00369     sigClose.connect( SigC::slot( *this, &MultiPlayerDialog::closeWindow ));
00370 
00371     caller = c;
00372     SetInputFocus();
00373 }
00374 
00375 
00376 MultiPlayerDialog::~MultiPlayerDialog() {
00377 }
00378 
00379 bool MultiPlayerDialog::closeWindow() {
00380     quitModalLoop(1);
00381     caller->SetInputFocus();
00382     return true;
00383 }
00384 
00385 bool MultiPlayerDialog::continueGame(PG_Button* button) {
00386     Hide();
00387 
00388     Show();
00389     return true;
00390 }
00391 
00392 bool MultiPlayerDialog::changeMapPassword(PG_Button* button) {
00393     Hide();
00394     ChangeMapPasswordDialog::changeMapPasswordDialog(this);
00395     Show();
00396     return true;
00397 }
00398 
00399 bool MultiPlayerDialog::superVise(PG_Button* button) {
00400     Hide();
00401     Show();
00402     return true;
00403 }
00404 
00405 
00406 void MultiPlayerDialog::multiPlayerDialog(PG_MessageObject* c) {
00407     MultiPlayerDialog spd(c);
00408     spd.Show();
00409     spd.RunModal();
00410 }
00411 
00412 
00413 //*******************************************************************************************************************+
00414 const int OptionsDialog::xSize = 450;
00415 const int OptionsDialog::ySize = 400;
00416 const int OptionsDialog::buttonIndent = 150;
00417 
00418 OptionsDialog::OptionsDialog(PG_MessageObject* c ): ASC_PG_Dialog(NULL, PG_Rect( 200, 100, xSize, ySize ), "Options", SHOW_CLOSE ) {
00419 
00420     soundButton = new PG_Button(this, PG_Rect(buttonIndent, GuiDimension::getTopOffSet()*2, 150, GuiDimension::getButtonHeight()), "Sound Options", 90);
00421     soundButton->sigClick.connect( SigC::slot( *this, &OptionsDialog::showSoundOptions ));
00422 
00423     PG_Point p = ScreenToClient(soundButton->x, soundButton->y);
00424     otherButton = new PG_Button(this, PG_Rect(p.x,  p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet(), 150, GuiDimension::getButtonHeight()), "Game Options", 90);
00425     otherButton->sigClick.connect( SigC::slot( *this, &OptionsDialog::showOtherOptions ));
00426 
00427     p = ScreenToClient(otherButton->x, otherButton->y);
00428     PG_Button* okButton = new PG_Button(this, PG_Rect(p.x,  p.y + GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet() * 2, 150, GuiDimension::getButtonHeight()), "Back", 90);
00429     okButton->sigClick.connect( SigC::slot( *this, &OptionsDialog::closeWindow ));
00430 
00431     sigClose.connect( SigC::slot( *this, &OptionsDialog::closeWindow ));
00432 
00433     caller = c;
00434     SetInputFocus();
00435 }
00436 
00437 
00438 OptionsDialog::~OptionsDialog() {
00439 }
00440 
00441 bool OptionsDialog::closeWindow() {
00442     quitModalLoop(1);
00443     caller->SetInputFocus();
00444     return true;
00445 }
00446 
00447 bool OptionsDialog::showSoundOptions(PG_Button* button) {
00448     Hide();
00449     soundSettings(this);
00450     Show();
00451     return true;
00452 }
00453 /*
00454 bool OptionsDialog::showMouseOptions(PG_Button* button) {
00455     Hide();
00456     MousePreferencesDialog::mousePreferencesDialog(this);
00457     Show();
00458     return true;
00459 }
00460 */
00461 
00462 bool OptionsDialog::showOtherOptions(PG_Button* button) {
00463     Hide();
00464     editGameOptions();
00465     Show();
00466     return true;
00467 }
00468 
00469 void OptionsDialog::optionsDialog(PG_MessageObject* caller) {
00470     OptionsDialog od(caller);
00471     od.Show();
00472     od.RunModal();
00473 }
00474 
00475 
00476 //*******************************************************************************************************************+
00477 const int GameOptionsDialog::xSize = 450;
00478 const int GameOptionsDialog::ySize = 320;
00479 const int GameOptionsDialog::buttonIndent = 60;
00480 
00481 GameOptionsDialog::GameOptionsDialog(PG_MessageObject* c): ASC_PG_Dialog(NULL, PG_Rect( 200, 100, xSize, ySize ), "Game Options",
00482         SHOW_CLOSE ) {
00483 
00484     autoAmmunitionLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), static_cast<int>(GuiDimension::getTopOffSet() * 1.5), 10, GetTextHeight() * 2), "Auto Ammunition");
00485     autoAmmunitionLabel->SetSizeByText();
00486 
00487     PG_Point p = ScreenToClient(autoUnitTrainingLabel->x, autoUnitTrainingLabel->y);
00488     promptEndOfTurnLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), p.y + GuiDimension::getTopOffSet() + GetTextHeight() * 2 , 10, GetTextHeight() * 2), "Prompt End of Turn");
00489     promptEndOfTurnLabel->SetSizeByText();
00490 
00491     promptEndOfTurnCButton = new PG_CheckButton(this, PG_Rect(xSize - (GuiDimension::getLineEditWidth() + GuiDimension::getLeftIndent()), p.y + GuiDimension::getTopOffSet() + static_cast<int>(GetTextHeight() * 1.5), GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00492     if(CGameOptions::Instance()->CGameOptions::Instance()->endturnquestion){
00493       promptEndOfTurnCButton->SetPressed();
00494     }
00495 
00496     p = ScreenToClient(promptEndOfTurnLabel->x, promptEndOfTurnLabel->y);
00497     changePasswordButton = new PG_Button(this, PG_Rect((xSize - GuiDimension::getButtonWidth())/2, p.y + GuiDimension::getTopOffSet() + GetTextHeight() * 2 , GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Change Password");
00498     changePasswordButton->sigClick.connect( SigC::slot( *this, &GameOptionsDialog::changePassword ));
00499 
00500     okButton = new PG_Button(this, PG_Rect( buttonIndent, ySize - (GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet()), GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "OK", 90);
00501     okButton->sigClick.connect( SigC::slot( *this, &GameOptionsDialog::ok ));
00502 
00503     p = ScreenToClient(okButton->x, okButton->y);
00504     cancelButton = new PG_Button(this, PG_Rect(p.x + GuiDimension::getButtonWidth() + 10, p.y, GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Cancel", 90);
00505     cancelButton->sigClick.connect( SigC::slot( *this, &GameOptionsDialog::closeWindow ));
00506 
00507     sigClose.connect( SigC::slot( *this, &GameOptionsDialog::closeWindow ));
00508 
00509     caller = c;
00510     SetInputFocus();
00511 }
00512 
00513 
00514 GameOptionsDialog::~GameOptionsDialog() {
00515 }
00516 
00517 bool GameOptionsDialog::closeWindow() {
00518     quitModalLoop(1);
00519     caller->SetInputFocus();
00520     return true;
00521 }
00522 
00523 bool GameOptionsDialog::changePassword(PG_Button* button){
00524 Hide();
00525 ChangeDefaultPasswordDialog::changeDefaultPasswordDialog(this);
00526 Show();
00527 return true;
00528 }
00529 bool GameOptionsDialog::ok(PG_Button* button) {
00530     CGameOptions::Instance()->CGameOptions::Instance()->endturnquestion = promptEndOfTurnCButton->GetPressed();
00531     quitModalLoop(1);
00532     return true;
00533 }
00534 
00535 void GameOptionsDialog::gameOptionsDialog(PG_MessageObject* caller) {
00536     GameOptionsDialog god(caller);
00537     god.Show();
00538     god.RunModal();
00539 }
00540 
00541 
00542 //*******************************************************************************************************************+
00543 const int ChangePasswordDialog::xSize = 450;
00544 const int ChangePasswordDialog::ySize = 220;
00545 const int ChangePasswordDialog::buttonIndent = 60;
00546 
00547 ChangePasswordDialog::ChangePasswordDialog(PG_MessageObject* c): ASC_PG_Dialog(NULL, PG_Rect( 200, 100, xSize, ySize ), "Change Password",
00548         SHOW_CLOSE ) {
00549         
00550     passwordLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), static_cast<int>(GuiDimension::getTopOffSet() * 1.5), 10, GetTextHeight() * 2), "New Password: ");
00551     passwordLabel->SetSizeByText();
00552     
00553     PG_Point p = ScreenToClient(passwordLabel->x, passwordLabel->y);
00554     passwordValue = new PG_LineEdit(this, PG_Rect((xSize - xSize/2)/2, p.y + GuiDimension::getTopOffSet(), xSize/2, GetTextHeight() * 2));
00555     passwordValue->SetText(CGameOptions::Instance()->CGameOptions::Instance()->defaultPassword);
00556     
00557 
00558     okButton = new PG_Button(this, PG_Rect( buttonIndent, ySize - (GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet()), GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "OK", 90);
00559     okButton->sigClick.connect( SigC::slot( *this, &ChangePasswordDialog::ok ));
00560 
00561     p = ScreenToClient(okButton->x, okButton->y);
00562     cancelButton = new PG_Button(this, PG_Rect(p.x + GuiDimension::getButtonWidth() + 10, p.y, GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Cancel", 90);
00563     cancelButton->sigClick.connect( SigC::slot( *this, &ChangePasswordDialog::closeWindow ));
00564     
00565     sigClose.connect( SigC::slot( *this, &ChangePasswordDialog::closeWindow ));
00566 
00567     caller = c;
00568     SetInputFocus();            
00569 }
00570 
00571 ChangePasswordDialog::~ChangePasswordDialog(){
00572 
00573 }
00574 
00575 
00576 bool ChangePasswordDialog::ok(PG_Button* button){
00577   CGameOptions::Instance()->CGameOptions::Instance()->defaultPassword = passwordValue->GetText();
00578   quitModalLoop(1);
00579   caller->SetInputFocus();
00580   return true;
00581 }
00582 
00583 //*******************************************************************************************************************+
00584 
00585 ChangeDefaultPasswordDialog::ChangeDefaultPasswordDialog(PG_MessageObject* c) : ChangePasswordDialog(c){
00586 
00587 
00588 }
00589 
00590 ChangeDefaultPasswordDialog::~ChangeDefaultPasswordDialog() {
00591 
00592 
00593 }
00594 
00595 bool ChangeDefaultPasswordDialog::ok(PG_Button* button){
00596   CGameOptions::Instance()->CGameOptions::Instance()->defaultPassword = passwordValue->GetText();
00597   quitModalLoop(1);
00598   caller->SetInputFocus();
00599   return true;
00600 }
00601 
00602 
00603 void ChangeDefaultPasswordDialog::changeDefaultPasswordDialog(PG_MessageObject* caller) {
00604     ChangeDefaultPasswordDialog cdpd(caller);
00605     cdpd.Show();
00606     cdpd.RunModal();
00607 }
00608 
00609 //*******************************************************************************************************************
00610 #if 0
00611  const int MousePreferencesDialog::xSize = 450;
00612  const int MousePreferencesDialog::ySize = 220;
00613    
00614  MousePreferencesDialog::MousePreferencesDialog(PG_MessageObject* c) : ASC_PG_Dialog(NULL, PG_Rect( 200, 100, xSize, ySize ), "Mouse Options",
00615         SHOW_CLOSE ) {
00616    
00617    sigClose.connect( SigC::slot( *this, &MousePreferencesDialog::closeWindow ));
00618 
00619     caller = c;
00620     SetInputFocus();
00621    }
00622    
00623    
00624    MousePreferencesDialog::~MousePreferencesDialog(){
00625    
00626    
00627    }
00628 
00629    
00630    
00631    bool MousePreferencesDialog::ok(PG_Button* button){
00632       return true;  
00633    }
00634    
00635    void MousePreferencesDialog::mousePreferencesDialog(PG_MessageObject* caller){
00636      MousePreferencesDialog mpd(caller);
00637      mpd.Show();
00638      mpd.RunModal();
00639    }
00640 #endif
00641 //*******************************************************************************************************************
00642 
00643 
00644 ChangeMapPasswordDialog::ChangeMapPasswordDialog(PG_MessageObject* c) : ChangePasswordDialog(c){
00645 
00646 
00647 }
00648 
00649 ChangeMapPasswordDialog::~ChangeMapPasswordDialog() {
00650 
00651 
00652 }
00653 
00654 bool ChangeMapPasswordDialog::ok(PG_Button* button){  
00655   actmap->player[actmap->actplayer].passwordcrc.setUnencoded(passwordValue->GetText());
00656   quitModalLoop(1);
00657   caller->SetInputFocus();
00658   return true;
00659 }
00660 
00661 
00662 void ChangeMapPasswordDialog::changeMapPasswordDialog(PG_MessageObject* caller) {
00663     ChangeMapPasswordDialog cdpd(caller);
00664     cdpd.Show();
00665     cdpd.RunModal();
00666 }
00667 
00668 
00669 
00670 //*******************************************************************************************************************+
00671 const int SaveGameBaseDialog::xSize = 450;
00672 const int SaveGameBaseDialog::ySize = 360;
00673 const int SaveGameBaseDialog::buttonIndent = 60;
00674 
00675 SaveGameBaseDialog::SaveGameBaseDialog(const ASCString& title, PG_MessageObject* c): ASC_PG_Dialog(NULL, PG_Rect( 200, 100, xSize, ySize ), title.c_str(), SHOW_CLOSE ) {
00676 
00677 
00678     fileList = new PG_ListBox(this, PG_Rect(GuiDimension::getLeftIndent(), GuiDimension::getTopOffSet(), xSize - (2 *GuiDimension::getLeftIndent() + GuiDimension::getSliderWidth()), 200));
00679 
00680     for(int i=0; i<17; i++) {
00681         PG_ListBoxItem* item = new PG_ListBoxItem(fileList, 25, "");
00682         item->SetTextFormat("Item %i", i+1);
00683     }
00684     fileList->EnableScrollBar(true, PG_ScrollBar::VERTICAL);
00685     fileList->Update();
00686 #if 0
00687     
00688     tfindfile ff ( "*.sav" ); //wildcard
00689 
00690     ASCString location;
00691     string fileName = ff.getnextname(NULL, NULL, &location );
00692     PG_ListBoxItem* item;
00693     while( !fileName.empty() ) {
00694         item = new PG_ListBoxItem(fileList, 20, fileName.c_str());       
00695        /*tfiledata f;
00696        f.name = filename.c_str();
00697 
00698        time_t tdate = get_filetime( filename.c_str() );
00699        f.time = tdate;
00700        if ( tdate != -1 )
00701           f.sdate = ctime ( &tdate );
00702 
00703        f.location = location;
00704 
00705        fileList->
00706        //files.push_back ( f );
00707 
00708        numberoffiles++;
00709 
00710      fileName = ff.getnextname(NULL, NULL, &location );
00711     }
00712     fileList->EnableScrollBar(true, PG_ScrollBar::VERTICAL);
00713     */
00714 #endif
00715     PG_Point p = ScreenToClient(fileList->x, fileList->y);
00716     /* slider = new PG_ScrollBar(this, PG_Rect(xSize - (GuiDimension::getLeftIndent() + GuiDimension::getSliderWidth()) , p.y, GuiDimension::getSliderWidth(), fileList->Height()), PG_ScrollBar::VERTICAL);
00717      slider->SetRange(0,fileList->GetWidgetCount());
00718      slider->sigScrollTrack.connect( SigC::slot( *this, &SaveGameBaseDialog::handleSlider));*/
00719 
00720 
00721     fileNameLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), p.y + fileList->Height() + GuiDimension::getTopOffSet(), 10, 10), "Filename: ");
00722     fileNameLabel->SetSizeByText();
00723 
00724     p = ScreenToClient(fileNameLabel->x, fileNameLabel->y);
00725     fileNameValue = new PG_LineEdit(this, PG_Rect(p.x + fileNameLabel->Width(), p.y, xSize - (GuiDimension::getLeftIndent()*2 + fileNameLabel->Width()), GetTextHeight()*2));
00726 
00727     p = ScreenToClient(fileNameValue->x, fileNameValue->y);
00728     sortNameButton = new PG_RadioButton(this, PG_Rect(p.x , p.y + + GuiDimension::getTopOffSet(), 20, 20), "by name");
00729     sortNameButton->SetSizeByText();
00730 
00731     sortDateButton = new PG_RadioButton(this, PG_Rect(p.x + sortNameButton->Width() + GuiDimension::getLineOffset() , p.y + + GuiDimension::getTopOffSet(), 20, 20), "by date");
00732     sortDateButton->SetSizeByText();
00733 
00734 
00735 
00736 
00737     okButton = new PG_Button(this, PG_Rect( buttonIndent, ySize - (GuiDimension::getButtonHeight() + GuiDimension::getTopOffSet()), GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "OK", 90);
00738     okButton->sigClick.connect( SigC::slot( *this, &SaveGameBaseDialog::ok ));
00739 
00740     p = ScreenToClient(okButton->x, okButton->y);
00741     cancelButton = new PG_Button(this, PG_Rect(p.x + GuiDimension::getButtonWidth() + 10, p.y, GuiDimension::getButtonWidth(), GuiDimension::getButtonHeight()), "Cancel", 90);
00742     cancelButton->sigClick.connect( SigC::slot( *this, &SaveGameBaseDialog::closeWindow ));
00743 
00744     sigClose.connect( SigC::slot( *this, &SaveGameBaseDialog::closeWindow ));
00745 
00746     caller = c;
00747     SetInputFocus();
00748 }
00749 
00750 
00751 SaveGameBaseDialog::~SaveGameBaseDialog() {
00752 }
00753 
00754 bool SaveGameBaseDialog::closeWindow() {
00755     quitModalLoop(1);
00756     caller->SetInputFocus();
00757     return true;
00758 }
00759 
00760 bool SaveGameBaseDialog::handleSlider(long data) {
00761 
00762     return true;
00763 }
00764 
00765 //*************************************************************************************************************************
00766 
00767 SaveGameDialog::SaveGameDialog(PG_MessageObject* c):SaveGameBaseDialog("Save Game", c) {
00768 }
00769 
00770 SaveGameDialog::~SaveGameDialog() {
00771 }
00772 bool SaveGameDialog::ok(PG_Button* button) {
00773     savegame( fileNameValue->GetText(), actmap );
00774     quitModalLoop(1);
00775     return true;
00776 }
00777 
00778 void SaveGameDialog::saveGameDialog(PG_MessageObject* c) {
00779     SaveGameDialog sgd(c);
00780     sgd.Show();
00781     sgd.RunModal();
00782 }
00783 
00784 //*************************************************************************************************************************
00785 #if 0
00786 LoadGameDialog::LoadGameDialog(PG_MessageObject* c):SaveGameBaseDialog("Load Game", c) {
00787 }
00788 
00789 LoadGameDialog::~LoadGameDialog() {
00790 }
00791 bool LoadGameDialog::ok(PG_Button* button) {
00792     vector<PG_ListBoxBaseItem*> selectedFileList;
00793     PG_ListBoxItem* fileName = dynamic_cast<PG_ListBoxItem*>(selectedFileList.front());
00794     // loadgame(fileName->GetText().c_str());
00795     quitModalLoop(1);
00796     return true;
00797 }
00798 /*
00799 void LoadGameDialog::loadGameDialog(PG_MessageObject* caller) {
00800 
00801     ItemSelectorWindow isw ( NULL, PG_Rect( 10,10,500,500) , new  ) ;
00802     
00803     File
00804 
00805     LoadGameDialog lgd(caller);
00806     lgd.Show();
00807     lgd.RunModal();
00808 }
00809 */
00810 //*************************************************************************************************************************
00811 
00812 
00813 
00814 //*******************************************************************************************************************+
00815 
00816     
00817 
00818 //*******************************************************************************************************************+
00819 
00820 
00821 void LoadGameDialog::loadGameDialog(PG_MessageObject* caller) {
00822 
00823     ItemSelectorWindow isw ( NULL, PG_Rect( 10,10,500,500) , "choose file", new FileSelectionItemFactory( "*.foo" )) ;
00824     
00825     isw.Show();
00826     isw.RunModal();
00827 }
00828 
00829 #endif
00830 
00831 

Generated on Mon May 21 01:26:33 2012 for Advanced Strategic Command by  doxygen 1.5.1