using Avalonia; using Avalonia.Controls; using Avalonia.Data; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.VisualTree; using Mesen.Config; using Mesen.Utilities; using Mesen.ViewModels; using Mesen.Windows; using System; namespace Mesen.Controls { public class InputComboBox : UserControl { public static readonly StyledProperty ControllerTypeProperty = AvaloniaProperty.Register(nameof(ControllerType), defaultBindingMode: BindingMode.TwoWay); public static readonly StyledProperty ConfigProperty = AvaloniaProperty.Register(nameof(Config), defaultBindingMode: BindingMode.TwoWay); public static readonly StyledProperty PortProperty = AvaloniaProperty.Register(nameof(Port), 0); public static readonly StyledProperty AvailableValuesProperty = AvaloniaProperty.Register(nameof(AvailableValues)); public static readonly StyledProperty SetupEnabledProperty = AvaloniaProperty.Register(nameof(SetupEnabled)); public ControllerType ControllerType { get { return GetValue(ControllerTypeProperty); } set { SetValue(ControllerTypeProperty, value); } } public ControllerConfig Config { get { return GetValue(ConfigProperty); } set { SetValue(ConfigProperty, value); } } public bool SetupEnabled { get { return GetValue(SetupEnabledProperty); } set { SetValue(SetupEnabledProperty, value); } } public int Port { get { return GetValue(PortProperty); } set { SetValue(PortProperty, value); } } public Enum[] AvailableValues { get { return GetValue(AvailableValuesProperty); } set { SetValue(AvailableValuesProperty, value); } } static InputComboBox() { ControllerTypeProperty.Changed.AddClassHandler((x, e) => { x.SetupEnabled = x.ControllerType.CanConfigure(); }); } public InputComboBox() { InitializeComponent(); } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } private async void btnSetup_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; PixelPoint startPosition = btn.PointToScreen(new Point(-7, btn.Bounds.Height)); ControllerConfigWindow wnd = new ControllerConfigWindow(); ControllerConfig cfg = Config.Clone(); wnd.DataContext = new ControllerConfigViewModel(ControllerType, cfg, Config, Port); if(await wnd.ShowDialogAtPosition(btn.GetVisualRoot() as Visual, startPosition)) { Config = cfg; } } } }