| 86 | } |
| 87 | |
| 88 | static void createErrorWindow(StringId title, StringId message, bool suppressErrorSound) |
| 89 | { |
| 90 | WindowManager::close(WindowType::error); |
| 91 | |
| 92 | char* buffer = _errorText; |
| 93 | |
| 94 | auto args = FormatArguments::common(); |
| 95 | |
| 96 | buffer = formatErrorString(title, message, args, buffer); |
| 97 | |
| 98 | if (buffer != &_errorText[0]) |
| 99 | { |
| 100 | // How wide is the error string? |
| 101 | uint16_t strWidth = Gfx::TextRenderer::getStringWidthNewLined(Gfx::Font::medium_bold, &_errorText[0]); |
| 102 | strWidth = std::clamp<uint16_t>(strWidth, kMinWidth, kMaxWidth); |
| 103 | |
| 104 | // How many linebreaks? |
| 105 | { |
| 106 | uint16_t breakLineCount = 0; |
| 107 | std::tie(strWidth, breakLineCount) = Gfx::TextRenderer::wrapString(Gfx::Font::medium_bold, &_errorText[0], strWidth + kPadding); |
| 108 | _linebreakCount = breakLineCount; |
| 109 | } |
| 110 | |
| 111 | // Calculate window dimensions |
| 112 | uint16_t width = strWidth + 2 * kPadding; |
| 113 | uint16_t height = (_linebreakCount + 1) * 10 + 2 * kPadding; |
| 114 | |
| 115 | // Add extra spacing for competitor image |
| 116 | if (_errorCompetitorId != CompanyId::null) |
| 117 | { |
| 118 | width += kCompetitorSize + 22; |
| 119 | height += kCompetitorSize - 22; |
| 120 | } |
| 121 | |
| 122 | // Calculate frame size |
| 123 | uint16_t frameWidth = width - 1; |
| 124 | uint16_t frameHeight = height - 1; |
| 125 | |
| 126 | // Position error message around the cursor |
| 127 | auto mousePos = Input::getMouseLocation(); |
| 128 | Ui::Point windowPosition = Ui::Point{ mousePos.x, mousePos.y } + Ui::Point(-width / 2, 26); |
| 129 | windowPosition.x = std::clamp<int32_t>(windowPosition.x, 0, Ui::width() - width - 40); |
| 130 | windowPosition.y = std::clamp<int32_t>(windowPosition.y, 22, Ui::height() - height - 40); |
| 131 | |
| 132 | auto error = WindowManager::createWindow( |
| 133 | WindowType::error, |
| 134 | windowPosition, |
| 135 | { width, height }, |
| 136 | WindowFlags::stickToFront | WindowFlags::transparent | WindowFlags::ignoreInFindAt, |
| 137 | Common::getEvents()); |
| 138 | |
| 139 | if (_errorCompetitorId != CompanyId::null) |
| 140 | { |
| 141 | error->setWidgets(ErrorCompetitor::widgets); |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | error->setWidgets(Error::widgets); |
no test coverage detected