MessageDialog.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/MessageDialog.h>
00022 #include <client/ScorchedClient.h>
00023 #include <common/OptionsScorched.h>
00024 #include <console/Console.h>
00025 #include <GLEXT/GLViewPort.h>
00026 #include <GLW/GLWFont.h>
00027 
00028 MessageDialog *MessageDialog::instance_ = 0;
00029 
00030 MessageDialog *MessageDialog::instance()
00031 {
00032         if (!instance_) instance_ = new MessageDialog();
00033         return instance_;
00034 }
00035 
00036 MessageDialog::MessageDialog() :
00037         showTime_(0.0f), GLWWindow("", 10.0f, 10.0f, 447.0f, 310.0f, 
00038                 GLWWindow::eTransparent | GLWWindow::eNoTitle,
00039                 "")
00040 {
00041         disabled_ = true;
00042         windowLevel_ = 90000;
00043 
00044         std::list<std::string> startupChannels;
00045         startupChannels.push_back("banner");
00046         ClientChannelManager::instance()->registerClient(this, startupChannels);
00047 }
00048 
00049 MessageDialog::~MessageDialog()
00050 {
00051 }
00052 
00053 void MessageDialog::channelText(ChannelText &text)
00054 {
00055         clear();
00056         texts_.push_back(text.getMessage());
00057 }
00058 
00059 void MessageDialog::registeredForChannels(
00060         std::list<ChannelDefinition> &registeredChannels,
00061         std::list<ChannelDefinition> &availableChannels)
00062 {
00063 }
00064 
00065 void MessageDialog::simulate(float simTime)
00066 {
00067         showTime_ -= simTime;
00068         if (showTime_ <= 0.0f)
00069         {
00070                 if (!texts_.empty())
00071                 {
00072                         currentText_ = texts_.front();
00073                         texts_.pop_front();
00074                         showTime_ = 5.0f;
00075                 }
00076         }
00077 }
00078 
00079 void MessageDialog::clear()
00080 {
00081         texts_.clear(); 
00082         showTime_ = 0.0f;
00083 }
00084 
00085 void MessageDialog::draw()
00086 {
00087         if (showTime_ <= 0.0f) return;
00088 
00089         GLState state(GLState::BLEND_ON | GLState::TEXTURE_OFF | GLState::DEPTH_OFF); 
00090 
00091         float wHeight = (float) GLViewPort::getHeight();
00092         float wWidth = (float) GLViewPort::getWidth();
00093         float textWidth = GLWFont::instance()->getGameFont()->getWidth(
00094                 30, currentText_);
00095 
00096         float x = (wWidth/2.0f) - (textWidth / 2) - 10.0f;
00097         float y = wHeight - 60.0f;
00098 
00099         setW(textWidth + 20.0f);
00100         setH(40);
00101         setX(x);
00102         setY(y);
00103         GLWWindow::draw();
00104 
00105         Vector white(0.9f, 0.9f, 1.0f);
00106         GLWFont::instance()->getGameFont()->draw(
00107                 white, 30, 
00108                 x + 10.0f, y + 7.0f, 0.0f,
00109                 currentText_);
00110 }

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