00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }