Beispiel #1
0
        public SetupWindow()
        {
            InitializeComponent();
            _vm              = new SetupWindowViewModel();
            DataContext      = _vm;
            _excludedSources = new List <string>();

            if (!Directory.Exists("skins"))
            {
                MessageBox.Show("Could not find skins folder!", "RetroSpy", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }

            Skin.LoadResults results = Skin.LoadAllSkinsFromParentFolder("skins");
            _skins = results.SkinsLoaded;

            _vm.Skins.UpdateContents(_skins.Where(x => x.Type == InputSource.DEFAULT));

            string[] hiddenConsoles = Properties.Settings.Default.HiddleConsoleList.Split(';');
            foreach (string source in hiddenConsoles)
            {
                if (source != "")
                {
                    _excludedSources.Add(source);
                }
            }

            PopulateSources();

            _vm.DelayInMilliseconds = Properties.Settings.Default.Delay;

            _vm.StaticViewerWindowName = Properties.Settings.Default.StaticViewerWindowName;

            _portListUpdateTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            _portListUpdateTimer.Tick += (sender, e) => UpdatePortList();
            _portListUpdateTimer.Start();

            _xiAndGamepadListUpdateTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(2)
            };
            _xiAndGamepadListUpdateTimer.Tick += (sender, e) =>
            {
                if (_vm.Sources.SelectedItem == InputSource.PAD)
                {
                    UpdateGamepadList();
                }
                else if (_vm.Sources.SelectedItem == InputSource.PC360)
                {
                    UpdateXIList();
                }
                //else if (_vm.Sources.SelectedItem == InputSource.XBOX)
                //{
                //    updateBeagleList();
                //}
                //else if (_vm.Sources.SelectedItem == InputSource.WII)
                //{
                //    updateBeagleI2CList();
                //}
            };
            _xiAndGamepadListUpdateTimer.Start();

            UpdatePortList();
            _vm.Ports.SelectIdFromText(Properties.Settings.Default.Port);
            _vm.Ports2.SelectIdFromText(Properties.Settings.Default.Port2);
            _vm.XIAndGamepad.SelectFirst();
            _vm.Sources.SelectId(Properties.Settings.Default.Source);
            _vm.Skins.SelectId(Properties.Settings.Default.Skin);
            _vm.Hostname = Properties.Settings.Default.Hostname;

            if (results.ParseErrors.Count > 0)
            {
                ShowSkinParseErrors(results.ParseErrors);
            }
        }
        public ViewWindow(Skin skin, Skin.Background skinBackground, IControllerReader reader, bool staticViewerWindowName)
        {
            InitializeComponent();
            DataContext = this;

            _skin   = skin;
            _reader = reader;

            if (staticViewerWindowName)
            {
                Title = "RetroSpy Viewer";
            }
            else
            {
                Title = skin.Name;
            }

            ControllerGrid.Width  = Width = _originalWidth = skinBackground.Width;
            ControllerGrid.Height = Height = _originalHeight = skinBackground.Height;
            var brush = new SolidColorBrush(skinBackground.Color);

            ControllerGrid.Background = brush;

            if (skinBackground.Image != null)
            {
                var img = new Image();
                img.VerticalAlignment   = VerticalAlignment.Top;
                img.HorizontalAlignment = HorizontalAlignment.Left;
                img.Source  = skinBackground.Image;
                img.Stretch = Stretch.Fill;
                img.Margin  = new Thickness(0, 0, 0, 0);
                img.Width   = skinBackground.Image.PixelWidth;
                img.Height  = skinBackground.Image.PixelHeight;

                ControllerGrid.Children.Add(img);
            }

            foreach (var detail in _skin.Details)
            {
                if (bgIsActive(skinBackground.Name, detail.Config.TargetBackgrounds, detail.Config.IgnoreBackgrounds))
                {
                    detail.Config.X = detail.Config.OriginalX;
                    detail.Config.Y = detail.Config.OriginalY;
                    var image = getImageForElement(detail.Config);
                    _detailsWithImages.Add(new Tuple <Skin.Detail, Image>(detail, image));
                    ControllerGrid.Children.Add(image);
                }
            }

            foreach (var trigger in _skin.AnalogTriggers)
            {
                if (bgIsActive(skinBackground.Name, trigger.Config.TargetBackgrounds, trigger.Config.IgnoreBackgrounds))
                {
                    trigger.Config.X = trigger.Config.OriginalX;
                    trigger.Config.Y = trigger.Config.OriginalY;
                    var grid = getGridForAnalogTrigger(trigger);
                    _triggersWithGridImages.Add(new Tuple <Skin.AnalogTrigger, Grid>(trigger, grid));
                    ControllerGrid.Children.Add(grid);
                }
            }

            foreach (var button in _skin.Buttons)
            {
                if (bgIsActive(skinBackground.Name, button.Config.TargetBackgrounds, button.Config.IgnoreBackgrounds))
                {
                    button.Config.X = button.Config.OriginalX;
                    button.Config.Y = button.Config.OriginalY;
                    var image = getImageForElement(button.Config);
                    _buttonsWithImages.Add(new Tuple <Skin.Button, Image>(button, image));
                    image.Visibility = Visibility.Hidden;
                    ControllerGrid.Children.Add(image);
                }
            }

            foreach (var button in _skin.RangeButtons)
            {
                if (bgIsActive(skinBackground.Name, button.Config.TargetBackgrounds, button.Config.IgnoreBackgrounds))
                {
                    button.Config.X = button.Config.OriginalX;
                    button.Config.Y = button.Config.OriginalY;
                    var image = getImageForElement(button.Config);
                    _rangeButtonsWithImages.Add(new Tuple <Skin.RangeButton, Image>(button, image));
                    image.Visibility = Visibility.Hidden;
                    ControllerGrid.Children.Add(image);
                }
            }

            foreach (var stick in _skin.AnalogSticks)
            {
                if (bgIsActive(skinBackground.Name, stick.Config.TargetBackgrounds, stick.Config.IgnoreBackgrounds))
                {
                    stick.Config.X = stick.Config.OriginalX;
                    stick.Config.Y = stick.Config.OriginalY;
                    stick.XRange   = stick.OriginalXRange;
                    stick.YRange   = stick.OriginalYRange;
                    var image = getImageForElement(stick.Config);
                    _sticksWithImages.Add(new Tuple <Skin.AnalogStick, Image>(stick, image));
                    if (stick.VisibilityName != "")
                    {
                        image.Visibility = Visibility.Hidden;
                    }
                    ControllerGrid.Children.Add(image);
                }
            }

            foreach (var touchpad in _skin.TouchPads)
            {
                if (bgIsActive(skinBackground.Name, touchpad.Config.TargetBackgrounds, touchpad.Config.IgnoreBackgrounds))
                {
                    touchpad.Config.X = touchpad.Config.OriginalX;
                    touchpad.Config.Y = touchpad.Config.OriginalY;
                    touchpad.XRange   = touchpad.OriginalXRange;
                    touchpad.YRange   = touchpad.OriginalYRange;
                    var image = getImageForElement(touchpad.Config);
                    _touchPadWithImages.Add(new Tuple <Skin.TouchPad, Image>(touchpad, image));
                    image.Visibility = Visibility.Hidden;
                    ControllerGrid.Children.Add(image);
                }
            }

            _reader.ControllerStateChanged += reader_ControllerStateChanged;
            _reader.ControllerDisconnected += reader_ControllerDisconnected;

            try {
                _keybindings = new Keybindings(Keybindings.XML_FILE_PATH, _reader);
            } catch (ConfigParseException) {
                MessageBox.Show("Error parsing keybindings.xml. Not binding any keys to gamepad inputs");
            }

            MassBlinkReductionEnabled   = Properties.Settings.Default.MassFilter;
            AnalogBlinkReductionEnabled = Properties.Settings.Default.AnalogFilter;
            ButtonBlinkReductionEnabled = Properties.Settings.Default.ButtonFilter;
            Topmost = Properties.Settings.Default.TopMost;
        }