00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <dialogs/ProgressDialog.h>
00022 #include <dialogs/BackdropDialog.h>
00023 #include <landscape/LandscapeMusicManager.h>
00024 #include <sound/Sound.h>
00025 #include <client/ScorchedClient.h>
00026 #include <client/ClientChannelManager.h>
00027 #include <graph/Main2DCamera.h>
00028 #include <client/ClientMain.h>
00029 #include <client/ClientState.h>
00030 #include <client/ClientProcessingLoop.h>
00031 #include <engine/MainLoop.h>
00032 #include <common/Clock.h>
00033 #include <common/Defines.h>
00034 #include <common/ChannelText.h>
00035 #include <GLW/GLWFont.h>
00036 #include <GLW/GLWWindowManager.h>
00037 #include <GLW/GLWColors.h>
00038 #include <lang/LangResource.h>
00039 #include <image/ImagePng.h>
00040 #include <image/ImageFactory.h>
00041 #include <math.h>
00042 #include <string.h>
00043
00044 ProgressDialog *ProgressDialog::instance_ = 0;
00045
00046 ProgressDialog *ProgressDialog::instance()
00047 {
00048 if (!instance_) instance_ = new ProgressDialog();
00049 return instance_;
00050 }
00051
00052 ProgressDialog::ProgressDialog() :
00053 GLWWindow("", 10.0f, 10.0f, 470.0f, 80.0f, eTransparent | eNoTitle, ""),
00054 progressPercentage_(0)
00055 {
00056 setUser(this);
00057 }
00058
00059 ProgressDialog::~ProgressDialog()
00060 {
00061 }
00062
00063 void ProgressDialog::progressChange(const LangString &op, const float percentage)
00064 {
00065 progressText_ = op;
00066 progressPercentage_ = percentage;
00067 }
00068
00069 void ProgressDialog::changeTip()
00070 {
00071 tips_.getLines().clear();
00072 tips_.readFile(S3D::getDataFile("data/tips.txt"));
00073 needsCentered();
00074
00075 std::string tip = tips_.getLines()[rand() % tips_.getLines().size()].c_str();
00076 char *nl = (char *) strchr(tip.c_str(), ':');
00077 if (nl) *nl = ' ';
00078
00079 ChannelText text("announce", LANG_RESOURCE_1("TIP_ENTRY", "[t:Tip:] {0}", tip));
00080 ClientChannelManager::instance()->showText(text);
00081 }
00082
00083 void ProgressDialog::setIcon(const std::string &iconName)
00084 {
00085 ImageHandle map = ImageFactory::loadImageHandle(iconName);
00086 ImageHandle newMap = map.createResize(64, 64);
00087 icon_.create(newMap);
00088 }
00089
00090 void ProgressDialog::draw()
00091 {
00092 GLWWindow::draw();
00093
00094 {
00095 GLState state(GLState::DEPTH_OFF | GLState::TEXTURE_ON | GLState::BLEND_ON);
00096
00097 if (!icon_.textureValid())
00098 {
00099 setIcon(S3D::getDataFile("data/windows/tank2.bmp"));
00100
00101 ImageHandle bar1 =
00102 ImageFactory::loadAlphaImageHandle(S3D::getDataFile("data/windows/bar1.png"));
00103 ImageHandle bar2 =
00104 ImageFactory::loadAlphaImageHandle(S3D::getDataFile("data/windows/bar2.png"));
00105 bar1_.create(bar1);
00106 bar2_.create(bar2);
00107
00108 bar1_.draw(true);
00109 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
00110 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
00111
00112 bar2_.draw(true);
00113 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
00114 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
00115 }
00116
00117
00118 glPushMatrix();
00119 glTranslatef(x_ + 80.0f, y_ + 10.0f, 0.0f);
00120
00121 bar1_.draw();
00122 glColor3f(1.0f, 1.0f, 1.0f);
00123 glBegin(GL_QUADS);
00124 glTexCoord2f(0.0f, 0.0f);
00125 glVertex2f(0.0f, 15.0f);
00126 glTexCoord2f(progressPercentage_ / 100.0f, 0.0f);
00127 glVertex2f(380.0f * progressPercentage_ / 100.0f, 15.0f);
00128 glTexCoord2f(progressPercentage_ / 100.0f, 1.0f);
00129 glVertex2f(380.0f * progressPercentage_ / 100.0f, 26.0f);
00130 glTexCoord2f(0.0, 1.0f);
00131 glVertex2f(0.0f, 26.0f);
00132 glEnd();
00133 bar2_.draw();
00134 glBegin(GL_QUADS);
00135 glTexCoord2f(progressPercentage_ / 100.0f, 0.0f);
00136 glVertex2f(380.0f * progressPercentage_ / 100.0f, 15.0f);
00137 glTexCoord2f(1.0f, 0.0f);
00138 glVertex2f(380.0f, 15.0f);
00139 glTexCoord2f(1.0f, 1.0f);
00140 glVertex2f(380.0f, 26.0f);
00141 glTexCoord2f(progressPercentage_ / 100.0f, 1.0f);
00142 glVertex2f(380.0f * progressPercentage_ / 100.0f, 26.0f);
00143 glEnd();
00144
00145
00146 GLWFont::instance()->getGameShadowFont()->drawWidth(380.0f,
00147 GLWColors::black,
00148 14.0f, 0.0f - 2.0f, 33.0f + 2.0f, 0.0f,
00149 progressText_);
00150
00151 Vector white(1.0f, 1.0f, 1.0f);
00152 GLWFont::instance()->getGameFont()->drawWidth(380.0f,
00153 white,
00154 14.0f, 0.0f, 33.0f, 0.0f,
00155 progressText_);
00156 glPopMatrix();
00157
00158
00159 icon_.draw();
00160 glPushMatrix();
00161 {
00162 glTranslatef(x_ + 12.0f, y_ + 12.0f, 0.0f);
00163 glColor3f(1.0f, 1.0f, 1.0f);
00164
00165 glBegin(GL_QUADS);
00166 glTexCoord2f(0.0f, 0.0f);
00167 glVertex2f(0.0f, 0.0f);
00168 glTexCoord2f(1.0f, 0.0f);
00169 glVertex2f(56.0f, 0.0f);
00170 glTexCoord2f(1.0f, 1.0f);
00171 glVertex2f(56.0f, 56.0f);
00172 glTexCoord2f(0.0f, 1.0f);
00173 glVertex2f(0.0f, 56.0f);
00174 glEnd();
00175 }
00176 {
00177 GLState state2(GLState::TEXTURE_OFF);
00178 glColor3f(0.0f, 0.0f, 0.0f);
00179 glLineWidth(2.0f);
00180 glBegin(GL_LINE_LOOP);
00181 glTexCoord2f(0.0f, 0.0f);
00182 glVertex2f(0.0f, 0.0f);
00183 glTexCoord2f(1.0f, 0.0f);
00184 glVertex2f(56.0f, 0.0f);
00185 glTexCoord2f(1.0f, 1.0f);
00186 glVertex2f(56.0f, 56.0f);
00187 glTexCoord2f(0.0f, 1.0f);
00188 glVertex2f(0.0f, 56.0f);
00189 glEnd();
00190 glLineWidth(1.0f);
00191 }
00192 glPopMatrix();
00193 }
00194 }
00195
00196 ProgressDialogSync *ProgressDialogSync::instance_ = 0;
00197
00198 ProgressDialogSync *ProgressDialogSync::instance()
00199 {
00200 if (!instance_) instance_ = new ProgressDialogSync();
00201 return instance_;
00202 }
00203
00204 ProgressDialogSync::ProgressDialogSync()
00205 {
00206 setUser(this);
00207 }
00208
00209 ProgressDialogSync::~ProgressDialogSync()
00210 {
00211 }
00212
00213 void ProgressDialogSync::progressChange(const LangString &op, const float percentage)
00214 {
00215 static Clock localTimer;
00216 static float timeDelay = 0.0f;
00217 static float timeDelay2 = 0.0f;
00218 float frameTime = localTimer.getTimeDifference();
00219 timeDelay += frameTime;
00220 timeDelay2 += frameTime;
00221
00222 ClientMain::clientEventLoop(frameTime);
00223 ClientProcessingLoop::instance()->simulate(0, frameTime);
00224
00225 ProgressDialog::instance()->progressChange(op, percentage);
00226
00227 if ((timeDelay > 0.25f) ||
00228 (percentage > 99.0f))
00229 {
00230 Main2DCamera::instance()->draw(0);
00231
00232 unsigned int state = ScorchedClient::instance()->getGameState().getState();
00233 if (state >= ClientState::StateGetPlayers)
00234 {
00235 GLWWindowManager::instance()->simulate(ClientState::StateLoadLevel, MIN(0.25f, timeDelay));
00236 GLWWindowManager::instance()->draw(ClientState::StateLoadLevel);
00237 LandscapeMusicManager::instance()->simulate(ClientState::StateLoadLevel, frameTime);
00238 Sound::instance()->simulate(ClientState::StateLoadLevel, frameTime);
00239 }
00240 else
00241 {
00242 BackdropDialog::instance()->draw();
00243 ProgressDialog::instance()->draw();
00244 LandscapeMusicManager::instance()->simulate(state, frameTime);
00245 Sound::instance()->simulate(state, frameTime);
00246 }
00247
00248 ScorchedClient::instance()->getMainLoop().swapBuffers();
00249
00250 timeDelay = 0.0f;
00251 }
00252
00253 if (timeDelay2 > 5.0f)
00254 {
00255 SDL_Delay(50);
00256 timeDelay2 = 0.0f;
00257 }
00258 }