00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <dialogs/QuitDialog.h>
00022 #include <dialogs/SaveDialog.h>
00023 #include <GLW/GLWWindowManager.h>
00024 #include <client/ClientParams.h>
00025 #include <server/ServerCommon.h>
00026 #include <client/ScorchedClient.h>
00027 #include <client/ClientState.h>
00028 #include <engine/MainLoop.h>
00029
00030 QuitDialog *QuitDialog::instance_ = 0;
00031
00032 QuitDialog *QuitDialog::instance()
00033 {
00034 if (!instance_)
00035 {
00036 instance_ = new QuitDialog;
00037 }
00038 return instance_;
00039 }
00040
00041 QuitDialog::QuitDialog() :
00042 GLWWindow("Quit", 210.0f, 150.0f, 0,
00043 "Allows the player to quit the game.")
00044 {
00045 killButton_ = (GLWTextButton *)
00046 addWidget(new GLWTextButton(LANG_RESOURCE("MASS_TANK_KILL", "Mass Tank Kill"), 10, 115, 190, this,
00047 GLWButton::ButtonFlagCenterX));
00048 killButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
00049 LANG_RESOURCE("MASS_TANK_KILL", "Mass tank kill"),
00050 LANG_RESOURCE("MADD_TANK_KILL_TOOLTIP", "Kills all the tanks and starts the next\n"
00051 "round. Only available in single player\n"
00052 "games.")));
00053
00054 saveButton_ = (GLWTextButton *)
00055 addWidget(new GLWTextButton(LANG_RESOURCE("SAVE_GAME", "Save Game"), 10, 80, 190, this,
00056 GLWButton::ButtonFlagCenterX));
00057 saveButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
00058 LANG_RESOURCE("SAVE_GAME", "Save Game"),
00059 LANG_RESOURCE("SAVE_GAME_TOOLTIP", "Saves the games.\n"
00060 "Only available in single player games.")));
00061
00062 quitButton_ = (GLWTextButton *)
00063 addWidget(new GLWTextButton(LANG_RESOURCE("QUIT_GAME", "Quit Game"), 10, 45, 190, this,
00064 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX));
00065 quitButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
00066 LANG_RESOURCE("QUIT_GAME", "Quit Game"),
00067 LANG_RESOURCE("QUIT_GAME_TOOLTIP", "Quits Scorched3D")));
00068
00069 okButton_ = (GLWTextButton *)
00070 addWidget(new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this,
00071 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX));
00072 okButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
00073 LANG_RESOURCE("CANCEL", "Cancel"),
00074 LANG_RESOURCE("CANCEL_TOOLTIP", "Return to the game.")));
00075 }
00076
00077 QuitDialog::~QuitDialog()
00078 {
00079
00080 }
00081
00082 void QuitDialog::display()
00083 {
00084 GLWWindow::display();
00085
00086 unsigned int state = ScorchedClient::instance()->getGameState().getState();
00087 bool disable = (ClientParams::instance()->getConnectedToServer() ||
00088 state == ClientState::StateOptions ||
00089 state == ClientState::StateConnect ||
00090 state == ClientState::StateGetPlayers ||
00091 state == ClientState::StateLoadPlayers);
00092 saveButton_->setEnabled(!disable);
00093 killButton_->setEnabled(!disable);
00094 }
00095
00096 void QuitDialog::buttonDown(unsigned int id)
00097 {
00098 if (id == okButton_->getId())
00099 {
00100 GLWWindowManager::instance()->hideWindow(id_);
00101 }
00102 else if (id == saveButton_->getId())
00103 {
00104 GLWWindowManager::instance()->showWindow(
00105 SaveDialog::instance()->getId());
00106 GLWWindowManager::instance()->hideWindow(id_);
00107 }
00108 else if (id == killButton_->getId())
00109 {
00110 ServerCommon::killAll();
00111 GLWWindowManager::instance()->hideWindow(id_);
00112 }
00113 else if (id == quitButton_->getId())
00114 {
00115 ScorchedClient::instance()->getMainLoop().exitLoop();
00116 }
00117 }