diff options
author | tron <tron@openttd.org> | 2006-11-22 16:08:01 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2006-11-22 16:08:01 +0000 |
commit | a199678abb43ceac4b27fcd37d69c7fffd4aa7d0 (patch) | |
tree | d2df3370917d66d4c0b26706181f24709d05fb07 | |
parent | 6bbb0169f92e1fb4395d4a6d97cec9c483330452 (diff) | |
download | openttd-a199678abb43ceac4b27fcd37d69c7fffd4aa7d0.tar.xz |
(svn r7239) Enumerate the widgets in the airport, dock, rail and road toolbars
-rw-r--r-- | airport_gui.c | 10 | ||||
-rw-r--r-- | dock_gui.c | 23 | ||||
-rw-r--r-- | rail_gui.c | 89 | ||||
-rw-r--r-- | road_gui.c | 48 |
4 files changed, 107 insertions, 63 deletions
diff --git a/airport_gui.c b/airport_gui.c index 33e6ad96e..c049d50d5 100644 --- a/airport_gui.c +++ b/airport_gui.c @@ -41,14 +41,20 @@ static void PlaceAir_DemolishArea(TileIndex tile) } +enum { + ATW_AIRPORT = 3, + ATW_DEMOLISH = 4 +}; + + static void BuildAirClick_Airport(Window *w) { - if (HandlePlacePushButton(w, 3, SPR_CURSOR_AIRPORT, 1, PlaceAirport)) ShowBuildAirportPicker(); + if (HandlePlacePushButton(w, ATW_AIRPORT, SPR_CURSOR_AIRPORT, 1, PlaceAirport)) ShowBuildAirportPicker(); } static void BuildAirClick_Demolish(Window *w) { - HandlePlacePushButton(w, 4, ANIMCURSOR_DEMOLISH, 1, PlaceAir_DemolishArea); + HandlePlacePushButton(w, ATW_DEMOLISH, ANIMCURSOR_DEMOLISH, 1, PlaceAir_DemolishArea); } static void BuildAirClick_Landscaping(Window *w) diff --git a/dock_gui.c b/dock_gui.c index 534af3ddf..8e550e9ec 100644 --- a/dock_gui.c +++ b/dock_gui.c @@ -65,35 +65,44 @@ static void PlaceDocks_BuildLock(TileIndex tile) } +enum { + DTW_CANAL = 3, + DTW_LOCK = 4, + DTW_DEMOLISH = 6, + DTW_DEPOT = 7, + DTW_STATION = 8, + DTW_BUOY = 9 +}; + + static void BuildDocksClick_Canal(Window *w) { - HandlePlacePushButton(w, 3, SPR_CURSOR_CANAL, 1, PlaceDocks_BuildCanal); + HandlePlacePushButton(w, DTW_CANAL, SPR_CURSOR_CANAL, 1, PlaceDocks_BuildCanal); } static void BuildDocksClick_Lock(Window *w) { - HandlePlacePushButton(w, 4, SPR_CURSOR_LOCK, 1, PlaceDocks_BuildLock); + HandlePlacePushButton(w, DTW_LOCK, SPR_CURSOR_LOCK, 1, PlaceDocks_BuildLock); } static void BuildDocksClick_Demolish(Window *w) { - HandlePlacePushButton(w, 6, ANIMCURSOR_DEMOLISH, 1, PlaceDocks_DemolishArea); + HandlePlacePushButton(w, DTW_DEMOLISH, ANIMCURSOR_DEMOLISH, 1, PlaceDocks_DemolishArea); } static void BuildDocksClick_Depot(Window *w) { - if (HandlePlacePushButton(w, 7, SPR_CURSOR_SHIP_DEPOT, 1, PlaceDocks_Depot)) ShowBuildDocksDepotPicker(); + if (HandlePlacePushButton(w, DTW_DEPOT, SPR_CURSOR_SHIP_DEPOT, 1, PlaceDocks_Depot)) ShowBuildDocksDepotPicker(); } static void BuildDocksClick_Dock(Window *w) { - - if (HandlePlacePushButton(w, 8, SPR_CURSOR_DOCK, 3, PlaceDocks_Dock)) ShowBuildDockStationPicker(); + if (HandlePlacePushButton(w, DTW_STATION, SPR_CURSOR_DOCK, 3, PlaceDocks_Dock)) ShowBuildDockStationPicker(); } static void BuildDocksClick_Buoy(Window *w) { - HandlePlacePushButton(w, 9, SPR_CURSOR_BOUY, 1, PlaceDocks_Buoy); + HandlePlacePushButton(w, DTW_BUOY, SPR_CURSOR_BOUY, 1, PlaceDocks_Buoy); } static void BuildDocksClick_Landscaping(Window *w) diff --git a/rail_gui.c b/rail_gui.c index 30bf0a034..b3e38e502 100644 --- a/rail_gui.c +++ b/rail_gui.c @@ -225,39 +225,60 @@ static void PlaceRail_AutoSignals(TileIndex tile) VpStartPlaceSizing(tile, VPM_SIGNALDIRS); } + +/** Enum referring to the widgets of the build rail toolbar */ +enum { + RTW_CAPTION = 1, + RTW_BUILD_NS = 4, + RTW_BUILD_X = 5, + RTW_BUILD_EW = 6, + RTW_BUILD_Y = 7, + RTW_AUTORAIL = 8, + RTW_DEMOLISH = 9, + RTW_BUILD_DEPOT = 10, + RTW_BUILD_WAYPOINT = 11, + RTW_BUILD_STATION = 12, + RTW_BUILD_SIGNALS = 13, + RTW_BUILD_BRIDGE = 14, + RTW_BUILD_TUNNEL = 15, + RTW_REMOVE = 16, + RTW_CONVERT_RAIL = 17 +}; + + static void BuildRailClick_N(Window *w) { - HandlePlacePushButton(w, 4, GetRailTypeInfo(_cur_railtype)->cursor.rail_ns, 1, PlaceRail_N); + HandlePlacePushButton(w, RTW_BUILD_NS, GetRailTypeInfo(_cur_railtype)->cursor.rail_ns, 1, PlaceRail_N); } static void BuildRailClick_NE(Window *w) { - HandlePlacePushButton(w, 5, GetRailTypeInfo(_cur_railtype)->cursor.rail_swne, 1, PlaceRail_NE); + HandlePlacePushButton(w, RTW_BUILD_X, GetRailTypeInfo(_cur_railtype)->cursor.rail_swne, 1, PlaceRail_NE); } static void BuildRailClick_E(Window *w) { - HandlePlacePushButton(w, 6, GetRailTypeInfo(_cur_railtype)->cursor.rail_ew, 1, PlaceRail_E); + HandlePlacePushButton(w, RTW_BUILD_EW, GetRailTypeInfo(_cur_railtype)->cursor.rail_ew, 1, PlaceRail_E); } static void BuildRailClick_NW(Window *w) { - HandlePlacePushButton(w, 7, GetRailTypeInfo(_cur_railtype)->cursor.rail_nwse, 1, PlaceRail_NW); + HandlePlacePushButton(w, RTW_BUILD_Y, GetRailTypeInfo(_cur_railtype)->cursor.rail_nwse, 1, PlaceRail_NW); } static void BuildRailClick_AutoRail(Window *w) { - HandlePlacePushButton(w, 8, GetRailTypeInfo(_cur_railtype)->cursor.autorail, VHM_RAIL, PlaceRail_AutoRail); + HandlePlacePushButton(w, RTW_AUTORAIL, GetRailTypeInfo(_cur_railtype)->cursor.autorail, VHM_RAIL, PlaceRail_AutoRail); } static void BuildRailClick_Demolish(Window *w) { - HandlePlacePushButton(w, 9, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea); + HandlePlacePushButton(w, RTW_DEMOLISH, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea); } static void BuildRailClick_Depot(Window *w) { - if (HandlePlacePushButton(w, 10, GetRailTypeInfo(_cur_railtype)->cursor.depot, 1, PlaceRail_Depot)) { + if (HandlePlacePushButton(w, RTW_BUILD_DEPOT, GetRailTypeInfo(_cur_railtype)->cursor.depot, 1, PlaceRail_Depot)) { ShowBuildTrainDepotPicker(); } } @@ -265,7 +286,7 @@ static void BuildRailClick_Depot(Window *w) static void BuildRailClick_Waypoint(Window *w) { _waypoint_count = GetNumCustomStations(STAT_CLASS_WAYP); - if (HandlePlacePushButton(w, 11, SPR_CURSOR_WAYPOINT, 1, PlaceRail_Waypoint) && + if (HandlePlacePushButton(w, RTW_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, 1, PlaceRail_Waypoint) && _waypoint_count > 1) { ShowBuildWaypointPicker(); } @@ -273,32 +294,32 @@ static void BuildRailClick_Waypoint(Window *w) static void BuildRailClick_Station(Window *w) { - if (HandlePlacePushButton(w, 12, SPR_CURSOR_RAIL_STATION, 1, PlaceRail_Station)) ShowStationBuilder(); + if (HandlePlacePushButton(w, RTW_BUILD_STATION, SPR_CURSOR_RAIL_STATION, 1, PlaceRail_Station)) ShowStationBuilder(); } static void BuildRailClick_AutoSignals(Window *w) { - HandlePlacePushButton(w, 13, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals); + HandlePlacePushButton(w, RTW_BUILD_SIGNALS, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals); } static void BuildRailClick_Bridge(Window *w) { - HandlePlacePushButton(w, 14, SPR_CURSOR_BRIDGE, 1, PlaceRail_Bridge); + HandlePlacePushButton(w, RTW_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, 1, PlaceRail_Bridge); } static void BuildRailClick_Tunnel(Window *w) { - HandlePlacePushButton(w, 15, GetRailTypeInfo(_cur_railtype)->cursor.tunnel, 3, PlaceRail_Tunnel); + HandlePlacePushButton(w, RTW_BUILD_TUNNEL, GetRailTypeInfo(_cur_railtype)->cursor.tunnel, 3, PlaceRail_Tunnel); } static void BuildRailClick_Remove(Window *w) { - if (IsWindowWidgetDisabled(w, 16)) return; + if (IsWindowWidgetDisabled(w, RTW_REMOVE)) return; SetWindowDirty(w); SndPlayFx(SND_15_BEEP); - ToggleWidgetLoweredState(w, 16); - _remove_button_clicked = IsWindowWidgetLowered(w, 16); + ToggleWidgetLoweredState(w, RTW_REMOVE); + _remove_button_clicked = IsWindowWidgetLowered(w, RTW_REMOVE); SetSelectionRed(_remove_button_clicked); // handle station builder @@ -309,7 +330,7 @@ static void BuildRailClick_Remove(Window *w) static void BuildRailClick_Convert(Window *w) { - HandlePlacePushButton(w, 17, GetRailTypeInfo(_cur_railtype)->cursor.convert, 1, PlaceRail_ConvertRail); + HandlePlacePushButton(w, RTW_CONVERT_RAIL, GetRailTypeInfo(_cur_railtype)->cursor.convert, 1, PlaceRail_ConvertRail); } static void BuildRailClick_Landscaping(Window *w) @@ -406,20 +427,27 @@ static void UpdateRemoveWidgetStatus(Window *w, int clicked_widget) { /* If it is the removal button that has been clicked, do nothing, * as it is up to the other buttons to drive removal status */ - if (clicked_widget == 16) return; + if (clicked_widget == RTW_REMOVE) return; switch (clicked_widget) { - case 4: case 5: case 6: case 7: case 8: case 11: case 12: case 13: + case RTW_BUILD_NS: + case RTW_BUILD_X: + case RTW_BUILD_EW: + case RTW_BUILD_Y: + case RTW_AUTORAIL: + case RTW_BUILD_WAYPOINT: + case RTW_BUILD_STATION: + case RTW_BUILD_SIGNALS: /* Removal button is enabled only if the rail/signal/waypoint/station * button is still lowered. Once raised, it has to be disabled */ - SetWindowWidgetDisabledState(w, 16, !IsWindowWidgetLowered(w, clicked_widget)); + SetWindowWidgetDisabledState(w, RTW_REMOVE, !IsWindowWidgetLowered(w, clicked_widget)); break; default: /* When any other buttons than rail/signal/waypoint/station, raise and * disable the removal button*/ - DisableWindowWidget(w, 16); - RaiseWindowWidget(w, 16); + DisableWindowWidget(w, RTW_REMOVE); + RaiseWindowWidget(w, RTW_REMOVE); break; } } @@ -427,7 +455,7 @@ static void UpdateRemoveWidgetStatus(Window *w, int clicked_widget) static void BuildRailToolbWndProc(Window *w, WindowEvent *e) { switch (e->event) { - case WE_CREATE: DisableWindowWidget(w, 16); break; + case WE_CREATE: DisableWindowWidget(w, RTW_REMOVE); break; case WE_PAINT: DrawWindowWidgets(w); break; @@ -494,8 +522,8 @@ static void BuildRailToolbWndProc(Window *w, WindowEvent *e) case WE_ABORT_PLACE_OBJ: RaiseWindowButtons(w); - DisableWindowWidget(w, 16); - InvalidateWidget(w, 16); + DisableWindowWidget(w, RTW_REMOVE); + InvalidateWidget(w, RTW_REMOVE); w = FindWindowById(WC_BUILD_STATION, 0); if (w != NULL) WP(w,def_d).close = true; @@ -554,19 +582,6 @@ static const WindowDesc _build_rail_desc = { BuildRailToolbWndProc }; -/** Enum referring to the widgets of the build rail toolbar - */ -typedef enum { - RTW_CAPTION = 1, - RTW_BUILD_NS = 4, - RTW_BUILD_X = 5, - RTW_BUILD_EW = 6, - RTW_BUILD_Y = 7, - RTW_AUTORAIL = 8, - RTW_BUILD_DEPOT = 10, - RTW_BUILD_TUNNEL = 15, - RTW_CONVERT_RAIL = 17 -} RailToolbarWidgets; /** Configures the rail toolbar for railtype given * @param railtype the railtype to display diff --git a/road_gui.c b/road_gui.c index 7bb31ca48..985e09853 100644 --- a/road_gui.c +++ b/road_gui.c @@ -107,59 +107,73 @@ static void PlaceRoad_DemolishArea(TileIndex tile) VpStartPlaceSizing(tile, 4); } + +enum { + RTW_ROAD_X = 3, + RTW_ROAD_Y = 4, + RTW_DEMOLISH = 5, + RTW_DEPOT = 6, + RTW_BUS_STATION = 7, + RTW_TRUCK_STATION = 8, + RTW_BUILD_BRIDGE = 9, + RTW_BUILD_TUNNEL = 10, + RTW_REMOVE = 11 +}; + + typedef void OnButtonClick(Window *w); static void BuildRoadClick_NE(Window *w) { - HandlePlacePushButton(w, 3, SPR_CURSOR_ROAD_NESW, 1, PlaceRoad_NE); + HandlePlacePushButton(w, RTW_ROAD_X, SPR_CURSOR_ROAD_NESW, 1, PlaceRoad_NE); } static void BuildRoadClick_NW(Window *w) { - HandlePlacePushButton(w, 4, SPR_CURSOR_ROAD_NWSE, 1, PlaceRoad_NW); + HandlePlacePushButton(w, RTW_ROAD_Y, SPR_CURSOR_ROAD_NWSE, 1, PlaceRoad_NW); } static void BuildRoadClick_Demolish(Window *w) { - HandlePlacePushButton(w, 5, ANIMCURSOR_DEMOLISH, 1, PlaceRoad_DemolishArea); + HandlePlacePushButton(w, RTW_DEMOLISH, ANIMCURSOR_DEMOLISH, 1, PlaceRoad_DemolishArea); } static void BuildRoadClick_Depot(Window *w) { if (_game_mode == GM_EDITOR) return; - if (HandlePlacePushButton(w, 6, SPR_CURSOR_ROAD_DEPOT, 1, PlaceRoad_Depot)) ShowRoadDepotPicker(); + if (HandlePlacePushButton(w, RTW_DEPOT, SPR_CURSOR_ROAD_DEPOT, 1, PlaceRoad_Depot)) ShowRoadDepotPicker(); } static void BuildRoadClick_BusStation(Window *w) { if (_game_mode == GM_EDITOR) return; - if (HandlePlacePushButton(w, 7, SPR_CURSOR_BUS_STATION, 1, PlaceRoad_BusStation)) ShowBusStationPicker(); + if (HandlePlacePushButton(w, RTW_BUS_STATION, SPR_CURSOR_BUS_STATION, 1, PlaceRoad_BusStation)) ShowBusStationPicker(); } static void BuildRoadClick_TruckStation(Window *w) { if (_game_mode == GM_EDITOR) return; - if (HandlePlacePushButton(w, 8, SPR_CURSOR_TRUCK_STATION, 1, PlaceRoad_TruckStation)) ShowTruckStationPicker(); + if (HandlePlacePushButton(w, RTW_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, 1, PlaceRoad_TruckStation)) ShowTruckStationPicker(); } static void BuildRoadClick_Bridge(Window *w) { - HandlePlacePushButton(w, 9, SPR_CURSOR_BRIDGE, 1, PlaceRoad_Bridge); + HandlePlacePushButton(w, RTW_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, 1, PlaceRoad_Bridge); } static void BuildRoadClick_Tunnel(Window *w) { - HandlePlacePushButton(w, 10, SPR_CURSOR_ROAD_TUNNEL, 3, PlaceRoad_Tunnel); + HandlePlacePushButton(w, RTW_BUILD_TUNNEL, SPR_CURSOR_ROAD_TUNNEL, 3, PlaceRoad_Tunnel); } static void BuildRoadClick_Remove(Window *w) { - if (IsWindowWidgetDisabled(w, 11)) return; + if (IsWindowWidgetDisabled(w, RTW_REMOVE)) return; SetWindowDirty(w); SndPlayFx(SND_15_BEEP); - ToggleWidgetLoweredState(w, 11); - SetSelectionRed(IsWindowWidgetLowered(w, 11)); + ToggleWidgetLoweredState(w, RTW_REMOVE); + SetSelectionRed(IsWindowWidgetLowered(w, RTW_REMOVE)); } static void BuildRoadClick_Landscaping(Window *w) @@ -183,11 +197,11 @@ static OnButtonClick* const _build_road_button_proc[] = { static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) { switch (e->event) { - case WE_CREATE: DisableWindowWidget(w, 11); break; + case WE_CREATE: DisableWindowWidget(w, RTW_REMOVE); break; case WE_PAINT: - if (IsWindowWidgetLowered(w, 3) || IsWindowWidgetLowered(w, 4)) { - EnableWindowWidget(w, 11); + if (IsWindowWidgetLowered(w, RTW_ROAD_X) || IsWindowWidgetLowered(w, RTW_ROAD_Y)) { + EnableWindowWidget(w, RTW_REMOVE); } DrawWindowWidgets(w); break; @@ -215,14 +229,14 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) break; case WE_PLACE_OBJ: - _remove_button_clicked = IsWindowWidgetLowered(w, 11); + _remove_button_clicked = IsWindowWidgetLowered(w, RTW_REMOVE); _place_proc(e->we.place.tile); break; case WE_ABORT_PLACE_OBJ: RaiseWindowButtons(w); - DisableWindowWidget(w, 11); - InvalidateWidget(w, 11); + DisableWindowWidget(w, RTW_REMOVE); + InvalidateWidget(w, RTW_REMOVE); w = FindWindowById(WC_BUS_STATION, 0); if (w != NULL) WP(w,def_d).close = true; |