From d1695a8fd342a48dff72dc85ba51629c9ade811b Mon Sep 17 00:00:00 2001 From: VladimirKhil Date: Fri, 22 Dec 2023 22:25:57 +0300 Subject: [PATCH] Options are shown before question when false starts are disabled --- src/Common/SIEngine.Core/FalseStartHelper.cs | 4 ++-- .../IQuestionEnginePlayHandler.cs | 2 +- src/Common/SIEngine.Core/QuestionEngine.cs | 6 +++++- src/Common/SIUI/Table.xaml | 8 +++---- src/SICore/SICore/Clients/Game/GameLogic.cs | 2 +- .../Clients/Game/QuestionPlayHandler.cs | 21 ++++++++++++++++--- .../SICore/Clients/Viewer/ViewerHumanLogic.cs | 1 + .../QuestionEnginePlayHandlerMock.cs | 5 +---- 8 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/Common/SIEngine.Core/FalseStartHelper.cs b/src/Common/SIEngine.Core/FalseStartHelper.cs index d32e5d01..4f96726e 100644 --- a/src/Common/SIEngine.Core/FalseStartHelper.cs +++ b/src/Common/SIEngine.Core/FalseStartHelper.cs @@ -13,8 +13,8 @@ public static class FalseStartHelper /// /// Question script. /// Question parameters. - /// - /// + /// False start mode. + /// Index of first step that should allow button press. public static int? GetAskAnswerStartIndex( Script script, StepParameters? parameters, diff --git a/src/Common/SIEngine.Core/IQuestionEnginePlayHandler.cs b/src/Common/SIEngine.Core/IQuestionEnginePlayHandler.cs index 0e715f9c..c1804c29 100644 --- a/src/Common/SIEngine.Core/IQuestionEnginePlayHandler.cs +++ b/src/Common/SIEngine.Core/IQuestionEnginePlayHandler.cs @@ -29,7 +29,7 @@ public interface IQuestionEnginePlayHandler /// /// Allows to press the button. /// - void OnButtonPressStart(); + bool OnButtonPressStart(); /// /// Sets question answerer(s). diff --git a/src/Common/SIEngine.Core/QuestionEngine.cs b/src/Common/SIEngine.Core/QuestionEngine.cs index f79ee0c9..4757585d 100644 --- a/src/Common/SIEngine.Core/QuestionEngine.cs +++ b/src/Common/SIEngine.Core/QuestionEngine.cs @@ -224,7 +224,11 @@ public bool PlayNext() case StepTypes.ShowContent: if (_stepIndex == _askAnswerStartIndex) { - _playHandler.OnButtonPressStart(); + if (_playHandler.OnButtonPressStart()) + { + return true; + } + _askAnswerStartIndex = null; } diff --git a/src/Common/SIUI/Table.xaml b/src/Common/SIUI/Table.xaml index 9f39f974..6c316bda 100644 --- a/src/Common/SIUI/Table.xaml +++ b/src/Common/SIUI/Table.xaml @@ -492,7 +492,7 @@ - + @@ -515,7 +515,7 @@ - + @@ -557,14 +557,14 @@ Name="image" Stretch="Uniform" Source="{Binding Value, Converter={StaticResource UriConverter}}" - lb:ImageController.LoadHandler="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ItemsControl}}" /> + lb:ImageController.LoadHandler="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ItemsControl, AncestorLevel=2}}" /> + lb:MediaController.LoadHandler="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ItemsControl, AncestorLevel=2}}" /> diff --git a/src/SICore/SICore/Clients/Game/GameLogic.cs b/src/SICore/SICore/Clients/Game/GameLogic.cs index 0cf14191..6eb38dd1 100644 --- a/src/SICore/SICore/Clients/Game/GameLogic.cs +++ b/src/SICore/SICore/Clients/Game/GameLogic.cs @@ -4712,7 +4712,7 @@ internal void OnAnswerOptions(bool questionHasScreenContent, AnswerOption[] answ _gameActions.SendMessage(messageBuilder.ToString()); } - internal void ShowAnswerOptions(Action continuation) + internal void ShowAnswerOptions(Action? continuation) { if (ClientData.QuestionPlayState.AnswerOptions == null) { diff --git a/src/SICore/SICore/Clients/Game/QuestionPlayHandler.cs b/src/SICore/SICore/Clients/Game/QuestionPlayHandler.cs index 30398b38..e2e1fa66 100644 --- a/src/SICore/SICore/Clients/Game/QuestionPlayHandler.cs +++ b/src/SICore/SICore/Clients/Game/QuestionPlayHandler.cs @@ -83,15 +83,30 @@ public void OnAskAnswerStop() GameData.IsPlayingMedia = false; } - public void OnButtonPressStart() + public bool OnButtonPressStart() { if (GameLogic == null || GameData == null) { - return; + return false; + } + + // TODO: merge somehow with GameLogic.AskToPress() and OnAskAnswer() for buttons + if (GameData.QuestionPlayState.AnswerOptions != null && !GameData.QuestionPlayState.LayoutShown) + { + GameLogic.OnAnswerOptions(false, GameData.QuestionPlayState.AnswerOptions); + GameData.QuestionPlayState.LayoutShown = true; + } + + if (GameData.QuestionPlayState.AnswerOptions != null && !GameData.QuestionPlayState.AnswerOptionsShown) + { + GameLogic.ShowAnswerOptions(null); + GameData.QuestionPlayState.AnswerOptionsShown = true; + return true; } GameData.AnswerMode = StepParameterValues.AskAnswerMode_Button; - GameLogic.OnButtonPressStart(); // TODO: merge somehow with GameLogic.AskToPress() + GameLogic.OnButtonPressStart(); + return false; } public void OnContentStart(IEnumerable contentItems) diff --git a/src/SICore/SICore/Clients/Viewer/ViewerHumanLogic.cs b/src/SICore/SICore/Clients/Viewer/ViewerHumanLogic.cs index a3b050e6..1573070b 100644 --- a/src/SICore/SICore/Clients/Viewer/ViewerHumanLogic.cs +++ b/src/SICore/SICore/Clients/Viewer/ViewerHumanLogic.cs @@ -1772,5 +1772,6 @@ public void OnAnswerOptions(bool questionHasScreenContent, IEnumerable o { TInfo.AnswerOptions.Options = optionsTypes.Select(i => new ItemViewModel()).ToArray(); TInfo.LayoutMode = LayoutMode.AnswerOptions; + TInfo.TStage = TableStage.Question; } } diff --git a/test/Common/SIEngine.Tests/QuestionEnginePlayHandlerMock.cs b/test/Common/SIEngine.Tests/QuestionEnginePlayHandlerMock.cs index b4e7af92..ebe59534 100644 --- a/test/Common/SIEngine.Tests/QuestionEnginePlayHandlerMock.cs +++ b/test/Common/SIEngine.Tests/QuestionEnginePlayHandlerMock.cs @@ -28,10 +28,7 @@ public void OnAskAnswerStop() } - public void OnButtonPressStart() - { - throw new NotImplementedException(); - } + public bool OnButtonPressStart() => false; public void OnContentStart(IEnumerable contentItems) {