Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed input disable to only be forced on switch #941

Merged
merged 10 commits into from
Aug 8, 2022
38 changes: 26 additions & 12 deletions libultraship/libultraship/ControlDeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "KeyboardController.h"
#include "SDLController.h"
#include <Utils/StringHelper.h>
#include "Cvar.h"

namespace Ship {
uint8_t* controllerBits;
Expand Down Expand Up @@ -51,18 +52,31 @@ namespace Ship {
*controllerBits |= (backend->Connected()) << slot;
}

void ControlDeck::WriteToPad(OSContPad* pad) const {
for (size_t i = 0; i < virtualDevices.size(); i++) {
const std::shared_ptr<Controller> backend = physicalDevices[virtualDevices[i]];
if (backend->GetGuid() == "Auto") {
for (const auto& device : physicalDevices) {
device->Read(&pad[i], i);
}
continue;
}
backend->Read(&pad[i], i);
}
}
void ControlDeck::WriteToPad(OSContPad* pad) const {

#ifdef __SWITCH__
bool shouldBlockGameInput = CVar_GetS32("gOpenMenuBar", 0);
#else
bool shouldBlockGameInput = CVar_GetS32("gOpenMenuBar", 0) && CVar_GetS32("gControlNav", 0);
#endif

for (size_t i = 0; i < virtualDevices.size(); i++) {
const std::shared_ptr<Controller> backend = physicalDevices[virtualDevices[i]];
if (backend->GetGuid() == "Auto") {
for (const auto& device : physicalDevices) {
if(shouldBlockGameInput && device->GetGuid() != "Keyboard") {
continue;
}
device->Read(&pad[i], i);
}
continue;
}
if(shouldBlockGameInput && backend->GetGuid() != "Keyboard") {
continue;
}
backend->Read(&pad[i], i);
}
}

#define NESTED(key, ...) StringHelper::Sprintf("Controllers.%s.Slot_%d." key, device->GetGuid().c_str(), slot, __VA_ARGS__)

Expand Down
13 changes: 10 additions & 3 deletions libultraship/libultraship/ImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,12 @@ namespace SohImGui {
GlobalCtx2::GetInstance()->GetWindow()->SetMenuBar(menu_bar);
ShowCursor(menu_bar, Dialogues::dMenubar);
GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->SaveControllerSettings();
if (CVar_GetS32("gControlNav", 0)) {
#ifdef __SWITCH__
bool enableControllerNavigation = true;
#else
bool enableControllerNavigation = CVar_GetS32("gControlNav", 0);
#endif
if (enableControllerNavigation) {
if (CVar_GetS32("gOpenMenuBar", 0)) {
io->ConfigFlags |=ImGuiConfigFlags_NavEnableGamepad | ImGuiConfigFlags_NavEnableKeyboard;
} else {
Expand Down Expand Up @@ -892,9 +897,11 @@ namespace SohImGui {

if (ImGui::BeginMenu("Controller"))
{

#ifndef __SWITCH__
KiritoDv marked this conversation as resolved.
Show resolved Hide resolved
EnhancementCheckbox("Use Controller Navigation", "gControlNav");
Tooltip("Allows controller navigation of the menu bar\nD-pad to move between items, A to select, and X to grab focus on the menu bar");

#endif
EnhancementCheckbox("Controller Configuration", "gControllerConfigurationEnabled");
controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0);

Expand Down Expand Up @@ -1347,7 +1354,7 @@ namespace SohImGui {
{
val = 20;
}

CVar_SetS32(fps_cvar, val);
needs_save = true;
}
Expand Down
7 changes: 3 additions & 4 deletions libultraship/libultraship/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <string>
#include <chrono>
#include "Console.h"
#include "Cvar.h"
#include "ImGuiImpl.h"

#include <iostream>

Expand Down Expand Up @@ -67,10 +67,9 @@ extern "C" {
pad->gyro_x = 0;
pad->gyro_y = 0;

if (!CVar_GetS32("gOpenMenuBar", 0)) {
Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->WriteToPad(pad);
}
if (SohImGui::controller->Opened) return;

Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->WriteToPad(pad);
Ship::ExecuteHooks<Ship::ControllerRead>(pad);
}

Expand Down