2016-05-04 19:24:41 +02:00
|
|
|
/*****************************************************************************
|
2023-01-01 04:58:01 -06:00
|
|
|
* Copyright (c) 2014-2023 OpenRCT2 developers
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
#include "Chat.h"
|
|
|
|
|
|
2017-03-25 17:42:14 +00:00
|
|
|
#include "../Context.h"
|
2018-06-22 22:59:46 +02:00
|
|
|
#include "../audio/AudioMixer.h"
|
|
|
|
|
#include "../audio/audio.h"
|
2018-03-19 23:28:40 +01:00
|
|
|
#include "../drawing/Drawing.h"
|
2021-12-11 18:06:06 -05:00
|
|
|
#include "../localisation/Formatter.h"
|
2020-12-05 13:23:21 +00:00
|
|
|
#include "../localisation/Formatting.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Localisation.h"
|
2015-07-18 17:57:42 -06:00
|
|
|
#include "../network/network.h"
|
2022-02-18 21:57:00 +01:00
|
|
|
#include "../platform/Platform.h"
|
2017-12-13 13:02:24 +01:00
|
|
|
#include "../util/Util.h"
|
2020-07-06 10:10:39 -03:00
|
|
|
#include "../world/Location.hpp"
|
2018-06-22 22:59:46 +02:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
2018-01-05 23:00:39 +00:00
|
|
|
|
2020-12-05 13:23:21 +00:00
|
|
|
using namespace OpenRCT2;
|
2022-06-27 17:41:53 +01:00
|
|
|
using namespace OpenRCT2::Audio;
|
2020-12-05 13:23:21 +00:00
|
|
|
|
2015-07-18 17:57:42 -06:00
|
|
|
bool gChatOpen = false;
|
2023-02-20 20:23:16 +02:00
|
|
|
static u8string _chatCurrentLine;
|
|
|
|
|
static std::deque<u8string> _chatHistory;
|
|
|
|
|
static std::deque<uint32_t> _chatHistoryTime;
|
2018-06-20 17:28:51 +02:00
|
|
|
static uint32_t _chatHistoryIndex = 0;
|
|
|
|
|
static uint32_t _chatCaretTicks = 0;
|
|
|
|
|
static int32_t _chatLeft;
|
|
|
|
|
static int32_t _chatTop;
|
|
|
|
|
static int32_t _chatRight;
|
|
|
|
|
static int32_t _chatBottom;
|
|
|
|
|
static int32_t _chatWidth;
|
|
|
|
|
static int32_t _chatHeight;
|
2018-06-22 22:59:46 +02:00
|
|
|
static TextInputSession* _chatTextInputSession;
|
2015-07-18 17:57:42 -06:00
|
|
|
|
2023-02-20 20:23:16 +02:00
|
|
|
static const u8string& ChatGetHistory(size_t index);
|
|
|
|
|
static uint32_t ChatHistoryGetTime(size_t index);
|
2023-01-16 21:14:50 +01:00
|
|
|
static void ChatClearInput();
|
2023-01-19 08:16:44 +00:00
|
|
|
static int32_t ChatHistoryDrawString(DrawPixelInfo* dpi, const char* text, const ScreenCoordsXY& screenCoords, int32_t width);
|
2015-07-18 17:57:42 -06:00
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
bool ChatAvailable()
|
2019-02-03 23:30:34 +01:00
|
|
|
{
|
2023-01-18 07:05:53 +01:00
|
|
|
return NetworkGetMode() != NETWORK_MODE_NONE && NetworkGetStatus() == NETWORK_STATUS_CONNECTED
|
|
|
|
|
&& NetworkGetAuthstatus() == NetworkAuth::Ok;
|
2019-02-03 23:30:34 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
void ChatOpen()
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gChatOpen = true;
|
2023-02-20 20:23:16 +02:00
|
|
|
_chatTextInputSession = ContextStartTextInput(_chatCurrentLine, CHAT_MAX_MESSAGE_LENGTH);
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
void ChatClose()
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gChatOpen = false;
|
2022-11-06 20:49:07 +00:00
|
|
|
ContextStopTextInput();
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
void ChatToggle()
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2018-06-22 22:59:46 +02:00
|
|
|
if (gChatOpen)
|
|
|
|
|
{
|
2023-01-16 21:14:50 +01:00
|
|
|
ChatClose();
|
2018-06-22 22:59:46 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-01-16 21:14:50 +01:00
|
|
|
ChatOpen();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
void ChatInit()
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2023-02-20 20:23:16 +02:00
|
|
|
_chatHistory.clear();
|
|
|
|
|
_chatHistoryTime.clear();
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
void ChatUpdate()
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Flash the caret
|
|
|
|
|
_chatCaretTicks = (_chatCaretTicks + 1) % 30;
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 08:16:44 +00:00
|
|
|
void ChatDraw(DrawPixelInfo* dpi, uint8_t chatBackgroundColor)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2020-10-13 23:34:18 +01:00
|
|
|
thread_local std::string lineBuffer;
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
if (!ChatAvailable())
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gChatOpen = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatLeft = 10;
|
2022-11-06 20:49:07 +00:00
|
|
|
_chatRight = std::min((ContextGetWidth() - 10), CHAT_MAX_WINDOW_WIDTH);
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatWidth = _chatRight - _chatLeft;
|
2022-11-06 20:49:07 +00:00
|
|
|
_chatBottom = ContextGetHeight() - 45;
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatTop = _chatBottom - 10;
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2023-02-20 20:23:16 +02:00
|
|
|
const char* inputLine = _chatCurrentLine.c_str();
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t inputLineHeight = 10;
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Draw chat window
|
2018-06-22 22:59:46 +02:00
|
|
|
if (gChatOpen)
|
|
|
|
|
{
|
2023-02-13 22:02:40 +01:00
|
|
|
inputLineHeight = ChatStringWrappedGetHeight(inputLine, _chatWidth - 10);
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatTop -= inputLineHeight;
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2023-02-20 20:23:16 +02:00
|
|
|
for (const auto& entry : _chatHistory)
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2023-02-20 20:23:16 +02:00
|
|
|
if (entry.empty())
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-02-20 20:23:16 +02:00
|
|
|
lineBuffer = entry;
|
2023-02-13 22:02:40 +01:00
|
|
|
int32_t lineHeight = ChatStringWrappedGetHeight(lineBuffer, _chatWidth - 10);
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatTop -= (lineHeight + 5);
|
|
|
|
|
}
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatHeight = _chatBottom - _chatTop;
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
if (_chatTop < 50)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatTop = 50;
|
2018-06-22 22:59:46 +02:00
|
|
|
}
|
|
|
|
|
else if (_chatHeight < 150)
|
|
|
|
|
{ // Min height
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatTop = _chatBottom - 150;
|
|
|
|
|
_chatHeight = 150;
|
|
|
|
|
}
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2020-09-15 23:02:22 -04:00
|
|
|
ScreenCoordsXY topLeft{ _chatLeft, _chatTop };
|
|
|
|
|
ScreenCoordsXY bottomRight{ _chatRight, _chatBottom };
|
|
|
|
|
ScreenCoordsXY bottomLeft{ _chatLeft, _chatBottom };
|
2023-01-16 13:50:43 +00:00
|
|
|
GfxSetDirtyBlocks(
|
2020-09-15 23:02:22 -04:00
|
|
|
{ topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } }); // Background area + Textbox
|
2023-01-16 13:50:43 +00:00
|
|
|
GfxFilterRect(
|
2020-09-15 23:02:22 -04:00
|
|
|
dpi, { topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } },
|
2021-11-13 23:38:04 +01:00
|
|
|
FilterPaletteID::Palette51); // Opaque grey background
|
2023-01-16 13:50:43 +00:00
|
|
|
GfxFillRectInset(
|
2020-09-15 23:02:22 -04:00
|
|
|
dpi, { topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } }, chatBackgroundColor,
|
|
|
|
|
INSET_RECT_FLAG_FILL_NONE);
|
2023-01-16 13:50:43 +00:00
|
|
|
GfxFillRectInset(
|
2020-09-15 23:02:22 -04:00
|
|
|
dpi, { topLeft + ScreenCoordsXY{ 1, -4 }, bottomRight - ScreenCoordsXY{ 1, inputLineHeight + 6 } },
|
|
|
|
|
chatBackgroundColor, INSET_RECT_FLAG_BORDER_INSET);
|
2023-01-16 13:50:43 +00:00
|
|
|
GfxFillRectInset(
|
2020-09-15 23:02:22 -04:00
|
|
|
dpi, { bottomLeft + ScreenCoordsXY{ 1, -inputLineHeight - 5 }, bottomRight + ScreenCoordsXY{ -1, 4 } },
|
|
|
|
|
chatBackgroundColor,
|
2018-06-22 22:59:46 +02:00
|
|
|
INSET_RECT_FLAG_BORDER_INSET); // Textbox
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2020-06-21 11:25:31 +02:00
|
|
|
auto screenCoords = ScreenCoordsXY{ _chatLeft + 5, _chatBottom - inputLineHeight - 20 };
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t stringHeight = 0;
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Draw chat history
|
2023-02-20 20:23:16 +02:00
|
|
|
for (size_t i = 0; i < CHAT_HISTORY_SIZE; i++, screenCoords.y -= stringHeight)
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2023-02-20 20:23:16 +02:00
|
|
|
if (i >= _chatHistory.size())
|
|
|
|
|
break;
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
uint32_t expireTime = ChatHistoryGetTime(i) + 10000;
|
2022-02-18 21:57:00 +01:00
|
|
|
if (!gChatOpen && Platform::GetTicks() > expireTime)
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2023-02-20 20:23:16 +02:00
|
|
|
lineBuffer = ChatGetHistory(i);
|
2020-10-13 23:34:18 +01:00
|
|
|
auto lineCh = lineBuffer.c_str();
|
2023-01-16 21:14:50 +01:00
|
|
|
stringHeight = ChatHistoryDrawString(dpi, lineCh, screenCoords, _chatWidth - 10) + 5;
|
2023-01-16 13:50:43 +00:00
|
|
|
GfxSetDirtyBlocks(
|
2020-07-08 12:16:24 -04:00
|
|
|
{ { screenCoords - ScreenCoordsXY{ 0, stringHeight } }, { screenCoords + ScreenCoordsXY{ _chatWidth, 20 } } });
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2020-06-21 11:25:31 +02:00
|
|
|
if ((screenCoords.y - stringHeight) < 50)
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Draw current chat input
|
2018-06-22 22:59:46 +02:00
|
|
|
if (gChatOpen)
|
|
|
|
|
{
|
2020-10-13 23:34:18 +01:00
|
|
|
lineBuffer.assign("{OUTLINE}{CELADON}");
|
|
|
|
|
lineBuffer += _chatCurrentLine;
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2020-06-21 11:25:31 +02:00
|
|
|
screenCoords.y = _chatBottom - inputLineHeight - 5;
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2020-10-13 23:34:18 +01:00
|
|
|
auto lineCh = lineBuffer.c_str();
|
2021-08-21 09:42:05 +02:00
|
|
|
auto ft = Formatter();
|
|
|
|
|
ft.Add<const char*>(lineCh);
|
2021-02-27 17:17:17 +01:00
|
|
|
inputLineHeight = DrawTextWrapped(
|
2021-08-21 09:42:05 +02:00
|
|
|
dpi, screenCoords + ScreenCoordsXY{ 0, 3 }, _chatWidth - 10, STR_STRING, ft, { TEXT_COLOUR_255 });
|
2023-01-16 13:50:43 +00:00
|
|
|
GfxSetDirtyBlocks({ screenCoords, { screenCoords + ScreenCoordsXY{ _chatWidth, inputLineHeight + 15 } } });
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// TODO: Show caret if the input text has multiple lines
|
2023-01-16 18:52:17 +00:00
|
|
|
if (_chatCaretTicks < 15 && GfxGetStringWidth(lineBuffer, FontStyle::Medium) < (_chatWidth - 10))
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2023-02-20 20:23:16 +02:00
|
|
|
lineBuffer.assign(_chatCurrentLine.c_str(), _chatTextInputSession->SelectionStart);
|
2023-01-16 18:52:17 +00:00
|
|
|
int32_t caretX = screenCoords.x + GfxGetStringWidth(lineBuffer, FontStyle::Medium);
|
2020-06-21 11:25:31 +02:00
|
|
|
int32_t caretY = screenCoords.y + 14;
|
2015-07-18 17:57:42 -06:00
|
|
|
|
2023-01-16 13:50:43 +00:00
|
|
|
GfxFillRect(dpi, { { caretX, caretY }, { caretX + 6, caretY + 1 } }, PALETTE_INDEX_56);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
void ChatAddHistory(std::string_view s)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2020-10-13 23:34:18 +01:00
|
|
|
// Format a timestamp
|
|
|
|
|
time_t timer{};
|
2017-06-08 19:14:01 +01:00
|
|
|
time(&timer);
|
2020-10-13 23:34:18 +01:00
|
|
|
auto tmInfo = localtime(&timer);
|
|
|
|
|
char timeBuffer[64]{};
|
2023-01-18 23:37:39 +01:00
|
|
|
StrCatFTime(timeBuffer, sizeof(timeBuffer), "[%H:%M] ", tmInfo);
|
2017-06-08 19:14:01 +01:00
|
|
|
|
2020-10-13 23:34:18 +01:00
|
|
|
std::string buffer = timeBuffer;
|
2021-09-17 23:46:58 +03:00
|
|
|
buffer += s;
|
2017-06-08 19:14:01 +01:00
|
|
|
|
2023-02-20 20:23:16 +02:00
|
|
|
if (_chatHistory.size() >= CHAT_HISTORY_SIZE)
|
|
|
|
|
{
|
|
|
|
|
_chatHistory.pop_front();
|
|
|
|
|
_chatHistoryTime.pop_front();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_chatHistory.push_back(buffer);
|
|
|
|
|
_chatHistoryTime.push_back(Platform::GetTicks());
|
2017-06-08 19:14:01 +01:00
|
|
|
|
|
|
|
|
// Log to file (src only as logging does its own timestamp)
|
2023-01-18 07:05:53 +01:00
|
|
|
NetworkAppendChatLog(s);
|
2017-06-08 19:14:01 +01:00
|
|
|
|
2022-06-27 17:41:53 +01:00
|
|
|
CreateAudioChannel(SoundId::NewsItem, 0, MIXER_VOLUME_MAX, 0.5f, 1.5f, true);
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
void ChatInput(enum ChatInput input)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2018-06-22 22:59:46 +02:00
|
|
|
switch (input)
|
|
|
|
|
{
|
2020-10-07 01:37:08 +01:00
|
|
|
case ChatInput::Send:
|
2023-02-20 20:23:16 +02:00
|
|
|
if (!_chatCurrentLine.empty())
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2023-02-20 20:23:16 +02:00
|
|
|
NetworkSendChat(_chatCurrentLine.c_str());
|
2018-06-22 22:59:46 +02:00
|
|
|
}
|
2023-01-16 21:14:50 +01:00
|
|
|
ChatClearInput();
|
|
|
|
|
ChatClose();
|
2018-06-22 22:59:46 +02:00
|
|
|
break;
|
2020-10-07 01:37:08 +01:00
|
|
|
case ChatInput::Close:
|
2023-01-16 21:14:50 +01:00
|
|
|
ChatClose();
|
2018-06-22 22:59:46 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-02-20 20:23:16 +02:00
|
|
|
static const u8string& ChatGetHistory(size_t index)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2023-02-20 20:23:16 +02:00
|
|
|
return _chatHistory[index];
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-02-20 20:23:16 +02:00
|
|
|
static uint32_t ChatHistoryGetTime(size_t index)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2023-02-20 20:23:16 +02:00
|
|
|
return _chatHistoryTime[index];
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
static void ChatClearInput()
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2023-02-20 20:23:16 +02:00
|
|
|
_chatCurrentLine.clear();
|
2015-10-30 15:18:29 +01:00
|
|
|
}
|
2016-06-22 12:10:24 -05:00
|
|
|
|
|
|
|
|
// This method is the same as gfx_draw_string_left_wrapped.
|
|
|
|
|
// But this adjusts the initial Y coordinate depending of the number of lines.
|
2023-01-19 08:16:44 +00:00
|
|
|
static int32_t ChatHistoryDrawString(DrawPixelInfo* dpi, const char* text, const ScreenCoordsXY& screenCoords, int32_t width)
|
2016-06-22 12:10:24 -05:00
|
|
|
{
|
2021-02-27 12:40:20 +01:00
|
|
|
int32_t numLines;
|
2023-02-13 22:02:40 +01:00
|
|
|
u8string wrappedString;
|
|
|
|
|
GfxWrapString(FormatString("{OUTLINE}{WHITE}{STRING}", text), width, FontStyle::Medium, &wrappedString, &numLines);
|
2023-01-16 22:31:34 +00:00
|
|
|
auto lineHeight = FontGetLineHeight(FontStyle::Medium);
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2019-10-18 12:57:31 -03:00
|
|
|
int32_t expectedY = screenCoords.y - (numLines * lineHeight);
|
2018-06-22 22:59:46 +02:00
|
|
|
if (expectedY < 50)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return (numLines * lineHeight); // Skip drawing, return total height.
|
|
|
|
|
}
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2023-02-13 22:02:40 +01:00
|
|
|
const utf8* bufferPtr = wrappedString.data();
|
|
|
|
|
int32_t lineY = screenCoords.y;
|
2018-06-22 22:59:46 +02:00
|
|
|
for (int32_t line = 0; line <= numLines; ++line)
|
|
|
|
|
{
|
2023-01-16 18:52:17 +00:00
|
|
|
GfxDrawString(dpi, { screenCoords.x, lineY - (numLines * lineHeight) }, bufferPtr, { TEXT_COLOUR_254 });
|
2023-01-17 00:12:35 +01:00
|
|
|
bufferPtr = GetStringEnd(bufferPtr) + 1;
|
2017-06-06 23:24:18 +02:00
|
|
|
lineY += lineHeight;
|
|
|
|
|
}
|
2019-10-18 12:57:31 -03:00
|
|
|
return lineY - screenCoords.y;
|
2016-06-22 12:10:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wrap string without drawing, useful to get the height of a wrapped string.
|
|
|
|
|
// Almost the same as gfx_draw_string_left_wrapped
|
2023-02-13 22:02:40 +01:00
|
|
|
int32_t ChatStringWrappedGetHeight(u8string_view args, int32_t width)
|
2016-06-22 12:10:24 -05:00
|
|
|
{
|
2021-02-28 00:22:24 +01:00
|
|
|
int32_t numLines;
|
2023-02-13 22:02:40 +01:00
|
|
|
GfxWrapString(FormatStringID(STR_STRING, args), width, FontStyle::Medium, nullptr, &numLines);
|
|
|
|
|
const int32_t lineHeight = FontGetLineHeight(FontStyle::Medium);
|
|
|
|
|
return lineHeight * numLines;
|
2016-06-22 12:10:24 -05:00
|
|
|
}
|