diff --git a/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/AnswerOptionViewModel.cs b/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/AnswerOptionViewModel.cs new file mode 100644 index 00000000..86c7cd3c --- /dev/null +++ b/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/AnswerOptionViewModel.cs @@ -0,0 +1,36 @@ +using SIEngine.Core; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace SIQuester.ViewModel.Workspaces.Dialogs.Play; + +/// +/// Defines answer option view model. +/// +/// Option label. +/// Option content. +public sealed record AnswerOptionViewModel(string Label, ContentInfo Content) : INotifyPropertyChanged +{ + private bool _isSelected; + + /// + /// Is option selected. + /// + public bool IsSelected + { + get => _isSelected; + set + { + if (_isSelected != value) + { + _isSelected = value; + OnPropertyChanged(); + } + } + } + + public event PropertyChangedEventHandler? PropertyChanged; + + private void OnPropertyChanged([CallerMemberName] string? propertyName = null) => + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); +} diff --git a/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentInfo.cs b/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentInfo.cs new file mode 100644 index 00000000..e53cda80 --- /dev/null +++ b/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentInfo.cs @@ -0,0 +1,8 @@ +namespace SIQuester.ViewModel.Workspaces.Dialogs.Play; + +/// +/// Defines content info. +/// +/// Content type. +/// Content value. +public sealed record ContentInfo(ContentType Type, string Value); diff --git a/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentTypes.cs b/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentType.cs similarity index 95% rename from src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentTypes.cs rename to src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentType.cs index e9050209..96179154 100644 --- a/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentTypes.cs +++ b/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/Play/ContentType.cs @@ -3,7 +3,7 @@ /// /// Defines question table content types. /// -public enum ContentTypes +public enum ContentType { /// /// Empty content. diff --git a/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/QuestionPlayViewModel.cs b/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/QuestionPlayViewModel.cs index b65f509e..2989b938 100644 --- a/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/QuestionPlayViewModel.cs +++ b/src/SIQuester/SIQuester.ViewModel/Workspaces/Dialogs/QuestionPlayViewModel.cs @@ -1,6 +1,7 @@ using SIEngine.Core; using SIPackages; using SIPackages.Core; +using SIQuester.ViewModel.Workspaces.Dialogs.Play; using Utils.Commands; namespace SIQuester.ViewModel.Workspaces.Dialogs; @@ -17,30 +18,12 @@ public sealed class QuestionPlayViewModel : WorkspaceViewModel, IQuestionEngineP public override string Header => Properties.Resources.QuestionPlay; - private Play.ContentTypes _contentType = Dialogs.Play.ContentTypes.None; - - /// - /// Current question content type. - /// - public Play.ContentTypes ContentType - { - get => _contentType; - set - { - if (_contentType != value) - { - _contentType = value; - OnPropertyChanged(); - } - } - } - - private string? _content; + private ContentInfo[] _content = Array.Empty(); /// /// Current question content. /// - public string? Content + public ContentInfo[] Content { get => _content; set @@ -97,6 +80,24 @@ public string? Oral } } + private AnswerOptionViewModel[] _answerOptions = Array.Empty(); + + /// + /// Answer options. + /// + public AnswerOptionViewModel[] AnswerOptions + { + get => _answerOptions; + set + { + if (_answerOptions != value) + { + _answerOptions = value; + OnPropertyChanged(); + } + } + } + private bool _isAnswer; /// @@ -157,7 +158,8 @@ public void Play_Executed(object? arg) _isFinished = true; Play.CanBeExecuted = false; Sound = null; - ContentType = Dialogs.Play.ContentTypes.None; + Content = Array.Empty(); + AnswerOptions = Array.Empty(); return; } @@ -167,59 +169,52 @@ public void Play_Executed(object? arg) public void OnQuestionContent(IReadOnlyCollection content) { + var screenContent = new List(); + foreach (var contentItem in content) { - OnQuestionContentItem(contentItem); + switch (contentItem.Placement) + { + case ContentPlacements.Replic: + Oral = contentItem.Value; + break; + + case ContentPlacements.Screen: + switch (contentItem.Type) + { + case ContentTypes.Text: + screenContent.Add(new ContentInfo(ContentType.Text, contentItem.Value)); + break; + + case ContentTypes.Image: + screenContent.Add(new ContentInfo(ContentType.Image, contentItem.IsRef ? _qDocument.Images.Wrap(contentItem.Value).Uri : contentItem.Value)); + break; + + case ContentTypes.Video: + screenContent.Add(new ContentInfo(ContentType.Video, contentItem.IsRef ? _qDocument.Video.Wrap(contentItem.Value).Uri : contentItem.Value)); + break; + + case ContentTypes.Html: + screenContent.Add(new ContentInfo(ContentType.Html, contentItem.IsRef ? _qDocument.Html.Wrap(contentItem.Value).Uri : contentItem.Value)); + break; + + default: + break; + } + break; + + case ContentPlacements.Background: + Sound = contentItem.IsRef ? _qDocument.Audio.Wrap(contentItem.Value).Uri : contentItem.Value; + break; + + default: + break; + } } - } - public void OnQuestionContentItem(ContentItem contentItem) - { - switch (contentItem.Placement) + if (screenContent.Count > 0) { - case ContentPlacements.Replic: - Oral = contentItem.Value; - break; - - case ContentPlacements.Screen: - switch (contentItem.Type) - { - case ContentTypes.Text: - Content = contentItem.Value; - ContentType = Dialogs.Play.ContentTypes.Text; - break; - - case ContentTypes.Image: - Content = contentItem.IsRef ? _qDocument.Images.Wrap(contentItem.Value).Uri : contentItem.Value; - ContentType = Dialogs.Play.ContentTypes.Image; - break; - - case ContentTypes.Video: - Content = contentItem.IsRef ? _qDocument.Video.Wrap(contentItem.Value).Uri : contentItem.Value; - ContentType = Dialogs.Play.ContentTypes.Video; - break; - - case ContentTypes.Html: - Content = contentItem.IsRef ? _qDocument.Html.Wrap(contentItem.Value).Uri : contentItem.Value; - ContentType = Dialogs.Play.ContentTypes.Html; - break; - - default: - break; - } - break; - - case ContentPlacements.Background: - Sound = contentItem.IsRef ? _qDocument.Audio.Wrap(contentItem.Value).Uri : contentItem.Value; - - if (ContentType == Dialogs.Play.ContentTypes.None) - { - ContentType = Dialogs.Play.ContentTypes.Audio; - } - break; - - default: - break; + Content = screenContent.ToArray(); } } @@ -264,7 +259,42 @@ public void OnAskAnswerStop() public bool OnAnnouncePrice(NumberSet? availableRange) => false; - public bool OnAnswerOptions(AnswerOption[] answerOptions) => false; + public bool OnAnswerOptions(AnswerOption[] answerOptions) + { + var options = new List(); + + foreach (var option in answerOptions) + { + switch (option.Content.Type) + { + case ContentTypes.Text: + options.Add(new AnswerOptionViewModel(option.Label, new ContentInfo(ContentType.Text, option.Content.Value))); + break; - public bool OnRightAnswerOption(string rightOptionLabel) => false; + case ContentTypes.Image: + options.Add(new AnswerOptionViewModel(option.Label, new ContentInfo(ContentType.Image, option.Content.IsRef ? _qDocument.Images.Wrap(option.Content.Value).Uri : option.Content.Value))); + break; + + default: + break; + } + } + + AnswerOptions = options.ToArray(); + return false; + } + + public bool OnRightAnswerOption(string rightOptionLabel) + { + foreach (var option in AnswerOptions) + { + if (option.Label == rightOptionLabel) + { + option.IsSelected = true; + break; + } + } + + return true; + } } diff --git a/src/SIQuester/SIQuester/View/Dialogs/QuestionPlayView.xaml b/src/SIQuester/SIQuester/View/Dialogs/QuestionPlayView.xaml index 7048ca80..aaf5accb 100644 --- a/src/SIQuester/SIQuester/View/Dialogs/QuestionPlayView.xaml +++ b/src/SIQuester/SIQuester/View/Dialogs/QuestionPlayView.xaml @@ -15,15 +15,13 @@ d:DesignWidth="800" d:DataContext="{d:DesignInstance vm:QuestionPlayViewModel}"> - - - + - + - - + + - + - - + + - - + + @@ -61,6 +59,7 @@ + @@ -79,11 +78,28 @@ - + + + + + + + + + + + + +