Beispiel #1
0
        public ViewWindow(Skin skin, Skin.Background skinBackground, IControllerReader reader)
        {
            InitializeComponent();
            DataContext = this;

            _skin   = skin;
            _reader = reader;

            ControllerGrid.Width  = skinBackground.Image.PixelWidth;
            ControllerGrid.Height = skinBackground.Image.PixelHeight;

            var brush = new ImageBrush(skinBackground.Image);

            brush.Stretch             = Stretch.Uniform;
            ControllerGrid.Background = brush;

            foreach (var trigger in _skin.AnalogTriggers)
            {
                var grid = getGridForAnalogTrigger(trigger);
                _triggersWithGridImages.Add(new Tuple <Skin.AnalogTrigger, Grid> (trigger, grid));
                ControllerGrid.Children.Add(grid);
            }

            foreach (var button in _skin.Buttons)
            {
                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)
            {
                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)
            {
                var image = getImageForElement(stick.Config);
                _sticksWithImages.Add(new Tuple <Skin.AnalogStick, Image> (stick, image));
                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");
            }
        }
        public ViewWindow(Skin skin, Skin.Background skinBackground, IControllerReader reader)
        {
            InitializeComponent();
            DataContext = this;

            _skin   = skin;
            _reader = reader;

            ControllerGrid.Width  = skinBackground.Width;
            ControllerGrid.Height = 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.Uniform;
                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))
                {
                    var image = getImageForElement(detail.Config);
                    ControllerGrid.Children.Add(image);
                }
            }

            foreach (var trigger in _skin.AnalogTriggers)
            {
                if (bgIsActive(skinBackground.Name, trigger.Config.TargetBackgrounds, trigger.Config.IgnoreBackgrounds))
                {
                    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))
                {
                    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))
                {
                    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))
                {
                    var image = getImageForElement(stick.Config);
                    _sticksWithImages.Add(new Tuple <Skin.AnalogStick, Image>(stick, image));
                    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;
        }