src/news_gui.cpp
author peter1138
Wed, 28 May 2008 17:08:45 +0000
changeset 9402 4eb0f983b218
parent 9354 845e07db4549
child 9405 69c042fc13a4
permissions -rw-r--r--
(svn r13313) -Fix-ish (r13306): List was copied in another place the autoreplace gui...
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9094
diff changeset
     3
/** @file news_gui.cpp GUI functions related to news messages. */
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1688
diff changeset
     6
#include "openttd.h"
3155
c4673c936039 (svn r3778) - Fix crash when resizing news history window.
peter1138
parents: 3143
diff changeset
     7
#include "gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
     8
#include "window_gui.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8214
diff changeset
     9
#include "viewport_func.h"
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
    10
#include "news_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8268
diff changeset
    11
#include "settings_type.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7824
diff changeset
    12
#include "transparency.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
    13
#include "strings_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8121
diff changeset
    14
#include "window_func.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8131
diff changeset
    15
#include "date_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    16
#include "vehicle_base.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8144
diff changeset
    17
#include "sound_func.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8157
diff changeset
    18
#include "string_func.h"
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents: 8270
diff changeset
    19
#include "widgets/dropdown_func.h"
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
    20
#include "map_func.h"
9248
5c057d6b7e21 (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 9245
diff changeset
    21
#include "statusbar_gui.h"
9281
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    22
#include "player_face.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    24
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    25
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    26
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    27
/** @file news_gui.cpp
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    28
 *
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    29
 * News system is realized as a FIFO queue (in an array)
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    30
 * The positions in the queue can't be rearranged, we only access
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    31
 * the array elements through pointers to the elements. Once the
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    32
 * array is full, the oldest entry (\a _oldest_news) is being overwritten
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    33
 * by the newest (\a _latest_news).
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    34
 *
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    35
 * \verbatim
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    36
 * oldest                   current   lastest
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    37
 *  |                          |         |
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    38
 * [O------------F-------------C---------L           ]
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    39
 *               |
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    40
 *            forced
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    41
 * \endverbatim
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    42
 *
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    43
 * Of course by using an array we can have situations like
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    44
 *
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    45
 * \verbatim
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    46
 * [----L          O-----F---------C-----------------]
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    47
 * This is where we have wrapped around the array and have
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
    48
 * (MAX_NEWS - O) + L news items
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    49
 * \endverbatim
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
    50
 */
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    51
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
    52
#define NB_WIDG_PER_SETTING 4
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    53
5246
fb214a312549 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
    54
typedef byte NewsID;
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
    55
#define INVALID_NEWS 255
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    56
8268
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    57
NewsItem _statusbar_news_item;
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8268
diff changeset
    58
bool _news_ticker_sound;
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
    59
static NewsItem *_news_items = NULL;        ///< The news FIFO queue
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
    60
static uint _max_news_items = 0;            ///< size of news FIFO queue
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    61
static NewsID _current_news = INVALID_NEWS; ///< points to news item that should be shown next
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    62
static NewsID _oldest_news = 0;             ///< points to first item in fifo queue
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    63
static NewsID _latest_news = INVALID_NEWS;  ///< points to last item in fifo queue
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    64
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    65
/** Forced news item.
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    66
 * Users can force an item by accessing the history or "last message".
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    67
 * If the message being shown was forced by the user, its index is stored in
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
    68
 * _forced_news. Otherwise, \a _forced_news variable is INVALID_NEWS. */
5246
fb214a312549 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
    69
static NewsID _forced_news = INVALID_NEWS;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
    70
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
    71
static uint _total_news = 0; ///< Number of news items in FIFO queue @see _news_items
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
    72
static void MoveToNextItem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
    74
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
    75
typedef void DrawNewsCallbackProc(struct Window *w, const NewsItem *ni);
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
    76
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni);
9281
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    77
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    78
static void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    79
{
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    80
	Player *p = GetPlayer((PlayerID)(ni->data_b));
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    81
	DrawPlayerFace(p->face, p->player_color, 2, 23);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    82
	GfxFillRect(3, 23, 3 + 91, 23 + 118, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    83
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    84
	SetDParam(0, p->index);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    85
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    86
	DrawStringMultiCenter(49, 148, STR_7058_PRESIDENT, 94);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    87
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    88
	switch (ni->subtype) {
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    89
		case NS_COMPANY_TROUBLE:
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    90
			DrawStringCentered(w->width >> 1, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, TC_FROMSTRING);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    91
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    92
			SetDParam(0, p->index);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    93
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    94
			DrawStringMultiCenter(
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    95
				((w->width - 101) >> 1) + 98,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    96
				90,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    97
				STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    98
				w->width - 101);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
    99
			break;
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   100
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   101
		case NS_COMPANY_MERGER:
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   102
			DrawStringCentered(w->width >> 1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, TC_FROMSTRING);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   103
			SetDParam(0, ni->params[2]);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   104
			SetDParam(1, p->index);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   105
			SetDParam(2, ni->params[4]);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   106
			DrawStringMultiCenter(
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   107
				((w->width - 101) >> 1) + 98,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   108
				90,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   109
				ni->params[4] == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   110
				w->width - 101);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   111
			break;
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   112
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   113
		case NS_COMPANY_BANKRUPT:
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   114
			DrawStringCentered(w->width >> 1, 1, STR_705C_BANKRUPT, TC_FROMSTRING);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   115
			SetDParam(0, p->index);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   116
			DrawStringMultiCenter(
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   117
				((w->width - 101) >> 1) + 98,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   118
				90,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   119
				STR_705D_HAS_BEEN_CLOSED_DOWN_BY,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   120
				w->width - 101);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   121
			break;
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   122
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   123
		case NS_COMPANY_NEW:
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   124
			DrawStringCentered(w->width >> 1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, TC_FROMSTRING);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   125
			SetDParam(0, p->index);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   126
			SetDParam(1, ni->params[3]);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   127
			DrawStringMultiCenter(
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   128
				((w->width - 101) >> 1) + 98,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   129
				90,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   130
				STR_705F_STARTS_CONSTRUCTION_NEAR,
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   131
				w->width - 101);
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   132
			break;
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   133
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   134
		default:
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   135
			NOT_REACHED();
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   136
	}
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   137
}
18200114be76 (svn r13147) -Codechange: move the code to draw bankruptcy news to news_gui.cpp.
rubidium
parents: 9273
diff changeset
   138
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   140
/**
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   141
 * Data common to all news items of a given subtype (structure)
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   142
 */
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   143
struct NewsSubtypeData {
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   144
	NewsType type;         ///< News category @see NewsType
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   145
	NewsMode display_mode; ///< Display mode value @see NewsMode
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   146
	NewsFlag flags;        ///< Initial NewsFlags bits @see NewsFlag
9313
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   147
	DrawNewsCallbackProc *callback; ///< Call-back function
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   148
};
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   149
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   150
/**
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   151
 * Data common to all news items of a given subtype (actual data)
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   152
 */
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   153
static const struct NewsSubtypeData _news_subtype_data[NS_END] = {
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   154
	/* type,             display_mode, flags,                  callback */
9313
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   155
	{ NT_ARRIVAL_PLAYER,  NM_THIN,     NF_VIEWPORT|NF_VEHICLE, NULL                    }, ///< NS_ARRIVAL_PLAYER
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   156
	{ NT_ARRIVAL_OTHER,   NM_THIN,     NF_VIEWPORT|NF_VEHICLE, NULL                    }, ///< NS_ARRIVAL_OTHER
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   157
	{ NT_ACCIDENT,        NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_ACCIDENT_TILE
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   158
	{ NT_ACCIDENT,        NM_THIN,     NF_VIEWPORT|NF_VEHICLE, NULL                    }, ///< NS_ACCIDENT_VEHICLE
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   159
	{ NT_COMPANY_INFO,    NM_CALLBACK, NF_NONE,                DrawNewsBankrupcy       }, ///< NS_COMPANY_TROUBLE
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   160
	{ NT_COMPANY_INFO,    NM_CALLBACK, NF_NONE,                DrawNewsBankrupcy       }, ///< NS_COMPANY_MERGER
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   161
	{ NT_COMPANY_INFO,    NM_CALLBACK, NF_NONE,                DrawNewsBankrupcy       }, ///< NS_COMPANY_BANKRUPT
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   162
	{ NT_COMPANY_INFO,    NM_CALLBACK, NF_TILE,                DrawNewsBankrupcy       }, ///< NS_COMPANY_NEW
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   163
	{ NT_OPENCLOSE,       NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_OPENCLOSE
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   164
	{ NT_ECONOMY,         NM_NORMAL,   NF_NONE,                NULL                    }, ///< NS_ECONOMY
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   165
	{ NT_INDUSTRY_PLAYER, NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_INDUSTRY_PLAYER
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   166
	{ NT_INDUSTRY_OTHER,  NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_INDUSTRY_OTHER
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   167
	{ NT_INDUSTRY_NOBODY, NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_INDUSTRY_NOBODY
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   168
	{ NT_ADVICE,          NM_SMALL,    NF_VIEWPORT|NF_VEHICLE, NULL                    }, ///< NS_ADVICE
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   169
	{ NT_NEW_VEHICLES,    NM_CALLBACK, NF_NONE,                DrawNewsNewVehicleAvail }, ///< NS_NEW_VEHICLES
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   170
	{ NT_ACCEPTANCE,      NM_SMALL,    NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_ACCEPTANCE
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   171
	{ NT_SUBSIDIES,       NM_NORMAL,   NF_TILE|NF_TILE2,       NULL                    }, ///< NS_SUBSIDIES
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   172
	{ NT_GENERAL,         NM_NORMAL,   NF_TILE,                NULL                    }, ///< NS_GENERAL
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   173
};
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   174
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   175
/** Initialize the news-items data structures */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   176
void InitNewsItemStructs()
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   177
{
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   178
	free(_news_items);
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   179
	_max_news_items = max(ScaleByMapSize(30), 30U);
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   180
	_news_items = CallocT<NewsItem>(_max_news_items);
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   181
	_current_news = INVALID_NEWS;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   182
	_oldest_news = 0;
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   183
	_latest_news = INVALID_NEWS;
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   184
	_forced_news = INVALID_NEWS;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   185
	_total_news = 0;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   186
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   188
struct NewsWindow : Window {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   189
	uint16 chat_height;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   190
	NewsItem *ni;
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   191
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   192
	NewsWindow(const WindowDesc *desc, NewsItem *ni) : Window(desc), ni(ni)
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   193
	{
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   194
		const Window *w = FindWindowById(WC_SEND_NETWORK_MSG, 0);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   195
		this->chat_height = (w != NULL) ? w->height : 0;
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   196
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   197
		this->ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news];
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   198
		this->flags4 |= WF_DISABLE_VP_SCROLL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   200
		this->FindWindowPlacementAndResize(desc);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   201
	}
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   202
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   203
	void DrawNewsBorder()
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   204
	{
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   205
		int left = 0;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   206
		int right = this->width - 1;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   207
		int top = 0;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   208
		int bottom = this->height - 1;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   209
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   210
		GfxFillRect(left, top, right, bottom, 0xF);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   211
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   212
		GfxFillRect(left, top, left, bottom, 0xD7);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   213
		GfxFillRect(right, top, right, bottom, 0xD7);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   214
		GfxFillRect(left, top, right, top, 0xD7);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   215
		GfxFillRect(left, bottom, right, bottom, 0xD7);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   216
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   217
		DrawString(left + 2, top + 1, STR_00C6, TC_FROMSTRING);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   218
	}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   219
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   220
	virtual void OnPaint()
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   221
	{
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   222
		const NewsMode display_mode = _news_subtype_data[this->ni->subtype].display_mode;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   223
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   224
		switch (display_mode) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   225
			case NM_NORMAL:
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   226
			case NM_THIN: {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   227
				this->DrawNewsBorder();
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   228
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   229
				DrawString(2, 1, STR_00C6, TC_FROMSTRING);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   230
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   231
				SetDParam(0, this->ni->date);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   232
				DrawStringRightAligned(428, 1, STR_01FF, TC_FROMSTRING);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   233
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   234
				if (!(this->ni->flags & NF_VIEWPORT)) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   235
					CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   236
					DrawStringMultiCenter(215, display_mode == NM_NORMAL ? 76 : 56,
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   237
						this->ni->string_id, this->width - 4);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   238
				} else {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   239
					/* Back up transparency options to draw news view */
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   240
					TransparencyOptionBits to_backup = _transparency_opt;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   241
					_transparency_opt = 0;
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9249
diff changeset
   242
					this->DrawViewport();
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   243
					_transparency_opt = to_backup;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   244
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   245
					/* Shade the viewport into gray, or color*/
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   246
					ViewPort *vp = this->viewport;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   247
					GfxFillRect(vp->left - this->left, vp->top - this->top,
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   248
						vp->left - this->left + vp->width - 1, vp->top - this->top + vp->height - 1,
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   249
						(this->ni->flags & NF_INCOLOR ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY) | (1 << USE_COLORTABLE)
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   250
					);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   251
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   252
					CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   253
					DrawStringMultiCenter(this->width / 2, 20, this->ni->string_id, this->width - 4);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   254
				}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   255
				break;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   256
			}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   257
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   258
			case NM_CALLBACK:
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   259
				this->DrawNewsBorder();
9313
11c910ed6d40 (svn r13181) -Codechange: make news callback handling a little simpler. Patch by Cirdan.
rubidium
parents: 9288
diff changeset
   260
				(_news_subtype_data[this->ni->subtype].callback)(this, ni);
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   261
				break;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   262
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   263
			default:
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9249
diff changeset
   264
				this->DrawWidgets();
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   265
				if (!(this->ni->flags & NF_VIEWPORT)) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   266
					CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   267
					DrawStringMultiCenter(140, 38, this->ni->string_id, 276);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   268
				} else {
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9249
diff changeset
   269
					this->DrawViewport();
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   270
					CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   271
					DrawStringMultiCenter(this->width / 2, this->height - 16, this->ni->string_id, this->width - 4);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   272
				}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   273
				break;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   274
		}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   275
	}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   276
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   277
	virtual void OnClick(Point pt, int widget)
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   278
	{
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   279
		switch (widget) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   280
			case 1:
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   281
				this->ni->duration = 0;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   282
				delete this;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   283
				_forced_news = INVALID_NEWS;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   284
				break;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   285
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   286
			case 0:
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   287
				if (this->ni->flags & NF_VEHICLE) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   288
					Vehicle *v = GetVehicle(this->ni->data_a);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   289
					ScrollMainWindowTo(v->x_pos, v->y_pos);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   290
				} else if (this->ni->flags & NF_TILE) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   291
					if (_ctrl_pressed) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   292
						ShowExtraViewPortWindow(this->ni->data_a);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   293
						if (this->ni->flags & NF_TILE2) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   294
							ShowExtraViewPortWindow(this->ni->data_b);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   295
						}
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   296
					} else {
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   297
						if (!ScrollMainWindowToTile(this->ni->data_a) && this->ni->flags & NF_TILE2) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   298
							ScrollMainWindowToTile(this->ni->data_b);
9093
0ba1a30d757b (svn r12952) -Cleanup: Indenting and codestyle
peter1138
parents: 9026
diff changeset
   299
						}
0ba1a30d757b (svn r12952) -Cleanup: Indenting and codestyle
peter1138
parents: 9026
diff changeset
   300
					}
0ba1a30d757b (svn r12952) -Cleanup: Indenting and codestyle
peter1138
parents: 9026
diff changeset
   301
				}
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   302
				break;
9093
0ba1a30d757b (svn r12952) -Cleanup: Indenting and codestyle
peter1138
parents: 9026
diff changeset
   303
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	}
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   305
9285
235e5e2d7f55 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 9281
diff changeset
   306
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   307
	{
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   308
		if (keycode == WKC_SPACE) {
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   309
			/* Don't continue. */
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   310
			delete this;
9285
235e5e2d7f55 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 9281
diff changeset
   311
			return ES_HANDLED;
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   312
		}
9285
235e5e2d7f55 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 9281
diff changeset
   313
		return ES_NOT_HANDLED;
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   314
	}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   315
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   316
	virtual void OnInvalidateData(int data)
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   317
	{
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   318
		/* The chatbar has notified us that is was either created or closed */
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   319
		this->chat_height = data;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   320
	}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   321
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   322
	virtual void OnTick()
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   323
	{
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   324
		/* Scroll up newsmessages from the bottom in steps of 4 pixels */
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   325
		int y = max(this->top - 4, _screen.height - this->height - 12 - this->chat_height);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   326
		if (y == this->top) return;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   327
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   328
		if (this->viewport != NULL) this->viewport->top += y - this->top;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   329
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   330
		int diff = Delta(this->top, y);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   331
		this->top = y;
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   332
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   333
		SetDirtyBlocks(this->left, this->top - diff, this->left + this->width, this->top + this->height);
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   334
	}
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   335
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   337
/**
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   338
 * Return the correct index in the pseudo-fifo
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   339
 * queue and deals with overflows when increasing the index
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   340
 */
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   341
static inline NewsID IncreaseIndex(NewsID i)
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   342
{
5258
28d07c40ea82 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   343
	assert(i != INVALID_NEWS);
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   344
	return (i + 1) % _max_news_items;
5245
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   345
}
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   346
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   347
/**
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   348
 * Return the correct index in the pseudo-fifo
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   349
 * queue and deals with overflows when decreasing the index
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   350
 */
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   351
static inline NewsID DecreaseIndex(NewsID i)
5245
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   352
{
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   353
	assert(i != INVALID_NEWS);
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   354
	return (i + _max_news_items - 1) % _max_news_items;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   355
}
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   356
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   357
/**
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   358
 * Add a new newsitem to be shown.
9245
cd9305c986e4 (svn r13111) -Documentation: update the documentation of AddNewsItem to reflect reality. Patch by Cirdan.
rubidium
parents: 9236
diff changeset
   359
 * @param string String to display
cd9305c986e4 (svn r13111) -Documentation: update the documentation of AddNewsItem to reflect reality. Patch by Cirdan.
rubidium
parents: 9236
diff changeset
   360
 * @param subtype news category, any of the NewsSubtype enums (NS_)
4873
11880cbbc9f6 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   361
 * @param data_a news-specific value based on news type
11880cbbc9f6 (svn r6803) -Codechange: Substitute magic numbers by an enum for the news windows
Darkvater
parents: 4719
diff changeset
   362
 * @param data_b news-specific value based on news type
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   363
 *
9245
cd9305c986e4 (svn r13111) -Documentation: update the documentation of AddNewsItem to reflect reality. Patch by Cirdan.
rubidium
parents: 9236
diff changeset
   364
 * @see NewsSubype
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   365
 */
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   366
void AddNewsItem(StringID string, NewsSubtype subtype, uint data_a, uint data_b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
{
4000
4009d092b306 (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
   368
	if (_game_mode == GM_MENU) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   370
	/* check the rare case that the oldest (to be overwritten) news item is open */
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   371
	if (_total_news == _max_news_items && (_oldest_news == _current_news || _oldest_news == _forced_news)) {
5253
ff50454e0604 (svn r7383) -Codechange: fix up typo in news-gui s/MoveToNexItem/MoveToNextItem/.
Darkvater
parents: 5246
diff changeset
   372
		MoveToNextItem();
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   373
	}
102
1d277a07f1f1 (svn r103) Fix: rare newspaper crash with too many messages [ 1009976 ] (thx to blathij)s
dominik
parents: 94
diff changeset
   374
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   375
	if (_total_news < _max_news_items) _total_news++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   376
5258
28d07c40ea82 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   377
	/* Increase _latest_news. If we have no news yet, use _oldest news as an
28d07c40ea82 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   378
	 * index. We cannot use 0 as _oldest_news can jump around due to
28d07c40ea82 (svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
Darkvater
parents: 5254
diff changeset
   379
	 * DeleteVehicleNews */
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   380
	NewsID l_news = _latest_news;
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   381
	_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
   382
5244
af95451c3b88 (svn r7368) -Fix: [FS#332] Vehicle Deletion Crash [News Window Related?] (r3757).
Darkvater
parents: 5108
diff changeset
   383
	/* If the fifo-buffer is full, overwrite the oldest entry */
5245
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   384
	if (l_news != INVALID_NEWS && _latest_news == _oldest_news) {
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   385
		assert(_total_news == _max_news_items);
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   386
		_oldest_news = IncreaseIndex(_oldest_news);
5245
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   387
	}
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   388
5595
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   389
	/*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d",
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   390
	  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
5520
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
   391
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   392
	/* Add news to _latest_news */
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   393
	NewsItem *ni = &_news_items[_latest_news];
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   394
	memset(ni, 0, sizeof(*ni));
5245
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   395
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   396
	ni->string_id = string;
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   397
	ni->subtype = subtype;
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   398
	ni->flags = _news_subtype_data[subtype].flags;
5245
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   399
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   400
	/* show this news message in color? */
9354
845e07db4549 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 9333
diff changeset
   401
	if (_cur_year >= _settings.gui.colored_news_year) ni->flags |= NF_INCOLOR;
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   402
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   403
	ni->data_a = data_a;
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   404
	ni->data_b = data_b;
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   405
	ni->date = _date;
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   406
	CopyOutDParam(ni->params, 0, lengthof(ni->params));
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   407
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   408
	Window *w = FindWindowById(WC_MESSAGE_HISTORY, 0);
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   409
	if (w == NULL) return;
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
   410
	w->SetDirty();
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8343
diff changeset
   411
	w->vscroll.count = _total_news;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
715
28dd55cc55ae (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
   414
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   415
/**
8990
0d5bb1c2a4a6 (svn r12785) -Codechange: put all news-type related constants in the same array. Patch by cirdan.
rubidium
parents: 8970
diff changeset
   416
 * Per-NewsType data
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   417
 */
9010
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   418
NewsTypeData _news_type_data[NT_END] = {
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   419
	/* name,              age, sound,           display */
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   420
	{ "arrival_player",    60, SND_1D_APPLAUSE, ND_FULL },  ///< NT_ARRIVAL_PLAYER
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   421
	{ "arrival_other",     60, SND_1D_APPLAUSE, ND_FULL },  ///< NT_ARRIVAL_OTHER
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   422
	{ "accident",          90, SND_BEGIN,       ND_FULL },  ///< NT_ACCIDENT
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   423
	{ "company_info",      60, SND_BEGIN,       ND_FULL },  ///< NT_COMPANY_INFO
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   424
	{ "openclose",         90, SND_BEGIN,       ND_FULL },  ///< NT_OPENCLOSE
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   425
	{ "economy",           30, SND_BEGIN,       ND_FULL },  ///< NT_ECONOMY
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   426
	{ "production_player", 30, SND_BEGIN,       ND_FULL },  ///< NT_INDUSTRY_PLAYER
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   427
	{ "production_other",  30, SND_BEGIN,       ND_FULL },  ///< NT_INDUSTRY_OTHER
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   428
	{ "production_nobody", 30, SND_BEGIN,       ND_FULL },  ///< NT_INDUSTRY_NOBODY
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   429
	{ "advice",           150, SND_BEGIN,       ND_FULL },  ///< NT_ADVICE
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   430
	{ "new_vehicles",      30, SND_1E_OOOOH,    ND_FULL },  ///< NT_NEW_VEHICLES
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   431
	{ "acceptance",        90, SND_BEGIN,       ND_FULL },  ///< NT_ACCEPTANCE
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   432
	{ "subsidies",        180, SND_BEGIN,       ND_FULL },  ///< NT_SUBSIDIES
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   433
	{ "general",           60, SND_BEGIN,       ND_FULL },  ///< NT_GENERAL
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   434
};
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   435
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
static const Widget _news_type13_widgets[] = {
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 745
diff changeset
   438
{      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   169, 0x0, STR_NULL},
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 745
diff changeset
   439
{      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
   440
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
static WindowDesc _news_type13_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   444
	WDP_CENTER, 476, 430, 170, 430, 170,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5839
diff changeset
   445
	WC_NEWS_WINDOW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
	_news_type13_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
static const Widget _news_type2_widgets[] = {
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 745
diff changeset
   451
{      WWT_PANEL,   RESIZE_NONE,    15,     0,   429,     0,   129, 0x0, STR_NULL},
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 745
diff changeset
   452
{      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
   453
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
static WindowDesc _news_type2_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   457
	WDP_CENTER, 476, 430, 130, 430, 130,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5839
diff changeset
   458
	WC_NEWS_WINDOW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
	_news_type2_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
static const Widget _news_type0_widgets[] = {
4344
7e123fec5b0b (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
   464
{      WWT_PANEL,   RESIZE_NONE,     5,     0,   279,    14,    86, 0x0,              STR_NULL},
7e123fec5b0b (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
   465
{   WWT_CLOSEBOX,   RESIZE_NONE,     5,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
7e123fec5b0b (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
   466
{    WWT_CAPTION,   RESIZE_NONE,     5,    11,   279,     0,    13, STR_012C_MESSAGE, STR_NULL},
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   467
{      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
   468
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
static WindowDesc _news_type0_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   472
	WDP_CENTER, 476, 280, 87, 280, 87,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5839
diff changeset
   473
	WC_NEWS_WINDOW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
	WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
	_news_type0_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   479
/** 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
   480
static void ShowNewspaper(NewsItem *ni)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
{
4874
afafed841c6d (svn r6804) -Codechange: Remove the unused NF_NOEXPIRE flag.
Darkvater
parents: 4873
diff changeset
   482
	ni->flags &= ~NF_FORCE_BIG;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   483
	ni->duration = 555;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   485
	SoundFx sound = _news_type_data[_news_subtype_data[ni->subtype].type].sound;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   486
	if (sound != 0) SndPlayFx(sound);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   487
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   488
	int top = _screen.height;
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   489
	Window *w;
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   490
	switch (_news_subtype_data[ni->subtype].display_mode) {
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   491
		case NM_NORMAL:
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   492
		case NM_CALLBACK:
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   493
			_news_type13_desc.top = top;
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   494
			w = new NewsWindow(&_news_type13_desc, ni);
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   495
			if (ni->flags & NF_VIEWPORT) {
8994
fb5e761cf141 (svn r12789) -Codechange: rename AssignWindowViewport to InitializeWindowViewport because the viewport is now part of the window struct. Patch by Alberth.
rubidium
parents: 8990
diff changeset
   496
				InitializeWindowViewport(w, 2, 58, 426, 110,
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6542
diff changeset
   497
					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   498
			}
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   499
			break;
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   500
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   501
		case NM_THIN:
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   502
			_news_type2_desc.top = top;
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   503
			w = new NewsWindow(&_news_type2_desc, ni);
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   504
			if (ni->flags & NF_VIEWPORT) {
8994
fb5e761cf141 (svn r12789) -Codechange: rename AssignWindowViewport to InitializeWindowViewport because the viewport is now part of the window struct. Patch by Alberth.
rubidium
parents: 8990
diff changeset
   505
				InitializeWindowViewport(w, 2, 58, 426, 70,
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6542
diff changeset
   506
					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   507
			}
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   508
			break;
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   509
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   510
		default:
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   511
			_news_type0_desc.top = top;
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
   512
			w = new NewsWindow(&_news_type0_desc, ni);
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   513
			if (ni->flags & NF_VIEWPORT) {
8994
fb5e761cf141 (svn r12789) -Codechange: rename AssignWindowViewport to InitializeWindowViewport because the viewport is now part of the window struct. Patch by Alberth.
rubidium
parents: 8990
diff changeset
   514
				InitializeWindowViewport(w, 3, 17, 274, 47,
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6542
diff changeset
   515
					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   516
			}
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   517
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
	}
5520
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
   519
5595
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   520
	/*DEBUG(misc, 0, " cur %3d, old %2d, lat %3d, for %3d, tot %2d",
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   521
	  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   522
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   524
/** Show news item in the ticker */
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   525
static void ShowTicker(const NewsItem *ni)
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   526
{
1688
af2bb9bcb2ed (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
   527
	if (_news_ticker_sound) SndPlayFx(SND_16_MORSE);
af2bb9bcb2ed (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
   528
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   529
	_statusbar_news_item = *ni;
9248
5c057d6b7e21 (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 9245
diff changeset
   530
	InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   531
}
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   532
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   533
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   534
/**
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   535
 * Are we ready to show another news item?
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   536
 * Only if nothing is in the newsticker and no newspaper is displayed
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   537
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   538
static bool ReadyForNextItem()
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   539
{
5246
fb214a312549 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   540
	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
   541
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   542
	if (item >= _max_news_items) return true;
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   543
	NewsItem *ni = &_news_items[item];
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   544
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   545
	/* Ticker message
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   546
	 * Check if the status bar message is still being displayed? */
9248
5c057d6b7e21 (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 9245
diff changeset
   547
	if (IsNewsTickerShown()) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   549
	/* Newspaper message, decrement duration counter */
5264
1e3cd1ed1ee6 (svn r7402) -Fix: [FS#255] Long Delay for Message Windows to Appear. Immediately show a new message
Darkvater
parents: 5258
diff changeset
   550
	if (ni->duration != 0) ni->duration--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   552
	/* neither newsticker nor newspaper are running */
5264
1e3cd1ed1ee6 (svn r7402) -Fix: [FS#255] Long Delay for Message Windows to Appear. Immediately show a new message
Darkvater
parents: 5258
diff changeset
   553
	return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   554
}
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   555
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   556
/** Move to the next news item */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   557
static void MoveToNextItem()
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   558
{
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   559
	DeleteWindowById(WC_NEWS_WINDOW, 0);
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   560
	_forced_news = INVALID_NEWS;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   561
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   562
	/* if we're not at the last item, then move on */
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   563
	if (_current_news != _latest_news) {
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   564
		_current_news = (_current_news == INVALID_NEWS) ? _oldest_news : IncreaseIndex(_current_news);
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   565
		NewsItem *ni = &_news_items[_current_news];
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   566
		const NewsType type = _news_subtype_data[ni->subtype].type;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   567
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   568
		/* check the date, don't show too old items */
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   569
		if (_date - _news_type_data[type].age > ni->date) return;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   570
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9199
diff changeset
   571
		switch (_news_type_data[type].display) {
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   572
			default: NOT_REACHED();
9248
5c057d6b7e21 (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 9245
diff changeset
   573
			case ND_OFF: // Off - show nothing only a small reminder in the status bar
5c057d6b7e21 (svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
rubidium
parents: 9245
diff changeset
   574
				InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   575
				break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   576
9010
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   577
			case ND_SUMMARY: // Summary - show ticker, but if forced big, cascade to full
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   578
				if (!(ni->flags & NF_FORCE_BIG)) {
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   579
					ShowTicker(ni);
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   580
					break;
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   581
				}
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   582
				/* Fallthrough */
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   583
9010
fa1aa6008a59 (svn r12805) -Codechange: remove some bit magic related to the news display states. Patch by cirdan.
rubidium
parents: 8994
diff changeset
   584
			case ND_FULL: // Full - show newspaper
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   585
				ShowNewspaper(ni);
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   586
				break;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   587
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
	}
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   589
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   591
void NewsLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
{
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   593
	/* no news item yet */
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   594
	if (_total_news == 0) return;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   595
5253
ff50454e0604 (svn r7383) -Codechange: fix up typo in news-gui s/MoveToNexItem/MoveToNextItem/.
Darkvater
parents: 5246
diff changeset
   596
	if (ReadyForNextItem()) MoveToNextItem();
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   597
}
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   598
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   599
/** Do a forced show of a specific message */
5246
fb214a312549 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   600
static void ShowNewsMessage(NewsID i)
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   601
{
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   602
	if (_total_news == 0) return;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   603
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   604
	/* Delete the news window */
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   605
	DeleteWindowById(WC_NEWS_WINDOW, 0);
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   606
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6302
diff changeset
   607
	/* setup forced news item */
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   608
	_forced_news = i;
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   609
427
1f488221b3d9 (svn r626) Merge r438 to trunk:
tron
parents: 337
diff changeset
   610
	if (_forced_news != INVALID_NEWS) {
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   611
		NewsItem *ni = &_news_items[_forced_news];
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   612
		ni->duration = 555;
4874
afafed841c6d (svn r6804) -Codechange: Remove the unused NF_NOEXPIRE flag.
Darkvater
parents: 4873
diff changeset
   613
		ni->flags |= NF_FORCE_BIG;
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   614
		DeleteWindowById(WC_NEWS_WINDOW, 0);
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   615
		ShowNewspaper(ni);
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   616
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   619
/** Show previous news item */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   620
void ShowLastNewsMessage()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
{
5595
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   622
	if (_forced_news == INVALID_NEWS) {
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   623
		/* Not forced any news yet, show the current one, unless a news window is
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   624
		 * open (which can only be the current one), then show the previous item */
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   625
		const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   626
		ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : DecreaseIndex(_current_news));
5595
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   627
	} else if (_forced_news == _oldest_news) {
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   628
		/* We have reached the oldest news, start anew with the latest */
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   629
		ShowNewsMessage(_latest_news);
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   630
	} else {
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   631
		/* 'Scrolling' through news history show each one in turn */
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   632
		ShowNewsMessage(DecreaseIndex(_forced_news));
83
bd21afea96d8 (svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents: 80
diff changeset
   633
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
79
15e3eef5f73d (svn r80) New internal news system (implemented with fifo queue)
dominik
parents: 0
diff changeset
   636
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   637
/* return news by number, with 0 being the most
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4345
diff changeset
   638
 * recent news. Returns INVALID_NEWS if end of queue reached. */
5246
fb214a312549 (svn r7370) -Cleanup: Use NewsID instead of byte for news identifiers, and some minor other things
Darkvater
parents: 5245
diff changeset
   639
static NewsID getNews(NewsID i)
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   640
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   641
	if (i >= _total_news) return INVALID_NEWS;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   642
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   643
	if (_latest_news < i) {
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   644
		i = _latest_news + _max_news_items - i;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   645
	} else {
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   646
		i = _latest_news - i;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   647
	}
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   648
9026
690846c6ee99 (svn r12842) -Codechange [FS#1604]: scale message history by map size
glx
parents: 9010
diff changeset
   649
	i %= _max_news_items;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   650
	return i;
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   651
}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   652
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   653
/**
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   654
 * Draw an unformatted news message truncated to a maximum length. If
2101
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   655
 * length exceeds maximum length it will be postfixed by '...'
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   656
 * @param x,y position of the string
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   657
 * @param color the color the string will be shown in
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   658
 * @param *ni NewsItem being printed
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   659
 * @param maxw maximum width of string in pixels
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   660
 */
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   661
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
   662
{
2101
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   663
	char buffer[512], buffer2[512];
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   664
	StringID str;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   665
9199
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9184
diff changeset
   666
	CopyInDParam(0, ni->params, lengthof(ni->params));
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9184
diff changeset
   667
	str = ni->string_id;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   668
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4874
diff changeset
   669
	GetString(buffer, str, lastof(buffer));
2101
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   670
	/* Copy the just gotten string to another buffer to remove any formatting
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   671
	 * from it such as big fonts, etc. */
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   672
	const char *ptr = buffer;
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   673
	char *dest = buffer2;
6542
47e288403035 (svn r9731) -Fix [FS#677]: in news history, newlines weren't replaced with spaces, making it look ugly from time to time
truelight
parents: 6481
diff changeset
   674
	WChar c_last = '\0';
5108
aeaef6fe53b7 (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
   675
	for (;;) {
aeaef6fe53b7 (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
   676
		WChar c = Utf8Consume(&ptr);
aeaef6fe53b7 (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
   677
		if (c == 0) break;
6542
47e288403035 (svn r9731) -Fix [FS#677]: in news history, newlines weren't replaced with spaces, making it look ugly from time to time
truelight
parents: 6481
diff changeset
   678
		/* Make a space from a newline, but ignore multiple newlines */
47e288403035 (svn r9731) -Fix [FS#677]: in news history, newlines weren't replaced with spaces, making it look ugly from time to time
truelight
parents: 6481
diff changeset
   679
		if (c == '\n' && c_last != '\n') {
47e288403035 (svn r9731) -Fix [FS#677]: in news history, newlines weren't replaced with spaces, making it look ugly from time to time
truelight
parents: 6481
diff changeset
   680
			dest[0] = ' ';
47e288403035 (svn r9731) -Fix [FS#677]: in news history, newlines weren't replaced with spaces, making it look ugly from time to time
truelight
parents: 6481
diff changeset
   681
			dest++;
47e288403035 (svn r9731) -Fix [FS#677]: in news history, newlines weren't replaced with spaces, making it look ugly from time to time
truelight
parents: 6481
diff changeset
   682
		} else if (c == '\r') {
2101
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   683
			dest[0] = dest[1] = dest[2] = dest[3] = ' ';
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   684
			dest += 4;
5108
aeaef6fe53b7 (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
   685
		} else if (IsPrintable(c)) {
aeaef6fe53b7 (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
   686
			dest += Utf8Encode(dest, c);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   687
		}
6542
47e288403035 (svn r9731) -Fix [FS#677]: in news history, newlines weren't replaced with spaces, making it look ugly from time to time
truelight
parents: 6481
diff changeset
   688
		c_last = c;
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   689
	}
2101
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   690
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   691
	*dest = '\0';
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   692
	/* Truncate and show string; postfixed by '...' if neccessary */
822f0b48ce64 (svn r2611) - CodeChange: use standardized truncutation with the newsmessage-history window as well
Darkvater
parents: 1959
diff changeset
   693
	DoDrawStringTruncated(buffer2, x, y, color, maxw);
89
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
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   696
9288
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   697
struct MessageHistoryWindow : Window {
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   698
	MessageHistoryWindow(const WindowDesc *desc) : Window(desc)
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   699
	{
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   700
		this->vscroll.cap = 10;
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   701
		this->vscroll.count = _total_news;
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   702
		this->resize.step_height = 12;
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   703
		this->resize.height = this->height - 12 * 6; // minimum of 4 items in the list, each item 12 high
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   704
		this->resize.step_width = 1;
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   705
		this->resize.width = 200; // can't make window any smaller than 200 pixel
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   706
9288
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   707
		this->FindWindowPlacementAndResize(desc);
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   708
	}
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   709
9288
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   710
	virtual void OnPaint()
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   711
	{
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   712
		int y = 19;
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   713
9288
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   714
		SetVScrollCount(this, _total_news);
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   715
		this->DrawWidgets();
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   716
9288
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   717
		if (_total_news == 0) return;
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   718
		NewsID show = min(_total_news, this->vscroll.cap);
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   719
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   720
		for (NewsID p = this->vscroll.pos; p < this->vscroll.pos + show; p++) {
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   721
			/* get news in correct order */
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   722
			const NewsItem *ni = &_news_items[getNews(p)];
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   723
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   724
			SetDParam(0, ni->date);
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   725
			DrawString(4, y, STR_SHORT_DATE, TC_WHITE);
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   726
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   727
			DrawNewsString(82, y, TC_WHITE, ni, this->width - 95);
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   728
			y += 12;
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   729
		}
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   730
	}
9288
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   731
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   732
	virtual void OnClick(Point pt, int widget)
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   733
	{
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   734
		if (widget == 3) {
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   735
			int y = (pt.y - 19) / 12;
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   736
			NewsID p = getNews(y + this->vscroll.pos);
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   737
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   738
			if (p != INVALID_NEWS) ShowNewsMessage(p);
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   739
		}
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   740
	}
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   741
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   742
	virtual void OnResize(Point new_size, Point delta)
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   743
	{
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   744
		this->vscroll.cap += delta.y / 12;
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   745
	}
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   746
};
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   747
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   748
static const Widget _message_history_widgets[] = {
4344
7e123fec5b0b (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
   749
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,            STR_018B_CLOSE_WINDOW},
7e123fec5b0b (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
   750
{    WWT_CAPTION,  RESIZE_RIGHT,    13,    11,   387,     0,    13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (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
   751
{  WWT_STICKYBOX,     RESIZE_LR,    13,   388,   399,     0,    13, 0x0,                 STR_STICKY_BUTTON},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   752
{      WWT_PANEL,     RESIZE_RB,    13,     0,   387,    14,   139, 0x0,                 STR_MESSAGE_HISTORY_TIP},
4344
7e123fec5b0b (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
   753
{  WWT_SCROLLBAR,    RESIZE_LRB,    13,   388,   399,    14,   127, 0x0,                 STR_0190_SCROLL_BAR_SCROLLS_LIST},
7e123fec5b0b (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
   754
{  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
   755
{   WIDGETS_END},
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   756
};
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   757
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   758
static const WindowDesc _message_history_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   759
	240, 22, 400, 140, 400, 140,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5839
diff changeset
   760
	WC_MESSAGE_HISTORY, WC_NONE,
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1095
diff changeset
   761
	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
   762
	_message_history_widgets,
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   763
};
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   764
7598
626c6a804e6d (svn r11125) -Documentation: add/update the documentation of news*. Based on a patch by Progman.
rubidium
parents: 7341
diff changeset
   765
/** Display window with news messages history */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   766
void ShowMessageHistory()
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   767
{
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   768
	DeleteWindowById(WC_MESSAGE_HISTORY, 0);
9288
82e1673da1db (svn r13154) -Codechange: make a window class of the news message history window.
rubidium
parents: 9285
diff changeset
   769
	new MessageHistoryWindow(&_message_history_desc);
89
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   770
}
b4a7784217ab (svn r90) Fix: Some news system bugfixes
dominik
parents: 83
diff changeset
   771
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   772
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   773
/** News settings window widget offset constants */
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   774
enum {
8343
a6b70ddd862b (svn r11909) -Codechange: use dropdown widget for player livery, network lobby/setup and news settings windows
peter1138
parents: 8284
diff changeset
   775
	WIDGET_NEWSOPT_DROP_SUMMARY = 4,  ///< Dropdown that adjusts at once the level for all settings
a6b70ddd862b (svn r11909) -Codechange: use dropdown widget for player livery, network lobby/setup and news settings windows
peter1138
parents: 8284
diff changeset
   776
	WIDGET_NEWSOPT_SOUNDTICKER  = 6,  ///< Button activating sound on events
a6b70ddd862b (svn r11909) -Codechange: use dropdown widget for player livery, network lobby/setup and news settings windows
peter1138
parents: 8284
diff changeset
   777
	WIDGET_NEWSOPT_START_OPTION = 8,  ///< First widget that is part of a group [<] .. [.]
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   778
};
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   779
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   780
static const StringID _message_opt[] = {STR_OFF, STR_SUMMARY, STR_FULL, INVALID_STRING_ID};
8343
a6b70ddd862b (svn r11909) -Codechange: use dropdown widget for player livery, network lobby/setup and news settings windows
peter1138
parents: 8284
diff changeset
   781
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   782
struct MessageOptionsWindow : Window {
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   783
	int state;
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   784
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   785
	MessageOptionsWindow(const WindowDesc *desc) : Window(desc)
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   786
	{
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   787
		NewsDisplay all_val;
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   788
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   789
		/* Set up the initial disabled buttons in the case of 'off' or 'full' */
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   790
		all_val = _news_type_data[0].display;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   791
		for (int i = 0; i < NT_END; i++) {
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   792
			this->SetMessageButtonStates(_news_type_data[i].display, i);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   793
			/* If the value doesn't match the ALL-button value, set the ALL-button value to 'off' */
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   794
			if (_news_type_data[i].display != all_val) all_val = ND_OFF;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   795
		}
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   796
		/* If all values are the same value, the ALL-button will take over this value */
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   797
		this->state = all_val;
9333
2da01b3b71d8 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 9317
diff changeset
   798
2da01b3b71d8 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 9317
diff changeset
   799
		this->FindWindowPlacementAndResize(desc);
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   800
	}
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   801
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   802
	/**
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   803
	 * Setup the disabled/enabled buttons in the message window
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   804
	 * If the value is 'off' disable the [<] widget, and enable the [>] one
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   805
	 * Same-wise for all the others. Starting value of 4 is the first widget
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   806
	 * group. These are grouped as [<][>] .. [<][>], etc.
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   807
	 * @param value to set in the widget
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   808
	 * @param element index of the group of widget to set
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   809
	 */
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   810
	void SetMessageButtonStates(byte value, int element)
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   811
	{
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   812
		element *= NB_WIDG_PER_SETTING;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   813
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   814
		this->SetWidgetDisabledState(element + WIDGET_NEWSOPT_START_OPTION, value == 0);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   815
		this->SetWidgetDisabledState(element + WIDGET_NEWSOPT_START_OPTION + 2, value == 2);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   816
	}
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   817
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   818
	virtual void OnPaint()
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   819
	{
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   820
		if (_news_ticker_sound) this->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   821
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   822
		this->widget[WIDGET_NEWSOPT_DROP_SUMMARY].data = _message_opt[this->state];
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9249
diff changeset
   823
		this->DrawWidgets();
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   824
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   825
		/* Draw the string of each setting on each button. */
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   826
		for (int i = 0, y = 26; i < NT_END; i++, y += 12) {
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   827
			/* 51 comes from 13 + 89 (left and right of the button)+1, shiefted by one as to get division,
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   828
				* which will give centered position */
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   829
			DrawStringCentered(51, y + 1, _message_opt[_news_type_data[i].display], TC_BLACK);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   830
		}
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   831
	}
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   832
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   833
	virtual void OnClick(Point pt, int widget)
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   834
	{
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   835
		switch (widget) {
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   836
			case WIDGET_NEWSOPT_DROP_SUMMARY: // Dropdown menu for all settings
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   837
				ShowDropDownMenu(this, _message_opt, this->state, WIDGET_NEWSOPT_DROP_SUMMARY, 0, 0);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   838
				break;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   839
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   840
			case WIDGET_NEWSOPT_SOUNDTICKER: // Change ticker sound on/off
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   841
				_news_ticker_sound ^= 1;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   842
				this->ToggleWidgetLoweredState(widget);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   843
				this->InvalidateWidget(widget);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   844
				break;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   845
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   846
			default: { // Clicked on the [<] .. [>] widgets
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   847
				int wid = widget - WIDGET_NEWSOPT_START_OPTION;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   848
				if (wid >= 0 && wid < (NB_WIDG_PER_SETTING * NT_END)) {
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   849
					int element = wid / NB_WIDG_PER_SETTING;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   850
					byte val = (_news_type_data[element].display + ((wid % NB_WIDG_PER_SETTING) ? 1 : -1)) % 3;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   851
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   852
					this->SetMessageButtonStates(val, element);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   853
					_news_type_data[element].display = (NewsDisplay)val;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   854
					this->SetDirty();
9093
0ba1a30d757b (svn r12952) -Cleanup: Indenting and codestyle
peter1138
parents: 9026
diff changeset
   855
				}
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   856
				break;
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   857
			}
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   858
		}
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   859
	}
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   860
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   861
	virtual void OnDropdownSelect(int widget, int index)
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   862
	{
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   863
		this->state = index;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   864
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   865
		for (int i = 0; i < NT_END; i++) {
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   866
			this->SetMessageButtonStates(index, i);
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   867
			_news_type_data[i].display = (NewsDisplay)index;
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   868
		}
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   869
		this->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	}
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   871
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   873
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   874
/*
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   875
* The news settings window widgets
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   876
*
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   877
* Main part of the window is a list of news-setting lines, one for each news category.
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   878
* Each line is constructed by an expansion of the \c NEWS_SETTINGS_LINE macro
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   879
*/
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   880
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   881
/**
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   882
* Macro to construct one news-setting line in the news-settings window.
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   883
* One line consists of four widgets, namely
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   884
* - A [<] button
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   885
* - A [...] label
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   886
* - A [>] button
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   887
* - A text label describing the news category
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   888
* Horizontal positions of the widgets are hard-coded, vertical start position is (\a basey + \a linenum * \c NEWS_SETTING_BASELINE_SKIP).
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   889
* Height of one line is 12, with the text label shifted 1 pixel down.
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   890
*
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   891
* First line should be widget number WIDGET_NEWSOPT_START_OPTION
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   892
*
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   893
* @param basey: Base Y coordinate
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   894
* @param linenum: Count, news-setting is the \a linenum-th line
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   895
* @param text: StringID for the text label to display
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   896
*/
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   897
#define NEWS_SETTINGS_LINE(basey, linenum, text) \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   898
	{ WWT_PUSHIMGBTN, RESIZE_NONE, COLOUR_YELLOW, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   899
	    4,  12,  basey     + linenum * NEWS_SETTING_BASELINE_SKIP,  basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   900
	  SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST}, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   901
	{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   902
	   13,  89,  basey     + linenum * NEWS_SETTING_BASELINE_SKIP,  basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   903
	  STR_EMPTY, STR_NULL}, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   904
	{ WWT_PUSHIMGBTN, RESIZE_NONE, COLOUR_YELLOW, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   905
	   90,  98,  basey     + linenum * NEWS_SETTING_BASELINE_SKIP,  basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   906
	  SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST}, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   907
        { WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   908
	  103, 409,  basey + 1 + linenum * NEWS_SETTING_BASELINE_SKIP,  basey + 13 + linenum * NEWS_SETTING_BASELINE_SKIP, \
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   909
	  text, STR_NULL}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   910
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   911
static const int NEWS_SETTING_BASELINE_SKIP = 12; ///< Distance between two news-setting lines, should be at least 12
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   912
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   913
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
static const Widget _message_options_widgets[] = {
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   915
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN,   0,  10,  0, 13,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   916
	STR_00C5,                 STR_018B_CLOSE_WINDOW},
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   917
{  WWT_CAPTION, RESIZE_NONE, COLOUR_BROWN,  11, 409,  0, 13,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   918
	STR_0204_MESSAGE_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   919
{    WWT_PANEL, RESIZE_NONE, COLOUR_BROWN,   0, 409, 14, 64 + NT_END * NEWS_SETTING_BASELINE_SKIP,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   920
	0x0,                      STR_NULL},
4344
7e123fec5b0b (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
   921
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   922
/* Text at the top of the main panel, in black */
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   923
{    WWT_LABEL, RESIZE_NONE, COLOUR_BROWN,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   924
	  0, 409, 13, 26,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   925
	STR_0205_MESSAGE_TYPES,   STR_NULL},
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   926
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   927
/* General drop down and sound button, widgets WIDGET_NEWSOPT_BTN_SUMMARY and WIDGET_NEWSOPT_DROP_SUMMARY */
8343
a6b70ddd862b (svn r11909) -Codechange: use dropdown widget for player livery, network lobby/setup and news settings windows
peter1138
parents: 8284
diff changeset
   928
{  WWT_DROPDOWN, RESIZE_NONE, COLOUR_YELLOW,
a6b70ddd862b (svn r11909) -Codechange: use dropdown widget for player livery, network lobby/setup and news settings windows
peter1138
parents: 8284
diff changeset
   929
	  4,  98,  34 + NT_END * NEWS_SETTING_BASELINE_SKIP,  45 + NT_END * NEWS_SETTING_BASELINE_SKIP,
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   930
	0x0, STR_NULL},
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   931
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   932
{      WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   933
	103, 409,  35 + NT_END * NEWS_SETTING_BASELINE_SKIP,  47 + NT_END * NEWS_SETTING_BASELINE_SKIP,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   934
	STR_MESSAGES_ALL, STR_NULL},
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   935
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   936
/* Below is widget WIDGET_NEWSOPT_SOUNDTICKER */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   937
{ WWT_TEXTBTN_2, RESIZE_NONE, COLOUR_YELLOW,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   938
	  4,  98,  46 + NT_END * NEWS_SETTING_BASELINE_SKIP,  57 + NT_END * NEWS_SETTING_BASELINE_SKIP,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   939
	STR_02DB_OFF,  STR_NULL},
6283
f9d97d412b0f (svn r9097) -Fix [FS#525]: open and close messages now have their own setting, so you can hide economy changes, but do show open/close of industries
truelight
parents: 6279
diff changeset
   940
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   941
{      WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   942
	103, 409,  47 + NT_END * NEWS_SETTING_BASELINE_SKIP,  59 + NT_END * NEWS_SETTING_BASELINE_SKIP,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   943
	STR_MESSAGE_SOUND, STR_NULL},
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   944
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   945
/* List of news-setting lines (4 widgets for each line).
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   946
 * First widget must be number WIDGET_NEWSOPT_START_OPTION
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   947
 */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   948
NEWS_SETTINGS_LINE(26, NT_ARRIVAL_PLAYER, STR_0206_ARRIVAL_OF_FIRST_VEHICLE),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   949
NEWS_SETTINGS_LINE(26, NT_ARRIVAL_OTHER,  STR_0207_ARRIVAL_OF_FIRST_VEHICLE),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   950
NEWS_SETTINGS_LINE(26, NT_ACCIDENT, STR_0208_ACCIDENTS_DISASTERS),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   951
NEWS_SETTINGS_LINE(26, NT_COMPANY_INFO, STR_0209_COMPANY_INFORMATION),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   952
NEWS_SETTINGS_LINE(26, NT_OPENCLOSE, STR_NEWS_OPEN_CLOSE),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   953
NEWS_SETTINGS_LINE(26, NT_ECONOMY, STR_020A_ECONOMY_CHANGES),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   954
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_PLAYER, STR_INDUSTRY_CHANGES_SERVED_BY_PLAYER),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   955
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_OTHER, STR_INDUSTRY_CHANGES_SERVED_BY_OTHER),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   956
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_NOBODY, STR_OTHER_INDUSTRY_PRODUCTION_CHANGES),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   957
NEWS_SETTINGS_LINE(26, NT_ADVICE, STR_020B_ADVICE_INFORMATION_ON_PLAYER),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   958
NEWS_SETTINGS_LINE(26, NT_NEW_VEHICLES, STR_020C_NEW_VEHICLES),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   959
NEWS_SETTINGS_LINE(26, NT_ACCEPTANCE, STR_020D_CHANGES_OF_CARGO_ACCEPTANCE),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   960
NEWS_SETTINGS_LINE(26, NT_SUBSIDIES, STR_020E_SUBSIDIES),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   961
NEWS_SETTINGS_LINE(26, NT_GENERAL, STR_020F_GENERAL_INFORMATION),
6279
fdae79bd4dc7 (svn r9089) -Codechange: Remove the 32 widgets limit on News Options window.
belugas
parents: 6247
diff changeset
   962
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 102
diff changeset
   963
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
static const WindowDesc _message_options_desc = {
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   967
	270,  22,  410,  65 + NT_END * NEWS_SETTING_BASELINE_SKIP,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7854
diff changeset
   968
	           410,  65 + NT_END * NEWS_SETTING_BASELINE_SKIP,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5839
diff changeset
   969
	WC_GAME_OPTIONS, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
	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
   971
	_message_options_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   974
void ShowMessageOptions()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	DeleteWindowById(WC_GAME_OPTIONS, 0);
9249
2b2f233edaed (svn r13115) -Codechange: make a window subclass of the MessageOptionsWindow.
rubidium
parents: 9248
diff changeset
   977
	new MessageOptionsWindow(&_message_options_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
}
3139
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   979
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   980
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   981
void DeleteVehicleNews(VehicleID vid, StringID news)
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   982
{
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
   983
	for (NewsID n = _oldest_news; _latest_news != INVALID_NEWS; n = IncreaseIndex(n)) {
5245
2dae2048ac0a (svn r7369) -Cleanup: Some coding style, usage of increaseIndex and decreaseIndex to loop through the
Darkvater
parents: 5244
diff changeset
   984
		const NewsItem *ni = &_news_items[n];
3139
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   985
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   986
		if (ni->flags & NF_VEHICLE &&
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   987
				ni->data_a == vid &&
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   988
				(news == INVALID_STRING_ID || ni->string_id == news)) {
5595
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   989
			/* If we delete a forced news and it is just before the current news
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   990
			 * then we need to advance to the next news (if any) */
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   991
			if (_forced_news == n) MoveToNextItem();
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
   992
			if (_forced_news == INVALID_NEWS && _current_news == n) MoveToNextItem();
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   993
			_total_news--;
3139
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
   994
5520
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
   995
			/* If this is the last news item, invalidate _latest_news */
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
   996
			if (_total_news == 0) {
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
   997
				assert(_latest_news == _oldest_news);
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
   998
				_latest_news = INVALID_NEWS;
8913
dd9b023c9f23 (svn r12683) -Fix [FS#1906]: in some cases a news messages would not be shown.
rubidium
parents: 8776
diff changeset
   999
				_current_news = INVALID_NEWS;
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1000
			}
3139
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
  1001
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1002
			/* Since we only imitate a FIFO removing an arbitrary element does need
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1003
			 * some magic. Remove the item by shifting head towards the tail. eg
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1004
			 *    oldest    remove  last
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1005
			 *        |        |     |
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1006
			 * [------O--------n-----L--]
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1007
			 * will become (change dramatized to make clear)
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1008
			 * [---------O-----------L--]
5520
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
  1009
			 * We also need an update of the current, forced and visible (open window)
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
  1010
			 * news's as this shifting could change the items they were pointing to */
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1011
			if (_total_news != 0) {
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
  1012
				NewsWindow *w = dynamic_cast<NewsWindow*>(FindWindowById(WC_NEWS_WINDOW, 0));
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
  1013
				NewsID visible_news = (w != NULL) ? (NewsID)(w->ni - _news_items) : INVALID_NEWS;
5520
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
  1014
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
  1015
				for (NewsID i = n;; i = DecreaseIndex(i)) {
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
  1016
					_news_items[i] = _news_items[DecreaseIndex(i)];
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1017
5839
15e33fa8f9f7 (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: 5668
diff changeset
  1018
					if (i != _latest_news) {
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
  1019
						if (i == _current_news) _current_news = IncreaseIndex(_current_news);
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
  1020
						if (i == _forced_news) _forced_news = IncreaseIndex(_forced_news);
9236
0c4f622cbcec (svn r13102) -Codechange: make a class of the NewsWindow.
rubidium
parents: 9234
diff changeset
  1021
						if (i == visible_news) w->ni = &_news_items[IncreaseIndex(visible_news)];
5839
15e33fa8f9f7 (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: 5668
diff changeset
  1022
					}
5520
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
  1023
5533
9336b14a5ef2 (svn r7861) -Fix (r7823): Crash when oldest news was deleted. First check the index for oldest news
Darkvater
parents: 5520
diff changeset
  1024
					if (i == _oldest_news) break;
9336b14a5ef2 (svn r7861) -Fix (r7823): Crash when oldest news was deleted. First check the index for oldest news
Darkvater
parents: 5520
diff changeset
  1025
				}
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
  1026
				_oldest_news = IncreaseIndex(_oldest_news);
3139
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
  1027
			}
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
  1028
5595
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
  1029
			/*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d",
6d738ef8fd96 (svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
Darkvater
parents: 5587
diff changeset
  1030
			  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
5520
dd1482ee78c4 (svn r7823) -Fix (r7384 / r7368 / r3757 / r7388): News windows could still cause crashes because
Darkvater
parents: 5475
diff changeset
  1031
8776
1db57a00cba8 (svn r12475) -Codechange: cleanup coding style in news_gui.cpp.
rubidium
parents: 8763
diff changeset
  1032
			Window *w = FindWindowById(WC_MESSAGE_HISTORY, 0);
3143
24e7291f7652 (svn r3761) Fix two bugs in r3757
tron
parents: 3140
diff changeset
  1033
			if (w != NULL) {
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1034
				w->SetDirty();
3143
24e7291f7652 (svn r3761) Fix two bugs in r3757
tron
parents: 3140
diff changeset
  1035
				w->vscroll.count = _total_news;
24e7291f7652 (svn r3761) Fix two bugs in r3757
tron
parents: 3140
diff changeset
  1036
			}
3139
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
  1037
		}
5254
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1038
bce68eeaab3b (svn r7384) -Fix: No vehicle was removed in DeleteVehicleNews when the fifo-array was full. Update the
Darkvater
parents: 5253
diff changeset
  1039
		if (n == _latest_news) break;
3139
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
  1040
	}
b17abef09e15 (svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents: 2791
diff changeset
  1041
}