66#include " ../profile/dialogue.h"
77#include " ../profile/games/chlcc/dialoguebox.h"
88
9+ #include " ../ui/ui.h"
910#include " ../data/tipssystem.h"
1011
1112#include " ../hud/waiticondisplay.h"
@@ -53,7 +54,7 @@ void DialoguePage::Init() {
5354 for (int i = 0 ; i < std::ssize (DialoguePages); i++) {
5455 DialoguePages[i].Clear ();
5556 DialoguePages[i].Id = i;
56- DialoguePages[i].AnimationId = 0 ;
57+ DialoguePages[i].CurrentVoiceCharacterId = 0 ;
5758 DialoguePages[i].FadeAnimation .DurationIn = FadeInDuration;
5859 DialoguePages[i].FadeAnimation .DurationOut = FadeOutDuration;
5960 DialoguePages[i].FadeAnimation .SkipOnSkipMode = true ;
@@ -69,7 +70,8 @@ void DialoguePage::Clear() {
6970 TextPage::Clear ();
7071
7172 Name.clear ();
72- Voice = nullptr ;
73+ AudioId.reset ();
74+ CurrentStringAddress.reset ();
7375
7476 CurrentLineTop = [this ]() {
7577 switch (this ->GetMode ()) {
@@ -89,7 +91,7 @@ void DialoguePage::Clear() {
8991 AdvanceMethod = AdvanceMethodType::Skip;
9092}
9193
92- void DialoguePage::AddString (Vm::Sc3VmThread* ctx, Audio::AudioStream* voice ,
94+ void DialoguePage::AddString (Vm::Sc3VmThread* ctx, std::optional< int > voiceId ,
9395 bool acted, int animId, int charId,
9496 bool shouldUpdateCharId) {
9597 const DialoguePageMode mode = GetMode ();
@@ -99,17 +101,24 @@ void DialoguePage::AddString(Vm::Sc3VmThread* ctx, Audio::AudioStream* voice,
99101 }
100102 TextFadeAnimation.Reset (AnimationDirection::Out);
101103
102- Voice = voice;
104+ CurrentStringAddress = {ctx->ScriptBufferId , ctx->IpOffset };
105+ AudioId = voiceId;
106+
107+ Audio::AudioStream* audioStream = nullptr ;
108+ if (voiceId.has_value ()) {
109+ Io::Stream* stream;
110+ IoError err = Io::VfsOpen (" voice" , *voiceId, &stream);
111+
112+ const bool playAudio = (err == IoError_OK && !GetFlag (SF_MESALLSKIP));
113+ if (playAudio) audioStream = Audio::AudioStream::Create (stream);
114+ }
103115
104116 if (shouldUpdateCharId) {
105117 CharacterId = charId;
106- ScrWork[Id + SW_ANIME0CHANO] = CharacterId ;
118+ ScrWork[Id + SW_ANIME0CHANO] = charId ;
107119 }
108120
109- const int nextAnimId = acted ? animId : charId;
110-
111- // Hold last voiced animation id
112- if (Voice != nullptr ) NextAnimationId = std::max (nextAnimId, 31 );
121+ AnimationId = std::max (acted ? animId : charId, 31 );
113122
114123 const size_t typeWriterStart = Glyphs.size ();
115124
@@ -128,12 +137,14 @@ void DialoguePage::AddString(Vm::Sc3VmThread* ctx, Audio::AudioStream* voice,
128137 Typewriter.SetFirstGlyph (typeWriterStart);
129138 Typewriter.SetGlyphCount (Glyphs.size () - typeWriterStart);
130139 Typewriter.SetParallelStartGlyphs (DialogueTextParserInst.ParallelStartGlyphs );
131- Typewriter.Start (Voice != nullptr );
140+ Typewriter.Start (AudioId. has_value () );
132141
133- if (Voice != nullptr ) {
134- AnimationId = NextAnimationId;
135- Audio::Channels[Audio::AC_VOICE0]->Play (
136- std::unique_ptr<Audio::AudioStream>(Voice), false , 0 .0f );
142+ if (AudioId.has_value ()) {
143+ CurrentVoiceCharacterId = AnimationId;
144+ if (audioStream) {
145+ Audio::Channels[Audio::AC_VOICE0]->Play (
146+ std::unique_ptr<Audio::AudioStream>(audioStream), false , 0 .0f );
147+ }
137148 }
138149
139150 AutoWaitTime = static_cast <float >(Typewriter.GetGlyphCount ());
@@ -248,4 +259,13 @@ void DialoguePage::Show() {
248259 TextFadeAnimation.Progress = 1 .0f ;
249260}
250261
262+ void DialoguePage::PushBacklogEntry () {
263+ if (!CurrentStringAddress.has_value () || GetFlag (SF_REVADDDISABLE) ||
264+ (ScrWork[SW_MESWIN0TYPE + 10 * Id] & 0b10 )) {
265+ return ;
266+ }
267+
268+ UI::BacklogMenuPtr->AddMessage (*CurrentStringAddress, AudioId, AnimationId);
269+ }
270+
251271} // namespace Impacto
0 commit comments