summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/airport_gui.cpp107
-rw-r--r--src/dock_gui.cpp113
-rw-r--r--src/rail_gui.cpp187
-rw-r--r--src/road_gui.cpp404
4 files changed, 420 insertions, 391 deletions
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index f887fb25a..b6ed2177f 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -65,51 +65,65 @@ static OnButtonClick * const _build_air_button_proc[] = {
BuildAirClick_Demolish,
};
-static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT:
- w->DrawWidgets();
- break;
-
- case WE_CLICK:
- if (e->we.click.widget - 3 >= 0)
- _build_air_button_proc[e->we.click.widget - 3](w);
- break;
-
- case WE_KEYPRESS: {
- switch (e->we.keypress.keycode) {
- case '1': BuildAirClick_Airport(w); break;
- case '2': BuildAirClick_Demolish(w); break;
- default: return;
- }
- } break;
-
- case WE_PLACE_OBJ:
- _place_proc(e->we.place.tile);
- break;
-
- case WE_PLACE_DRAG:
- VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
- break;
-
- case WE_PLACE_MOUSEUP:
- if (e->we.place.pt.x != -1 && e->we.place.select_proc == DDSP_DEMOLISH_AREA) {
- GUIPlaceProcDragXY(e->we.place.select_proc, e->we.place.starttile, e->we.place.tile);
- }
- break;
-
- case WE_ABORT_PLACE_OBJ:
- w->RaiseButtons();
-
- delete FindWindowById(WC_BUILD_STATION, 0);
- break;
-
- case WE_DESTROY:
- if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
- break;
+struct BuildAirToolbarWindow : Window {
+ BuildAirToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
+ {
+ this->FindWindowPlacementAndResize(desc);
+ if (_patches.link_terraform_toolbar) ShowTerraformToolbar(this);
+ }
+
+ ~BuildAirToolbarWindow()
+ {
+ if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
+ }
+
+ virtual void OnPaint()
+ {
+ this->DrawWidgets();
+ }
+
+ virtual void OnClick(Point pt, int widget)
+ {
+ if (widget - 3 >= 0) {
+ _build_air_button_proc[widget - 3](this);
+ }
+ }
+
+
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
+ {
+ switch (keycode) {
+ case '1': BuildAirClick_Airport(this); break;
+ case '2': BuildAirClick_Demolish(this); break;
+ default: return ES_NOT_HANDLED;
+ }
+ return ES_HANDLED;
+ }
+
+ virtual void OnPlaceObject(Point pt, TileIndex tile)
+ {
+ _place_proc(tile);
}
-}
+
+ virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
+ {
+ VpSelectTilesWithMethod(pt.x, pt.y, select_method);
+ }
+
+ virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
+ {
+ if (pt.x != -1 && select_proc == DDSP_DEMOLISH_AREA) {
+ GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
+ }
+ }
+
+ virtual void OnPlaceObjectAbort()
+ {
+ this->RaiseButtons();
+
+ delete FindWindowById(WC_BUILD_STATION, 0);
+ }
+};
static const Widget _air_toolbar_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
@@ -126,7 +140,7 @@ static const WindowDesc _air_toolbar_desc = {
WC_BUILD_TOOLBAR, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_air_toolbar_widgets,
- BuildAirToolbWndProc
+ NULL
};
void ShowBuildAirToolbar()
@@ -134,8 +148,7 @@ void ShowBuildAirToolbar()
if (!IsValidPlayer(_current_player)) return;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
- Window *w = AllocateWindowDescFront<Window>(&_air_toolbar_desc, TRANSPORT_AIR);
- if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
+ AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
}
class AirportPickerWindow : public PickerWindowBase {
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
index acfa4967a..84cd10092 100644
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -125,77 +125,85 @@ static OnButtonClick * const _build_docks_button_proc[] = {
BuildDocksClick_Buoy
};
-static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT:
- w->DrawWidgets();
- w->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP), 7, 8, 9, WIDGET_LIST_END);
- break;
-
- case WE_CLICK:
- if (e->we.click.widget - 3 >= 0 && e->we.click.widget != 5) _build_docks_button_proc[e->we.click.widget - 3](w);
- break;
-
- case WE_KEYPRESS:
- switch (e->we.keypress.keycode) {
- case '1': BuildDocksClick_Canal(w); break;
- case '2': BuildDocksClick_Lock(w); break;
- case '3': BuildDocksClick_Demolish(w); break;
- case '4': BuildDocksClick_Depot(w); break;
- case '5': BuildDocksClick_Dock(w); break;
- case '6': BuildDocksClick_Buoy(w); break;
- default: return;
+struct BuildDocksToolbarWindow : Window {
+ BuildDocksToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
+ {
+ this->FindWindowPlacementAndResize(desc);
+ if (_patches.link_terraform_toolbar) ShowTerraformToolbar(this);
+ }
+
+ ~BuildDocksToolbarWindow()
+ {
+ if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
+ }
+
+ virtual void OnPaint()
+ {
+ this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP), 7, 8, 9, WIDGET_LIST_END);
+ this->DrawWidgets();
+ }
+
+ virtual void OnClick(Point pt, int widget)
+ {
+ if (widget - 3 >= 0 && widget != 5) _build_docks_button_proc[widget - 3](this);
+ }
+
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
+ {
+ switch (keycode) {
+ case '1': BuildDocksClick_Canal(this); break;
+ case '2': BuildDocksClick_Lock(this); break;
+ case '3': BuildDocksClick_Demolish(this); break;
+ case '4': BuildDocksClick_Depot(this); break;
+ case '5': BuildDocksClick_Dock(this); break;
+ case '6': BuildDocksClick_Buoy(this); break;
+ default: return ES_NOT_HANDLED;
}
- break;
+ return ES_HANDLED;
+ }
- case WE_PLACE_OBJ:
- _place_proc(e->we.place.tile);
- break;
+ virtual void OnPlaceObject(Point pt, TileIndex tile)
+ {
+ _place_proc(tile);
+ }
- case WE_PLACE_DRAG: {
- VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
- return;
+ virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
+ {
+ VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
- case WE_PLACE_MOUSEUP:
- if (e->we.place.pt.x != -1) {
- switch (e->we.place.select_proc) {
+ virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
+ {
+ if (pt.x != -1) {
+ switch (select_proc) {
case DDSP_DEMOLISH_AREA:
- GUIPlaceProcDragXY(e->we.place.select_proc, e->we.place.starttile, e->we.place.tile);
+ GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
break;
case DDSP_CREATE_WATER:
- DoCommandP(e->we.place.tile, e->we.place.starttile, 0, CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS));
+ DoCommandP(end_tile, start_tile, 0, CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS));
break;
+
default: break;
}
}
- break;
+ }
- case WE_ABORT_PLACE_OBJ:
- w->RaiseButtons();
+ virtual void OnPlaceObjectAbort()
+ {
+ this->RaiseButtons();
delete FindWindowById(WC_BUILD_STATION, 0);
delete FindWindowById(WC_BUILD_DEPOT, 0);
- break;
-
- case WE_PLACE_PRESIZE: {
- TileIndex tile_from;
- TileIndex tile_to;
-
- tile_from = e->we.place.tile;
+ }
+ virtual void OnPlacePresize(Point pt, TileIndex tile_from)
+ {
DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from, NULL));
- tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile_from, ReverseDiagDir(dir)) : tile_from);
+ TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile_from, ReverseDiagDir(dir)) : tile_from);
VpSetPresizeRange(tile_from, tile_to);
- } break;
-
- case WE_DESTROY:
- if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
- break;
}
-}
+};
static const Widget _build_docks_toolb_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
@@ -218,7 +226,7 @@ static const WindowDesc _build_docks_toolbar_desc = {
WC_BUILD_TOOLBAR, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_build_docks_toolb_widgets,
- BuildDocksToolbWndProc
+ NULL
};
void ShowBuildDocksToolbar()
@@ -226,8 +234,7 @@ void ShowBuildDocksToolbar()
if (!IsValidPlayer(_current_player)) return;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
- Window *w = AllocateWindowDescFront<Window>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
- if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
+ AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
}
struct BuildDocksStationWindow : public PickerWindowBase {
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 860261387..5a5f48e1b 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -526,90 +526,99 @@ static const uint16 _rail_keycodes[] = {
};
-static void UpdateRemoveWidgetStatus(Window *w, int clicked_widget)
-{
- switch (clicked_widget) {
- case RTW_REMOVE:
- /* If it is the removal button that has been clicked, do nothing,
- * as it is up to the other buttons to drive removal status */
- return;
- break;
- 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 */
- w->SetWidgetDisabledState(RTW_REMOVE, !w->IsWidgetLowered(clicked_widget));
- break;
-
- default:
- /* When any other buttons than rail/signal/waypoint/station, raise and
- * disable the removal button */
- w->DisableWidget(RTW_REMOVE);
- w->RaiseWidget(RTW_REMOVE);
- break;
+struct BuildRailToolbarWindow : Window {
+ BuildRailToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
+ {
+ this->DisableWidget(RTW_REMOVE);
+
+ this->FindWindowPlacementAndResize(desc);
+ if (_patches.link_terraform_toolbar) ShowTerraformToolbar(this);
}
-}
-/**
- * Railway toolbar window event definition
- *
- * @param w window pointer
- * @param e event been triggered
- */
-static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_CREATE: w->DisableWidget(RTW_REMOVE); break;
+ ~BuildRailToolbarWindow()
+ {
+ if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
+ }
- case WE_PAINT: w->DrawWidgets(); break;
+ void UpdateRemoveWidgetStatus(int clicked_widget)
+ {
+ switch (clicked_widget) {
+ case RTW_REMOVE:
+ /* If it is the removal button that has been clicked, do nothing,
+ * as it is up to the other buttons to drive removal status */
+ return;
+ break;
+ 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 */
+ this->SetWidgetDisabledState(RTW_REMOVE, !this->IsWidgetLowered(clicked_widget));
+ break;
+
+ default:
+ /* When any other buttons than rail/signal/waypoint/station, raise and
+ * disable the removal button */
+ this->DisableWidget(RTW_REMOVE);
+ this->RaiseWidget(RTW_REMOVE);
+ break;
+ }
+ }
+
+ virtual void OnPaint()
+ {
+ this->DrawWidgets();
+ }
- case WE_CLICK:
- if (e->we.click.widget >= RTW_BUILD_NS) {
+ virtual void OnClick(Point pt, int widget)
+ {
+ if (widget >= RTW_BUILD_NS) {
_remove_button_clicked = false;
- _build_railroad_button_proc[e->we.click.widget - RTW_BUILD_NS](w);
+ _build_railroad_button_proc[widget - RTW_BUILD_NS](this);
}
- UpdateRemoveWidgetStatus(w, e->we.click.widget);
- if (_ctrl_pressed) RailToolbar_CtrlChanged(w);
- break;
+ this->UpdateRemoveWidgetStatus(widget);
+ if (_ctrl_pressed) RailToolbar_CtrlChanged(this);
+ }
- case WE_KEYPRESS:
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
+ {
+ EventState state = ES_NOT_HANDLED;
for (uint8 i = 0; i != lengthof(_rail_keycodes); i++) {
- if (e->we.keypress.keycode == _rail_keycodes[i]) {
- e->we.keypress.cont = false;
+ if (keycode == _rail_keycodes[i]) {
_remove_button_clicked = false;
- _build_railroad_button_proc[i](w);
- UpdateRemoveWidgetStatus(w, i + RTW_BUILD_NS);
- if (_ctrl_pressed) RailToolbar_CtrlChanged(w);
+ _build_railroad_button_proc[i](this);
+ this->UpdateRemoveWidgetStatus(i + RTW_BUILD_NS);
+ if (_ctrl_pressed) RailToolbar_CtrlChanged(this);
+ state = ES_HANDLED;
break;
}
}
MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection
- break;
+ return state;
+ }
- case WE_PLACE_OBJ:
- _place_proc(e->we.place.tile);
- return;
+ virtual void OnPlaceObject(Point pt, TileIndex tile)
+ {
+ _place_proc(tile);
+ }
- case WE_PLACE_DRAG: {
+ virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
+ {
/* no dragging if you have pressed the convert button */
- if (FindWindowById(WC_BUILD_SIGNAL, 0) != NULL && _convert_signal_button && w->IsWidgetLowered(RTW_BUILD_SIGNALS)) return;
+ if (FindWindowById(WC_BUILD_SIGNAL, 0) != NULL && _convert_signal_button && this->IsWidgetLowered(RTW_BUILD_SIGNALS)) return;
- VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
- return;
+ VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
- case WE_PLACE_MOUSEUP:
- if (e->we.place.pt.x != -1) {
- TileIndex start_tile = e->we.place.starttile;
- TileIndex end_tile = e->we.place.tile;
-
- switch (e->we.place.select_proc) {
+ virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
+ {
+ if (pt.x != -1) {
+ switch (select_proc) {
default: NOT_REACHED();
case DDSP_BUILD_BRIDGE:
ResetObjectToPlace();
@@ -625,7 +634,7 @@ static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
break;
case DDSP_DEMOLISH_AREA:
- GUIPlaceProcDragXY(e->we.place.select_proc, e->we.place.starttile, e->we.place.tile);
+ GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
break;
case DDSP_CONVERT_RAIL:
@@ -643,39 +652,36 @@ static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
case DDSP_PLACE_RAIL_NE:
case DDSP_PLACE_RAIL_NW:
- DoRailroadTrack(e->we.place.select_proc == DDSP_PLACE_RAIL_NE ? TRACK_X : TRACK_Y);
+ DoRailroadTrack(select_proc == DDSP_PLACE_RAIL_NE ? TRACK_X : TRACK_Y);
break;
}
}
- break;
+ }
- case WE_ABORT_PLACE_OBJ:
- w->RaiseButtons();
- w->DisableWidget(RTW_REMOVE);
- w->InvalidateWidget(RTW_REMOVE);
+ virtual void OnPlaceObjectAbort()
+ {
+ this->RaiseButtons();
+ this->DisableWidget(RTW_REMOVE);
+ this->InvalidateWidget(RTW_REMOVE);
delete FindWindowById(WC_BUILD_SIGNAL, 0);
delete FindWindowById(WC_BUILD_STATION, 0);
delete FindWindowById(WC_BUILD_DEPOT, 0);
- break;
-
- case WE_PLACE_PRESIZE: {
- TileIndex tile = e->we.place.tile;
+ }
+ virtual void OnPlacePresize(Point pt, TileIndex tile)
+ {
DoCommand(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL);
VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
- } break;
-
- case WE_DESTROY:
- if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
- break;
+ }
- case WE_CTRL_CHANGED:
+ virtual EventState OnCTRLStateChange()
+ {
/* do not toggle Remove button by Ctrl when placing station */
- if (!w->IsWidgetLowered(RTW_BUILD_STATION) && RailToolbar_CtrlChanged(w)) e->we.ctrl.cont = false;
- break;
+ if (!this->IsWidgetLowered(RTW_BUILD_STATION) && RailToolbar_CtrlChanged(this)) return ES_HANDLED;
+ return ES_NOT_HANDLED;
}
-}
+};
/** Widget definition for the rail toolbar */
static const Widget _build_rail_widgets[] = {
@@ -710,7 +716,7 @@ static const WindowDesc _build_rail_desc = {
WC_BUILD_TOOLBAR, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_build_rail_widgets,
- BuildRailToolbWndProc
+ NULL
};
@@ -736,25 +742,24 @@ static void SetupRailToolbar(RailType railtype, Window *w)
void ShowBuildRailToolbar(RailType railtype, int button)
{
- Window *w;
+ BuildRailToolbarWindow *w;
if (!IsValidPlayer(_current_player)) return;
if (!ValParamRailtype(railtype)) return;
// don't recreate the window if we're clicking on a button and the window exists.
- if (button < 0 || !(w = FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL))) {
+ if (button < 0 || !(w = dynamic_cast<BuildRailToolbarWindow*>(FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL)))) {
DeleteWindowByClass(WC_BUILD_TOOLBAR);
_cur_railtype = railtype;
- w = AllocateWindowDescFront<Window>(&_build_rail_desc, TRANSPORT_RAIL);
+ w = AllocateWindowDescFront<BuildRailToolbarWindow>(&_build_rail_desc, TRANSPORT_RAIL);
SetupRailToolbar(railtype, w);
}
_remove_button_clicked = false;
if (w != NULL && button >= RTW_CLOSEBOX) {
_build_railroad_button_proc[button](w);
- UpdateRemoveWidgetStatus(w, button + RTW_BUILD_NS);
+ w->UpdateRemoveWidgetStatus(button + RTW_BUILD_NS);
}
- if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
}
/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index 00f96f7ad..8611e8cac 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -400,217 +400,222 @@ static const uint16 _road_keycodes[] = {
'R',
};
-/**
- * Update the remove button lowered state of the road toolbar
- *
- * @param w The toolbar window
- * @param clicked_widget The widget which the player clicked just now
- */
-static void UpdateOptionWidgetStatus(Window *w, RoadToolbarWidgets clicked_widget)
-{
- /* The remove and the one way button state is driven
- * by the other buttons so they don't act on themselfs.
- * Both are only valid if they are able to apply as options. */
- switch (clicked_widget) {
- case RTW_REMOVE:
- w->RaiseWidget(RTW_ONE_WAY);
- w->InvalidateWidget(RTW_ONE_WAY);
- break;
-
- case RTW_ONE_WAY:
- w->RaiseWidget(RTW_REMOVE);
- w->InvalidateWidget(RTW_REMOVE);
- break;
-
- case RTW_BUS_STATION:
- case RTW_TRUCK_STATION:
- w->DisableWidget(RTW_ONE_WAY);
- w->SetWidgetDisabledState(RTW_REMOVE, !w->IsWidgetLowered(clicked_widget));
- break;
-
- case RTW_ROAD_X:
- case RTW_ROAD_Y:
- case RTW_AUTOROAD:
- w->SetWidgetsDisabledState(!w->IsWidgetLowered(clicked_widget),
- RTW_REMOVE,
- RTW_ONE_WAY,
- WIDGET_LIST_END);
- break;
-
- default:
- /* When any other buttons than road/station, raise and
- * disable the removal button */
- w->SetWidgetsDisabledState(true,
- RTW_REMOVE,
- RTW_ONE_WAY,
- WIDGET_LIST_END);
- w->SetWidgetsLoweredState (false,
- RTW_REMOVE,
- RTW_ONE_WAY,
- WIDGET_LIST_END);
- break;
+struct BuildRoadToolbarWindow : Window {
+ BuildRoadToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
+ {
+ this->SetWidgetsDisabledState(true,
+ RTW_REMOVE,
+ RTW_ONE_WAY,
+ WIDGET_LIST_END);
+
+ this->FindWindowPlacementAndResize(desc);
+ if (_patches.link_terraform_toolbar) ShowTerraformToolbar(this);
}
-}
-static void BuildRoadToolbWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_CREATE:
- w->SetWidgetsDisabledState(true,
- RTW_REMOVE,
- RTW_ONE_WAY,
- WIDGET_LIST_END);
- break;
-
- case WE_PAINT:
- w->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
- RTW_DEPOT,
- RTW_BUS_STATION,
- RTW_TRUCK_STATION,
- WIDGET_LIST_END);
- w->DrawWidgets();
- break;
-
- case WE_CLICK:
- if (e->we.click.widget >= RTW_ROAD_X) {
+ ~BuildRoadToolbarWindow()
+ {
+ if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
+ }
+
+ /**
+ * Update the remove button lowered state of the road toolbar
+ *
+ * @param clicked_widget The widget which the player clicked just now
+ */
+ void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
+ {
+ /* The remove and the one way button state is driven
+ * by the other buttons so they don't act on themselfs.
+ * Both are only valid if they are able to apply as options. */
+ switch (clicked_widget) {
+ case RTW_REMOVE:
+ this->RaiseWidget(RTW_ONE_WAY);
+ this->InvalidateWidget(RTW_ONE_WAY);
+ break;
+
+ case RTW_ONE_WAY:
+ this->RaiseWidget(RTW_REMOVE);
+ this->InvalidateWidget(RTW_REMOVE);
+ break;
+
+ case RTW_BUS_STATION:
+ case RTW_TRUCK_STATION:
+ this->DisableWidget(RTW_ONE_WAY);
+ this->SetWidgetDisabledState(RTW_REMOVE, !this->IsWidgetLowered(clicked_widget));
+ break;
+
+ case RTW_ROAD_X:
+ case RTW_ROAD_Y:
+ case RTW_AUTOROAD:
+ this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget),
+ RTW_REMOVE,
+ RTW_ONE_WAY,
+ WIDGET_LIST_END);
+ break;
+
+ default:
+ /* When any other buttons than road/station, raise and
+ * disable the removal button */
+ this->SetWidgetsDisabledState(true,
+ RTW_REMOVE,
+ RTW_ONE_WAY,
+ WIDGET_LIST_END);
+ this->SetWidgetsLoweredState (false,
+ RTW_REMOVE,
+ RTW_ONE_WAY,
+ WIDGET_LIST_END);
+ break;
+ }
+ }
+
+ virtual void OnPaint()
+ {
+ this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
+ RTW_DEPOT,
+ RTW_BUS_STATION,
+ RTW_TRUCK_STATION,
+ WIDGET_LIST_END);
+ this->DrawWidgets();
+ }
+
+ virtual void OnClick(Point pt, int widget)
+ {
+ if (widget >= RTW_ROAD_X) {
+ _remove_button_clicked = false;
+ _one_way_button_clicked = false;
+ _build_road_button_proc[widget - RTW_ROAD_X](this);
+ }
+ this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget);
+ if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
+ }
+
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
+ {
+ EventState state = ES_NOT_HANDLED;
+ for (uint i = 0; i != lengthof(_road_keycodes); i++) {
+ if (keycode == _road_keycodes[i]) {
_remove_button_clicked = false;
_one_way_button_clicked = false;
- _build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w);
- }
- UpdateOptionWidgetStatus(w, (RoadToolbarWidgets)e->we.click.widget);
- if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
- break;
-
- case WE_KEYPRESS:
- for (uint i = 0; i != lengthof(_road_keycodes); i++) {
- if (e->we.keypress.keycode == _road_keycodes[i]) {
- e->we.keypress.cont = false;
- _remove_button_clicked = false;
- _one_way_button_clicked = false;
- _build_road_button_proc[i](w);
- UpdateOptionWidgetStatus(w, (RoadToolbarWidgets)(i + RTW_ROAD_X));
- if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
- break;
- }
+ _build_road_button_proc[i](this);
+ this->UpdateOptionWidgetStatus((RoadToolbarWidgets)(i + RTW_ROAD_X));
+ if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
+ state = ES_HANDLED;
+ break;
}
- MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection
- break;
-
- case WE_PLACE_OBJ:
- _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
- _one_way_button_clicked = w->IsWidgetLowered(RTW_ONE_WAY);
- _place_proc(e->we.place.tile);
- break;
-
- case WE_ABORT_PLACE_OBJ:
- w->RaiseButtons();
- w->SetWidgetsDisabledState(true,
- RTW_REMOVE,
- RTW_ONE_WAY,
- WIDGET_LIST_END);
- w->InvalidateWidget(RTW_REMOVE);
- w->InvalidateWidget(RTW_ONE_WAY);
-
- delete FindWindowById(WC_BUS_STATION, 0);
- delete FindWindowById(WC_TRUCK_STATION, 0);
- delete FindWindowById(WC_BUILD_DEPOT, 0);
- break;
-
- case WE_PLACE_DRAG:
- /* Here we update the end tile flags
- * of the road placement actions.
- * At first we reset the end halfroad
- * bits and if needed we set them again. */
- switch (e->we.place.select_proc) {
- case DDSP_PLACE_ROAD_X_DIR:
- _place_road_flag &= ~RF_END_HALFROAD_X;
- if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
- break;
+ }
+ MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection
+ return state;
+ }
- case DDSP_PLACE_ROAD_Y_DIR:
- _place_road_flag &= ~RF_END_HALFROAD_Y;
- if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
- break;
+ virtual void OnPlaceObject(Point pt, TileIndex tile)
+ {
+ _remove_button_clicked = this->IsWidgetLowered(RTW_REMOVE);
+ _one_way_button_clicked = this->IsWidgetLowered(RTW_ONE_WAY);
+ _place_proc(tile);
+ }
- case DDSP_PLACE_AUTOROAD:
- _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
- if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
- if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
-
- /* For autoroad we need to update the
- * direction of the road */
- if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
- ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
- (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
- /* Set dir = X */
- _place_road_flag &= ~RF_DIR_Y;
- } else {
- /* Set dir = Y */
- _place_road_flag |= RF_DIR_Y;
- }
+ virtual void OnPlaceObjectAbort()
+ {
+ this->RaiseButtons();
+ this->SetWidgetsDisabledState(true,
+ RTW_REMOVE,
+ RTW_ONE_WAY,
+ WIDGET_LIST_END);
+ this->InvalidateWidget(RTW_REMOVE);
+ this->InvalidateWidget(RTW_ONE_WAY);
- break;
+ delete FindWindowById(WC_BUS_STATION, 0);
+ delete FindWindowById(WC_TRUCK_STATION, 0);
+ delete FindWindowById(WC_BUILD_DEPOT, 0);
+ }
- default:
- break;
- }
+ virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
+ {
+ /* Here we update the end tile flags
+ * of the road placement actions.
+ * At first we reset the end halfroad
+ * bits and if needed we set them again. */
+ switch (select_proc) {
+ case DDSP_PLACE_ROAD_X_DIR:
+ _place_road_flag &= ~RF_END_HALFROAD_X;
+ if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
+ break;
+
+ case DDSP_PLACE_ROAD_Y_DIR:
+ _place_road_flag &= ~RF_END_HALFROAD_Y;
+ if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
+ break;
- VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
- return;
-
- case WE_PLACE_MOUSEUP:
- if (e->we.place.pt.x != -1) {
- TileIndex start_tile = e->we.place.starttile;
- TileIndex end_tile = e->we.place.tile;
-
- switch (e->we.place.select_proc) {
- default: NOT_REACHED();
- case DDSP_BUILD_BRIDGE:
- ResetObjectToPlace();
- ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
- break;
-
- case DDSP_DEMOLISH_AREA:
- GUIPlaceProcDragXY(e->we.place.select_proc, e->we.place.starttile, e->we.place.tile);
- break;
-
- case DDSP_PLACE_ROAD_X_DIR:
- case DDSP_PLACE_ROAD_Y_DIR:
- case DDSP_PLACE_AUTOROAD:
- /* Flag description:
- * Use the first three bits (0x07) if dir == Y
- * else use the last 2 bits (X dir has
- * not the 3rd bit set) */
- _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
-
- DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), CcPlaySound1D,
- (_ctrl_pressed || _remove_button_clicked) ?
- CMD_REMOVE_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
- CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road));
- break;
+ case DDSP_PLACE_AUTOROAD:
+ _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
+ if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
+ if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
+
+ /* For autoroad we need to update the
+ * direction of the road */
+ if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
+ ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
+ (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
+ /* Set dir = X */
+ _place_road_flag &= ~RF_DIR_Y;
+ } else {
+ /* Set dir = Y */
+ _place_road_flag |= RF_DIR_Y;
}
- }
- break;
- case WE_PLACE_PRESIZE: {
- TileIndex tile = e->we.place.tile;
+ break;
+
+ default:
+ break;
+ }
+
+ VpSelectTilesWithMethod(pt.x, pt.y, select_method);
+ }
- DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL);
- VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
- } break;
+ virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
+ {
+ if (pt.x != -1) {
+ switch (select_proc) {
+ default: NOT_REACHED();
+ case DDSP_BUILD_BRIDGE:
+ ResetObjectToPlace();
+ ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
+ break;
- case WE_DESTROY:
- if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
- break;
+ case DDSP_DEMOLISH_AREA:
+ GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
+ break;
+
+ case DDSP_PLACE_ROAD_X_DIR:
+ case DDSP_PLACE_ROAD_Y_DIR:
+ case DDSP_PLACE_AUTOROAD:
+ /* Flag description:
+ * Use the first three bits (0x07) if dir == Y
+ * else use the last 2 bits (X dir has
+ * not the 3rd bit set) */
+ _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
+
+ DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), CcPlaySound1D,
+ (_ctrl_pressed || _remove_button_clicked) ?
+ CMD_REMOVE_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
+ CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road));
+ break;
+ }
+ }
+ }
- case WE_CTRL_CHANGED:
- if (RoadToolbar_CtrlChanged(w)) e->we.ctrl.cont = false;
- break;
+ virtual void OnPlacePresize(Point pt, TileIndex tile)
+ {
+ DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL);
+ VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
+ }
- default:
- break;
+ virtual EventState OnCTRLStateChange()
+ {
+ if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
+ return ES_NOT_HANDLED;
}
-}
+};
/** Widget definition of the build road toolbar */
static const Widget _build_road_widgets[] = {
@@ -638,7 +643,7 @@ static const WindowDesc _build_road_desc = {
WC_BUILD_TOOLBAR, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_build_road_widgets,
- BuildRoadToolbWndProc
+ NULL
};
/** Widget definition of the build tram toolbar */
@@ -667,7 +672,7 @@ static const WindowDesc _build_tramway_desc = {
WC_BUILD_TOOLBAR, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_build_tramway_widgets,
- BuildRoadToolbWndProc
+ NULL
};
void ShowBuildRoadToolbar(RoadType roadtype)
@@ -676,8 +681,7 @@ void ShowBuildRoadToolbar(RoadType roadtype)
_cur_roadtype = roadtype;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
- Window *w = AllocateWindowDescFront<Window>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
- if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
+ AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
}
/** Widget definition of the build road toolbar in the scenario editor */
@@ -705,13 +709,13 @@ static const WindowDesc _build_road_scen_desc = {
WC_SCEN_BUILD_ROAD, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_build_road_scen_widgets,
- BuildRoadToolbWndProc
+ NULL
};
void ShowBuildRoadScenToolbar()
{
_cur_roadtype = ROADTYPE_ROAD;
- AllocateWindowDescFront<Window>(&_build_road_scen_desc, 0);
+ AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc, 0);
}
struct BuildRoadDepotWindow : public PickerWindowBase {