more wrappers and helpers!

This commit is contained in:
SimoZ64
2025-04-29 22:40:07 +02:00
parent b319255178
commit 730f5bed24
11 changed files with 194 additions and 89 deletions

View File

@@ -2,13 +2,14 @@
#include <log.hpp>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_keycode.h>
InputSettings::InputSettings(nlohmann::json &settings) : settings(settings) {
for(auto& kb : kbButtons) {
kb.setLabel(JSONGetField<std::string>(settings, "input", kb.getName()));
}
devices.addItem("Keyboard/Mouse");
devices.addItem({"Keyboard/Mouse"});
/* TODO: GAMEPAD STUFF IDK HOW TO HANDLE YET
connect(devices.get(), &QComboBox::currentTextChanged, this, [&](const QString &text) {
@@ -51,16 +52,16 @@ void InputSettings::keyPressEvent(QKeyEvent *e) {
if (grabbing) {
const auto k = QKeySequence(e->key()).toString().toStdString();
JSONSetField<std::string>(settings, "input", buttonLabels[whichGrabbing]->text().toStdString(), k);
kbButtons[whichGrabbing]->setText(k.c_str());
devices->setEnabled(true);
kbButtons[whichGrabbing].setText(k.c_str());
devices.setEnabled(true);
for (const auto &kbButton : kbButtons) {
kbButton->setEnabled(true);
kbButton.setEnabled(true);
}
grabbing = false;
whichGrabbing = -1;
if (devices->currentText() == "Keyboard/Mouse") {
if (devices.currentText() == "Keyboard/Mouse") {
releaseKeyboard();
emit modified();
}
@@ -73,16 +74,15 @@ std::array<SDL_Keycode, 18> InputSettings::GetMappedKeys() {
int i = 0;
for (const auto& kb : kbButtons) {
for (auto& kb : kbButtons) {
ret[i++] = SDL_GetKeyFromName(kb.getLabel().c_str());
}
return ret;
}
/*TODO: RECREATE THIS IN SDL
void InputSettings::QueryDevices() noexcept {
if (!devices->isEnabled())
if (!devices.isEnabled())
return;
SDL_Event e;
@@ -102,17 +102,17 @@ void InputSettings::QueryDevices() noexcept {
if (!gamepadIndexes.contains(index)) {
gamepadIndexes[index] = name;
}
devices->addItem(name);
devices.addItem({name});
} else if (serial) {
if (!gamepadIndexes.contains(index)) {
gamepadIndexes[index] = serial;
}
devices->addItem(serial);
devices.addItem({serial});
} else if (path) {
if (!gamepadIndexes.contains(index)) {
gamepadIndexes[index] = path;
}
devices->addItem(path);
devices.addItem({path});
}
SDL_CloseGamepad(gamepad);
@@ -123,13 +123,14 @@ void InputSettings::QueryDevices() noexcept {
const auto index = e.gdevice.which;
if (gamepadIndexes.contains(index))
devices->removeItem(devices->findText(gamepadIndexes[index].c_str()));
devices.removeItem(gamepadIndexes[index]);
}
break;
}
}
}
/*
void InputSettings::PollGamepad() noexcept {
if (!selectedDeviceIsNotKeyboard)
return;
@@ -141,16 +142,16 @@ void InputSettings::PollGamepad() noexcept {
{
const auto k = SDL_GetGamepadStringForButton(static_cast<SDL_GamepadButton>(e.gbutton.button));
JSONSetField<std::string>(settings, "input", buttonLabels[whichGrabbing]->text().toStdString(), k);
kbButtons[whichGrabbing]->setText(k);
devices->setEnabled(true);
kbButtons[whichGrabbing].setText(k);
devices.setEnabled(true);
for (const auto &kbButton : kbButtons) {
kbButton->setEnabled(true);
kbButton.setEnabled(true);
}
grabbing = false;
whichGrabbing = -1;
emit modified();
modified = true;
}
break;
default: