2008-04-18 15:13:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file statusbar_gui.cpp The GUI for the bottom status bar. */
|
2008-04-18 15:13:45 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
|
|
|
#include "settings_type.h"
|
|
|
|
#include "date_func.h"
|
|
|
|
#include "gfx_func.h"
|
|
|
|
#include "news_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2008-04-18 15:13:45 +00:00
|
|
|
#include "string_func.h"
|
|
|
|
#include "strings_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_base.h"
|
2008-05-08 13:29:35 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2008-04-18 15:13:45 +00:00
|
|
|
#include "news_gui.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_gui.h"
|
2008-04-18 15:13:45 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "variables.h"
|
2008-05-06 22:17:12 +00:00
|
|
|
#include "window_func.h"
|
2008-05-16 07:08:04 +00:00
|
|
|
#include "statusbar_gui.h"
|
2008-04-18 15:13:45 +00:00
|
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
|
2009-05-12 20:01:39 +00:00
|
|
|
static bool DrawScrollingStatusText(const NewsItem *ni, int scroll_pos, int left, int right, int top, int bottom)
|
2008-04-18 15:13:45 +00:00
|
|
|
{
|
2008-05-13 10:17:04 +00:00
|
|
|
CopyInDParam(0, ni->params, lengthof(ni->params));
|
|
|
|
StringID str = ni->string_id;
|
2008-04-18 15:13:45 +00:00
|
|
|
|
|
|
|
char buf[512];
|
|
|
|
GetString(buf, str, lastof(buf));
|
|
|
|
const char *s = buf;
|
|
|
|
|
|
|
|
char buffer[256];
|
|
|
|
char *d = buffer;
|
|
|
|
const char *last = lastof(buffer);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
WChar c = Utf8Consume(&s);
|
|
|
|
if (c == 0) {
|
|
|
|
break;
|
2009-03-02 21:01:19 +00:00
|
|
|
} else if (c == '\n') {
|
2008-04-18 15:13:45 +00:00
|
|
|
if (d + 4 >= last) break;
|
|
|
|
d[0] = d[1] = d[2] = d[3] = ' ';
|
|
|
|
d += 4;
|
|
|
|
} else if (IsPrintable(c)) {
|
|
|
|
if (d + Utf8CharLen(c) >= last) break;
|
|
|
|
d += Utf8Encode(d, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*d = '\0';
|
|
|
|
|
|
|
|
DrawPixelInfo tmp_dpi;
|
2009-05-12 20:01:39 +00:00
|
|
|
if (!FillDrawPixelInfo(&tmp_dpi, left, top, right - left, bottom)) return true;
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2009-05-12 22:28:18 +00:00
|
|
|
int width = GetStringBoundingBox(buffer).width;
|
|
|
|
int pos = (_dynlang.text_dir == TD_RTL) ? (scroll_pos - width) : (right - scroll_pos - left);
|
|
|
|
|
2008-04-18 15:13:45 +00:00
|
|
|
DrawPixelInfo *old_dpi = _cur_dpi;
|
|
|
|
_cur_dpi = &tmp_dpi;
|
2009-05-12 22:28:18 +00:00
|
|
|
DrawString(pos, INT16_MAX, 0, buffer, TC_LIGHT_BLUE, SA_LEFT | SA_FORCE);
|
2008-04-18 15:13:45 +00:00
|
|
|
_cur_dpi = old_dpi;
|
|
|
|
|
2009-05-12 22:28:18 +00:00
|
|
|
return (_dynlang.text_dir == TD_RTL) ? (pos < right - left) : (pos + width > 0);
|
2008-04-18 15:13:45 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 12:38:18 +00:00
|
|
|
enum StatusbarWidget {
|
|
|
|
SBW_LEFT, ///< left part of the statusbar; date is shown there
|
|
|
|
SBW_MIDDLE, ///< middle part; current news or company name or *** SAVING *** or *** PAUSED ***
|
|
|
|
SBW_RIGHT, ///< right part; bank balance
|
|
|
|
};
|
|
|
|
|
2008-05-16 07:24:21 +00:00
|
|
|
struct StatusBarWindow : Window {
|
|
|
|
bool saving;
|
|
|
|
int ticker_scroll;
|
|
|
|
int reminder_timeout;
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2009-01-09 23:49:46 +00:00
|
|
|
enum {
|
2009-05-12 22:28:18 +00:00
|
|
|
TICKER_STOP = 1640, ///< scrolling is finished when counter reaches this value
|
|
|
|
REMINDER_START = 91, ///< initial value of the reminder counter (right dot on the right)
|
|
|
|
REMINDER_STOP = 0, ///< reminder disappears when counter reaches this value
|
|
|
|
COUNTER_STEP = 2, ///< this is subtracted from active counters every tick
|
2009-01-09 23:49:46 +00:00
|
|
|
};
|
|
|
|
|
2008-05-16 07:24:21 +00:00
|
|
|
StatusBarWindow(const WindowDesc *desc) : Window(desc)
|
|
|
|
{
|
|
|
|
CLRBITS(this->flags4, WF_WHITE_BORDER_MASK);
|
2009-01-09 23:49:46 +00:00
|
|
|
this->ticker_scroll = TICKER_STOP;
|
|
|
|
this->reminder_timeout = REMINDER_STOP;
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2008-05-16 07:24:21 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2008-05-16 07:24:21 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Company *c = (_local_company == COMPANY_SPECTATOR) ? NULL : Company::Get(_local_company);
|
2008-05-16 07:24:21 +00:00
|
|
|
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2008-05-16 07:24:21 +00:00
|
|
|
SetDParam(0, _date);
|
2009-05-06 15:06:57 +00:00
|
|
|
DrawString(this->widget[SBW_LEFT].left + 1, this->widget[SBW_LEFT].right - 1, 1, (_pause_mode || _settings_client.gui.status_long_date) ? STR_DATE_LONG_WHITE : STR_DATE_SHORT_WHITE, TC_FROMSTRING, SA_CENTER);
|
2008-05-16 07:24:21 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c != NULL) {
|
|
|
|
/* Draw company money */
|
|
|
|
SetDParam(0, c->money);
|
2009-04-21 23:40:56 +00:00
|
|
|
DrawString(this->widget[SBW_RIGHT].left + 1, this->widget[SBW_RIGHT].right - 1, 1, STR_COMPANY_MONEY, TC_FROMSTRING, SA_CENTER);
|
2008-05-16 07:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw status bar */
|
|
|
|
if (this->saving) { // true when saving is active
|
2009-04-21 23:40:56 +00:00
|
|
|
DrawString(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_STATUSBAR_SAVING_GAME, TC_FROMSTRING, SA_CENTER);
|
2008-05-16 07:24:21 +00:00
|
|
|
} else if (_do_autosave) {
|
2009-04-21 23:40:56 +00:00
|
|
|
DrawString(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_STATUSBAR_AUTOSAVE, TC_FROMSTRING, SA_CENTER);
|
2009-05-06 15:06:57 +00:00
|
|
|
} else if (_pause_mode != PM_UNPAUSED) {
|
2009-04-21 23:40:56 +00:00
|
|
|
DrawString(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_STATUSBAR_PAUSED, TC_FROMSTRING, SA_CENTER);
|
2009-05-12 22:28:18 +00:00
|
|
|
} else if (this->ticker_scroll < TICKER_STOP && FindWindowById(WC_NEWS_WINDOW, 0) == NULL && _statusbar_news_item.string_id != 0) {
|
2008-05-16 07:24:21 +00:00
|
|
|
/* Draw the scrolling news text */
|
2009-05-12 20:01:39 +00:00
|
|
|
if (!DrawScrollingStatusText(&_statusbar_news_item, this->ticker_scroll, this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, this->widget[SBW_MIDDLE].top + 1, this->widget[SBW_MIDDLE].bottom)) {
|
2009-01-09 23:49:46 +00:00
|
|
|
this->ticker_scroll = TICKER_STOP;
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c != NULL) {
|
2008-04-18 15:13:45 +00:00
|
|
|
/* This is the default text */
|
2008-09-30 20:39:50 +00:00
|
|
|
SetDParam(0, c->index);
|
2009-04-21 23:40:56 +00:00
|
|
|
DrawString(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_CENTER);
|
2008-04-18 15:13:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-16 07:24:21 +00:00
|
|
|
} else {
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c != NULL) {
|
2008-05-16 07:24:21 +00:00
|
|
|
/* This is the default text */
|
2008-09-30 20:39:50 +00:00
|
|
|
SetDParam(0, c->index);
|
2009-04-21 23:40:56 +00:00
|
|
|
DrawString(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_CENTER);
|
2008-05-16 07:08:04 +00:00
|
|
|
}
|
2008-05-16 07:24:21 +00:00
|
|
|
}
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2009-01-09 23:49:46 +00:00
|
|
|
if (this->reminder_timeout > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, this->widget[SBW_MIDDLE].right - 11, 2);
|
2008-05-16 07:24:21 +00:00
|
|
|
}
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2008-05-16 07:24:21 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
|
{
|
|
|
|
switch (data) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case SBI_SAVELOAD_START: this->saving = true; break;
|
|
|
|
case SBI_SAVELOAD_FINISH: this->saving = false; break;
|
2009-05-12 22:28:18 +00:00
|
|
|
case SBI_SHOW_TICKER: this->ticker_scroll = 0; break;
|
2009-01-09 23:49:46 +00:00
|
|
|
case SBI_SHOW_REMINDER: this->reminder_timeout = REMINDER_START; break;
|
2009-01-09 20:42:17 +00:00
|
|
|
case SBI_NEWS_DELETED:
|
2009-01-09 23:49:46 +00:00
|
|
|
this->ticker_scroll = TICKER_STOP; // reset ticker ...
|
|
|
|
this->reminder_timeout = REMINDER_STOP; // ... and reminder
|
2009-01-09 20:42:17 +00:00
|
|
|
break;
|
2008-05-16 07:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2008-05-16 07:24:21 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2009-01-09 23:49:46 +00:00
|
|
|
case SBW_MIDDLE: ShowLastNewsMessage(); break;
|
|
|
|
case SBW_RIGHT: if (_local_company != COMPANY_SPECTATOR) ShowCompanyFinances(_local_company); break;
|
2008-05-16 07:24:21 +00:00
|
|
|
default: ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
}
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2008-05-16 07:24:21 +00:00
|
|
|
virtual void OnTick()
|
|
|
|
{
|
2009-05-06 15:06:57 +00:00
|
|
|
if (_pause_mode != PM_UNPAUSED) return;
|
2008-05-16 07:24:21 +00:00
|
|
|
|
2009-05-12 22:28:18 +00:00
|
|
|
if (this->ticker_scroll < TICKER_STOP) { // Scrolling text
|
|
|
|
this->ticker_scroll += COUNTER_STEP;
|
2009-01-09 23:49:46 +00:00
|
|
|
this->InvalidateWidget(SBW_MIDDLE);
|
2008-05-16 07:24:21 +00:00
|
|
|
}
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2009-01-09 23:49:46 +00:00
|
|
|
if (this->reminder_timeout > REMINDER_STOP) { // Red blot to show there are new unread newsmessages
|
|
|
|
this->reminder_timeout -= COUNTER_STEP;
|
|
|
|
} else if (this->reminder_timeout < REMINDER_STOP) {
|
|
|
|
this->reminder_timeout = REMINDER_STOP;
|
|
|
|
this->InvalidateWidget(SBW_MIDDLE);
|
2008-05-16 07:24:21 +00:00
|
|
|
}
|
2008-04-18 15:13:45 +00:00
|
|
|
}
|
2008-05-16 07:24:21 +00:00
|
|
|
};
|
2008-04-18 15:13:45 +00:00
|
|
|
|
|
|
|
static const Widget _main_status_widgets[] = {
|
2008-08-02 02:28:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 139, 0, 11, 0x0, STR_NULL},
|
2009-04-21 23:40:56 +00:00
|
|
|
{ WWT_PUSHBTN, RESIZE_RIGHT, COLOUR_GREY, 140, 179, 0, 11, 0x0, STR_STATUSBAR_TOOLTIP_SHOW_LAST_NEWS},
|
2008-08-02 02:28:17 +00:00
|
|
|
{ WWT_PUSHBTN, RESIZE_LR, COLOUR_GREY, 180, 319, 0, 11, 0x0, STR_NULL},
|
2008-04-18 15:13:45 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2009-04-03 12:39:52 +00:00
|
|
|
static const NWidgetPart _nested_main_status_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, SBW_LEFT), SetMinimalSize(140, 12), EndContainer(),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_PUSHBTN, COLOUR_GREY, SBW_MIDDLE), SetMinimalSize(40, 12), SetDataTip(0x0, STR_STATUSBAR_TOOLTIP_SHOW_LAST_NEWS), SetResize(1, 0),
|
2009-04-03 12:39:52 +00:00
|
|
|
NWidget(WWT_PUSHBTN, COLOUR_GREY, SBW_RIGHT), SetMinimalSize(140, 12),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static WindowDesc _main_status_desc(
|
2008-04-18 15:13:45 +00:00
|
|
|
WDP_CENTER, 0, 320, 12, 640, 12,
|
|
|
|
WC_STATUS_BAR, WC_NONE,
|
2009-02-09 01:22:29 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_NO_FOCUS,
|
2009-04-03 12:39:52 +00:00
|
|
|
_main_status_widgets, _nested_main_status_widgets, lengthof(_nested_main_status_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2008-04-18 15:13:45 +00:00
|
|
|
|
2008-05-16 07:08:04 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the news ticker is currently being used.
|
|
|
|
*/
|
|
|
|
bool IsNewsTickerShown()
|
|
|
|
{
|
2008-05-16 07:24:21 +00:00
|
|
|
const StatusBarWindow *w = dynamic_cast<StatusBarWindow*>(FindWindowById(WC_STATUS_BAR, 0));
|
2009-05-12 22:28:18 +00:00
|
|
|
return w != NULL && w->ticker_scroll < StatusBarWindow::TICKER_STOP;
|
2008-05-16 07:08:04 +00:00
|
|
|
}
|
|
|
|
|
2008-04-18 15:13:45 +00:00
|
|
|
void ShowStatusBar()
|
|
|
|
{
|
|
|
|
_main_status_desc.top = _screen.height - 12;
|
2008-05-16 07:24:21 +00:00
|
|
|
new StatusBarWindow(&_main_status_desc);
|
2008-04-18 15:13:45 +00:00
|
|
|
}
|