10249
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
/** @file main_gui.cpp */
|
|
4 |
|
|
5 |
#include "stdafx.h"
|
|
6 |
#include "openttd.h"
|
|
7 |
#include "settings_type.h"
|
|
8 |
#include "date_func.h"
|
|
9 |
#include "gfx_func.h"
|
|
10 |
#include "news_func.h"
|
|
11 |
#include "player_func.h"
|
|
12 |
#include "string_func.h"
|
|
13 |
#include "strings_func.h"
|
|
14 |
#include "player_base.h"
|
|
15 |
#include "viewport_func.h"
|
|
16 |
#include "news_gui.h"
|
|
17 |
#include "player_gui.h"
|
|
18 |
#include "window_gui.h"
|
|
19 |
#include "variables.h"
|
|
20 |
|
|
21 |
#include "table/strings.h"
|
|
22 |
#include "table/sprites.h"
|
|
23 |
|
|
24 |
extern GetNewsStringCallbackProc * const _get_news_string_callback[];
|
|
25 |
|
|
26 |
static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width)
|
|
27 |
{
|
|
28 |
StringID str;
|
|
29 |
if (ni->display_mode == NM_CALLBACK) {
|
|
30 |
str = _get_news_string_callback[ni->callback](ni);
|
|
31 |
} else {
|
|
32 |
CopyInDParam(0, ni->params, lengthof(ni->params));
|
|
33 |
str = ni->string_id;
|
|
34 |
}
|
|
35 |
|
|
36 |
char buf[512];
|
|
37 |
GetString(buf, str, lastof(buf));
|
|
38 |
const char *s = buf;
|
|
39 |
|
|
40 |
char buffer[256];
|
|
41 |
char *d = buffer;
|
|
42 |
const char *last = lastof(buffer);
|
|
43 |
|
|
44 |
for (;;) {
|
|
45 |
WChar c = Utf8Consume(&s);
|
|
46 |
if (c == 0) {
|
|
47 |
break;
|
|
48 |
} else if (c == 0x0D) {
|
|
49 |
if (d + 4 >= last) break;
|
|
50 |
d[0] = d[1] = d[2] = d[3] = ' ';
|
|
51 |
d += 4;
|
|
52 |
} else if (IsPrintable(c)) {
|
|
53 |
if (d + Utf8CharLen(c) >= last) break;
|
|
54 |
d += Utf8Encode(d, c);
|
|
55 |
}
|
|
56 |
}
|
|
57 |
*d = '\0';
|
|
58 |
|
|
59 |
DrawPixelInfo tmp_dpi;
|
|
60 |
if (!FillDrawPixelInfo(&tmp_dpi, 141, 1, width, 11)) return true;
|
|
61 |
|
|
62 |
DrawPixelInfo *old_dpi = _cur_dpi;
|
|
63 |
_cur_dpi = &tmp_dpi;
|
|
64 |
|
|
65 |
int x = DoDrawString(buffer, pos, 0, TC_LIGHT_BLUE);
|
|
66 |
_cur_dpi = old_dpi;
|
|
67 |
|
|
68 |
return x > 0;
|
|
69 |
}
|
|
70 |
|
|
71 |
static void StatusBarWndProc(Window *w, WindowEvent *e)
|
|
72 |
{
|
|
73 |
switch (e->event) {
|
|
74 |
case WE_PAINT: {
|
|
75 |
const Player *p = (_local_player == PLAYER_SPECTATOR) ? NULL : GetPlayer(_local_player);
|
|
76 |
|
|
77 |
DrawWindowWidgets(w);
|
|
78 |
SetDParam(0, _date);
|
|
79 |
DrawStringCentered(70, 1, (_pause_game || _patches.status_long_date) ? STR_00AF : STR_00AE, TC_FROMSTRING);
|
|
80 |
|
|
81 |
if (p != NULL) {
|
|
82 |
/* Draw player money */
|
|
83 |
SetDParam(0, p->player_money);
|
|
84 |
DrawStringCentered(w->widget[2].left + 70, 1, STR_0004, TC_FROMSTRING);
|
|
85 |
}
|
|
86 |
|
|
87 |
/* Draw status bar */
|
|
88 |
if (w->message.msg) { // true when saving is active
|
|
89 |
DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING);
|
|
90 |
} else if (_do_autosave) {
|
|
91 |
DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING);
|
|
92 |
} else if (_pause_game) {
|
|
93 |
DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING);
|
|
94 |
} else if (WP(w, def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) {
|
|
95 |
/* Draw the scrolling news text */
|
|
96 |
if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w, def_d).data_1, w->widget[1].right - w->widget[1].left - 2)) {
|
|
97 |
WP(w, def_d).data_1 = -1280;
|
|
98 |
if (p != NULL) {
|
|
99 |
/* This is the default text */
|
|
100 |
SetDParam(0, p->index);
|
|
101 |
DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
|
|
102 |
}
|
|
103 |
}
|
|
104 |
} else {
|
|
105 |
if (p != NULL) {
|
|
106 |
/* This is the default text */
|
|
107 |
SetDParam(0, p->index);
|
|
108 |
DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
|
|
109 |
}
|
|
110 |
}
|
|
111 |
|
|
112 |
if (WP(w, def_d).data_2 > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, w->widget[1].right - 11, 2);
|
|
113 |
} break;
|
|
114 |
|
|
115 |
case WE_MESSAGE:
|
|
116 |
w->message.msg = e->we.message.msg;
|
|
117 |
SetWindowDirty(w);
|
|
118 |
break;
|
|
119 |
|
|
120 |
case WE_CLICK:
|
|
121 |
switch (e->we.click.widget) {
|
|
122 |
case 1: ShowLastNewsMessage(); break;
|
|
123 |
case 2: if (_local_player != PLAYER_SPECTATOR) ShowPlayerFinances(_local_player); break;
|
|
124 |
default: ResetObjectToPlace();
|
|
125 |
}
|
|
126 |
break;
|
|
127 |
|
|
128 |
case WE_TICK: {
|
|
129 |
if (_pause_game) return;
|
|
130 |
|
|
131 |
if (WP(w, def_d).data_1 > -1280) { // Scrolling text
|
|
132 |
WP(w, def_d).data_1 -= 2;
|
|
133 |
w->InvalidateWidget(1);
|
|
134 |
}
|
|
135 |
|
|
136 |
if (WP(w, def_d).data_2 > 0) { // Red blot to show there are new unread newsmessages
|
|
137 |
WP(w, def_d).data_2 -= 2;
|
|
138 |
} else if (WP(w, def_d).data_2 < 0) {
|
|
139 |
WP(w, def_d).data_2 = 0;
|
|
140 |
w->InvalidateWidget(1);
|
|
141 |
}
|
|
142 |
|
|
143 |
} break;
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
static const Widget _main_status_widgets[] = {
|
|
148 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 139, 0, 11, 0x0, STR_NULL},
|
|
149 |
{ WWT_PUSHBTN, RESIZE_RIGHT, 14, 140, 179, 0, 11, 0x0, STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS},
|
|
150 |
{ WWT_PUSHBTN, RESIZE_LR, 14, 180, 319, 0, 11, 0x0, STR_NULL},
|
|
151 |
{ WIDGETS_END},
|
|
152 |
};
|
|
153 |
|
|
154 |
static WindowDesc _main_status_desc = {
|
|
155 |
WDP_CENTER, 0, 320, 12, 640, 12,
|
|
156 |
WC_STATUS_BAR, WC_NONE,
|
|
157 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
158 |
_main_status_widgets,
|
|
159 |
StatusBarWndProc
|
|
160 |
};
|
|
161 |
|
|
162 |
void ShowStatusBar()
|
|
163 |
{
|
|
164 |
_main_status_desc.top = _screen.height - 12;
|
|
165 |
Window *w = AllocateWindowDesc(&_main_status_desc);
|
|
166 |
if (w != NULL) {
|
|
167 |
CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
|
|
168 |
WP(w, def_d).data_1 = -1280;
|
|
169 |
}
|
|
170 |
}
|