Merge 1.9.0-beta2

This commit is contained in:
Pavel Stupnikov
2019-02-14 00:47:22 +03:00
1364 changed files with 22213 additions and 10721 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: toolbar_gui.cpp 27671 2016-10-30 17:36:57Z frosch $ */
/* $Id$ */
/*
* This file is part of OpenTTD.
@@ -47,6 +47,8 @@
#include "goal_base.h"
#include "story_base.h"
#include "toolbar_gui.h"
#include "framerate_type.h"
#include "guitimer_func.h"
#include "widgets/toolbar_widget.h"
@@ -122,21 +124,14 @@ public:
*/
class DropDownListCompanyItem : public DropDownListItem {
Dimension icon_size;
Dimension lock_icon_size;
uint line_height;
Dimension lock_size;
public:
bool greyed;
DropDownListCompanyItem(int result, bool masked, bool greyed) : DropDownListItem(result, masked), greyed(greyed)
{
this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
if (_networking) {
this->lock_icon_size = GetSpriteSize(SPR_LOCK);
this->line_height = max(this->lock_icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL);
} else {
this->lock_icon_size.width = 0;
this->line_height = max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL);
}
this->lock_size = GetSpriteSize(SPR_LOCK);
}
virtual ~DropDownListCompanyItem() {}
@@ -151,12 +146,12 @@ public:
CompanyID company = (CompanyID)this->result;
SetDParam(0, company);
SetDParam(1, company);
return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_icon_size.width + 3;
return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_size.width + 6;
}
uint Height(uint width) const
{
return this->line_height;
return max(max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL);
}
void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
@@ -169,12 +164,11 @@ public:
int icon_offset = (bottom - top - icon_size.height) / 2;
int text_offset = (bottom - top - FONT_HEIGHT_NORMAL) / 2;
int lock_icon_offset = (bottom - top - this->lock_icon_size.height) / 2;
int lock_offset = (bottom - top - lock_size.height) / 2;
DrawCompanyIcon(company, rtl ? right - this->icon_size.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + icon_offset);
int text_x_ofs = WD_FRAMERECT_LEFT + this->icon_size.width + this->lock_icon_size.width;
if (_networking && NetworkCompanyIsPassworded(company)){
DrawSprite(SPR_LOCK, PAL_NONE, rtl ? right - this->icon_size.width - this->lock_icon_size.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT + this->icon_size.width + WD_FRAMERECT_LEFT, top + lock_icon_offset);
if (NetworkCompanyIsPassworded(company)) {
DrawSprite(SPR_LOCK, PAL_NONE, rtl ? left + WD_FRAMERECT_LEFT : right - this->lock_size.width - WD_FRAMERECT_RIGHT, top + lock_offset);
}
SetDParam(0, company);
@@ -185,7 +179,7 @@ public:
} else {
col = sel ? TC_WHITE : TC_BLACK;
}
DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : text_x_ofs), right - WD_FRAMERECT_RIGHT - (rtl ? text_x_ofs : 0), top + text_offset, STR_COMPANY_NAME_COMPANY_NUM, col);
DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 3 + this->lock_size.width : 3 + this->icon_size.width), right - WD_FRAMERECT_RIGHT - (rtl ? 3 + this->icon_size.width : 3 + this->lock_size.width), top + text_offset, STR_COMPANY_NAME_COMPANY_NUM, col);
}
};
@@ -675,9 +669,9 @@ static CallBackFunction MenuClickCompany(int index)
case CTMN_NEW_COMPANY:
if (_network_server) {
DoCommandP(0, 0, _network_own_client_id, CMD_COMPANY_CTRL);
DoCommandP(0, CCA_NEW, _network_own_client_id, CMD_COMPANY_CTRL);
} else {
NetworkSendCommand(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
}
return CBF_NONE;
@@ -1110,7 +1104,7 @@ static CallBackFunction PlaceLandBlockInfo()
static CallBackFunction ToolbarHelpClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 9);
PopupMainToolbMenu(w, WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 14 : 10);
return CBF_NONE;
}
@@ -1218,11 +1212,12 @@ static CallBackFunction MenuClickHelp(int index)
case 5: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
case 6: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
case 7: MenuClickLargeWorldScreenshot(SC_WORLD); break;
case 8: ShowAboutWindow(); break;
case 9: ShowSpriteAlignerWindow(); break;
case 10: ToggleBoundingBoxes(); break;
case 11: ToggleDirtyBlocks(); break;
case 12: ShowLoginWindow(); break;
case 8: ShowFramerateWindow(); break;
case 9: ShowAboutWindow(); break;
case 10: ShowSpriteAlignerWindow(); break;
case 11: ToggleBoundingBoxes(); break;
case 12: ToggleDirtyBlocks(); break;
case 13: ShowLoginWindow(); break;
}
return CBF_NONE;
}
@@ -1556,7 +1551,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_TRAINS,
WID_TN_ROADVEHS,
WID_TN_SHIPS,
WID_TN_AIRCRAFTS,
WID_TN_AIRCRAFT,
WID_TN_ZOOM_IN,
WID_TN_ZOOM_OUT,
WID_TN_RAILS,
@@ -1588,7 +1583,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_TRAINS,
WID_TN_ROADVEHS,
WID_TN_SHIPS,
WID_TN_AIRCRAFTS,
WID_TN_AIRCRAFT,
WID_TN_RAILS,
WID_TN_ROADS,
WID_TN_WATER,
@@ -1622,7 +1617,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_TRAINS,
WID_TN_ROADVEHS,
WID_TN_SHIPS,
WID_TN_AIRCRAFTS,
WID_TN_AIRCRAFT,
WID_TN_RAILS,
WID_TN_ROADS,
WID_TN_WATER,
@@ -1658,7 +1653,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_TRAINS,
WID_TN_ROADVEHS,
WID_TN_SHIPS,
WID_TN_AIRCRAFTS,
WID_TN_AIRCRAFT,
WID_TN_RAILS,
WID_TN_ROADS,
WID_TN_WATER,
@@ -1717,7 +1712,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_TRAINS,
WID_TN_ROADVEHS,
WID_TN_SHIPS,
WID_TN_AIRCRAFTS,
WID_TN_AIRCRAFT,
WID_TN_MUSIC_SOUND,
WID_TN_MESSAGES,
WID_TN_HELP,
@@ -1735,7 +1730,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_TRAINS,
WID_TN_ROADVEHS,
WID_TN_SHIPS,
WID_TN_AIRCRAFTS,
WID_TN_AIRCRAFT,
WID_TN_RAILS,
WID_TN_ROADS,
WID_TN_WATER,
@@ -1776,7 +1771,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_TRAINS,
WID_TN_ROADVEHS,
WID_TN_SHIPS,
WID_TN_AIRCRAFTS,
WID_TN_AIRCRAFT,
WID_TN_RAILS,
WID_TN_ROADS,
WID_TN_WATER,
@@ -1830,7 +1825,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_TRAINS,
WID_TN_ROADVEHS,
WID_TN_SHIPS,
WID_TN_AIRCRAFTS,
WID_TN_AIRCRAFT,
WID_TN_ZOOM_IN,
WID_TN_ZOOM_OUT,
WID_TN_RAILS,
@@ -2063,6 +2058,8 @@ enum MainToolbarHotkeys {
/** Main toolbar. */
struct MainToolbarWindow : Window {
GUITimer timer;
MainToolbarWindow(WindowDesc *desc) : Window(desc)
{
this->InitNested(0);
@@ -2073,6 +2070,8 @@ struct MainToolbarWindow : Window {
this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
PositionMainToolbar(this);
DoZoomInOutWindow(ZOOM_NONE, this);
this->timer.SetInterval(MILLISECONDS_PER_TICK);
}
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
@@ -2087,7 +2086,7 @@ struct MainToolbarWindow : Window {
* Since enabled state is the default, just disable when needed */
this->SetWidgetsDisabledState(_local_company == COMPANY_SPECTATOR, WID_TN_RAILS, WID_TN_ROADS, WID_TN_WATER, WID_TN_AIR, WID_TN_LANDSCAPE, WIDGET_LIST_END);
/* disable company list drop downs, if there are no companies */
this->SetWidgetsDisabledState(Company::GetNumItems() == 0, WID_TN_STATIONS, WID_TN_FINANCES, WID_TN_CARGOS, WID_TN_WATCH, WID_TN_TRAINS, WID_TN_ROADVEHS, WID_TN_SHIPS, WID_TN_AIRCRAFTS, WIDGET_LIST_END);
this->SetWidgetsDisabledState(Company::GetNumItems() == 0, WID_TN_STATIONS, WID_TN_FINANCES, WID_TN_CARGOS, WID_TN_WATCH, WID_TN_TRAINS, WID_TN_ROADVEHS, WID_TN_SHIPS, WID_TN_AIRCRAFT, WIDGET_LIST_END);
this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
@@ -2225,8 +2224,11 @@ struct MainToolbarWindow : Window {
}
virtual void OnTick()
virtual void OnRealtimeTick(uint delta_ms)
{
if (!this->timer.Elapsed(delta_ms)) return;
this->timer.SetInterval(MILLISECONDS_PER_TICK);
if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
this->ToggleWidgetLoweredState(WID_TN_PAUSE);
this->SetWidgetDirty(WID_TN_PAUSE);
@@ -2454,6 +2456,8 @@ enum MainToolbarEditorHotkeys {
};
struct ScenarioEditorToolbarWindow : Window {
GUITimer timer;
ScenarioEditorToolbarWindow(WindowDesc *desc) : Window(desc)
{
this->InitNested(0);
@@ -2462,6 +2466,8 @@ struct ScenarioEditorToolbarWindow : Window {
CLRBITS(this->flags, WF_WHITE_BORDER);
PositionMainToolbar(this);
DoZoomInOutWindow(ZOOM_NONE, this);
this->timer.SetInterval(MILLISECONDS_PER_TICK);
}
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
@@ -2589,8 +2595,11 @@ struct ScenarioEditorToolbarWindow : Window {
this->SetWidgetDirty(WID_TE_DATE_FORWARD);
}
virtual void OnTick()
virtual void OnRealtimeTick(uint delta_ms)
{
if (!this->timer.Elapsed(delta_ms)) return;
this->timer.SetInterval(MILLISECONDS_PER_TICK);
if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
this->ToggleWidgetLoweredState(WID_TE_PAUSE);
this->SetDirty();