File diff r15688:5bb1558218af → r15689:f98f51eeeb0c
src/airport_gui.cpp
Show inline comments
 
@@ -24,43 +24,45 @@
 
#include "company_base.h"
 
#include "station_type.h"
 
#include "newgrf_airport.h"
 
#include "widgets/dropdown_type.h"
 
#include "core/geometry_func.hpp"
 
#include "hotkeys.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
static AirportClassID _selected_airport_class; ///< the currently visible airport class
 
static int _selected_airport_index;            ///< the index of the selected airport in the current class or -1
 
static byte _selected_airport_layout;          ///< selected airport layout number.
 

	
 
static void ShowBuildAirportPicker(Window *parent);
 

	
 

	
 
void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (result.Failed()) return;
 

	
 
	SndPlayTileFx(SND_1F_SPLAT, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
static void PlaceAirport(TileIndex tile)
 
{
 
	if (_selected_airport_index == -1) return;
 
	uint32 p2 = _ctrl_pressed;
 
	SB(p2, 16, 16, INVALID_STATION); // no station to join
 

	
 
	uint32 p1 = GetAirportSpecFromClass(_selected_airport_class, _selected_airport_index)->GetIndex();
 
	p1 |= _selected_airport_layout << 8;
 
	CommandContainer cmdcont = { tile, p1, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport, "" };
 
	ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));
 
}
 

	
 
/** Widget number of the airport build window. */
 
enum AirportToolbarWidgets {
 
	ATW_AIRPORT,
 
	ATW_DEMOLISH,
 
};
 

	
 

	
 
static void BuildAirClick_Airport(Window *w)
 
@@ -188,24 +190,27 @@ EventState AirportToolbarGlobalHotkeys(u
 
	int num = CheckHotkeyMatch<BuildAirToolbarWindow>(_airtoolbar_hotkeys, keycode, NULL, true);
 
	if (num == -1) return ES_NOT_HANDLED;
 
	Window *w = ShowBuildAirToolbar();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	return w->OnKeyPress(key, keycode);
 
}
 

	
 
/** Airport widgets in the airport picker window. */
 
enum AirportPickerWidgets {
 
	BAIRW_CLASS_DROPDOWN,
 
	BAIRW_AIRPORT_LIST,
 
	BAIRW_SCROLLBAR,
 
	BAIRW_LAYOUT_NUM,
 
	BAIRW_LAYOUT_DECREASE,
 
	BAIRW_LAYOUT_INCREASE,
 
	BAIRW_BOTTOMPANEL,
 
	BAIRW_COVERAGE_LABEL,
 
	BAIRW_BTN_DONTHILIGHT,
 
	BAIRW_BTN_DOHILIGHT,
 
};
 

	
 
class BuildAirportWindow : public PickerWindowBase {
 
	int line_height;
 

	
 
	/** Build a dropdown list of available airport classes */
 
	static DropDownList *BuildAirportClassDropDown()
 
	{
 
@@ -231,27 +236,36 @@ public:
 

	
 
		this->vscroll.SetCount(GetNumAirportsInClass(_selected_airport_class));
 
		this->SelectFirstAvailableAirport(true);
 
	}
 

	
 
	virtual ~BuildAirportWindow()
 
	{
 
		DeleteWindowById(WC_SELECT_STATION, 0);
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget != BAIRW_CLASS_DROPDOWN) return;
 
		switch (widget) {
 
			case BAIRW_CLASS_DROPDOWN:
 
				SetDParam(0, GetAirportClassName(_selected_airport_class));
 
				break;
 

	
 
		SetDParam(0, GetAirportClassName(_selected_airport_class));
 
			case BAIRW_LAYOUT_NUM:
 
				SetDParam(0, STR_STATION_BUILD_AIRPORT_LAYOUT_NAME);
 
				SetDParam(1, _selected_airport_layout + 1);
 
				break;
 

	
 
			default: break;
 
		}
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case BAIRW_CLASS_DROPDOWN: {
 
				Dimension d = {0, 0};
 
				for (uint i = 0; i < GetNumAirportClasses(); i++) {
 
					SetDParam(0, GetAirportClassName((AirportClassID)i));
 
					d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
 
				}
 
				d.width += padding.width;
 
@@ -319,37 +333,43 @@ public:
 
			top = DrawStationCoverageAreaText(panel_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
 
		}
 

	
 
		/* Resize background if the text is not equally long as the window. */
 
		if (top > bottom || (top < bottom && panel_nwi->current_y > panel_nwi->smallest_y)) {
 
			ResizeWindow(this, 0, top - bottom);
 
		}
 
	}
 

	
 
	void SelectOtherAirport(int airport_index)
 
	{
 
		_selected_airport_index = airport_index;
 
		_selected_airport_layout = 0;
 

	
 
		this->UpdateSelectSize();
 
		this->SetDirty();
 
	}
 

	
 
	void UpdateSelectSize()
 
	{
 
		if (_selected_airport_index == -1) {
 
			SetTileSelectSize(1, 1);
 
			this->DisableWidget(BAIRW_LAYOUT_DECREASE);
 
			this->DisableWidget(BAIRW_LAYOUT_INCREASE);
 
		} else {
 
			const AirportSpec *as = GetAirportSpecFromClass(_selected_airport_class, _selected_airport_index);
 
			SetTileSelectSize(as->size_x, as->size_y);
 

	
 
			this->SetWidgetDisabledState(BAIRW_LAYOUT_DECREASE, _selected_airport_layout == 0);
 
			this->SetWidgetDisabledState(BAIRW_LAYOUT_INCREASE, _selected_airport_layout + 1 >= as->num_table);
 

	
 
			int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
 
			if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case BAIRW_CLASS_DROPDOWN:
 
				ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class, BAIRW_CLASS_DROPDOWN);
 
				break;
 

	
 
@@ -360,24 +380,36 @@ public:
 
				if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
 
				break;
 
			}
 

	
 
			case BAIRW_BTN_DONTHILIGHT: case BAIRW_BTN_DOHILIGHT:
 
				_settings_client.gui.station_show_coverage = (widget != BAIRW_BTN_DONTHILIGHT);
 
				this->SetWidgetLoweredState(BAIRW_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
 
				this->SetWidgetLoweredState(BAIRW_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
 
				this->SetDirty();
 
				SndPlayFx(SND_15_BEEP);
 
				this->UpdateSelectSize();
 
				break;
 

	
 
			case BAIRW_LAYOUT_DECREASE:
 
				_selected_airport_layout--;
 
				this->UpdateSelectSize();
 
				this->SetDirty();
 
				break;
 

	
 
			case BAIRW_LAYOUT_INCREASE:
 
				_selected_airport_layout++;
 
				this->UpdateSelectSize();
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 

	
 
	/**
 
	 * Select the first available airport.
 
	 * @param change_class If true, change the class if no airport in the current
 
	 *   class is available.
 
	 */
 
	void SelectFirstAvailableAirport(bool change_class)
 
	{
 
		/* First try to select an airport in the selected class. */
 
		for (uint i = 0; i < GetNumAirportsInClass(_selected_airport_class); i++) {
 
@@ -422,24 +454,29 @@ public:
 
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),
 
		NWidget(WWT_DROPDOWN, COLOUR_GREY, BAIRW_CLASS_DROPDOWN), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NULL),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_MATRIX, COLOUR_GREY, BAIRW_AIRPORT_LIST), SetFill(1, 0), SetDataTip(0x501, STR_NULL),
 
			NWidget(WWT_SCROLLBAR, COLOUR_GREY, BAIRW_SCROLLBAR),
 
		EndContainer(),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(NWID_BUTTON_ARROW, COLOUR_GREY, BAIRW_LAYOUT_DECREASE), SetMinimalSize(12, 0),SetDataTip(AWV_DECREASE, STR_NULL),
 
			NWidget(WWT_LABEL, COLOUR_GREY, BAIRW_LAYOUT_NUM), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NULL),
 
			NWidget(NWID_BUTTON_ARROW, COLOUR_GREY, BAIRW_LAYOUT_INCREASE), SetMinimalSize(12, 0), SetDataTip(AWV_INCREASE, STR_NULL),
 
		EndContainer(),
 
	EndContainer(),
 
	/* Bottom panel. */
 
	NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BAIRW_BOTTOMPANEL), SetPIP(2, 2, 2),
 
		NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL), SetFill(1, 0),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(NWID_SPACER), SetMinimalSize(14, 0), SetFill(1, 0),
 
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
 
				NWidget(WWT_TEXTBTN, COLOUR_GREY, BAIRW_BTN_DONTHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
 
											SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
 
				NWidget(WWT_TEXTBTN, COLOUR_GREY, BAIRW_BTN_DOHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
 
											SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
 
			EndContainer(),