1 #ifdef USE_ONLINE_UPDATE
2 // Description:
3 //   OpenGL display for online update.
4 //
5 // Copyright (C) 2005 Frank Becker
6 //
7 // This program is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free Software
9 // Foundation;  either version 2 of the License,  or (at your option) any  later
10 // version.
11 //
12 // This program is distributed in the hope that it will be useful,  but  WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
15 //
16 #include <Trace.hpp>
17 #include <FontManager.hpp>
18 #include <Video.hpp>
19 #include <GameState.hpp>
20 #include <Config.hpp>
21 
22 #include <Constants.hpp>
23 #include <OnlineUpdate.hpp>
24 #include <OnlineUpdateDisplay.hpp>
25 
OnlineUpdateDisplay(void)26 OnlineUpdateDisplay::OnlineUpdateDisplay( void):
27   _posX(VIDEO_ORTHO_WIDTH),
28   _delay(10),
29   _updateIsReady(false)
30 {
31     _currentMessage = _messages.begin();
32 }
33 
~OnlineUpdateDisplay()34 OnlineUpdateDisplay::~OnlineUpdateDisplay()
35 {
36 }
37 
update(void)38 void OnlineUpdateDisplay::update( void)
39 {
40     bool onlineCheck = false;
41     ConfigS::instance()->getBoolean("onlineCheck", onlineCheck);
42     if( !onlineCheck) return;
43 
44     GLBitmapFont &fontWhite =
45 	*(FontManagerS::instance()->getFont( "bitmaps/arial-small"));
46 
47     if( ! _updateIsReady)
48     {
49 	OnlineUpdate &ou = *OnlineUpdateS::instance();
50 	if( ou.getUpdateStatus() == OnlineUpdate::eSuccess)
51 	{
52 	    list<OnlineUpdate::NewsItem*> &newsItemList = ou.getNewsItems();
53 	    list<OnlineUpdate::NewsItem*>::iterator i;
54 	    for( i=newsItemList.begin(); i!=newsItemList.end(); i++)
55 	    {
56 		MessageInfo mi;
57 		mi.message = (*i)->title + ": " + (*i)->text + " (" + (*i)->date + ")";
58 		mi.r = (*i)->r;
59 		mi.g = (*i)->g;
60 		mi.b = (*i)->b;
61 		_messages.insert( _messages.end(), mi);
62 	    }
63 
64 	    if(!ou.isLatest())
65 	    {
66 		MessageInfo mi;
67 		mi.message = "A new version of " + GAMETITLE + " is available! Latest version is " + ou.getLatestVersion() + ". " + ou.getLatestVersionText();
68 		mi.r = 1.0;
69 		mi.g = 0.2;
70 		mi.b = 0.0;
71 		_messages.insert( _messages.begin(), mi);
72 	    }
73 	    _currentMessage = _messages.begin();
74 	    _updateIsReady = true;
75 
76 	    MessageInfo mi = (*_currentMessage);
77 	    _currentTextLength = fontWhite.GetWidth( mi.message.c_str(), 0.6);
78 	}
79     }
80 
81     if( _currentMessage == _messages.end()) return;
82 
83     _prevPosX = _posX;
84     if( _posX > -_currentTextLength)
85     {
86 	_posX-=5.0;
87     }
88     else if( _delay > 0 )
89     {
90 	_delay--;
91 	if( _delay == 0)
92 	{
93 	    _posX=VIDEO_ORTHO_WIDTH;
94 	    _prevPosX = _posX;
95 	    _delay=10; //00;
96 	    _currentMessage++;
97 	    if( _currentMessage == _messages.end())
98 		_currentMessage = _messages.begin();
99 
100 	    MessageInfo mi = (*_currentMessage);
101 	    _currentTextLength = fontWhite.GetWidth( mi.message.c_str(), 0.6);
102 	}
103     }
104 }
105 
draw(void)106 void OnlineUpdateDisplay::draw( void)
107 {
108     bool onlineCheck = false;
109     ConfigS::instance()->getBoolean("onlineCheck", onlineCheck);
110     if( !onlineCheck) return;
111 
112     if( !_updateIsReady) return;
113 
114     if( _currentMessage == _messages.end()) return;
115 
116     MessageInfo mi= (*_currentMessage);
117 
118     GLBitmapFont &fontWhite =
119 	*(FontManagerS::instance()->getFont( "bitmaps/arial-small"));
120     glColor4f(mi.r, mi.g, mi.b, 0.7);
121 
122     glPushMatrix();
123     float posX = _prevPosX+(_posX-_prevPosX)*GameState::frameFractionOther;
124     fontWhite.DrawString( mi.message.c_str(), posX, 25, 0.6, 0.6);
125     glPopMatrix();
126 }
127 #endif
128