Changeset - r23650:dd03dfeb617d
[Not reviewed]
master
0 8 0
peter1138 - 6 years ago 2019-02-22 18:14:06
peter1138@openttd.org
Feature: Add coverage area display for existing stations.
8 files changed with 102 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -234,12 +234,14 @@ STR_TOOLTIP_GROUP_ORDER                 
 
STR_TOOLTIP_SORT_ORDER                                          :{BLACK}Select sorting order (descending/ascending)
 
STR_TOOLTIP_SORT_CRITERIA                                       :{BLACK}Select sorting criteria
 
STR_TOOLTIP_FILTER_CRITERIA                                     :{BLACK}Select filtering criteria
 
STR_BUTTON_SORT_BY                                              :{BLACK}Sort by
 
STR_BUTTON_LOCATION                                             :{BLACK}Location
 
STR_BUTTON_RENAME                                               :{BLACK}Rename
 
STR_BUTTON_CATCHMENT                                            :{BLACK}Coverage
 
STR_TOOLTIP_CATCHMENT                                           :{BLACK}Toggle coverage area display
 

	
 
STR_TOOLTIP_CLOSE_WINDOW                                        :{BLACK}Close window
 
STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS                              :{BLACK}Window title - drag this to move window
 
STR_TOOLTIP_SHADE                                               :{BLACK}Shade window - only show the title bar
 
STR_TOOLTIP_DEBUG                                               :{BLACK}Show NewGRF debug information
 
STR_TOOLTIP_DEFSIZE                                             :{BLACK}Resize window to default size. Ctrl+Click to store current size as default
src/script/api/game/game_window.hpp.sq
Show inline comments
 
@@ -1114,12 +1114,13 @@ void SQGSWindow_Register(Squirrel *engin
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_RENAME,                             "WID_SV_RENAME");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_CLOSE_AIRPORT,                      "WID_SV_CLOSE_AIRPORT");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_TRAINS,                             "WID_SV_TRAINS");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_ROADVEHS,                           "WID_SV_ROADVEHS");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_SHIPS,                              "WID_SV_SHIPS");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_PLANES,                             "WID_SV_PLANES");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_CATCHMENT,                          "WID_SV_CATCHMENT");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_CAPTION,                           "WID_STL_CAPTION");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_LIST,                              "WID_STL_LIST");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_SCROLLBAR,                         "WID_STL_SCROLLBAR");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_TRAIN,                             "WID_STL_TRAIN");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_TRUCK,                             "WID_STL_TRUCK");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_BUS,                               "WID_STL_BUS");
src/script/api/script_window.hpp
Show inline comments
 
@@ -2286,12 +2286,13 @@ public:
 
		WID_SV_RENAME                                = ::WID_SV_RENAME,                                ///< 'Rename' button.
 
		WID_SV_CLOSE_AIRPORT                         = ::WID_SV_CLOSE_AIRPORT,                         ///< 'Close airport' button.
 
		WID_SV_TRAINS                                = ::WID_SV_TRAINS,                                ///< List of scheduled trains button.
 
		WID_SV_ROADVEHS                              = ::WID_SV_ROADVEHS,                              ///< List of scheduled road vehs button.
 
		WID_SV_SHIPS                                 = ::WID_SV_SHIPS,                                 ///< List of scheduled ships button.
 
		WID_SV_PLANES                                = ::WID_SV_PLANES,                                ///< List of scheduled planes button.
 
		WID_SV_CATCHMENT                             = ::WID_SV_CATCHMENT,                             ///< Toggle catchment area highlight.
 
	};
 

	
 
	/** Widgets of the #CompanyStationsWindow class. */
 
	enum StationListWidgets {
 
		/* Name starts with ST instead of S, because of collision with SaveLoadWidgets */
 
		WID_STL_CAPTION                              = ::WID_STL_CAPTION,                              ///< Caption of the window.
src/settings.cpp
Show inline comments
 
@@ -1317,12 +1317,13 @@ static bool ChangeMaxHeightLevel(int32 p
 
	return true;
 
}
 

	
 
static bool StationCatchmentChanged(int32 p1)
 
{
 
	Station::RecomputeCatchmentForAll();
 
	MarkWholeScreenDirty();
 
	return true;
 
}
 

	
 
static bool MaxVehiclesChanged(int32 p1)
 
{
 
	InvalidateWindowClassesData(WC_BUILD_TOOLBAR);
src/station_gui.cpp
Show inline comments
 
@@ -782,12 +782,13 @@ static const NWidgetPart _nested_station
 
					SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_RENAME), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1),
 
					SetDataTip(STR_BUTTON_RENAME, STR_STATION_VIEW_RENAME_TOOLTIP),
 
		EndContainer(),
 
		NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1),
 
				SetDataTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
 
		NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CATCHMENT), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_TRAINS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ROADVEHS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SHIPS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_PLANES),  SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_PLANE, STR_STATION_VIEW_SCHEDULED_AIRCRAFT_TOOLTIP),
 
		NWidget(WWT_RESIZEBOX, COLOUR_GREY),
 
	EndContainer(),
 
@@ -1310,12 +1311,14 @@ struct StationViewWindow : public Window
 
	~StationViewWindow()
 
	{
 
		DeleteWindowById(WC_TRAINS_LIST,   VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN,    this->owner, this->window_number).Pack(), false);
 
		DeleteWindowById(WC_ROADVEH_LIST,  VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD,     this->owner, this->window_number).Pack(), false);
 
		DeleteWindowById(WC_SHIPS_LIST,    VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP,     this->owner, this->window_number).Pack(), false);
 
		DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false);
 

	
 
		SetViewportCatchmentStation(Station::Get(this->window_number), false);
 
	}
 

	
 
	/**
 
	 * Show a certain cargo entry characterized by source/next/dest station, cargo ID and amount of cargo at the
 
	 * right place in the cargo view. I.e. update as many rows as are expanded following that characterization.
 
	 * @param data Root entry of the tree.
 
@@ -1399,12 +1402,16 @@ struct StationViewWindow : public Window
 
		this->SetWidgetDisabledState(WID_SV_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
 
		this->SetWidgetDisabledState(WID_SV_SHIPS,    !(st->facilities & FACIL_DOCK));
 
		this->SetWidgetDisabledState(WID_SV_PLANES,   !(st->facilities & FACIL_AIRPORT));
 
		this->SetWidgetDisabledState(WID_SV_CLOSE_AIRPORT, !(st->facilities & FACIL_AIRPORT) || st->owner != _local_company || st->owner == OWNER_NONE); // Also consider SE, where _local_company == OWNER_NONE
 
		this->SetWidgetLoweredState(WID_SV_CLOSE_AIRPORT, (st->facilities & FACIL_AIRPORT) && (st->airport.flags & AIRPORT_CLOSED_block) != 0);
 

	
 
		extern const Station *_viewport_highlight_station;
 
		this->SetWidgetDisabledState(WID_SV_CATCHMENT, st->facilities == FACIL_NONE);
 
		this->SetWidgetLoweredState(WID_SV_CATCHMENT, _viewport_highlight_station == st);
 

	
 
		this->DrawWidgets();
 

	
 
		if (!this->IsShaded()) {
 
			/* Draw 'accepted cargo' or 'cargo ratings'. */
 
			const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SV_ACCEPT_RATING_LIST);
 
			const Rect r = {(int)wid->pos_x, (int)wid->pos_y, (int)(wid->pos_x + wid->current_x - 1), (int)(wid->pos_y + wid->current_y - 1)};
 
@@ -1880,12 +1887,16 @@ struct StationViewWindow : public Window
 
	{
 
		switch (widget) {
 
			case WID_SV_WAITING:
 
				this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL) - this->vscroll->GetPosition());
 
				break;
 

	
 
			case WID_SV_CATCHMENT:
 
				SetViewportCatchmentStation(Station::Get(this->window_number), !this->IsWidgetLowered(WID_SV_CATCHMENT));
 
				break;
 

	
 
			case WID_SV_LOCATION:
 
				if (_ctrl_pressed) {
 
					ShowExtraViewPortWindow(Station::Get(this->window_number)->xy);
 
				} else {
 
					ScrollMainWindowToTile(Station::Get(this->window_number)->xy);
 
				}
 
@@ -2244,12 +2255,17 @@ struct SelectStationWindow : Window {
 
		this->vscroll = this->GetScrollbar(WID_JS_SCROLLBAR);
 
		this->GetWidget<NWidgetCore>(WID_JS_CAPTION)->widget_data = T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION;
 
		this->FinishInitNested(0);
 
		this->OnInvalidateData(0);
 
	}
 

	
 
	~SelectStationWindow()
 
	{
 
		if (_settings_client.gui.station_show_coverage) SetViewportCatchmentStation(nullptr, true);
 
	}
 

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

	
 
		/* Determine the widest string */
 
		Dimension d = GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
src/viewport.cpp
Show inline comments
 
@@ -976,22 +976,63 @@ static void DrawAutorailSelection(const 
 
		pal = PALETTE_SEL_TILE_RED;
 
	}
 

	
 
	DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti, 7, foundation_part);
 
}
 

	
 
enum TileHighlightType {
 
	THT_NONE,
 
	THT_WHITE,
 
	THT_BLUE,
 
};
 

	
 
const Station *_viewport_highlight_station; ///< Currently selected station for coverage area highlight
 

	
 
/**
 
 * Get tile highlight type of coverage area for a given tile.
 
 * @param t Tile that is being drawn
 
 * @return Tile highlight type to draw
 
 */
 
static TileHighlightType GetTileHighlightType(TileIndex t)
 
{
 
	if (_viewport_highlight_station != nullptr) {
 
		if (IsTileType(t, MP_STATION) && GetStationIndex(t) == _viewport_highlight_station->index) return THT_WHITE;
 
		if (_viewport_highlight_station->TileIsInCatchment(t)) return THT_BLUE;
 
	}
 

	
 
	return THT_NONE;
 
}
 

	
 
/**
 
 * Draw tile highlight for coverage area highlight.
 
 * @param *ti TileInfo Tile that is being drawn
 
 * @param tht Highlight type to draw.
 
 */
 
static void DrawTileHighlightType(const TileInfo *ti, TileHighlightType tht)
 
{
 
	switch (tht) {
 
		default:
 
		case THT_NONE: break;
 
		case THT_WHITE: DrawTileSelectionRect(ti, PAL_NONE); break;
 
		case THT_BLUE:  DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE); break;
 
	}
 
}
 

	
 
/**
 
 * Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
 
 * @param *ti TileInfo Tile that is being drawn
 
 */
 
static void DrawTileSelection(const TileInfo *ti)
 
{
 
	/* Draw a red error square? */
 
	bool is_redsq = _thd.redsq == ti->tile;
 
	if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING);
 

	
 
	TileHighlightType tht = GetTileHighlightType(ti->tile);
 
	DrawTileHighlightType(ti, tht);
 

	
 
	/* No tile selection active? */
 
	if ((_thd.drawstyle & HT_DRAG_MASK) == HT_NONE) return;
 

	
 
	if (_thd.diagonal) { // We're drawing a 45 degrees rotated (diagonal) rectangle
 
		if (IsInsideRotatedRectangle((int)ti->x, (int)ti->y)) goto draw_inner;
 
		return;
 
@@ -1040,13 +1081,13 @@ draw_inner:
 
			DrawAutorailSelection(ti, _autorail_type[dir][side]);
 
		}
 
		return;
 
	}
 

	
 
	/* Check if it's inside the outer area? */
 
	if (!is_redsq && _thd.outersize.x > 0 &&
 
	if (!is_redsq && tht == THT_NONE && _thd.outersize.x > 0 &&
 
			IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
 
			IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
 
		/* Draw a blue rect. */
 
		DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE);
 
		return;
 
	}
 
@@ -3339,6 +3380,40 @@ CommandCost CmdScrollViewport(TileIndex 
 
	if (flags & DC_EXEC) {
 
		ResetObjectToPlace();
 
		ScrollMainWindowToTile(tile);
 
	}
 
	return CommandCost();
 
}
 

	
 
static void MarkCatchmentTilesDirty()
 
{
 
	if (_viewport_highlight_station != nullptr) {
 
		if (_viewport_highlight_station->catchment_tiles.tile == INVALID_TILE) {
 
			MarkWholeScreenDirty();
 
			_viewport_highlight_station = nullptr;
 
		} else {
 
			BitmapTileIterator it(_viewport_highlight_station->catchment_tiles);
 
			for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Select or deselect station for coverage area highlight.
 
 * @param *st Station in question
 
 * @param sel Select or deselect given station
 
 */
 
void SetViewportCatchmentStation(const Station *st, bool sel)
 
{
 
	if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index);
 
	if (sel && _viewport_highlight_station != st) {
 
		MarkCatchmentTilesDirty();
 
		_viewport_highlight_station = st;
 
		MarkCatchmentTilesDirty();
 
	} else if (!sel && _viewport_highlight_station == st) {
 
		MarkCatchmentTilesDirty();
 
		_viewport_highlight_station = nullptr;
 
	}
 
	if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index);
 
}
src/viewport_func.h
Show inline comments
 
@@ -91,7 +91,11 @@ static inline void MarkTileDirtyByTile(T
 
{
 
	MarkTileDirtyByTile(tile, bridge_level_offset, TileHeight(tile));
 
}
 

	
 
Point GetViewportStationMiddle(const ViewPort *vp, const Station *st);
 

	
 
struct Station;
 

	
 
void SetViewportCatchmentStation(const Station *st, bool sel);
 

	
 
#endif /* VIEWPORT_FUNC_H */
src/widgets/station_widget.h
Show inline comments
 
@@ -27,12 +27,13 @@ enum StationViewWidgets {
 
	WID_SV_RENAME,             ///< 'Rename' button.
 
	WID_SV_CLOSE_AIRPORT,      ///< 'Close airport' button.
 
	WID_SV_TRAINS,             ///< List of scheduled trains button.
 
	WID_SV_ROADVEHS,           ///< List of scheduled road vehs button.
 
	WID_SV_SHIPS,              ///< List of scheduled ships button.
 
	WID_SV_PLANES,             ///< List of scheduled planes button.
 
	WID_SV_CATCHMENT,          ///< Toggle catchment area highlight.
 
};
 

	
 
/** Widgets of the #CompanyStationsWindow class. */
 
enum StationListWidgets {
 
	/* Name starts with ST instead of S, because of collision with SaveLoadWidgets */
 
	WID_STL_CAPTION,        ///< Caption of the window.
0 comments (0 inline, 0 general)