diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 0cd6209ba5..f6b7831074 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -167,6 +167,11 @@ struct BuildAirToolbarWindow : Window { VpSelectTilesWithMethod(pt.x, pt.y, select_method); } + Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override + { + return AlignInitialConstructionToolbar(sm_width); + } + void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override { if (pt.x != -1 && select_proc == DDSP_DEMOLISH_AREA) { @@ -219,7 +224,7 @@ static constexpr std::initializer_list _nested_air_toolbar_widgets }; static WindowDesc _air_toolbar_desc( - WDP_ALIGN_TOOLBAR, "toolbar_air", 0, 0, + WDP_MANUAL, "toolbar_air", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WindowDefaultFlag::Construction, _nested_air_toolbar_widgets, diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 92a1449cb1..4de7932f07 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -265,6 +265,11 @@ struct BuildDocksToolbarWindow : Window { VpSelectTilesWithMethod(pt.x, pt.y, select_method); } + Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override + { + return AlignInitialConstructionToolbar(sm_width); + } + void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override { if (pt.x != -1) { @@ -369,7 +374,7 @@ static constexpr std::initializer_list _nested_build_docks_toolbar_ }; static WindowDesc _build_docks_toolbar_desc( - WDP_ALIGN_TOOLBAR, "toolbar_water", 0, 0, + WDP_MANUAL, "toolbar_water", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WindowDefaultFlag::Construction, _nested_build_docks_toolbar_widgets, diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index c1454b416a..f058568570 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -872,6 +872,11 @@ struct BuildRailToolbarWindow : Window { VpSelectTilesWithMethod(pt.x, pt.y, select_method); } + Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override + { + return AlignInitialConstructionToolbar(sm_width); + } + void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override { if (pt.x != -1) { @@ -1093,7 +1098,7 @@ static constexpr std::initializer_list _nested_build_rail_widgets = }; static WindowDesc _build_rail_desc( - WDP_ALIGN_TOOLBAR, "toolbar_rail", 0, 0, + WDP_MANUAL, "toolbar_rail", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WindowDefaultFlag::Construction, _nested_build_rail_widgets, diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 98b10e956c..aea1dc00a2 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -755,6 +755,11 @@ struct BuildRoadToolbarWindow : Window { VpSelectTilesWithMethod(pt.x, pt.y, select_method); } + Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override + { + return AlignInitialConstructionToolbar(sm_width); + } + void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override { if (pt.x != -1) { @@ -974,7 +979,7 @@ static constexpr std::initializer_list _nested_build_road_widgets = }; static WindowDesc _build_road_desc( - WDP_ALIGN_TOOLBAR, "toolbar_road", 0, 0, + WDP_MANUAL, "toolbar_road", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WindowDefaultFlag::Construction, _nested_build_road_widgets, @@ -1019,7 +1024,7 @@ static constexpr std::initializer_list _nested_build_tramway_widget }; static WindowDesc _build_tramway_desc( - WDP_ALIGN_TOOLBAR, "toolbar_tramway", 0, 0, + WDP_MANUAL, "toolbar_tramway", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WindowDefaultFlag::Construction, _nested_build_tramway_widgets, diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 5ee58cb65e..2bf5d14870 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -338,7 +338,8 @@ struct TerraformToolbarWindow : Window { Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override { Point pt = GetToolbarAlignedWindowPosition(sm_width); - pt.y += sm_height; + if (FindWindowByClass(WC_BUILD_TOOLBAR) != nullptr && !_settings_client.gui.link_terraform_toolbar) pt.y += sm_height; + return pt; } @@ -449,19 +450,13 @@ Window *ShowTerraformToolbar(Window *link) { if (!Company::IsValidID(_local_company)) return nullptr; - Window *w; - if (link == nullptr) { - w = AllocateWindowDescFront(_terraform_desc, 0); - return w; - } - /* Delete the terraform toolbar to place it again. */ CloseWindowById(WC_SCEN_LAND_GEN, 0, true); - w = AllocateWindowDescFront(_terraform_desc, 0); - /* Align the terraform toolbar under the main toolbar. */ - w->top -= w->height; - w->SetDirty(); - /* Put the linked toolbar to the left / right of it. */ + + if (link == nullptr) return AllocateWindowDescFront(_terraform_desc, 0); + + Window *w = AllocateWindowDescFront(_terraform_desc, 0); + /* Put the linked toolbar to the left / right of the main toolbar. */ link->left = w->left + (_current_text_dir == TD_RTL ? w->width : -link->width); link->top = w->top; link->SetDirty(); diff --git a/src/window.cpp b/src/window.cpp index 53071fee7f..8275eb5e4a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1690,7 +1690,7 @@ restart: /** * Computer the position of the top-left corner of a window to be opened right * under the toolbar. - * @param window_width the width of the window to get the position for + * @param window_width the width of the window to get the position for. * @return Coordinate of the top-left corner of the new window. */ Point GetToolbarAlignedWindowPosition(int window_width) @@ -1701,6 +1701,24 @@ Point GetToolbarAlignedWindowPosition(int window_width) return pt; } +/** + * Compute the position of the construction toolbars. + * + * If the terraform toolbar is open place them to the right/left of it, + * otherwise use default toolbar aligned position. + * @param window_width the width of the toolbar to get the position for. + * @return Coordinate of the top-left corner of the new toolbar. + */ +Point AlignInitialConstructionToolbar(int window_width) +{ + Point pt = GetToolbarAlignedWindowPosition(window_width); + const Window *w = FindWindowByClass(WC_SCEN_LAND_GEN); + if (w != nullptr && w->top == pt.y && !_settings_client.gui.link_terraform_toolbar) { + pt.x = w->left + (_current_text_dir == TD_RTL ? w->width : - window_width); + } + return pt; +} + /** * Compute the position of the top-left corner of a new window that is opened. * diff --git a/src/window_gui.h b/src/window_gui.h index ce216ae77c..9ca8257c5c 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -160,6 +160,7 @@ enum class WindowDefaultFlag : uint8_t { using WindowDefaultFlags = EnumBitSet; Point GetToolbarAlignedWindowPosition(int window_width); +Point AlignInitialConstructionToolbar(int window_width); struct HotkeyList;