mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-25 23:49:09 +00:00
bin
docs
media
os
projects
src
3rdparty
ai
blitter
core
depend
lang
misc
music
network
os
pathfinder
saveload
script
sound
spriteloader
strgen
table
thread
video
widgets
aircraft.h
aircraft_cmd.cpp
aircraft_gui.cpp
airport.cpp
airport.h
airport_gui.cpp
animated_tile.cpp
animated_tile_func.h
articulated_vehicles.cpp
articulated_vehicles.h
autoreplace.cpp
autoreplace_base.h
autoreplace_cmd.cpp
autoreplace_func.h
autoreplace_gui.cpp
autoreplace_gui.h
autoreplace_type.h
autoslope.h
base_media_base.h
base_media_func.h
base_station_base.h
bmp.cpp
bmp.h
bridge.h
bridge_gui.cpp
bridge_map.cpp
bridge_map.h
build_vehicle_gui.cpp
cargo_type.h
cargopacket.cpp
cargopacket.h
cargotype.cpp
cargotype.h
cheat.cpp
cheat_func.h
cheat_gui.cpp
cheat_type.h
clear_cmd.cpp
clear_map.h
cmd_helper.h
command.cpp
command_func.h
command_type.h
company_base.h
company_cmd.cpp
company_func.h
company_gui.cpp
company_gui.h
company_manager_face.h
company_type.h
console.cpp
console_cmds.cpp
console_func.h
console_gui.cpp
console_gui.h
console_internal.h
console_type.h
crashlog.cpp
crashlog.h
currency.cpp
currency.h
date.cpp
date_func.h
date_gui.cpp
date_gui.h
date_type.h
debug.cpp
debug.h
dedicated.cpp
depot.cpp
depot_base.h
depot_cmd.cpp
depot_func.h
depot_gui.cpp
depot_map.h
depot_type.h
direction_func.h
direction_type.h
disaster_cmd.cpp
dock_gui.cpp
driver.cpp
driver.h
economy.cpp
economy_base.h
economy_func.h
economy_type.h
effectvehicle.cpp
effectvehicle_base.h
effectvehicle_func.h
elrail.cpp
elrail_func.h
endian_check.cpp
engine.cpp
engine_base.h
engine_func.h
engine_gui.cpp
engine_gui.h
engine_type.h
fileio.cpp
fileio_func.h
fileio_type.h
fios.cpp
fios.h
fios_gui.cpp
fontcache.cpp
fontcache.h
functions.h
gamelog.cpp
gamelog.h
gamelog_internal.h
genworld.cpp
genworld.h
genworld_gui.cpp
gfx.cpp
gfx_func.h
gfx_type.h
gfxinit.cpp
gfxinit.h
graph_gui.cpp
graph_gui.h
ground_vehicle.cpp
ground_vehicle.hpp
group.h
group_cmd.cpp
group_gui.cpp
group_gui.h
group_type.h
gui.h
heightmap.cpp
heightmap.h
highscore.cpp
highscore.h
highscore_gui.cpp
hotkeys.cpp
hotkeys.h
house.h
house_type.h
industry.h
industry_cmd.cpp
industry_gui.cpp
industry_map.h
industry_type.h
industrytype.h
ini.cpp
ini_type.h
intro_gui.cpp
landscape.cpp
landscape.h
landscape_type.h
language.h
livery.h
main_gui.cpp
map.cpp
map_func.h
map_type.h
misc.cpp
misc_cmd.cpp
misc_gui.cpp
mixer.cpp
mixer.h
music.cpp
music_gui.cpp
newgrf.cpp
newgrf.h
newgrf_airport.cpp
newgrf_airport.h
newgrf_airporttiles.cpp
newgrf_airporttiles.h
newgrf_animation_base.h
newgrf_animation_type.h
newgrf_callbacks.h
newgrf_canal.cpp
newgrf_canal.h
newgrf_cargo.cpp
newgrf_cargo.h
newgrf_class.h
newgrf_class_func.h
newgrf_commons.cpp
newgrf_commons.h
newgrf_config.cpp
newgrf_config.h
newgrf_debug.h
newgrf_debug_gui.cpp
newgrf_engine.cpp
newgrf_engine.h
newgrf_generic.cpp
newgrf_generic.h
newgrf_gui.cpp
newgrf_house.cpp
newgrf_house.h
newgrf_industries.cpp
newgrf_industries.h
newgrf_industrytiles.cpp
newgrf_industrytiles.h
newgrf_object.cpp
newgrf_object.h
newgrf_properties.h
newgrf_railtype.cpp
newgrf_railtype.h
newgrf_sound.cpp
newgrf_sound.h
newgrf_spritegroup.cpp
newgrf_spritegroup.h
newgrf_station.cpp
newgrf_station.h
newgrf_storage.cpp
newgrf_storage.h
newgrf_text.cpp
newgrf_text.h
newgrf_town.cpp
newgrf_town.h
newgrf_townname.cpp
newgrf_townname.h
news_func.h
news_gui.cpp
news_gui.h
news_type.h
object.h
object_base.h
object_cmd.cpp
object_gui.cpp
object_map.h
object_type.h
openttd.cpp
openttd.h
order_backup.cpp
order_backup.h
order_base.h
order_cmd.cpp
order_func.h
order_gui.cpp
order_type.h
os_timer.cpp
osk_gui.cpp
pbs.cpp
pbs.h
querystring_gui.h
rail.cpp
rail.h
rail_cmd.cpp
rail_gui.cpp
rail_gui.h
rail_map.h
rail_type.h
rev.cpp.in
rev.h
road.cpp
road_cmd.cpp
road_cmd.h
road_func.h
road_gui.cpp
road_gui.h
road_internal.h
road_map.cpp
road_map.h
road_type.h
roadstop.cpp
roadstop_base.h
roadveh.h
roadveh_cmd.cpp
roadveh_gui.cpp
screenshot.cpp
screenshot.h
sdl.cpp
sdl.h
settings.cpp
settings_func.h
settings_gui.cpp
settings_internal.h
settings_type.h
ship.h
ship_cmd.cpp
ship_gui.cpp
signal.cpp
signal_func.h
signal_type.h
signs.cpp
signs_base.h
signs_cmd.cpp
signs_func.h
signs_gui.cpp
signs_type.h
slope_func.h
slope_type.h
smallmap_gui.cpp
smallmap_gui.h
sortlist_type.h
sound.cpp
sound_func.h
sound_type.h
sprite.cpp
sprite.h
spritecache.cpp
spritecache.h
station.cpp
station_base.h
station_cmd.cpp
station_func.h
station_gui.cpp
station_gui.h
station_map.h
station_type.h
statusbar_gui.cpp
statusbar_gui.h
stdafx.h
string.cpp
string_func.h
string_type.h
strings.cpp
strings_func.h
strings_type.h
subsidy.cpp
subsidy_base.h
subsidy_func.h
subsidy_gui.cpp
subsidy_type.h
tar_type.h
terraform_cmd.cpp
terraform_gui.cpp
terraform_gui.h
textbuf_gui.h
texteff.cpp
texteff.hpp
tgp.cpp
tgp.h
tile_cmd.h
tile_map.cpp
tile_map.h
tile_type.h
tilearea.cpp
tilearea_type.h
tilehighlight_func.h
tilehighlight_type.h
timetable.h
timetable_cmd.cpp
timetable_gui.cpp
toolbar_gui.cpp
toolbar_gui.h
town.h
town_cmd.cpp
town_gui.cpp
town_map.h
town_type.h
townname.cpp
townname_func.h
townname_type.h
track_func.h
track_type.h
train.h
train_cmd.cpp
train_gui.cpp
transparency.h
transparency_gui.cpp
transparency_gui.h
transport_type.h
tree_cmd.cpp
tree_gui.cpp
tree_map.h
tunnel_map.cpp
tunnel_map.h
tunnelbridge.h
tunnelbridge_cmd.cpp
tunnelbridge_map.h
vehicle.cpp
vehicle_base.h
vehicle_cmd.cpp
vehicle_func.h
vehicle_gui.cpp
vehicle_gui.h
vehicle_gui_base.h
vehicle_type.h
vehiclelist.cpp
vehiclelist.h
viewport.cpp
viewport_func.h
viewport_gui.cpp
viewport_type.h
void_cmd.cpp
void_map.h
water.h
water_cmd.cpp
water_map.h
waypoint.cpp
waypoint_base.h
waypoint_cmd.cpp
waypoint_func.h
waypoint_gui.cpp
widget.cpp
widget_type.h
window.cpp
window_func.h
window_gui.h
window_type.h
zoom_func.h
zoom_type.h
.gitignore
.hgignore
COPYING
Doxyfile
Makefile.bundle.in
Makefile.grf.in
Makefile.in
Makefile.lang.in
Makefile.msvc
Makefile.src.in
changelog.txt
config.lib
configure
findversion.sh
known-bugs.txt
readme.txt
source.list
259 lines
8.9 KiB
C++
259 lines
8.9 KiB
C++
/* $Id$ */
|
|
|
|
/*
|
|
* This file is part of OpenTTD.
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/** @file statusbar_gui.cpp The GUI for the bottom status bar. */
|
|
|
|
#include "stdafx.h"
|
|
#include "openttd.h"
|
|
#include "date_func.h"
|
|
#include "gfx_func.h"
|
|
#include "news_func.h"
|
|
#include "company_func.h"
|
|
#include "string_func.h"
|
|
#include "strings_func.h"
|
|
#include "company_base.h"
|
|
#include "tilehighlight_func.h"
|
|
#include "news_gui.h"
|
|
#include "company_gui.h"
|
|
#include "window_gui.h"
|
|
#include "saveload/saveload.h"
|
|
#include "window_func.h"
|
|
#include "statusbar_gui.h"
|
|
#include "core/geometry_func.hpp"
|
|
|
|
#include "table/strings.h"
|
|
#include "table/sprites.h"
|
|
|
|
static bool DrawScrollingStatusText(const NewsItem *ni, int scroll_pos, int left, int right, int top, int bottom)
|
|
{
|
|
CopyInDParam(0, ni->params, lengthof(ni->params));
|
|
StringID str = ni->string_id;
|
|
|
|
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;
|
|
} else if (c == '\n') {
|
|
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;
|
|
if (!FillDrawPixelInfo(&tmp_dpi, left, top, right - left, bottom)) return true;
|
|
|
|
int width = GetStringBoundingBox(buffer).width;
|
|
int pos = (_current_text_dir == TD_RTL) ? (scroll_pos - width) : (right - scroll_pos - left);
|
|
|
|
DrawPixelInfo *old_dpi = _cur_dpi;
|
|
_cur_dpi = &tmp_dpi;
|
|
DrawString(pos, INT16_MAX, 0, buffer, TC_LIGHT_BLUE, SA_LEFT | SA_FORCE);
|
|
_cur_dpi = old_dpi;
|
|
|
|
return (_current_text_dir == TD_RTL) ? (pos < right - left) : (pos + width > 0);
|
|
}
|
|
|
|
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
|
|
};
|
|
|
|
struct StatusBarWindow : Window {
|
|
bool saving;
|
|
int ticker_scroll;
|
|
int reminder_timeout;
|
|
|
|
static const int TICKER_STOP = 1640; ///< scrolling is finished when counter reaches this value
|
|
static const int REMINDER_START = 91; ///< initial value of the reminder counter (right dot on the right)
|
|
static const int REMINDER_STOP = 0; ///< reminder disappears when counter reaches this value
|
|
static const int COUNTER_STEP = 2; ///< this is subtracted from active counters every tick
|
|
|
|
StatusBarWindow(const WindowDesc *desc) : Window()
|
|
{
|
|
CLRBITS(this->flags4, WF_WHITE_BORDER_MASK);
|
|
this->ticker_scroll = TICKER_STOP;
|
|
this->reminder_timeout = REMINDER_STOP;
|
|
|
|
this->InitNested(desc);
|
|
PositionStatusbar(this);
|
|
}
|
|
|
|
virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
|
|
{
|
|
Point pt = { 0, _screen.height - sm_height };
|
|
return pt;
|
|
}
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
{
|
|
Dimension d;
|
|
switch (widget) {
|
|
case SBW_LEFT:
|
|
SetDParam(0, MAX_YEAR * DAYS_IN_YEAR);
|
|
d = GetStringBoundingBox(STR_WHITE_DATE_LONG);
|
|
break;
|
|
|
|
case SBW_RIGHT: {
|
|
int64 max_money = UINT32_MAX;
|
|
const Company *c;
|
|
FOR_ALL_COMPANIES(c) max_money = max<int64>(c->money, max_money);
|
|
SetDParam(0, 100LL * max_money);
|
|
d = GetStringBoundingBox(STR_COMPANY_MONEY);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
return;
|
|
}
|
|
|
|
d.width += padding.width;
|
|
d.height += padding.height;
|
|
*size = maxdim(d, *size);
|
|
}
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
{
|
|
switch (widget) {
|
|
case SBW_LEFT:
|
|
/* Draw the date */
|
|
SetDParam(0, _date);
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, (_pause_mode || _settings_client.gui.status_long_date) ? STR_WHITE_DATE_LONG : STR_WHITE_DATE_SHORT, TC_FROMSTRING, SA_HOR_CENTER);
|
|
break;
|
|
|
|
case SBW_RIGHT: {
|
|
/* Draw company money, if any */
|
|
const Company *c = Company::GetIfValid(_local_company);
|
|
if (c != NULL) {
|
|
SetDParam(0, c->money);
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_COMPANY_MONEY, TC_FROMSTRING, SA_HOR_CENTER);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case SBW_MIDDLE:
|
|
/* Draw status bar */
|
|
if (this->saving) { // true when saving is active
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_SAVING_GAME, TC_FROMSTRING, SA_HOR_CENTER);
|
|
} else if (_do_autosave) {
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_AUTOSAVE, TC_FROMSTRING, SA_HOR_CENTER);
|
|
} else if (_pause_mode != PM_UNPAUSED) {
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_PAUSED, TC_FROMSTRING, SA_HOR_CENTER);
|
|
} else if (this->ticker_scroll < TICKER_STOP && FindWindowById(WC_NEWS_WINDOW, 0) == NULL && _statusbar_news_item != NULL && _statusbar_news_item->string_id != 0) {
|
|
/* Draw the scrolling news text */
|
|
if (!DrawScrollingStatusText(_statusbar_news_item, this->ticker_scroll, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) {
|
|
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED);
|
|
if (Company::IsValidID(_local_company)) {
|
|
/* This is the default text */
|
|
SetDParam(0, _local_company);
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_HOR_CENTER);
|
|
}
|
|
}
|
|
} else {
|
|
if (Company::IsValidID(_local_company)) {
|
|
/* This is the default text */
|
|
SetDParam(0, _local_company);
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_HOR_CENTER);
|
|
}
|
|
}
|
|
|
|
if (this->reminder_timeout > 0) {
|
|
Dimension icon_size = GetSpriteSize(SPR_UNREAD_NEWS);
|
|
DrawSprite(SPR_UNREAD_NEWS, PAL_NONE, r.right - WD_FRAMERECT_RIGHT - icon_size.width, r.top + WD_FRAMERECT_TOP + (int)(FONT_HEIGHT_NORMAL - icon_size.height) / 2);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
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;
|
|
case SBI_SHOW_TICKER: this->ticker_scroll = 0; break;
|
|
case SBI_SHOW_REMINDER: this->reminder_timeout = REMINDER_START; break;
|
|
case SBI_NEWS_DELETED:
|
|
this->ticker_scroll = TICKER_STOP; // reset ticker ...
|
|
this->reminder_timeout = REMINDER_STOP; // ... and reminder
|
|
break;
|
|
}
|
|
}
|
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
{
|
|
switch (widget) {
|
|
case SBW_MIDDLE: ShowLastNewsMessage(); break;
|
|
case SBW_RIGHT: if (_local_company != COMPANY_SPECTATOR) ShowCompanyFinances(_local_company); break;
|
|
default: ResetObjectToPlace();
|
|
}
|
|
}
|
|
|
|
virtual void OnTick()
|
|
{
|
|
if (_pause_mode != PM_UNPAUSED) return;
|
|
|
|
if (this->ticker_scroll < TICKER_STOP) { // Scrolling text
|
|
this->ticker_scroll += COUNTER_STEP;
|
|
this->SetWidgetDirty(SBW_MIDDLE);
|
|
}
|
|
|
|
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->SetWidgetDirty(SBW_MIDDLE);
|
|
}
|
|
}
|
|
};
|
|
|
|
static const NWidgetPart _nested_main_status_widgets[] = {
|
|
NWidget(NWID_HORIZONTAL),
|
|
NWidget(WWT_PANEL, COLOUR_GREY, SBW_LEFT), SetMinimalSize(140, 12), EndContainer(),
|
|
NWidget(WWT_PUSHBTN, COLOUR_GREY, SBW_MIDDLE), SetMinimalSize(40, 12), SetDataTip(0x0, STR_STATUSBAR_TOOLTIP_SHOW_LAST_NEWS), SetResize(1, 0),
|
|
NWidget(WWT_PUSHBTN, COLOUR_GREY, SBW_RIGHT), SetMinimalSize(140, 12),
|
|
EndContainer(),
|
|
};
|
|
|
|
static WindowDesc _main_status_desc(
|
|
WDP_MANUAL, 640, 12,
|
|
WC_STATUS_BAR, WC_NONE,
|
|
WDF_UNCLICK_BUTTONS | WDF_NO_FOCUS,
|
|
_nested_main_status_widgets, lengthof(_nested_main_status_widgets)
|
|
);
|
|
|
|
/**
|
|
* Checks whether the news ticker is currently being used.
|
|
*/
|
|
bool IsNewsTickerShown()
|
|
{
|
|
const StatusBarWindow *w = dynamic_cast<StatusBarWindow*>(FindWindowById(WC_STATUS_BAR, 0));
|
|
return w != NULL && w->ticker_scroll < StatusBarWindow::TICKER_STOP;
|
|
}
|
|
|
|
int16 *_preferred_statusbar_size = &_main_status_desc.default_width; ///< Pointer to the default size for the status toolbar.
|
|
|
|
void ShowStatusBar()
|
|
{
|
|
new StatusBarWindow(&_main_status_desc);
|
|
}
|