mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
Improve readability of hover tooltip
Also removed reliance on the localisation table.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <openrct2-ui/interface/Graph.h>
|
||||
#include <openrct2/Date.h>
|
||||
#include <openrct2/localisation/Formatter.h>
|
||||
#include <openrct2/localisation/Formatting.h>
|
||||
#include <openrct2/localisation/Localisation.Date.h>
|
||||
#include <openrct2/world/Park.h>
|
||||
|
||||
@@ -22,16 +23,16 @@ namespace OpenRCT2::Graph
|
||||
template<typename T>
|
||||
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<T>(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<typename T>
|
||||
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<money64>(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<money64>& p)
|
||||
{
|
||||
constexpr StringId fmt = STR_FINANCES_FINANCIAL_GRAPH_CASH_VALUE;
|
||||
DrawYLabels<money64>(dpi, p.internalBounds, p.min, p.max, p.numYLabels, p.yLabelStepPx, fmt, p.lineCol);
|
||||
const FmtString fmt("{BLACK}{CURRENCY2DP} -");
|
||||
DrawYLabels<money64>(dpi, p.internalBounds, p.min, p.max, p.numYLabels, p.yLabelStepPx, p.lineCol, fmt);
|
||||
DrawMonths<money64, kMoney64Undefined>(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx);
|
||||
DrawLine<money64, kMoney64Undefined, true>(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max);
|
||||
DrawLine<money64, kMoney64Undefined, false>(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<money64>(dpi, value, p.hoverIdx, p.internalBounds, p.xStepPx, p.min, p.max);
|
||||
{
|
||||
char buffer[64]{};
|
||||
FormatStringToBuffer(buffer, sizeof(buffer), "{CURRENCY2DP}", value);
|
||||
DrawHoveredValue<money64>(
|
||||
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<uint8_t>& 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<uint16_t>(dpi, p.internalBounds, p.min, 1000, p.numYLabels, p.yLabelStepPx, fmt, p.lineCol);
|
||||
DrawYLabels<uint16_t>(dpi, p.internalBounds, p.min, 1000, p.numYLabels, p.yLabelStepPx, p.lineCol, fmt);
|
||||
DrawMonths<uint8_t, noValue>(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx);
|
||||
DrawLine<uint8_t, noValue, true>(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max);
|
||||
DrawLine<uint8_t, noValue, false>(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<uint8_t>(dpi, value, p.hoverIdx, p.internalBounds, p.xStepPx, p.min, p.max);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawGuestGraph(DrawPixelInfo& dpi, const GraphProperties<uint32_t>& p)
|
||||
{
|
||||
constexpr uint32_t noValue = GuestsInParkHistoryUndefined;
|
||||
constexpr StringId fmt = STR_GRAPH_AXIS_LABEL;
|
||||
DrawYLabels<uint32_t>(dpi, p.internalBounds, p.min, p.max, p.numYLabels, p.yLabelStepPx, fmt, p.lineCol);
|
||||
const FmtString fmt("{BLACK}{COMMA32} -");
|
||||
DrawYLabels<uint32_t>(dpi, p.internalBounds, p.min, p.max, p.numYLabels, p.yLabelStepPx, p.lineCol, fmt);
|
||||
DrawMonths<uint32_t, noValue>(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx);
|
||||
DrawLine<uint32_t, noValue, true>(dpi, p.series, p.numPoints, p.internalBounds, p.xStepPx, p.min, p.max);
|
||||
DrawLine<uint32_t, noValue, false>(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<uint32_t>(dpi, value, p.hoverIdx, p.internalBounds, p.xStepPx, p.min, p.max);
|
||||
}
|
||||
}
|
||||
} // namespace OpenRCT2::Graph
|
||||
|
||||
@@ -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<uint32_t>::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.
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
#include "../interface/Theme.h"
|
||||
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <openrct2-ui/interface/Dropdown.h>
|
||||
#include <openrct2-ui/interface/Graph.h>
|
||||
#include <openrct2-ui/interface/LandTool.h>
|
||||
#include <openrct2-ui/interface/Objective.h>
|
||||
#include <openrct2-ui/interface/Viewport.h>
|
||||
#include <openrct2-ui/interface/Widget.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/Context.h>
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user