Change: Clamp terraform toolbar to main toolbar (#14725)
This commit is contained in:
@@ -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<NWidgetPart> _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,
|
||||
|
||||
@@ -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<NWidgetPart> _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,
|
||||
|
||||
@@ -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<NWidgetPart> _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,
|
||||
|
||||
@@ -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<NWidgetPart> _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<NWidgetPart> _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,
|
||||
|
||||
@@ -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<TerraformToolbarWindow>(_terraform_desc, 0);
|
||||
return w;
|
||||
}
|
||||
|
||||
/* Delete the terraform toolbar to place it again. */
|
||||
CloseWindowById(WC_SCEN_LAND_GEN, 0, true);
|
||||
w = AllocateWindowDescFront<TerraformToolbarWindow>(_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<TerraformToolbarWindow>(_terraform_desc, 0);
|
||||
|
||||
Window *w = AllocateWindowDescFront<TerraformToolbarWindow>(_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();
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -158,6 +158,7 @@ enum class WindowDefaultFlag : uint8_t {
|
||||
using WindowDefaultFlags = EnumBitSet<WindowDefaultFlag, uint8_t>;
|
||||
|
||||
Point GetToolbarAlignedWindowPosition(int window_width);
|
||||
Point AlignInitialConstructionToolbar(int window_width);
|
||||
|
||||
struct HotkeyList;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user