mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-22 22:34:33 +01:00
Improve contrast for error messages
Co-authored-by: Aaron van Geffen <aaron@aaronweb.net>
This commit is contained in:
committed by
GitHub
parent
0df7e41f59
commit
a0be444d24
@@ -21,16 +21,19 @@
|
||||
|
||||
namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
// clang-format off
|
||||
enum {
|
||||
WIDX_BACKGROUND
|
||||
};
|
||||
enum
|
||||
{
|
||||
WIDX_BACKGROUND,
|
||||
};
|
||||
|
||||
static Widget window_error_widgets[] = {
|
||||
MakeWidget({0, 0}, {200, 42}, WindowWidgetType::ImgBtn, WindowColour::Primary),
|
||||
kWidgetsEnd,
|
||||
};
|
||||
// clang-format on
|
||||
static constexpr auto kMinWidth = 70;
|
||||
static constexpr auto kMaxWidth = 250;
|
||||
static constexpr auto kPadding = 4;
|
||||
|
||||
static Widget window_error_widgets[] = {
|
||||
MakeWidget({ 0, 0 }, { 200, 42 }, WindowWidgetType::Frame, WindowColour::Primary),
|
||||
kWidgetsEnd,
|
||||
};
|
||||
|
||||
class ErrorWindow final : public Window
|
||||
{
|
||||
@@ -50,57 +53,24 @@ static Widget window_error_widgets[] = {
|
||||
|
||||
void OnOpen() override
|
||||
{
|
||||
window_error_widgets[WIDX_BACKGROUND].right = width;
|
||||
window_error_widgets[WIDX_BACKGROUND].bottom = height;
|
||||
window_error_widgets[WIDX_BACKGROUND].right = width - 1;
|
||||
window_error_widgets[WIDX_BACKGROUND].bottom = height - 1;
|
||||
|
||||
widgets = window_error_widgets;
|
||||
_staleCount = 0;
|
||||
|
||||
if (!gDisableErrorWindowSound)
|
||||
{
|
||||
OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::Error, 0, windowPos.x + (width / 2));
|
||||
Audio::Play(Audio::SoundId::Error, 0, windowPos.x + (width / 2));
|
||||
}
|
||||
}
|
||||
|
||||
void OnDraw(DrawPixelInfo& dpi) override
|
||||
{
|
||||
ScreenCoordsXY leftTop{ windowPos };
|
||||
ScreenCoordsXY rightBottom{ windowPos + ScreenCoordsXY{ width - 1, height - 1 } };
|
||||
ScreenCoordsXY leftBottom{ leftTop.x, rightBottom.y };
|
||||
ScreenCoordsXY rightTop{ rightBottom.x, leftTop.y };
|
||||
WindowDrawWidgets(*this, dpi);
|
||||
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ leftTop + ScreenCoordsXY{ 1, 1 }, rightBottom - ScreenCoordsXY{ 1, 1 } },
|
||||
FilterPaletteID::Palette45);
|
||||
GfxFilterRect(dpi, ScreenRect{ leftTop, rightBottom }, FilterPaletteID::PaletteGlassSaturatedRed);
|
||||
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ leftTop + ScreenCoordsXY{ 0, 2 }, leftBottom - ScreenCoordsXY{ 0, 2 } },
|
||||
FilterPaletteID::PaletteDarken3);
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ rightTop + ScreenCoordsXY{ 0, 2 }, rightBottom - ScreenCoordsXY{ 0, 2 } },
|
||||
FilterPaletteID::PaletteDarken3);
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ leftBottom + ScreenCoordsXY{ 2, 0 }, rightBottom - ScreenCoordsXY{ 2, 0 } },
|
||||
FilterPaletteID::PaletteDarken3);
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ leftTop + ScreenCoordsXY{ 2, 0 }, rightTop - ScreenCoordsXY{ 2, 0 } },
|
||||
FilterPaletteID::PaletteDarken3);
|
||||
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ rightTop + ScreenCoordsXY{ 1, 1 }, rightTop + ScreenCoordsXY{ 1, 1 } },
|
||||
FilterPaletteID::PaletteDarken3);
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ rightTop + ScreenCoordsXY{ -1, 1 }, rightTop + ScreenCoordsXY{ -1, 1 } },
|
||||
FilterPaletteID::PaletteDarken3);
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ leftBottom + ScreenCoordsXY{ 1, -1 }, leftBottom + ScreenCoordsXY{ 1, -1 } },
|
||||
FilterPaletteID::PaletteDarken3);
|
||||
GfxFilterRect(
|
||||
dpi, ScreenRect{ rightBottom - ScreenCoordsXY{ 1, 1 }, rightBottom - ScreenCoordsXY{ 1, 1 } },
|
||||
FilterPaletteID::PaletteDarken3);
|
||||
|
||||
DrawStringCentredRaw(
|
||||
dpi, { leftTop + ScreenCoordsXY{ (width + 1) / 2 - 1, 1 } }, _numLines, _text.data(), FontStyle::Medium);
|
||||
auto screenCoords = windowPos + ScreenCoordsXY{ (width + 1) / 2 - 1, kPadding - 1 };
|
||||
DrawStringCentredRaw(dpi, screenCoords, _numLines, _text.data(), FontStyle::Medium);
|
||||
}
|
||||
|
||||
void OnPeriodicUpdate() override
|
||||
@@ -125,7 +95,7 @@ static Widget window_error_widgets[] = {
|
||||
|
||||
WindowBase* ErrorOpen(std::string_view title, std::string_view message, bool autoClose)
|
||||
{
|
||||
std::string buffer = "{BLACK}";
|
||||
std::string buffer = "{WINDOW_COLOUR_1}";
|
||||
buffer.append(title);
|
||||
|
||||
// Format the message
|
||||
@@ -152,30 +122,24 @@ static Widget window_error_widgets[] = {
|
||||
// Close any existing error windows if they exist.
|
||||
WindowCloseByClass(WindowClass::Error);
|
||||
|
||||
// How wide is the error string?
|
||||
int32_t width = GfxGetStringWidthNewLined(buffer.data(), FontStyle::Medium);
|
||||
width = std::clamp(width, 64, 196);
|
||||
width = std::clamp(width + 2 * kPadding, kMinWidth, kMaxWidth);
|
||||
|
||||
// How high is the error string?
|
||||
int32_t numLines{};
|
||||
GfxWrapString(buffer, width + 1, FontStyle::Medium, &buffer, &numLines);
|
||||
int32_t height = (numLines + 1) * FontGetLineHeight(FontStyle::Medium) + (2 * kPadding);
|
||||
|
||||
width = width + 3;
|
||||
int32_t height = (numLines + 1) * FontGetLineHeight(FontStyle::Medium) + 4;
|
||||
int32_t screenWidth = ContextGetWidth();
|
||||
int32_t screenHeight = ContextGetHeight();
|
||||
// Position error message around the cursor
|
||||
const CursorState* state = ContextGetCursorState();
|
||||
ScreenCoordsXY windowPosition = state->position - ScreenCoordsXY(width / 2, -26);
|
||||
windowPosition.x = std::clamp(windowPosition.x, 0, screenWidth);
|
||||
windowPosition.y = std::max(22, windowPosition.y);
|
||||
int32_t maxY = screenHeight - height;
|
||||
if (windowPosition.y > maxY)
|
||||
{
|
||||
windowPosition.y = std::min(windowPosition.y - height - 40, maxY);
|
||||
}
|
||||
windowPosition.x = std::clamp(windowPosition.x, 0, ContextGetWidth() - width - 40);
|
||||
windowPosition.y = std::clamp(windowPosition.y, 22, ContextGetHeight() - height - 40);
|
||||
|
||||
auto errorWindow = std::make_unique<ErrorWindow>(std::move(buffer), numLines, autoClose);
|
||||
return WindowCreate(
|
||||
std::move(errorWindow), WindowClass::Error, windowPosition, width, height,
|
||||
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_RESIZABLE);
|
||||
std::move(errorWindow), WindowClass::Error, windowPosition, width, height, WF_STICK_TO_FRONT | WF_TRANSPARENT);
|
||||
}
|
||||
|
||||
WindowBase* ErrorOpen(StringId title, StringId message, const Formatter& args, bool autoClose)
|
||||
|
||||
Reference in New Issue
Block a user