author | pasky |
Sat, 12 Mar 2005 08:52:40 +0000 | |
changeset 1494 | 31436e59176a |
parent 1390 | e7cdf3ce0fb6 |
child 1648 | 41c3d5de9994 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1097
diff
changeset
|
3 |
#include "strings.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
4 |
#include "table/strings.h" |
0 | 5 |
#include "window.h" |
6 |
#include "gui.h" |
|
7 |
#include "viewport.h" |
|
8 |
#include "gfx.h" |
|
9 |
#include "news.h" |
|
10 |
#include "vehicle.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
11 |
#include "sound.h" |
0 | 12 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
13 |
/* News system |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
14 |
News system is realized as a FIFO queue (in an array) |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
15 |
The positions in the queue can't be rearranged, we only access |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
16 |
the array elements through pointers to the elements. Once the |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
17 |
array is full, the oldest entry (_oldest_news) is being overwritten |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
18 |
by the newest (_latest news). |
0 | 19 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
20 |
oldest current lastest |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
21 |
| | | |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
22 |
[O------------F-------------C---------L ] |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
23 |
| |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
24 |
forced |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
25 |
*/ |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
26 |
|
427 | 27 |
#define MAX_NEWS 30 |
28 |
||
29 |
#define INVALID_NEWS 255 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
30 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
31 |
static NewsItem _news_items[MAX_NEWS]; |
427 | 32 |
static byte _current_news = INVALID_NEWS; // points to news item that should be shown next |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
33 |
static byte _oldest_news = 0; // points to first item in fifo queue |
427 | 34 |
static byte _latest_news = INVALID_NEWS; // points to last item in fifo queue |
35 |
/* if the message being shown was forced by the user, its index is stored in |
|
36 |
* _forced_news. forced_news is INVALID_NEWS otherwise. |
|
37 |
* (Users can force messages through history or "last message") */ |
|
38 |
static byte _forced_news = INVALID_NEWS; |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
39 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
40 |
static byte _total_news = 0; // total news count |
0 | 41 |
|
42 |
void DrawNewsNewTrainAvail(Window *w); |
|
43 |
void DrawNewsNewRoadVehAvail(Window *w); |
|
44 |
void DrawNewsNewShipAvail(Window *w); |
|
45 |
void DrawNewsNewAircraftAvail(Window *w); |
|
46 |
void DrawNewsBankrupcy(Window *w); |
|
427 | 47 |
static void MoveToNexItem(void); |
0 | 48 |
|
49 |
StringID GetNewsStringNewTrainAvail(NewsItem *ni); |
|
50 |
StringID GetNewsStringNewRoadVehAvail(NewsItem *ni); |
|
51 |
StringID GetNewsStringNewShipAvail(NewsItem *ni); |
|
52 |
StringID GetNewsStringNewAircraftAvail(NewsItem *ni); |
|
53 |
StringID GetNewsStringBankrupcy(NewsItem *ni); |
|
54 |
||
55 |
static DrawNewsCallbackProc * const _draw_news_callback[] = { |
|
427 | 56 |
DrawNewsNewTrainAvail, /* DNC_TRAINAVAIL */ |
57 |
DrawNewsNewRoadVehAvail, /* DNC_ROADAVAIL */ |
|
58 |
DrawNewsNewShipAvail, /* DNC_SHIPAVAIL */ |
|
0 | 59 |
DrawNewsNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */ |
427 | 60 |
DrawNewsBankrupcy, /* DNC_BANKRUPCY */ |
0 | 61 |
}; |
62 |
||
63 |
GetNewsStringCallbackProc * const _get_news_string_callback[] = { |
|
427 | 64 |
GetNewsStringNewTrainAvail, /* DNC_TRAINAVAIL */ |
65 |
GetNewsStringNewRoadVehAvail, /* DNC_ROADAVAIL */ |
|
66 |
GetNewsStringNewShipAvail, /* DNC_SHIPAVAIL */ |
|
0 | 67 |
GetNewsStringNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */ |
427 | 68 |
GetNewsStringBankrupcy, /* DNC_BANKRUPCY */ |
0 | 69 |
}; |
70 |
||
427 | 71 |
void InitNewsItemStructs(void) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
72 |
{ |
427 | 73 |
memset(_news_items, 0, sizeof(_news_items)); |
74 |
_current_news = INVALID_NEWS; |
|
89 | 75 |
_oldest_news = 0; |
427 | 76 |
_latest_news = INVALID_NEWS; |
77 |
_forced_news = INVALID_NEWS; |
|
89 | 78 |
_total_news = 0; |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
79 |
} |
0 | 80 |
|
427 | 81 |
void DrawNewsBorder(const Window *w) |
0 | 82 |
{ |
83 |
int left = 0; |
|
84 |
int right = w->width - 1; |
|
85 |
int top = 0; |
|
86 |
int bottom = w->height - 1; |
|
87 |
||
88 |
GfxFillRect(left, top, right, bottom, 0xF); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
89 |
|
0 | 90 |
GfxFillRect(left, top, left, bottom, 0xD7); |
91 |
GfxFillRect(right, top, right, bottom, 0xD7); |
|
92 |
GfxFillRect(left, top, right, top, 0xD7); |
|
93 |
GfxFillRect(left, bottom, right, bottom, 0xD7); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
94 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
95 |
DrawString(left + 2, top + 1, STR_00C6, 0); |
0 | 96 |
} |
97 |
||
98 |
static void NewsWindowProc(Window *w, WindowEvent *e) |
|
99 |
{ |
|
427 | 100 |
switch (e->event) { |
0 | 101 |
case WE_PAINT: { |
427 | 102 |
const NewsItem *ni = WP(w, news_d).ni; |
0 | 103 |
ViewPort *vp; |
104 |
||
427 | 105 |
switch (ni->display_mode) { |
106 |
case NM_NORMAL: |
|
107 |
case NM_THIN: { |
|
108 |
DrawNewsBorder(w); |
|
0 | 109 |
|
427 | 110 |
DrawString(2, 1, STR_00C6, 0); |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
111 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
112 |
SetDParam(0, ni->date); |
427 | 113 |
DrawStringRightAligned(428, 1, STR_01FF, 0); |
114 |
||
115 |
if (!(ni->flags & NF_VIEWPORT)) { |
|
116 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); |
|
117 |
DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56, |
|
118 |
ni->string_id, 426); |
|
119 |
} else { |
|
120 |
byte bk = _display_opt; |
|
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
427
diff
changeset
|
121 |
_display_opt &= ~DO_TRANS_BUILDINGS; |
427 | 122 |
DrawWindowViewport(w); |
123 |
_display_opt = bk; |
|
124 |
||
125 |
/* Shade the viewport into gray, or color*/ |
|
126 |
vp = w->viewport; |
|
127 |
GfxFillRect(vp->left - w->left, vp->top - w->top, |
|
128 |
vp->left - w->left + vp->width - 1, vp->top - w->top + vp->height - 1, |
|
129 |
ni->flags & NF_INCOLOR ? 0x4322 : 0x4323 |
|
130 |
); |
|
131 |
||
132 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); |
|
133 |
DrawStringMultiCenter(w->width / 2, 20, ni->string_id, 428); |
|
134 |
} |
|
135 |
break; |
|
0 | 136 |
} |
427 | 137 |
|
138 |
case NM_CALLBACK: { |
|
139 |
_draw_news_callback[ni->callback](w); |
|
140 |
break; |
|
141 |
} |
|
142 |
||
143 |
default: { |
|
144 |
DrawWindowWidgets(w); |
|
145 |
if (!(ni->flags & NF_VIEWPORT)) { |
|
146 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); |
|
147 |
DrawStringMultiCenter(140, 38, ni->string_id, 276); |
|
148 |
} else { |
|
149 |
DrawWindowViewport(w); |
|
150 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); |
|
151 |
DrawStringMultiCenter(w->width / 2, w->height - 16, ni->string_id, 276); |
|
152 |
} |
|
153 |
break; |
|
0 | 154 |
} |
155 |
} |
|
156 |
} break; |
|
157 |
||
158 |
case WE_CLICK: { |
|
427 | 159 |
switch (e->click.widget) { |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
160 |
case 1: { |
427 | 161 |
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
|
162 |
DeleteWindow(w); |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
163 |
ni->duration = 0; |
427 | 164 |
_forced_news = INVALID_NEWS; |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
165 |
} break; |
0 | 166 |
case 0: { |
427 | 167 |
NewsItem *ni = WP(w, news_d).ni; |
0 | 168 |
if (ni->flags & NF_VEHICLE) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
169 |
Vehicle *v = GetVehicle(ni->data_a); |
0 | 170 |
ScrollMainWindowTo(v->x_pos, v->y_pos); |
171 |
} else if (ni->flags & NF_TILE) { |
|
172 |
if (!ScrollMainWindowToTile(ni->data_a) && ni->data_b != 0) |
|
173 |
ScrollMainWindowToTile(ni->data_b); |
|
174 |
} |
|
175 |
} break; |
|
176 |
} |
|
177 |
} break; |
|
178 |
||
179 |
case WE_KEYPRESS: |
|
180 |
if (e->keypress.keycode == WKC_SPACE) { |
|
181 |
// Don't continue. |
|
182 |
e->keypress.cont = false; |
|
183 |
DeleteWindow(w); |
|
184 |
} |
|
185 |
break; |
|
186 |
||
187 |
case WE_TICK: { |
|
188 |
int y = max(w->top - 4, _screen.height - w->height); |
|
189 |
if (y == w->top) |
|
190 |
return; |
|
191 |
||
192 |
if (w->viewport != NULL) |
|
193 |
w->viewport->top += y - w->top; |
|
194 |
||
195 |
w->top = y; |
|
196 |
||
197 |
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height + 4); |
|
198 |
} break; |
|
199 |
} |
|
200 |
} |
|
201 |
||
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
202 |
// returns the correct index in the array |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
203 |
// (to deal with overflows) |
1095 | 204 |
static byte increaseIndex(byte i) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
205 |
{ |
427 | 206 |
if (i == INVALID_NEWS) |
83
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
207 |
return 0; |
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
208 |
i++; |
427 | 209 |
if (i >= MAX_NEWS) |
83
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
210 |
i = i % MAX_NEWS; |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
211 |
return i; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
212 |
} |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
213 |
|
0 | 214 |
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b) |
215 |
{ |
|
216 |
NewsItem *ni; |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
217 |
Window *w; |
0 | 218 |
|
219 |
if (_game_mode == GM_MENU) |
|
220 |
return; |
|
221 |
||
102
1d277a07f1f1
(svn r103) Fix: rare newspaper crash with too many messages [ 1009976 ] (thx to blathij)s
dominik
parents:
94
diff
changeset
|
222 |
// check the rare case that the oldest (to be overwritten) news item is open |
935 | 223 |
if (_total_news==MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) |
102
1d277a07f1f1
(svn r103) Fix: rare newspaper crash with too many messages [ 1009976 ] (thx to blathij)s
dominik
parents:
94
diff
changeset
|
224 |
MoveToNexItem(); |
1d277a07f1f1
(svn r103) Fix: rare newspaper crash with too many messages [ 1009976 ] (thx to blathij)s
dominik
parents:
94
diff
changeset
|
225 |
|
427 | 226 |
_forced_news = INVALID_NEWS; |
227 |
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
|
228 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
229 |
// make sure our pointer isn't overflowing |
83
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
230 |
_latest_news = increaseIndex(_latest_news); |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
231 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
232 |
// overwrite oldest news entry |
427 | 233 |
if (_oldest_news == _latest_news && _news_items[_oldest_news].string_id != 0) |
83
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
234 |
_oldest_news = increaseIndex(_oldest_news); // but make sure we're not overflowing here |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
235 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
236 |
// add news to _latest_news |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
237 |
ni = &_news_items[_latest_news]; |
745
6073a73d0b13
(svn r1201) -Fix: I forgot to add a * in r1183 ;)
truelight
parents:
731
diff
changeset
|
238 |
memset(ni, 0, sizeof(*ni)); |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
239 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
240 |
ni->string_id = string; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
241 |
ni->display_mode = (byte)flags; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
242 |
ni->flags = (byte)(flags >> 8) | NF_NOEXPIRE; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
243 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
244 |
// show this news message in color? |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
245 |
if (_date >= ConvertIntDate(_patches.colored_news_date)) |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
246 |
ni->flags |= NF_INCOLOR; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
247 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
248 |
ni->type = (byte)(flags >> 16); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
249 |
ni->callback = (byte)(flags >> 24); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
250 |
ni->data_a = data_a; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
251 |
ni->data_b = data_b; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
252 |
ni->date = _date; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
253 |
COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params)); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
254 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
255 |
w = FindWindowById(WC_MESSAGE_HISTORY, 0); |
427 | 256 |
if (w == NULL) return; |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
257 |
SetWindowDirty(w); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
258 |
w->vscroll.count = _total_news; |
0 | 259 |
} |
260 |
||
715
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
261 |
/* To add a news item with an attached validation function. This validation function |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
262 |
* makes sure that the news item is not outdated when the newspaper pops up. */ |
718
0bb3e204abb5
(svn r1170) Fix: news_gui.c should compile everywhere without warnings now.
dominik
parents:
715
diff
changeset
|
263 |
void AddValidatedNewsItem(StringID string, uint32 flags, uint data_a, uint data_b, ValidationProc *validation) |
715
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
264 |
{ |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
265 |
AddNewsItem(string, flags, data_a, data_b); |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
266 |
_news_items[_latest_news].isValid = validation; |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
267 |
} |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
268 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
269 |
// don't show item if it's older than x days |
0 | 270 |
static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180}; |
271 |
||
272 |
static const Widget _news_type13_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
273 |
{ WWT_PANEL, RESIZE_NONE, 15, 0, 429, 0, 169, 0x0, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
274 |
{ 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
|
275 |
{ WIDGETS_END}, |
0 | 276 |
}; |
277 |
||
278 |
static WindowDesc _news_type13_desc = { |
|
279 |
WDP_CENTER, 476, 430, 170, |
|
427 | 280 |
WC_NEWS_WINDOW, 0, |
0 | 281 |
WDF_DEF_WIDGET, |
282 |
_news_type13_widgets, |
|
283 |
NewsWindowProc |
|
284 |
}; |
|
285 |
||
286 |
static const Widget _news_type2_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
287 |
{ WWT_PANEL, RESIZE_NONE, 15, 0, 429, 0, 129, 0x0, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
288 |
{ 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
|
289 |
{ WIDGETS_END}, |
0 | 290 |
}; |
291 |
||
292 |
static WindowDesc _news_type2_desc = { |
|
293 |
WDP_CENTER, 476, 430, 130, |
|
427 | 294 |
WC_NEWS_WINDOW, 0, |
0 | 295 |
WDF_DEF_WIDGET, |
296 |
_news_type2_widgets, |
|
297 |
NewsWindowProc |
|
298 |
}; |
|
299 |
||
300 |
static const Widget _news_type0_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
301 |
{ WWT_PANEL, RESIZE_NONE, 5, 0, 279, 14, 86, 0x0, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
302 |
{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
303 |
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 279, 0, 13, STR_012C_MESSAGE, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
304 |
{ WWT_6, 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
|
305 |
{ WIDGETS_END}, |
0 | 306 |
}; |
307 |
||
308 |
static WindowDesc _news_type0_desc = { |
|
309 |
WDP_CENTER, 476, 280, 87, |
|
427 | 310 |
WC_NEWS_WINDOW, 0, |
0 | 311 |
WDF_DEF_WIDGET, |
312 |
_news_type0_widgets, |
|
313 |
NewsWindowProc |
|
314 |
}; |
|
315 |
||
427 | 316 |
static const SoundFx _news_sounds[] = { |
317 |
SND_1D_APPLAUSE, |
|
318 |
SND_1D_APPLAUSE, |
|
319 |
0, |
|
320 |
0, |
|
321 |
0, |
|
322 |
0, |
|
323 |
SND_1E_OOOOH, |
|
324 |
0, |
|
325 |
0, |
|
326 |
0 |
|
327 |
}; |
|
0 | 328 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
329 |
// open up an own newspaper window for the news item |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
330 |
static void ShowNewspaper(NewsItem *ni) |
0 | 331 |
{ |
332 |
Window *w; |
|
333 |
int sound; |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
334 |
int top; |
427 | 335 |
ni->flags &= ~(NF_NOEXPIRE | NF_FORCE_BIG); |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
336 |
ni->duration = 555; |
0 | 337 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
338 |
sound = _news_sounds[ni->type]; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
339 |
if (sound != 0) |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
340 |
SndPlayFx(sound); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
341 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
342 |
top = _screen.height - 4; |
427 | 343 |
switch (ni->display_mode) { |
344 |
case NM_NORMAL: |
|
345 |
case NM_CALLBACK: { |
|
346 |
_news_type13_desc.top = top; |
|
347 |
w = AllocateWindowDesc(&_news_type13_desc); |
|
348 |
if (ni->flags & NF_VIEWPORT) |
|
349 |
AssignWindowViewport(w, 2, 58, 0x1AA, 0x6E, |
|
350 |
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0); |
|
351 |
break; |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
352 |
} |
427 | 353 |
|
354 |
case NM_THIN: { |
|
355 |
_news_type2_desc.top = top; |
|
356 |
w = AllocateWindowDesc(&_news_type2_desc); |
|
357 |
if (ni->flags & NF_VIEWPORT) |
|
358 |
AssignWindowViewport(w, 2, 58, 0x1AA, 0x46, |
|
359 |
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0); |
|
360 |
break; |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
361 |
} |
427 | 362 |
|
363 |
default: { |
|
364 |
_news_type0_desc.top = top; |
|
365 |
w = AllocateWindowDesc(&_news_type0_desc); |
|
366 |
if (ni->flags & NF_VIEWPORT) |
|
367 |
AssignWindowViewport(w, 3, 17, 0x112, 0x2F, |
|
368 |
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0); |
|
369 |
break; |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
370 |
} |
0 | 371 |
} |
427 | 372 |
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
|
373 |
w->flags4 |= WF_DISABLE_VP_SCROLL; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
374 |
} |
0 | 375 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
376 |
// show news item in the ticker |
427 | 377 |
static void ShowTicker(const NewsItem *ni) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
378 |
{ |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
379 |
Window *w; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
380 |
|
541 | 381 |
SndPlayFx(SND_16_MORSE); |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
382 |
_statusbar_news_item = *ni; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
383 |
w = FindWindowById(WC_STATUS_BAR, 0); |
427 | 384 |
if (w != NULL) |
385 |
WP(w, def_d).data_1 = 360; |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
386 |
} |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
387 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
388 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
389 |
// Are we ready to show another news item? |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
390 |
// Only if nothing is in the newsticker and no newspaper is displayed |
427 | 391 |
static bool ReadyForNextItem(void) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
392 |
{ |
427 | 393 |
const Window *w; |
394 |
byte 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
|
395 |
NewsItem *ni; |
20b4c7536349
(svn r93) Fix: memory leak in news system (blathijs)
dominik
parents:
89
diff
changeset
|
396 |
|
427 | 397 |
if (item >= MAX_NEWS) return true; |
92
20b4c7536349
(svn r93) Fix: memory leak in news system (blathijs)
dominik
parents:
89
diff
changeset
|
398 |
ni = &_news_items[item]; |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
399 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
400 |
// Ticker message |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
401 |
// Check if the status bar message is still being displayed? |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
402 |
w = FindWindowById(WC_STATUS_BAR, 0); |
427 | 403 |
if (w != NULL && WP(w, def_d).data_1 > -1280) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
404 |
return false; |
0 | 405 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
406 |
// Newspaper message |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
407 |
// Wait until duration reaches 0 |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
408 |
if (ni->duration != 0) { |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
409 |
ni->duration--; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
410 |
return false; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
411 |
} |
0 | 412 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
413 |
// neither newsticker nor newspaper are running |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
414 |
return true; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
415 |
} |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
416 |
|
427 | 417 |
static void MoveToNexItem(void) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
418 |
{ |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
419 |
DeleteWindowById(WC_NEWS_WINDOW, 0); |
427 | 420 |
_forced_news = INVALID_NEWS; |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
421 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
422 |
// if we're not at the last item, than move on |
427 | 423 |
if (_current_news != _latest_news) { |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
424 |
NewsItem *ni; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
425 |
|
83
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
426 |
_current_news = increaseIndex(_current_news); |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
427 |
ni = &_news_items[_current_news]; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
428 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
429 |
// check the date, don't show too old items |
427 | 430 |
if (_date - _news_items_age[ni->type] > ni->date) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
431 |
return; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
432 |
|
715
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
433 |
// execute the validation function to see if this item is still valid |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
434 |
if ( ni->isValid != NULL && !ni->isValid(ni->data_a, ni->data_b) ) |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
435 |
return; |
28dd55cc55ae
(svn r1167) Feature: Added the possibility to add validation functions to NewsItems. This is now done for "Train in depot" messages. Before displaying such a message, it checks if the train really still is in the depot. Can be applied to other news items as well.
dominik
parents:
541
diff
changeset
|
436 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
437 |
// show newspaper or send to ticker? |
427 | 438 |
if (!HASBIT(_news_display_opt, ni->type) && !(ni->flags & NF_FORCE_BIG)) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
439 |
ShowTicker(ni); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
440 |
else |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
441 |
ShowNewspaper(ni); |
0 | 442 |
} |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
443 |
} |
0 | 444 |
|
427 | 445 |
void NewsLoop(void) |
0 | 446 |
{ |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
447 |
// no news item yet |
427 | 448 |
if (_total_news == 0) return; |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
449 |
|
427 | 450 |
if (ReadyForNextItem()) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
451 |
MoveToNexItem(); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
452 |
} |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
453 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
454 |
/* Do a forced show of a specific message */ |
1095 | 455 |
static void ShowNewsMessage(byte i) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
456 |
{ |
427 | 457 |
if (_total_news == 0) return; |
89 | 458 |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
459 |
// Delete the news window |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
460 |
DeleteWindowById(WC_NEWS_WINDOW, 0); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
461 |
|
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
462 |
// setup forced news item |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
463 |
_forced_news = i; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
464 |
|
427 | 465 |
if (_forced_news != INVALID_NEWS) { |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
466 |
NewsItem *ni = &_news_items[_forced_news]; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
467 |
ni->duration = 555; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
468 |
ni->flags |= NF_NOEXPIRE | NF_FORCE_BIG; |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
469 |
DeleteWindowById(WC_NEWS_WINDOW, 0); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
470 |
ShowNewspaper(ni); |
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
471 |
} |
0 | 472 |
} |
473 |
||
427 | 474 |
void ShowLastNewsMessage(void) |
0 | 475 |
{ |
427 | 476 |
if (_forced_news == INVALID_NEWS) |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
477 |
ShowNewsMessage(_current_news); |
427 | 478 |
else if (_forced_news != 0) |
479 |
ShowNewsMessage(_forced_news - 1); |
|
83
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
480 |
else { |
427 | 481 |
if (_total_news != MAX_NEWS) |
83
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
482 |
ShowNewsMessage(_latest_news); |
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
483 |
else |
427 | 484 |
ShowNewsMessage(MAX_NEWS - 1); |
83
bd21afea96d8
(svn r84) Improved news system code a little to avoid potential memory leaks
dominik
parents:
80
diff
changeset
|
485 |
} |
0 | 486 |
} |
487 |
||
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
488 |
|
89 | 489 |
/* return news by number, with 0 being the most |
427 | 490 |
recent news. Returns INVALID_NEWS if end of queue reached. */ |
89 | 491 |
static byte getNews(byte i) |
492 |
{ |
|
427 | 493 |
if (i >= _total_news) |
494 |
return INVALID_NEWS; |
|
89 | 495 |
|
427 | 496 |
if (_latest_news < i) |
89 | 497 |
i = _latest_news + MAX_NEWS - i; |
498 |
else |
|
499 |
i = _latest_news - i; |
|
500 |
||
427 | 501 |
i %= MAX_NEWS; |
89 | 502 |
return i; |
503 |
} |
|
504 |
||
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
505 |
// cut string after len pixels |
1329 | 506 |
static void GetNewsString(NewsItem *ni, char *buffer, uint max) |
89 | 507 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1329
diff
changeset
|
508 |
char buf[512]; |
89 | 509 |
StringID str; |
1329 | 510 |
const char *s; |
511 |
char *d; |
|
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
512 |
uint len = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
513 |
|
89 | 514 |
if (ni->display_mode == 3) { |
515 |
str = _get_news_string_callback[ni->callback](ni); |
|
516 |
} else { |
|
517 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
518 |
str = ni->string_id; |
89 | 519 |
} |
520 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1329
diff
changeset
|
521 |
GetString(buf, str); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
522 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1329
diff
changeset
|
523 |
s = buf; |
89 | 524 |
d = buffer; |
525 |
||
427 | 526 |
for (;; s++) { |
89 | 527 |
// cut strings that are too long |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
528 |
if (len >= max-24) { // add 3x "." at the end |
89 | 529 |
d[0] = d[1] = d[2] = '.'; |
427 | 530 |
d += 3; |
531 |
*d = '\0'; |
|
89 | 532 |
break; |
533 |
} |
|
534 |
||
427 | 535 |
if (*s == '\0') { |
536 |
*d = '\0'; |
|
89 | 537 |
break; |
427 | 538 |
} else if (*s == '\r') { |
89 | 539 |
d[0] = d[1] = d[2] = d[3] = ' '; |
427 | 540 |
d += 4; |
1329 | 541 |
} else if ((byte)*s >= ' ' && ((byte)*s < 0x88 || (byte)*s >= 0x99)) { |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1336
diff
changeset
|
542 |
len += GetCharacterWidth((byte)*s); |
89 | 543 |
*d++ = *s; |
544 |
} |
|
545 |
} |
|
546 |
} |
|
547 |
||
548 |
||
549 |
static void MessageHistoryWndProc(Window *w, WindowEvent *e) |
|
550 |
{ |
|
427 | 551 |
switch (e->event) { |
89 | 552 |
case WE_PAINT: { |
427 | 553 |
int y = 19; |
89 | 554 |
byte p, show; |
555 |
NewsItem *ni; |
|
556 |
||
557 |
DrawWindowWidgets(w); |
|
558 |
||
427 | 559 |
if (_total_news == 0) break; |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
560 |
show = min(_total_news, w->vscroll.cap); |
89 | 561 |
|
427 | 562 |
for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) { |
1329 | 563 |
char buffer[256]; |
564 |
||
89 | 565 |
// get news in correct order |
427 | 566 |
ni = &_news_items[getNews(p)]; |
89 | 567 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
568 |
SetDParam(0, ni->date); |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
569 |
DrawString(4, y, STR_SHORT_DATE, 16); |
89 | 570 |
|
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
571 |
GetNewsString(ni, buffer, w->width-90); |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
572 |
DoDrawString(buffer, 82, y, 16); |
89 | 573 |
y += 12; |
574 |
} |
|
575 |
||
576 |
break; |
|
577 |
} |
|
578 |
||
579 |
case WE_CLICK: |
|
427 | 580 |
switch (e->click.widget) { |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
581 |
case 3: { |
89 | 582 |
int y = (e->click.pt.y - 19) / 12; |
583 |
byte p, q; |
|
584 |
||
427 | 585 |
#if 0 // === DEBUG code only |
586 |
for (p = 0; p < _total_news; p++) |
|
89 | 587 |
{ |
588 |
NewsItem *ni; |
|
589 |
byte buffer[256]; |
|
427 | 590 |
ni = &_news_items[p]; |
89 | 591 |
GetNewsString(ni, buffer); |
592 |
printf("%i\t%i\t%s\n", p, ni->date, buffer); |
|
593 |
} |
|
594 |
printf("=========================\n"); |
|
427 | 595 |
#endif |
89 | 596 |
|
597 |
p = y + w->vscroll.pos; |
|
427 | 598 |
if (p > _total_news - 1) break; |
89 | 599 |
|
427 | 600 |
if (_latest_news >= p) |
601 |
q = _latest_news - p; |
|
602 |
else |
|
603 |
q = _latest_news + MAX_NEWS - p; |
|
89 | 604 |
ShowNewsMessage(q); |
605 |
||
606 |
break; |
|
607 |
} |
|
608 |
} |
|
609 |
break; |
|
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
610 |
|
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
611 |
case WE_RESIZE: |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
612 |
w->vscroll.cap += e->sizing.diff.y / 12; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
613 |
break; |
89 | 614 |
} |
615 |
} |
|
616 |
||
617 |
static const Widget _message_history_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
618 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
619 |
{ WWT_CAPTION, RESIZE_RIGHT, 13, 11, 387, 0, 13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
620 |
{ WWT_STICKYBOX, RESIZE_LR, 13, 388, 399, 0, 13, 0x0, STR_STICKY_BUTTON}, |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
621 |
{ WWT_IMGBTN, RESIZE_RB, 13, 0, 387, 14, 139, 0x0, STR_MESSAGE_HISTORY_TIP}, |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
622 |
{ WWT_SCROLLBAR, RESIZE_LRB, 13, 388, 399, 14, 127, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
623 |
{ 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
|
624 |
{ WIDGETS_END}, |
89 | 625 |
}; |
626 |
||
627 |
static const WindowDesc _message_history_desc = { |
|
628 |
240, 22, 400, 140, |
|
427 | 629 |
WC_MESSAGE_HISTORY, 0, |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
630 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
89 | 631 |
_message_history_widgets, |
632 |
MessageHistoryWndProc |
|
633 |
}; |
|
634 |
||
427 | 635 |
void ShowMessageHistory(void) |
89 | 636 |
{ |
637 |
Window *w; |
|
638 |
||
639 |
DeleteWindowById(WC_MESSAGE_HISTORY, 0); |
|
640 |
w = AllocateWindowDesc(&_message_history_desc); |
|
641 |
||
427 | 642 |
if (w != NULL) { |
89 | 643 |
w->vscroll.cap = 10; |
644 |
w->vscroll.count = _total_news; |
|
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
645 |
w->resize.step_height = 12; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
646 |
w->resize.height = w->height - 12 * 6; // minimum of 4 items in the list, each item 12 high |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
647 |
w->resize.step_width = 1; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1095
diff
changeset
|
648 |
w->resize.width = 200; // can't make window any smaller than 200 pixel |
89 | 649 |
SetWindowDirty(w); |
650 |
} |
|
651 |
} |
|
652 |
||
0 | 653 |
|
654 |
static void MessageOptionsWndProc(Window *w, WindowEvent *e) |
|
655 |
{ |
|
427 | 656 |
switch (e->event) { |
0 | 657 |
case WE_PAINT: { |
658 |
uint16 x = _news_display_opt; |
|
659 |
uint32 cs = 0; |
|
660 |
int i, y; |
|
661 |
||
427 | 662 |
for (i = 3; i != 23; i += 2) { |
663 |
cs |= 1 << (i + (x & 1)); |
|
0 | 664 |
x >>= 1; |
665 |
} |
|
666 |
cs |= (w->click_state >> 23) << 23; |
|
667 |
||
668 |
w->click_state = cs; |
|
669 |
DrawWindowWidgets(w); |
|
670 |
||
671 |
DrawStringCentered(185, 15, STR_0205_MESSAGE_TYPES, 0); |
|
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
672 |
|
0 | 673 |
y = 27; |
427 | 674 |
for (i = STR_0206_ARRIVAL_OF_FIRST_VEHICLE; i <= STR_020F_GENERAL_INFORMATION; i++) { |
0 | 675 |
DrawString(124, y, i, 0); |
676 |
y += 12; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
677 |
} |
0 | 678 |
|
679 |
break; |
|
427 | 680 |
} |
0 | 681 |
|
682 |
case WE_CLICK: { |
|
683 |
int wid; |
|
427 | 684 |
if ((uint)(wid = e->click.widget - 3) < 20) { |
685 |
if (!(wid & 1)) |
|
686 |
_news_display_opt &= ~(1 << (wid / 2)); |
|
687 |
else |
|
688 |
_news_display_opt |= (1 << (wid / 2)); |
|
0 | 689 |
SetWindowDirty(w); |
79
15e3eef5f73d
(svn r80) New internal news system (implemented with fifo queue)
dominik
parents:
0
diff
changeset
|
690 |
// XXX: write settings |
0 | 691 |
} |
427 | 692 |
if (e->click.widget == 23) { |
0 | 693 |
_news_display_opt = 0; |
694 |
HandleButtonClick(w, 23); |
|
695 |
SetWindowDirty(w); |
|
696 |
} |
|
427 | 697 |
if (e->click.widget == 24) { |
0 | 698 |
_news_display_opt = ~0; |
699 |
HandleButtonClick(w, 24); |
|
700 |
SetWindowDirty(w); |
|
701 |
} |
|
702 |
} break; |
|
703 |
} |
|
704 |
} |
|
705 |
||
706 |
static const Widget _message_options_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
707 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
708 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 369, 0, 13, STR_0204_MESSAGE_OPTIONS,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
709 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 369, 14, 172, 0x0, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
710 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 26, 37, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
711 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 26, 37, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
712 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 38, 49, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
713 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 38, 49, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
714 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 50, 61, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
715 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 50, 61, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
716 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 62, 73, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
717 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 62, 73, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
718 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 74, 85, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
719 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 74, 85, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
720 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 86, 97, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
721 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 86, 97, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
722 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 98, 109, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
723 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 98, 109, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
724 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 110, 121, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
725 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 110, 121, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
726 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 122, 133, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
727 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 122, 133, STR_02B9_FULL, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
728 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 2, 61, 134, 145, STR_02B8_SUMMARY, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
729 |
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 62, 121, 134, 145, STR_02B9_FULL, STR_NULL}, |
0 | 730 |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
731 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 15, 170, 154, 165, STR_MESSAGES_DISABLE_ALL,STR_NULL }, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
745
diff
changeset
|
732 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 200, 355, 154, 165, STR_MESSAGES_ENABLE_ALL, STR_NULL }, |
0 | 733 |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
102
diff
changeset
|
734 |
{ WIDGETS_END}, |
0 | 735 |
}; |
736 |
||
737 |
static const WindowDesc _message_options_desc = { |
|
738 |
270, 22, 370, 173, |
|
427 | 739 |
WC_GAME_OPTIONS, 0, |
0 | 740 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
741 |
_message_options_widgets, |
|
742 |
MessageOptionsWndProc |
|
743 |
}; |
|
744 |
||
427 | 745 |
void ShowMessageOptions(void) |
0 | 746 |
{ |
747 |
DeleteWindowById(WC_GAME_OPTIONS, 0); |
|
748 |
AllocateWindowDesc(&_message_options_desc); |
|
749 |
} |