00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <graph/ShotCountDown.h>
00022 #include <client/ScorchedClient.h>
00023 #include <client/ClientState.h>
00024 #include <common/OptionsScorched.h>
00025 #include <common/DefinesString.h>
00026 #include <GLEXT/GLViewPort.h>
00027 #include <GLW/GLWFont.h>
00028 #include <GLW/GLWidget.h>
00029
00030 ShotCountDown *ShotCountDown::instance_ = 0;
00031
00032 ShotCountDown *ShotCountDown::instance()
00033 {
00034 if (!instance_)
00035 {
00036 instance_ = new ShotCountDown;
00037 }
00038 return instance_;
00039 }
00040
00041 ShotCountDown::ShotCountDown() :
00042 GameStateI("ShotCountDown"),
00043 counter_(0.0f), blinkTimer_(0.0f),
00044 showTime_(true), timerOff_(true)
00045 {
00046 }
00047
00048 ShotCountDown::~ShotCountDown()
00049 {
00050 }
00051
00052 void ShotCountDown::reset(float time)
00053 {
00054 timerOff_ = (time == 0.0f);
00055 counter_ = time;
00056 blinkTimer_ = 0.0f;
00057 showTime_ = true;
00058 }
00059
00060 void ShotCountDown::simulate(const unsigned state, float simTime)
00061 {
00062 counter_ -= simTime;
00063 blinkTimer_ += simTime;
00064
00065 if (blinkTimer_ > 0.25f)
00066 {
00067 if (counter_ < 5.0f)
00068 {
00069 showTime_ = !showTime_;
00070 }
00071 blinkTimer_ = 0.0f;
00072 }
00073 }
00074
00075 void ShotCountDown::draw(const unsigned currentstate)
00076 {
00077 if (timerOff_) return;
00078
00079
00080 int timeLeft = (int) counter_;
00081
00082
00083 div_t split = div(timeLeft, 60);
00084
00085 GLState state(GLState::BLEND_ON | GLState::TEXTURE_OFF | GLState::DEPTH_OFF);
00086
00087 static Vector fontColor;
00088 fontColor = Vector(0.7f, 0.7f, 0.2f);
00089 if (timeLeft <= 5)
00090 {
00091 fontColor = Vector(0.7f, 0.0f, 0.0f);
00092 }
00093
00094 const char *format = "%02i:%02i";
00095 if (timeLeft < 0) format = "--:--";
00096
00097 float width = 0.0f;
00098 if (currentstate == ClientState::StateWait)
00099 {
00100 width = GLWFont::instance()->getGameFont()->getWidth(10,
00101 S3D::formatStringBuffer(format,
00102 split.quot,
00103 split.rem));
00104 }
00105 else
00106 {
00107 width = GLWFont::instance()->getGameFont()->getWidth(20,
00108 S3D::formatStringBuffer(format,
00109 split.quot,
00110 split.rem));
00111 }
00112
00113 float wHeight = (float) GLViewPort::getHeight();
00114 float wWidth = (float) GLViewPort::getWidth();
00115 if (currentstate == ClientState::StateWait)
00116 {
00117 static Vector green(0.2f, 0.7f, 0.2f);
00118 GLWFont::instance()->getGameFont()->draw(
00119 green, 10, (wWidth/2.0f) - (width / 2),
00120 wHeight - 50.0f, 0.0f,
00121 S3D::formatStringBuffer(format,
00122 split.quot,
00123 split.rem));
00124 }
00125 else if (showTime_)
00126 {
00127 GLWFont::instance()->getGameFont()->draw(
00128 fontColor, 20, (wWidth/2.0f) - (width / 2),
00129 wHeight - 50.0f, 0.0f,
00130 S3D::formatStringBuffer(format,
00131 split.quot,
00132 split.rem));
00133 }
00134 }