src/airport_gui.cpp
changeset 9268 fa447d3b408d
parent 9238 e2f586d12318
child 9273 35e0224ea8f1
equal deleted inserted replaced
9267:22095cc802dd 9268:fa447d3b408d
   136 	DeleteWindowByClass(WC_BUILD_TOOLBAR);
   136 	DeleteWindowByClass(WC_BUILD_TOOLBAR);
   137 	Window *w = AllocateWindowDescFront<Window>(&_air_toolbar_desc, TRANSPORT_AIR);
   137 	Window *w = AllocateWindowDescFront<Window>(&_air_toolbar_desc, TRANSPORT_AIR);
   138 	if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
   138 	if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
   139 }
   139 }
   140 
   140 
   141 enum {
   141 class AirportPickerWindow : public PickerWindowBase {
   142 	BAW_BOTTOMPANEL = 10,
   142 
   143 	BAW_SMALL_AIRPORT,
   143 	enum {
   144 	BAW_CITY_AIRPORT,
   144 		BAW_BOTTOMPANEL = 10,
   145 	BAW_HELIPORT,
   145 		BAW_SMALL_AIRPORT,
   146 	BAW_METRO_AIRPORT,
   146 		BAW_CITY_AIRPORT,
   147 	BAW_STR_INTERNATIONAL_AIRPORT,
   147 		BAW_HELIPORT,
   148 	BAW_COMMUTER_AIRPORT,
   148 		BAW_METRO_AIRPORT,
   149 	BAW_HELIDEPOT,
   149 		BAW_STR_INTERNATIONAL_AIRPORT,
   150 	BAW_STR_INTERCONTINENTAL_AIRPORT,
   150 		BAW_COMMUTER_AIRPORT,
   151 	BAW_HELISTATION,
   151 		BAW_HELIDEPOT,
   152 	BAW_LAST_AIRPORT = BAW_HELISTATION,
   152 		BAW_STR_INTERCONTINENTAL_AIRPORT,
   153 	BAW_AIRPORT_COUNT = BAW_LAST_AIRPORT - BAW_SMALL_AIRPORT + 1,
   153 		BAW_HELISTATION,
   154 	BAW_BTN_DONTHILIGHT = BAW_LAST_AIRPORT + 1,
   154 		BAW_LAST_AIRPORT = BAW_HELISTATION,
   155 	BAW_BTN_DOHILIGHT,
   155 		BAW_AIRPORT_COUNT = BAW_LAST_AIRPORT - BAW_SMALL_AIRPORT + 1,
   156 };
   156 		BAW_BTN_DONTHILIGHT = BAW_LAST_AIRPORT + 1,
   157 
   157 		BAW_BTN_DOHILIGHT,
   158 static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
   158 	};
   159 {
   159 
   160 	switch (e->event) {
   160 public:
   161 		case WE_CREATE:
   161 
   162 			w->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
   162 	AirportPickerWindow(const WindowDesc *desc) : PickerWindowBase(desc)
   163 			w->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
   163 	{
   164 			w->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   164 		this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
   165 			break;
   165 		this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
   166 
   166 		this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   167 		case WE_PAINT: {
   167 
   168 			int i; // airport enabling loop
   168 		this->FindWindowPlacementAndResize(desc);
   169 			uint32 avail_airports;
   169 	}
   170 			const AirportFTAClass *airport;
   170 
   171 
   171 	virtual void OnPaint()
   172 			avail_airports = GetValidAirports();
   172 	{
   173 
   173 		int i; // airport enabling loop
   174 			w->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   174 		uint32 avail_airports;
   175 			if (!HasBit(avail_airports, 0) && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE;
   175 		const AirportFTAClass *airport;
   176 			if (!HasBit(avail_airports, 1) && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL;
   176 
   177 			w->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   177 		avail_airports = GetValidAirports();
   178 
   178 
   179 			/* 'Country Airport' starts at widget BAW_SMALL_AIRPORT, and if its bit is set, it is
   179 		this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   180 			 * available, so take its opposite value to set the disabled state.
   180 		if (!HasBit(avail_airports, 0) && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE;
   181 			 * There are 9 buildable airports
   181 		if (!HasBit(avail_airports, 1) && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL;
   182 			 * XXX TODO : all airports should be held in arrays, with all relevant data.
   182 		this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   183 			 * This should be part of newgrf-airports, i suppose
   183 
   184 			 */
   184 		/* 'Country Airport' starts at widget BAW_SMALL_AIRPORT, and if its bit is set, it is
   185 			for (i = 0; i < BAW_AIRPORT_COUNT; i++) w->SetWidgetDisabledState(i + BAW_SMALL_AIRPORT, !HasBit(avail_airports, i));
   185 		 * available, so take its opposite value to set the disabled state.
   186 
   186 		 * There are 9 buildable airports
   187 			/* select default the coverage area to 'Off' (16) */
   187 		 * XXX TODO : all airports should be held in arrays, with all relevant data.
   188 			airport = GetAirport(_selected_airport_type);
   188 		 * This should be part of newgrf-airports, i suppose
   189 			SetTileSelectSize(airport->size_x, airport->size_y);
   189 		 */
   190 
   190 		for (i = 0; i < BAW_AIRPORT_COUNT; i++) this->SetWidgetDisabledState(i + BAW_SMALL_AIRPORT, !HasBit(avail_airports, i));
   191 			int rad = _patches.modified_catchment ? airport->catchment : (uint)CA_UNMODIFIED;
   191 
   192 
   192 		/* select default the coverage area to 'Off' (16) */
   193 			if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
   193 		airport = GetAirport(_selected_airport_type);
   194 
   194 		SetTileSelectSize(airport->size_x, airport->size_y);
   195 			DrawWindowWidgets(w);
   195 
   196 			/* strings such as 'Size' and 'Coverage Area' */
   196 		int rad = _patches.modified_catchment ? airport->catchment : (uint)CA_UNMODIFIED;
   197 			int text_end = DrawStationCoverageAreaText(2, 206, SCT_ALL, rad, false);
   197 
   198 			text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4;
   198 		if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
   199 			if (text_end != w->widget[BAW_BOTTOMPANEL].bottom) {
   199 
   200 				w->SetDirty();
   200 		DrawWindowWidgets(this);
   201 				ResizeWindowForWidget(w, BAW_BOTTOMPANEL, 0, text_end - w->widget[BAW_BOTTOMPANEL].bottom);
   201 		/* strings such as 'Size' and 'Coverage Area' */
   202 				w->SetDirty();
   202 		int text_end = DrawStationCoverageAreaText(2, 206, SCT_ALL, rad, false);
   203 			}
   203 		text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4;
   204 			break;
   204 		if (text_end != this->widget[BAW_BOTTOMPANEL].bottom) {
       
   205 			this->SetDirty();
       
   206 			ResizeWindowForWidget(this, BAW_BOTTOMPANEL, 0, text_end - this->widget[BAW_BOTTOMPANEL].bottom);
       
   207 			this->SetDirty();
   205 		}
   208 		}
   206 
   209 	}
   207 		case WE_CLICK: {
   210 
   208 			switch (e->we.click.widget) {
   211 	virtual void OnClick(Point pt, int widget)
   209 				case BAW_SMALL_AIRPORT: case BAW_CITY_AIRPORT: case BAW_HELIPORT: case BAW_METRO_AIRPORT:
   212 	{
   210 				case BAW_STR_INTERNATIONAL_AIRPORT: case BAW_COMMUTER_AIRPORT: case BAW_HELIDEPOT:
   213 		switch (widget) {
   211 				case BAW_STR_INTERCONTINENTAL_AIRPORT: case BAW_HELISTATION:
   214 			case BAW_SMALL_AIRPORT: case BAW_CITY_AIRPORT: case BAW_HELIPORT: case BAW_METRO_AIRPORT:
   212 					w->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   215 			case BAW_STR_INTERNATIONAL_AIRPORT: case BAW_COMMUTER_AIRPORT: case BAW_HELIDEPOT:
   213 					_selected_airport_type = e->we.click.widget - BAW_SMALL_AIRPORT;
   216 			case BAW_STR_INTERCONTINENTAL_AIRPORT: case BAW_HELISTATION:
   214 					w->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   217 				this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   215 					SndPlayFx(SND_15_BEEP);
   218 				_selected_airport_type = widget - BAW_SMALL_AIRPORT;
   216 					w->SetDirty();
   219 				this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
   217 					break;
   220 				SndPlayFx(SND_15_BEEP);
   218 
   221 				this->SetDirty();
   219 				case BAW_BTN_DONTHILIGHT: case BAW_BTN_DOHILIGHT:
   222 				break;
   220 					_station_show_coverage = (e->we.click.widget != BAW_BTN_DONTHILIGHT);
   223 
   221 					w->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
   224 			case BAW_BTN_DONTHILIGHT: case BAW_BTN_DOHILIGHT:
   222 					w->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
   225 				_station_show_coverage = (widget != BAW_BTN_DONTHILIGHT);
   223 					SndPlayFx(SND_15_BEEP);
   226 				this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
   224 					w->SetDirty();
   227 				this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
   225 					break;
   228 				SndPlayFx(SND_15_BEEP);
   226 			}
   229 				this->SetDirty();
   227 		} break;
   230 				break;
   228 
   231 		}
   229 		case WE_TICK:
   232 	}
   230 			CheckRedrawStationCoverage(w);
   233 
   231 			break;
   234 	virtual void OnTick()
   232 
   235 	{
   233 		case WE_DESTROY:
   236 		CheckRedrawStationCoverage(this);
   234 			ResetObjectToPlace();
   237 	}
   235 			break;
   238 };
   236 	}
       
   237 }
       
   238 
   239 
   239 static const Widget _build_airport_picker_widgets[] = {
   240 static const Widget _build_airport_picker_widgets[] = {
   240 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                         STR_018B_CLOSE_WINDOW},
   241 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                         STR_018B_CLOSE_WINDOW},
   241 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   147,     0,    13, STR_3001_AIRPORT_SELECTION,       STR_018C_WINDOW_TITLE_DRAG_THIS},
   242 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   147,     0,    13, STR_3001_AIRPORT_SELECTION,       STR_018C_WINDOW_TITLE_DRAG_THIS},
   242 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   147,    14,    52, 0x0,                              STR_NULL},
   243 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   147,    14,    52, 0x0,                              STR_NULL},
   266 static const WindowDesc _build_airport_desc = {
   267 static const WindowDesc _build_airport_desc = {
   267 	WDP_AUTO, WDP_AUTO, 148, 240, 148, 240,
   268 	WDP_AUTO, WDP_AUTO, 148, 240, 148, 240,
   268 	WC_BUILD_STATION, WC_BUILD_TOOLBAR,
   269 	WC_BUILD_STATION, WC_BUILD_TOOLBAR,
   269 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
   270 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
   270 	_build_airport_picker_widgets,
   271 	_build_airport_picker_widgets,
   271 	BuildAirportPickerWndProc
   272 	NULL
   272 };
   273 };
   273 
   274 
   274 static void ShowBuildAirportPicker()
   275 static void ShowBuildAirportPicker()
   275 {
   276 {
   276 	new Window(&_build_airport_desc);
   277 	new AirportPickerWindow(&_build_airport_desc);
   277 }
   278 }
   278 
   279 
   279 void InitializeAirportGui()
   280 void InitializeAirportGui()
   280 {
   281 {
   281 	_selected_airport_type = AT_SMALL;
   282 	_selected_airport_type = AT_SMALL;