2016-05-04 19:24:41 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 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"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Localisation.h"
|
2015-07-18 17:57:42 -06:00
|
|
|
#include "../network/network.h"
|
|
|
|
|
#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
|
|
|
|
2015-07-18 17:57:42 -06:00
|
|
|
bool gChatOpen = false;
|
2017-03-26 03:36:22 +01:00
|
|
|
static char _chatCurrentLine[CHAT_MAX_MESSAGE_LENGTH];
|
|
|
|
|
static char _chatHistory[CHAT_HISTORY_SIZE][CHAT_INPUT_SIZE];
|
2018-06-20 17:28:51 +02:00
|
|
|
static uint32_t _chatHistoryTime[CHAT_HISTORY_SIZE];
|
|
|
|
|
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
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
static const char* chat_history_get(uint32_t index);
|
|
|
|
|
static uint32_t chat_history_get_time(uint32_t index);
|
2015-07-18 17:57:42 -06:00
|
|
|
static void chat_clear_input();
|
|
|
|
|
|
2019-02-03 23:30:34 +01:00
|
|
|
bool chat_available()
|
|
|
|
|
{
|
|
|
|
|
return network_get_mode() != NETWORK_MODE_NONE && network_get_status() == NETWORK_STATUS_CONNECTED
|
2020-09-04 15:40:12 -03:00
|
|
|
&& network_get_authstatus() == NetworkAuth::Ok;
|
2019-02-03 23:30:34 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-18 17:57:42 -06:00
|
|
|
void chat_open()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gChatOpen = true;
|
|
|
|
|
_chatTextInputSession = context_start_text_input(_chatCurrentLine, sizeof(_chatCurrentLine));
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void chat_close()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gChatOpen = false;
|
|
|
|
|
context_stop_text_input();
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void chat_toggle()
|
|
|
|
|
{
|
2018-06-22 22:59:46 +02:00
|
|
|
if (gChatOpen)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
chat_close();
|
2018-06-22 22:59:46 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
chat_open();
|
|
|
|
|
}
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void chat_init()
|
|
|
|
|
{
|
2018-12-15 22:23:31 +01:00
|
|
|
std::memset(_chatHistory, 0x00, sizeof(_chatHistory));
|
|
|
|
|
std::memset(_chatHistoryTime, 0x00, sizeof(_chatHistoryTime));
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void chat_update()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Flash the caret
|
|
|
|
|
_chatCaretTicks = (_chatCaretTicks + 1) % 30;
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2019-02-03 23:30:34 +01:00
|
|
|
if (!chat_available())
|
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;
|
2018-01-05 23:00:39 +00:00
|
|
|
_chatRight = std::min((context_get_width() - 10), CHAT_MAX_WINDOW_WIDTH);
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatWidth = _chatRight - _chatLeft;
|
|
|
|
|
_chatBottom = context_get_height() - 45;
|
|
|
|
|
_chatTop = _chatBottom - 10;
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
char lineBuffer[CHAT_INPUT_SIZE + 10];
|
|
|
|
|
char* lineCh = lineBuffer;
|
|
|
|
|
char* inputLine = _chatCurrentLine;
|
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)
|
|
|
|
|
{
|
2020-06-07 23:18:11 +02:00
|
|
|
inputLineHeight = chat_string_wrapped_get_height(static_cast<void*>(&inputLine), _chatWidth - 10);
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatTop -= inputLineHeight;
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
for (int32_t i = 0; i < CHAT_HISTORY_SIZE; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strlen(chat_history_get(i)) == 0)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
safe_strcpy(lineBuffer, chat_history_get(i), sizeof(lineBuffer));
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2020-06-07 23:18:11 +02:00
|
|
|
int32_t lineHeight = chat_string_wrapped_get_height(static_cast<void*>(&lineCh), _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 };
|
|
|
|
|
gfx_set_dirty_blocks(
|
|
|
|
|
{ topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } }); // Background area + Textbox
|
2020-07-04 14:16:09 -04:00
|
|
|
gfx_filter_rect(
|
2020-09-15 23:02:22 -04:00
|
|
|
dpi, { topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } },
|
|
|
|
|
PALETTE_51); // Opaque gray background
|
2018-06-22 22:59:46 +02:00
|
|
|
gfx_fill_rect_inset(
|
2020-09-15 23:02:22 -04:00
|
|
|
dpi, { topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } }, chatBackgroundColor,
|
|
|
|
|
INSET_RECT_FLAG_FILL_NONE);
|
2018-06-22 22:59:46 +02:00
|
|
|
gfx_fill_rect_inset(
|
2020-09-15 23:02:22 -04:00
|
|
|
dpi, { topLeft + ScreenCoordsXY{ 1, -4 }, bottomRight - ScreenCoordsXY{ 1, inputLineHeight + 6 } },
|
|
|
|
|
chatBackgroundColor, INSET_RECT_FLAG_BORDER_INSET);
|
2018-06-22 22:59:46 +02:00
|
|
|
gfx_fill_rect_inset(
|
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
|
2020-06-21 11:25:31 +02:00
|
|
|
for (int32_t i = 0; i < CHAT_HISTORY_SIZE; i++, screenCoords.y -= stringHeight)
|
2018-06-22 22:59:46 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t expireTime = chat_history_get_time(i) + 10000;
|
2018-06-22 22:59:46 +02:00
|
|
|
if (!gChatOpen && platform_get_ticks() > expireTime)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
safe_strcpy(lineBuffer, chat_history_get(i), sizeof(lineBuffer));
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2020-06-21 11:25:31 +02:00
|
|
|
stringHeight = chat_history_draw_string(dpi, static_cast<void*>(&lineCh), screenCoords, _chatWidth - 10) + 5;
|
2020-07-08 12:16:24 -04:00
|
|
|
gfx_set_dirty_blocks(
|
|
|
|
|
{ { 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)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
lineCh = utf8_write_codepoint(lineCh, FORMAT_OUTLINE);
|
|
|
|
|
lineCh = utf8_write_codepoint(lineCh, FORMAT_CELADON);
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
safe_strcpy(lineCh, _chatCurrentLine, sizeof(_chatCurrentLine));
|
2020-06-21 11:25:31 +02:00
|
|
|
screenCoords.y = _chatBottom - inputLineHeight - 5;
|
2016-06-21 15:58:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
lineCh = lineBuffer;
|
2018-07-21 11:50:45 +02:00
|
|
|
inputLineHeight = gfx_draw_string_left_wrapped(
|
2020-06-21 11:25:31 +02:00
|
|
|
dpi, static_cast<void*>(&lineCh), screenCoords + ScreenCoordsXY{ 0, 3 }, _chatWidth - 10, STR_STRING,
|
|
|
|
|
TEXT_COLOUR_255);
|
2020-07-08 12:16:24 -04:00
|
|
|
gfx_set_dirty_blocks({ 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
|
2018-06-22 22:59:46 +02:00
|
|
|
if (_chatCaretTicks < 15 && gfx_get_string_width(lineBuffer) < (_chatWidth - 10))
|
|
|
|
|
{
|
2018-12-15 22:23:31 +01:00
|
|
|
std::memcpy(lineBuffer, _chatCurrentLine, _chatTextInputSession->SelectionStart);
|
2017-06-06 23:24:18 +02:00
|
|
|
lineBuffer[_chatTextInputSession->SelectionStart] = 0;
|
2020-06-21 11:25:31 +02:00
|
|
|
int32_t caretX = screenCoords.x + gfx_get_string_width(lineBuffer);
|
|
|
|
|
int32_t caretY = screenCoords.y + 14;
|
2015-07-18 17:57:42 -06:00
|
|
|
|
2020-07-08 13:07:26 -04:00
|
|
|
gfx_fill_rect(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
|
|
|
}
|
|
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
void chat_history_add(const char* src)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2017-06-08 19:14:01 +01:00
|
|
|
size_t bufferSize = strlen(src) + 64;
|
2020-04-22 17:09:29 +02:00
|
|
|
utf8* buffer = static_cast<utf8*>(calloc(1, bufferSize));
|
2017-06-08 19:14:01 +01:00
|
|
|
|
2017-06-10 00:53:51 +01:00
|
|
|
// Find the start of the text (after format codes)
|
2018-06-22 22:59:46 +02:00
|
|
|
const char* ch = src;
|
|
|
|
|
const char* nextCh;
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t codepoint;
|
2018-06-22 22:59:46 +02:00
|
|
|
while ((codepoint = utf8_get_next(ch, &nextCh)) != 0)
|
|
|
|
|
{
|
|
|
|
|
if (!utf8_is_format_code(codepoint))
|
|
|
|
|
{
|
2017-06-08 19:14:01 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2017-06-10 00:53:51 +01:00
|
|
|
ch = nextCh;
|
2017-06-08 19:14:01 +01:00
|
|
|
}
|
2018-06-22 22:59:46 +02:00
|
|
|
const char* srcText = ch;
|
2017-06-10 00:53:51 +01:00
|
|
|
|
|
|
|
|
// Copy format codes to buffer
|
2020-04-22 17:09:29 +02:00
|
|
|
std::memcpy(buffer, src, std::min(bufferSize, static_cast<size_t>(srcText - src)));
|
2017-06-08 19:14:01 +01:00
|
|
|
|
|
|
|
|
// Prepend a timestamp
|
|
|
|
|
time_t timer;
|
|
|
|
|
time(&timer);
|
2018-06-22 22:59:46 +02:00
|
|
|
struct tm* tmInfo = localtime(&timer);
|
2017-06-08 19:14:01 +01:00
|
|
|
|
|
|
|
|
strcatftime(buffer, bufferSize, "[%H:%M] ", tmInfo);
|
2017-06-10 00:53:51 +01:00
|
|
|
safe_strcat(buffer, srcText, bufferSize);
|
2017-06-08 19:14:01 +01:00
|
|
|
|
|
|
|
|
// Add to history list
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t index = _chatHistoryIndex % CHAT_HISTORY_SIZE;
|
2018-12-15 22:23:31 +01:00
|
|
|
std::fill_n(_chatHistory[index], CHAT_INPUT_SIZE, 0x00);
|
|
|
|
|
std::memcpy(_chatHistory[index], buffer, std::min<size_t>(strlen(buffer), CHAT_INPUT_SIZE - 1));
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatHistoryTime[index] = platform_get_ticks();
|
|
|
|
|
_chatHistoryIndex++;
|
2017-06-08 19:14:01 +01:00
|
|
|
|
|
|
|
|
// Log to file (src only as logging does its own timestamp)
|
2017-06-06 23:24:18 +02:00
|
|
|
network_append_chat_log(src);
|
2017-06-08 19:14:01 +01:00
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
2019-07-22 19:02:45 +01:00
|
|
|
Mixer_Play_Effect(SoundId::NewsItem, 0, MIXER_VOLUME_MAX, 0.5f, 1.5f, true);
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2017-06-10 16:19:46 +01:00
|
|
|
void chat_input(CHAT_INPUT input)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2018-06-22 22:59:46 +02:00
|
|
|
switch (input)
|
|
|
|
|
{
|
|
|
|
|
case CHAT_INPUT_SEND:
|
|
|
|
|
if (strlen(_chatCurrentLine) > 0)
|
|
|
|
|
{
|
|
|
|
|
network_send_chat(_chatCurrentLine);
|
|
|
|
|
}
|
|
|
|
|
chat_clear_input();
|
|
|
|
|
chat_close();
|
|
|
|
|
break;
|
|
|
|
|
case CHAT_INPUT_CLOSE:
|
|
|
|
|
chat_close();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
static const char* chat_history_get(uint32_t index)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return _chatHistory[(_chatHistoryIndex + CHAT_HISTORY_SIZE - index - 1) % CHAT_HISTORY_SIZE];
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
static uint32_t chat_history_get_time(uint32_t index)
|
2015-07-18 17:57:42 -06:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return _chatHistoryTime[(_chatHistoryIndex + CHAT_HISTORY_SIZE - index - 1) % CHAT_HISTORY_SIZE];
|
2015-07-18 17:57:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void chat_clear_input()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
_chatCurrentLine[0] = 0;
|
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.
|
2020-02-28 23:43:29 -03:00
|
|
|
int32_t chat_history_draw_string(rct_drawpixelinfo* dpi, void* args, const ScreenCoordsXY& screenCoords, int32_t width)
|
2016-06-22 12:10:24 -05:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t fontSpriteBase, lineHeight, lineY, numLines;
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2020-06-07 23:18:11 +02:00
|
|
|
gfx_draw_string(dpi, "", TEXT_COLOUR_255, { dpi->x, dpi->y });
|
2018-06-22 22:59:46 +02:00
|
|
|
char* buffer = gCommonStringFormatBuffer;
|
2017-06-06 23:24:18 +02:00
|
|
|
format_string(buffer, 256, STR_STRING, args);
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
|
|
|
|
gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase);
|
|
|
|
|
lineHeight = font_get_line_height(fontSpriteBase);
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gCurrentFontFlags = 0;
|
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
|
|
|
|
2019-10-18 12:57:31 -03:00
|
|
|
lineY = screenCoords.y;
|
2018-06-22 22:59:46 +02:00
|
|
|
for (int32_t line = 0; line <= numLines; ++line)
|
|
|
|
|
{
|
2020-05-10 14:49:15 +02:00
|
|
|
gfx_draw_string(dpi, buffer, TEXT_COLOUR_254, { screenCoords.x, lineY - (numLines * lineHeight) });
|
2017-06-06 23:24:18 +02:00
|
|
|
buffer = get_string_end(buffer) + 1;
|
|
|
|
|
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
|
2018-06-22 22:59:46 +02:00
|
|
|
int32_t chat_string_wrapped_get_height(void* args, int32_t width)
|
2016-06-22 12:10:24 -05:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t fontSpriteBase, lineHeight, lineY, numLines;
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
char* buffer = gCommonStringFormatBuffer;
|
2017-06-06 23:24:18 +02:00
|
|
|
format_string(buffer, 256, STR_STRING, args);
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
|
|
|
|
gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase);
|
|
|
|
|
lineHeight = font_get_line_height(fontSpriteBase);
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gCurrentFontFlags = 0;
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
lineY = 0;
|
2018-06-22 22:59:46 +02:00
|
|
|
for (int32_t line = 0; line <= numLines; ++line)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
buffer = get_string_end(buffer) + 1;
|
|
|
|
|
lineY += lineHeight;
|
|
|
|
|
}
|
2016-06-22 12:10:24 -05:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
return lineY;
|
2016-06-22 12:10:24 -05:00
|
|
|
}
|