From 82f658963febb2e481ffd7ab12cd48b1b22fbb44 Mon Sep 17 00:00:00 2001 From: Michael Bernardi Date: Fri, 2 Aug 2024 05:31:22 +1000 Subject: [PATCH] Improve readability of hover tooltip Also removed reliance on the localisation table. --- src/openrct2-ui/interface/Graph.cpp | 48 ++++++++++++---------------- src/openrct2-ui/windows/Finances.cpp | 10 ++++-- src/openrct2-ui/windows/Park.cpp | 4 +-- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/openrct2-ui/interface/Graph.cpp b/src/openrct2-ui/interface/Graph.cpp index 6146ef68e5..b67f35cdaf 100644 --- a/src/openrct2-ui/interface/Graph.cpp +++ b/src/openrct2-ui/interface/Graph.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -22,16 +23,16 @@ namespace OpenRCT2::Graph template static void DrawYLabels( DrawPixelInfo& dpi, const ScreenRect& internalBounds, const T min, const T max, const int32_t numYLabels, - const int32_t yLabelStepPx, const StringId fmt, const ColourWithFlags lineCol) + const int32_t yLabelStepPx, const ColourWithFlags lineCol, const FmtString& fmt) { T curLabel = max; int32_t curScreenPos = internalBounds.GetTop() - 5; const T yLabelStep = (max - min) / (numYLabels - 1); for (int32_t i = 0; i < numYLabels; i++) { - Formatter ft; - ft.Add(curLabel); - DrawTextBasic(dpi, { internalBounds.GetLeft(), curScreenPos }, fmt, ft, { FontStyle::Small, TextAlignment::RIGHT }); + char buffer[64]{}; + FormatStringToBuffer(buffer, sizeof(buffer), fmt, curLabel); + DrawText(dpi, { internalBounds.GetLeft(), curScreenPos }, { FontStyle::Small, TextAlignment::RIGHT }, buffer); GfxFillRectInset( dpi, { { internalBounds.GetLeft(), curScreenPos + 5 }, { internalBounds.GetRight(), curScreenPos + 5 } }, lineCol, INSET_RECT_FLAG_BORDER_INSET); @@ -72,7 +73,7 @@ namespace OpenRCT2::Graph template static void DrawHoveredValue( DrawPixelInfo& dpi, const T value, const int32_t hoverIdx, const ScreenRect& bounds, const int32_t xStep, - const T minValue, const T maxValue) + const T minValue, const T maxValue, const_utf8string text, ColourWithFlags textCol) { const int32_t screenRange = bounds.GetHeight(); const int32_t valueRange = maxValue - minValue; @@ -89,10 +90,9 @@ namespace OpenRCT2::Graph kDashLength, PALETTE_INDEX_10); GfxDrawDashedLine(dpi, { { bounds.GetLeft(), coords.y }, coords }, kDashLength, PALETTE_INDEX_10); - auto ft = Formatter(); + Formatter ft; ft.Add(value); - DrawTextBasic( - dpi, coords - ScreenCoordsXY{ 0, 16 }, STR_FINANCES_SUMMARY_EXPENDITURE_VALUE, ft, { TextAlignment::CENTRE }); + DrawText(dpi, coords - ScreenCoordsXY{ 0, 16 }, { textCol, TextAlignment::CENTRE }, text); GfxFillRect(dpi, { { coords - ScreenCoordsXY{ 2, 2 } }, coords + ScreenCoordsXY{ 2, 2 } }, PALETTE_INDEX_10); GfxFillRect(dpi, { { coords - ScreenCoordsXY{ 1, 1 } }, { coords + ScreenCoordsXY{ 1, 1 } } }, PALETTE_INDEX_21); @@ -156,8 +156,8 @@ namespace OpenRCT2::Graph void DrawFinanceGraph(DrawPixelInfo& dpi, const GraphProperties& p) { - constexpr StringId fmt = STR_FINANCES_FINANCIAL_GRAPH_CASH_VALUE; - DrawYLabels(dpi, p.internalBounds, p.min, p.max, p.numYLabels, p.yLabelStepPx, fmt, p.lineCol); + const FmtString fmt("{BLACK}{CURRENCY2DP} -"); + DrawYLabels(dpi, p.internalBounds, p.min, p.max, p.numYLabels, p.yLabelStepPx, p.lineCol, fmt); DrawMonths(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx); DrawLine(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max); DrawLine(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max); @@ -165,40 +165,34 @@ namespace OpenRCT2::Graph { const money64 value = p.series[p.hoverIdx]; if (value != kMoney64Undefined) - DrawHoveredValue(dpi, value, p.hoverIdx, p.internalBounds, p.xStepPx, p.min, p.max); + { + char buffer[64]{}; + FormatStringToBuffer(buffer, sizeof(buffer), "{CURRENCY2DP}", value); + DrawHoveredValue( + dpi, value, p.hoverIdx, p.internalBounds, p.xStepPx, p.min, p.max, buffer, + p.lineCol.withFlag(ColourFlag::withOutline, true)); + } } } void DrawRatingGraph(DrawPixelInfo& dpi, const GraphProperties& p) { constexpr uint8_t noValue = ParkRatingHistoryUndefined; - constexpr StringId fmt = STR_GRAPH_AXIS_LABEL; + const FmtString fmt("{BLACK}{COMMA32} -"); // Since the park rating rating history is divided by 4, we have to fudge the max number here. - DrawYLabels(dpi, p.internalBounds, p.min, 1000, p.numYLabels, p.yLabelStepPx, fmt, p.lineCol); + DrawYLabels(dpi, p.internalBounds, p.min, 1000, p.numYLabels, p.yLabelStepPx, p.lineCol, fmt); DrawMonths(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx); DrawLine(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max); DrawLine(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max); - if (p.hoverIdx >= 0 && p.hoverIdx < p.numPoints) - { - const uint8_t value = p.series[p.hoverIdx]; - if (value != noValue) - DrawHoveredValue(dpi, value, p.hoverIdx, p.internalBounds, p.xStepPx, p.min, p.max); - } } void DrawGuestGraph(DrawPixelInfo& dpi, const GraphProperties& p) { constexpr uint32_t noValue = GuestsInParkHistoryUndefined; - constexpr StringId fmt = STR_GRAPH_AXIS_LABEL; - DrawYLabels(dpi, p.internalBounds, p.min, p.max, p.numYLabels, p.yLabelStepPx, fmt, p.lineCol); + const FmtString fmt("{BLACK}{COMMA32} -"); + DrawYLabels(dpi, p.internalBounds, p.min, p.max, p.numYLabels, p.yLabelStepPx, p.lineCol, fmt); DrawMonths(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx); DrawLine(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max); DrawLine(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max); - if (p.hoverIdx >= 0 && p.hoverIdx < p.numPoints) - { - const uint32_t value = p.series[p.hoverIdx]; - if (value != noValue) - DrawHoveredValue(dpi, value, p.hoverIdx, p.internalBounds, p.xStepPx, p.min, p.max); - } } } // namespace OpenRCT2::Graph diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index 240963c007..6b69f7e04b 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -222,7 +222,7 @@ static Widget _windowFinancesResearchWidgets[] = static constexpr ScreenCoordsXY kGraphTopLeftPadding{ 88, 20 }; static constexpr ScreenCoordsXY kGraphBottomRightPadding{ 15, 18 }; static constexpr uint8_t kGraphNumYLabels = 5; - static constexpr int32_t kGraphNumPoints = 64; // todo. was always 64 in original code. + static constexpr int32_t kGraphNumPoints = 64; #pragma endregion @@ -244,7 +244,6 @@ static Widget _windowFinancesResearchWidgets[] = SetPage(WINDOW_FINANCES_PAGE_SUMMARY); _lastPaintedMonth = std::numeric_limits::max(); ResearchUpdateUncompletedTypes(); - _graphProps.lineCol = colours[2]; _graphProps.hoverIdx = -1; } @@ -363,6 +362,7 @@ static Widget _windowFinancesResearchWidgets[] = _graphProps.RecalculateLayout( { _graphBounds.Point1 + kGraphTopLeftPadding, _graphBounds.Point2 - kGraphBottomRightPadding }, kGraphNumYLabels, kGraphNumPoints); + _graphProps.lineCol = colours[2]; } break; } @@ -848,6 +848,12 @@ static Widget _windowFinancesResearchWidgets[] = // Graph GfxFillRectInset(dpi, _graphBounds, colours[1], INSET_RECT_F_30); + // hide resize widget on graph area + constexpr ScreenCoordsXY offset{ 1, 1 }; + constexpr ScreenCoordsXY bigOffset{ 5, 5 }; + GfxFillRectInset( + dpi, { _graphBounds.Point2 - bigOffset, _graphBounds.Point2 - offset }, colours[1], + INSET_RECT_FLAG_FILL_DONT_LIGHTEN | INSET_RECT_FLAG_BORDER_NONE); // Calculate Y axis max and min. // This is how the original code does it. Could be improved. diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index 6cf552796c..cb7f735724 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -10,11 +10,11 @@ #include "../interface/Theme.h" #include -#include #include #include #include #include +#include #include #include #include @@ -38,7 +38,7 @@ namespace OpenRCT2::Ui::Windows static constexpr StringId WINDOW_TITLE = STR_STRINGID; static constexpr int32_t WH = 224; - static constexpr ScreenCoordsXY kGraphTopLeftPadding{ 35, 15 }; + static constexpr ScreenCoordsXY kGraphTopLeftPadding{ 45, 15 }; static constexpr ScreenCoordsXY kGraphBottomRightPadding{ 5, 5 }; static constexpr uint8_t kGraphNumYLabels = 6;