rail_gui.c
changeset 5147 866030c20f0a
parent 5116 3c0c3da214ca
child 5231 ac9fcb5cc5f4
equal deleted inserted replaced
5146:a2a2cfc45bc3 5147:866030c20f0a
   223 static void PlaceRail_AutoSignals(TileIndex tile)
   223 static void PlaceRail_AutoSignals(TileIndex tile)
   224 {
   224 {
   225 	VpStartPlaceSizing(tile, VPM_SIGNALDIRS);
   225 	VpStartPlaceSizing(tile, VPM_SIGNALDIRS);
   226 }
   226 }
   227 
   227 
       
   228 
       
   229 /** Enum referring to the widgets of the build rail toolbar */
       
   230 enum {
       
   231 	RTW_CAPTION        =  1,
       
   232 	RTW_BUILD_NS       =  4,
       
   233 	RTW_BUILD_X        =  5,
       
   234 	RTW_BUILD_EW       =  6,
       
   235 	RTW_BUILD_Y        =  7,
       
   236 	RTW_AUTORAIL       =  8,
       
   237 	RTW_DEMOLISH       =  9,
       
   238 	RTW_BUILD_DEPOT    = 10,
       
   239 	RTW_BUILD_WAYPOINT = 11,
       
   240 	RTW_BUILD_STATION  = 12,
       
   241 	RTW_BUILD_SIGNALS  = 13,
       
   242 	RTW_BUILD_BRIDGE   = 14,
       
   243 	RTW_BUILD_TUNNEL   = 15,
       
   244 	RTW_REMOVE         = 16,
       
   245 	RTW_CONVERT_RAIL   = 17
       
   246 };
       
   247 
       
   248 
   228 static void BuildRailClick_N(Window *w)
   249 static void BuildRailClick_N(Window *w)
   229 {
   250 {
   230 	HandlePlacePushButton(w, 4, GetRailTypeInfo(_cur_railtype)->cursor.rail_ns, 1, PlaceRail_N);
   251 	HandlePlacePushButton(w, RTW_BUILD_NS, GetRailTypeInfo(_cur_railtype)->cursor.rail_ns, 1, PlaceRail_N);
   231 }
   252 }
   232 
   253 
   233 static void BuildRailClick_NE(Window *w)
   254 static void BuildRailClick_NE(Window *w)
   234 {
   255 {
   235 	HandlePlacePushButton(w, 5, GetRailTypeInfo(_cur_railtype)->cursor.rail_swne, 1, PlaceRail_NE);
   256 	HandlePlacePushButton(w, RTW_BUILD_X, GetRailTypeInfo(_cur_railtype)->cursor.rail_swne, 1, PlaceRail_NE);
   236 }
   257 }
   237 
   258 
   238 static void BuildRailClick_E(Window *w)
   259 static void BuildRailClick_E(Window *w)
   239 {
   260 {
   240 	HandlePlacePushButton(w, 6, GetRailTypeInfo(_cur_railtype)->cursor.rail_ew, 1, PlaceRail_E);
   261 	HandlePlacePushButton(w, RTW_BUILD_EW, GetRailTypeInfo(_cur_railtype)->cursor.rail_ew, 1, PlaceRail_E);
   241 }
   262 }
   242 
   263 
   243 static void BuildRailClick_NW(Window *w)
   264 static void BuildRailClick_NW(Window *w)
   244 {
   265 {
   245 	HandlePlacePushButton(w, 7, GetRailTypeInfo(_cur_railtype)->cursor.rail_nwse, 1, PlaceRail_NW);
   266 	HandlePlacePushButton(w, RTW_BUILD_Y, GetRailTypeInfo(_cur_railtype)->cursor.rail_nwse, 1, PlaceRail_NW);
   246 }
   267 }
   247 
   268 
   248 static void BuildRailClick_AutoRail(Window *w)
   269 static void BuildRailClick_AutoRail(Window *w)
   249 {
   270 {
   250 	HandlePlacePushButton(w, 8, GetRailTypeInfo(_cur_railtype)->cursor.autorail, VHM_RAIL, PlaceRail_AutoRail);
   271 	HandlePlacePushButton(w, RTW_AUTORAIL, GetRailTypeInfo(_cur_railtype)->cursor.autorail, VHM_RAIL, PlaceRail_AutoRail);
   251 }
   272 }
   252 
   273 
   253 static void BuildRailClick_Demolish(Window *w)
   274 static void BuildRailClick_Demolish(Window *w)
   254 {
   275 {
   255 	HandlePlacePushButton(w, 9, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea);
   276 	HandlePlacePushButton(w, RTW_DEMOLISH, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea);
   256 }
   277 }
   257 
   278 
   258 static void BuildRailClick_Depot(Window *w)
   279 static void BuildRailClick_Depot(Window *w)
   259 {
   280 {
   260 	if (HandlePlacePushButton(w, 10, GetRailTypeInfo(_cur_railtype)->cursor.depot, 1, PlaceRail_Depot)) {
   281 	if (HandlePlacePushButton(w, RTW_BUILD_DEPOT, GetRailTypeInfo(_cur_railtype)->cursor.depot, 1, PlaceRail_Depot)) {
   261 		ShowBuildTrainDepotPicker();
   282 		ShowBuildTrainDepotPicker();
   262 	}
   283 	}
   263 }
   284 }
   264 
   285 
   265 static void BuildRailClick_Waypoint(Window *w)
   286 static void BuildRailClick_Waypoint(Window *w)
   266 {
   287 {
   267 	_waypoint_count = GetNumCustomStations(STAT_CLASS_WAYP);
   288 	_waypoint_count = GetNumCustomStations(STAT_CLASS_WAYP);
   268 	if (HandlePlacePushButton(w, 11, SPR_CURSOR_WAYPOINT, 1, PlaceRail_Waypoint) &&
   289 	if (HandlePlacePushButton(w, RTW_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, 1, PlaceRail_Waypoint) &&
   269 			_waypoint_count > 1) {
   290 			_waypoint_count > 1) {
   270 		ShowBuildWaypointPicker();
   291 		ShowBuildWaypointPicker();
   271 	}
   292 	}
   272 }
   293 }
   273 
   294 
   274 static void BuildRailClick_Station(Window *w)
   295 static void BuildRailClick_Station(Window *w)
   275 {
   296 {
   276 	if (HandlePlacePushButton(w, 12, SPR_CURSOR_RAIL_STATION, 1, PlaceRail_Station)) ShowStationBuilder();
   297 	if (HandlePlacePushButton(w, RTW_BUILD_STATION, SPR_CURSOR_RAIL_STATION, 1, PlaceRail_Station)) ShowStationBuilder();
   277 }
   298 }
   278 
   299 
   279 static void BuildRailClick_AutoSignals(Window *w)
   300 static void BuildRailClick_AutoSignals(Window *w)
   280 {
   301 {
   281 	HandlePlacePushButton(w, 13, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals);
   302 	HandlePlacePushButton(w, RTW_BUILD_SIGNALS, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals);
   282 }
   303 }
   283 
   304 
   284 static void BuildRailClick_Bridge(Window *w)
   305 static void BuildRailClick_Bridge(Window *w)
   285 {
   306 {
   286 	HandlePlacePushButton(w, 14, SPR_CURSOR_BRIDGE, 1, PlaceRail_Bridge);
   307 	HandlePlacePushButton(w, RTW_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, 1, PlaceRail_Bridge);
   287 }
   308 }
   288 
   309 
   289 static void BuildRailClick_Tunnel(Window *w)
   310 static void BuildRailClick_Tunnel(Window *w)
   290 {
   311 {
   291 	HandlePlacePushButton(w, 15, GetRailTypeInfo(_cur_railtype)->cursor.tunnel, 3, PlaceRail_Tunnel);
   312 	HandlePlacePushButton(w, RTW_BUILD_TUNNEL, GetRailTypeInfo(_cur_railtype)->cursor.tunnel, 3, PlaceRail_Tunnel);
   292 }
   313 }
   293 
   314 
   294 static void BuildRailClick_Remove(Window *w)
   315 static void BuildRailClick_Remove(Window *w)
   295 {
   316 {
   296 	if (IsWindowWidgetDisabled(w, 16)) return;
   317 	if (IsWindowWidgetDisabled(w, RTW_REMOVE)) return;
   297 	SetWindowDirty(w);
   318 	SetWindowDirty(w);
   298 	SndPlayFx(SND_15_BEEP);
   319 	SndPlayFx(SND_15_BEEP);
   299 
   320 
   300 	ToggleWidgetLoweredState(w, 16);
   321 	ToggleWidgetLoweredState(w, RTW_REMOVE);
   301 	_remove_button_clicked = IsWindowWidgetLowered(w, 16);
   322 	_remove_button_clicked = IsWindowWidgetLowered(w, RTW_REMOVE);
   302 	SetSelectionRed(_remove_button_clicked);
   323 	SetSelectionRed(_remove_button_clicked);
   303 
   324 
   304 	// handle station builder
   325 	// handle station builder
   305 	if (_remove_button_clicked) {
   326 	if (_remove_button_clicked) {
   306 		SetTileSelectSize(1, 1);
   327 		SetTileSelectSize(1, 1);
   307 	}
   328 	}
   308 }
   329 }
   309 
   330 
   310 static void BuildRailClick_Convert(Window *w)
   331 static void BuildRailClick_Convert(Window *w)
   311 {
   332 {
   312 	HandlePlacePushButton(w, 17, GetRailTypeInfo(_cur_railtype)->cursor.convert, 1, PlaceRail_ConvertRail);
   333 	HandlePlacePushButton(w, RTW_CONVERT_RAIL, GetRailTypeInfo(_cur_railtype)->cursor.convert, 1, PlaceRail_ConvertRail);
   313 }
   334 }
   314 
   335 
   315 static void BuildRailClick_Landscaping(Window *w)
   336 static void BuildRailClick_Landscaping(Window *w)
   316 {
   337 {
   317 	ShowTerraformToolbar();
   338 	ShowTerraformToolbar();
   404 
   425 
   405 static void UpdateRemoveWidgetStatus(Window *w, int clicked_widget)
   426 static void UpdateRemoveWidgetStatus(Window *w, int clicked_widget)
   406 {
   427 {
   407 	/* If it is the removal button that has been clicked, do nothing,
   428 	/* If it is the removal button that has been clicked, do nothing,
   408 	 * as it is up to the other buttons to drive removal status */
   429 	 * as it is up to the other buttons to drive removal status */
   409 	if (clicked_widget == 16) return;
   430 	if (clicked_widget == RTW_REMOVE) return;
   410 
   431 
   411 	switch (clicked_widget) {
   432 	switch (clicked_widget) {
   412 		case 4: case 5: case 6: case 7: case 8: case 11: case 12: case 13:
   433 		case RTW_BUILD_NS:
       
   434 		case RTW_BUILD_X:
       
   435 		case RTW_BUILD_EW:
       
   436 		case RTW_BUILD_Y:
       
   437 		case RTW_AUTORAIL:
       
   438 		case RTW_BUILD_WAYPOINT:
       
   439 		case RTW_BUILD_STATION:
       
   440 		case RTW_BUILD_SIGNALS:
   413 			/* Removal button is enabled only if the rail/signal/waypoint/station
   441 			/* Removal button is enabled only if the rail/signal/waypoint/station
   414 			 * button is still lowered.  Once raised, it has to be disabled */
   442 			 * button is still lowered.  Once raised, it has to be disabled */
   415 			SetWindowWidgetDisabledState(w, 16, !IsWindowWidgetLowered(w, clicked_widget));
   443 			SetWindowWidgetDisabledState(w, RTW_REMOVE, !IsWindowWidgetLowered(w, clicked_widget));
   416 			break;
   444 			break;
   417 
   445 
   418 		default:
   446 		default:
   419 			/* When any other buttons than rail/signal/waypoint/station, raise and
   447 			/* When any other buttons than rail/signal/waypoint/station, raise and
   420 			 * disable the removal button*/
   448 			 * disable the removal button*/
   421 			DisableWindowWidget(w, 16);
   449 			DisableWindowWidget(w, RTW_REMOVE);
   422 			RaiseWindowWidget(w, 16);
   450 			RaiseWindowWidget(w, RTW_REMOVE);
   423 			break;
   451 			break;
   424 	}
   452 	}
   425 }
   453 }
   426 
   454 
   427 static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
   455 static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
   428 {
   456 {
   429 	switch (e->event) {
   457 	switch (e->event) {
   430 	case WE_CREATE: DisableWindowWidget(w, 16); break;
   458 	case WE_CREATE: DisableWindowWidget(w, RTW_REMOVE); break;
   431 
   459 
   432 	case WE_PAINT: DrawWindowWidgets(w); break;
   460 	case WE_PAINT: DrawWindowWidgets(w); break;
   433 
   461 
   434 	case WE_CLICK:
   462 	case WE_CLICK:
   435 		if (e->we.click.widget >= 4) {
   463 		if (e->we.click.widget >= 4) {
   492 		}
   520 		}
   493 		break;
   521 		break;
   494 
   522 
   495 	case WE_ABORT_PLACE_OBJ:
   523 	case WE_ABORT_PLACE_OBJ:
   496 		RaiseWindowButtons(w);
   524 		RaiseWindowButtons(w);
   497 		DisableWindowWidget(w, 16);
   525 		DisableWindowWidget(w, RTW_REMOVE);
   498 		InvalidateWidget(w, 16);
   526 		InvalidateWidget(w, RTW_REMOVE);
   499 
   527 
   500 		w = FindWindowById(WC_BUILD_STATION, 0);
   528 		w = FindWindowById(WC_BUILD_STATION, 0);
   501 		if (w != NULL) WP(w,def_d).close = true;
   529 		if (w != NULL) WP(w,def_d).close = true;
   502 		w = FindWindowById(WC_BUILD_DEPOT, 0);
   530 		w = FindWindowById(WC_BUILD_DEPOT, 0);
   503 		if (w != NULL) WP(w,def_d).close = true;
   531 		if (w != NULL) WP(w,def_d).close = true;
   552 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
   580 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
   553 	_build_rail_widgets,
   581 	_build_rail_widgets,
   554 	BuildRailToolbWndProc
   582 	BuildRailToolbWndProc
   555 };
   583 };
   556 
   584 
   557 /** Enum referring to the widgets of the build rail toolbar
       
   558  */
       
   559 typedef enum {
       
   560 	RTW_CAPTION = 1,
       
   561 	RTW_BUILD_NS = 4,
       
   562 	RTW_BUILD_X = 5,
       
   563 	RTW_BUILD_EW = 6,
       
   564 	RTW_BUILD_Y = 7,
       
   565 	RTW_AUTORAIL = 8,
       
   566 	RTW_BUILD_DEPOT = 10,
       
   567 	RTW_BUILD_TUNNEL = 15,
       
   568 	RTW_CONVERT_RAIL = 17
       
   569 } RailToolbarWidgets;
       
   570 
   585 
   571 /** Configures the rail toolbar for railtype given
   586 /** Configures the rail toolbar for railtype given
   572  * @param railtype the railtype to display
   587  * @param railtype the railtype to display
   573  * @param w the window to modify
   588  * @param w the window to modify
   574  */
   589  */