diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 3520857915..b0bdd7cbb8 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -161,6 +161,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) { @@ -211,7 +216,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 caad21a280..eea54f16e3 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -250,6 +250,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) { @@ -352,7 +357,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 98400d2363..5cbb9de220 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -728,6 +728,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) { @@ -899,7 +904,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 7aac90b4b9..aecfc9c8cd 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -724,6 +724,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) { @@ -939,7 +944,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, @@ -984,7 +989,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 239f347025..14a4597e1f 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -257,7 +257,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; } @@ -364,19 +365,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 419612e0bf..4422cd86ed 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1677,7 +1677,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) @@ -1688,6 +1688,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 c6f1909ef2..bf09cd1985 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -158,6 +158,7 @@ enum class WindowDefaultFlag : uint8_t { using WindowDefaultFlags = EnumBitSet; Point GetToolbarAlignedWindowPosition(int window_width); +Point AlignInitialConstructionToolbar(int window_width); struct HotkeyList;