src/news_gui.cpp
author KUDr
Sat, 21 Apr 2007 08:23:57 +0000
branchcpp_gui
changeset 6308 646711c5feaa
parent 6307 f40e88cff863
permissions -rw-r--r--
(svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
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
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
     3
/** @file news_gui.cpp */
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
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: 1688
diff changeset
     6
#include "openttd.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     7
#include "functions.h"
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1097
diff changeset
     8
#include "strings.h"
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
     9
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
    10
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "window.h"
3155
b2cd7bc9f90f (svn r3778) - Fix crash when resizing news history window.
peter1138
parents: 3143
diff changeset
    12
#include "gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "vehicle.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    17
#include "sound.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    18
#include "variables.h"
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4171
diff changeset
    19
#include "date.h"
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: 4939
diff changeset
    20
#include "string.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    22
/* News system
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    23
 * News system is realized as a FIFO queue (in an array)
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    24
 * The positions in the queue can't be rearranged, we only access
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    25
 * the array elements through pointers to the elements. Once the
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    26
 * array is full, the oldest entry (_oldest_news) is being overwritten
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    27
 * by the newest (_latest news).
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    28
 *
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    29
 * oldest                   current   lastest
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    30
 *  |                          |         |
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    31
 * [O------------F-------------C---------L           ]
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    32
 *               |
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    33
 *            forced
5254
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    34
 *
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    35
 * Of course by using an array we can have situations like
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    36
 *
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    37
 * [----L          O-----F---------C-----------------]
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    38
 * This is where we have wrapped around the array and have
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    39
 * (MAX_NEWS - O) + L news items
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    40
 */
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    41
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    42
#define MAX_NEWS 30
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
    43
#define NB_WIDG_PER_SETTING 4
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    44
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
    45
typedef byte NewsID;
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    46
#define INVALID_NEWS 255
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    47
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    48
static NewsItem _news_items[MAX_NEWS];
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
    49
static NewsID _current_news = INVALID_NEWS; // points to news item that should be shown next
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
    50
static NewsID _oldest_news = 0;    // points to first item in fifo queue
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
    51
static NewsID _latest_news = INVALID_NEWS;  // points to last item in fifo queue
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    52
/* if the message being shown was forced by the user, its index is stored in
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    53
 * _forced_news. forced_news is INVALID_NEWS otherwise.
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    54
 * (Users can force messages through history or "last message") */
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
    55
static NewsID _forced_news = INVALID_NEWS;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    56
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    57
static byte _total_news = 0; // total news count
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6263
diff changeset
    59
void DrawNewsNewVehicleAvail(BaseWindow *w);
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
    60
void DrawNewsBankrupcy(BaseWindow *w);
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
    61
static void MoveToNextItem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6263
diff changeset
    63
StringID GetNewsStringNewVehicleAvail(const NewsItem *ni);
2101
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
    64
StringID GetNewsStringBankrupcy(const NewsItem *ni);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
static DrawNewsCallbackProc * const _draw_news_callback[] = {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
    67
	DrawNewsNewVehicleAvail,  //< DNC_VEHICLEAVAIL
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
    68
	DrawNewsBankrupcy,        //< DNC_BANKRUPCY
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    71
extern GetNewsStringCallbackProc * const _get_news_string_callback[];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
GetNewsStringCallbackProc * const _get_news_string_callback[] = {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
    73
	GetNewsStringNewVehicleAvail,  ///< DNC_VEHICLEAVAIL
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
    74
	GetNewsStringBankrupcy,        ///< DNC_BANKRUPCY
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
    77
void InitNewsItemStructs()
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    78
{
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    79
	memset(_news_items, 0, sizeof(_news_items));
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    80
	_current_news = INVALID_NEWS;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
    81
	_oldest_news = 0;
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    82
	_latest_news = INVALID_NEWS;
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    83
	_forced_news = INVALID_NEWS;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
    84
	_total_news = 0;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    85
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
    87
void DrawNewsBorder(const BaseWindow *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	int left = 0;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
    90
	int right = w->Width() - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	int top = 0;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
    92
	int bottom = w->Height() - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	GfxFillRect(left, top, right, bottom, 0xF);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    95
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
	GfxFillRect(left, top, left, bottom, 0xD7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	GfxFillRect(right, top, right, bottom, 0xD7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
	GfxFillRect(left, top, right, top, 0xD7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
	GfxFillRect(left, bottom, right, bottom, 0xD7);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   100
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   101
	DrawString(left + 2, top + 1, STR_00C6, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   104
static void NewsWindowProc(BaseWindow *w, WindowEvent *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
{
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   106
	switch (e->event) {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   107
	case WE_CREATE: { // If chatbar is open at creation time, we need to go above it
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   108
		const BaseWindow *w1 = BaseWindow::FindById(WC_SEND_NETWORK_MSG, 0);
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   109
		w->message.msg = (w1 != NULL) ? w1->Height() : 0;
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
   110
	} break;
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
   111
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
	case WE_PAINT: {
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   113
		const NewsItem *ni = WP(w, news_d).ni;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
		ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   116
		switch (ni->display_mode) {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   117
			case NM_NORMAL:
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   118
			case NM_THIN: {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   119
				DrawNewsBorder(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   121
				DrawString(2, 1, STR_00C6, 0);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   122
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   123
				SetDParam(0, ni->date);
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   124
				DrawStringRightAligned(428, 1, STR_01FF, 0);
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   125
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   126
				if (!(ni->flags & NF_VIEWPORT)) {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   127
					COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   128
					DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56,
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6263
diff changeset
   129
						ni->string_id, w->Width() - 4);
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   130
				} else {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   131
					/* Back up transparency options to draw news view */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   132
					byte to_backup = _transparent_opt;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   133
					_transparent_opt = 0;
6244
4b42fb40e6d2 (svn r8710) [cpp_gui] -Codechange: yet another two functions are turned into Window methods
bjarni
parents: 6242
diff changeset
   134
					w->DrawViewport();
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   135
					_transparent_opt = to_backup;
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   136
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   137
					/* Shade the viewport into gray, or color*/
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   138
					vp = w->viewport;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   139
					GfxFillRect(vp->left - w->Left(), vp->top - w->Top(),
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   140
						vp->left - w->Left() + vp->width - 1, vp->top - w->Top() + vp->height - 1,
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5846
diff changeset
   141
						(ni->flags & NF_INCOLOR ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY) | (1 << USE_COLORTABLE)
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   142
					);
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   143
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   144
					COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6263
diff changeset
   145
					DrawStringMultiCenter(w->Width() / 2, 20, ni->string_id, w->Width() - 4);
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   146
				}
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   147
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
			}
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   149
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   150
			case NM_CALLBACK: {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   151
				_draw_news_callback[ni->callback](w);
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   152
				break;
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   153
			}
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   154
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   155
			default: {
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6237
diff changeset
   156
				w->DrawWidgets();
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   157
				if (!(ni->flags & NF_VIEWPORT)) {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   158
					COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   159
					DrawStringMultiCenter(140, 38, ni->string_id, 276);
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   160
				} else {
6244
4b42fb40e6d2 (svn r8710) [cpp_gui] -Codechange: yet another two functions are turned into Window methods
bjarni
parents: 6242
diff changeset
   161
					w->DrawViewport();
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   162
					COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6263
diff changeset
   163
					DrawStringMultiCenter(w->Width() / 2, w->Height() - 16, ni->string_id, w->Width() - 4);
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   164
				}
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   165
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
	case WE_CLICK: {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   171
		switch (e->we.click.widget) {
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   172
		case 1: {
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   173
			NewsItem *ni = WP(w, news_d).ni;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6144
diff changeset
   174
			w->Close();
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   175
			ni->duration = 0;
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   176
			_forced_news = INVALID_NEWS;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   177
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
		case 0: {
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   179
			NewsItem *ni = WP(w, news_d).ni;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
			if (ni->flags & NF_VEHICLE) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   181
				Vehicle *v = GetVehicle(ni->data_a);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
				ScrollMainWindowTo(v->x_pos, v->y_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
			} else if (ni->flags & NF_TILE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
				if (!ScrollMainWindowToTile(ni->data_a) && ni->data_b != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
					ScrollMainWindowToTile(ni->data_b);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	case WE_KEYPRESS:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   192
		if (e->we.keypress.keycode == WKC_SPACE) {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   193
			/* Don't continue. */
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   194
			e->we.keypress.cont = false;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6144
diff changeset
   195
			w->Close();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   199
	case WE_MESSAGE: // The chatbar has notified us that is was either created or closed
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   200
		switch (e->we.message.msg) {
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   201
			case WE_CREATE: w->message.msg = e->we.message.wparam; break;
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
   202
			case WE_DESTROY: w->message.msg = 0; break;
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
   203
		}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
   204
		break;
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
   205
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   206
	case WE_TICK: { // Scroll up newsmessages from the bottom in steps of 4 pixels
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   207
		int y = max(w->Top() - 4, _screen.height - w->Height() - 12 - w->message.msg);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   208
		if (y == w->Top()) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
		if (w->viewport != NULL)
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   211
			w->viewport->top += y - w->Top();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   213
		int16 diff = delta(w->Top(), (int16)y);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   214
		w->SetTop(y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   216
		SetDirtyBlocks(w->Left(), w->Top() - diff, w->Left() + w->Width(), w->Top() + w->Height());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   221
/** Return the correct index in the pseudo-fifo
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   222
 * queue and deals with overflows when increasing the index */
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   223
static inline NewsID increaseIndex(NewsID i)
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   224
{
5258
eae66ac02803 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   225
	assert(i != INVALID_NEWS);
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   226
	return (i + 1) % MAX_NEWS;
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   227
}
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   228
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   229
/** Return the correct index in the pseudo-fifo
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   230
 * queue and deals with overflows when decreasing the index */
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   231
static inline NewsID decreaseIndex(NewsID i)
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   232
{
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   233
	assert(i != INVALID_NEWS);
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   234
	return (i + MAX_NEWS - 1) % MAX_NEWS;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   235
}
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   236
4873
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   237
/** Add a new newsitem to be shown.
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   238
 * @param string String to display, can have special values based on parameter 'flags'
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   239
 * @param flags various control bits that will show various news-types. See macro NEWS_FLAGS()
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   240
 * @param data_a news-specific value based on news type
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   241
 * @param data_b news-specific value based on news type
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   242
 * @note flags exists of 4 byte-sized extra parameters.
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   243
 * 1.  0 -  7 display_mode, any of the NewsMode enums (NM_)
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   244
 * 2.  8 - 15 news flags, any of the NewsFlags enums (NF_) NF_INCOLOR are set automatically if needed
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   245
 * 3. 16 - 23 news category, any of the NewsType enums (NT_)
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   246
 * 4. 24 - 31 news callback function, any of the NewsCallback enums (DNC_)
4873
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   247
 * If the display mode is NM_CALLBACK special news is shown and parameter
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   248
 * stringid has a special meaning.
4873
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   249
 * DNC_TRAINAVAIL, DNC_ROADAVAIL, DNC_SHIPAVAIL, DNC_AIRCRAFTAVAIL: StringID is
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   250
 * the index of the engine that is shown
4873
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   251
 * DNC_BANKRUPCY: bytes 0-3 of StringID contains the player that is in trouble,
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   252
 * and 4-7 contains what kind of bankrupcy message is shown, NewsBankrupcy enum (NB_)
4873
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   253
 * @see NewsMode
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   254
 * @see NewsFlags
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   255
 * @see NewsType
7cb19235cf60 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   256
 * @see NewsCallback */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
{
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   259
	NewsID l_news;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
4000
bab1ebc37da0 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3155
diff changeset
   261
	if (_game_mode == GM_MENU) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   263
	/* check the rare case that the oldest (to be overwritten) news item is open */
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   264
	if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news))
5253
a9775de4e6b6 (svn r7383) -Codechange: fix up typo in news-gui s/MoveToNexItem/MoveToNextItem/.
Darkvater
parents: 5246
diff changeset
   265
		MoveToNextItem();
102
1d277a07f1f1 (svn r103) Fix: rare newspaper crash with too many messages [ 1009976 ] (thx to blathij)s
dominik
parents: 94
diff changeset
   266
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   267
	if (_total_news < MAX_NEWS) _total_news++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   268
5258
eae66ac02803 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   269
	/* Increase _latest_news. If we have no news yet, use _oldest news as an
eae66ac02803 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   270
	 * index. We cannot use 0 as _oldest_news can jump around due to
eae66ac02803 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   271
	 * DeleteVehicleNews */
5244
e110f52333e8 (svn r7368) -Fix: [FS#332] Vehicle Deletion Crash [News Window Related?] (r3757).
Darkvater
parents: 5108
diff changeset
   272
	l_news = _latest_news;
5258
eae66ac02803 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   273
	_latest_news = (_latest_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_latest_news);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   274
5244
e110f52333e8 (svn r7368) -Fix: [FS#332] Vehicle Deletion Crash [News Window Related?] (r3757).
Darkvater
parents: 5108
diff changeset
   275
	/* If the fifo-buffer is full, overwrite the oldest entry */
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   276
	if (l_news != INVALID_NEWS && _latest_news == _oldest_news) {
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   277
		assert(_total_news == MAX_NEWS);
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   278
		_oldest_news = increaseIndex(_oldest_news);
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   279
	}
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   280
5846
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   281
	/*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d",
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   282
	  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   283
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   284
	/* Add news to _latest_news */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   285
	{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   286
		BaseWindow *w;
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   287
		NewsItem *ni = &_news_items[_latest_news];
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   288
		memset(ni, 0, sizeof(*ni));
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   289
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   290
		ni->string_id = string;
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   291
		ni->display_mode = (byte)flags;
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   292
		ni->flags = (byte)(flags >> 8);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   293
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   294
		/* show this news message in color? */
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   295
		if (_cur_year >= _patches.colored_news_year) ni->flags |= NF_INCOLOR;
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   296
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   297
		ni->type = (byte)(flags >> 16);
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   298
		ni->callback = (byte)(flags >> 24);
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   299
		ni->data_a = data_a;
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   300
		ni->data_b = data_b;
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   301
		ni->date = _date;
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   302
		COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params));
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   303
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   304
		w = BaseWindow::FindById(WC_MESSAGE_HISTORY, 0);
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   305
		if (w == NULL) return;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6144
diff changeset
   306
		w->SetDirty();
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   307
		w->vscroll.count = _total_news;
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   308
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
715
83805642c830 (svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents: 541
diff changeset
   311
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   312
/* Don't show item if it's older than x days, corresponds with NewsType in news.h */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   315
static const OldWidget _news_type13_widgets[] = {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 745
diff changeset
   316
{      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   169, 0x0, STR_NULL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 745
diff changeset
   317
{      WWT_PANEL,   RESIZE_NONE,    15,     0,    10,     0,    11, 0x0, STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 102
diff changeset
   318
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
static WindowDesc _news_type13_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
	WDP_CENTER, 476, 430, 170,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6090
diff changeset
   323
	WC_NEWS_WINDOW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
	WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	_news_type13_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
	NewsWindowProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   329
static const OldWidget _news_type2_widgets[] = {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 745
diff changeset
   330
{      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   129, 0x0, STR_NULL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 745
diff changeset
   331
{      WWT_PANEL,   RESIZE_NONE,    15,     0,    10,     0,    11, 0x0, STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 102
diff changeset
   332
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
static WindowDesc _news_type2_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	WDP_CENTER, 476, 430, 130,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6090
diff changeset
   337
	WC_NEWS_WINDOW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
	_news_type2_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	NewsWindowProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   343
static const OldWidget _news_type0_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   344
{      WWT_PANEL,   RESIZE_NONE,     5,     0,   279,    14,    86, 0x0,              STR_NULL},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   345
{   WWT_CLOSEBOX,   RESIZE_NONE,     5,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   346
{    WWT_CAPTION,   RESIZE_NONE,     5,    11,   279,     0,    13, STR_012C_MESSAGE, STR_NULL},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   347
{      WWT_INSET,   RESIZE_NONE,     5,     2,   277,    16,    64, 0x0,              STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 102
diff changeset
   348
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
static WindowDesc _news_type0_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
	WDP_CENTER, 476, 280, 87,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6090
diff changeset
   353
	WC_NEWS_WINDOW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	_news_type0_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
	NewsWindowProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   359
static const SoundFx _news_sounds[NT_END] = {
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   360
	SND_1D_APPLAUSE,
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   361
	SND_1D_APPLAUSE,
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   362
	SND_BEGIN,
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   363
	SND_BEGIN,
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   364
	SND_BEGIN,
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   365
	SND_BEGIN,
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   366
	SND_BEGIN,
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   367
	SND_1E_OOOOH,
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   368
	SND_BEGIN,
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   369
	SND_BEGIN,
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   370
	SND_BEGIN,
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   371
};
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   372
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   373
const char *_news_display_name[NT_END] = {
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   374
	"arrival_player",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   375
	"arrival_other",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   376
	"accident",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   377
	"company_info",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   378
	"openclose",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   379
	"economy",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   380
	"advice",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   381
	"new_vehicles",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   382
	"acceptance",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   383
	"subsidies",
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   384
	"general",
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   385
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   387
/** Get the value of an item of the news-display settings. This is
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   388
 * a little tricky since on/off/summary must use 2 bits to store the value
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   389
 * @param item the item whose value is requested
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   390
 * @return return the found value which is between 0-2
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   391
 */
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   392
static inline byte GetNewsDisplayValue(byte item)
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   393
{
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   394
	assert(item < NT_END && GB(_news_display_opt, item * 2, 2) <= 2);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2498
diff changeset
   395
	return GB(_news_display_opt, item * 2, 2);
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   396
}
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   397
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   398
/** Set the value of an item in the news-display settings. This is
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   399
 * a little tricky since on/off/summary must use 2 bits to store the value
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   400
 * @param item the item whose value is being set
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   401
 * @param val new value
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   402
 */
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   403
static inline void SetNewsDisplayValue(byte item, byte val)
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   404
{
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   405
	assert(item < NT_END && val <= 2);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2498
diff changeset
   406
	SB(_news_display_opt, item * 2, 2, val);
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   407
}
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   408
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   409
/* open up an own newspaper window for the news item */
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   410
static void ShowNewspaper(NewsItem *ni)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   412
	BaseWindow *w;
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2227
diff changeset
   413
	SoundFx sound;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   414
	int top;
4874
b95cdd66085f (svn r6804) -Codechange: Remove the unused NF_NOEXPIRE flag.
Darkvater
parents: 4873
diff changeset
   415
	ni->flags &= ~NF_FORCE_BIG;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   416
	ni->duration = 555;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   418
	sound = _news_sounds[ni->type];
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   419
	if (sound != 0) SndPlayFx(sound);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   420
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
   421
	top = _screen.height;
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   422
	switch (ni->display_mode) {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   423
		case NM_NORMAL:
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   424
		case NM_CALLBACK: {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   425
			_news_type13_desc.top = top;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   426
			w = BaseWindow::Allocate(&_news_type13_desc);
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   427
			if (ni->flags & NF_VIEWPORT)
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   428
				AssignWindowViewport(w, 2, 58, 0x1AA, 0x6E,
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   429
					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0);
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   430
			break;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   431
		}
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   432
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   433
		case NM_THIN: {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   434
			_news_type2_desc.top = top;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   435
			w = BaseWindow::Allocate(&_news_type2_desc);
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   436
			if (ni->flags & NF_VIEWPORT)
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   437
				AssignWindowViewport(w, 2, 58, 0x1AA, 0x46,
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   438
					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0);
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   439
			break;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   440
		}
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   441
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   442
		default: {
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   443
			_news_type0_desc.top = top;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   444
			w = BaseWindow::Allocate(&_news_type0_desc);
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   445
			if (ni->flags & NF_VIEWPORT)
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   446
				AssignWindowViewport(w, 3, 17, 0x112, 0x2F,
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   447
					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0);
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   448
			break;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   449
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	}
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   451
5846
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   452
	/*DEBUG(misc, 0, " cur %3d, old %2d, lat %3d, for %3d, tot %2d",
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   453
	  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   454
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   455
	WP(w, news_d).ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news];
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   456
	w->flags4 |= WF_DISABLE_VP_SCROLL;
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   457
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   459
/* show news item in the ticker */
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   460
static void ShowTicker(const NewsItem *ni)
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   461
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   462
	BaseWindow *w;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   463
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   464
	if (_news_ticker_sound) SndPlayFx(SND_16_MORSE);
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   465
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   466
	_statusbar_news_item = *ni;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   467
	w = BaseWindow::FindById(WC_STATUS_BAR, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   468
	if (w != NULL) WP(w, def_d).data_1 = 360;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   469
}
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   470
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   471
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   472
/** Are we ready to show another news item?
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   473
 * Only if nothing is in the newsticker and no newspaper is displayed */
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   474
static bool ReadyForNextItem()
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   475
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   476
	const BaseWindow *w;
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   477
	NewsID item = (_forced_news == INVALID_NEWS) ? _current_news : _forced_news;
92
20b4c7536349 (svn r93) Fix: memory leak in news system (blathijs)
dominik
parents: 89
diff changeset
   478
	NewsItem *ni;
20b4c7536349 (svn r93) Fix: memory leak in news system (blathijs)
dominik
parents: 89
diff changeset
   479
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   480
	if (item >= MAX_NEWS) return true;
92
20b4c7536349 (svn r93) Fix: memory leak in news system (blathijs)
dominik
parents: 89
diff changeset
   481
	ni = &_news_items[item];
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   482
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   483
	/* Ticker message
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   484
	 * Check if the status bar message is still being displayed? */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   485
	w = BaseWindow::FindById(WC_STATUS_BAR, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   486
	if (w != NULL && WP(w, const def_d).data_1 > -1280) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   488
	/* Newspaper message, decrement duration counter */
5264
b2b3c60af210 (svn r7402) -Fix: [FS#255] Long Delay for Message Windows to Appear. Immediately show a new message
Darkvater
parents: 5258
diff changeset
   489
	if (ni->duration != 0) ni->duration--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   491
	/* neither newsticker nor newspaper are running */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   492
	return (ni->duration == 0 || BaseWindow::FindById(WC_NEWS_WINDOW, 0) == NULL);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   493
}
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   494
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   495
static void MoveToNextItem()
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   496
{
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   497
	DeleteWindowById(WC_NEWS_WINDOW, 0);
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   498
	_forced_news = INVALID_NEWS;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   499
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   500
	/* if we're not at the last item, then move on */
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   501
	if (_current_news != _latest_news) {
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   502
		NewsItem *ni;
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   503
5258
eae66ac02803 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   504
		_current_news = (_current_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_current_news);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   505
		ni = &_news_items[_current_news];
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   506
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   507
		/* check the date, don't show too old items */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   508
		if (_date - _news_items_age[ni->type] > ni->date) return;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   509
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   510
		switch (GetNewsDisplayValue(ni->type)) {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   511
		case 0: { // Off - show nothing only a small reminder in the status bar
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   512
			BaseWindow *w = BaseWindow::FindById(WC_STATUS_BAR, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   513
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   514
			if (w != NULL) {
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   515
				WP(w, def_d).data_2 = 91;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6144
diff changeset
   516
				w->SetDirty();
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   517
			}
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   518
			break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   519
		}
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   520
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   521
		case 1: // Summary - show ticker, but if forced big, cascade to full
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   522
			if (!(ni->flags & NF_FORCE_BIG)) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   523
				ShowTicker(ni);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   524
				break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   525
			}
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   526
			/* Fallthrough */
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   527
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   528
		case 2: // Full - show newspaper
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   529
			ShowNewspaper(ni);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   530
			break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   531
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
	}
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   533
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   535
void NewsLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   537
	/* no news item yet */
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   538
	if (_total_news == 0) return;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   539
5253
a9775de4e6b6 (svn r7383) -Codechange: fix up typo in news-gui s/MoveToNexItem/MoveToNextItem/.
Darkvater
parents: 5246
diff changeset
   540
	if (ReadyForNextItem()) MoveToNextItem();
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   541
}
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   542
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   543
/* Do a forced show of a specific message */
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   544
static void ShowNewsMessage(NewsID i)
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   545
{
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   546
	if (_total_news == 0) return;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   547
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   548
	/* Delete the news window */
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   549
	DeleteWindowById(WC_NEWS_WINDOW, 0);
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   550
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   551
	/* setup forced news item */
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   552
	_forced_news = i;
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   553
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   554
	if (_forced_news != INVALID_NEWS) {
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   555
		NewsItem *ni = &_news_items[_forced_news];
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   556
		ni->duration = 555;
4874
b95cdd66085f (svn r6804) -Codechange: Remove the unused NF_NOEXPIRE flag.
Darkvater
parents: 4873
diff changeset
   557
		ni->flags |= NF_FORCE_BIG;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   558
		DeleteWindowById(WC_NEWS_WINDOW, 0);
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   559
		ShowNewspaper(ni);
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   560
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   563
void ShowLastNewsMessage()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
{
5846
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   565
	if (_forced_news == INVALID_NEWS) {
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   566
		/* Not forced any news yet, show the current one, unless a news window is
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   567
		 * open (which can only be the current one), then show the previous item */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   568
		const BaseWindow *w = BaseWindow::FindById(WC_NEWS_WINDOW, 0);
6090
21f2934dee5c (svn r8409) -Regression (r8049): When the latest news was deleted, the news queue wrapped back to the oldest item, showing all news again.
Darkvater
parents: 5919
diff changeset
   569
		ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : decreaseIndex(_current_news));
5846
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   570
	} else if (_forced_news == _oldest_news) {
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   571
		/* We have reached the oldest news, start anew with the latest */
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   572
		ShowNewsMessage(_latest_news);
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   573
	} else {
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   574
		/* 'Scrolling' through news history show each one in turn */
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   575
		ShowNewsMessage(decreaseIndex(_forced_news));
83
bd21afea96d8 (svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents: 80
diff changeset
   576
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   579
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   580
/* return news by number, with 0 being the most
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
   581
 * recent news. Returns INVALID_NEWS if end of queue reached. */
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   582
static NewsID getNews(NewsID i)
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   583
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   584
	if (i >= _total_news) return INVALID_NEWS;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   585
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   586
	if (_latest_news < i) {
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   587
		i = _latest_news + MAX_NEWS - i;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   588
	} else {
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   589
		i = _latest_news - i;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   590
	}
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   591
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   592
	i %= MAX_NEWS;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   593
	return i;
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   594
}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   595
2101
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   596
/** Draw an unformatted news message truncated to a maximum length. If
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   597
 * length exceeds maximum length it will be postfixed by '...'
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   598
 * @param x,y position of the string
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   599
 * @param color the color the string will be shown in
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   600
 * @param *ni NewsItem being printed
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   601
 * @param maxw maximum width of string in pixels
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   602
 */
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   603
static void DrawNewsString(int x, int y, uint16 color, const NewsItem *ni, uint maxw)
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   604
{
2101
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   605
	char buffer[512], buffer2[512];
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: 4939
diff changeset
   606
	const char *ptr;
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: 4939
diff changeset
   607
	char *dest;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   608
	StringID str;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   609
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   610
	if (ni->display_mode == 3) {
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   611
		str = _get_news_string_callback[ni->callback](ni);
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   612
	} else {
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   613
		COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   614
		str = ni->string_id;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   615
	}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   616
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4874
diff changeset
   617
	GetString(buffer, str, lastof(buffer));
2101
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   618
	/* Copy the just gotten string to another buffer to remove any formatting
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   619
	 * from it such as big fonts, etc. */
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: 4939
diff changeset
   620
	ptr  = buffer;
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: 4939
diff changeset
   621
	dest = buffer2;
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: 4939
diff changeset
   622
	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: 4939
diff changeset
   623
		WChar c = Utf8Consume(&ptr);
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: 4939
diff changeset
   624
		if (c == 0) break;
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: 4939
diff changeset
   625
		if (c == '\r') {
2101
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   626
			dest[0] = dest[1] = dest[2] = dest[3] = ' ';
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   627
			dest += 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: 4939
diff changeset
   628
		} else if (IsPrintable(c)) {
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: 4939
diff changeset
   629
			dest += Utf8Encode(dest, c);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   630
		}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   631
	}
2101
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   632
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   633
	*dest = '\0';
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   634
	/* Truncate and show string; postfixed by '...' if neccessary */
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   635
	DoDrawStringTruncated(buffer2, x, y, color, maxw);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   636
}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   637
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   638
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   639
static void MessageHistoryWndProc(BaseWindow *w, WindowEvent *e)
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   640
{
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   641
	switch (e->event) {
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   642
	case WE_PAINT: {
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   643
		int y = 19;
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   644
		NewsID p, show;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   645
3155
b2cd7bc9f90f (svn r3778) - Fix crash when resizing news history window.
peter1138
parents: 3143
diff changeset
   646
		SetVScrollCount(w, _total_news);
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6237
diff changeset
   647
		w->DrawWidgets();
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   648
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   649
		if (_total_news == 0) break;
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   650
		show = min(_total_news, w->vscroll.cap);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   651
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   652
		for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   653
			/* get news in correct order */
2101
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   654
			const NewsItem *ni = &_news_items[getNews(p)];
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   655
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   656
			SetDParam(0, ni->date);
2101
763d0d48f39c (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   657
			DrawString(4, y, STR_SHORT_DATE, 12);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   658
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   659
			DrawNewsString(82, y, 12, ni, w->Width() - 95);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   660
			y += 12;
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   661
		}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   662
		break;
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   663
	}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   664
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   665
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   666
		switch (e->we.click.widget) {
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   667
		case 3: {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   668
			int y = (e->we.click.pt.y - 19) / 12;
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   669
			NewsID p = getNews(y + w->vscroll.pos);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   670
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   671
			if (p == INVALID_NEWS) break;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   672
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   673
			ShowNewsMessage(p);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   674
			break;
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   675
		}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   676
		}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   677
		break;
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   678
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   679
	case WE_RESIZE:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   680
		w->vscroll.cap += e->we.sizing.diff.y / 12;
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   681
		break;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   682
	}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   683
}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   684
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   685
static const OldWidget _message_history_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   686
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,            STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   687
{    WWT_CAPTION,  RESIZE_RIGHT,    13,    11,   387,     0,    13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   688
{  WWT_STICKYBOX,     RESIZE_LR,    13,   388,   399,     0,    13, 0x0,                 STR_STICKY_BUTTON},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   689
{      WWT_PANEL,     RESIZE_RB,    13,     0,   387,    14,   139, 0x0,                 STR_MESSAGE_HISTORY_TIP},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   690
{  WWT_SCROLLBAR,    RESIZE_LRB,    13,   388,   399,    14,   127, 0x0,                 STR_0190_SCROLL_BAR_SCROLLS_LIST},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   691
{  WWT_RESIZEBOX,   RESIZE_LRTB,    13,   388,   399,   128,   139, 0x0,                 STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 102
diff changeset
   692
{   WIDGETS_END},
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   693
};
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   694
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   695
static const WindowDesc _message_history_desc = {
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   696
	240, 22, 400, 140,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6090
diff changeset
   697
	WC_MESSAGE_HISTORY, WC_NONE,
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   698
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   699
	_message_history_widgets,
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   700
	MessageHistoryWndProc
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   701
};
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   702
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   703
void ShowMessageHistory()
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   704
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   705
	BaseWindow *w;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   706
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   707
	DeleteWindowById(WC_MESSAGE_HISTORY, 0);
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   708
	w = BaseWindow::Allocate(&_message_history_desc);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   709
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   710
	if (w != NULL) {
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   711
		w->vscroll.cap = 10;
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   712
		w->vscroll.count = _total_news;
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   713
		w->resize.step_height = 12;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   714
		w->resize.height = w->Height() - 12 * 6; // minimum of 4 items in the list, each item 12 high
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   715
		w->resize.step_width = 1;
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   716
		w->resize.width = 200; // can't make window any smaller than 200 pixel
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6144
diff changeset
   717
		w->SetDirty();
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   718
	}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   719
}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   720
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   721
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   722
enum {
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   723
	WIDGET_NEWSOPT_BTN_SUMMARY  = 4,  ///< Button that adjusts at once the level for all settings
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   724
	WIDGET_NEWSOPT_DROP_SUMMARY,      ///< Drop down button for same upper button
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   725
	WIDGET_NEWSOPT_SOUNDTICKER  = 7,  ///< Button activating sound on events
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   726
	WIDGET_NEWSOPT_START_OPTION = 9,  ///< First widget that is part of a group [<] .. [.]
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   727
};
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   728
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   729
/** Setup the disabled/enabled buttons in the message window
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   730
 * If the value is 'off' disable the [<] widget, and enable the [>] one
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   731
 * Same-wise for all the others. Starting value of 4 is the first widget
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   732
 * group. These are grouped as [<][>] .. [<][>], etc.
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   733
 * @param w Window been used
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   734
 * @param value to set in the widget
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   735
 * @param element index of the group of widget to set
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   736
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   737
static void SetMessageButtonStates(BaseWindow *w, byte value, int element)
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   738
{
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   739
	element *= NB_WIDG_PER_SETTING;
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   740
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   741
	w->SetWidgetDisabledState(element + WIDGET_NEWSOPT_START_OPTION, value == 0);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   742
	w->SetWidgetDisabledState(element + WIDGET_NEWSOPT_START_OPTION + 2, value == 2);
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   743
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   745
/**
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   746
 * Event handler of the Message Options window
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   747
 * @param w window pointer
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   748
 * @param e event been triggered
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   749
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   750
static void MessageOptionsWndProc(BaseWindow *w, WindowEvent *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
{
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   752
	static const StringID message_opt[] = {STR_OFF, STR_SUMMARY, STR_FULL, INVALID_STRING_ID};
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   753
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   754
	/* WP(w, def_d).data_1 stores state of the ALL on/off/summary button */
427
d87c7d677d2f (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   755
	switch (e->event) {
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   756
		case WE_CREATE: {
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   757
			uint32 val = _news_display_opt;
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   758
			uint32 all_val;
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   759
			int i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   761
			/* Set up the initial disabled buttons in the case of 'off' or 'full' */
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   762
			all_val = val & 0x3;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   763
			for (i = 0; i < NT_END; i++, val >>= 2) {
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   764
				SetMessageButtonStates(w, val & 0x3, i);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   765
				/* If the value doesn't match the ALL-button value, set the ALL-button value to 'off' */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   766
				if ((val & 0x3) != all_val) all_val = 0;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   767
			}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   768
			/* If all values are the same value, the ALL-button will take over this value */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   769
			WP(w, def_d).data_1 = all_val;
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   770
		} break;
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   771
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   772
		case WE_PAINT: {
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   773
			uint32 val = _news_display_opt;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   774
			int i, y;
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   775
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   776
			if (_news_ticker_sound) w->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   777
			w->DrawWidgets();
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1648
diff changeset
   778
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   779
			/* Draw the string of each setting on each button. */
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   780
			for (i = 0, y = 26; i < NT_END; i++, y += 12, val >>= 2) {
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   781
				/* 51 comes from 13 + 89 (left and right of the button)+1, shiefted by one as to get division,
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   782
				 * which will give centered position */
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   783
				DrawStringCentered(51, y + 1, message_opt[val & 0x3], 0x10);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   784
			}
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   785
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   786
			/* Draw the general bottom button string as well */
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   787
			DrawStringCentered(51, y + 10, message_opt[WP(w, def_d).data_1], 0x10);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   788
		} break;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   789
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   790
		case WE_CLICK:
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   791
			switch (e->we.click.widget) {
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   792
				case WIDGET_NEWSOPT_BTN_SUMMARY:
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   793
				case WIDGET_NEWSOPT_DROP_SUMMARY: // Dropdown menu for all settings
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   794
					w->ShowDropDownMenu(message_opt, WP(w, def_d).data_1, WIDGET_NEWSOPT_DROP_SUMMARY, 0, 0);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   795
					break;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   796
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   797
				case WIDGET_NEWSOPT_SOUNDTICKER: // Change ticker sound on/off
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   798
					_news_ticker_sound ^= 1;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   799
					w->ToggleWidgetLoweredState(e->we.click.widget);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   800
					w->InvalidateWidget(e->we.click.widget);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   801
					break;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   802
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   803
				default: { // Clicked on the [<] .. [>] widgets
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   804
					int wid = e->we.click.widget - WIDGET_NEWSOPT_START_OPTION;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   805
					if (wid >= 0 && wid < (NB_WIDG_PER_SETTING * NT_END)) {
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   806
						int element = wid / NB_WIDG_PER_SETTING;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   807
						byte val = (GetNewsDisplayValue(element) + ((wid % NB_WIDG_PER_SETTING) ? 1 : -1)) % 3;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   808
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   809
						SetMessageButtonStates(w, val, element);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   810
						SetNewsDisplayValue(element, val);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   811
						w->SetDirty();
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   812
					}
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   813
				} break;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   814
			} break;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   815
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   816
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   817
		case WE_DROPDOWN_SELECT: { // Select all settings for newsmessages
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   818
			int i;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   819
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   820
			WP(w, def_d).data_1 = e->we.dropdown.index;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   821
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   822
			for (i = 0; i < NT_END; i++) {
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   823
				SetMessageButtonStates(w, e->we.dropdown.index, i);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   824
				SetNewsDisplayValue(i, e->we.dropdown.index);
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   825
			}
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   826
			w->SetDirty();
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   827
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   831
static const OldWidget _message_options_widgets[] = {
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   832
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,   10,     0,    13, STR_00C5,                              STR_018B_CLOSE_WINDOW},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   833
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,  409,     0,    13, STR_0204_MESSAGE_OPTIONS,              STR_018C_WINDOW_TITLE_DRAG_THIS},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   834
{      WWT_PANEL,   RESIZE_NONE,    13,     0,  409,    14,   196, 0x0,                                   STR_NULL},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   835
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   836
/* Text at the top of the main panel, in black */
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   837
{      WWT_LABEL,   RESIZE_NONE,    13,     0,  409,    13,    26, STR_0205_MESSAGE_TYPES,                STR_NULL},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   838
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   839
/* General drop down and sound button */
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   840
{      WWT_PANEL,   RESIZE_NONE,     3,     4,   86,   166,   177, 0x0,                                   STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   841
{    WWT_TEXTBTN,   RESIZE_NONE,     3,    87,   98,   166,   177, STR_0225,                              STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   842
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,   167,   179, STR_MESSAGES_ALL,                      STR_NULL},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   843
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   844
{  WWT_TEXTBTN_2,   RESIZE_NONE,     3,     4,   98,   178,   189, STR_02DB_OFF,                          STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   845
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,   179,   191, STR_MESSAGE_SOUND,                     STR_NULL},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   846
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   847
/* Each four group is composed of the buttons [<] [..] [>] and the descriptor of the setting */
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   848
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,    26,    37, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   849
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,    26,    37, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   850
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,    26,    37, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   851
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,    27,    39, STR_0206_ARRIVAL_OF_FIRST_VEHICLE,     STR_NULL},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   853
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,    38,    49, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   854
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,    38,    49, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   855
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,    38,    49, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   856
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,    39,    51, STR_0207_ARRIVAL_OF_FIRST_VEHICLE,     STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   857
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   858
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,    50,    61, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   859
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,    50,    61, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   860
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,    50,    61, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   861
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,    51,    63, STR_0208_ACCIDENTS_DISASTERS,          STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   862
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   863
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,    62,    73, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   864
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,    62,    73, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   865
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,    62,    73, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   866
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,    63,    75, STR_0209_COMPANY_INFORMATION,          STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   867
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   868
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,    74,    85, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   869
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,    74,    85, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   870
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,    74,    85, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   871
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,    75,    87, STR_NEWS_OPEN_CLOSE,                   STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   872
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   873
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,    86,    97, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   874
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,    86,    97, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   875
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,    86,    97, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   876
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,    87,    99, STR_020A_ECONOMY_CHANGES,              STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   877
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   878
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,    98,   109, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   879
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,    98,   109, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   880
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,    98,   109, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   881
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,    99,   111, STR_020B_ADVICE_INFORMATION_ON_PLAYER, STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   882
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   883
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,   110,   121, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   884
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,   110,   121, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   885
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,   110,   121, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   886
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,   111,   123, STR_020C_NEW_VEHICLES,                 STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   887
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   888
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,   122,   133, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   889
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,   122,   133, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   890
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,   122,   133, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   891
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,   123,   135, STR_020D_CHANGES_OF_CARGO_ACCEPTANCE,  STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   892
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   893
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,   134,   145, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   894
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,   134,   145, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   895
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,   134,   145, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   896
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,   135,   147, STR_020E_SUBSIDIES,                    STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   897
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   898
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,     4,   12,   146,   157, SPR_ARROW_LEFT,                        STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   899
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     3,    13,   89,   146,   157, STR_EMPTY,                             STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   900
{ WWT_PUSHIMGBTN,   RESIZE_NONE,     3,    90,   98,   146,   157, SPR_ARROW_RIGHT,                       STR_HSCROLL_BAR_SCROLLS_LIST},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   901
{       WWT_TEXT,   RESIZE_NONE,     3,    103, 409,   147,   159, STR_020F_GENERAL_INFORMATION,          STR_NULL},
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   902
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 102
diff changeset
   903
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
static const WindowDesc _message_options_desc = {
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   907
	270, 22, 410, 197,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6090
diff changeset
   908
	WC_GAME_OPTIONS, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
	_message_options_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
	MessageOptionsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   914
void ShowMessageOptions()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
	DeleteWindowById(WC_GAME_OPTIONS, 0);
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   917
	BaseWindow::Allocate(&_message_options_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
}
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   919
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   920
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   921
void DeleteVehicleNews(VehicleID vid, StringID news)
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   922
{
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   923
	NewsID n;
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   924
5254
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   925
	for (n = _oldest_news; _latest_news != INVALID_NEWS; n = increaseIndex(n)) {
5245
5f1a514e8bfe (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   926
		const NewsItem *ni = &_news_items[n];
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   927
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   928
		if (ni->flags & NF_VEHICLE &&
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   929
				ni->data_a == vid &&
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   930
				(news == INVALID_STRING_ID || ni->string_id == news)) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   931
			BaseWindow *w;
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   932
5846
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   933
			/* If we delete a forced news and it is just before the current news
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   934
			 * then we need to advance to the next news (if any) */
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   935
			if (_forced_news == n) MoveToNextItem();
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   936
			if (_forced_news == INVALID_NEWS && _current_news == n) MoveToNextItem();
5254
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   937
			_total_news--;
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   938
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   939
			/* If this is the last news item, invalidate _latest_news */
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   940
			if (_total_news == 0) {
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   941
				assert(_latest_news == _oldest_news);
5254
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   942
				_latest_news = INVALID_NEWS;
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   943
			}
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   944
5254
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   945
			/* Since we only imitate a FIFO removing an arbitrary element does need
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   946
			 * some magic. Remove the item by shifting head towards the tail. eg
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   947
			 *    oldest    remove  last
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   948
			 *        |        |     |
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   949
			 * [------O--------n-----L--]
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   950
			 * will become (change dramatized to make clear)
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   951
			 * [---------O-----------L--]
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   952
			 * We also need an update of the current, forced and visible (open window)
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   953
			 * news's as this shifting could change the items they were pointing to */
5254
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   954
			if (_total_news != 0) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   955
				w = BaseWindow::FindById(WC_NEWS_WINDOW, 0);
5846
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   956
				NewsID visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS;
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   957
5846
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   958
				for (NewsID i = n;; i = decreaseIndex(i)) {
5246
29224c621fd6 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   959
					_news_items[i] = _news_items[decreaseIndex(i)];
5254
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   960
6090
21f2934dee5c (svn r8409) -Regression (r8049): When the latest news was deleted, the news queue wrapped back to the oldest item, showing all news again.
Darkvater
parents: 5919
diff changeset
   961
					if (i != _latest_news) {
21f2934dee5c (svn r8409) -Regression (r8049): When the latest news was deleted, the news queue wrapped back to the oldest item, showing all news again.
Darkvater
parents: 5919
diff changeset
   962
						if (i == _current_news) _current_news = increaseIndex(_current_news);
21f2934dee5c (svn r8409) -Regression (r8049): When the latest news was deleted, the news queue wrapped back to the oldest item, showing all news again.
Darkvater
parents: 5919
diff changeset
   963
						if (i == _forced_news) _forced_news = increaseIndex(_forced_news);
21f2934dee5c (svn r8409) -Regression (r8049): When the latest news was deleted, the news queue wrapped back to the oldest item, showing all news again.
Darkvater
parents: 5919
diff changeset
   964
						if (i == visible_news) WP(w, news_d).ni = &_news_items[increaseIndex(visible_news)];
21f2934dee5c (svn r8409) -Regression (r8049): When the latest news was deleted, the news queue wrapped back to the oldest item, showing all news again.
Darkvater
parents: 5919
diff changeset
   965
					}
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   966
5784
33ed39422ae6 (svn r7861) -Fix (r7823): Crash when oldest news was deleted. First check the index for oldest news
Darkvater
parents: 5771
diff changeset
   967
					if (i == _oldest_news) break;
33ed39422ae6 (svn r7861) -Fix (r7823): Crash when oldest news was deleted. First check the index for oldest news
Darkvater
parents: 5771
diff changeset
   968
				}
5244
e110f52333e8 (svn r7368) -Fix: [FS#332] Vehicle Deletion Crash [News Window Related?] (r3757).
Darkvater
parents: 5108
diff changeset
   969
				_oldest_news = increaseIndex(_oldest_news);
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   970
			}
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   971
5846
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   972
			/*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d",
55f4c68b7616 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5838
diff changeset
   973
			  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
5771
7288d4e4bfba (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5726
diff changeset
   974
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   975
			w = BaseWindow::FindById(WC_MESSAGE_HISTORY, 0);
3143
30fa7ff401f8 (svn r3761) Fix two bugs in r3757
tron
parents: 3140
diff changeset
   976
			if (w != NULL) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6144
diff changeset
   977
				w->SetDirty();
3143
30fa7ff401f8 (svn r3761) Fix two bugs in r3757
tron
parents: 3140
diff changeset
   978
				w->vscroll.count = _total_news;
30fa7ff401f8 (svn r3761) Fix two bugs in r3757
tron
parents: 3140
diff changeset
   979
			}
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   980
		}
5254
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   981
0cf8d2dcc848 (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   982
		if (n == _latest_news) break;
3139
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   983
	}
4c950c7ec5c9 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   984
}