diff --git a/src/citymania/cm_hotkeys.cpp b/src/citymania/cm_hotkeys.cpp index fc2909e6a2..5b3d5e87df 100644 --- a/src/citymania/cm_hotkeys.cpp +++ b/src/citymania/cm_hotkeys.cpp @@ -12,6 +12,7 @@ #include "../window_gui.h" #include "../window_type.h" #include "../widgets/rail_widget.h" +#include "../widgets/road_widget.h" #include "../safeguards.h" @@ -124,7 +125,7 @@ bool RailToolbar_RemoveModChanged(Window *w, bool invert_remove, bool remove_act if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return false; DeleteWindowById(WC_SELECT_STATION, 0); - for (uint i = WID_RAT_BUILD_NS; i <= WID_RAT_BUILD_TUNNEL; i++) { + for (uint i = WID_RAT_BUILD_NS; i < WID_RAT_REMOVE; i++) { if (w->IsWidgetLowered(i)) { auto old_active = remove_active; switch (RailToolbar_GetRemoveMode(i)) { @@ -145,4 +146,85 @@ bool RailToolbar_RemoveModChanged(Window *w, bool invert_remove, bool remove_act return remove_active; } +ToolRemoveMode RoadToolbar_GetRemoveMode(int widget) { + switch(widget) { + case WID_ROT_ROAD_X: + case WID_ROT_ROAD_Y: + case WID_ROT_AUTOROAD: + return ToolRemoveMode::MOD; + + case WID_ROT_BUS_STATION: + case WID_ROT_TRUCK_STATION: + return HasSeparateRemoveMod() ? ToolRemoveMode::MOD : ToolRemoveMode::BUTTON; + + default: + return ToolRemoveMode::NONE; + } +} + +void RoadToolbar_UpdateOptionWidgetStatus(Window *w, int widget, bool remove_active, bool is_road) { + + switch (widget) { + case WID_ROT_REMOVE: + case WID_ROT_ONE_WAY: + return; + + case WID_ROT_BUS_STATION: + case WID_ROT_TRUCK_STATION: + if (is_road) w->DisableWidget(WID_ROT_ONE_WAY); + break; + + case WID_ROT_ROAD_X: + case WID_ROT_ROAD_Y: + case WID_ROT_AUTOROAD: + if (is_road) w->SetWidgetDisabledState(WID_ROT_ONE_WAY, !w->IsWidgetLowered(widget)); + break; + + default: + if (is_road) { + w->SetWidgetDisabledState(WID_ROT_ONE_WAY, true); + w->SetWidgetLoweredState(WID_ROT_ONE_WAY, false); + } + + break; + } + + + if (RoadToolbar_GetRemoveMode(widget) == citymania::ToolRemoveMode::NONE || !w->IsWidgetLowered(widget)) { + w->DisableWidget(WID_ROT_REMOVE); + w->RaiseWidget(WID_ROT_REMOVE); + } else { + w->EnableWidget(WID_ROT_REMOVE); + w->SetWidgetLoweredState(WID_ROT_REMOVE, remove_active); + SetSelectionRed(remove_active); + } + w->SetWidgetDirty(WID_ROT_REMOVE); +} + +bool RoadToolbar_RemoveModChanged(Window *w, bool remove_active, bool button_clicked, bool is_road) { + if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false; + + DeleteWindowById(WC_SELECT_STATION, 0); + for (uint i = WID_ROT_ROAD_X; i < WID_ROT_REMOVE; i++) { + if (w->IsWidgetLowered(i)) { + auto old_active = remove_active; + switch (RoadToolbar_GetRemoveMode(i)) { + case ToolRemoveMode::BUTTON: + if (button_clicked) remove_active = !w->IsWidgetLowered(WID_ROT_REMOVE); + break; + case ToolRemoveMode::MOD: + if (_remove_mod || !button_clicked) remove_active = _remove_mod; + else remove_active = !w->IsWidgetLowered(WID_ROT_REMOVE); + break; + default: + break; + } + if (old_active != remove_active) RoadToolbar_UpdateOptionWidgetStatus(w, i, remove_active, is_road); + return remove_active; + } + } + return remove_active; +} + + } // namespace citymania diff --git a/src/citymania/cm_hotkeys.hpp b/src/citymania/cm_hotkeys.hpp index e15f9996f2..ab681d0fbb 100644 --- a/src/citymania/cm_hotkeys.hpp +++ b/src/citymania/cm_hotkeys.hpp @@ -21,6 +21,10 @@ bool RailToolbar_IsRemoveInverted(int widget); void RailToolbar_UpdateRemoveWidgetStatus(Window *w, int widged, bool remove_active); bool RailToolbar_RemoveModChanged(Window *w, bool invert_remove, bool remove_active, bool button_clicked); +ToolRemoveMode RoadToolbar_GetRemoveMode(int widget); +void RoadToolbar_UpdateOptionWidgetStatus(Window *w, int widget, bool remove_active, bool is_road); +bool RoadToolbar_RemoveModChanged(Window *w, bool remove_active, bool button_clicked, bool is_road); + } // namespace citymania #endif diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 805dfcd0c0..1218445a13 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -539,7 +539,7 @@ struct BuildRoadToolbarWindow : Window { void OnClick(Point pt, int widget, int click_count) override { - _remove_button_clicked = false; + if (widget != WID_ROT_REMOVE) _remove_button_clicked = false; _one_way_button_clicked = false; switch (widget) { case WID_ROT_ROAD_X: @@ -590,7 +590,7 @@ struct BuildRoadToolbarWindow : Window { if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return; this->SetDirty(); this->ToggleWidgetLoweredState(WID_ROT_ONE_WAY); - SetSelectionRed(false); + // CM SetSelectionRed(false); break; case WID_ROT_BUILD_BRIDGE: @@ -604,11 +604,12 @@ struct BuildRoadToolbarWindow : Window { break; case WID_ROT_REMOVE: - if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return; + _remove_button_clicked = citymania::RoadToolbar_RemoveModChanged(this, _remove_button_clicked, true, RoadTypeIsRoad(this->roadtype)); + // if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return; - DeleteWindowById(WC_SELECT_STATION, 0); - ToggleRoadButton_Remove(this); - if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); + // DeleteWindowById(WC_SELECT_STATION, 0); + // ToggleRoadButton_Remove(this); + // if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); break; case WID_ROT_CONVERT_ROAD: @@ -618,8 +619,9 @@ struct BuildRoadToolbarWindow : Window { default: NOT_REACHED(); } - this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget); - if (citymania::_remove_mod) RoadToolbar_CtrlChanged(this); + citymania::RoadToolbar_UpdateOptionWidgetStatus(this, widget, _remove_button_clicked, RoadTypeIsRoad(this->roadtype)); + // this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget); + // if (citymania::_remove_mod) RoadToolbar_CtrlChanged(this); } EventState OnHotkey(int hotkey) override @@ -631,7 +633,7 @@ struct BuildRoadToolbarWindow : Window { void OnPlaceObject(Point pt, TileIndex tile) override { DiagDirection ddir; - _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE); + // CM _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE); _one_way_button_clicked = RoadTypeIsRoad(this->roadtype) ? this->IsWidgetLowered(WID_ROT_ONE_WAY) : false; switch (this->last_started_action) { case WID_ROT_ROAD_X: @@ -844,7 +846,11 @@ struct BuildRoadToolbarWindow : Window { EventState CM_OnRemoveModStateChange() override { - if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED; + auto new_remove = citymania::RoadToolbar_RemoveModChanged(this, _remove_button_clicked, false, RoadTypeIsRoad(this->roadtype)); + if (new_remove != _remove_button_clicked) { + _remove_button_clicked = new_remove; + return ES_HANDLED; + } return ES_NOT_HANDLED; }