|
1 | | -#include "dialog.h" |
2 | | -#include "v_sound_service.h" |
| 1 | +#include "dialog.hpp" |
3 | 2 | #include "core.h" |
4 | 3 | #include "string_compare.hpp" |
| 4 | +#include "v_sound_service.h" |
5 | 5 |
|
6 | 6 | #include "v_file_service.h" |
7 | 7 |
|
@@ -70,14 +70,15 @@ void DIALOG::DlgTextDescribe::ChangeText(const char *pcText) |
70 | 70 | memcpy(&pcTmp[n - i], "...", 4 * sizeof(char)); |
71 | 71 | i = n + 2; |
72 | 72 | n++; |
73 | | - AddToStringArrayLimitedByWidth(pcTmp, nFontID, fScale, nWindowWidth, asText, &anPageEndIndex, |
| 73 | + AddToStringArrayLimitedByWidth(pcTmp, nFontID, fScale, nWindowWidth, asText, RenderService, &anPageEndIndex, |
74 | 74 | nShowQuantity); |
75 | 75 | if (anPageEndIndex.size() == 0 || anPageEndIndex[anPageEndIndex.size() - 1] != asText.size()) |
76 | 76 | anPageEndIndex.push_back(asText.size()); |
77 | 77 | delete[] pcTmp; |
78 | 78 | } |
79 | 79 | } |
80 | | - AddToStringArrayLimitedByWidth(&pcText[i], nFontID, fScale, nWindowWidth, asText, &anPageEndIndex, nShowQuantity); |
| 80 | + AddToStringArrayLimitedByWidth(&pcText[i], nFontID, fScale, nWindowWidth, asText, RenderService, &anPageEndIndex, |
| 81 | + nShowQuantity); |
81 | 82 | // if( anPageEndIndex.size()!=0 && anPageEndIndex[anPageEndIndex.size()-1]!=asText.size() ) |
82 | 83 | // anPageEndIndex.Add( asText.size() ); |
83 | 84 | nStartIndex = 0; |
@@ -202,7 +203,8 @@ void DIALOG::DlgLinkDescribe::ChangeText(ATTRIBUTES *pALinks) |
202 | 203 | nEditVarIndex = pA->GetAttributeAsDword("edit", 0); |
203 | 204 | nEditCharIndex = 0; |
204 | 205 | } |
205 | | - AddToStringArrayLimitedByWidth(pA->GetThisAttr(), nFontID, fScale, nWindowWidth, asText, nullptr, 100); |
| 206 | + AddToStringArrayLimitedByWidth(pA->GetValue(), nFontID, fScale, nWindowWidth, asText, RenderService, |
| 207 | + nullptr, 100); |
206 | 208 | anLineEndIndex.push_back(asText.size()); |
207 | 209 | } |
208 | 210 | } |
@@ -440,8 +442,8 @@ DIALOG::~DIALOG() |
440 | 442 | void DIALOG::CreateBack() |
441 | 443 | { |
442 | 444 | 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 |
445 | 447 |
|
446 | 448 | if (m_idVBufBack == -1) |
447 | 449 | m_idVBufBack = |
@@ -777,77 +779,73 @@ void DIALOG::GetPointFromIni(INIFILE *ini, const char *pcSection, const char *pc |
777 | 779 | sscanf(param, "%f,%f", &fpoint.x, &fpoint.y); |
778 | 780 | } |
779 | 781 |
|
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, |
782 | 785 | int32_t nPageSize) |
783 | 786 | { |
784 | | - if (!pcSrcText) |
| 787 | + if (text.empty()) |
785 | 788 | return; |
786 | 789 | if (nLimitWidth < 20) |
787 | 790 | nLimitWidth = 20; |
788 | 791 |
|
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()) |
794 | 794 | nPrevIdx = panPageIndices->back(); |
795 | | - while (true) |
| 795 | + |
| 796 | + size_t current_offset = 0; |
| 797 | + std::string_view current_span = text; |
| 798 | + for (;;) |
796 | 799 | { |
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) |
798 | 803 | { |
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) |
808 | 807 | { |
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') |
810 | 813 | { |
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; |
833 | 816 | } |
834 | | - asOutTextList.push_back(param); |
835 | | - n = 0; |
836 | | - |
837 | | - if (panPageIndices && asOutTextList.size() - nPrevIdx == nPageSize) |
| 817 | + else |
838 | 818 | { |
839 | | - nPrevIdx = asOutTextList.size(); |
840 | | - panPageIndices->push_back(nPrevIdx); |
| 819 | + current_span = current_span.substr(last_space + 1u); |
| 820 | + current_offset = 0; |
841 | 821 | } |
842 | 822 | } |
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 | + } |
847 | 834 | } |
848 | 835 | else |
849 | 836 | { |
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; |
851 | 849 | } |
852 | 850 | } |
853 | 851 | } |
@@ -972,7 +970,8 @@ void DIALOG::Realize(uint32_t Delta_Time) |
972 | 970 | { |
973 | 971 | if (m_DlgLinks.nSelectLine > 0) |
974 | 972 | 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; |
976 | 975 | if (m_DlgLinks.nStartIndex > nTmp) |
977 | 976 | { |
978 | 977 | m_DlgLinks.nStartIndex = nTmp; |
@@ -1048,7 +1047,7 @@ void DIALOG::Realize(uint32_t Delta_Time) |
1048 | 1047 | pA = pA->GetAttributeClass(m_DlgLinks.nSelectLine); |
1049 | 1048 | if (pA) |
1050 | 1049 | { |
1051 | | - const char* goName = pA->GetAttribute("go"); |
| 1050 | + const char *goName = pA->GetAttribute("go"); |
1052 | 1051 | if (!goName || storm::iEquals(goName, selectedLinkName)) |
1053 | 1052 | EmergencyExit(); |
1054 | 1053 | else |
@@ -1082,7 +1081,8 @@ void DIALOG::Realize(uint32_t Delta_Time) |
1082 | 1081 |
|
1083 | 1082 | m_DlgText.Show(textViewport.Y); |
1084 | 1083 | 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)); |
1086 | 1086 |
|
1087 | 1087 | if (snd && !snd->SoundIsPlaying(curSnd)) |
1088 | 1088 | { |
@@ -1189,7 +1189,7 @@ void DIALOG::UpdateDlgViewport() |
1189 | 1189 |
|
1190 | 1190 | textViewport.Height = nAllHeight; |
1191 | 1191 | 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)); |
1193 | 1193 |
|
1194 | 1194 | const float fTopBorder = textViewport.Y - GetScrHeight(DIALOG_TOP_LINESPACE); |
1195 | 1195 | if (m_BackParams.m_frBorderInt.top != fTopBorder) |
|
0 commit comments