From a7bab0cad2dbd2d876816149eb1e80c6329a4372 Mon Sep 17 00:00:00 2001 From: Duck <61479436+duck-dev@users.noreply.github.com> Date: Fri, 5 May 2023 17:07:13 +0200 Subject: [PATCH] Add display for alternative definitions - After entering the right definition for a vocabulary item, there are also alternative definitions (synonyms that could have counted as a valid answer as well) displayed on the SolutionPanel, below the entered definition. - In order to make this fit into the current layout, the layout had to be adjusted and partially redesigned as well. It doesn't look much different, but it has been adjusted to behave as intended with different window sizes and possibilities that could occur. --- .../BaseClasses/AnswerViewModelBase.cs | 46 +++++++++++++------ .../LearningModes/ThesaurusViewModel.cs | 4 +- .../SecondaryElements/SolutionPanelView.axaml | 40 +++++++++++++--- 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/ViewModels/LearningModes/BaseClasses/AnswerViewModelBase.cs b/src/ViewModels/LearningModes/BaseClasses/AnswerViewModelBase.cs index 2edacd8..756abb6 100644 --- a/src/ViewModels/LearningModes/BaseClasses/AnswerViewModelBase.cs +++ b/src/ViewModels/LearningModes/BaseClasses/AnswerViewModelBase.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; -using Avalonia; using Avalonia.Media; using ReactiveUI; using VocabularyTrainer.Enums; @@ -18,19 +18,15 @@ public abstract class AnswerViewModelBase : SingleWordViewModelBase private bool _isSolutionShown; private SolutionPanelViewModel? _solutionPanel; private SolidColorBrush _answerColor; + private bool _showPossibleSynonyms; + private ObservableCollection? _possibleSynonyms; private int _knownWords; private int _wrongWords; - private readonly SolidColorBrush _blackColor - = Utilities.GetResourceFromStyle(Application.Current, "OppositeAccent", Resources.StyleIndex) - ?? new(Color.Parse("#000000")); - private readonly SolidColorBrush _greenColor - = Utilities.GetResourceFromStyle(Application.Current, "MainGreen", Resources.StyleIndex) - ?? new(Color.Parse("#0CA079")); - private readonly SolidColorBrush _redColor - = Utilities.GetResourceFromStyle(Application.Current, "MainRed", Resources.StyleIndex) - ?? new(Color.Parse("#FF0000")); + private readonly SolidColorBrush _blackColor = Resources.OppositeAccentBrush; + private readonly SolidColorBrush _greenColor = Resources.MainGreenBrush; + private readonly SolidColorBrush _redColor = Resources.MainRedBrush; public event EventHandler? ReadyToFocus; @@ -83,7 +79,21 @@ protected int WrongWords set => this.RaiseAndSetIfChanged(ref _wrongWords, value); } - protected IEnumerable? PossibleDefinitions { get; set; } + protected List? PossibleDefinitions { get; set; } + + internal ObservableCollection? PossibleSynonyms + { + get => _possibleSynonyms; + private set => this.RaiseAndSetIfChanged(ref _possibleSynonyms, value); + } + + internal string PossibleSynonymsString => PossibleSynonyms is null ? string.Empty : string.Join("; ", PossibleSynonyms); + + internal bool ShowPossibleSynonyms + { + get => _showPossibleSynonyms; + set => this.RaiseAndSetIfChanged(ref _showPossibleSynonyms, value); + } protected internal override void VisualizeLearningProgress(LearningState previousState, LearningState newState, bool hadNotAsked) { @@ -116,7 +126,7 @@ protected void CheckAnswer() bool tolerateTransposition = CurrentLesson.Options.TolerateSwappedLetters; PossibleDefinitions ??= new List {Definition}; - string finalDefinition = string.Join(", ", this.PossibleDefinitions); + string finalDefinition = string.Join("; ", this.PossibleDefinitions); int minDistance = mistakeTolerance + 1; foreach (string definition in this.PossibleDefinitions) { @@ -141,12 +151,22 @@ protected void CheckAnswer() Utilities.ChangeLearningStateThesaurus(CurrentWord, this, correct); else Utilities.ChangeLearningState(CurrentWord, this, correct, considerOverallState: true); + + ShowPossibleSynonyms = PossibleDefinitions.Count > 1 && correct; + if (!ShowPossibleSynonyms) + return; + var possibleDefinitionsCopy = PossibleDefinitions.Clone, string>(); + if (possibleDefinitionsCopy is null) + return; + PossibleSynonyms = new ObservableCollection(possibleDefinitionsCopy); + PossibleSynonyms?.Remove(finalDefinition); + this.RaisePropertyChanged(nameof(PossibleSynonymsString)); } protected void ShowSolution() { PossibleDefinitions ??= new List { Definition }; - OpenSolutionPanel(this.DisplayedTerm, string.Join(", ", PossibleDefinitions), false); + OpenSolutionPanel(this.DisplayedTerm, string.Join("; ", PossibleDefinitions), false); Utilities.ChangeLearningState(CurrentWord, this, false, considerOverallState: true); } diff --git a/src/ViewModels/LearningModes/ThesaurusViewModel.cs b/src/ViewModels/LearningModes/ThesaurusViewModel.cs index d36ac07..9c4bc76 100644 --- a/src/ViewModels/LearningModes/ThesaurusViewModel.cs +++ b/src/ViewModels/LearningModes/ThesaurusViewModel.cs @@ -254,13 +254,13 @@ private void SetThesaurus() if (synonymChosen && synonyms.Count > 0) { - PossibleDefinitions = synonyms.Select(x => x.Definition); + PossibleDefinitions = synonyms.Select(x => x.Definition).ToList(); this.ThesaurusType = SynonymType; this.IndefiniteArticle = IndefiniteWithoutVowel; } else if (antonymChosen && antonyms.Count > 0) { - PossibleDefinitions = antonyms.Select(x => x.Definition); + PossibleDefinitions = antonyms.Select(x => x.Definition).ToList(); this.ThesaurusType = AntonymType; this.IndefiniteArticle = IndefiniteWithVowel; } diff --git a/src/Views/LearningModes/SecondaryElements/SolutionPanelView.axaml b/src/Views/LearningModes/SecondaryElements/SolutionPanelView.axaml index 3d2bf87..951bbc6 100644 --- a/src/Views/LearningModes/SecondaryElements/SolutionPanelView.axaml +++ b/src/Views/LearningModes/SecondaryElements/SolutionPanelView.axaml @@ -8,10 +8,10 @@ - - + + + Margin="0,30"> @@ -23,11 +23,37 @@ - - - + + + + + + + + + + + + + + + + + + + + - +