// Menu -> PhraseList_LanguageSelection private IUserInterface BuildPhraseList_LanguageSelectionSection() { string sectionName = "phrase_list-language_selection"; Buttons buttons = BuildSectionButtons(sectionName); IUserInterface phraseList_LanguageSelectionInterface = new ButtonInterface( buttons: buttons, controlKeyContainer: controlKeyContainer, getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}", withSoundEffect: () => withSoundEffect, getHeaderText: () => localization[$"{sectionName}:header"] ); buttons[1].OnPressed += (o, args) => { IUserInterface ruPhraseListInterface = BuildPhraseListSection <RuPhraseAndTranslation>(); ConnectStoppedEvents(phraseList_LanguageSelectionInterface, ruPhraseListInterface); ruPhraseListInterface.Display().Wait(); }; buttons[2].OnPressed += (o, args) => { IUserInterface enPhraseListInterface = BuildPhraseListSection <EnPhraseAndTranslation>(); ConnectStoppedEvents(phraseList_LanguageSelectionInterface, enPhraseListInterface); enPhraseListInterface.Display().Wait(); }; buttons[3].OnPressed += (o, args) => phraseList_LanguageSelectionInterface.Stop(); return(phraseList_LanguageSelectionInterface); }
static void Main(string[] args) { ClientContext.PreloadNativeLibraries(); using (ServerAutoStarter serverAutoStarter = new ServerAutoStarter()) using (OSVR.ClientKit.ClientContext context = new OSVR.ClientKit.ClientContext("com.osvr.exampleclients.managed.ButtonCallback")) { // This is just one of the paths: specifically, the Hydra's left // controller's button labelled "1". More are in the docs and/or listed on // startup #if NET20 using (var button1 = ButtonInterface.GetInterface(context, "/controller/left/1")) #else using (var button1 = context.GetButtonInterface("/controller/left/1")) #endif { button1.StateChanged += button1_StateChanged; // Pretend that this is your application's main loop for (int i = 0; i < 1000000; ++i) { context.update(); } Console.WriteLine("Library shut down; exiting."); } } }
// Menu -> SoundSetting private IUserInterface BuildSoundSettingSection() { string sectionName = "sound_setting_section"; Buttons buttons = BuildSectionButtons(sectionName); IUserInterface soundSettingInterface = new ButtonInterface( buttons: buttons, controlKeyContainer: controlKeyContainer, getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}", withSoundEffect: () => withSoundEffect ); buttons[1].OnPressed += (o, args) => { withSoundEffect = true; StaticFunctions.EditSettingInConfig( path: "config.ini", settingKey: "sound_effect", newValue: withSoundEffect.ToString().ToLower() ); StaticFunctions.OpenConfig("config.ini", out coreConfiguration); }; buttons[2].OnPressed += (o, args) => { withSoundEffect = false; StaticFunctions.EditSettingInConfig( path: "config.ini", settingKey: "sound_effect", newValue: withSoundEffect.ToString().ToLower() ); StaticFunctions.OpenConfig("config.ini", out coreConfiguration); }; buttons[3].OnPressed += (o, args) => soundSettingInterface.Stop(); return(soundSettingInterface); }
// Menu private IUserInterface BuildMenuSection() { string sectionName = "menu"; Buttons buttons = BuildSectionButtons(sectionName); ButtonInterface menuInterface = new ButtonInterface( buttons: buttons, controlKeyContainer: controlKeyContainer, getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}", withSoundEffect: () => withSoundEffect ); buttons[1].OnPressed += (o, args) => { IUserInterface training_ModeSelectionInterface = BuildTraining_ModeSelectionSection(); ConnectStoppedEvents(menuInterface, training_ModeSelectionInterface); training_ModeSelectionInterface.Display().Wait(); }; buttons[2].OnPressed += (o, args) => { IUserInterface addPhrase_LanguageSelectionInterface = BuildAddPhrase_LanguageSelectionSection(); ConnectStoppedEvents(menuInterface, addPhrase_LanguageSelectionInterface); addPhrase_LanguageSelectionInterface.Display().Wait(); }; buttons[3].OnPressed += (o, args) => { IUserInterface phraseList_LanguageSelectionInterface = BuildPhraseList_LanguageSelectionSection(); ConnectStoppedEvents(menuInterface, phraseList_LanguageSelectionInterface); phraseList_LanguageSelectionInterface.Display().Wait(); }; buttons[4].OnPressed += (o, args) => { ButtonInterface localizationSettingInterface = BuildLocalizationSettingSection() as ButtonInterface; // Обновляем названия кнопок у интерфейса menuInterface в зависимости от выбранной локализации for (int buttonId = 1; buttonId < localizationSettingInterface.Buttons.ButtonCount; ++buttonId) { localizationSettingInterface.Buttons[buttonId].OnPressed += (o, args) => menuInterface.Buttons = BuildSectionButtons(sectionName); } ConnectStoppedEvents(menuInterface, localizationSettingInterface); localizationSettingInterface.Display().Wait(); }; buttons[5].OnPressed += (o, args) => { IUserInterface soundSettingInterface = BuildSoundSettingSection(); ConnectStoppedEvents(menuInterface, soundSettingInterface); soundSettingInterface.Display().Wait(); }; buttons[6].OnPressed += (o, args) => menuInterface.Stop(); return(menuInterface); }
// 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 private IUserInterface BuildTraining_ModeSelectionSection() { string sectionName = "training-mode_selection"; Buttons buttons = BuildSectionButtons(sectionName); ButtonInterface training_ModeSelectionInterface = new ButtonInterface( buttons: buttons, controlKeyContainer: controlKeyContainer, getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}", withSoundEffect: () => withSoundEffect, getHeaderText: () => $"{localization[$"{sectionName}:header"]}" ); buttons[1].OnPressed += (o, args) => { IUserInterface trainingInterface = BuildTrainingSection( translateFromEnglish: true, translateFromRussian: false ); ConnectStoppedEvents(training_ModeSelectionInterface, trainingInterface); trainingInterface.Display().Wait(); }; buttons[2].OnPressed += (o, args) => { IUserInterface trainingInterface = BuildTrainingSection( translateFromEnglish: false, translateFromRussian: true ); ConnectStoppedEvents(training_ModeSelectionInterface, trainingInterface); trainingInterface.Display().Wait(); }; buttons[3].OnPressed += (o, args) => { IUserInterface trainingInterface = BuildTrainingSection( translateFromEnglish: true, translateFromRussian: true ); ConnectStoppedEvents(training_ModeSelectionInterface, trainingInterface); trainingInterface.Display().Wait(); }; buttons[4].OnPressed += (o, args) => training_ModeSelectionInterface.Stop(); return(training_ModeSelectionInterface); }
// 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); }
public static void Main(string[] args) { ClientContext.PreloadNativeLibraries(); using (ServerAutoStarter serverAutoStarter = new ServerAutoStarter()) using (ClientContext context = new ClientContext("com.osvr.exampleclients.managed.TrackerCallback")) { #if NET20 using (var button1 = ButtonInterface.GetInterface(context, "/controller/left/1")) using (var button2 = ButtonInterface.GetInterface(context, "/controller/left/2")) #else using (var button1 = context.GetButtonInterface("/controller/left/1")) using (var button2 = context.GetButtonInterface("/controller/left/2")) #endif { // Pretend that this is your application's main loop for (int i = 0; i < 1000000; ++i) { context.update(); // getting the current state calls into the native DLL, so // try to get the state only once per frame. var button1State = button1.GetState(); var button2State = button2.GetState(); if (button1State.Value == ButtonInterface.Pressed) { Console.WriteLine("Pressing button 1!"); } // re-using button1State if (button1State.Value == ButtonInterface.Pressed && button2State.Value == ButtonInterface.Pressed) { Console.WriteLine("Pressing both button 1 and 2!"); } } Console.WriteLine("Library shut down; exiting."); } } }
public Button(ClientContext context, String path) { buttonValue = false; buttonInterface = context.GetButtonInterface(path); buttonInterface.StateChanged += ButtonInterface_StateChanged; }
// 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); }
// Menu -> PhraseList_LanguageSelection -> PhraseList private IUserInterface BuildPhraseListSection <T>() where T : PhraseAndTranslation { string sectionName = "phrase_list"; Buttons headerButtons = BuildPhraseListHeaderButtons <T>(sectionName); ButtonInterface phraseListInterface = new ButtonInterface( buttons: headerButtons, controlKeyContainer: controlKeyContainer, getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}", withSoundEffect: () => withSoundEffect ); // Событие при нажатии на кнопку "Назад" headerButtons[1].OnPressed += (o, args) => phraseListInterface.Stop(); // События для получения фраз for (int receivePhraseButtonId = 2; receivePhraseButtonId <= headerButtons.ButtonCount; ++receivePhraseButtonId) { headerButtons[receivePhraseButtonId].OnPressed += (headerButton, args) => { Buttons receivedPhraseButtons = null; // Получаем кнопки фраз: // При нажатии на "Показать все фразы" if (receivePhraseButtonId == 2) { receivedPhraseButtons = BuildReceivedPhraseButtons <T>(headerButton as Button, sectionName, true); } // При нажатии на букву else { receivedPhraseButtons = BuildReceivedPhraseButtons <T>(headerButton as Button, sectionName); } // Добавляем события к полученным кнопкам: for (int receivedPhraseVerticalLineId = 1; receivedPhraseVerticalLineId <= receivedPhraseButtons.VerticalLineCount; ++receivedPhraseVerticalLineId) { // Получаем фразу, относящуюся к текущей строке T phrase = dataContainer.GetPhrase <T>(receivedPhraseButtons[receivedPhraseVerticalLineId, 1].Name); // Кнопка "Получить информацию о фразе": receivedPhraseButtons[receivedPhraseVerticalLineId, 1].OnPressed += (o, args) => { IUserInterface phraseInfoInterface = BuildPhraseInfoSection(phrase); ConnectStoppedEvents(phraseListInterface, phraseInfoInterface); phraseInfoInterface.Display().Wait(); // Если после выхода из интерфейса фраза удалена, тогда удаляем строку с этой кнопкой // и поднимаем таргет наверх if (phrase.Deleted) { phraseListInterface.Buttons.RemoveVerticalLine(phraseListInterface.Position.Item1); phraseListInterface.Position = (phraseListInterface.Position.Item1 - 1, phraseListInterface.Position.Item2); } }; // Кнопка "Изменить фразу" receivedPhraseButtons[receivedPhraseVerticalLineId, 2].OnPressed += (o, args) => { IUserInterface editingPhraseInterface = BuildEditingPhraseSection(phrase); ConnectStoppedEvents(phraseListInterface, editingPhraseInterface); editingPhraseInterface.Display().Wait(); // Обновляем значения кнопок (headerButton as Button).Press(); if (phraseListInterface.Position.Item1 > phraseListInterface.Buttons.VerticalLineCount) { phraseListInterface.Position = (phraseListInterface.Buttons.VerticalLineCount, phraseListInterface.Position.Item2); } }; // Кнопка "Удалить фразу" receivedPhraseButtons[receivedPhraseVerticalLineId, 3].OnPressed += (o, args) => { phrase.Delete(); SerializeDataContainer(); phraseListInterface.Buttons.RemoveVerticalLine(phraseListInterface.Position.Item1); phraseListInterface.Position = (phraseListInterface.Position.Item1 - 1, phraseListInterface.Position.Item2); }; } // Соединяем headerButtons и receivedPhraseButtons и передаем полученные кнопки объекту интерфейса phraseListInterface.Buttons = Buttons.Union(headerButtons, receivedPhraseButtons); }; } return(phraseListInterface); }