diff options
author | glx <glx@openttd.org> | 2020-03-23 18:28:55 +0100 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2020-03-30 08:17:40 +0200 |
commit | 0b5e0522b6c3842c9b77d5b67b488b4060bc1f82 (patch) | |
tree | ffab91be9ba9fa1640cff1be76f3d6c7efda838f | |
parent | 2cc9afe057a076cca5e22755053849cfdfbb4798 (diff) | |
download | openttd-0b5e0522b6c3842c9b77d5b67b488b4060bc1f82.tar.xz |
Fix #8043, c02ef3e4: Incorrect handling of global road/tram hotkeys
-rw-r--r-- | src/road_gui.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 8f5c96f98..ea34102ee 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -717,26 +717,38 @@ struct BuildRoadToolbarWindow : Window { * @param last_build Last build road type * @return ES_HANDLED if hotkey was accepted. */ -static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build) +static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build, RoadTramType rtt) { - Window *w = (_game_mode == GM_NORMAL) ? ShowBuildRoadToolbar(last_build) : ShowBuildRoadScenToolbar(last_build); + Window* w = nullptr; + switch (_game_mode) { + case GM_NORMAL: + if (!CanBuildVehicleInfrastructure(VEH_ROAD, rtt)) return ES_NOT_HANDLED; + w = ShowBuildRoadToolbar(last_build); + break; + + case GM_EDITOR: + if ((GetRoadTypes(true) & ((rtt == RTT_ROAD) ? ~_roadtypes_type : _roadtypes_type)) == ROADTYPES_NONE) return ES_NOT_HANDLED; + w = ShowBuildRoadScenToolbar(last_build); + break; + + default: + break; + } + if (w == nullptr) return ES_NOT_HANDLED; return w->OnHotkey(hotkey); } static EventState RoadToolbarGlobalHotkeys(int hotkey) { - if (_game_mode == GM_NORMAL && !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_ROAD)) return ES_NOT_HANDLED; - extern RoadType _last_built_roadtype; - return RoadTramToolbarGlobalHotkeys(hotkey, _last_built_roadtype); + return RoadTramToolbarGlobalHotkeys(hotkey, _last_built_roadtype, RTT_ROAD); } static EventState TramToolbarGlobalHotkeys(int hotkey) { - if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM)) return ES_NOT_HANDLED; extern RoadType _last_built_tramtype; - return RoadTramToolbarGlobalHotkeys(hotkey, _last_built_tramtype); + return RoadTramToolbarGlobalHotkeys(hotkey, _last_built_tramtype, RTT_TRAM); } static Hotkey roadtoolbar_hotkeys[] = { |