|
|
|
|
@ -19,7 +19,36 @@ namespace devilution {
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
std::deque<std::string> DiabloMessages; |
|
|
|
|
std::vector<std::string> TextLines; |
|
|
|
|
uint32_t msgdelay; |
|
|
|
|
int ErrorWindowHeight = 54; |
|
|
|
|
const int LineHeight = 12; |
|
|
|
|
const int LineWidth = 418; |
|
|
|
|
|
|
|
|
|
void InitNextLines() |
|
|
|
|
{ |
|
|
|
|
msgdelay = SDL_GetTicks(); |
|
|
|
|
auto message = DiabloMessages.front(); |
|
|
|
|
|
|
|
|
|
TextLines.clear(); |
|
|
|
|
|
|
|
|
|
char tempstr[1536]; // Longest test is about 768 chars * 2 for unicode
|
|
|
|
|
strcpy(tempstr, message.data()); |
|
|
|
|
|
|
|
|
|
WordWrapGameString(tempstr, LineWidth, GameFontSmall, 1); |
|
|
|
|
const string_view paragraphs = tempstr; |
|
|
|
|
|
|
|
|
|
size_t previous = 0; |
|
|
|
|
while (true) { |
|
|
|
|
size_t next = paragraphs.find('\n', previous); |
|
|
|
|
TextLines.emplace_back(paragraphs.substr(previous, next)); |
|
|
|
|
if (next == std::string::npos) |
|
|
|
|
break; |
|
|
|
|
previous = next + 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ErrorWindowHeight = std::max(54, static_cast<int>((TextLines.size() * LineHeight) + 42)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
@ -85,7 +114,11 @@ const char *const MsgStrings[] = {
|
|
|
|
|
void InitDiabloMsg(diablo_message e) |
|
|
|
|
{ |
|
|
|
|
std::string msg = _(MsgStrings[e]); |
|
|
|
|
InitDiabloMsg(msg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void InitDiabloMsg(std::string msg) |
|
|
|
|
{ |
|
|
|
|
if (DiabloMessages.size() >= MAX_SEND_STR_LEN) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
@ -93,7 +126,8 @@ void InitDiabloMsg(diablo_message e)
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
DiabloMessages.push_back(msg); |
|
|
|
|
msgdelay = SDL_GetTicks(); |
|
|
|
|
if (DiabloMessages.size() == 1) |
|
|
|
|
InitNextLines(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsDiabloMsgAvailable() |
|
|
|
|
@ -111,41 +145,44 @@ void ClrDiabloMsg()
|
|
|
|
|
DiabloMessages.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define DIALOG_Y ((gnScreenHeight - PANEL_HEIGHT) / 2 - 18) |
|
|
|
|
|
|
|
|
|
void DrawDiabloMsg(const Surface &out) |
|
|
|
|
{ |
|
|
|
|
CelDrawTo(out, { PANEL_X + 101, DIALOG_Y }, *pSTextSlidCels, 1); |
|
|
|
|
CelDrawTo(out, { PANEL_X + 527, DIALOG_Y }, *pSTextSlidCels, 4); |
|
|
|
|
CelDrawTo(out, { PANEL_X + 101, DIALOG_Y + 48 }, *pSTextSlidCels, 2); |
|
|
|
|
CelDrawTo(out, { PANEL_X + 527, DIALOG_Y + 48 }, *pSTextSlidCels, 3); |
|
|
|
|
int dialogStartY = ((gnScreenHeight - PANEL_HEIGHT) / 2) - (ErrorWindowHeight / 2) + 9; |
|
|
|
|
|
|
|
|
|
CelDrawTo(out, { PANEL_X + 101, dialogStartY }, *pSTextSlidCels, 1); |
|
|
|
|
CelDrawTo(out, { PANEL_X + 527, dialogStartY }, *pSTextSlidCels, 4); |
|
|
|
|
CelDrawTo(out, { PANEL_X + 101, dialogStartY + ErrorWindowHeight - 6 }, *pSTextSlidCels, 2); |
|
|
|
|
CelDrawTo(out, { PANEL_X + 527, dialogStartY + ErrorWindowHeight - 6 }, *pSTextSlidCels, 3); |
|
|
|
|
|
|
|
|
|
int sx = PANEL_X + 109; |
|
|
|
|
for (int i = 0; i < 35; i++) { |
|
|
|
|
CelDrawTo(out, { sx, DIALOG_Y }, *pSTextSlidCels, 5); |
|
|
|
|
CelDrawTo(out, { sx, DIALOG_Y + 48 }, *pSTextSlidCels, 7); |
|
|
|
|
CelDrawTo(out, { sx, dialogStartY }, *pSTextSlidCels, 5); |
|
|
|
|
CelDrawTo(out, { sx, dialogStartY + ErrorWindowHeight - 6 }, *pSTextSlidCels, 7); |
|
|
|
|
sx += 12; |
|
|
|
|
} |
|
|
|
|
int sy = DIALOG_Y + 12; |
|
|
|
|
for (int i = 0; i < 3; i++) { |
|
|
|
|
CelDrawTo(out, { PANEL_X + 101, sy }, *pSTextSlidCels, 6); |
|
|
|
|
CelDrawTo(out, { PANEL_X + 527, sy }, *pSTextSlidCels, 8); |
|
|
|
|
sy += 12; |
|
|
|
|
int drawnYborder = 12; |
|
|
|
|
while ((drawnYborder + 12) < ErrorWindowHeight) { |
|
|
|
|
CelDrawTo(out, { PANEL_X + 101, dialogStartY + drawnYborder }, *pSTextSlidCels, 6); |
|
|
|
|
CelDrawTo(out, { PANEL_X + 527, dialogStartY + drawnYborder }, *pSTextSlidCels, 8); |
|
|
|
|
drawnYborder += 12; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DrawHalfTransparentRectTo(out, PANEL_X + 104, DIALOG_Y - 8, 432, 54); |
|
|
|
|
DrawHalfTransparentRectTo(out, PANEL_X + 104, dialogStartY - 8, 432, ErrorWindowHeight); |
|
|
|
|
|
|
|
|
|
auto message = DiabloMessages.front(); |
|
|
|
|
DrawString(out, message, { { PANEL_X + 101, DIALOG_Y + 24 }, { 442, 0 } }, UiFlags::AlignCenter); |
|
|
|
|
int lineNumber = 0; |
|
|
|
|
for (auto &line : TextLines) { |
|
|
|
|
DrawString(out, line.c_str(), { { PANEL_X + 109, dialogStartY + 24 + lineNumber * LineHeight }, { LineWidth, LineHeight } }, UiFlags::AlignCenter, 1, LineHeight); |
|
|
|
|
lineNumber += 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (msgdelay > 0 && msgdelay <= SDL_GetTicks() - 3500) { |
|
|
|
|
msgdelay = 0; |
|
|
|
|
} |
|
|
|
|
if (msgdelay == 0) { |
|
|
|
|
DiabloMessages.pop_front(); |
|
|
|
|
if (!DiabloMessages.empty()) { |
|
|
|
|
msgdelay = SDL_GetTicks(); |
|
|
|
|
} |
|
|
|
|
if (!DiabloMessages.empty()) |
|
|
|
|
InitNextLines(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|