Allow remove modifier key to work with road stations

This commit is contained in:
dP
2020-07-14 01:58:50 +03:00
parent 495192890a
commit 1e99e2475a
3 changed files with 103 additions and 11 deletions

View File

@@ -12,6 +12,7 @@
#include "../window_gui.h" #include "../window_gui.h"
#include "../window_type.h" #include "../window_type.h"
#include "../widgets/rail_widget.h" #include "../widgets/rail_widget.h"
#include "../widgets/road_widget.h"
#include "../safeguards.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; if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return false;
DeleteWindowById(WC_SELECT_STATION, 0); 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)) { if (w->IsWidgetLowered(i)) {
auto old_active = remove_active; auto old_active = remove_active;
switch (RailToolbar_GetRemoveMode(i)) { switch (RailToolbar_GetRemoveMode(i)) {
@@ -145,4 +146,85 @@ bool RailToolbar_RemoveModChanged(Window *w, bool invert_remove, bool remove_act
return remove_active; 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 } // namespace citymania

View File

@@ -21,6 +21,10 @@ bool RailToolbar_IsRemoveInverted(int widget);
void RailToolbar_UpdateRemoveWidgetStatus(Window *w, int widged, bool remove_active); void RailToolbar_UpdateRemoveWidgetStatus(Window *w, int widged, bool remove_active);
bool RailToolbar_RemoveModChanged(Window *w, bool invert_remove, bool remove_active, bool button_clicked); 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 } // namespace citymania
#endif #endif

View File

@@ -539,7 +539,7 @@ struct BuildRoadToolbarWindow : Window {
void OnClick(Point pt, int widget, int click_count) override 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; _one_way_button_clicked = false;
switch (widget) { switch (widget) {
case WID_ROT_ROAD_X: case WID_ROT_ROAD_X:
@@ -590,7 +590,7 @@ struct BuildRoadToolbarWindow : Window {
if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return; if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return;
this->SetDirty(); this->SetDirty();
this->ToggleWidgetLoweredState(WID_ROT_ONE_WAY); this->ToggleWidgetLoweredState(WID_ROT_ONE_WAY);
SetSelectionRed(false); // CM SetSelectionRed(false);
break; break;
case WID_ROT_BUILD_BRIDGE: case WID_ROT_BUILD_BRIDGE:
@@ -604,11 +604,12 @@ struct BuildRoadToolbarWindow : Window {
break; break;
case WID_ROT_REMOVE: 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); // DeleteWindowById(WC_SELECT_STATION, 0);
ToggleRoadButton_Remove(this); // ToggleRoadButton_Remove(this);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); // if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
break; break;
case WID_ROT_CONVERT_ROAD: case WID_ROT_CONVERT_ROAD:
@@ -618,8 +619,9 @@ struct BuildRoadToolbarWindow : Window {
default: NOT_REACHED(); default: NOT_REACHED();
} }
this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget); citymania::RoadToolbar_UpdateOptionWidgetStatus(this, widget, _remove_button_clicked, RoadTypeIsRoad(this->roadtype));
if (citymania::_remove_mod) RoadToolbar_CtrlChanged(this); // this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget);
// if (citymania::_remove_mod) RoadToolbar_CtrlChanged(this);
} }
EventState OnHotkey(int hotkey) override EventState OnHotkey(int hotkey) override
@@ -631,7 +633,7 @@ struct BuildRoadToolbarWindow : Window {
void OnPlaceObject(Point pt, TileIndex tile) override void OnPlaceObject(Point pt, TileIndex tile) override
{ {
DiagDirection ddir; 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; _one_way_button_clicked = RoadTypeIsRoad(this->roadtype) ? this->IsWidgetLowered(WID_ROT_ONE_WAY) : false;
switch (this->last_started_action) { switch (this->last_started_action) {
case WID_ROT_ROAD_X: case WID_ROT_ROAD_X:
@@ -844,7 +846,11 @@ struct BuildRoadToolbarWindow : Window {
EventState CM_OnRemoveModStateChange() override 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; return ES_NOT_HANDLED;
} }