Ejemplo n.º 1
0
        private void AddCheckBox(OrderedDictionary <SettingCategory, OrderedDictionary <string, Setting> > settingcategories, StackPanel panel, SettingCategory category, string name, I18N.I18NString label, bool isChecked, bool isDefaultChecked)
        {
            StackPanel inputPanel = new StackPanel()
            {
                Orientation = Orientation.Horizontal,
            };

            CheckBox cb = new CheckBox
            {
                Name      = name,
                Content   = new Run(I18N.Get(label)),
                Margin    = new Thickness(10),
                IsChecked = isChecked
            };

            cb.Checked += (object sender, RoutedEventArgs e) =>
            {
                HLVRSettingsManager.TrySetSetting(settingcategories, category, name, true);
            };
            cb.Unchecked += (object sender, RoutedEventArgs e) =>
            {
                HLVRSettingsManager.TrySetSetting(settingcategories, category, name, false);
            };
            cb.Indeterminate += (object sender, RoutedEventArgs e) =>
            {
                HLVRSettingsManager.TrySetSetting(settingcategories, category, name, false);
            };
            inputPanel.Children.Add(cb);

            panel.Children.Add(inputPanel);
        }
Ejemplo n.º 2
0
        private static void UpdateSpeechLanguages()
        {
            HLVRSettingsManager.ModSettings.SpeechRecognitionLanguages.Clear();

            uint pulNumLanguages     = 0;
            uint pcchLanguagesBuffer = 0;

            if (GetUserPreferredUILanguages(MUI_LANGUAGE_ID, ref pulNumLanguages, IntPtr.Zero, ref pcchLanguagesBuffer) &&
                pcchLanguagesBuffer > 0)
            {
                // size is given in wchar characters, so we need to allocate size*2 bytes
                IntPtr pwszLanguagesBuffer = Marshal.AllocHGlobal((int)pcchLanguagesBuffer * 2);

                if (GetUserPreferredUILanguages(MUI_LANGUAGE_ID, ref pulNumLanguages, pwszLanguagesBuffer, ref pcchLanguagesBuffer))
                {
                    if (pulNumLanguages > 0)
                    {
                        // make sure sizes are correct:
                        // each language is 4 characters + 0 delimiter and the entire list ends with an additional 0
                        if (pulNumLanguages * 5 + 1 == pcchLanguagesBuffer)
                        {
                            for (int i = 0; i < pulNumLanguages; i++)
                            {
                                // copy language (4 characters excluding 0) into char array
                                // all characters are 0-F, so we can safely cast them to char and create a string to parse the value from
                                char[] language = new char[4];
                                Marshal.Copy(IntPtr.Add(pwszLanguagesBuffer, i * 5), language, 0, 4);
                                string      hexCultureId = new string(language);
                                CultureInfo cultureInfo;
                                try
                                {
                                    int cultureId = I18N.ParseInt(hexCultureId, NumberStyles.HexNumber);
                                    cultureInfo = new CultureInfo(cultureId, true);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                HLVRSettingsManager.ModSettings.SpeechRecognitionLanguages[hexCultureId] = new I18NString("vr_speech_language_id." + hexCultureId, cultureInfo.DisplayName);
                            }
                        }
                    }
                }

                Marshal.FreeHGlobal(pwszLanguagesBuffer);
            }

            if (HLVRSettingsManager.ModSettings.SpeechRecognitionLanguages.Count == 0)
            {
                HLVRSettingsManager.ModSettings.SpeechRecognitionLanguages["1400"] = new I18NString("vr_speech_language_id.1400", "System Default");
            }

            // Make sure selected language exists in current list - if not, select first available language
            if (!HLVRSettingsManager.ModSettings.SpeechRecognitionLanguages.ContainsKey(HLVRSettingsManager.ModSettings.AudioSettings[ModSettings.CategorySpeechRecognition][ModSettings.SpeechRecognitionLanguage].Value))
            {
                HLVRSettingsManager.TrySetSetting(HLVRSettingsManager.ModSettings.AudioSettings, ModSettings.CategorySpeechRecognition, ModSettings.SpeechRecognitionLanguage, "vr_speech_language_id." + HLVRSettingsManager.ModSettings.SpeechRecognitionLanguages.Keys.First());
            }
        }
Ejemplo n.º 3
0
        private void AddInput(OrderedDictionary <SettingCategory, OrderedDictionary <string, Setting> > settingcategories, StackPanel panel, SettingCategory category, string name, I18N.I18NString label, Setting value)
        {
            StackPanel inputPanel = new StackPanel()
            {
                Orientation = Orientation.Horizontal,
                Margin      = new Thickness(5),
            };

            inputPanel.Children.Add(new TextBlock()
            {
                TextWrapping = TextWrapping.NoWrap,
                Padding      = new Thickness(5),
                Margin       = new Thickness(5),
                Focusable    = true,
                MinWidth     = 150,
                Text         = I18N.Get(label)
            });

            if (value.AllowedValues.Count == 0)
            {
                var textbox = MakeTextBox(value);
                textbox.TextChanged += (object sender, TextChangedEventArgs e) =>
                {
                    HLVRSettingsManager.TrySetSetting(settingcategories, category, name, textbox.Text);
                };
                inputPanel.Children.Add(textbox);

                if (value.Type == SettingType.SPEED || value.Type == SettingType.DISTANCE)
                {
                    var meterTextbox = MakeTextBox(value);
                    meterTextbox.Text = UnitToMeter(textbox.Text);
                    bool preventinfiniteloop = false;
                    textbox.TextChanged += (object sender, TextChangedEventArgs e) =>
                    {
                        if (preventinfiniteloop)
                        {
                            return;
                        }
                        preventinfiniteloop = true;
                        meterTextbox.Text   = UnitToMeter(textbox.Text);
                        preventinfiniteloop = false;
                    };
                    meterTextbox.TextChanged += (object sender, TextChangedEventArgs e) =>
                    {
                        if (preventinfiniteloop)
                        {
                            return;
                        }
                        preventinfiniteloop = true;
                        textbox.Text        = MeterToUnit(meterTextbox.Text);
                        preventinfiniteloop = false;
                    };
                    inputPanel.Children.Add(CreateMiniText(value.Type == SettingType.SPEED ? "units/s" : "units"));
                    inputPanel.Children.Add(meterTextbox);
                    inputPanel.Children.Add(CreateMiniText(value.Type == SettingType.SPEED ? "cm/s" : "cm"));

                    inputPanel.Children.Add(CreateDefaultLabel(value.DefaultValue + "/" + UnitToMeter(value.DefaultValue)));
                }
                else
                {
                    inputPanel.Children.Add(CreateDefaultLabel(value.DefaultValue));
                }
            }
            else
            {
                var combobox = new ComboBox()
                {
                    MinWidth = 200,
                };
                int             index         = 0;
                int             selectedIndex = 0;
                I18N.I18NString defaultValue  = null;
                foreach (var allowedValue in value.AllowedValues)
                {
                    var comboboxitem = new ComboBoxItem()
                    {
                    };
                    comboboxitem.Content = allowedValue.Value;
                    combobox.Items.Add(comboboxitem);
                    if (allowedValue.Key.Equals(value.Value))
                    {
                        selectedIndex = index;
                    }
                    if (allowedValue.Key.Equals(value.DefaultValue))
                    {
                        defaultValue = allowedValue.Value;
                    }
                    index++;
                }
                combobox.SelectedIndex     = selectedIndex;
                combobox.SelectionChanged += (object sender, SelectionChangedEventArgs e) =>
                {
                    HLVRSettingsManager.TrySetSetting(settingcategories, category, name, ((I18N.I18NString)(combobox.SelectedValue as ComboBoxItem).Content).Key);
                };
                inputPanel.Children.Add(combobox);

                if (defaultValue != null)
                {
                    inputPanel.Children.Add(CreateDefaultLabel(I18N.Get(defaultValue)));
                }
            }

            panel.Children.Add(inputPanel);
        }