mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-12-22 16:18:50 -05:00
Added 'Auto' controller backend (#850)
This commit is contained in:
parent
50bc5de2da
commit
d180b8a299
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Window.h"
|
||||
#include "Controller.h"
|
||||
#include "DisconnectedController.h"
|
||||
#include "VirtualController.h"
|
||||
#include "KeyboardController.h"
|
||||
#include "SDLController.h"
|
||||
#include <Utils/StringHelper.h>
|
||||
@ -27,8 +27,9 @@ void Ship::ControlDeck::ScanPhysicalDevices() {
|
||||
}
|
||||
}
|
||||
|
||||
physicalDevices.push_back(std::make_shared<VirtualController>("Auto", "Auto", true));
|
||||
physicalDevices.push_back(std::make_shared<KeyboardController>());
|
||||
physicalDevices.push_back(std::make_shared<DisconnectedController>());
|
||||
physicalDevices.push_back(std::make_shared<VirtualController>("Disconnected", "None", false));
|
||||
|
||||
for (const auto& device : physicalDevices) {
|
||||
for (int i = 0; i < MAXCONTROLLERS; i++) {
|
||||
@ -51,7 +52,14 @@ void Ship::ControlDeck::SetPhysicalDevice(int slot, int deviceSlot) {
|
||||
|
||||
void Ship::ControlDeck::WriteToPad(OSContPad* pad) const {
|
||||
for (size_t i = 0; i < virtualDevices.size(); i++) {
|
||||
physicalDevices[virtualDevices[i]]->Read(&pad[i], 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ namespace Ship {
|
||||
|
||||
float size = 40;
|
||||
bool readingMode = BtnReading == n64Btn;
|
||||
bool disabled = BtnReading != -1 && !readingMode || !backend->Connected();
|
||||
bool disabled = (BtnReading != -1 && !readingMode) || !backend->Connected() || backend->GetGuid() == "Auto";
|
||||
ImVec2 len = ImGui::CalcTextSize(label);
|
||||
ImVec2 pos = ImGui::GetCursorPos();
|
||||
ImGui::SetCursorPosY(pos.y + len.y / 4);
|
||||
@ -90,7 +90,7 @@ namespace Ship {
|
||||
std::shared_ptr<Controller> Backend = devices[vDevices[CurrentPort]];
|
||||
DeviceProfile& profile =Backend->profiles[CurrentPort];
|
||||
float sensitivity = profile.Thresholds[SENSITIVITY];
|
||||
bool IsKeyboard = Backend->GetGuid() == "Keyboard" || !Backend->Connected();
|
||||
bool IsKeyboard = Backend->GetGuid() == "Keyboard" || Backend->GetGuid() == "Auto" || !Backend->Connected();
|
||||
const char* ControllerName = Backend->GetControllerName();
|
||||
|
||||
if (ControllerName != nullptr && ImGui::BeginCombo("##ControllerEntries", ControllerName)) {
|
||||
|
@ -4,18 +4,20 @@
|
||||
|
||||
#include "Controller.h"
|
||||
|
||||
class DisconnectedController final : public Ship::Controller {
|
||||
class VirtualController final : public Ship::Controller {
|
||||
public:
|
||||
DisconnectedController() {
|
||||
GUID = "Disconnected";
|
||||
VirtualController(const std::string& CUID, const std::string& KeyName, bool Connected) {
|
||||
GUID = CUID;
|
||||
isConnected = Connected;
|
||||
ButtonName = KeyName;
|
||||
}
|
||||
|
||||
std::map<std::vector<std::string>, int32_t> ReadButtonPress();
|
||||
void ReadFromSource(int32_t slot) override {}
|
||||
const char* GetControllerName() override { return "Disconnected"; }
|
||||
const char* GetButtonName(int slot, int n64Button) override { return "None"; }
|
||||
const char* GetControllerName() override { return GUID.c_str(); }
|
||||
const char* GetButtonName(int slot, int n64Button) override { return ButtonName.c_str(); }
|
||||
void WriteToSource(int32_t slot, ControllerCallback* controller) override { }
|
||||
bool Connected() const override { return false; }
|
||||
bool Connected() const override { return isConnected; }
|
||||
bool CanRumble() const override { return false; }
|
||||
bool CanGyro() const override { return false; }
|
||||
|
||||
@ -25,6 +27,8 @@ public:
|
||||
std::optional<std::string> GetPadConfSection() { return "Unk"; }
|
||||
void CreateDefaultBinding(int32_t slot) override {}
|
||||
protected:
|
||||
std::string ButtonName;
|
||||
bool isConnected = false;
|
||||
std::string GetControllerType() { return "Unk"; }
|
||||
std::string GetConfSection() { return "Unk"; }
|
||||
std::string GetBindingConfSection() { return "Unk"; }
|
@ -344,6 +344,7 @@
|
||||
<ClCompile Include="SDLController.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="VirtualController.h" />
|
||||
<ClInclude Include="Lib\Mercury\Mercury.h" />
|
||||
<ClInclude Include="Lib\nlohmann\json.hpp" />
|
||||
<ClInclude Include="abi.h" />
|
||||
@ -352,7 +353,6 @@
|
||||
<ClInclude Include="Blob.h" />
|
||||
<ClInclude Include="ControlDeck.h" />
|
||||
<ClInclude Include="Cvar.h" />
|
||||
<ClInclude Include="DisconnectedController.h" />
|
||||
<ClInclude Include="Environment.h" />
|
||||
<ClInclude Include="Factories\AudioFactory.h" />
|
||||
<ClInclude Include="InputEditor.h" />
|
||||
|
@ -674,14 +674,14 @@
|
||||
<ClInclude Include="ControlDeck.h">
|
||||
<Filter>Source Files\Controller</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DisconnectedController.h">
|
||||
<Filter>Source Files\Controller</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Lib\nlohmann\json.hpp">
|
||||
<Filter>Source Files\Lib\nlohmann</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Lib\Mercury\Mercury.h">
|
||||
<Filter>Source Files\Lib\Mercury</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="VirtualController.h">
|
||||
<Filter>Source Files\Controller</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user