Esempio n. 1
0
        public void NextWord()
        {
            SuspendPlay();
            BackIndex++;
            if (BackIndex < WordsRecords.Count && BackIndex > 0)
            {
                WordPlayViewMode.Instance.Word = WordsRecords[BackIndex];
                WordPlayViewMode.Instance.Word.ShowCount++;
                SpeakAsync();
            }
            else
            {
                Task.Run(new Func <bool>(() =>
                {
                    var Word = new WordMode("");
                    List <WordMode> Words = new List <WordMode>();

                    Words = TypeWordViewMode.Instance.TypeWord.FindAll((index) => !index.IsOk);
                    if (Words == null)
                    {
                        return(false);
                    }
                    if (Words.Count <= 0)
                    {
                        return(false);
                    }

                    again: if (Random)
                    {
                        WordIndex = ran.Next(0, Words.Count);
                    }
                    else
                    {
                        WordIndex += 1;
                        if (WordIndex >= Words.Count)
                        {
                            WordIndex = 0;
                        }
                    }
                    if (WordIndex < Words.Count)
                    {
                        Word = Words[WordIndex];
                        Word.AsynTrans();
                    }
                    else
                    {
                        goto again;
                    }

                    WordPlayViewMode.Instance.Word = Word;
                    WordPlayViewMode.Instance.Word.ShowCount++;

                    WordsRecords.Add(Word);
                    BackIndex = WordsRecords.Count - 1;
                    SpeakAsync();
                    return(true);
                }));
            }
        }
Esempio n. 2
0
        private void StartPlayClick()
        {
            if (PlayThread == null)
            {
                PlayThread = new Thread(new ThreadStart(() =>
                {
                    var NextWord          = false;
                    var Word              = new WordMode("");
                    List <WordMode> Words = new List <WordMode>();
                    WordsRecords.Clear();

                    while (true)
                    {
                        var work = Task.Run(new Func <bool>(() =>
                        {
                            Words = TypeWordViewMode.Instance.TypeWord.FindAll((index) => !index.IsOk);
                            if (Words == null)
                            {
                                return(false);
                            }
                            if (Words.Count <= 0)
                            {
                                return(false);
                            }

                            again:  if (Random)
                            {
                                WordIndex = ran.Next(0, Words.Count);
                            }
                            else
                            {
                                WordIndex += 1;
                                if (WordIndex >= Words.Count)
                                {
                                    WordIndex = 0;
                                }
                            }
                            if (WordIndex < Words.Count)
                            {
                                Word = Words[WordIndex];
                                Word.AsynTrans();
                            }
                            else
                            {
                                goto again;
                            }
                            return(true);
                        }));
                        DelayManualResetEvent.Reset();
                        //Thread.Sleep((int)(ShowTime * 1000));
                        NextWord = DelayManualResetEvent.WaitOne((int)(ShowTime * 1000));
                        SuspendManualResetEvent.WaitOne();
                        if (!NextWord)
                        {
                            Status = PlayStatus.Play;

                            if (!work.Result)
                            {
                                Status = PlayStatus.Stop;
                                return;
                            }

                            if (!NextWord)
                            {
                                while (WordPlayViewMode.Instance.WordOpacity > 0)
                                {
                                    WordPlayViewMode.Instance.WordExplainingOpacity = WordPlayViewMode.Instance.WordOpacity -= (1f / 30f);
                                    //Thread.Sleep((int)(FadeOut / 30 * 1000));
                                    if (NextWord = DelayManualResetEvent.WaitOne((int)(FadeOut / 30 * 1000)))
                                    {
                                        break;
                                    }
                                }
                            }


                            WordPlayViewMode.Instance.Word = Word;
                            WordPlayViewMode.Instance.Word.ShowCount++;
                            if (!NextWord)
                            {
                                while (WordPlayViewMode.Instance.WordOpacity < 1)
                                {
                                    WordPlayViewMode.Instance.WordExplainingOpacity = WordPlayViewMode.Instance.WordOpacity += 1f / 30f;
                                    //Thread.Sleep((int)(FadeOut / 30 * 1000));
                                    if (NextWord = DelayManualResetEvent.WaitOne((int)(FadeOut / 30 * 1000)))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            WordPlayViewMode.Instance.Word = Word;
                            WordPlayViewMode.Instance.Word.ShowCount++;
                        }

                        if (NextWord)
                        {
                            WordPlayViewMode.Instance.WordOpacity           = 1;
                            WordPlayViewMode.Instance.WordExplainingOpacity = 1;
                        }

                        WordsRecords.Add(Word);
                        BackIndex = WordsRecords.Count - 1;
                        SpeakAsync();
                    }
                }));
                PlayThread.IsBackground = true;
                PlayThread.Start();
            }
            SuspendManualResetEvent.Set();
            DelayManualResetEvent.Set();
            Status = PlayStatus.Play;
        }