File: OnlineUpdateDisplay.cpp

package info (click to toggle)
criticalmass 1%3A1.0.0-1.5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 18,740 kB
  • sloc: ansic: 47,628; cpp: 25,167; sh: 12,025; xml: 3,532; perl: 3,271; makefile: 662; python: 66; awk: 40; lisp: 33
file content (125 lines) | stat: -rw-r--r-- 3,398 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Description:
//   OpenGL display for online update.
//
// Copyright (C) 2005 Frank Becker
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation;  either version 2 of the License,  or (at your option) any  later
// version.
//
// This program is distributed in the hope that it will be useful,  but  WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
//
#include <Trace.hpp>
#include <FontManager.hpp>
#include <Video.hpp>
#include <GameState.hpp>
#include <Config.hpp>

#include <Constants.hpp>
#include <OnlineUpdate.hpp>
#include <OnlineUpdateDisplay.hpp>

OnlineUpdateDisplay::OnlineUpdateDisplay( void):
  _posX(VIDEO_ORTHO_WIDTH),
  _delay(10),
  _updateIsReady(false)
{
    _currentMessage = _messages.begin();
}

OnlineUpdateDisplay::~OnlineUpdateDisplay()
{
}

void OnlineUpdateDisplay::update( void)
{
    bool onlineCheck = false;
    ConfigS::instance()->getBoolean("onlineCheck", onlineCheck);
    if( !onlineCheck) return;

    GLBitmapFont &fontWhite = 
	*(FontManagerS::instance()->getFont( "bitmaps/arial-small"));

    if( ! _updateIsReady)
    {
	OnlineUpdate &ou = *OnlineUpdateS::instance();
	if( ou.getStatus() == OnlineUpdate::eSuccess)
	{
	    list<OnlineUpdate::NewsItem*> &newsItemList = ou.getNewsItems();
	    list<OnlineUpdate::NewsItem*>::iterator i;
	    for( i=newsItemList.begin(); i!=newsItemList.end(); i++)
	    {
		MessageInfo mi;
		mi.message = (*i)->title + ": " + (*i)->text + " (" + (*i)->date + ")";
		mi.r = (*i)->r;
		mi.g = (*i)->g;
		mi.b = (*i)->b;
		_messages.insert( _messages.end(), mi);
	    }

	    if(!ou.isLatest())
	    {
		MessageInfo mi;
		mi.message = "A new version of " + GAMETITLE + " is available! Latest version is " + ou.getLatestVersion() + ". " + ou.getLatestVersionText();
		mi.r = 1.0;
		mi.g = 0.2;
		mi.b = 0.0;
		_messages.insert( _messages.begin(), mi);
	    }
	    _currentMessage = _messages.begin();
	    _updateIsReady = true;

	    MessageInfo mi = (*_currentMessage);
	    _currentTextLength = fontWhite.GetWidth( mi.message.c_str(), 0.6);
	}
    }

    if( _currentMessage == _messages.end()) return;

    _prevPosX = _posX;
    if( _posX > -_currentTextLength)
    {
	_posX-=5.0;
    }
    else if( _delay > 0 )
    {
	_delay--;
	if( _delay == 0)
	{
	    _posX=VIDEO_ORTHO_WIDTH;
	    _prevPosX = _posX;
	    _delay=10; //00;
	    _currentMessage++;
	    if( _currentMessage == _messages.end())
		_currentMessage = _messages.begin();

	    MessageInfo mi = (*_currentMessage);
	    _currentTextLength = fontWhite.GetWidth( mi.message.c_str(), 0.6);
	}
    }
}

void OnlineUpdateDisplay::draw( void)
{
    bool onlineCheck = false;
    ConfigS::instance()->getBoolean("onlineCheck", onlineCheck);
    if( !onlineCheck) return;

    if( !_updateIsReady) return;

    if( _currentMessage == _messages.end()) return;

    MessageInfo mi= (*_currentMessage);

    GLBitmapFont &fontWhite = 
	*(FontManagerS::instance()->getFont( "bitmaps/arial-small"));
    glColor4f(mi.r, mi.g, mi.b, 0.7);

    glPushMatrix();
    float posX = _prevPosX+(_posX-_prevPosX)*GameState::frameFractionOther;
    fontWhite.DrawString( mi.message.c_str(), posX, 25, 0.6, 0.6);
    glPopMatrix();
}