SkipAllDialog.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/SkipAllDialog.h>
00022 #include <engine/MainLoop.h>
00023 #include <GLW/GLWTextButton.h>
00024 #include <GLW/GLWWindowManager.h>
00025 #include <client/ScorchedClient.h>
00026 #include <tankgraph/TankKeyboardControlUtil.h>
00027 #include <tank/TankContainer.h>
00028 #include <tank/TankState.h>
00029 #include <common/Defines.h>
00030 #include <time.h>
00031 
00032 SkipAllDialog *SkipAllDialog::instance_ = 0;
00033 
00034 SkipAllDialog *SkipAllDialog::instance()
00035 {
00036         if (!instance_)
00037         {
00038                 instance_ = new SkipAllDialog;
00039         }
00040         return instance_;
00041 }
00042 
00043 SkipAllDialog::SkipAllDialog() : 
00044         GLWWindow("", 270.0f, 80.0f, 0, ""),
00045         skipAll_(false)
00046 {
00047         label_ = (GLWLabel *) addWidget(new GLWLabel(10, 45));
00048         nowId_ = addWidget(new GLWTextButton(LANG_RESOURCE("SKIP_NOW", "Skip Now"), 10, 10, 130, this, 
00049                 GLWButton::ButtonFlagCenterX))->getId();
00050         cancelId_ = addWidget(new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 155, 10, 105, this, 
00051                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX))->getId();
00052 }
00053 
00054 SkipAllDialog::~SkipAllDialog()
00055 {
00056 
00057 }
00058 
00059 void SkipAllDialog::simulate(float frameTime)
00060 {
00061         if (skipAll_)
00062         {
00063                 unsigned int currentTime = (unsigned int) time(0);
00064                 unsigned int passedTime = currentTime - startTime_;
00065 
00066                 if (passedTime >= 5)
00067                 {
00068                         Tank *firstTank = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00069                         if (firstTank)
00070                         {
00071                                 TankKeyboardControlUtil::skipShot(firstTank);
00072                         }
00073                         GLWWindowManager::instance()->hideWindow(id_);
00074                 }
00075                 else
00076                 {
00077                         label_->setText(LANG_RESOURCE_1(
00078                                 "SKIPPING_MOVE", "Skipping move in {0}...", S3D::formatStringBuffer("%i", (5 - passedTime))));
00079                 }
00080         }
00081 
00082         GLWWindow::simulate(frameTime);
00083 }
00084 
00085 void SkipAllDialog::display()
00086 {
00087         startTime_ = (unsigned int) time(0);
00088 }
00089 
00090 void SkipAllDialog::windowInit(const unsigned state)
00091 {
00092         skipAll_ = false;
00093 
00094         Tank *firstTank = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00095         if (firstTank)
00096         {
00097                 if (firstTank->getState().getSkipShots())
00098                 {
00099                         skipAll_ = true;
00100                 }
00101         }
00102 
00103         if (skipAll_)
00104         {
00105                 GLWWindowManager::instance()->showWindow(id_);
00106         }
00107         else
00108         {
00109                 GLWWindowManager::instance()->hideWindow(id_);
00110         }
00111 }
00112 
00113 void SkipAllDialog::buttonDown(unsigned int id)
00114 {
00115         if (id == cancelId_)
00116         {
00117                 Tank *firstTank = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00118                 if (firstTank)
00119                 {
00120                         firstTank->getState().setSkipShots(false);
00121                 }
00122                 GLWWindowManager::instance()->hideWindow(id_);
00123         }
00124         else if (id == nowId_)
00125         {
00126                 startTime_ = 0;
00127         }
00128 }

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