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