0
|
1 |
#include "stdafx.h"
|
|
2 |
#include "ttd.h"
|
|
3 |
|
|
4 |
#include "window.h"
|
|
5 |
#include "gui.h"
|
|
6 |
#include "viewport.h"
|
|
7 |
#include "gfx.h"
|
|
8 |
#include "news.h"
|
|
9 |
#include "vehicle.h"
|
|
10 |
|
|
11 |
static NewsItem _news_items[10];
|
|
12 |
static NewsItem _active_news_items[20];
|
|
13 |
|
|
14 |
void ExpireNewsItem();
|
|
15 |
|
|
16 |
void DrawNewsNewTrainAvail(Window *w);
|
|
17 |
void DrawNewsNewRoadVehAvail(Window *w);
|
|
18 |
void DrawNewsNewShipAvail(Window *w);
|
|
19 |
void DrawNewsNewAircraftAvail(Window *w);
|
|
20 |
void DrawNewsBankrupcy(Window *w);
|
|
21 |
|
|
22 |
StringID GetNewsStringNewTrainAvail(NewsItem *ni);
|
|
23 |
StringID GetNewsStringNewRoadVehAvail(NewsItem *ni);
|
|
24 |
StringID GetNewsStringNewShipAvail(NewsItem *ni);
|
|
25 |
StringID GetNewsStringNewAircraftAvail(NewsItem *ni);
|
|
26 |
StringID GetNewsStringBankrupcy(NewsItem *ni);
|
|
27 |
|
|
28 |
static DrawNewsCallbackProc * const _draw_news_callback[] = {
|
|
29 |
DrawNewsNewTrainAvail, /* DNC_TRAINAVAIL */
|
|
30 |
DrawNewsNewRoadVehAvail, /* DNC_ROADAVAIL */
|
|
31 |
DrawNewsNewShipAvail, /* DNC_SHIPAVAIL */
|
|
32 |
DrawNewsNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */
|
|
33 |
DrawNewsBankrupcy, /* DNC_BANKRUPCY */
|
|
34 |
};
|
|
35 |
|
|
36 |
GetNewsStringCallbackProc * const _get_news_string_callback[] = {
|
|
37 |
GetNewsStringNewTrainAvail, /* DNC_TRAINAVAIL */
|
|
38 |
GetNewsStringNewRoadVehAvail, /* DNC_ROADAVAIL */
|
|
39 |
GetNewsStringNewShipAvail, /* DNC_SHIPAVAIL */
|
|
40 |
GetNewsStringNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */
|
|
41 |
GetNewsStringBankrupcy, /* DNC_BANKRUPCY */
|
|
42 |
};
|
|
43 |
|
|
44 |
|
|
45 |
void DrawNewsBorder(Window *w)
|
|
46 |
{
|
|
47 |
int left = 0;
|
|
48 |
int right = w->width - 1;
|
|
49 |
int top = 0;
|
|
50 |
int bottom = w->height - 1;
|
|
51 |
|
|
52 |
GfxFillRect(left, top, right, bottom, 0xF);
|
|
53 |
|
|
54 |
GfxFillRect(left, top, left, bottom, 0xD7);
|
|
55 |
GfxFillRect(right, top, right, bottom, 0xD7);
|
|
56 |
GfxFillRect(left, top, right, top, 0xD7);
|
|
57 |
GfxFillRect(left, bottom, right, bottom, 0xD7);
|
|
58 |
|
|
59 |
DrawString(left + 2, top + 1, STR_00C6, 0);
|
|
60 |
}
|
|
61 |
|
|
62 |
static void NewsWindowProc(Window *w, WindowEvent *e)
|
|
63 |
{
|
|
64 |
switch(e->event) {
|
|
65 |
case WE_PAINT: {
|
|
66 |
NewsItem *ni = WP(w,news_d).ni;
|
|
67 |
ViewPort *vp;
|
|
68 |
|
|
69 |
if (ni->display_mode == NM_NORMAL || ni->display_mode == NM_THIN) {
|
|
70 |
DrawNewsBorder(w);
|
|
71 |
|
|
72 |
DrawString(2, 1, STR_00C6, 0);
|
|
73 |
|
|
74 |
SET_DPARAM16(0, ni->date);
|
|
75 |
DrawStringRightAligned(428, 1, STR_01FF, 0);
|
|
76 |
|
|
77 |
if (!(ni->flags & NF_VIEWPORT)) {
|
|
78 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
79 |
DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56, ni->string_id, 426);
|
|
80 |
} else {
|
|
81 |
byte bk = _display_opt;
|
|
82 |
_display_opt |= DO_TRANS_BUILDINGS;
|
|
83 |
DrawWindowViewport(w);
|
|
84 |
_display_opt = bk;
|
|
85 |
|
|
86 |
/* Shade the viewport into gray, or color*/
|
|
87 |
vp = w->viewport;
|
|
88 |
GfxFillRect(vp->left - w->left, vp->top - w->top, vp->left - w->left + vp->width - 1, vp->top - w->top + vp->height - 1,
|
|
89 |
ni->flags & NF_INCOLOR ? 0x4322:0x4323
|
|
90 |
);
|
|
91 |
|
|
92 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
93 |
DrawStringMultiCenter((w->width>>1), 20, ni->string_id, 428);
|
|
94 |
}
|
|
95 |
} else if (ni->display_mode == NM_CALLBACK) {
|
|
96 |
_draw_news_callback[ni->callback](w);
|
|
97 |
} else {
|
|
98 |
DrawWindowWidgets(w);
|
|
99 |
if (!(ni->flags & NF_VIEWPORT)) {
|
|
100 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
101 |
DrawStringMultiCenter(140,38, ni->string_id, 276);
|
|
102 |
} else {
|
|
103 |
DrawWindowViewport(w);
|
|
104 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
105 |
DrawStringMultiCenter((w->width>>1), w->height - 16, ni->string_id, 276);
|
|
106 |
}
|
|
107 |
}
|
|
108 |
} break;
|
|
109 |
|
|
110 |
case WE_CLICK: {
|
|
111 |
switch(e->click.widget) {
|
|
112 |
case 1:DeleteWindow(w); ExpireNewsItem(); break;
|
|
113 |
case 0: {
|
|
114 |
NewsItem *ni = WP(w,news_d).ni;
|
|
115 |
if (ni->flags & NF_VEHICLE) {
|
|
116 |
Vehicle *v = &_vehicles[ni->data_a];
|
|
117 |
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
|
118 |
} else if (ni->flags & NF_TILE) {
|
|
119 |
if (!ScrollMainWindowToTile(ni->data_a) && ni->data_b != 0)
|
|
120 |
ScrollMainWindowToTile(ni->data_b);
|
|
121 |
}
|
|
122 |
} break;
|
|
123 |
}
|
|
124 |
} break;
|
|
125 |
|
|
126 |
case WE_KEYPRESS:
|
|
127 |
if (e->keypress.keycode == WKC_SPACE) {
|
|
128 |
// Don't continue.
|
|
129 |
e->keypress.cont = false;
|
|
130 |
DeleteWindow(w);
|
|
131 |
ExpireNewsItem();
|
|
132 |
}
|
|
133 |
break;
|
|
134 |
|
|
135 |
case WE_TICK: {
|
|
136 |
int y = max(w->top - 4, _screen.height - w->height);
|
|
137 |
if (y == w->top)
|
|
138 |
return;
|
|
139 |
|
|
140 |
if (w->viewport != NULL)
|
|
141 |
w->viewport->top += y - w->top;
|
|
142 |
|
|
143 |
w->top = y;
|
|
144 |
|
|
145 |
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height + 4);
|
|
146 |
} break;
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
|
|
152 |
{
|
|
153 |
NewsItem *ni;
|
|
154 |
|
|
155 |
if (_game_mode == GM_MENU)
|
|
156 |
return;
|
|
157 |
|
|
158 |
// Find a free place and add it there.
|
|
159 |
for(ni=_news_items; ni!=endof(_news_items); ni++) {
|
|
160 |
if (ni->string_id==0) {
|
|
161 |
ni->string_id = string;
|
|
162 |
ni->display_mode = (byte)flags;
|
|
163 |
ni->flags = (byte)(flags >> 8) | NF_NOEXPIRE;
|
|
164 |
|
|
165 |
// show this news message in color?
|
|
166 |
if (_date >= ConvertIntDate(_patches.colored_news_date))
|
|
167 |
ni->flags |= NF_INCOLOR;
|
|
168 |
|
|
169 |
ni->type = (byte)(flags >> 16);
|
|
170 |
ni->callback = (byte)(flags >> 24);
|
|
171 |
ni->duration = 555;
|
|
172 |
ni->data_a = data_a;
|
|
173 |
ni->data_b = data_b;
|
|
174 |
ni->date = _date;
|
|
175 |
COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params));
|
|
176 |
break;
|
|
177 |
}
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
// _active_news_items 0..9 are the ones that have already been shown
|
|
182 |
// _active_news_items 10..19 are the ones that are to be shown next
|
|
183 |
|
|
184 |
static void MoveNewsItems()
|
|
185 |
{
|
|
186 |
Window *w;
|
|
187 |
NewsItem *ni;
|
|
188 |
|
|
189 |
// No new news item?
|
|
190 |
if (_news_items[0].string_id == 0)
|
|
191 |
return;
|
|
192 |
|
|
193 |
// Check if the status bar message is still being displayed?
|
|
194 |
w = FindWindowById(WC_STATUS_BAR, 0);
|
|
195 |
if (w != NULL && WP(w,def_d).data_1 > -1280)
|
|
196 |
return;
|
|
197 |
|
|
198 |
// Add the news items to the list of pending ones.
|
|
199 |
for(ni=_active_news_items + 10; ni != _active_news_items + 20; ni++) {
|
|
200 |
if (ni->string_id == 0) {
|
|
201 |
*ni = _news_items[0];
|
|
202 |
memcpy_overlapping(_news_items, _news_items+1, sizeof(_news_items) - sizeof(_news_items[0]) * 1);
|
|
203 |
endof(_news_items)[-1].string_id = 0;
|
|
204 |
break;
|
|
205 |
}
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
void ExpireNewsItem()
|
|
210 |
{
|
|
211 |
memcpy_overlapping(_active_news_items, _active_news_items + 1, sizeof(_active_news_items) - sizeof(_active_news_items[0]));
|
|
212 |
endof(_active_news_items)[-1].string_id = 0;
|
|
213 |
}
|
|
214 |
|
|
215 |
static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
|
|
216 |
|
|
217 |
static void RemoveOldNewsItems()
|
|
218 |
{
|
|
219 |
NewsItem *ni, *nit;
|
|
220 |
|
|
221 |
ni = _active_news_items;
|
|
222 |
do {
|
|
223 |
if (ni->string_id != 0 &&
|
|
224 |
ni != _active_news_items + 10 &&
|
|
225 |
_date - _news_items_age[ni->type] > ni->date) {
|
|
226 |
|
|
227 |
if (ni >= _active_news_items + 10) {
|
|
228 |
nit = ni;
|
|
229 |
while (nit != _active_news_items + 19) {
|
|
230 |
nit[0] = nit[1];
|
|
231 |
nit++;
|
|
232 |
}
|
|
233 |
nit->string_id = 0;
|
|
234 |
} else {
|
|
235 |
nit = ni + 1;
|
|
236 |
while (nit != _active_news_items + 1) {
|
|
237 |
nit--;
|
|
238 |
nit[0] = nit[-1];
|
|
239 |
}
|
|
240 |
_active_news_items[0].string_id = 0;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
} while (++ni != endof(_active_news_items) );
|
|
244 |
}
|
|
245 |
|
|
246 |
static const Widget _news_type13_widgets[] = {
|
|
247 |
{ WWT_PANEL, 15, 0, 429, 0, 169, 0x0},
|
|
248 |
{ WWT_PANEL, 15, 0, 10, 0, 11, 0x0},
|
|
249 |
{ WWT_LAST},
|
|
250 |
};
|
|
251 |
|
|
252 |
static WindowDesc _news_type13_desc = {
|
|
253 |
WDP_CENTER, 476, 430, 170,
|
|
254 |
WC_NEWS_WINDOW,0,
|
|
255 |
WDF_DEF_WIDGET,
|
|
256 |
_news_type13_widgets,
|
|
257 |
NewsWindowProc
|
|
258 |
};
|
|
259 |
|
|
260 |
static const Widget _news_type2_widgets[] = {
|
|
261 |
{ WWT_PANEL, 15, 0, 429, 0, 129, 0x0},
|
|
262 |
{ WWT_PANEL, 15, 0, 10, 0, 11, 0x0},
|
|
263 |
{ WWT_LAST},
|
|
264 |
};
|
|
265 |
|
|
266 |
static WindowDesc _news_type2_desc = {
|
|
267 |
WDP_CENTER, 476, 430, 130,
|
|
268 |
WC_NEWS_WINDOW,0,
|
|
269 |
WDF_DEF_WIDGET,
|
|
270 |
_news_type2_widgets,
|
|
271 |
NewsWindowProc
|
|
272 |
};
|
|
273 |
|
|
274 |
static const Widget _news_type0_widgets[] = {
|
|
275 |
{ WWT_PANEL, 5, 0, 279, 14, 86, 0x0},
|
|
276 |
{ WWT_CLOSEBOX, 5, 0, 10, 0, 13, STR_00C5},
|
|
277 |
{ WWT_CAPTION, 5, 11, 279, 0, 13, STR_012C_MESSAGE},
|
|
278 |
{ WWT_6, 5, 2, 277, 16, 64, 0},
|
|
279 |
{ WWT_LAST},
|
|
280 |
};
|
|
281 |
|
|
282 |
static WindowDesc _news_type0_desc = {
|
|
283 |
WDP_CENTER, 476, 280, 87,
|
|
284 |
WC_NEWS_WINDOW,0,
|
|
285 |
WDF_DEF_WIDGET,
|
|
286 |
_news_type0_widgets,
|
|
287 |
NewsWindowProc
|
|
288 |
};
|
|
289 |
|
|
290 |
static byte _news_sounds[] = { 27, 27, 0, 0, 0, 0, 28, 0, 0, 0 };
|
|
291 |
|
|
292 |
static void ProcessNewsItem(NewsItem *ni)
|
|
293 |
{
|
|
294 |
Window *w;
|
|
295 |
int sound;
|
|
296 |
|
|
297 |
// No news item, quit
|
|
298 |
if (ni->string_id == 0)
|
|
299 |
return;
|
|
300 |
|
|
301 |
// Delete the item once the duration reaches 0
|
|
302 |
if (ni->duration == 0) {
|
|
303 |
DeleteWindowById(WC_NEWS_WINDOW, 0);
|
|
304 |
ExpireNewsItem();
|
|
305 |
return;
|
|
306 |
}
|
|
307 |
ni->duration--;
|
|
308 |
|
|
309 |
// As long as the window still is shown, don't go further
|
|
310 |
w = FindWindowById(WC_NEWS_WINDOW, 0);
|
|
311 |
if (w != NULL)
|
|
312 |
return;
|
|
313 |
|
|
314 |
// Expire the item if NF_NOEXPIRE was removed
|
|
315 |
if (!(ni->flags & NF_NOEXPIRE)) {
|
|
316 |
ExpireNewsItem();
|
|
317 |
return;
|
|
318 |
}
|
|
319 |
|
|
320 |
if (!HASBIT(_news_display_opt, ni->type) && !(ni->flags&NF_FORCE_BIG)) {
|
|
321 |
SndPlayFx(20);
|
|
322 |
_statusbar_news_item = *ni;
|
|
323 |
w = FindWindowById(WC_STATUS_BAR, 0);
|
|
324 |
if (w != 0)
|
|
325 |
WP(w,def_d).data_1 = 360;
|
|
326 |
ExpireNewsItem();
|
|
327 |
} else {
|
|
328 |
int top;
|
|
329 |
|
|
330 |
ni->flags &= ~(NF_NOEXPIRE|NF_FORCE_BIG);
|
|
331 |
|
|
332 |
sound = _news_sounds[ni->type];
|
|
333 |
if (sound != 0)
|
|
334 |
SndPlayFx(sound);
|
|
335 |
|
|
336 |
top = _screen.height - 4;
|
|
337 |
if (ni->display_mode == NM_NORMAL || ni->display_mode == NM_CALLBACK) {
|
|
338 |
_news_type13_desc.top = top;
|
|
339 |
w = AllocateWindowDesc(&_news_type13_desc);
|
|
340 |
if (ni->flags & NF_VIEWPORT) {
|
|
341 |
AssignWindowViewport(w, 2, 58, 0x1AA, 0x6E, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0);
|
|
342 |
}
|
|
343 |
} else if (ni->display_mode == NM_THIN) {
|
|
344 |
_news_type2_desc.top = top;
|
|
345 |
w = AllocateWindowDesc(&_news_type2_desc);
|
|
346 |
if (ni->flags & NF_VIEWPORT) {
|
|
347 |
AssignWindowViewport(w, 2, 58, 0x1AA, 0x46, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0);
|
|
348 |
}
|
|
349 |
} else {
|
|
350 |
_news_type0_desc.top = top;
|
|
351 |
w = AllocateWindowDesc(&_news_type0_desc);
|
|
352 |
if (ni->flags & NF_VIEWPORT) {
|
|
353 |
AssignWindowViewport(w, 3, 17, 0x112, 0x2F, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0);
|
|
354 |
}
|
|
355 |
}
|
|
356 |
WP(w,news_d).ni = _active_news_items + 10;
|
|
357 |
w->flags4 |= WF_DISABLE_VP_SCROLL;
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
void NewsLoop()
|
|
362 |
{
|
|
363 |
RemoveOldNewsItems();
|
|
364 |
MoveNewsItems();
|
|
365 |
ProcessNewsItem(_active_news_items + 10);
|
|
366 |
}
|
|
367 |
|
|
368 |
void ShowLastNewsMessage()
|
|
369 |
{
|
|
370 |
// No news item immediately before 10?
|
|
371 |
if (_active_news_items[9].string_id == 0)
|
|
372 |
return;
|
|
373 |
|
|
374 |
// Delete the news window
|
|
375 |
DeleteWindowById(WC_NEWS_WINDOW, 0);
|
|
376 |
|
|
377 |
// Move all items one step
|
|
378 |
memmove(_active_news_items+1, _active_news_items, sizeof(NewsItem)*19);
|
|
379 |
_active_news_items[0].string_id = 0;
|
|
380 |
|
|
381 |
// Default duration and flags for re-shown items
|
|
382 |
_active_news_items[10].duration = 555;
|
|
383 |
_active_news_items[10].flags |= NF_NOEXPIRE | NF_FORCE_BIG;
|
|
384 |
}
|
|
385 |
|
|
386 |
void InitNewsItemStructs()
|
|
387 |
{
|
|
388 |
memset(_news_items, 0, sizeof(_news_items));
|
|
389 |
memset(_active_news_items, 0, sizeof(_active_news_items));
|
|
390 |
}
|
|
391 |
|
|
392 |
static void MessageOptionsWndProc(Window *w, WindowEvent *e)
|
|
393 |
{
|
|
394 |
switch(e->event) {
|
|
395 |
case WE_PAINT: {
|
|
396 |
uint16 x = _news_display_opt;
|
|
397 |
uint32 cs = 0;
|
|
398 |
int i, y;
|
|
399 |
|
|
400 |
for(i=3; i!=23; i+=2) {
|
|
401 |
cs |= 1 << (i + (x&1));
|
|
402 |
x >>= 1;
|
|
403 |
}
|
|
404 |
cs |= (w->click_state >> 23) << 23;
|
|
405 |
|
|
406 |
w->click_state = cs;
|
|
407 |
DrawWindowWidgets(w);
|
|
408 |
|
|
409 |
DrawStringCentered(185, 15, STR_0205_MESSAGE_TYPES, 0);
|
|
410 |
|
|
411 |
y = 27;
|
|
412 |
for(i=STR_0206_ARRIVAL_OF_FIRST_VEHICLE; i <= STR_020F_GENERAL_INFORMATION; i++) {
|
|
413 |
DrawString(124, y, i, 0);
|
|
414 |
y += 12;
|
|
415 |
}
|
|
416 |
|
|
417 |
break;
|
|
418 |
}
|
|
419 |
|
|
420 |
case WE_CLICK: {
|
|
421 |
int wid;
|
|
422 |
if ( (uint)(wid=e->click.widget - 3) < 20) {
|
|
423 |
if (!(wid & 1)) {
|
|
424 |
_news_display_opt &= ~(1 << (wid>>1));
|
|
425 |
} else {
|
|
426 |
_news_display_opt |= (1 << (wid>>1));
|
|
427 |
}
|
|
428 |
SetWindowDirty(w);
|
|
429 |
/* XXX: write settings */
|
|
430 |
}
|
|
431 |
if( e->click.widget == 23) {
|
|
432 |
_news_display_opt = 0;
|
|
433 |
HandleButtonClick(w, 23);
|
|
434 |
SetWindowDirty(w);
|
|
435 |
}
|
|
436 |
if( e->click.widget == 24) {
|
|
437 |
_news_display_opt = ~0;
|
|
438 |
HandleButtonClick(w, 24);
|
|
439 |
SetWindowDirty(w);
|
|
440 |
}
|
|
441 |
} break;
|
|
442 |
}
|
|
443 |
}
|
|
444 |
|
|
445 |
static const Widget _message_options_widgets[] = {
|
|
446 |
{ WWT_CLOSEBOX, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
447 |
{ WWT_CAPTION, 13, 11, 369, 0, 13, STR_0204_MESSAGE_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
448 |
{ WWT_PANEL, 13, 0, 369, 14, 172, 0x0},
|
|
449 |
{ WWT_CLOSEBOX, 3, 2, 61, 26, 37, STR_02B8_SUMMARY},
|
|
450 |
{ WWT_CLOSEBOX, 3, 62, 121, 26, 37, STR_02B9_FULL},
|
|
451 |
{ WWT_CLOSEBOX, 3, 2, 61, 38, 49, STR_02B8_SUMMARY},
|
|
452 |
{ WWT_CLOSEBOX, 3, 62, 121, 38, 49, STR_02B9_FULL},
|
|
453 |
{ WWT_CLOSEBOX, 3, 2, 61, 50, 61, STR_02B8_SUMMARY},
|
|
454 |
{ WWT_CLOSEBOX, 3, 62, 121, 50, 61, STR_02B9_FULL},
|
|
455 |
{ WWT_CLOSEBOX, 3, 2, 61, 62, 73, STR_02B8_SUMMARY},
|
|
456 |
{ WWT_CLOSEBOX, 3, 62, 121, 62, 73, STR_02B9_FULL},
|
|
457 |
{ WWT_CLOSEBOX, 3, 2, 61, 74, 85, STR_02B8_SUMMARY},
|
|
458 |
{ WWT_CLOSEBOX, 3, 62, 121, 74, 85, STR_02B9_FULL},
|
|
459 |
{ WWT_CLOSEBOX, 3, 2, 61, 86, 97, STR_02B8_SUMMARY},
|
|
460 |
{ WWT_CLOSEBOX, 3, 62, 121, 86, 97, STR_02B9_FULL},
|
|
461 |
{ WWT_CLOSEBOX, 3, 2, 61, 98, 109, STR_02B8_SUMMARY},
|
|
462 |
{ WWT_CLOSEBOX, 3, 62, 121, 98, 109, STR_02B9_FULL},
|
|
463 |
{ WWT_CLOSEBOX, 3, 2, 61, 110, 121, STR_02B8_SUMMARY},
|
|
464 |
{ WWT_CLOSEBOX, 3, 62, 121, 110, 121, STR_02B9_FULL},
|
|
465 |
{ WWT_CLOSEBOX, 3, 2, 61, 122, 133, STR_02B8_SUMMARY},
|
|
466 |
{ WWT_CLOSEBOX, 3, 62, 121, 122, 133, STR_02B9_FULL},
|
|
467 |
{ WWT_CLOSEBOX, 3, 2, 61, 134, 145, STR_02B8_SUMMARY},
|
|
468 |
{ WWT_CLOSEBOX, 3, 62, 121, 134, 145, STR_02B9_FULL},
|
|
469 |
|
|
470 |
{ WWT_PUSHTXTBTN, 3, 15, 170, 154, 165, STR_MESSAGES_DISABLE_ALL, STR_NULL },
|
|
471 |
{ WWT_PUSHTXTBTN, 3, 200, 355, 154, 165, STR_MESSAGES_ENABLE_ALL, STR_NULL },
|
|
472 |
|
|
473 |
{ WWT_LAST},
|
|
474 |
};
|
|
475 |
|
|
476 |
static const WindowDesc _message_options_desc = {
|
|
477 |
270, 22, 370, 173,
|
|
478 |
WC_GAME_OPTIONS,0,
|
|
479 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
480 |
_message_options_widgets,
|
|
481 |
MessageOptionsWndProc
|
|
482 |
};
|
|
483 |
|
|
484 |
|
|
485 |
|
|
486 |
|
|
487 |
void ShowMessageOptions()
|
|
488 |
{
|
|
489 |
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
|
490 |
AllocateWindowDesc(&_message_options_desc);
|
|
491 |
}
|
|
492 |
|
|
493 |
|
|
494 |
static void GetNewsString(NewsItem *ni, byte *buffer)
|
|
495 |
{
|
|
496 |
StringID str;
|
|
497 |
byte *s, *d;
|
|
498 |
|
|
499 |
if (ni->display_mode == 3) {
|
|
500 |
str = _get_news_string_callback[ni->callback](ni);
|
|
501 |
} else {
|
|
502 |
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
503 |
str = ni->string_id;
|
|
504 |
}
|
|
505 |
|
|
506 |
GetString(str_buffr, str);
|
|
507 |
assert(strlen(str_buffr) < sizeof(str_buffr) - 1);
|
|
508 |
|
|
509 |
s = str_buffr;
|
|
510 |
d = buffer;
|
|
511 |
|
|
512 |
for(;;s++) {
|
|
513 |
// cut strings that are too long
|
|
514 |
if(s >= str_buffr + 55) {
|
|
515 |
d[0] = d[1] = d[2] = '.';
|
|
516 |
d+=3;
|
|
517 |
*d = 0;
|
|
518 |
break;
|
|
519 |
}
|
|
520 |
|
|
521 |
if (*s == 0) {
|
|
522 |
*d = 0;
|
|
523 |
break;
|
|
524 |
} else if (*s == 13) {
|
|
525 |
d[0] = d[1] = d[2] = d[3] = ' ';
|
|
526 |
d+=4;
|
|
527 |
} else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) {
|
|
528 |
*d++ = *s;
|
|
529 |
}
|
|
530 |
}
|
|
531 |
}
|
|
532 |
|
|
533 |
|
|
534 |
static void MessageHistoryWndProc(Window *w, WindowEvent *e)
|
|
535 |
{
|
|
536 |
switch(e->event) {
|
|
537 |
case WE_PAINT: {
|
|
538 |
uint n, y, i;
|
|
539 |
char buffer[256];
|
|
540 |
NewsItem *ni;
|
|
541 |
|
|
542 |
for(n=10; n!=0; n--)
|
|
543 |
if (!_active_news_items[n - 1].string_id)
|
|
544 |
break;
|
|
545 |
n = 10 - n;
|
|
546 |
|
|
547 |
SetVScrollCount(w, n);
|
|
548 |
DrawWindowWidgets(w);
|
|
549 |
|
|
550 |
y = 18;
|
|
551 |
for(i=w->vscroll.pos; i!=n; i++) {
|
|
552 |
ni = &_active_news_items[i + (10 - n)];
|
|
553 |
|
|
554 |
assert(ni->string_id);
|
|
555 |
|
|
556 |
SET_DPARAM16(0, ni->date);
|
|
557 |
DrawString(4, y, STR_00AF, 16);
|
|
558 |
|
|
559 |
GetNewsString(ni, buffer);
|
|
560 |
DoDrawString(buffer, 85, y, 16);
|
|
561 |
y += 12;
|
|
562 |
}
|
|
563 |
break;
|
|
564 |
}
|
|
565 |
|
|
566 |
case WE_CLICK:
|
|
567 |
switch(e->click.widget) {
|
|
568 |
case 2: {
|
|
569 |
uint y = (e->click.pt.y - 18) / 12;
|
|
570 |
NewsItem *ni;
|
|
571 |
|
|
572 |
if (y >= (uint)w->vscroll.count)
|
|
573 |
return;
|
|
574 |
|
|
575 |
ni = &_active_news_items[w->vscroll.pos + y + (10 - w->vscroll.count)];
|
|
576 |
|
|
577 |
// NOT YET...
|
|
578 |
// ShowNewsMessage(y);
|
|
579 |
|
|
580 |
break;
|
|
581 |
}
|
|
582 |
}
|
|
583 |
break;
|
|
584 |
}
|
|
585 |
}
|
|
586 |
|
|
587 |
static const Widget _message_history_widgets[] = {
|
|
588 |
{ WWT_CLOSEBOX, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
589 |
{ WWT_CAPTION, 13, 11, 399, 0, 13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
590 |
{ WWT_IMGBTN, 13, 0, 388, 14, 147, 0x0, STR_MESSAGE_HISTORY_TIP},
|
|
591 |
{ WWT_SCROLLBAR, 13, 389, 399, 14, 147, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
592 |
{ WWT_LAST},
|
|
593 |
};
|
|
594 |
|
|
595 |
static const WindowDesc _message_history_desc = {
|
|
596 |
240, 22, 400, 148,
|
|
597 |
WC_MESSAGE_HISTORY,0,
|
|
598 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
599 |
_message_history_widgets,
|
|
600 |
MessageHistoryWndProc
|
|
601 |
};
|
|
602 |
|
|
603 |
void ShowMessageHistory()
|
|
604 |
{
|
|
605 |
Window *w;
|
|
606 |
|
|
607 |
DeleteWindowById(WC_MESSAGE_HISTORY, 0);
|
|
608 |
w = AllocateWindowDesc(&_message_history_desc);
|
|
609 |
|
|
610 |
if (w) {
|
|
611 |
w->vscroll.cap = 11;
|
|
612 |
SetWindowDirty(w);
|
|
613 |
}
|
|
614 |
}
|
|
615 |
|