Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 726d3bb

Browse files
authored
Merge pull request #385 from storm-devs/feature/legacy-dialog
Add new LegacyDialog entity
2 parents 421b3e6 + a36b8ba commit 726d3bb

File tree

10 files changed

+863
-70
lines changed

10 files changed

+863
-70
lines changed

src/libs/dialog/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
STORM_SETUP(
22
TARGET_NAME dialog
33
TYPE storm_module
4-
DEPENDENCIES core renderer sound_service
4+
DEPENDENCIES core geometry model renderer sound_service
55
)

src/libs/dialog/src/dialog.cpp

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "dialog.h"
2-
#include "v_sound_service.h"
1+
#include "dialog.hpp"
32
#include "core.h"
43
#include "string_compare.hpp"
4+
#include "v_sound_service.h"
55

66
#include "v_file_service.h"
77

@@ -70,14 +70,15 @@ void DIALOG::DlgTextDescribe::ChangeText(const char *pcText)
7070
memcpy(&pcTmp[n - i], "...", 4 * sizeof(char));
7171
i = n + 2;
7272
n++;
73-
AddToStringArrayLimitedByWidth(pcTmp, nFontID, fScale, nWindowWidth, asText, &anPageEndIndex,
73+
AddToStringArrayLimitedByWidth(pcTmp, nFontID, fScale, nWindowWidth, asText, RenderService, &anPageEndIndex,
7474
nShowQuantity);
7575
if (anPageEndIndex.size() == 0 || anPageEndIndex[anPageEndIndex.size() - 1] != asText.size())
7676
anPageEndIndex.push_back(asText.size());
7777
delete[] pcTmp;
7878
}
7979
}
80-
AddToStringArrayLimitedByWidth(&pcText[i], nFontID, fScale, nWindowWidth, asText, &anPageEndIndex, nShowQuantity);
80+
AddToStringArrayLimitedByWidth(&pcText[i], nFontID, fScale, nWindowWidth, asText, RenderService, &anPageEndIndex,
81+
nShowQuantity);
8182
// if( anPageEndIndex.size()!=0 && anPageEndIndex[anPageEndIndex.size()-1]!=asText.size() )
8283
// anPageEndIndex.Add( asText.size() );
8384
nStartIndex = 0;
@@ -202,7 +203,8 @@ void DIALOG::DlgLinkDescribe::ChangeText(ATTRIBUTES *pALinks)
202203
nEditVarIndex = pA->GetAttributeAsDword("edit", 0);
203204
nEditCharIndex = 0;
204205
}
205-
AddToStringArrayLimitedByWidth(pA->GetThisAttr(), nFontID, fScale, nWindowWidth, asText, nullptr, 100);
206+
AddToStringArrayLimitedByWidth(pA->GetValue(), nFontID, fScale, nWindowWidth, asText, RenderService,
207+
nullptr, 100);
206208
anLineEndIndex.push_back(asText.size());
207209
}
208210
}
@@ -440,8 +442,8 @@ DIALOG::~DIALOG()
440442
void DIALOG::CreateBack()
441443
{
442444
const int32_t nSquareQuantity = 9 + 3 + 1; // 9-for back, 3-for name & 1-for divider
443-
m_nIQntBack = 6 * nSquareQuantity; // 6 indices in one rectangle
444-
m_nVQntBack = 4 * nSquareQuantity; // 4 vertices in one rectangle
445+
m_nIQntBack = 6 * nSquareQuantity; // 6 indices in one rectangle
446+
m_nVQntBack = 4 * nSquareQuantity; // 4 vertices in one rectangle
445447

446448
if (m_idVBufBack == -1)
447449
m_idVBufBack =
@@ -777,77 +779,73 @@ void DIALOG::GetPointFromIni(INIFILE *ini, const char *pcSection, const char *pc
777779
sscanf(param, "%f,%f", &fpoint.x, &fpoint.y);
778780
}
779781

780-
void DIALOG::AddToStringArrayLimitedByWidth(const char *pcSrcText, int32_t nFontID, float fScale, int32_t nLimitWidth,
781-
std::vector<std::string> &asOutTextList, std::vector<int32_t> *panPageIndices,
782+
void DIALOG::AddToStringArrayLimitedByWidth(const std::string_view &text, int32_t nFontID, float fScale,
783+
int32_t nLimitWidth, std::vector<std::string> &asOutTextList,
784+
VDX9RENDER *renderService, std::vector<int32_t> *panPageIndices,
782785
int32_t nPageSize)
783786
{
784-
if (!pcSrcText)
787+
if (text.empty())
785788
return;
786789
if (nLimitWidth < 20)
787790
nLimitWidth = 20;
788791

789-
int32_t n = 0;
790-
char param[1024];
791-
int32_t nCur = 0;
792-
int32_t nPrevIdx = 0;
793-
if (panPageIndices && panPageIndices->size() > 0)
792+
size_t nPrevIdx = 0;
793+
if (panPageIndices && !panPageIndices->empty())
794794
nPrevIdx = panPageIndices->back();
795-
while (true)
795+
796+
size_t current_offset = 0;
797+
std::string_view current_span = text;
798+
for (;;)
796799
{
797-
if ((pcSrcText[nCur] == 0x20 && pcSrcText[nCur + 1] != 0) || pcSrcText[nCur] == 0) // space
800+
const size_t next_space = current_span.find_first_of(" \\", current_offset);
801+
802+
if (next_space != std::string_view::npos)
798803
{
799-
// boal fix space at the end of the line
800-
param[n] = 0;
801-
const int32_t nW = RenderService->StringWidth(param, nFontID, fScale);
802-
if (nW < nLimitWidth && pcSrcText[nCur] != 0)
803-
{
804-
// have not yet exceeded the width limit
805-
param[n++] = 0x20;
806-
}
807-
else
804+
const std::string_view text_section = current_span.substr(0, next_space);
805+
const int32_t nW = renderService->StringWidth(text_section, nFontID, fScale);
806+
if (nW > nLimitWidth)
808807
{
809-
if (nW > nLimitWidth)
808+
const size_t last_space = text_section.find_last_of(" \\");
809+
asOutTextList.emplace_back(text_section.substr(0, last_space));
810+
811+
if (current_span[last_space] == '\\' && current_span.size() > last_space + 1 &&
812+
current_span[last_space + 1] == 'n')
810813
{
811-
// find prev space;
812-
int32_t nPrev = nCur;
813-
while (nPrev > 0 && pcSrcText[nPrev - 1] != 0x20)
814-
nPrev--;
815-
if (nPrev <= 0) // no spaces
816-
{
817-
// looking for the first character set in the range
818-
while (n > 0 && RenderService->StringWidth(param, nFontID, fScale) > nLimitWidth)
819-
{
820-
int dec = utf8::u8_dec(param + n);
821-
n -= dec;
822-
nCur -= dec;
823-
param[n] = 0;
824-
}
825-
}
826-
else
827-
{
828-
n -= nCur - nPrev;
829-
Assert(n > 0);
830-
param[n] = 0;
831-
nCur = nPrev;
832-
}
814+
current_span = current_span.substr(last_space);
815+
current_offset = 0;
833816
}
834-
asOutTextList.push_back(param);
835-
n = 0;
836-
837-
if (panPageIndices && asOutTextList.size() - nPrevIdx == nPageSize)
817+
else
838818
{
839-
nPrevIdx = asOutTextList.size();
840-
panPageIndices->push_back(nPrevIdx);
819+
current_span = current_span.substr(last_space + 1u);
820+
current_offset = 0;
841821
}
842822
}
843-
while (pcSrcText[nCur] == 0x20 && pcSrcText[nCur + 1] != 0)
844-
nCur++; // boal fix
845-
if (pcSrcText[nCur] == 0)
846-
break;
823+
else if (current_span[next_space] == '\\' && current_span.size() > next_space + 1 &&
824+
current_span[next_space + 1] == 'n')
825+
{
826+
asOutTextList.emplace_back(text_section.substr(0, next_space));
827+
current_span = current_span.substr(next_space + 2u);
828+
current_offset = 0;
829+
}
830+
else
831+
{
832+
current_offset = next_space + 1;
833+
}
847834
}
848835
else
849836
{
850-
param[n++] = pcSrcText[nCur++];
837+
asOutTextList.emplace_back(current_span);
838+
}
839+
840+
if (panPageIndices && asOutTextList.size() - nPrevIdx == nPageSize)
841+
{
842+
nPrevIdx = asOutTextList.size();
843+
panPageIndices->push_back(static_cast<long>(nPrevIdx));
844+
}
845+
846+
if (next_space == std::string_view::npos)
847+
{
848+
break;
851849
}
852850
}
853851
}
@@ -972,7 +970,8 @@ void DIALOG::Realize(uint32_t Delta_Time)
972970
{
973971
if (m_DlgLinks.nSelectLine > 0)
974972
m_DlgLinks.nSelectLine--;
975-
const int32_t nTmp = (m_DlgLinks.nSelectLine > 0) ? m_DlgLinks.anLineEndIndex[m_DlgLinks.nSelectLine - 1] : 0;
973+
const int32_t nTmp =
974+
(m_DlgLinks.nSelectLine > 0) ? m_DlgLinks.anLineEndIndex[m_DlgLinks.nSelectLine - 1] : 0;
976975
if (m_DlgLinks.nStartIndex > nTmp)
977976
{
978977
m_DlgLinks.nStartIndex = nTmp;
@@ -1048,7 +1047,7 @@ void DIALOG::Realize(uint32_t Delta_Time)
10481047
pA = pA->GetAttributeClass(m_DlgLinks.nSelectLine);
10491048
if (pA)
10501049
{
1051-
const char* goName = pA->GetAttribute("go");
1050+
const char *goName = pA->GetAttribute("go");
10521051
if (!goName || storm::iEquals(goName, selectedLinkName))
10531052
EmergencyExit();
10541053
else
@@ -1082,7 +1081,8 @@ void DIALOG::Realize(uint32_t Delta_Time)
10821081

10831082
m_DlgText.Show(textViewport.Y);
10841083
if (m_DlgText.IsLastPage())
1085-
m_DlgLinks.Show(static_cast<int32_t>(textViewport.Y + m_BackParams.nDividerOffsetY + m_BackParams.nDividerHeight));
1084+
m_DlgLinks.Show(
1085+
static_cast<int32_t>(textViewport.Y + m_BackParams.nDividerOffsetY + m_BackParams.nDividerHeight));
10861086

10871087
if (snd && !snd->SoundIsPlaying(curSnd))
10881088
{
@@ -1189,7 +1189,7 @@ void DIALOG::UpdateDlgViewport()
11891189

11901190
textViewport.Height = nAllHeight;
11911191
textViewport.Y = static_cast<uint32_t>(static_cast<int32_t>(m_BackParams.m_frBorderInt.bottom) - nAllHeight -
1192-
GetScrHeight(DIALOG_BOTTOM_LINESPACE));
1192+
GetScrHeight(DIALOG_BOTTOM_LINESPACE));
11931193

11941194
const float fTopBorder = textViewport.Y - GetScrHeight(DIALOG_TOP_LINESPACE);
11951195
if (m_BackParams.m_frBorderInt.top != fTopBorder)

src/libs/dialog/src/dialog.h renamed to src/libs/dialog/src/dialog.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class DIALOG final : public Entity
6262
}
6363
}
6464

65-
static void AddToStringArrayLimitedByWidth(const char *pcSrcText, int32_t nFontID, float fScale, int32_t nLimitWidth,
66-
std::vector<std::string> &asOutTextList,
65+
static void AddToStringArrayLimitedByWidth(const std::string_view &text, int32_t nFontID, float fScale, int32_t nLimitWidth,
66+
std::vector<std::string> &asOutTextList, VDX9RENDER *renderService,
6767
std::vector<int32_t> *panPageIndices, int32_t nPageSize);
6868

6969
private:

0 commit comments

Comments
 (0)