git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / dialogs / QuitDialog.cpp
blob48ef7f77f35ee624c1e40fe93251143ac690a5d5
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <dialogs/QuitDialog.h>
22 #include <dialogs/SaveDialog.h>
23 #include <GLW/GLWWindowManager.h>
24 #include <client/ClientParams.h>
25 #include <server/ServerCommon.h>
26 #include <client/ScorchedClient.h>
27 #include <client/ClientState.h>
28 #include <engine/MainLoop.h>
30 QuitDialog *QuitDialog::instance_ = 0;
32 QuitDialog *QuitDialog::instance()
34 if (!instance_)
36 instance_ = new QuitDialog;
38 return instance_;
41 QuitDialog::QuitDialog() :
42 GLWWindow("Quit", 210.0f, 150.0f, 0,
43 "Allows the player to quit the game.")
45 killButton_ = (GLWTextButton *)
46 addWidget(new GLWTextButton(LANG_RESOURCE("MASS_TANK_KILL", "Mass Tank Kill"), 10, 115, 190, this,
47 GLWButton::ButtonFlagCenterX));
48 killButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
49 LANG_RESOURCE("MASS_TANK_KILL", "Mass tank kill"),
50 LANG_RESOURCE("MADD_TANK_KILL_TOOLTIP", "Kills all the tanks and starts the next\n"
51 "round. Only available in single player\n"
52 "games.")));
54 saveButton_ = (GLWTextButton *)
55 addWidget(new GLWTextButton(LANG_RESOURCE("SAVE_GAME", "Save Game"), 10, 80, 190, this,
56 GLWButton::ButtonFlagCenterX));
57 saveButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
58 LANG_RESOURCE("SAVE_GAME", "Save Game"),
59 LANG_RESOURCE("SAVE_GAME_TOOLTIP", "Saves the games.\n"
60 "Only available in single player games.")));
62 quitButton_ = (GLWTextButton *)
63 addWidget(new GLWTextButton(LANG_RESOURCE("QUIT_GAME", "Quit Game"), 10, 45, 190, this,
64 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX));
65 quitButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
66 LANG_RESOURCE("QUIT_GAME", "Quit Game"),
67 LANG_RESOURCE("QUIT_GAME_TOOLTIP", "Quits Scorched3D")));
69 okButton_ = (GLWTextButton *)
70 addWidget(new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this,
71 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX));
72 okButton_->setToolTip(new ToolTip(ToolTip::ToolTipHelp,
73 LANG_RESOURCE("CANCEL", "Cancel"),
74 LANG_RESOURCE("CANCEL_TOOLTIP", "Return to the game.")));
77 QuitDialog::~QuitDialog()
82 void QuitDialog::display()
84 GLWWindow::display();
86 unsigned int state = ScorchedClient::instance()->getGameState().getState();
87 bool disable = (ClientParams::instance()->getConnectedToServer() ||
88 state == ClientState::StateOptions ||
89 state == ClientState::StateConnect ||
90 state == ClientState::StateGetPlayers ||
91 state == ClientState::StateLoadPlayers);
92 saveButton_->setEnabled(!disable);
93 killButton_->setEnabled(!disable);
96 void QuitDialog::buttonDown(unsigned int id)
98 if (id == okButton_->getId())
100 GLWWindowManager::instance()->hideWindow(id_);
102 else if (id == saveButton_->getId())
104 GLWWindowManager::instance()->showWindow(
105 SaveDialog::instance()->getId());
106 GLWWindowManager::instance()->hideWindow(id_);
108 else if (id == killButton_->getId())
110 ServerCommon::killAll();
111 GLWWindowManager::instance()->hideWindow(id_);
113 else if (id == quitButton_->getId())
115 ScorchedClient::instance()->getMainLoop().exitLoop();