Skip to content

Commit

Permalink
Add setting to enable/disable thumbsticks
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Aug 14, 2024
1 parent a47184f commit 31d7133
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
38 changes: 38 additions & 0 deletions CelestiaAppComponent/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ namespace winrt::CelestiaAppComponent::implementation
auto gamepadInvertYResult = propertySet.TryLookup(L"GamepadInvertY");
if (gamepadInvertYResult)
gamepadInvertY = unbox_value_or(gamepadInvertYResult, gamepadInvertY);
auto gamepadEnableLeftThumbstickResult = propertySet.TryLookup(L"GamepadEnableLeftThumbstick");
if (gamepadEnableLeftThumbstickResult)
gamepadEnableLeftThumbstick = unbox_value_or(gamepadEnableLeftThumbstickResult, gamepadEnableLeftThumbstick);
auto gamepadEnableRightThumbstickResult = propertySet.TryLookup(L"GamepadEnableRightThumbstick");
if (gamepadEnableRightThumbstickResult)
gamepadEnableRightThumbstick = unbox_value_or(gamepadEnableRightThumbstickResult, gamepadEnableRightThumbstick);
}

bool AppSettings::UseFullDPI()
Expand Down Expand Up @@ -288,6 +294,26 @@ namespace winrt::CelestiaAppComponent::implementation
gamepadInvertY = value;
}

bool AppSettings::GamepadEnableLeftThumbstick()
{
return gamepadEnableLeftThumbstick;
}

void AppSettings::GamepadEnableLeftThumbstick(bool value)
{
gamepadEnableLeftThumbstick = value;
}

bool AppSettings::GamepadEnableRightThumbstick()
{
return gamepadEnableRightThumbstick;
}

void AppSettings::GamepadEnableRightThumbstick(bool value)
{
gamepadEnableRightThumbstick = value;
}

void AppSettings::SetBoolean(CelestiaAppComponent::AppSettingBooleanEntry entry, bool value)
{
switch (entry)
Expand All @@ -307,6 +333,12 @@ namespace winrt::CelestiaAppComponent::implementation
case CelestiaAppComponent::AppSettingBooleanEntry::GamepadInvertY:
GamepadInvertY(value);
break;
case CelestiaAppComponent::AppSettingBooleanEntry::GamepadEnableLeftThumbstick:
GamepadEnableLeftThumbstick(value);
break;
case CelestiaAppComponent::AppSettingBooleanEntry::GamepadEnableRightThumbstick:
GamepadEnableRightThumbstick(value);
break;
case CelestiaAppComponent::AppSettingBooleanEntry::OnboardMessageDisplayed:
OnboardMessageDisplayed(value);
break;
Expand All @@ -329,6 +361,10 @@ namespace winrt::CelestiaAppComponent::implementation
return GamepadInvertX();
case CelestiaAppComponent::AppSettingBooleanEntry::GamepadInvertY:
return GamepadInvertY();
case CelestiaAppComponent::AppSettingBooleanEntry::GamepadEnableLeftThumbstick:
return GamepadEnableLeftThumbstick();
case CelestiaAppComponent::AppSettingBooleanEntry::GamepadEnableRightThumbstick:
return GamepadEnableRightThumbstick();
case CelestiaAppComponent::AppSettingBooleanEntry::OnboardMessageDisplayed:
return OnboardMessageDisplayed();
default:
Expand Down Expand Up @@ -488,5 +524,7 @@ namespace winrt::CelestiaAppComponent::implementation
settings.Values().Insert(L"GamepadRemapDpadRight", box_value(static_cast<int>(gamepadRemapDpadRight)));
settings.Values().Insert(L"GamepadInvertX", box_value(gamepadInvertX));
settings.Values().Insert(L"GamepadInvertY", box_value(gamepadInvertY));
settings.Values().Insert(L"GamepadEnableLeftThumbstick", box_value(gamepadEnableLeftThumbstick));
settings.Values().Insert(L"GamepadEnableRightThumbstick", box_value(gamepadEnableRightThumbstick));
}
}
8 changes: 8 additions & 0 deletions CelestiaAppComponent/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ namespace winrt::CelestiaAppComponent::implementation
bool GamepadInvertY();
void GamepadInvertY(bool);

bool GamepadEnableLeftThumbstick();
void GamepadEnableLeftThumbstick(bool);

bool GamepadEnableRightThumbstick();
void GamepadEnableRightThumbstick(bool);

void SetBoolean(CelestiaAppComponent::AppSettingBooleanEntry entry, bool value);
bool GetBoolean(CelestiaAppComponent::AppSettingBooleanEntry entry);
void SetInt32(CelestiaAppComponent::AppSettingInt32Entry entry, int32_t value);
Expand Down Expand Up @@ -106,6 +112,8 @@ namespace winrt::CelestiaAppComponent::implementation

bool gamepadInvertX{ false };
bool gamepadInvertY{ false };
bool gamepadEnableLeftThumbstick{ true };
bool gamepadEnableRightThumbstick{ true };
};
}

Expand Down
4 changes: 4 additions & 0 deletions CelestiaAppComponent/AppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace CelestiaAppComponent
OnboardMessageDisplayed,
GamepadInvertX,
GamepadInvertY,
GamepadEnableLeftThumbstick,
GamepadEnableRightThumbstick,
};

enum AppSettingInt32Entry
Expand Down Expand Up @@ -72,6 +74,8 @@ namespace CelestiaAppComponent

Boolean GamepadInvertX;
Boolean GamepadInvertY;
Boolean GamepadEnableLeftThumbstick;
Boolean GamepadEnableRightThumbstick;

void Save(Windows.Storage.ApplicationDataContainer settings);
}
Expand Down
14 changes: 12 additions & 2 deletions CelestiaAppComponent/GamepadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,18 @@ namespace winrt::CelestiaAppComponent::implementation
bool isDpadDownPressedNew = (int)(reading.Buttons & GamepadButtons::DPadDown) != 0;
bool isDpadLeftPressedNew = (int)(reading.Buttons & GamepadButtons::DPadLeft) != 0;
bool isDpadRightPressedNew = (int)(reading.Buttons & GamepadButtons::DPadRight) != 0;
double thumbstickX = reading.LeftThumbstickX + reading.RightThumbstickX;
double thumbstickY = reading.LeftThumbstickY + reading.RightThumbstickY;
double thumbstickX = 0.0;
double thumbstickY = 0.0;
if (appSettings.GamepadEnableLeftThumbstick())
{
thumbstickX = reading.LeftThumbstickX;
thumbstickY = reading.LeftThumbstickY;
}
if (appSettings.GamepadEnableRightThumbstick())
{
thumbstickX = reading.RightThumbstickX;
thumbstickY = reading.RightThumbstickY;
}
if (isAPressedNew != isAPressed)
{
isAPressed = isAPressedNew;
Expand Down
2 changes: 2 additions & 0 deletions CelestiaUWP/Settings/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ private void Nav_SelectionChanged(NavigationView sender, NavigationViewSelection
new AppSettingsInt32Item(LocalizationHelper.Localize("RB / R1", "Game controller button"), AppSettings, AppSettingInt32Entry.GamepadRemapRB, actions, localSettings),
new AppSettingsInt32Item(LocalizationHelper.Localize("RT / R2", "Game controller button"), AppSettings, AppSettingInt32Entry.GamepadRemapRT, actions, localSettings),
new SettingHeaderItem(LocalizationHelper.Localize("Thumbsticks", "Settings for game controller thumbsticks")),
new AppSettingsBooleanItem(LocalizationHelper.Localize("Enable Left Thumbstick", "Setting item to control whether left thumbstick should be enabled"), AppSettings, AppSettingBooleanEntry.GamepadEnableLeftThumbstick, localSettings),
new AppSettingsBooleanItem(LocalizationHelper.Localize("Enable Right Thumbstick", "Setting item to control whether right thumbstick should be enabled"), AppSettings, AppSettingBooleanEntry.GamepadEnableRightThumbstick, localSettings),
new AppSettingsBooleanItem(LocalizationHelper.Localize("Invert Horizontally", "Invert game controller thumbstick axis horizontally"), AppSettings, AppSettingBooleanEntry.GamepadInvertX, localSettings),
new AppSettingsBooleanItem(LocalizationHelper.Localize("Invert Vertically", "Invert game controller thumbstick axis vertically"), AppSettings, AppSettingBooleanEntry.GamepadInvertY, localSettings),
};
Expand Down

0 comments on commit 31d7133

Please sign in to comment.