diff --git a/Controls/AppTile.xaml.cs b/Controls/AppTile.xaml.cs index 968d3d7..d57e620 100644 --- a/Controls/AppTile.xaml.cs +++ b/Controls/AppTile.xaml.cs @@ -279,6 +279,41 @@ public AppTile(string familyName) startButton.Tapped += (_, _) => StartApp(); } + + public async void ShowControllerInteractDialog() + { + ContentDialog dialog = new ContentDialog(); + dialog.XamlRoot = App.MainWindow.Content.XamlRoot; + dialog.Title = _package.DisplayName; + StackPanel optionsPanel = new StackPanel(); + optionsPanel.HorizontalAlignment = HorizontalAlignment.Center; + dialog.Content = optionsPanel; + + TextBlock textBlock = new TextBlock(); + textBlock.Text = "NON-FUNCTIONAL"; + + // todo: onclick for all + + // we need to either move the uninstall options somewhere else or figure out a way to make it work with controller + Button uninstallButton = new Button(); + uninstallButton.Content = "Uninstall"; + uninstallButton.Margin = new Thickness(0, 0, 0, 10); + + Button manageSavesButton = new Button(); + manageSavesButton.Content = "Manage saves"; + manageSavesButton.Margin = new Thickness(0, 0, 0, 10); + + Button manageModsButton = new Button(); + manageModsButton.Content = "Manage mods"; + manageModsButton.Margin = new Thickness(0, 0, 0, 10); + + optionsPanel.Children.Add(textBlock); + optionsPanel.Children.Add(uninstallButton); + optionsPanel.Children.Add(manageSavesButton); + optionsPanel.Children.Add(manageModsButton); + + await dialog.ShowAsync(); + } public async void StartApp() diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 26ce374..918a2bc 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -20,6 +20,13 @@ public sealed partial class MainWindow : Window public AppsListPage AppsListPage; public SettingsPage SettingsPage; public AboutPage AboutPage; + public AppMode currentMode; + + public enum AppMode + { + DESKTOP, + CONTROLLER + } private void NavigationInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args) { @@ -141,6 +148,12 @@ private void appTitleBar_SizeChanged(object sender, SizeChangedEventArgs e) } } + public void SwitchMode(AppMode mode) + { + currentMode = mode; + navView.PaneDisplayMode = currentMode == AppMode.CONTROLLER ? NavigationViewPaneDisplayMode.Top : NavigationViewPaneDisplayMode.LeftCompact; + } + private void SetupTitleBar() { AppWindowTitleBar titleBar = AppWindow.TitleBar; diff --git a/Pages/AppsListPage.xaml.cs b/Pages/AppsListPage.xaml.cs index 0ddbc39..aff1b69 100644 --- a/Pages/AppsListPage.xaml.cs +++ b/Pages/AppsListPage.xaml.cs @@ -151,29 +151,37 @@ public AppsListPage() private void OnAppListPage_Loaded(object sender, RoutedEventArgs e) { - Gamepad.GamepadAdded += onGamepadAdded; + Gamepad.GamepadAdded += OnGamepadAdded; Gamepad.GamepadRemoved += OnGamepadRemoved; } private void OnGamepadRemoved(object sender, Gamepad e) { + Logger.WriteInformation("Controller disconnected"); gamepad = null; + this.DispatcherQueue.TryEnqueue(() => + { + App.MainWindow.SwitchMode(MainWindow.AppMode.DESKTOP); + }); } - private void onGamepadAdded(object sender, Gamepad e) + private void OnGamepadAdded(object sender, Gamepad e) { + Logger.WriteInformation("Controller connected"); gamepad = e; - ListenGamepadInput(); this.DispatcherQueue.TryEnqueue(() => { if (appList.Children.Count > 0) { appList.Children[currentIndex].Focus(FocusState.Keyboard); } + App.MainWindow.SwitchMode(MainWindow.AppMode.CONTROLLER); }); + ListenGamepadInput(); } + // can we make this work everywhere, like in content dialogs? private async void ListenGamepadInput() { while (gamepad != null) @@ -183,9 +191,12 @@ private async void ListenGamepadInput() bool moveLeft = gamepadInput.LeftThumbstickX < -0.5 || (gamepadInput.Buttons & GamepadButtons.DPadLeft) != 0; bool moveUp = gamepadInput.LeftThumbstickY > 0.5 || (gamepadInput.Buttons & GamepadButtons.DPadUp) != 0; bool moveDown = gamepadInput.LeftThumbstickY < -0.5 || (gamepadInput.Buttons & GamepadButtons.DPadDown) != 0; + bool start = (gamepadInput.Buttons & GamepadButtons.Menu) != 0; // start as in the button, not start package + bool view = (gamepadInput.Buttons & GamepadButtons.View) != 0; // TODO: on click it should switch between the navigationview, bottom docked bar, and apps list (needs handling for other pages) bool actionClicked = (gamepadInput.Buttons & GamepadButtons.A) != 0; - + // feel like we should have like event listeners or whatever + // actionClicked += whatever if (actionClicked && inputProcessed) { inputProcessed = false; @@ -197,6 +208,19 @@ private async void ListenGamepadInput() }); } + // disabled until controller support works + // also pressing start twice will crash cuz 2 contentdialogs + //if (start && inputProcessed) + //{ + // inputProcessed = false; + // this.DispatcherQueue.TryEnqueue(() => + // { + // var appTile = appList.Children[currentIndex] as AppTile; + // appTile.ShowControllerInteractDialog(); + // inputProcessed = true; + // }); + //} + if ((moveRight || moveLeft || moveUp || moveDown) && inputProcessed) { inputProcessed = false; @@ -213,7 +237,7 @@ private async void ListenGamepadInput() private void MoveFocus(int xOffset, int yOffset) { bool firstInput = lastInput == 0; - if (lastInput > DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - 200) + if (lastInput > DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - 10) { inputProcessed = true; return; diff --git a/README.md b/README.md index e1bb894..7b737d7 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ For building you'll need Visual Studio 2022 with the following: - [X] Scan for already installed EraOS/XUWP stuff - [X] Allow for any existing installed package to be added to the applist - [ ] Built in updater + - [ ] Controller support + - [ ] Setup program (maybe MSIX?) - [ ] Fitting place for extra xbox-specific info - [ ] Resize content to fit to screen - [X] Allow for search