git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / dialogs / MessageDialog.cpp
blobee25477e6d0ed25e99683e517baab397a4bf3292
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/MessageDialog.h>
22 #include <client/ScorchedClient.h>
23 #include <common/OptionsScorched.h>
24 #include <console/Console.h>
25 #include <GLEXT/GLViewPort.h>
26 #include <GLW/GLWFont.h>
28 MessageDialog *MessageDialog::instance_ = 0;
30 MessageDialog *MessageDialog::instance()
32 if (!instance_) instance_ = new MessageDialog();
33 return instance_;
36 MessageDialog::MessageDialog() :
37 showTime_(0.0f), GLWWindow("", 10.0f, 10.0f, 447.0f, 310.0f,
38 GLWWindow::eTransparent | GLWWindow::eNoTitle,
39 "")
41 disabled_ = true;
42 windowLevel_ = 90000;
44 std::list<std::string> startupChannels;
45 startupChannels.push_back("banner");
46 ClientChannelManager::instance()->registerClient(this, startupChannels);
49 MessageDialog::~MessageDialog()
53 void MessageDialog::channelText(ChannelText &text)
55 clear();
56 texts_.push_back(text.getMessage());
59 void MessageDialog::registeredForChannels(
60 std::list<ChannelDefinition> &registeredChannels,
61 std::list<ChannelDefinition> &availableChannels)
65 void MessageDialog::simulate(float simTime)
67 showTime_ -= simTime;
68 if (showTime_ <= 0.0f)
70 if (!texts_.empty())
72 currentText_ = texts_.front();
73 texts_.pop_front();
74 showTime_ = 5.0f;
79 void MessageDialog::clear()
81 texts_.clear();
82 showTime_ = 0.0f;
85 void MessageDialog::draw()
87 if (showTime_ <= 0.0f) return;
89 GLState state(GLState::BLEND_ON | GLState::TEXTURE_OFF | GLState::DEPTH_OFF);
91 float wHeight = (float) GLViewPort::getHeight();
92 float wWidth = (float) GLViewPort::getWidth();
93 float textWidth = GLWFont::instance()->getGameFont()->getWidth(
94 30, currentText_);
96 float x = (wWidth/2.0f) - (textWidth / 2) - 10.0f;
97 float y = wHeight - 60.0f;
99 setW(textWidth + 20.0f);
100 setH(40);
101 setX(x);
102 setY(y);
103 GLWWindow::draw();
105 Vector white(0.9f, 0.9f, 1.0f);
106 GLWFont::instance()->getGameFont()->draw(
107 white, 30,
108 x + 10.0f, y + 7.0f, 0.0f,
109 currentText_);