From fcbe1aaf92a8b45186f9af52aa931511a34a4e51 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Wed, 11 Sep 2024 17:08:20 +0200 Subject: [PATCH] Display height units in preferred length measurement unit --- src/openrct2-ui/windows/MapGen.cpp | 71 +++++++++++++++++++----------- src/openrct2/util/Util.cpp | 15 +++++++ src/openrct2/util/Util.h | 3 ++ 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/src/openrct2-ui/windows/MapGen.cpp b/src/openrct2-ui/windows/MapGen.cpp index 61705497b5..99353989c9 100644 --- a/src/openrct2-ui/windows/MapGen.cpp +++ b/src/openrct2-ui/windows/MapGen.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -770,11 +771,11 @@ namespace OpenRCT2::Ui::Windows {}, { textColour }); ft = Formatter(); - ft.Add(_settings.minTreeAltitude); + ft.Add(BaseZToMetres(_settings.minTreeAltitude)); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_TREE_ALTITUDE_MIN].left + 1, widgets[WIDX_TREE_ALTITUDE_MIN].top + 1 }, - STR_COMMA16, ft, { textColour }); + STR_RIDE_LENGTH_ENTRY, ft, { textColour }); // Maximum tree altitude, label and value DrawTextBasic( @@ -782,11 +783,11 @@ namespace OpenRCT2::Ui::Windows {}, { textColour }); ft = Formatter(); - ft.Add(_settings.maxTreeAltitude); + ft.Add(BaseZToMetres(_settings.maxTreeAltitude)); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_TREE_ALTITUDE_MAX].left + 1, widgets[WIDX_TREE_ALTITUDE_MAX].top + 1 }, - STR_COMMA16, ft, { textColour }); + STR_RIDE_LENGTH_ENTRY, ft, { textColour }); } #pragma endregion @@ -933,11 +934,11 @@ namespace OpenRCT2::Ui::Windows case WIDX_BASE_HEIGHT: { Formatter ft; - ft.Add((kMinimumLandHeight - 12) / 2); - ft.Add((kMaximumLandHeight - 12) / 2); + ft.Add(BaseZToMetres(kMinimumLandHeight)); + ft.Add(BaseZToMetres(kMaximumLandHeight)); WindowTextInputOpen( this, WIDX_BASE_HEIGHT, STR_BASE_HEIGHT, STR_ENTER_BASE_HEIGHT, ft, STR_FORMAT_INTEGER, - (_settings.baseHeight - 12) / 2, 3); + BaseZToMetres(_settings.baseHeight), 6); break; } case WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES: @@ -1001,21 +1002,30 @@ namespace OpenRCT2::Ui::Windows void TerrainTextInput(WidgetIndex widgetIndex, std::string_view text) { - int32_t value; - char* end; - const auto strText = u8string(text); - value = strtol(strText.c_str(), &end, 10); - + char* end; + int32_t value = strtol(strText.c_str(), &end, 10); if (*end != '\0') { return; } + switch (Config::Get().general.MeasurementFormat) + { + case MeasurementFormat::Imperial: + value = FeetToMetres(value); + [[fallthrough]]; + + default: + value = std::clamp(MetresToBaseZ(value), kMinimumLandHeight, kMaximumLandHeight); + break; + } + switch (widgetIndex) { case WIDX_BASE_HEIGHT: - _settings.baseHeight = std::clamp((value * 2) + 12, kMinimumLandHeight, kMaximumLandHeight); + _settings.baseHeight = value; + break; break; } @@ -1154,10 +1164,10 @@ namespace OpenRCT2::Ui::Windows { textColour }); auto ft = Formatter(); - ft.Add((_settings.baseHeight - 12) / 2); + ft.Add(BaseZToMetres(_settings.baseHeight)); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_BASE_HEIGHT].left + 1, widgets[WIDX_BASE_HEIGHT].top + 1 }, - STR_COMMA16, ft, { colours[1] }); + STR_RIDE_LENGTH_ENTRY, ft, { colours[1] }); // Floor texture label DrawTextBasic( @@ -1170,10 +1180,10 @@ namespace OpenRCT2::Ui::Windows { textColour }); ft = Formatter(); - ft.Add(_settings.heightmapLow); + ft.Add(BaseZToMetres(_settings.heightmapLow)); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_HEIGHTMAP_LOW].left + 1, widgets[WIDX_HEIGHTMAP_LOW].top + 1 }, - STR_COMMA16, ft, { textColour }); + STR_RIDE_LENGTH_ENTRY, ft, { textColour }); // Maximum land height label and value DrawTextBasic( @@ -1181,10 +1191,10 @@ namespace OpenRCT2::Ui::Windows { textColour }); ft = Formatter(); - ft.Add(_settings.heightmapHigh); + ft.Add(BaseZToMetres(_settings.heightmapHigh)); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_HEIGHTMAP_HIGH].left + 1, widgets[WIDX_HEIGHTMAP_HIGH].top + 1 }, - STR_COMMA16, ft, { textColour }); + STR_RIDE_LENGTH_ENTRY, ft, { textColour }); } #pragma endregion @@ -1200,11 +1210,11 @@ namespace OpenRCT2::Ui::Windows case WIDX_WATER_LEVEL: { Formatter ft; - ft.Add((kMinimumWaterHeight - 12) / 2); - ft.Add((kMaximumWaterHeight - 12) / 2); + ft.Add(kMinimumWaterHeight); + ft.Add(kMaximumWaterHeight); WindowTextInputOpen( this, WIDX_WATER_LEVEL, STR_WATER_LEVEL, STR_ENTER_WATER_LEVEL, ft, STR_FORMAT_INTEGER, - (_settings.waterLevel - 12) / 2, 3); + _settings.waterLevel, 6); break; } @@ -1253,10 +1263,21 @@ namespace OpenRCT2::Ui::Windows return; } + switch (Config::Get().general.MeasurementFormat) + { + case MeasurementFormat::Imperial: + value = FeetToMetres(value); + [[fallthrough]]; + + default: + value = std::clamp(MetresToBaseZ(value), kMinimumWaterHeight, kMaximumWaterHeight); + break; + } + switch (widgetIndex) { case WIDX_WATER_LEVEL: - _settings.waterLevel = std::clamp((value * 2) + 12, kMinimumWaterHeight, kMaximumWaterHeight); + _settings.waterLevel = value; break; } @@ -1288,10 +1309,10 @@ namespace OpenRCT2::Ui::Windows { textColour }); auto ft = Formatter(); - ft.Add((_settings.waterLevel - 12) / 2); + ft.Add(BaseZToMetres(_settings.waterLevel)); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_WATER_LEVEL].left + 1, widgets[WIDX_WATER_LEVEL].top + 1 }, - STR_COMMA16, ft, { colours[1] }); + STR_RIDE_LENGTH_ENTRY, ft, { colours[1] }); } #pragma endregion diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 3e1e8dd4da..fcaf6703a1 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -39,6 +39,11 @@ int32_t MetresToFeet(int32_t metres) return (metres * 840) / 256; } +int32_t FeetToMetres(int32_t feet) +{ + return feet * 256 / 840; +} + int32_t MphToKmph(int32_t mph) { // 1 mph = 1.60934 kmph @@ -52,6 +57,16 @@ int32_t MphToDmps(int32_t mph) return (mph * 73243) >> 14; } +int32_t BaseZToMetres(int16_t baseZ) +{ + return (baseZ / 2 - 7) * 1.5; +} + +uint8_t MetresToBaseZ(int16_t metres) +{ + return ((metres / 1.5) + 7) * 2; +} + /* Case insensitive logical compare */ // Example: // - Guest 10 diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index ec4074c63a..b94e51042d 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -25,8 +25,11 @@ int32_t SquaredMetresToSquaredFeet(int32_t squaredMetres); int32_t MetresToFeet(int32_t metres); +int32_t FeetToMetres(int32_t feet); int32_t MphToKmph(int32_t mph); int32_t MphToDmps(int32_t mph); +int32_t BaseZToMetres(int16_t baseZ); +uint8_t MetresToBaseZ(int16_t metres); inline int32_t UtilBitScanForward(uint32_t source) {