Skip to content

Commit

Permalink
UI: Fix diaglog popups doubling the window controls and laying text o…
Browse files Browse the repository at this point in the history
…ver the menu bar.
  • Loading branch information
GreemDev committed Oct 17, 2024
1 parent 045f9a3 commit 4300738
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 60 deletions.
6 changes: 3 additions & 3 deletions src/Ryujinx/UI/Applet/AvaHostUIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public bool DisplayInputDialog(SoftwareKeyboardUIArgs args, out string userText)
{
try
{
MainWindow.ViewModel.AppHost.NpadManager.BlockInputUpdates();
_parent.ViewModel.AppHost.NpadManager.BlockInputUpdates();
var response = await SwkbdAppletDialog.ShowInputDialog(LocaleManager.Instance[LocaleKeys.SoftwareKeyboard], args);

if (response.Result == UserResult.Ok)
Expand All @@ -144,7 +144,7 @@ public bool DisplayInputDialog(SoftwareKeyboardUIArgs args, out string userText)
});

dialogCloseEvent.WaitOne();
MainWindow.ViewModel.AppHost.NpadManager.UnblockInputUpdates();
_parent.ViewModel.AppHost.NpadManager.UnblockInputUpdates();

userText = error ? null : inputText;

Expand All @@ -154,7 +154,7 @@ public bool DisplayInputDialog(SoftwareKeyboardUIArgs args, out string userText)
public void ExecuteProgram(Switch device, ProgramSpecifyKind kind, ulong value)
{
device.Configuration.UserChannelPersistence.ExecuteProgram(kind, value);
MainWindow.ViewModel.AppHost?.Stop();
_parent.ViewModel.AppHost?.Stop();
}

public bool DisplayErrorAppletDialog(string title, string message, string[] buttons)
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void Dispose()
Dispatcher.UIThread.Post(() =>
{
_hiddenTextBox.Clear();
MainWindow.ViewModel.RendererHostControl.Focus();
_parent.ViewModel.RendererHostControl.Focus();

_parent = null;
});
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Applet/ErrorAppletWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Ryujinx.Ava.UI.Applet
{
internal partial class ErrorAppletWindow : StyleableWindow
internal partial class ErrorAppletWindow : StyleableAppWindow
{
private readonly Window _owner;
private object _buttonResponse;
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Helpers/ContentDialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async static Task<UserResult> ShowTextDialog(
}

public static Task<UserResult> ShowDeferredContentDialog(
StyleableWindow window,
Window window,
string title,
string primaryText,
string secondaryText,
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Models/SaveModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SaveModel(SaveDataInfo info)
TitleId = info.ProgramId;
UserId = info.UserId;

var appData = MainWindow.ViewModel.Applications.FirstOrDefault(x => x.IdString.Equals(TitleIdString, StringComparison.OrdinalIgnoreCase));
var appData = MainWindow.MainWindowViewModel.Applications.FirstOrDefault(x => x.IdString.Equals(TitleIdString, StringComparison.OrdinalIgnoreCase));

InGameList = appData != null;

Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/ViewModels/AmiiboWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AmiiboWindowViewModel : BaseModel, IDisposable
private readonly string _amiiboJsonPath;
private readonly byte[] _amiiboLogoBytes;
private readonly HttpClient _httpClient;
private readonly StyleableWindow _owner;
private readonly StyleableAppWindow _owner;

private Bitmap _amiiboImage;
private List<AmiiboApi> _amiiboList;
Expand All @@ -49,7 +49,7 @@ public class AmiiboWindowViewModel : BaseModel, IDisposable

private static readonly AmiiboJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());

public AmiiboWindowViewModel(StyleableWindow owner, string lastScannedAmiiboId, string titleId)
public AmiiboWindowViewModel(StyleableAppWindow owner, string lastScannedAmiiboId, string titleId)
{
_owner = owner;

Expand Down
16 changes: 5 additions & 11 deletions src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public InputViewModel(UserControl owner) : this()
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected;

MainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates();
_mainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates();

_isLoaded = false;

Expand Down Expand Up @@ -357,18 +357,12 @@ private void LoadInputDriver()

private void HandleOnGamepadDisconnected(string id)
{
Dispatcher.UIThread.Post(() =>
{
LoadDevices();
});
Dispatcher.UIThread.Post(LoadDevices);
}

private void HandleOnGamepadConnected(string id)
{
Dispatcher.UIThread.Post(() =>
{
LoadDevices();
});
Dispatcher.UIThread.Post(LoadDevices);
}

private string GetCurrentGamepadId()
Expand Down Expand Up @@ -847,7 +841,7 @@ public void Save()
}
}

MainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse);
_mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse);

// Atomically replace and signal input change.
// NOTE: Do not modify InputConfig.Value directly as other code depends on the on-change event.
Expand Down Expand Up @@ -879,7 +873,7 @@ public void Dispose()
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected -= HandleOnGamepadConnected;
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected -= HandleOnGamepadDisconnected;

MainWindow.ViewModel.AppHost?.NpadManager.UnblockInputUpdates();
_mainWindow.ViewModel.AppHost?.NpadManager.UnblockInputUpdates();

SelectedGamepad?.Dispose();

Expand Down
15 changes: 6 additions & 9 deletions src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,23 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)

if (VisualRoot is MainWindow window)
{
Window = window;
DataContext = ViewModel = window.ViewModel;
}

ViewModel = MainWindow.ViewModel;
DataContext = ViewModel;
}

private async void StopEmulation_Click(object sender, RoutedEventArgs e)
{
await MainWindow.ViewModel.AppHost?.ShowExitPrompt().OrCompleted()!;
await ViewModel.AppHost?.ShowExitPrompt().OrCompleted()!;
}

private void PauseEmulation_Click(object sender, RoutedEventArgs e)
{
MainWindow.ViewModel.AppHost?.Pause();
ViewModel.AppHost?.Pause();
}

private void ResumeEmulation_Click(object sender, RoutedEventArgs e)
{
MainWindow.ViewModel.AppHost?.Resume();
ViewModel.AppHost?.Resume();
}

public async void OpenSettings(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -178,15 +175,15 @@ public async void OpenCheatManagerForCurrentApp(object sender, RoutedEventArgs e
Window.VirtualFileSystem,
ViewModel.AppHost.Device.Processes.ActiveApplication.ProgramIdText,
name,
MainWindow.ViewModel.SelectedApplication.Path).ShowDialog(Window);
ViewModel.SelectedApplication.Path).ShowDialog(Window);

ViewModel.AppHost.Device.EnableCheats();
}

private void ScanAmiiboMenuItem_AttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e)
{
if (sender is MenuItem)
ViewModel.IsAmiiboRequested = MainWindow.ViewModel.AppHost.Device.System.SearchingForAmiibo(out _);
ViewModel.IsAmiiboRequested = ViewModel.AppHost.Device.System.SearchingForAmiibo(out _);
}

private async void InstallFileTypes_Click(object sender, RoutedEventArgs e)
Expand Down
11 changes: 5 additions & 6 deletions src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
if (VisualRoot is MainWindow window)
{
Window = window;
DataContext = window.ViewModel;
}

DataContext = MainWindow.ViewModel;
}

private void VsyncStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
{
MainWindow.ViewModel.AppHost.ToggleVSync();
Window.ViewModel.AppHost.ToggleVSync();

Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {MainWindow.ViewModel.AppHost.Device.EnableDeviceVsync}");
Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {Window.ViewModel.AppHost.Device.EnableDeviceVsync}");
}

private void DockedStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
Expand All @@ -57,9 +56,9 @@ private void Refresh_OnClick(object sender, RoutedEventArgs e)
private void VolumeStatus_OnPointerWheelChanged(object sender, PointerWheelEventArgs e)
{
// Change the volume by 5% at a time
float newValue = MainWindow.ViewModel.Volume + (float)e.Delta.Y * 0.05f;
float newValue = Window.ViewModel.Volume + (float)e.Delta.Y * 0.05f;

MainWindow.ViewModel.Volume = newValue switch
Window.ViewModel.Volume = newValue switch
{
< 0 => 0,
> 1 => 1,
Expand Down
5 changes: 2 additions & 3 deletions src/Ryujinx/UI/Views/Main/MainViewControls.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);

if (VisualRoot is MainWindow)
if (VisualRoot is MainWindow window)
{
ViewModel = MainWindow.ViewModel;
DataContext = ViewModel = window.ViewModel;
}

DataContext = ViewModel;
}

public void Sort_Checked(object sender, RoutedEventArgs args)
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/Windows/AmiiboWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<window:StyleableWindow
<window:StyleableAppWindow
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -72,4 +72,4 @@
Click="CancelButton_Click" />
</Grid>
</Grid>
</window:StyleableWindow>
</window:StyleableAppWindow>
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Ryujinx.Ava.UI.Windows
{
public partial class AmiiboWindow : StyleableWindow
public partial class AmiiboWindow : StyleableAppWindow
{
public AmiiboWindow(bool showAll, string lastScannedAmiiboId, string titleId)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/Windows/CheatWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<window:StyleableWindow
<window:StyleableAppWindow
x:Class="Ryujinx.Ava.UI.Windows.CheatWindow"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -123,4 +123,4 @@
</DockPanel>
</DockPanel>
</Grid>
</window:StyleableWindow>
</window:StyleableAppWindow>
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Windows/CheatWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Ryujinx.Ava.UI.Windows
{
public partial class CheatWindow : StyleableWindow
public partial class CheatWindow : StyleableAppWindow
{
private readonly string _enabledCheatsPath;
public bool NoCheatsFound { get; }
Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<window:StyleableWindow
<window:StyleableAppWindow
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -11,15 +11,15 @@
x:Class="Ryujinx.Ava.UI.Windows.ContentDialogOverlayWindow"
Title="ContentDialogOverlayWindow"
Focusable="False">
<window:StyleableWindow.Styles>
<window:StyleableAppWindow.Styles>
<Style Selector="ui|ContentDialog /template/ Panel#LayoutRoot">
<Setter Property="Background"
Value="Transparent" />
</Style>
</window:StyleableWindow.Styles>
</window:StyleableAppWindow.Styles>
<ui:ContentDialog Name="ContentDialog"
IsPrimaryButtonEnabled="True"
IsSecondaryButtonEnabled="True"
IsVisible="False"
Focusable="True"/>
</window:StyleableWindow>
</window:StyleableAppWindow>
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public ContentDialogOverlayWindow()
{
InitializeComponent();

TransparencyLevelHint = new[] { WindowTransparencyLevel.Transparent };
TransparencyLevelHint = [WindowTransparencyLevel.Transparent];
WindowStartupLocation = WindowStartupLocation.Manual;
SystemDecorations = SystemDecorations.None;
ExtendClientAreaTitleBarHeightHint = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/Windows/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<window:StyleableWindow
<window:StyleableAppWindow
x:Class="Ryujinx.Ava.UI.Windows.MainWindow"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -200,4 +200,4 @@
Grid.Row="2" />
</Grid>
</Grid>
</window:StyleableWindow>
</window:StyleableAppWindow>
12 changes: 7 additions & 5 deletions src/Ryujinx/UI/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@

namespace Ryujinx.Ava.UI.Windows
{
public partial class MainWindow : StyleableWindow
public partial class MainWindow : StyleableAppWindow
{
internal static MainWindowViewModel ViewModel { get; private set; }
internal static MainWindowViewModel MainWindowViewModel { get; private set; }

public MainWindowViewModel ViewModel { get; }

internal readonly AvaHostUIHandler UiHandler;

Expand Down Expand Up @@ -69,7 +71,7 @@ public partial class MainWindow : StyleableWindow

public MainWindow()
{
DataContext = ViewModel = new MainWindowViewModel();
DataContext = ViewModel = MainWindowViewModel = new MainWindowViewModel();

InitializeComponent();
Load();
Expand All @@ -78,8 +80,8 @@ public MainWindow()

ViewModel.Title = App.FormatTitle();

TitleBar.ExtendsContentIntoTitleBar = true;
TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex;
//TitleBar.ExtendsContentIntoTitleBar = true;
//TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex;


// NOTE: Height of MenuBar and StatusBar is not usable here, since it would still be 0 at this point.
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/Windows/SettingsWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<window:StyleableWindow
<window:StyleableAppWindow
x:Class="Ryujinx.Ava.UI.Windows.SettingsWindow"
xmlns="https://github.com/avaloniaui"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
Expand Down Expand Up @@ -127,4 +127,4 @@
Command="{Binding ApplyButton}" />
</ReversibleStackPanel>
</Grid>
</window:StyleableWindow>
</window:StyleableAppWindow>
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Ryujinx.Ava.UI.Windows
{
public partial class SettingsWindow : StyleableWindow
public partial class SettingsWindow : StyleableAppWindow
{
internal SettingsViewModel ViewModel { get; set; }

Expand Down
Loading

0 comments on commit 4300738

Please sign in to comment.