Changeset - r23124:8fa6d269005b
[Not reviewed]
master
0 21 0
Peter Nelson - 6 years ago 2018-05-04 20:29:22
peter1138@openttd.org
Change: Split up Window::OnTick into OnGameTick and OnRealtimeTick. Adjust timers to work with milliseconds instead of ticks.
21 files changed with 144 insertions and 64 deletions:
0 comments (0 inline, 0 general)
src/airport_gui.cpp
Show inline comments
 
@@ -534,25 +534,25 @@ public:
 
		/* If all airports are unavailable, select nothing. */
 
		this->SelectOtherAirport(-1);
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		assert(widget == WID_AP_CLASS_DROPDOWN);
 
		_selected_airport_class = (AirportClassID)index;
 
		this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
 
		this->SelectFirstAvailableAirport(false);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_build_airport_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 0), SetPIP(2, 0, 2),
 
		NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL, STR_NULL), SetFill(1, 0),
src/dock_gui.cpp
Show inline comments
 
@@ -442,25 +442,25 @@ public:
 
		switch (widget) {
 
			case BDSW_LT_OFF:
 
			case BDSW_LT_ON:
 
				this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
 
				_settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
 
				this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
 
				if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 
};
 

	
 
/** Nested widget parts of a build dock station window. */
 
static const NWidgetPart _nested_build_dock_station_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
src/graph_gui.cpp
Show inline comments
 
@@ -530,25 +530,25 @@ public:
 

	
 
	virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
 
	{
 
		return INVALID_DATAPOINT;
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		/* Clicked on legend? */
 
		if (widget == WID_CV_KEY_BUTTON) ShowGraphLegend();
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		this->UpdateStatistics(false);
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (!gui_scope) return;
 
@@ -989,27 +989,27 @@ struct PaymentRatesGraphWindow : BaseGra
 
			default:
 
				if (widget >= WID_CPR_CARGO_FIRST) {
 
					int i = widget - WID_CPR_CARGO_FIRST;
 
					ToggleBit(_legend_excluded_cargo, _sorted_cargo_specs[i]->Index());
 
					this->ToggleWidgetLoweredState(widget);
 
					this->UpdateExcludedData();
 
					this->SetDirty();
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		/* Override default OnTick */
 
		/* Override default OnGameTick */
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (!gui_scope) return;
 
		this->OnHundredthTick();
 
	}
 
@@ -1230,25 +1230,25 @@ public:
 
			SetDParam(1, c->index);
 
			SetDParam(2, _performance_titles[widest_title]);
 
			widest_width = max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
 
		}
 

	
 
		this->text_width = widest_width + 30; // Keep some extra spacing
 

	
 
		size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + this->icon_width + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT;
 
		size->height = WD_FRAMERECT_TOP + this->line_height * MAX_COMPANIES + WD_FRAMERECT_BOTTOM;
 
	}
 

	
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (this->companies.NeedResort()) {
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
@@ -1463,25 +1463,25 @@ struct PerformanceRatingDetailWindow : W
 
		/* Check which button is clicked */
 
		if (IsInsideMM(widget, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST + 1)) {
 
			/* Is it no on disable? */
 
			if (!this->IsWidgetDisabled(widget)) {
 
				this->RaiseWidget(this->company + WID_PRD_COMPANY_FIRST);
 
				this->company = (CompanyID)(widget - WID_PRD_COMPANY_FIRST);
 
				this->LowerWidget(this->company + WID_PRD_COMPANY_FIRST);
 
				this->SetDirty();
 
			}
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 

	
 
		/* Update the company score every 5 days */
 
		if (--this->timeout == 0) {
 
			this->UpdateCompanyStats();
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
src/group_gui.cpp
Show inline comments
 
@@ -849,25 +849,25 @@ public:
 
						DoCommandP(0, this->vli.index, 0, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
 
						break;
 
					default: NOT_REACHED();
 
				}
 
				break;
 

	
 
			default: NOT_REACHED();
 
		}
 

	
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (this->groups.NeedResort() || this->vehicles.NeedResort()) {
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnPlaceObjectAbort()
 
	{
 
		/* abort drag & drop */
 
		this->vehicle_sel = INVALID_VEHICLE;
 
		this->DirtyHighlightedGroupWidget();
src/industry_gui.cpp
Show inline comments
 
@@ -638,25 +638,25 @@ public:
 

	
 
			cur_company.Restore();
 
			_ignore_restrictions = false;
 
			_generating_world = false;
 
		} else {
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
		}
 

	
 
		/* If an industry has been built, just reset the cursor and the system */
 
		if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (!this->timer_enabled) return;
 
		if (--this->callback_timer == 0) {
 
			/* We have just passed another day.
 
			 * See if we need to update availability of currently selected industry */
 
			this->callback_timer = DAY_TICKS; // restart counter
 

	
 
			const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
 

	
 
			if (indsp->enabled) {
 
				bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
src/main_gui.cpp
Show inline comments
 
@@ -226,45 +226,46 @@ enum {
 
	GHK_TOGGLE_TRANSPARENCY,
 
	GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
 
	GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
 
	GHK_TRANSPARANCY,
 
	GHK_CHAT,
 
	GHK_CHAT_ALL,
 
	GHK_CHAT_COMPANY,
 
	GHK_CHAT_SERVER,
 
};
 

	
 
struct MainWindow : Window
 
{
 
	uint refresh;
 
	int refresh;
 

	
 
	static const uint LINKGRAPH_REFRESH_PERIOD = 0xff;
 
	static const uint LINKGRAPH_DELAY = 0xf;
 
	/* Refresh times in milliseconds */
 
	static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
 
	static const uint LINKGRAPH_DELAY = 450;
 

	
 
	MainWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->InitNested(0);
 
		CLRBITS(this->flags, WF_WHITE_BORDER);
 
		ResizeWindow(this, _screen.width, _screen.height);
 

	
 
		NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
 
		nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
 

	
 
		this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 3);
 
		this->refresh = LINKGRAPH_DELAY;
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (--this->refresh > 0) return;
 
		if (!TimerElapsed(this->refresh, delta_ms)) return;
 

	
 
		this->refresh = LINKGRAPH_REFRESH_PERIOD;
 

	
 
		if (this->viewport->overlay->GetCargoMask() == 0 ||
 
				this->viewport->overlay->GetCompanyMask() == 0) {
 
			return;
 
		}
 

	
 
		this->viewport->overlay->RebuildCache();
 
		this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
 
	}
 

	
src/misc_gui.cpp
Show inline comments
 
@@ -445,33 +445,34 @@ static const char * const _credits[] = {
 
	"  Andrew Parkhouse (andythenorth) - River graphics",
 
	"  David Dallaston (Pikka) - Tram tracks",
 
	"  All Translators - Who made OpenTTD a truly international game",
 
	"  Bug Reporters - Without whom OpenTTD would still be full of bugs!",
 
	"",
 
	"",
 
	"And last but not least:",
 
	"  Chris Sawyer - For an amazing game!"
 
};
 

	
 
struct AboutWindow : public Window {
 
	int text_position;                       ///< The top of the scrolling text
 
	byte counter;                            ///< Used to scroll the text every 5 ticks
 
	int line_height;                         ///< The height of a single line
 
	static const int num_visible_lines = 19; ///< The number of lines visible simultaneously
 

	
 
	static const uint TIMER_INTERVAL = 150;  ///< Scrolling interval in ms
 
	uint timer;
 

	
 
	AboutWindow() : Window(&_about_desc)
 
	{
 
		this->InitNested(WN_GAME_OPTIONS_ABOUT);
 

	
 
		this->counter = 5;
 
		this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget == WID_A_WEBSITE) SetDParamStr(0, "Website: http://www.openttd.org");
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		if (widget != WID_A_SCROLLING_TEXT) return;
 

	
 
@@ -493,29 +494,29 @@ struct AboutWindow : public Window {
 

	
 
		int y = this->text_position;
 

	
 
		/* Show all scrolling _credits */
 
		for (uint i = 0; i < lengthof(_credits); i++) {
 
			if (y >= r.top + 7 && y < r.bottom - this->line_height) {
 
				DrawString(r.left, r.right, y, _credits[i], TC_BLACK, SA_LEFT | SA_FORCE);
 
			}
 
			y += this->line_height;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (--this->counter == 0) {
 
			this->counter = 5;
 
			this->text_position--;
 
		uint count = CountIntervalElapsed(this->timer, delta_ms, TIMER_INTERVAL);
 
		if (count > 0) {
 
			this->text_position -= count;
 
			/* If the last text has scrolled start a new from the start */
 
			if (this->text_position < (int)(this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y - lengthof(_credits) * this->line_height)) {
 
				this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
 
			}
 
			this->SetDirty();
 
		}
 
	}
 
};
 

	
 
void ShowAboutWindow()
 
{
 
	DeleteWindowByClass(WC_GAME_OPTIONS);
src/newgrf_gui.cpp
Show inline comments
 
@@ -394,25 +394,25 @@ struct NewGRFParametersWindow : public W
 
							if (val < par_info->max_value) val++;
 
							this->clicked_increase = true;
 
						} else {
 
							/* Decrease button clicked */
 
							if (val > par_info->min_value) val--;
 
							this->clicked_increase = false;
 
						}
 
					}
 
					if (val != old_val) {
 
						par_info->SetValue(this->grf_config, val);
 

	
 
						this->clicked_button = num;
 
						this->timeout = 5;
 
						this->timeout = 150;
 
					}
 
				} else if (par_info->type == PTYPE_UINT_ENUM && !par_info->complete_labels && click_count >= 2) {
 
					/* Display a query box so users can enter a custom value. */
 
					SetDParam(0, old_val);
 
					ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE);
 
				}
 
				this->SetDirty();
 
				break;
 
			}
 

	
 
			case WID_NP_RESET:
 
				if (!this->editable) break;
 
@@ -474,27 +474,27 @@ struct NewGRFParametersWindow : public W
 
		if (!this->action14present) {
 
			this->SetWidgetDisabledState(WID_NP_NUMPAR_DEC, !this->editable || this->grf_config->num_params == 0);
 
			this->SetWidgetDisabledState(WID_NP_NUMPAR_INC, !this->editable || this->grf_config->num_params >= this->grf_config->num_valid_params);
 
		}
 

	
 
		this->vscroll->SetCount(this->action14present ? this->grf_config->num_valid_params : this->grf_config->num_params);
 
		if (this->clicked_row != UINT_MAX && this->clicked_row >= this->vscroll->GetCount()) {
 
			this->clicked_row = UINT_MAX;
 
			DeleteChildWindows(WC_QUERY_STRING);
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (--this->timeout == 0) {
 
		if (TimerElapsed(this->timeout, delta_ms)) {
 
			this->clicked_button = UINT_MAX;
 
			this->SetDirty();
 
		}
 
	}
 
};
 
GRFParameterInfo NewGRFParametersWindow::dummy_parameter_info(0);
 

	
 

	
 
static const NWidgetPart _nested_newgrf_parameter_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
 
		NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
src/news_gui.cpp
Show inline comments
 
@@ -251,29 +251,31 @@ NewsDisplay NewsTypeData::GetDisplay() c
 
	uint index;
 
	const SettingDesc *sd = GetSettingFromName(this->name, &index);
 
	assert(sd != NULL);
 
	void *ptr = GetVariableAddress(NULL, &sd->save);
 
	return (NewsDisplay)ReadValue(ptr, sd->save.conv);
 
}
 

	
 
/** Window class displaying a news item. */
 
struct NewsWindow : Window {
 
	uint16 chat_height;   ///< Height of the chat window.
 
	uint16 status_height; ///< Height of the status bar window
 
	const NewsItem *ni;   ///< News item to display.
 
	static uint duration; ///< Remaining time for showing current news message (may only be accessed while a news item is displayed).
 
	static int duration;  ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
 

	
 
	uint timer;
 

	
 
	NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
 
	{
 
		NewsWindow::duration = 555;
 
		NewsWindow::duration = 16650;
 
		const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
 
		this->chat_height = (w != NULL) ? w->height : 0;
 
		this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
 

	
 
		this->flags |= WF_DISABLE_VP_SCROLL;
 

	
 
		this->CreateNestedTree();
 

	
 
		/* For company news with a face we have a separate headline in param[0] */
 
		if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0];
 

	
 
		this->FinishInitNested(0);
 
@@ -476,29 +478,36 @@ struct NewsWindow : Window {
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (!gui_scope) return;
 
		/* The chatbar has notified us that is was either created or closed */
 
		int newtop = this->top + this->chat_height - data;
 
		this->chat_height = data;
 
		this->SetWindowTop(newtop);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		/* Scroll up newsmessages from the bottom in steps of 4 pixels */
 
		int newtop = max(this->top - 4, _screen.height - this->height - this->status_height - this->chat_height);
 
		this->SetWindowTop(newtop);
 
		int count = CountIntervalElapsed(this->timer, delta_ms, 15);
 
		if (count > 0) {
 
			/* Scroll up newsmessages from the bottom */
 
			int newtop = max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
 
			this->SetWindowTop(newtop);
 
		}
 

	
 
		/* Decrement the news timer. We don't need to action an elapsed event here,
 
		 * so no need to use TimerElapsed(). */
 
		if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
 
	}
 

	
 
private:
 
	/**
 
	 * Moves the window to a new #top coordinate. Makes screen dirty where needed.
 
	 * @param newtop new top coordinate
 
	 */
 
	void SetWindowTop(int newtop)
 
	{
 
		if (this->top == newtop) return;
 

	
 
		int mintop = min(newtop, this->top);
 
@@ -527,25 +536,25 @@ private:
 
				return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
 

	
 
			case WID_N_VEH_NAME:
 
				SetDParam(0, engine);
 
				return STR_NEWS_NEW_VEHICLE_TYPE;
 

	
 
			default:
 
				NOT_REACHED();
 
		}
 
	}
 
};
 

	
 
/* static */ uint NewsWindow::duration = 0; // Instance creation.
 
/* static */ int NewsWindow::duration = 0; // Instance creation.
 

	
 

	
 
/** Open up an own newspaper window for the news item */
 
static void ShowNewspaper(const NewsItem *ni)
 
{
 
	SoundFx sound = _news_type_data[ni->type].sound;
 
	if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
 

	
 
	new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
 
}
 

	
 
/** Show news item in the ticker */
 
@@ -579,29 +588,26 @@ void InitNewsItemStructs()
 
 * Are we ready to show another news item?
 
 * Only if nothing is in the newsticker and no newspaper is displayed
 
 */
 
static bool ReadyForNextItem()
 
{
 
	const NewsItem *ni = _forced_news == NULL ? _current_news : _forced_news;
 
	if (ni == NULL) return true;
 

	
 
	/* Ticker message
 
	 * Check if the status bar message is still being displayed? */
 
	if (IsNewsTickerShown()) return false;
 

	
 
	/* Newspaper message, decrement duration counter */
 
	if (NewsWindow::duration != 0) NewsWindow::duration--;
 

	
 
	/* neither newsticker nor newspaper are running */
 
	return (NewsWindow::duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
 
	return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
 
}
 

	
 
/** Move to the next news item */
 
static void MoveToNextItem()
 
{
 
	InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
 
	DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
 
	_forced_news = NULL;
 
	_statusbar_news_item = NULL;
 

	
 
	/* if we're not at the last item, then move on */
 
	if (_current_news != _latest_news) {
src/openttd.cpp
Show inline comments
 
@@ -67,25 +67,25 @@
 

	
 
#include "linkgraph/linkgraphschedule.h"
 

	
 
#include <stdarg.h>
 

	
 
#include "safeguards.h"
 

	
 
void CallLandscapeTick();
 
void IncreaseDate();
 
void DoPaletteAnimations();
 
void MusicLoop();
 
void ResetMusic();
 
void CallWindowTickEvent();
 
void CallWindowGameTickEvent();
 
bool HandleBootstrap();
 

	
 
extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
 
extern void ShowOSErrorBox(const char *buf, bool system);
 
extern char *_config_file;
 

	
 
/**
 
 * Error handling for fatal user errors.
 
 * @param s the string to print.
 
 * @note Does NEVER return.
 
 */
 
void CDECL usererror(const char *s, ...)
 
@@ -1354,43 +1354,42 @@ void StateGameLoop()
 
		PerformanceMeasurer::Paused(PFE_GAMELOOP);
 
		PerformanceMeasurer::Paused(PFE_GL_ECONOMY);
 
		PerformanceMeasurer::Paused(PFE_GL_TRAINS);
 
		PerformanceMeasurer::Paused(PFE_GL_ROADVEHS);
 
		PerformanceMeasurer::Paused(PFE_GL_SHIPS);
 
		PerformanceMeasurer::Paused(PFE_GL_AIRCRAFT);
 
		PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE);
 

	
 
		UpdateLandscapingLimits();
 
#ifndef DEBUG_DUMP_COMMANDS
 
		Game::GameLoop();
 
#endif
 
		CallWindowTickEvent();
 
		return;
 
	}
 

	
 
	PerformanceMeasurer framerate(PFE_GAMELOOP);
 
	PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
 
	if (HasModalProgress()) return;
 

	
 
	Layouter::ReduceLineCache();
 

	
 
	if (_game_mode == GM_EDITOR) {
 
		BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
 
		UpdateLandscapingLimits();
 

	
 
		CallWindowTickEvent();
 
		CallWindowGameTickEvent();
 
		NewsLoop();
 
	} else {
 
		if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
 
			/* Save the desync savegame if needed. */
 
			char name[MAX_PATH];
 
			seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
 
			SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
 
		}
 

	
 
		CheckCaches();
 

	
 
		/* All these actions has to be done from OWNER_NONE
 
@@ -1402,25 +1401,25 @@ void StateGameLoop()
 
		IncreaseDate();
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
 

	
 
#ifndef DEBUG_DUMP_COMMANDS
 
		AI::GameLoop();
 
		Game::GameLoop();
 
#endif
 
		UpdateLandscapingLimits();
 

	
 
		CallWindowTickEvent();
 
		CallWindowGameTickEvent();
 
		NewsLoop();
 
		cur_company.Restore();
 
	}
 

	
 
	assert(IsLocalCompany());
 
}
 

	
 
/**
 
 * Create an autosave. The default name is "autosave#.sav". However with
 
 * the setting 'keep_all_autosave' the name defaults to company-name + date
 
 */
 
static void DoAutosave()
src/rail_gui.cpp
Show inline comments
 
@@ -1359,25 +1359,25 @@ public:
 

	
 
				this->CheckSelectedSize(statspec);
 
				this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX)->SetClicked(_railstation.station_type);
 

	
 
				if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
 
				this->SetDirty();
 
				DeleteWindowById(WC_SELECT_STATION, 0);
 
				break;
 
			}
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_station_builder_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_RAIL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BRAS_SHOW_NEWST_DEFSIZE),
 
			NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
 
		EndContainer(),
src/road_gui.cpp
Show inline comments
 
@@ -1044,25 +1044,25 @@ struct BuildRoadStationWindow : public P
 
				this->RaiseWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
 
				_settings_client.gui.station_show_coverage = (widget != WID_BROS_LT_OFF);
 
				this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
 
				if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
 
				this->SetDirty();
 
				break;
 

	
 
			default:
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 
};
 

	
 
/** Widget definition of the build road station window */
 
static const NWidgetPart _nested_road_station_picker_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION,  COLOUR_DARK_GREEN, WID_BROS_CAPTION),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BROS_BACKGROUND),
src/smallmap_gui.cpp
Show inline comments
 
@@ -1561,28 +1561,28 @@ int SmallMapWindow::GetPositionOnLegend(
 
{
 
	if (_settings_client.gui.scrollwheel_scrolling != 2) {
 
		const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
 
		int cursor_x = _cursor.pos.x - this->left - wid->pos_x;
 
		int cursor_y = _cursor.pos.y - this->top  - wid->pos_y;
 
		if (IsInsideMM(cursor_x, 0, wid->current_x) && IsInsideMM(cursor_y, 0, wid->current_y)) {
 
			Point pt = {cursor_x, cursor_y};
 
			this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
 
		}
 
	}
 
}
 

	
 
/* virtual */ void SmallMapWindow::OnTick()
 
/* virtual */ void SmallMapWindow::OnRealtimeTick(uint delta_ms)
 
{
 
	/* Update the window every now and then */
 
	if (--this->refresh != 0) return;
 
	if (!TimerElapsed(this->refresh, delta_ms)) return;
 

	
 
	if (this->map_type == SMT_LINKSTATS) {
 
		uint32 company_mask = this->GetOverlayCompanyMask();
 
		if (this->overlay->GetCompanyMask() != company_mask) {
 
			this->overlay->SetCompanyMask(company_mask);
 
		} else {
 
			this->overlay->RebuildCache();
 
		}
 
	}
 
	_smallmap_industry_highlight_state = !_smallmap_industry_highlight_state;
 

	
 
	this->refresh = _smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD;
src/smallmap_gui.h
Show inline comments
 
@@ -58,37 +58,37 @@ protected:
 
	enum ZoomLevelChange {
 
		ZLC_INITIALIZE, ///< Initialize zoom level.
 
		ZLC_ZOOM_OUT,   ///< Zoom out.
 
		ZLC_ZOOM_IN,    ///< Zoom in.
 
	};
 

	
 
	static SmallMapType map_type; ///< Currently displayed legends.
 
	static bool show_towns;       ///< Display town names in the smallmap.
 
	static int max_heightlevel;   ///< Currently used/cached maximum heightlevel.
 

	
 
	static const uint LEGEND_BLOB_WIDTH = 8;              ///< Width of the coloured blob in front of a line text in the #WID_SM_LEGEND widget.
 
	static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; ///< Minimal number of columns in the #WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
 
	static const uint FORCE_REFRESH_PERIOD = 0x1F; ///< map is redrawn after that many ticks
 
	static const uint BLINK_PERIOD         = 0x0F; ///< highlight blinking interval
 
	static const uint FORCE_REFRESH_PERIOD = 930; ///< map is redrawn after that many milliseconds.
 
	static const uint BLINK_PERIOD         = 450; ///< highlight blinking interval in milliseconds.
 

	
 
	uint min_number_of_columns;    ///< Minimal number of columns in legends.
 
	uint min_number_of_fixed_rows; ///< Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY).
 
	uint column_width;             ///< Width of a column in the #WID_SM_LEGEND widget.
 

	
 
	int32 scroll_x;  ///< Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
 
	int32 scroll_y;  ///< Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
 
	int32 subscroll; ///< Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner of the smallmap display.
 
	int zoom;        ///< Zoom level. Bigger number means more zoom-out (further away).
 

	
 
	uint8 refresh;   ///< Refresh counter, zeroed every FORCE_REFRESH_PERIOD ticks.
 
	int refresh;     ///< Refresh timer, in millseconds.
 
	LinkGraphOverlay *overlay;
 

	
 
	static void BreakIndustryChainLink();
 
	Point SmallmapRemapCoords(int x, int y) const;
 

	
 
	/**
 
	 * Draws vertical part of map indicator
 
	 * @param x X coord of left/right border of main viewport
 
	 * @param y Y coord of top border of main viewport
 
	 * @param y2 Y coord of bottom border of main viewport
 
	 */
 
	static inline void DrawVertMapIndicator(int x, int y, int y2)
 
@@ -178,18 +178,18 @@ public:
 

	
 
	void SmallMapCenterOnCurrentPos();
 
	Point GetStationMiddle(const Station *st) const;
 

	
 
	virtual void SetStringParameters(int widget) const;
 
	virtual void OnInit();
 
	virtual void OnPaint();
 
	virtual void DrawWidget(const Rect &r, int widget) const;
 
	virtual void OnClick(Point pt, int widget, int click_count);
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
 
	virtual bool OnRightClick(Point pt, int widget);
 
	virtual void OnMouseWheel(int wheel);
 
	virtual void OnTick();
 
	virtual void OnRealtimeTick(uint delta_ms);
 
	virtual void OnScroll(Point delta);
 
	virtual void OnMouseOver(Point pt, int widget);
 
};
 

	
 
#endif /* SMALLMAP_GUI_H */
src/station_gui.cpp
Show inline comments
 
@@ -612,25 +612,25 @@ public:
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		if (this->stations.SortType() != index) {
 
			this->stations.SetSortType(index);
 

	
 
			/* Display the current sort variant */
 
			this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = this->sorter_names[this->stations.SortType()];
 

	
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (this->stations.NeedResort()) {
 
			DEBUG(misc, 3, "Periodic rebuild station list company %d", this->window_number);
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll->SetCapacityFromWidget(this, WID_STL_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
	}
 
@@ -2303,25 +2303,25 @@ struct SelectStationWindow : Window {
 

	
 
		/* Insert station to be joined into stored command */
 
		SB(this->select_station_cmd.p2, 16, 16,
 
		   (distant_join ? _stations_nearby_list[st_index] : NEW_STATION));
 

	
 
		/* Execute stored Command */
 
		DoCommandP(&this->select_station_cmd);
 

	
 
		/* Close Window; this might cause double frees! */
 
		DeleteWindowById(WC_SELECT_STATION, 0);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (_thd.dirty & 2) {
 
			_thd.dirty &= ~2;
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll->SetCapacityFromWidget(this, WID_JS_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
	}
 

	
src/statusbar_gui.cpp
Show inline comments
 
@@ -70,28 +70,29 @@ static bool DrawScrollingStatusText(cons
 

	
 
	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);
 
}
 

	
 
struct StatusBarWindow : Window {
 
	bool saving;
 
	int ticker_scroll;
 
	uint ticker_timer;
 
	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_START = 1350; ///< time in ms for reminder notification (red dot on the right) to stay
 
	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(WindowDesc *desc) : Window(desc)
 
	{
 
		this->ticker_scroll    =   TICKER_STOP;
 
		this->reminder_timeout = REMINDER_STOP;
 

	
 
		this->InitNested();
 
		CLRBITS(this->flags, WF_WHITE_BORDER);
 
		PositionStatusbar(this);
 
	}
 
@@ -194,51 +195,53 @@ struct StatusBarWindow : Window {
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (!gui_scope) return;
 
		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->ticker_timer     = 0;
 
				this->reminder_timeout = REMINDER_STOP; // ... and reminder
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case WID_S_MIDDLE: ShowLastNewsMessage(); break;
 
			case WID_S_RIGHT:  if (_local_company != COMPANY_SPECTATOR) ShowCompanyFinances(_local_company); break;
 
			default: ResetObjectToPlace();
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 

	
 
		if (this->ticker_scroll < TICKER_STOP) { // Scrolling text
 
			this->ticker_scroll += COUNTER_STEP;
 
			this->SetWidgetDirty(WID_S_MIDDLE);
 
			uint count = CountIntervalElapsed(this->ticker_timer, delta_ms, 15);
 
			if (count > 0) {
 
				this->ticker_scroll += count;
 
				this->SetWidgetDirty(WID_S_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;
 
		// Red blot to show there are new unread newsmessages
 
		if (TimerElapsed(this->reminder_timeout, delta_ms)) {
 
			this->SetWidgetDirty(WID_S_MIDDLE);
 
		}
 
	}
 
};
 

	
 
static const NWidgetPart _nested_main_status_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_PANEL, COLOUR_GREY, WID_S_LEFT), SetMinimalSize(140, 12), EndContainer(),
 
		NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_S_MIDDLE), SetMinimalSize(40, 12), SetDataTip(0x0, STR_STATUSBAR_TOOLTIP_SHOW_LAST_NEWS), SetResize(1, 0),
 
		NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_S_RIGHT), SetMinimalSize(140, 12),
 
	EndContainer(),
 
};
src/toolbar_gui.cpp
Show inline comments
 
@@ -1969,34 +1969,38 @@ enum MainToolbarHotkeys {
 
	MTHK_ZOOMEDIN_SCREENSHOT,
 
	MTHK_DEFAULTZOOM_SCREENSHOT,
 
	MTHK_GIANT_SCREENSHOT,
 
	MTHK_CHEATS,
 
	MTHK_TERRAFORM,
 
	MTHK_EXTRA_VIEWPORT,
 
	MTHK_CLIENT_LIST,
 
	MTHK_SIGN_LIST,
 
};
 

	
 
/** Main toolbar. */
 
struct MainToolbarWindow : Window {
 
	int timer;
 

	
 
	MainToolbarWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->InitNested(0);
 

	
 
		_last_started_action = CBF_NONE;
 
		CLRBITS(this->flags, WF_WHITE_BORDER);
 
		this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
 
		this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
 
		PositionMainToolbar(this);
 
		DoZoomInOutWindow(ZOOM_NONE, this);
 

	
 
		this->timer = MILLISECONDS_PER_TICK;
 
	}
 

	
 
	virtual void FindWindowPlacementAndResize(int def_width, int def_height)
 
	{
 
		Window::FindWindowPlacementAndResize(_toolbar_width, def_height);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		/* If spectator, disable all construction buttons
 
		 * ie : Build road, rail, ships, airports and landscaping
 
		 * Since enabled state is the default, just disable when needed */
 
@@ -2083,26 +2087,29 @@ struct MainToolbarWindow : Window {
 
				ShowLandInfo(tile);
 
				break;
 

	
 
			default: NOT_REACHED();
 
		}
 
	}
 

	
 
	virtual void OnPlaceObjectAbort()
 
	{
 
		_last_started_action = CBF_NONE;
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (!TimerElapsed(this->timer, delta_ms)) return;
 
		this->timer = MILLISECONDS_PER_TICK;
 

	
 
		if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
 
			this->ToggleWidgetLoweredState(WID_TN_PAUSE);
 
			this->SetWidgetDirty(WID_TN_PAUSE);
 
		}
 

	
 
		if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != !!_fast_forward) {
 
			this->ToggleWidgetLoweredState(WID_TN_FAST_FORWARD);
 
			this->SetWidgetDirty(WID_TN_FAST_FORWARD);
 
		}
 
	}
 

	
 
	virtual void OnTimeout()
 
@@ -2301,32 +2308,36 @@ enum MainToolbarEditorHotkeys {
 
	MTEHK_SMALL_SCREENSHOT,
 
	MTEHK_ZOOMEDIN_SCREENSHOT,
 
	MTEHK_DEFAULTZOOM_SCREENSHOT,
 
	MTEHK_GIANT_SCREENSHOT,
 
	MTEHK_ZOOM_IN,
 
	MTEHK_ZOOM_OUT,
 
	MTEHK_TERRAFORM,
 
	MTEHK_SMALLMAP,
 
	MTEHK_EXTRA_VIEWPORT,
 
};
 

	
 
struct ScenarioEditorToolbarWindow : Window {
 
	int timer;
 

	
 
	ScenarioEditorToolbarWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->InitNested(0);
 

	
 
		_last_started_action = CBF_NONE;
 
		CLRBITS(this->flags, WF_WHITE_BORDER);
 
		PositionMainToolbar(this);
 
		DoZoomInOutWindow(ZOOM_NONE, this);
 

	
 
		this->timer = MILLISECONDS_PER_TICK;
 
	}
 

	
 
	virtual void FindWindowPlacementAndResize(int def_width, int def_height)
 
	{
 
		Window::FindWindowPlacementAndResize(_toolbar_width, def_height);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= MIN_YEAR);
 
		this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= MAX_YEAR);
 

	
 
@@ -2436,26 +2447,29 @@ struct ScenarioEditorToolbarWindow : Win
 
	virtual void OnPlaceObjectAbort()
 
	{
 
		_last_started_action = CBF_NONE;
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		this->SetWidgetsLoweredState(false, WID_TE_DATE_BACKWARD, WID_TE_DATE_FORWARD, WIDGET_LIST_END);
 
		this->SetWidgetDirty(WID_TE_DATE_BACKWARD);
 
		this->SetWidgetDirty(WID_TE_DATE_FORWARD);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (!TimerElapsed(this->timer, delta_ms)) return;
 
		this->timer = MILLISECONDS_PER_TICK;
 

	
 
		if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
 
			this->ToggleWidgetLoweredState(WID_TE_PAUSE);
 
			this->SetDirty();
 
		}
 

	
 
		if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != !!_fast_forward) {
 
			this->ToggleWidgetLoweredState(WID_TE_FAST_FORWARD);
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	/**
src/vehicle_gui.cpp
Show inline comments
 
@@ -1667,25 +1667,25 @@ public:
 
					case ADI_DEPOT: // Send to Depots
 
						DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : (DepotCommand)0), this->window_number, GetCmdSendToDepot(this->vli.vtype));
 
						break;
 

	
 
					default: NOT_REACHED();
 
				}
 
				break;
 
			default: NOT_REACHED();
 
		}
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (this->vehicles.NeedResort()) {
 
			StationID station = (this->vli.type == VL_STATION_LIST) ? this->vli.index : INVALID_STATION;
 

	
 
			DEBUG(misc, 3, "Periodic resort %d list company %d at station %d", this->vli.vtype, this->owner, station);
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
@@ -2724,25 +2724,25 @@ public:
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		if (this->viewport != NULL) {
 
			NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT);
 
			nvp->UpdateViewportCoordinates(this);
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		const Vehicle *v = Vehicle::Get(this->window_number);
 
		bool veh_stopped = v->IsStoppedInDepot();
 

	
 
		/* Widget WID_VV_GOTO_DEPOT must be hidden if the vehicle is already stopped in depot.
 
		 * Widget WID_VV_CLONE_VEH should then be shown, since cloning is allowed only while in depot and stopped.
 
		 */
 
		PlaneSelections plane = veh_stopped ? SEL_DC_CLONE : SEL_DC_GOTO_DEPOT;
 
		NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_DEPOT_CLONE); // Selection widget 'send to depot' / 'clone'.
 
		if (nwi->shown_plane + SEL_DC_BASEPLANE != plane) {
 
			this->SelectPlane(plane);
 
			this->SetWidgetDirty(WID_VV_SELECT_DEPOT_CLONE);
src/window.cpp
Show inline comments
 
@@ -3066,31 +3066,50 @@ void InputLoop()
 
		/* The input loop is called only once per GameLoop() - so we can clear the counter here */
 
		_input_events_this_tick = 0;
 
		/* there were some inputs this tick, don't scroll ??? */
 
		return;
 
	}
 

	
 
	/* HandleMouseEvents was already called for this tick */
 
	HandleMouseEvents();
 
	HandleAutoscroll();
 
}
 

	
 
/**
 
 * Dispatch OnRealtimeTick event over all windows
 
 */
 
void CallWindowRealtimeTickEvent(uint delta_ms)
 
{
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		w->OnRealtimeTick(delta_ms);
 
	}
 
}
 

	
 
/**
 
 * Update the continuously changing contents of the windows, such as the viewports
 
 */
 
void UpdateWindows()
 
{
 
	static uint32 last_realtime_tick = _realtime_tick;
 
	uint delta_ms = _realtime_tick - last_realtime_tick;
 
	last_realtime_tick = _realtime_tick;
 

	
 
	if (delta_ms == 0) return;
 

	
 
	PerformanceMeasurer framerate(PFE_DRAWING);
 
	PerformanceAccumulator::Reset(PFE_DRAWWORLD);
 

	
 
	CallWindowRealtimeTickEvent(delta_ms);
 

	
 
	Window *w;
 

	
 
	static int highlight_timer = 1;
 
	if (--highlight_timer == 0) {
 
		highlight_timer = 15;
 
		_window_highlight_colour = !_window_highlight_colour;
 
	}
 

	
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		w->ProcessScheduledInvalidations();
 
		w->ProcessHighlightedInvalidations();
 
	}
 
@@ -3254,31 +3273,31 @@ void InvalidateWindowData(WindowClass cl
 
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
 
{
 
	Window *w;
 

	
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		if (w->window_class == cls) {
 
			w->InvalidateData(data, gui_scope);
 
		}
 
	}
 
}
 

	
 
/**
 
 * Dispatch WE_TICK event over all windows
 
 * Dispatch OnTick event over all windows
 
 */
 
void CallWindowTickEvent()
 
void CallWindowGameTickEvent()
 
{
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		w->OnTick();
 
		w->OnGameTick();
 
	}
 
}
 

	
 
/**
 
 * Try to delete a non-vital window.
 
 * Non-vital windows are windows other than the game selection, main toolbar,
 
 * status bar, toolbar menu, and tooltip windows. Stickied windows are also
 
 * considered vital.
 
 */
 
void DeleteNonVitalWindows()
 
{
 
	Window *w;
src/window_func.h
Show inline comments
 
@@ -47,13 +47,45 @@ void ShowVitalWindows();
 
void ReInitAllWindows();
 

	
 
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index);
 
void SetWindowDirty(WindowClass cls, WindowNumber number);
 
void SetWindowClassesDirty(WindowClass cls);
 

	
 
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force = true);
 
void DeleteWindowByClass(WindowClass cls);
 

	
 
bool EditBoxInGlobalFocus();
 
Point GetCaretPosition();
 

	
 
/**
 
 * Count how many times the interval has elapsed, and update the timer.
 
 * Use to ensure a specific amount of events happen within a timeframe, e.g. for animation.
 
 * The timer value does not need to be initialised.
 
 * @param timer Timer to test. Value will be increased.
 
 * @param delta Time since last test.
 
 * @param interval Timing interval.
 
 * @return Number of times the interval has elapsed.
 
 */
 
static inline uint CountIntervalElapsed(uint &timer, uint delta, uint interval)
 
{
 
	uint count = delta / interval;
 
	if (timer + (delta % interval) >= interval) count++;
 
	timer = (timer + delta) % interval;
 
	return count;
 
}
 

	
 
/**
 
 * Test if a timer has elapsed, and update the timer.
 
 * Use to ensure an event happens only once within a timeframe, e.g. for window updates.
 
 * The timer value must be initialised in order for the timer to elapsed.
 
 * @param timer Timer to test. Value will be decreased.
 
 * @param delta Time since last test.
 
 * @return True iff the timer has elapsed.
 
 */
 
static inline bool TimerElapsed(int &timer, uint delta)
 
{
 
	if (timer <= 0) return false;
 
	timer -= delta;
 
	return timer <= 0;
 
}
 

	
 
#endif /* WINDOW_FUNC_H */
src/window_gui.h
Show inline comments
 
@@ -669,32 +669,37 @@ public:
 
	 */
 
	virtual void OnMouseWheel(int wheel) {}
 

	
 

	
 
	/**
 
	 * Called for every mouse loop run, which is at least once per (game) tick.
 
	 */
 
	virtual void OnMouseLoop() {}
 

	
 
	/**
 
	 * Called once per (game) tick.
 
	 */
 
	virtual void OnTick() {}
 
	virtual void OnGameTick() {}
 

	
 
	/**
 
	 * Called once every 100 (game) ticks.
 
	 */
 
	virtual void OnHundredthTick() {}
 

	
 
	/**
 
	 * Called periodically.
 
	 */
 
	virtual void OnRealtimeTick(uint delta_ms) {}
 

	
 
	/**
 
	 * Called when this window's timeout has been reached.
 
	 */
 
	virtual void OnTimeout() {}
 

	
 

	
 
	/**
 
	 * Called after the window got resized.
 
	 * For nested windows with a viewport, call NWidgetViewport::UpdateViewportCoordinates.
 
	 */
 
	virtual void OnResize() {}
 

	
 
	/**
0 comments (0 inline, 0 general)