src/statusbar_gui.cpp
author rubidium
Fri, 04 Jul 2008 19:00:11 +0000
changeset 11118 f66e0a4ce878
parent 10775 7061477bfbcf
permissions -rw-r--r--
(svn r13676) -Fix [FS#2126]: inactive companies from old (TTD) saves could be marked active in some cases, which then loads garbage in their statistics and such.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10236
diff changeset
     3
/** @file statusbar_gui.cpp The GUI for the bottom status bar. */
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6145
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1885
diff changeset
     6
#include "openttd.h"
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
     7
#include "settings_type.h"
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
     8
#include "date_func.h"
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
     9
#include "gfx_func.h"
9259
088d3649dd4f (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 9222
diff changeset
    10
#include "news_func.h"
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    11
#include "player_func.h"
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    12
#include "string_func.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8607
diff changeset
    13
#include "strings_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8720
diff changeset
    14
#include "player_base.h"
10467
a8de2b5759bd (svn r13010) -Codechange: move the tree building GUI out of misc_gui.cpp.
rubidium
parents: 10461
diff changeset
    15
#include "tilehighlight_func.h"
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    16
#include "news_gui.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8720
diff changeset
    17
#include "player_gui.h"
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    18
#include "window_gui.h"
10235
684949ed0f03 (svn r12767) -Codechange: merge all main toolbar related functions into a single file instead of scattering the functionality over several files.
rubidium
parents: 10083
diff changeset
    19
#include "variables.h"
10435
0e2b98df9707 (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents: 10434
diff changeset
    20
#include "window_func.h"
10570
b83e3644d1da (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 10521
diff changeset
    21
#include "statusbar_gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    23
#include "table/strings.h"
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    24
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
7855
0465a871522f (svn r10722) -Codechange: unhardcode the positions of strings in the status bar.
rubidium
parents: 7853
diff changeset
    26
static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
{
10521
79e3bb000aed (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 10485
diff changeset
    28
	CopyInDParam(0, ni->params, lengthof(ni->params));
79e3bb000aed (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 10485
diff changeset
    29
	StringID str = ni->string_id;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    31
	char buf[512];
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4907
diff changeset
    32
	GetString(buf, str, lastof(buf));
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    33
	const char *s = buf;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    35
	char buffer[256];
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    36
	char *d = buffer;
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    37
	const char *last = lastof(buffer);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5107
diff changeset
    39
	for (;;) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5107
diff changeset
    40
		WChar c = Utf8Consume(&s);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5107
diff changeset
    41
		if (c == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
			break;
9080
a5e184c542c4 (svn r12165) -Fix [FS#1652, FS#1773]: buffer overflow when drawing scrolling news
glx
parents: 9025
diff changeset
    43
		} else if (c == 0x0D) {
a5e184c542c4 (svn r12165) -Fix [FS#1652, FS#1773]: buffer overflow when drawing scrolling news
glx
parents: 9025
diff changeset
    44
			if (d + 4 >= last) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
			d[0] = d[1] = d[2] = d[3] = ' ';
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    46
			d += 4;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5107
diff changeset
    47
		} else if (IsPrintable(c)) {
9080
a5e184c542c4 (svn r12165) -Fix [FS#1652, FS#1773]: buffer overflow when drawing scrolling news
glx
parents: 9025
diff changeset
    48
			if (d + Utf8CharLen(c) >= last) break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5107
diff changeset
    49
			d += Utf8Encode(d, c);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	}
9080
a5e184c542c4 (svn r12165) -Fix [FS#1652, FS#1773]: buffer overflow when drawing scrolling news
glx
parents: 9025
diff changeset
    52
	*d = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    54
	DrawPixelInfo tmp_dpi;
7855
0465a871522f (svn r10722) -Codechange: unhardcode the positions of strings in the status bar.
rubidium
parents: 7853
diff changeset
    55
	if (!FillDrawPixelInfo(&tmp_dpi, 141, 1, width, 11)) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    57
	DrawPixelInfo *old_dpi = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	_cur_dpi = &tmp_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    60
	int x = DoDrawString(buffer, pos, 0, TC_LIGHT_BLUE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	_cur_dpi = old_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	return x > 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    66
struct StatusBarWindow : Window {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    67
	bool saving;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    68
	int ticker_scroll;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    69
	int reminder_timeout;
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
    70
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    71
	StatusBarWindow(const WindowDesc *desc) : Window(desc)
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    72
	{
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    73
		CLRBITS(this->flags4, WF_WHITE_BORDER_MASK);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    74
		this->ticker_scroll = -1280;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    75
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    76
		this->FindWindowPlacementAndResize(desc);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    77
	}
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    78
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    79
	virtual void OnPaint()
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    80
	{
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    81
		const Player *p = (_local_player == PLAYER_SPECTATOR) ? NULL : GetPlayer(_local_player);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    82
10595
7957c71b0dfe (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 10572
diff changeset
    83
		this->DrawWidgets();
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    84
		SetDParam(0, _date);
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10703
diff changeset
    85
		DrawStringCentered(70, 1, (_pause_game || _settings_client.gui.status_long_date) ? STR_00AF : STR_00AE, TC_FROMSTRING);
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    86
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    87
		if (p != NULL) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    88
			/* Draw player money */
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    89
			SetDParam(0, p->player_money);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    90
			DrawStringCentered(this->widget[2].left + 70, 1, STR_0004, TC_FROMSTRING);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    91
		}
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    92
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    93
		/* Draw status bar */
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    94
		if (this->saving) { // true when saving is active
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    95
			DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    96
		} else if (_do_autosave) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    97
			DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    98
		} else if (_pause_game) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
    99
			DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   100
		} else if (this->ticker_scroll > -1280 && FindWindowById(WC_NEWS_WINDOW, 0) == NULL && _statusbar_news_item.string_id != 0) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   101
			/* Draw the scrolling news text */
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   102
			if (!DrawScrollingStatusText(&_statusbar_news_item, this->ticker_scroll, this->widget[1].right - this->widget[1].left - 2)) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   103
				this->ticker_scroll = -1280;
7855
0465a871522f (svn r10722) -Codechange: unhardcode the positions of strings in the status bar.
rubidium
parents: 7853
diff changeset
   104
				if (p != NULL) {
0465a871522f (svn r10722) -Codechange: unhardcode the positions of strings in the status bar.
rubidium
parents: 7853
diff changeset
   105
					/* This is the default text */
0465a871522f (svn r10722) -Codechange: unhardcode the positions of strings in the status bar.
rubidium
parents: 7853
diff changeset
   106
					SetDParam(0, p->index);
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   107
					DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
7855
0465a871522f (svn r10722) -Codechange: unhardcode the positions of strings in the status bar.
rubidium
parents: 7853
diff changeset
   108
				}
0465a871522f (svn r10722) -Codechange: unhardcode the positions of strings in the status bar.
rubidium
parents: 7853
diff changeset
   109
			}
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   110
		} else {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   111
			if (p != NULL) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   112
				/* This is the default text */
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   113
				SetDParam(0, p->index);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   114
				DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
   115
			}
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   116
		}
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
   117
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   118
		if (this->reminder_timeout > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, this->widget[1].right - 11, 2);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   119
	}
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
   120
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   121
	virtual void OnInvalidateData(int data)
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   122
	{
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   123
		switch (data) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   124
			default: NOT_REACHED();
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   125
			case SBI_SAVELOAD_START:  this->saving = true;  break;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   126
			case SBI_SAVELOAD_FINISH: this->saving = false; break;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   127
			case SBI_SHOW_TICKER:     this->ticker_scroll    = 360; break;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   128
			case SBI_SHOW_REMINDER:   this->reminder_timeout =  91; break;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   129
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	}
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   131
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   132
	virtual void OnClick(Point pt, int widget)
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   133
	{
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   134
		switch (widget) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   135
			case 1: ShowLastNewsMessage(); break;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   136
			case 2: if (_local_player != PLAYER_SPECTATOR) ShowPlayerFinances(_local_player); break;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   137
			default: ResetObjectToPlace();
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   138
		}
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   139
	}
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   140
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   141
	virtual void OnTick()
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   142
	{
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   143
		if (_pause_game) return;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   144
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   145
		if (this->ticker_scroll > -1280) { // Scrolling text
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   146
			this->ticker_scroll -= 2;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   147
			this->InvalidateWidget(1);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   148
		}
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   149
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   150
		if (this->reminder_timeout > 0) { // Red blot to show there are new unread newsmessages
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   151
			this->reminder_timeout -= 2;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   152
		} else if (this->reminder_timeout < 0) {
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   153
			this->reminder_timeout = 0;
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   154
			this->InvalidateWidget(1);
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   155
		}
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   156
	}
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   157
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
static const Widget _main_status_widgets[] = {
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   160
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   139,     0,    11, 0x0, STR_NULL},
7856
121ae75a45a0 (svn r10723) -Codechange: dynamically sized (width) main toolbars and status bar for when the window becomes less than 640 pixels in width.
rubidium
parents: 7855
diff changeset
   161
{    WWT_PUSHBTN,   RESIZE_RIGHT,   14,   140,   179,     0,    11, 0x0, STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS},
121ae75a45a0 (svn r10723) -Codechange: dynamically sized (width) main toolbars and status bar for when the window becomes less than 640 pixels in width.
rubidium
parents: 7855
diff changeset
   162
{    WWT_PUSHBTN,   RESIZE_LR,      14,   180,   319,     0,    11, 0x0, STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 168
diff changeset
   163
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
static WindowDesc _main_status_desc = {
7856
121ae75a45a0 (svn r10723) -Codechange: dynamically sized (width) main toolbars and status bar for when the window becomes less than 640 pixels in width.
rubidium
parents: 7855
diff changeset
   167
	WDP_CENTER, 0, 320, 12, 640, 12,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6141
diff changeset
   168
	WC_STATUS_BAR, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
	_main_status_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
10570
b83e3644d1da (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 10521
diff changeset
   173
/**
b83e3644d1da (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 10521
diff changeset
   174
 * Checks whether the news ticker is currently being used.
b83e3644d1da (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 10521
diff changeset
   175
 */
b83e3644d1da (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 10521
diff changeset
   176
bool IsNewsTickerShown()
b83e3644d1da (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 10521
diff changeset
   177
{
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   178
	const StatusBarWindow *w = dynamic_cast<StatusBarWindow*>(FindWindowById(WC_STATUS_BAR, 0));
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   179
	return w != NULL && w->ticker_scroll > -1280;
10570
b83e3644d1da (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 10521
diff changeset
   180
}
b83e3644d1da (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 10521
diff changeset
   181
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
   182
void ShowStatusBar()
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   183
{
10236
62a0a74e7332 (svn r12768) -Codechange: move the statusbar GUI to it's own file.
rubidium
parents: 10235
diff changeset
   184
	_main_status_desc.top = _screen.height - 12;
10572
bdc63a6797fe (svn r13116) -Codechange: make a window class of the statusbar window.
rubidium
parents: 10570
diff changeset
   185
	new StatusBarWindow(&_main_status_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
}