private async void UpdateRelationsPanel()
        {
            ClearPanel(relationsPanel);

            int max = 7;

            foreach (Relation rel in rightAnswerForRound.Relations)
            {
                var copy = (FrameworkElement)XamlReader.Parse(XamlWriter.Save(relTemplatePanel));
                copy.Name               = null; //To show that it's a new item
                copy.Visibility         = Visibility.Visible;
                copy.MouseLeftButtonUp += async(s, e) => await PlaySoundAsync(rel.ToClause);

                copy.ToolTip = ClauseToDataGridClauseMapper.MakeTranslationsString(
                    (await dbFacade.GetClauseByIdAsync(rel.ToClause.Id)).Translations);

                if (PrgSettings.Default.AutoplaySound && !String.IsNullOrEmpty(rel.ToClause.Sound))
                {
                    copy.ToolTipOpening += async(s, e) => await PlaySoundAsync(rel.ToClause);
                }

                var newWordLbl = (Label)copy.FindName(nameof(wordLbl));
                newWordLbl.Content = rel.ToClause.Word;

                var newDescriptionLbl = (Label)copy.FindName(nameof(descriptionLbl));
                newDescriptionLbl.Content = $" - {rel.Description}";

                relationsPanel.Children.Insert(relationsPanel.Children.IndexOf(relTemplatePanel), copy);

                if (--max == 0)
                {
                    break;
                }
            }
        }
Beispiel #2
0
        private static string FormatWord(Clause word)
        {
            const string row = @"
                <tr>
                    <td>
                        <audio src=""{0}"" id=""{1}"" preload=""none""></audio>
                        <a href=""javascript:playAudio('{1}');"" title=""[{2}]"">
                            <span class=""fas fa-volume-up""></span>
                        </a>
                    </td>
                    <td class=""dict-word"" title=""Created: {3} 
Updated: {4}"">{5}</td>
                    <td class=""dict-transl"">{6}</td>
                    <td class=""dict-rel"">{7}</td>
                    <td class=""dict-context"">{8}</td>
                </tr>
";

            return(String.Format(row,
                                 word.Sound ?? "#",
                                 word.Id,
                                 word.Transcription,
                                 word.Added.ToString("yyyy-MM-dd"),
                                 word.Updated.ToString("yyyy-MM-dd"),
                                 word.Word,
                                 ClauseToDataGridClauseMapper.MakeTranslationsString(word.Translations),
                                 (word.Relations.Count > 0)
                    ? word.Relations.Aggregate("", (s, o) => $"{s}<div title=\"{o.Description}\">{o.ToClause.Word}; </div>")
                    : "---",
                                 word.Context));
        }
        private async Task NextRoundAsync()
        {
            //Preparations for the round
            currentAction = CurrentAction.WaitingForUserAnswer;

            UpdateActionButton();
            DecorateButton(actionBtn, ButtonDecoration.ResetDecoration);

            rightAnswerForRound = await dbFacade.GetClauseByIdAsync(wordsForTraining[currentRound]);

            answerTime = DateTime.UtcNow;

            triesWereMade = 0;

            //Set up the controls
            counterLbl.Text = $"{currentRound + 1}/{TotalRounds}";

            translationLbl.Text = ClauseToDataGridClauseMapper.MakeTranslationsString(rightAnswerForRound.Translations);

            if (!String.IsNullOrEmpty(rightAnswerForRound.Transcription))
            {
                transcriptionLbl.Text = $"[{rightAnswerForRound.Transcription}]";
            }
            else
            {
                transcriptionLbl.Text = "";
            }

            contextLbl.Text = rightAnswerForRound.Context;

            relationsPanel.Visibility     = contextLbl.Visibility = transcriptionLbl.Visibility =
                translationLbl.Visibility = Visibility.Hidden;

            correctAnsLbl.Visibility = wrongAnsLbl.Visibility = Visibility.Collapsed;

            ClearPanel(relationsPanel);

            answerEdit.Text       = "";
            answerEdit.Visibility = enterHereLbl.Visibility = Visibility.Visible;
            answerEdit.Focus();

            await PlaySoundAsync(rightAnswerForRound); //Auto play sound
        }
        private async void UpdateRelations()
        {
            LooseHeight();

            ClearRelationsArea();

            int countOfShownRelations = 0;

            foreach (RelationDTO rel in relations)
            {
                var copy = (FrameworkElement)XamlReader.Parse(XamlWriter.Save(relTemplatePanel));
                copy.Name               = null; //To show that it's a new item
                copy.Visibility         = Visibility.Visible;
                copy.MouseLeftButtonUp += OnRelationsLbl_MouseLeftButtonUp;
                var cl = await dbFacade.GetClauseByIdAsync(rel.ToWordId);

                copy.ToolTip = ClauseToDataGridClauseMapper.MakeTranslationsString(cl.Translations);

                if (PrgSettings.Default.AutoplaySound && !String.IsNullOrEmpty(cl.Sound))
                {
                    copy.ToolTipOpening += async(s, e) =>
                                           await SoundManager.PlaySoundAsync(cl.Id, cl.Sound, dbFacade.DataSource);
                }

                var newWordLbl = (Label)copy.FindName(nameof(wordLbl));
                newWordLbl.Content = rel.ToWord;

                var newDescriptionLbl = (Label)copy.FindName(nameof(descriptionLbl));
                newDescriptionLbl.Content = $" - {rel.Description}";

                relationsPanel.Children.Insert(relationsPanel.Children.IndexOf(relTemplatePanel), copy);

                if (countOfShownRelations == MaxCountOfRelations)
                {
                    break;
                }
            }

            if (Visibility == Visibility.Visible) //Only if form is already shown and knows its size
            {
                FixHeight();
            }
        }
Beispiel #5
0
        private void UpdateResult()
        {
            int correct = Answers.Count(o => o.Correct);
            int total   = Answers.Count;

            if (correct == total)
            {
                if (!ExclamationHasBeenPlayed)
                {
                    resultCongrats.Visibility = Visibility.Visible;
                    resultCongrats.Content    = String.Format(PrgResources.WithoutErrorsMessage, correct, total);

                    SystemSounds.Exclamation.Play();
                    ExclamationHasBeenPlayed = true;
                }
            }
            else
            {
                resultCongrats.Visibility = Visibility.Collapsed;
            }

            resultLbl.Content = String.Format(PrgResources.RightTestAnswers, correct, total,
                                              (int)Math.Round((double)correct / total * 100));

            mistakesLbl.Text = String.Format(PrgResources.MistakesLabel, total - correct);
            correctLbl.Text  = String.Format(PrgResources.CorrectLabel, correct);

            //Remove all old rows
            FrameworkElement[] toRemove = resultsPanel.Children.OfType <FrameworkElement>()
                                          .Where(o => o.Name == null)                      //The item that was added
                                          .ToArray();

            foreach (FrameworkElement item in toRemove)
            {
                resultsPanel.Children.Remove(item);
            }

            resultPanel.Visibility = Visibility.Visible;

            foreach (TestAnswer ans in Answers.Reverse()) //To show answers in the order as they were given
            {
                var copy = (FrameworkElement)XamlReader.Parse(XamlWriter.Save(resultPanel));
                copy.Name = null; //To show that it's a new item

                var newAsteriskLbl = (TextBlock)copy.FindName(nameof(asteriskLbl));
                newAsteriskLbl.Text = "";
                if (ans.Word.Asterisk != null && ans.Word.Asterisk.Type != AsteriskType.None)
                {
                    newAsteriskLbl.Text = $"{ans.Word.Asterisk.Type.ToShortStr()}✶";
                }
                newAsteriskLbl.MouseWheel += OnAsteriskLbl_MouseWheel;
                newAsteriskLbl.Tag         = ans.Word;

                var newTimeLbl = (TextBlock)copy.FindName(nameof(timeLbl));
                newTimeLbl.Text = $"{ans.Time.TotalSeconds:F0} s";

                var newGroupLbl = (TextBlock)copy.FindName(nameof(groupLbl));
                newGroupLbl.Text        = ans.Word.Group.ToGradeStr();
                newGroupLbl.MouseWheel += OnGroupLbl_MouseWheel;
                newGroupLbl.Tag         = ans.Word;

                var newPlayBtn = (Button)copy.FindName(nameof(playBtn));
                newPlayBtn.IsEnabled = !String.IsNullOrEmpty(ans.Word.Sound);
                newPlayBtn.Click    += OnPlayBtn_Click;
                newPlayBtn.Tag       = ans.Word;

                var newTriesLbl = (TextBlock)copy.FindName(nameof(triesLbl));
                if (ans.Tries <= 0)
                {
                    newTriesLbl.Visibility = Visibility.Collapsed; //Test without tries
                }
                else
                {
                    newTriesLbl.Text = ans.Tries.ToString();
                }

                var newWordLbl = (TextBlock)copy.FindName(nameof(wordLbl));
                newWordLbl.Text = ans.Word.Word;
                newWordLbl.MouseLeftButtonUp += OnWordLbl_MouseLeftButtonUp;
                newWordLbl.Tag = ans.Word;

                var newTranslationsLbl = (TextBlock)copy.FindName(nameof(translationsLbl));
                newTranslationsLbl.Text = ClauseToDataGridClauseMapper.MakeTranslationsString(ans.Word.Translations);

                if (newTranslationsLbl.Text?.Length > 55) //Truncate too long string
                {
                    newTranslationsLbl.ToolTip = newTranslationsLbl.Text;
                    newTranslationsLbl.Text    = $"{newTranslationsLbl.Text.Substring(0, 50)}...";
                }

                //Maybe to show the word data in the popup?..

                if (ans.Deleted)
                { //For the deleted clause
                    newWordLbl.TextDecorations.Clear();
                    newWordLbl.TextDecorations.Add(TextDecorations.Strikethrough);
                    newTranslationsLbl.TextDecorations.Add(TextDecorations.Strikethrough);

                    copy.IsEnabled = false;
                }

                int idx = resultsPanel.Children.IndexOf(ans.Correct ? correctLbl : mistakesLbl);
                resultsPanel.Children.Insert(idx + 1, copy);
            }

            resultPanel.Visibility = Visibility.Collapsed;
        }
Beispiel #6
0
        public InfoPopup(DataGridClause clause)
        {
            if (clause is null)
            {
                throw new ArgumentNullException(nameof(clause));
            }


            InitializeComponent();
            ApplyGUIScale();

            this.clause = clause;

            groupLbl.Content        = clause.Group.ToFullStr();
            wordLbl.Content         = clause.Word;
            translationsLbl.Content = clause.Translations;
            asteriskLbl.Content     = clause.AsteriskType != AsteriskType.None ? $"✶ {clause.AsteriskType.ToShortStr()}" : "";
            dateLbl.Content         = String.Format(Properties.Resources.WatchedDateCount, clause.Watched, clause.WatchedCount);

            if (String.IsNullOrEmpty(clause.Transcription))
            {
                transcriptionLbl.Visibility = Visibility.Hidden;
            }
            else
            {
                transcriptionLbl.Content = $"[{clause.Transcription}]";
            }

            if (clause.HasRelations)
            {
                Clause cl = dbFacade.GetClauseByIdAsync(clause.Id).Result;
                Debug.Assert(cl != null);

                int maxCount = 10;
                foreach (Relation rl in cl.Relations)
                {
                    var copy = (FrameworkElement)XamlReader.Parse(XamlWriter.Save(relTemplatePanel));
                    copy.Name       = null; //To show that it's a new item
                    copy.Visibility = Visibility.Visible;
                    copy.ToolTip    = ClauseToDataGridClauseMapper.MakeTranslationsString(
                        dbFacade.GetClauseByIdAsync(rl.ToClause.Id).Result.Translations);

                    if (PrgSettings.Default.AutoplaySound && !String.IsNullOrEmpty(rl.ToClause.Sound))
                    {
                        copy.ToolTipOpening += async(s, e) =>
                                               await SoundManager.PlaySoundAsync(rl.ToClause.Id, rl.ToClause.Sound, dbFacade.DataSource);
                    }

                    var newWordLbl = (Label)copy.FindName(nameof(relationLbl));
                    newWordLbl.Content = rl.ToClause.Word;

                    var newDescriptionLbl = (Label)copy.FindName(nameof(descriptionLbl));
                    newDescriptionLbl.Content = $" - {rl.Description}";

                    mainPanel.Children.Insert(mainPanel.Children.IndexOf(relTemplatePanel), copy);

                    if (--maxCount == 0)
                    {
                        break;
                    }
                }
            }

            relTemplatePanel.Visibility = Visibility.Hidden;
            relTemplatePanel.Height     = 0; //To correct row height
        }