Index: src/rail_gui.cpp =================================================================== --- src/rail_gui.cpp (Revision 11245) +++ src/rail_gui.cpp (Arbeitskopie) @@ -453,7 +453,7 @@ default: /* When any other buttons than rail/signal/waypoint/station, raise and - * disable the removal button*/ + * disable the removal button */ DisableWindowWidget(w, RTW_REMOVE); RaiseWindowWidget(w, RTW_REMOVE); break; @@ -468,28 +468,25 @@ case WE_PAINT: DrawWindowWidgets(w); break; case WE_CLICK: - if (e->we.click.widget >= 4) { + if (e->we.click.widget >= RTW_BUILD_NS) { _remove_button_clicked = false; - _build_railroad_button_proc[e->we.click.widget - 4](w); + _build_railroad_button_proc[e->we.click.widget - RTW_BUILD_NS](w); } UpdateRemoveWidgetStatus(w, e->we.click.widget); break; - case WE_KEYPRESS: { - uint i; - - for (i = 0; i != lengthof(_rail_keycodes); i++) { + case WE_KEYPRESS: + for (uint8 i = 0; i != lengthof(_rail_keycodes); i++) { if (e->we.keypress.keycode == _rail_keycodes[i]) { e->we.keypress.cont = false; _remove_button_clicked = false; _build_railroad_button_proc[i](w); - UpdateRemoveWidgetStatus(w, i + 4); + UpdateRemoveWidgetStatus(w, i + RTW_BUILD_NS); break; } } MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection break; - } case WE_PLACE_OBJ: _place_proc(e->we.place.tile); Index: src/road_gui.cpp =================================================================== --- src/road_gui.cpp (Revision 11245) +++ src/road_gui.cpp (Arbeitskopie) @@ -182,15 +182,15 @@ 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 + RTW_ROAD_X = 3, + RTW_ROAD_Y, + RTW_DEMOLISH, + RTW_DEPOT, + RTW_BUS_STATION, + RTW_TRUCK_STATION, + RTW_BUILD_BRIDGE, + RTW_BUILD_TUNNEL, + RTW_REMOVE, }; @@ -249,7 +249,6 @@ SetSelectionRed(IsWindowWidgetLowered(w, RTW_REMOVE)); } - static OnButtonClick* const _build_road_button_proc[] = { BuildRoadClick_NE, BuildRoadClick_NW, @@ -262,38 +261,76 @@ BuildRoadClick_Remove }; +static const uint16 _road_keycodes[] = { + '1', + '2', + '3', + '4', + '5', + '6', + 'B', + 'T', + 'R', +}; + +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 == RTW_REMOVE) return; + + switch (clicked_widget) { + case RTW_ROAD_X: + case RTW_ROAD_Y: + case RTW_BUS_STATION: + case RTW_TRUCK_STATION: + /* Removal button is enabled only if the road/station + * button is still lowered. Once raised, it has to be disabled */ + SetWindowWidgetDisabledState(w, RTW_REMOVE, !IsWindowWidgetLowered(w, clicked_widget)); + break; + + default: + /* When any other buttons than road/station, raise and + * disable the removal button */ + DisableWindowWidget(w, RTW_REMOVE); + RaiseWindowWidget(w, RTW_REMOVE); + break; + } +} + static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) { switch (e->event) { case WE_CREATE: DisableWindowWidget(w, RTW_REMOVE); break; case WE_PAINT: - if (IsWindowWidgetLowered(w, RTW_ROAD_X) || IsWindowWidgetLowered(w, RTW_ROAD_Y) || IsWindowWidgetLowered(w, RTW_BUS_STATION) || IsWindowWidgetLowered(w, RTW_TRUCK_STATION)) { - EnableWindowWidget(w, RTW_REMOVE); - } - SetWindowWidgetsDisabledState(w, !CanBuildVehicleInfrastructure(VEH_ROAD), 6, 7, 8, WIDGET_LIST_END); + SetWindowWidgetsDisabledState(w, !CanBuildVehicleInfrastructure(VEH_ROAD), + RTW_DEPOT, + RTW_BUS_STATION, + RTW_TRUCK_STATION, + WIDGET_LIST_END); DrawWindowWidgets(w); break; - case WE_CLICK: { - if (e->we.click.widget >= 3) _build_road_button_proc[e->we.click.widget - 3](w); - } break; + case WE_CLICK: + if (e->we.click.widget >= RTW_ROAD_X) { + _remove_button_clicked = false; + _build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w); + } + UpdateRemoveWidgetStatus(w, e->we.click.widget); + break; case WE_KEYPRESS: - switch (e->we.keypress.keycode) { - case '1': BuildRoadClick_NE(w); break; - case '2': BuildRoadClick_NW(w); break; - case '3': BuildRoadClick_Demolish(w); break; - case '4': BuildRoadClick_Depot(w); break; - case '5': BuildRoadClick_BusStation(w); break; - case '6': BuildRoadClick_TruckStation(w); break; - case 'B': BuildRoadClick_Bridge(w); break; - case 'T': BuildRoadClick_Tunnel(w); break; - case 'R': BuildRoadClick_Remove(w); break; - default: return; + for (uint8 i = 0; i != lengthof(_road_keycodes); i++) { + if (e->we.keypress.keycode == _road_keycodes[i]) { + e->we.keypress.cont = false; + _remove_button_clicked = false; + _build_road_button_proc[i](w); + UpdateRemoveWidgetStatus(w, i + RTW_ROAD_X); + break; + } } MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection - e->we.keypress.cont = false; break; case WE_PLACE_OBJ: