public DeviceStatus(DeviceInfo info, CommonStream stream = null)
        {
            InitializeComponent();

            Info = info;

            if (info.InstanceGUID.Equals(Guid.Empty))
            {
                if (stream == null)
                {
                    Ninty = new NintyControl(Info);
                }
                else
                {
                    Ninty = new NintyControl(Info, stream);
                }

                Ninty.OnTypeChange  += Ninty_OnTypeChange;
                Ninty.OnDisconnect  += Ninty_OnDisconnect;
                Ninty.OnPrefsChange += Ninty_OnPrefsChange;
                Ninty.OnRumbleSubscriptionChange += Ninty_OnRumbleSubscriptionChange;

                // Use saved icon if there is one
                var prefs = AppPrefs.Instance.GetDevicePreferences(Info.DevicePath);
                if (prefs != null && !string.IsNullOrWhiteSpace(prefs.icon))
                {
                    icon.Source      = new BitmapImage(new Uri("../Images/Icons/" + prefs.icon, UriKind.Relative));
                    nickname.Content = string.IsNullOrWhiteSpace(prefs.nickname) ? info.Type.ToName() : prefs.nickname;
                }
                else
                {
                    UpdateType(info.Type);
                }
            }
            else
            {
                Joy = new JoyControl(Info);
                Joy.OnDisconnect  += Ninty_OnDisconnect;
                Joy.OnPrefsChange += Ninty_OnPrefsChange;
                nickname.Content   = JoyControl.ToName(Joy.Type);
                if (info.VID == "057e" && info.PID == "2006")
                {
                    icon.Source = new BitmapImage(new Uri("../Images/Icons/switch_jcl_black.png", UriKind.Relative));
                }
                else if (info.VID == "057e" && info.PID == "2007")
                {
                    icon.Source = new BitmapImage(new Uri("../Images/Icons/switch_jcr_black.png", UriKind.Relative));
                }
                else if (info.VID == "057e" && info.PID == "2009")
                {
                    icon.Source = new BitmapImage(new Uri("../Images/Icons/switch_pro_black.png", UriKind.Relative));
                }
                else
                {
                    icon.Source = new BitmapImage(new Uri("../Images/Icons/joystick_icon.png", UriKind.Relative));
                }
            }
        }
Ejemplo n.º 2
0
        /***********
         * The strategy here is once the program launches, it will gather all controller paths
         * and all saved information on each device and use what was saved about the device
         * to help populate details on each tab. The users can click on each tab and then
         * attempt to connect that controller then they are good to go.
         */

        private void AddController(object sender, MouseButtonEventArgs e)
        {
            // More testing
            TabItem test  = new TabItem();
            var     stack = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };

            stack.Children.Add(new Image()
            {
                Source              = new BitmapImage(new Uri("../Images/Icons/ProController_white_24.png", UriKind.Relative)),
                Height              = 12,
                Margin              = new Thickness(0, 0, 4, 0),
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            });
            stack.Children.Add(new TextBlock()
            {
                Text = "DUMMY " + tabControl.Items.Count.ToString()
            });
            test.Header = stack;
            NintyControl nin = new NintyControl(new Shared.DeviceInfo()
            {
                DevicePath = "Dummy", Type = NintrollerLib.ControllerType.ProController
            });

            nin.OnTypeChange += (NintrollerLib.ControllerType type) =>
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    ((Image)stack.Children[0]).Source = new BitmapImage(new Uri("../Images/Icons/ProController_black_24.png", UriKind.Relative));
                }));
            };
            test.Content = nin;
            tabControl.Items.Insert(tabControl.Items.Count - 1, test);
            tabControl.SelectedIndex = tabControl.Items.Count - 2;
            nin.Connect();
        }