Skip to content

Commit

Permalink
Add display for alternative definitions
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
duck-dev committed May 5, 2023
1 parent 7b5e170 commit a7bab0c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 22 deletions.
46 changes: 33 additions & 13 deletions src/ViewModels/LearningModes/BaseClasses/AnswerViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,19 +18,15 @@ public abstract class AnswerViewModelBase : SingleWordViewModelBase
private bool _isSolutionShown;
private SolutionPanelViewModel? _solutionPanel;
private SolidColorBrush _answerColor;
private bool _showPossibleSynonyms;
private ObservableCollection<string>? _possibleSynonyms;

private int _knownWords;
private int _wrongWords;

private readonly SolidColorBrush _blackColor
= Utilities.GetResourceFromStyle<SolidColorBrush,Application>(Application.Current, "OppositeAccent", Resources.StyleIndex)
?? new(Color.Parse("#000000"));
private readonly SolidColorBrush _greenColor
= Utilities.GetResourceFromStyle<SolidColorBrush, Application>(Application.Current, "MainGreen", Resources.StyleIndex)
?? new(Color.Parse("#0CA079"));
private readonly SolidColorBrush _redColor
= Utilities.GetResourceFromStyle<SolidColorBrush, Application>(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;

Expand Down Expand Up @@ -83,7 +79,21 @@ protected int WrongWords
set => this.RaiseAndSetIfChanged(ref _wrongWords, value);
}

protected IEnumerable<string>? PossibleDefinitions { get; set; }
protected List<string>? PossibleDefinitions { get; set; }

internal ObservableCollection<string>? 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)
{
Expand Down Expand Up @@ -116,7 +126,7 @@ protected void CheckAnswer()
bool tolerateTransposition = CurrentLesson.Options.TolerateSwappedLetters;

PossibleDefinitions ??= new List<string> {Definition};
string finalDefinition = string.Join(", ", this.PossibleDefinitions);
string finalDefinition = string.Join("; ", this.PossibleDefinitions);
int minDistance = mistakeTolerance + 1;
foreach (string definition in this.PossibleDefinitions)
{
Expand All @@ -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<List<string>, string>();
if (possibleDefinitionsCopy is null)
return;
PossibleSynonyms = new ObservableCollection<string>(possibleDefinitionsCopy);
PossibleSynonyms?.Remove(finalDefinition);
this.RaisePropertyChanged(nameof(PossibleSynonymsString));
}

protected void ShowSolution()
{
PossibleDefinitions ??= new List<string> { Definition };
OpenSolutionPanel(this.DisplayedTerm, string.Join(", ", PossibleDefinitions), false);
OpenSolutionPanel(this.DisplayedTerm, string.Join("; ", PossibleDefinitions), false);
Utilities.ChangeLearningState(CurrentWord, this, false, considerOverallState: true);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ViewModels/LearningModes/ThesaurusViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
40 changes: 33 additions & 7 deletions src/Views/LearningModes/SecondaryElements/SolutionPanelView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<Panel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Panel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{StaticResource OppositeAccent}"
Opacity="0.7"/>
<Grid RowDefinitions="3*,1*" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="30">
<Grid Grid.Row="0" RowDefinitions="*,*,*" HorizontalAlignment="Stretch" VerticalAlignment="Center">
<Grid RowDefinitions="*,Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="30">
<Grid Grid.Row="0" RowDefinitions="Auto,Auto,Auto" HorizontalAlignment="Stretch" VerticalAlignment="Center">
<Grid Grid.Row="0" ColumnDefinitions="*,Auto" HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="0,0,0,30">
Margin="0,30">
<Viewbox Grid.Column="0" MaxHeight="96" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Foreground="{StaticResource SameAccent}" FontWeight="Bold" Text="{Binding Term}"/>
</Viewbox>
Expand All @@ -23,11 +23,37 @@
<Viewbox Grid.Row="1" MaxHeight="36" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,30">
<TextBlock Foreground="{StaticResource SameAccent}" Text="{Binding ExplanationText}"/>
</Viewbox>
<Viewbox Grid.Row="2" MaxHeight="124" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,30,0,0">
<TextBlock Foreground="{Binding AnswerViewModel.AnswerColor}" FontWeight="Bold" Text="{Binding Definition}"/>
</Viewbox>
<Grid Grid.Row="2" RowDefinitions="Auto,*" HorizontalAlignment="Stretch" VerticalAlignment="Center"
Margin="0,30">
<Viewbox Grid.Row="0" MaxHeight="124" HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="0,0,0,15">
<TextBlock Foreground="{Binding AnswerViewModel.AnswerColor}" FontWeight="Bold"
Text="{Binding Definition}"/>
</Viewbox>
<Grid Grid.Row="1" ColumnDefinitions="Auto,*" HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding AnswerViewModel.ShowPossibleSynonyms}">
<TextBlock Grid.Column="0" Foreground="{StaticResource SameAccent}" FontWeight="Bold"
FontSize="28" Text="Alternative definitions:" Margin="0,0,15,0"
VerticalAlignment="Center"/>
<ItemsControl Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center"
Items="{Binding AnswerViewModel.PossibleSynonyms}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Foreground="{Binding $parent[UserControl].DataContext.AnswerViewModel.AnswerColor}"
FontWeight="Bold" FontSize="36" TextWrapping="Wrap" Text="{Binding}"
Margin="10, 0" VerticalAlignment="Center"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Grid>
</Grid>
<Grid Grid.Row="1" ColumnDefinitions="Auto,Auto" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,30,0,0">
<Grid Grid.Row="1" ColumnDefinitions="Auto,Auto" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,30,0,30">
<Button Grid.Column="0" Classes="highlight-no-change selectable-button-effect" Width="240" Height="70"
Background="{StaticResource MainGreen}" Foreground="{StaticResource SameAccent}"
Margin="35,0" IsVisible="{Binding !IsAnswerCorrect}" CornerRadius="10"
Expand Down

0 comments on commit a7bab0c

Please sign in to comment.