private Buttons BuildReceivedPhraseButtons <T>(Button pressedButton, string sectionName, bool showAllButton = false)
            where T : PhraseAndTranslation
        {
            Buttons phraseButtons = new Buttons();
            // Получаем список фраз, соответствующие нажатой кнопке
            IEnumerable <PhraseAndTranslation> phrases = null;

            if (typeof(T) == typeof(RuPhraseAndTranslation))
            {
                phrases = dataContainer.RuPhrasesDb;
            }
            else
            {
                phrases = dataContainer.EnPhrasesDb;
            }
            if (!showAllButton)
            {
                Regex regex = new Regex(@"\[ (?<letter>[A-Z]|[А-Я]) \]");
                phrases = phrases.Where(p => p.Phrase.StartsWith(regex.Match(pressedButton.Name).Groups["letter"].ToString(), StringComparison.OrdinalIgnoreCase));
            }
            // Создаем для каждой фразы кнопки "Фраза", "Изменить", "Удалить"
            foreach (var phrase in phrases)
            {
                // Кнопка для получения информации о фразе
                Button phraseButton = new Button(phrase.Phrase);
                phraseButtons.AddButton(phraseButtons.VerticalLineCount + 1, 1, phraseButton);
                // Кнопка редактирования фразы
                Button editButton = new Button(localization[$"{sectionName}:edit_button"]);
                phraseButtons.AddButton(phraseButtons.VerticalLineCount, 2, editButton);
                // Кнопка удаления фразы
                Button deleteButton = new Button(localization["common:delete_button"]);
                phraseButtons.AddButton(phraseButtons.VerticalLineCount, 3, deleteButton);
            }
            return(phraseButtons);
        }
예제 #2
0
 private Buttons BuildPhraseListHeaderButtons<T>(string sectionName) where T : PhraseAndTranslation
 {
     Buttons headerButtons = new Buttons();
     // Создаем и добавляем кнопку Назад
     Button backButton = new Button(localization["common:back_button"]);
     headerButtons.AddButton(1, 1, backButton);
     // Создаем и добавляем кнопку Показать все фразы
     Button showAllPhrases = new Button($"[ {localization[$"{sectionName}:show_all_button"]} ]");
     headerButtons.AddButton(2, 1, showAllPhrases);
     string letters = null;
     if (typeof(T) == typeof(RuPhraseAndTranslation))
     {
         letters = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
     }
     else
     {
         letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     }
     // Получаем количество кнопок букв в линии 
     int letterButtonHorizontalCount = Convert.ToInt32(coreConfiguration["letter_button_horizontal_count"]);
     int verticalLineId = 3, horizontalButtonId = 1;
     foreach (var letter in letters)
     {
         if (horizontalButtonId > letterButtonHorizontalCount)
         {
             ++verticalLineId;
             horizontalButtonId = 1;
         }
         Button letterButton = new Button($"[ {letter} ]");
         headerButtons.AddButton(verticalLineId, horizontalButtonId, letterButton);
         ++horizontalButtonId;
     }
     return headerButtons;
 }
예제 #3
0
        // Тут не создается кнопка "Назад"
        private Buttons BuildLocalizationSettingButtons()
        {
            var     localizationPaths = Directory.GetFiles("localizations", "*_localization");
            Buttons buttons           = new Buttons();

            foreach (var localizationPath in localizationPaths)
            {
                // Открываем файл с локализацией и получаем название локализации
                StaticFunctions.OpenConfig(
                    path: localizationPath,
                    configuration: out IConfiguration _localization
                    );
                string localizationName = _localization["localization_name"];
                Button button           = new Button(localizationName);
                button.OnPressed += (o, args) =>
                {
                    localization = _localization;
                    // Изменяем значение ключа lang в core_config
                    Regex regex = new Regex(@"(?<lang>\w+)_localization$");
                    StaticFunctions.EditSettingInConfig(
                        path: "config.ini",
                        settingKey: "lang",
                        newValue: regex.Match(localizationPath).Groups[1].Value
                        );
                    StaticFunctions.OpenConfig(
                        path: "config.ini",
                        configuration: out coreConfiguration
                        );
                    // Изменяем название кнопки назад в зависимости от текущей локализации
                    buttons[buttons.ButtonCount].Rename(localization["LocalizationSettings:button_1_1"]);
                };
                buttons.AddButton(buttons.VerticalLineCount + 1, 1, button);
            }
            return(buttons);
        }
예제 #4
0
 void LoadButtonsAndTests()
 {
     if (buttonsMgr.buttons.Count > 0)
     {
         return;
     }
     foreach (Transform t in goButtons.transform)
     {
         GameObject go = t.gameObject;
         Debug.Log("add button " + go.name + "\n");
         string txt      = go.name;
         Test   test     = null;
         bool   ynStayOn = false;
         if (txt.Contains("ButtonTest") == true)
         {
             txt  = txt.Replace("Button", "");
             test = FindTestByName(txt);
             test.InitTest();
         }
         else
         {
             if (go.name.Contains("ButtonVideo") == true)
             {
                 VideoPauseAtStart(go);
                 ynStayOn = true;
             }
         }
         //
         buttonsMgr.AddButton(go, ynStayOn);
         tests.Add(test);
     }
     //
     buttonsMgr.AddButton(goButtonLeft, false);
     tests.Add(null);
     //
     buttonsMgr.AddButton(goButtonRight, false);
     tests.Add(null);
     //
     buttonsMgr.AddButton(goButtonUp, false);
     tests.Add(null);
     //
     buttonsMgr.AddButton(goButtonDown, false);
     tests.Add(null);
     //
 }
예제 #5
0
        // Menu -> PhraseList_LanguageSelection -> PhraseList -> PhraseList-PhraseInfo
        private IUserInterface BuildPhraseInfoSection(PhraseAndTranslation phrase)
        {
            string          sectionName         = "phrase_list-phrase_info";
            Buttons         buttons             = new Buttons();
            ButtonInterface phraseInfoInterface = new ButtonInterface(
                buttons: buttons,
                controlKeyContainer: controlKeyContainer,
                getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}",
                withSoundEffect: () => withSoundEffect,
                getHeaderText: () => $"{localization[$"{sectionName}:phrase"]}: {phrase.Phrase}\n{localization[$"{sectionName}:translations"]}:"
                );
            // Добавляем кнопки для удаления перевода
            int verticalLineId = 1;

            foreach (var translation in phrase.Translations)
            {
                Button translationButton = new Button(translation.Phrase, false);
                buttons.AddButton(verticalLineId, 1, translationButton);
                Button deleteTranslationButton = new Button($"{localization["common:delete_button"]}");
                deleteTranslationButton.OnPressed += (o, args) =>
                {
                    phrase.DeleteTranslation(translation);
                    SerializeDataContainer();
                    buttons.RemoveVerticalLine(phraseInfoInterface.Position.Item1);
                    if (phraseInfoInterface.Position.Item1 != 1 && phraseInfoInterface.Position.Item1 == buttons.VerticalLineCount)
                    {
                        phraseInfoInterface.Position = (phraseInfoInterface.Position.Item1 - 1, phraseInfoInterface.Position.Item2);
                    }
                    if (phrase.Deleted)
                    {
                        phraseInfoInterface.Stop();
                    }
                };
                buttons.AddButton(verticalLineId++, 2, deleteTranslationButton);
            }
            // Добавляем кнопку "Назад"
            Button backButton = new Button($"{localization["common:back_button"]}");

            backButton.OnPressed += (o, args) => phraseInfoInterface.Stop();
            buttons.AddButton(buttons.VerticalLineCount + 1, 1, backButton);
            return(phraseInfoInterface);
        }
예제 #6
0
    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Buttons?.AddButton(this);

        if (Size == Size.None)
        {
            Size = Size.ExtraSmall;
        }
    }
예제 #7
0
    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Buttons?.AddButton(this);

        if (Size == Size.None)
        {
            Size = Size.ExtraSmall;
        }

        ConfirmButtonText ??= Localizer[nameof(ConfirmButtonText)];
        CloseButtonText ??= Localizer[nameof(CloseButtonText)];
        Content ??= Localizer[nameof(Content)];
    }
예제 #8
0
        // Menu -> LocalizationSetting
        private IUserInterface BuildLocalizationSettingSection()
        {
            string  sectionName = "localization_setting";
            Buttons buttons     = BuildLocalizationSettingButtons();
            Button  backButton  = new Button(localization["common:back_button"]);

            buttons.AddButton(buttons.ButtonCount + 1, 1, backButton);
            IUserInterface localizationSettingInterface = new ButtonInterface(
                buttons: buttons,
                controlKeyContainer: controlKeyContainer,
                getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}",
                withSoundEffect: () => withSoundEffect
                );

            backButton.OnPressed += (o, args) => localizationSettingInterface.Stop();
            return(localizationSettingInterface);
        }
        // Menu -> Training_ModeSelection -> Training
        private IUserInterface BuildTrainingSection(bool translateFromRussian, bool translateFromEnglish)
        {
            string   sectionName = "training";
            Training training    = new Training(dataContainer);

            TextInputtingInterface.VariableInfoPair[] variableInfoPairs =
            {
                new TextInputtingInterface.VariableInfoPair()
            };
            TextInputtingInterface trainingInterface = new TextInputtingInterface(
                variableInfoPairs: variableInfoPairs,
                successfulInputtingMsg: $"{localization["common:press_any_key_to_continue"]}",
                getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}"
                );

            trainingInterface.OnBeforeTyping += (o, args) =>
            {
                if (training.EmptyQueue)
                {
                    if (translateFromRussian)
                    {
                        training.AddRuPhrasesToQueue(dataContainer.RuPhrasesDb.Count);
                    }
                    if (translateFromEnglish)
                    {
                        training.AddEnPhrasesToQueue(dataContainer.EnPhrasesDb.Count);
                    }
                }
                if (!training.EmptyQueue)
                {
                    variableInfoPairs[0].Info = $"{localization[$"{sectionName}:phrase"]}: {training.GetPhrase().Phrase}\n" +
                                                $"{localization[$"{sectionName}:input_translation"]} ({localization[$"{sectionName}:input_empty_to_exit"]}):";
                    if (!training.EmptyQueue && translateFromRussian && translateFromEnglish)
                    {
                        training.MixQueue();
                    }
                }
                else
                {
                    Console.Write($"{localization[$"{sectionName}:db_is_empty"]}\n{localization["common:press_any_key_to_continue"]}");
                    Console.ReadKey();
                    trainingInterface.Stop();
                }
            };
            trainingInterface.OnGettingData += (translations) =>
            {
                string inputtedTranslation = translations.ElementAt(0);
                bool   correctTranslation  = training.CorrectTranslation(inputtedTranslation);
                // При получении неверного значения спрашиваем у пользователя
                // является ли это одним из вариантов перевода
                // Для этого создаем ButtonInterface. В качестве header передаем
                // весь текст с консоли
                if (!correctTranslation)
                {
                    string outputtedText = $"{variableInfoPairs[0].Info}\n{inputtedTranslation}\n" +
                                           $"{localization[$"{sectionName}:correct_translations"]}: ";
                    for (var translationNode = training.GetPhrase().Translations.First;
                         translationNode != null; translationNode = translationNode.Next)
                    {
                        outputtedText += $"\"{translationNode.Value.Phrase}\"{(translationNode.Next != null ? "; " : string.Empty)}";
                    }
                    Buttons buttons = new Buttons();
                    buttons.AddButton(1, new Button(localization[$"{sectionName}:yes"]));
                    buttons.AddButton(2, new Button(localization[$"{sectionName}:no"]));
                    IUserInterface choiceInterface = new ButtonInterface(
                        buttons: buttons,
                        controlKeyContainer: controlKeyContainer,
                        getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}",
                        withSoundEffect: () => withSoundEffect,
                        getHeaderText: () => $"{outputtedText}\n{localization[$"{sectionName}:it_is_variant_of_translation"]}"
                        );
                    // Функция восстановления текста в консоли до входа в choiceInterface
                    Action stateRecovery = () =>
                    {
                        Console.Clear();
                        Console.WriteLine(outputtedText);
                        Console.CursorVisible = true;
                    };
                    // Кнопка "Да"
                    buttons[1].OnPressed += (o, args) =>
                    {
                        training.GetPhrase().AddTranslation(inputtedTranslation);
                        correctTranslation = true;
                        choiceInterface.Stop();
                        stateRecovery();
                    };
                    // Кнопка "Нет"
                    buttons[2].OnPressed += (o, args) =>
                    {
                        training.HandlerForIncorrectInput();
                        choiceInterface.Stop();
                        stateRecovery();
                        Console.WriteLine($"{localization[$"{sectionName}:wrong"]}");
                    };
                    ConnectStoppedEvents(trainingInterface, choiceInterface);
                    choiceInterface.Display().Wait();
                }
                if (correctTranslation)
                {
                    Console.WriteLine($"{localization[$"{sectionName}:right"]}");
                    training.HandlerForCorrectInput(phrase => { if (phrase.CorrectAnswersSuccessively >= 30)
                                                                {
                                                                    phrase.Delete();
                                                                }
                                                    });
                }
            };
            return(trainingInterface);
        }