QuitDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 }

Generated on Mon Feb 16 15:14:37 2009 for Scorched3D by  doxygen 1.5.3