示例#1
0
 private void CheckBox_HapticFeedback_Checked(object sender, RoutedEventArgs e)
 {
     MainModel.UpdateSetting(MainModel.Setting.Haptic, CheckboxValue(e));
 }
示例#2
0
 private void CheckBox_DebugNotifications_Checked(object sender, RoutedEventArgs e)
 {
     MainModel.UpdateSetting(MainModel.Setting.Notification, CheckboxValue(e));
 }
示例#3
0
 private void CheckBox_ExitWithSteamVR_Checked(object sender, RoutedEventArgs e)
 {
     MainModel.UpdateSetting(MainModel.Setting.ExitWithSteam, CheckboxValue(e));
 }
示例#4
0
 private void CheckBox_Tray_Checked(object sender, RoutedEventArgs e)
 {
     MainModel.UpdateSetting(MainModel.Setting.Tray, CheckboxValue(e));
 }
示例#5
0
        public MainWindow()
        {
            InitWindow();
            InitializeComponent();
            Title = Properties.Resources.AppName;

            // Prevent multiple instances running at once
            _mutex = new Mutex(true, Properties.Resources.AppName, out bool createdNew);
            if (!createdNew)
            {
                MessageBox.Show(
                    Application.Current.MainWindow,
                    "This application is already running!",
                    Properties.Resources.AppName,
                    MessageBoxButton.OK,
                    MessageBoxImage.Information
                    );
                Application.Current.Shutdown();
            }


            _controller = new MainController
            {
                // Reports on the status of OpenVR
                StatusUpdateAction = (connected) =>
                {
                    Debug.WriteLine($"Status Update Action: connected={connected}");
                    var message = connected ? "Connected" : "Disconnected";
                    var color   = connected ? Brushes.OliveDrab : Brushes.Tomato;
                    Dispatcher.Invoke(() =>
                    {
                        Label_OpenVR.Content    = message;
                        Label_OpenVR.Background = color;
                        if (!connected && _initDone && MainModel.LoadSetting(MainModel.Setting.ExitWithSteam))
                        {
                            if (_notifyIcon != null)
                            {
                                _notifyIcon.Dispose();
                            }
                            System.Windows.Application.Current.Shutdown();
                        }
                    });
                },

                // Triggered when a new scene app is detected
                AppUpdateAction = (appId) =>
                {
                    Debug.WriteLine($"App Update Action: appId={appId}");
                    _currentlyRunningAppId = appId;
                    var color = Brushes.OliveDrab;
                    if (appId == MainModel.CONFIG_DEFAULT)
                    {
                        color = Brushes.Gray;
                    }
                    var appIdFixed = appId.Replace("_", "__"); // Single underscores makes underlined chars
                    Dispatcher.Invoke(() =>
                    {
                        Debug.WriteLine($"Setting AppID to: {appId}");
                        Label_Application.Content    = appIdFixed;
                        Label_Application.Background = color;
                    });
                },

                // We should update the text on the current binding we are recording
                KeyTextUpdateAction = (keyText, cancel) =>
                {
                    Debug.WriteLine($"Key Text Update Action: keyText={keyText}");
                    Dispatcher.Invoke(() =>
                    {
                        if (_activeElement != null)
                        {
                            (_activeElement as Label).Content = keyText;
                            if (cancel)
                            {
                                UpdateLabel(_activeElement as Label, false);
                            }
                        }
                    });
                },

                // We have loaded a config
                ConfigRetrievedAction = (config, forceButtonOff) =>
                {
                    var loaded = config != null;
                    if (loaded)
                    {
                        Debug.WriteLine($"Config Retrieved Action: count()={config.Count}");
                    }
                    Dispatcher.Invoke(() =>
                    {
                        if (loaded)
                        {
                            InitList(config);
                        }
                        UpdateConfigButton(loaded, forceButtonOff);
                    });
                },

                KeyActivatedAction = (key, on) =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        if (!_dashboardIsVisible)
                        {
                            if (on)
                            {
                                _activeKeys.Add(key);
                            }
                            else
                            {
                                _activeKeys.Remove(key);
                            }
                            if (_activeKeys.Count > 0)
                            {
                                Label_Keys.Content = string.Join(", ", _activeKeys);
                            }
                            else
                            {
                                Label_Keys.Content = "None";
                            }
                            Label_Keys.ToolTip    = "";
                            Label_Keys.Background = Brushes.Gray;
                        }
                    });
                },

                // Dashboard Visible
                DashboardVisibleAction = (visible) => {
                    Dispatcher.Invoke(() =>
                    {
                        _dashboardIsVisible = visible;
                        if (visible)
                        {
                            Label_Keys.Content    = "Blocked";
                            Label_Keys.ToolTip    = "The SteamVR Dashboard is visible which will block input from this application.";
                            Label_Keys.Background = Brushes.Tomato;
                        }
                        else
                        {
                            Label_Keys.Content    = "Unblocked";
                            Label_Keys.ToolTip    = "";
                            Label_Keys.Background = Brushes.Gray;
                        }
                    });
                }
            };

            // Receives error messages from OpenVR
            _controller.SetDebugLogAction((message) =>
            {
                Dispatcher.Invoke(() =>
                {
                    WriteToLog(message);
                });
            });

            // Init the things
            var actionKeys = InitList();

            _controller.Init(actionKeys);
            InitSettings();
            InitTrayIcon();
            _initDone = true;
        }