61 _cur_dpi = old_dpi; |
61 _cur_dpi = old_dpi; |
62 |
62 |
63 return x > 0; |
63 return x > 0; |
64 } |
64 } |
65 |
65 |
66 static void StatusBarWndProc(Window *w, WindowEvent *e) |
66 struct StatusBarWindow : Window { |
67 { |
67 bool saving; |
68 switch (e->event) { |
68 int ticker_scroll; |
69 case WE_PAINT: { |
69 int reminder_timeout; |
70 const Player *p = (_local_player == PLAYER_SPECTATOR) ? NULL : GetPlayer(_local_player); |
|
71 |
70 |
72 DrawWindowWidgets(w); |
71 StatusBarWindow(const WindowDesc *desc) : Window(desc) |
73 SetDParam(0, _date); |
72 { |
74 DrawStringCentered(70, 1, (_pause_game || _patches.status_long_date) ? STR_00AF : STR_00AE, TC_FROMSTRING); |
73 CLRBITS(this->flags4, WF_WHITE_BORDER_MASK); |
|
74 this->ticker_scroll = -1280; |
75 |
75 |
76 if (p != NULL) { |
76 this->FindWindowPlacementAndResize(desc); |
77 /* Draw player money */ |
77 } |
78 SetDParam(0, p->player_money); |
|
79 DrawStringCentered(w->widget[2].left + 70, 1, STR_0004, TC_FROMSTRING); |
|
80 } |
|
81 |
78 |
82 /* Draw status bar */ |
79 virtual void OnPaint() |
83 if (WP(w, def_d).data_3) { // true when saving is active |
80 { |
84 DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING); |
81 const Player *p = (_local_player == PLAYER_SPECTATOR) ? NULL : GetPlayer(_local_player); |
85 } else if (_do_autosave) { |
82 |
86 DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING); |
83 DrawWindowWidgets(this); |
87 } else if (_pause_game) { |
84 SetDParam(0, _date); |
88 DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING); |
85 DrawStringCentered(70, 1, (_pause_game || _patches.status_long_date) ? STR_00AF : STR_00AE, TC_FROMSTRING); |
89 } else if (WP(w, def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) { |
86 |
90 /* Draw the scrolling news text */ |
87 if (p != NULL) { |
91 if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w, def_d).data_1, w->widget[1].right - w->widget[1].left - 2)) { |
88 /* Draw player money */ |
92 WP(w, def_d).data_1 = -1280; |
89 SetDParam(0, p->player_money); |
93 if (p != NULL) { |
90 DrawStringCentered(this->widget[2].left + 70, 1, STR_0004, TC_FROMSTRING); |
94 /* This is the default text */ |
91 } |
95 SetDParam(0, p->index); |
92 |
96 DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING); |
93 /* Draw status bar */ |
97 } |
94 if (this->saving) { // true when saving is active |
98 } |
95 DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING); |
99 } else { |
96 } else if (_do_autosave) { |
|
97 DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING); |
|
98 } else if (_pause_game) { |
|
99 DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING); |
|
100 } else if (this->ticker_scroll > -1280 && FindWindowById(WC_NEWS_WINDOW, 0) == NULL && _statusbar_news_item.string_id != 0) { |
|
101 /* Draw the scrolling news text */ |
|
102 if (!DrawScrollingStatusText(&_statusbar_news_item, this->ticker_scroll, this->widget[1].right - this->widget[1].left - 2)) { |
|
103 this->ticker_scroll = -1280; |
100 if (p != NULL) { |
104 if (p != NULL) { |
101 /* This is the default text */ |
105 /* This is the default text */ |
102 SetDParam(0, p->index); |
106 SetDParam(0, p->index); |
103 DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING); |
107 DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING); |
104 } |
108 } |
105 } |
109 } |
|
110 } else { |
|
111 if (p != NULL) { |
|
112 /* This is the default text */ |
|
113 SetDParam(0, p->index); |
|
114 DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING); |
|
115 } |
|
116 } |
106 |
117 |
107 if (WP(w, def_d).data_2 > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, w->widget[1].right - 11, 2); |
118 if (this->reminder_timeout > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, this->widget[1].right - 11, 2); |
108 } break; |
119 } |
109 |
120 |
110 case WE_INVALIDATE_DATA: |
121 virtual void OnInvalidateData(int data) |
111 switch (e->we.invalidate.data) { |
122 { |
112 default: NOT_REACHED(); |
123 switch (data) { |
113 case SBI_SAVELOAD_START: WP(w, def_d).data_3 = true; break; |
124 default: NOT_REACHED(); |
114 case SBI_SAVELOAD_FINISH: WP(w, def_d).data_3 = false; break; |
125 case SBI_SAVELOAD_START: this->saving = true; break; |
115 case SBI_SHOW_TICKER: WP(w, def_d).data_1 = 360; break; |
126 case SBI_SAVELOAD_FINISH: this->saving = false; break; |
116 case SBI_SHOW_REMINDER: WP(w, def_d).data_2 = 91; break; |
127 case SBI_SHOW_TICKER: this->ticker_scroll = 360; break; |
117 } |
128 case SBI_SHOW_REMINDER: this->reminder_timeout = 91; break; |
118 break; |
129 } |
|
130 } |
119 |
131 |
120 case WE_CLICK: |
132 virtual void OnClick(Point pt, int widget) |
121 switch (e->we.click.widget) { |
133 { |
122 case 1: ShowLastNewsMessage(); break; |
134 switch (widget) { |
123 case 2: if (_local_player != PLAYER_SPECTATOR) ShowPlayerFinances(_local_player); break; |
135 case 1: ShowLastNewsMessage(); break; |
124 default: ResetObjectToPlace(); |
136 case 2: if (_local_player != PLAYER_SPECTATOR) ShowPlayerFinances(_local_player); break; |
125 } |
137 default: ResetObjectToPlace(); |
126 break; |
138 } |
|
139 } |
127 |
140 |
128 case WE_TICK: { |
141 virtual void OnTick() |
129 if (_pause_game) return; |
142 { |
|
143 if (_pause_game) return; |
130 |
144 |
131 if (WP(w, def_d).data_1 > -1280) { // Scrolling text |
145 if (this->ticker_scroll > -1280) { // Scrolling text |
132 WP(w, def_d).data_1 -= 2; |
146 this->ticker_scroll -= 2; |
133 w->InvalidateWidget(1); |
147 this->InvalidateWidget(1); |
134 } |
148 } |
135 |
149 |
136 if (WP(w, def_d).data_2 > 0) { // Red blot to show there are new unread newsmessages |
150 if (this->reminder_timeout > 0) { // Red blot to show there are new unread newsmessages |
137 WP(w, def_d).data_2 -= 2; |
151 this->reminder_timeout -= 2; |
138 } else if (WP(w, def_d).data_2 < 0) { |
152 } else if (this->reminder_timeout < 0) { |
139 WP(w, def_d).data_2 = 0; |
153 this->reminder_timeout = 0; |
140 w->InvalidateWidget(1); |
154 this->InvalidateWidget(1); |
141 } |
155 } |
142 |
|
143 } break; |
|
144 } |
156 } |
145 } |
157 }; |
146 |
158 |
147 static const Widget _main_status_widgets[] = { |
159 static const Widget _main_status_widgets[] = { |
148 { WWT_PANEL, RESIZE_NONE, 14, 0, 139, 0, 11, 0x0, STR_NULL}, |
160 { 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}, |
161 { 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}, |
162 { WWT_PUSHBTN, RESIZE_LR, 14, 180, 319, 0, 11, 0x0, STR_NULL}, |
154 static WindowDesc _main_status_desc = { |
166 static WindowDesc _main_status_desc = { |
155 WDP_CENTER, 0, 320, 12, 640, 12, |
167 WDP_CENTER, 0, 320, 12, 640, 12, |
156 WC_STATUS_BAR, WC_NONE, |
168 WC_STATUS_BAR, WC_NONE, |
157 WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
169 WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
158 _main_status_widgets, |
170 _main_status_widgets, |
159 StatusBarWndProc |
171 NULL |
160 }; |
172 }; |
161 |
173 |
162 /** |
174 /** |
163 * Checks whether the news ticker is currently being used. |
175 * Checks whether the news ticker is currently being used. |
164 */ |
176 */ |
165 bool IsNewsTickerShown() |
177 bool IsNewsTickerShown() |
166 { |
178 { |
167 const Window *w = FindWindowById(WC_STATUS_BAR, 0); |
179 const StatusBarWindow *w = dynamic_cast<StatusBarWindow*>(FindWindowById(WC_STATUS_BAR, 0)); |
168 return w != NULL && WP(w, const def_d).data_1 > -1280; |
180 return w != NULL && w->ticker_scroll > -1280; |
169 } |
181 } |
170 |
182 |
171 void ShowStatusBar() |
183 void ShowStatusBar() |
172 { |
184 { |
173 _main_status_desc.top = _screen.height - 12; |
185 _main_status_desc.top = _screen.height - 12; |
174 Window *w = new Window(&_main_status_desc); |
186 new StatusBarWindow(&_main_status_desc); |
175 if (w != NULL) { |
|
176 CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); |
|
177 WP(w, def_d).data_1 = -1280; |
|
178 } |
|
179 } |
187 } |