Skip to content

Commit

Permalink
Manual XInput index fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
FlavioFS committed Mar 4, 2023
1 parent 7600a97 commit 1dc8636
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
4 changes: 3 additions & 1 deletion ParsecSoda/MetadataCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ MetadataCache::Preferences MetadataCache::loadPreferences()
tryLoadUInt("fps", preferences.fps, 60);
tryLoadUInt("bandwidth", preferences.bandwidth, 20);
tryLoadUInt("xboxPuppetCount", preferences.xboxPuppetCount, 4);
tryLoadUInt("ds4PuppetCount", preferences.ds4PuppetCount, 0);
tryLoadUInt("ds4PuppetCount", preferences.ds4PuppetCount, 0);
tryLoadBool("autoXInputIndexFetching", preferences.autoXInputIndexFetching, false);
tryLoadBool("latencyLimiterEnabled", preferences.latencyLimiterEnabled, false);
tryLoadUInt("maxLatencyMs", preferences.maxLatencyMs, 100);
tryLoadUInt("hotseatDurationSeconds", preferences.hotseatDurationSeconds, 300);
Expand Down Expand Up @@ -229,6 +230,7 @@ bool MetadataCache::savePreferences(MetadataCache::Preferences preferences)
MTY_JSONObjSetUInt(json, "adapter", preferences.adapter);
MTY_JSONObjSetUInt(json, "xboxPuppetCount", preferences.xboxPuppetCount);
MTY_JSONObjSetUInt(json, "ds4PuppetCount", preferences.ds4PuppetCount);
MTY_JSONObjSetBool(json, "autoXInputIndexFetching", preferences.autoXInputIndexFetching);
MTY_JSONObjSetBool(json, "latencyLimiterEnabled", preferences.latencyLimiterEnabled);
MTY_JSONObjSetUInt(json, "maxLatencyMs", preferences.maxLatencyMs);
MTY_JSONObjSetUInt(json, "hotseatDurationSeconds", preferences.hotseatDurationSeconds);
Expand Down
1 change: 1 addition & 0 deletions ParsecSoda/MetadataCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MetadataCache
uint32_t bandwidth = 20;
uint32_t xboxPuppetCount = 4;
uint32_t ds4PuppetCount = 0;
bool autoXInputIndexFetching = false;
bool latencyLimiterEnabled = false;
uint32_t maxLatencyMs = 100;
uint32_t hotseatDurationSeconds = 300;
Expand Down
43 changes: 29 additions & 14 deletions ParsecSoda/Widgets/GamepadsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bool GamepadsWidget::render()

static ImVec2 cursor;
static bool isWindowLocked = false;
static bool isConnectionButtonPressed = false;
static bool isConnectionButtonPressed = false, refreshGamepads = false;
static ImVec2 dummySize = ImVec2(0.0f, 5.0f);
static string name, id, tooltipTitle, tooltipDescription;

Expand Down Expand Up @@ -42,7 +42,7 @@ bool GamepadsWidget::render()
userID = gi->owner.guest.userID;

ImGui::BeginGroup();
renderPadInputTypeIcon(gi);
renderPadInputTypeIcon(gi, i, refreshGamepads);

id = "###Connect gamepad" + to_string(i);
if (ToggleIconButtonWidget::render(AppIcons::padOn, AppIcons::padOff, gi->isConnected(), id.c_str()))
Expand Down Expand Up @@ -302,8 +302,9 @@ bool GamepadsWidget::render()
AppStyle::pop();


if (isConnectionButtonPressed)
if (refreshGamepads || (MetadataCache::preferences.autoXInputIndexFetching && isConnectionButtonPressed))
{
refreshGamepads = false;
isConnectionButtonPressed = false;
for (size_t i = 0; i < _gamepads.size(); ++i)
{
Expand Down Expand Up @@ -408,6 +409,16 @@ void GamepadsWidget::renderOptionsMenu()

if (ImGui::BeginPopupContextItem("Gamepad Options", ImGuiPopupFlags_MouseButtonLeft))
{
if (SwitchWidget::render(
MetadataCache::preferences.autoXInputIndexFetching,
"###Auto XInput Fetching switch", "Automatic XInput Fetching",
"Auto XInput Fetch [ON]", "XInput indices will be identified automatically.\n\nBeware! Enabling this may cause BSOD's for some users.",
"Auto XInput Fetch [OFF]", "XInput indices will be identified manually on button press.\n\nManual fetch is the safest option."
))
{
MetadataCache::savePreferences();
}

if (SwitchWidget::render(
MetadataCache::preferences.defaultMirrorValue,
"###Mirror default switch", "Default mirror",
Expand Down Expand Up @@ -450,7 +461,7 @@ void GamepadsWidget::renderOptionsMenu()
ImGui::PopStyleVar();
}

void GamepadsWidget::renderPadInputTypeIcon(AGamepad* pad)
void GamepadsWidget::renderPadInputTypeIcon(AGamepad* pad, const size_t& gamepadIndex, bool& refreshGamepads)
{
static ImVec2 cursor;
static const ImVec2 ICON_SIZE = ImVec2(40, 40);
Expand All @@ -476,29 +487,33 @@ void GamepadsWidget::renderPadInputTypeIcon(AGamepad* pad)
);

ImGui::SetCursorPos(cursor);
ImGui::Image(
xboxIcons[xboxIndex],
ICON_SIZE, ImVec2(0, 0), ImVec2(1, 1), AppColors::primary
);
if (IconButton::render(xboxIcons[xboxIndex], AppColors::primary, ICON_SIZE, (string("XInput index btn ") + to_string(gamepadIndex)).c_str()))
{
refreshGamepads = true;
}
TitleTooltipWidget::render(
(string() + "XInput " + to_string(padIndex)).c_str(),
(
string("This controller is using XInput slot ") + to_string(padIndex) + ".\n\n" +
string("")
+ "Press to identify XInput indices (this is visual only).\n\n"
+ "This controller is using XInput slot " + to_string(padIndex) + ".\n" +
"* Remember:\nYour physical controllers may also occupy XInput slots."
).c_str()
);

}
else
{
ImGui::Image(
AppIcons::xinput,
ICON_SIZE, ImVec2(0, 0), ImVec2(1, 1), AppColors::backgroundIcon
);
if (IconButton::render(AppIcons::xinput, AppColors::backgroundIcon, ICON_SIZE, (string("XInput index btn ") + to_string(gamepadIndex)).c_str()))
{
refreshGamepads = true;
}
TitleTooltipWidget::render(
(string() + "XBox controller").c_str(),
(
string("This is an XBox controller out of XInput range.") + "\n\n" +
string("") +
+ "Press to identify XInput indices (this is visual only).\n\n"
+ "This is an XBox controller out of XInput range." + "\n" +
"* It still works, but as a generic controller without XInput features."
).c_str()
);
Expand Down
2 changes: 1 addition & 1 deletion ParsecSoda/Widgets/GamepadsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GamepadsWidget
private:
void renderTopBar(bool& isWindowLocked, const ImVec2& windowSize);
void renderOptionsMenu();
void renderPadInputTypeIcon(AGamepad* pad);
void renderPadInputTypeIcon(AGamepad* pad, const size_t& gamepadIndex, bool& refreshGamepads);

// Dependency injection
Hosting& _hosting;
Expand Down
2 changes: 1 addition & 1 deletion ParsecSoda/Widgets/VersionWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool VersionWidget::render()
ImGui::SetNextWindowSize(ImVec2(100, 32));
ImGui::Begin("##Version", (bool*)0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBringToFrontOnFocus);
AppStyle::pushLabel();
ImGui::Text("v. 1.2.7");
ImGui::Text("v. 1.2.8");
AppStyle::pop();
ImGui::End();

Expand Down

0 comments on commit 1dc8636

Please sign in to comment.