Skip to content

Commit a75eff7

Browse files
Merge pull request #14 from DexrnZacAttack/main
experimental: extra controller stuff such as start button dialog
2 parents 7d23b41 + c2bd1ac commit a75eff7

4 files changed

Lines changed: 79 additions & 5 deletions

File tree

Controls/AppTile.xaml.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,41 @@ public AppTile(string familyName)
279279

280280
startButton.Tapped += (_, _) => StartApp();
281281
}
282+
283+
public async void ShowControllerInteractDialog()
284+
{
285+
ContentDialog dialog = new ContentDialog();
286+
dialog.XamlRoot = App.MainWindow.Content.XamlRoot;
287+
dialog.Title = _package.DisplayName;
288+
StackPanel optionsPanel = new StackPanel();
289+
optionsPanel.HorizontalAlignment = HorizontalAlignment.Center;
290+
dialog.Content = optionsPanel;
291+
292+
TextBlock textBlock = new TextBlock();
293+
textBlock.Text = "NON-FUNCTIONAL";
294+
295+
// todo: onclick for all
296+
297+
// we need to either move the uninstall options somewhere else or figure out a way to make it work with controller
298+
Button uninstallButton = new Button();
299+
uninstallButton.Content = "Uninstall";
300+
uninstallButton.Margin = new Thickness(0, 0, 0, 10);
301+
302+
Button manageSavesButton = new Button();
303+
manageSavesButton.Content = "Manage saves";
304+
manageSavesButton.Margin = new Thickness(0, 0, 0, 10);
305+
306+
Button manageModsButton = new Button();
307+
manageModsButton.Content = "Manage mods";
308+
manageModsButton.Margin = new Thickness(0, 0, 0, 10);
309+
310+
optionsPanel.Children.Add(textBlock);
311+
optionsPanel.Children.Add(uninstallButton);
312+
optionsPanel.Children.Add(manageSavesButton);
313+
optionsPanel.Children.Add(manageModsButton);
314+
315+
await dialog.ShowAsync();
316+
}
282317

283318

284319
public async void StartApp()

MainWindow.xaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ public sealed partial class MainWindow : Window
2020
public AppsListPage AppsListPage;
2121
public SettingsPage SettingsPage;
2222
public AboutPage AboutPage;
23+
public AppMode currentMode;
24+
25+
public enum AppMode
26+
{
27+
DESKTOP,
28+
CONTROLLER
29+
}
2330

2431
private void NavigationInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
2532
{
@@ -141,6 +148,12 @@ private void appTitleBar_SizeChanged(object sender, SizeChangedEventArgs e)
141148
}
142149
}
143150

151+
public void SwitchMode(AppMode mode)
152+
{
153+
currentMode = mode;
154+
navView.PaneDisplayMode = currentMode == AppMode.CONTROLLER ? NavigationViewPaneDisplayMode.Top : NavigationViewPaneDisplayMode.LeftCompact;
155+
}
156+
144157
private void SetupTitleBar()
145158
{
146159
AppWindowTitleBar titleBar = AppWindow.TitleBar;

Pages/AppsListPage.xaml.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,37 @@ public AppsListPage()
151151

152152
private void OnAppListPage_Loaded(object sender, RoutedEventArgs e)
153153
{
154-
Gamepad.GamepadAdded += onGamepadAdded;
154+
Gamepad.GamepadAdded += OnGamepadAdded;
155155
Gamepad.GamepadRemoved += OnGamepadRemoved;
156156
}
157157

158158
private void OnGamepadRemoved(object sender, Gamepad e)
159159
{
160+
Logger.WriteInformation("Controller disconnected");
160161
gamepad = null;
162+
this.DispatcherQueue.TryEnqueue(() =>
163+
{
164+
App.MainWindow.SwitchMode(MainWindow.AppMode.DESKTOP);
165+
});
161166
}
162167

163-
private void onGamepadAdded(object sender, Gamepad e)
168+
private void OnGamepadAdded(object sender, Gamepad e)
164169
{
170+
Logger.WriteInformation("Controller connected");
165171
gamepad = e;
166-
ListenGamepadInput();
167172
this.DispatcherQueue.TryEnqueue(() =>
168173
{
169174
if (appList.Children.Count > 0)
170175
{
171176
appList.Children[currentIndex].Focus(FocusState.Keyboard);
172177
}
178+
App.MainWindow.SwitchMode(MainWindow.AppMode.CONTROLLER);
173179
});
180+
ListenGamepadInput();
174181
}
175182

176183

184+
// can we make this work everywhere, like in content dialogs?
177185
private async void ListenGamepadInput()
178186
{
179187
while (gamepad != null)
@@ -183,9 +191,12 @@ private async void ListenGamepadInput()
183191
bool moveLeft = gamepadInput.LeftThumbstickX < -0.5 || (gamepadInput.Buttons & GamepadButtons.DPadLeft) != 0;
184192
bool moveUp = gamepadInput.LeftThumbstickY > 0.5 || (gamepadInput.Buttons & GamepadButtons.DPadUp) != 0;
185193
bool moveDown = gamepadInput.LeftThumbstickY < -0.5 || (gamepadInput.Buttons & GamepadButtons.DPadDown) != 0;
194+
bool start = (gamepadInput.Buttons & GamepadButtons.Menu) != 0; // start as in the button, not start package
195+
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)
186196
bool actionClicked = (gamepadInput.Buttons & GamepadButtons.A) != 0;
187197

188-
198+
// feel like we should have like event listeners or whatever
199+
// actionClicked += whatever
189200
if (actionClicked && inputProcessed)
190201
{
191202
inputProcessed = false;
@@ -197,6 +208,19 @@ private async void ListenGamepadInput()
197208
});
198209
}
199210

211+
// disabled until controller support works
212+
// also pressing start twice will crash cuz 2 contentdialogs
213+
//if (start && inputProcessed)
214+
//{
215+
// inputProcessed = false;
216+
// this.DispatcherQueue.TryEnqueue(() =>
217+
// {
218+
// var appTile = appList.Children[currentIndex] as AppTile;
219+
// appTile.ShowControllerInteractDialog();
220+
// inputProcessed = true;
221+
// });
222+
//}
223+
200224
if ((moveRight || moveLeft || moveUp || moveDown) && inputProcessed)
201225
{
202226
inputProcessed = false;
@@ -213,7 +237,7 @@ private async void ListenGamepadInput()
213237
private void MoveFocus(int xOffset, int yOffset)
214238
{
215239
bool firstInput = lastInput == 0;
216-
if (lastInput > DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - 200)
240+
if (lastInput > DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - 10)
217241
{
218242
inputProcessed = true;
219243
return;

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ For building you'll need Visual Studio 2022 with the following:
1919
- [X] Scan for already installed EraOS/XUWP stuff
2020
- [X] Allow for any existing installed package to be added to the applist
2121
- [ ] Built in updater
22+
- [ ] Controller support
23+
- [ ] Setup program (maybe MSIX?)
2224
- [ ] Fitting place for extra xbox-specific info
2325
- [ ] Resize content to fit to screen
2426
- [X] Allow for search

0 commit comments

Comments
 (0)