diff --git a/src/Common/SIEngine.Core/IQuestionEnginePlayHandler.cs b/src/Common/SIEngine.Core/IQuestionEnginePlayHandler.cs index b7e52baf..3090bd90 100644 --- a/src/Common/SIEngine.Core/IQuestionEnginePlayHandler.cs +++ b/src/Common/SIEngine.Core/IQuestionEnginePlayHandler.cs @@ -12,7 +12,8 @@ public interface IQuestionEnginePlayHandler /// Sets answer options. /// /// Answer options. - bool OnAnswerOptions(AnswerOption[] answerOptions); + /// Screen content sequence. + bool OnAnswerOptions(AnswerOption[] answerOptions, IReadOnlyList screenContentSequence); /// /// Shows question content. diff --git a/src/Common/SIEngine.Core/QuestionEngine.cs b/src/Common/SIEngine.Core/QuestionEngine.cs index ae38db02..f0cb86f4 100644 --- a/src/Common/SIEngine.Core/QuestionEngine.cs +++ b/src/Common/SIEngine.Core/QuestionEngine.cs @@ -210,8 +210,42 @@ public bool PlayNext() continue; } + var allTypes = new List(); + + if (_question.Parameters != null) + { + foreach (var param in _question.Parameters) + { + if (param.Value.ContentValue != null) + { + var types = new List(); + + foreach (var contentItem in param.Value.ContentValue) + { + if (contentItem.Placement != ContentPlacements.Screen) + { + continue; + } + + types.Add(contentItem); + + if (contentItem.WaitForFinish) + { + allTypes.Add(types.ToArray()); + types.Clear(); + } + } + + if (types.Count > 0) + { + allTypes.Add(types.ToArray()); + } + } + } + } + _isAnswerTypeSelect = true; - var setAnswerOptions = _playHandler.OnAnswerOptions(answerOptions.ToArray()); + var setAnswerOptions = _playHandler.OnAnswerOptions(answerOptions.ToArray(), allTypes); _stepIndex++; if (setAnswerOptions) diff --git a/src/SICore/SICore/Clients/Game/GameLogic.cs b/src/SICore/SICore/Clients/Game/GameLogic.cs index babca1f9..28aaeb74 100644 --- a/src/SICore/SICore/Clients/Game/GameLogic.cs +++ b/src/SICore/SICore/Clients/Game/GameLogic.cs @@ -4642,12 +4642,24 @@ internal void AcceptQuestion() ScheduleExecution(Tasks.MoveNext, 20, 1); } - internal void OnAnswerOptions(bool questionHasScreenContent, AnswerOption[] answerOptions) + internal void OnAnswerOptions() { - var messageBuilder = new MessageBuilder(Messages.Layout).Add(MessageParams.Layout_AnswerOptions).Add(questionHasScreenContent ? '+' : '-'); - messageBuilder.AddRange(answerOptions.Select(o => o.Content.Type)); + var screenContentSequence = _data.QuestionPlayState.ScreenContentSequence; + var answerOptions = _data.QuestionPlayState.AnswerOptions; + + if (answerOptions == null || screenContentSequence == null) + { + return; + } + + var messageBuilder = new MessageBuilder(Messages.Layout) + .Add(MessageParams.Layout_AnswerOptions) + .Add(string.Join("|", screenContentSequence.Select(group => string.Join("+", group.Select(serializeContentItem))))) + .AddRange(answerOptions.Select(o => o.Content.Type)); _gameActions.SendMessage(messageBuilder.ToString()); + + static string serializeContentItem(ContentItem ci) => $"{ci.Type}{(ci.Type == ContentTypes.Text ? "." + ci.Value.Length : "")}"; } internal void ShowAnswerOptions(Action? continuation) diff --git a/src/SICore/SICore/Clients/Game/QuestionPlayHandler.cs b/src/SICore/SICore/Clients/Game/QuestionPlayHandler.cs index 6c835049..8b0284cc 100644 --- a/src/SICore/SICore/Clients/Game/QuestionPlayHandler.cs +++ b/src/SICore/SICore/Clients/Game/QuestionPlayHandler.cs @@ -11,7 +11,7 @@ internal sealed class QuestionPlayHandler : IQuestionEnginePlayHandler private GameData? GameData => GameLogic?.ClientData; - public bool OnAnswerOptions(AnswerOption[] answerOptions) + public bool OnAnswerOptions(AnswerOption[] answerOptions, IReadOnlyList screenContentSequence) { if (GameLogic == null || GameData == null) { @@ -19,6 +19,7 @@ public bool OnAnswerOptions(AnswerOption[] answerOptions) } GameData.QuestionPlayState.AnswerOptions = answerOptions; + GameData.QuestionPlayState.ScreenContentSequence = screenContentSequence; return false; } @@ -37,7 +38,7 @@ public void OnAskAnswer(string mode) if (GameData.QuestionPlayState.AnswerOptions != null && !GameData.QuestionPlayState.LayoutShown) { - GameLogic.OnAnswerOptions(false, GameData.QuestionPlayState.AnswerOptions); + GameLogic.OnAnswerOptions(); GameData.QuestionPlayState.LayoutShown = true; } @@ -93,7 +94,7 @@ public bool OnButtonPressStart() // TODO: merge somehow with GameLogic.AskToPress() and OnAskAnswer() for buttons if (GameData.QuestionPlayState.AnswerOptions != null && !GameData.QuestionPlayState.LayoutShown) { - GameLogic.OnAnswerOptions(false, GameData.QuestionPlayState.AnswerOptions); + GameLogic.OnAnswerOptions(); GameData.QuestionPlayState.LayoutShown = true; } @@ -116,9 +117,9 @@ public void OnContentStart(IEnumerable contentItems) return; } - if (contentItems.Any(item => item.Placement == ContentPlacements.Screen) && GameData.QuestionPlayState.AnswerOptions != null && !GameData.QuestionPlayState.LayoutShown) + if (GameData.QuestionPlayState.AnswerOptions != null && !GameData.QuestionPlayState.LayoutShown) { - GameLogic.OnAnswerOptions(true, GameData.QuestionPlayState.AnswerOptions); + GameLogic.OnAnswerOptions(); GameData.QuestionPlayState.LayoutShown = true; } diff --git a/src/SICore/SICore/Clients/Game/QuestionPlayState.cs b/src/SICore/SICore/Clients/Game/QuestionPlayState.cs index cdd86d95..80e41b3b 100644 --- a/src/SICore/SICore/Clients/Game/QuestionPlayState.cs +++ b/src/SICore/SICore/Clients/Game/QuestionPlayState.cs @@ -1,4 +1,5 @@ using SIEngine.Core; +using SIPackages; namespace SICore.Clients.Game; @@ -32,6 +33,11 @@ internal sealed class QuestionPlayState /// internal bool AnswerOptionsShown { get; set; } + /// + /// Screen content sequence. + /// + internal IReadOnlyList? ScreenContentSequence { get; set; } + internal void Clear() { AnswererIndicies.Clear();