|
|
|
|
@@ -10,24 +10,17 @@ InputSettings::InputSettings(nlohmann::json &settings) : settings(settings) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
devices.addItem({"Keyboard/Mouse"});
|
|
|
|
|
|
|
|
|
|
/* TODO: GAMEPAD STUFF IDK HOW TO HANDLE YET
|
|
|
|
|
connect(devices.get(), &QComboBox::currentTextChanged, this, [&](const QString &text) {
|
|
|
|
|
JSONSetField<std::string>(settings, "input", "Device", text.toStdString());
|
|
|
|
|
emit modified();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
|
|
|
|
|
|
|
|
|
connect(&refresh, &QTimer::timeout, this, &InputSettings::QueryDevices);
|
|
|
|
|
refresh.start(16);
|
|
|
|
|
|
|
|
|
|
connect(&pollGamepad, &QTimer::timeout, this, &InputSettings::PollGamepad);
|
|
|
|
|
pollGamepad.start(16);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InputSettings::render() {
|
|
|
|
|
if(devices.render()) {
|
|
|
|
|
auto currentlySelectedDevice = devices.getCurrentlySelected();
|
|
|
|
|
JSONSetField<std::string>(settings, "input", "Device", currentlySelectedDevice);
|
|
|
|
|
selectedDeviceIsNotKeyboard = currentlySelectedDevice == "Keyboard/Mouse";
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(auto& kb : kbButtons) {
|
|
|
|
|
if(kb.render()) {
|
|
|
|
|
@@ -35,10 +28,12 @@ bool InputSettings::render() {
|
|
|
|
|
for (auto &otherKb : kbButtons) {
|
|
|
|
|
otherKb.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
whichGrabbing = i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: ACTUALLY GRAB THE PRESSED INPUT
|
|
|
|
|
// ...
|
|
|
|
|
QueryDevices();
|
|
|
|
|
PollGamepad();
|
|
|
|
|
|
|
|
|
|
if(i % 2 != 0) // only go down every 2 buttons... just... i like it this way
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
@@ -47,28 +42,6 @@ bool InputSettings::render() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: RECREATE THIS IN SDL
|
|
|
|
|
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);
|
|
|
|
|
for (const auto &kbButton : kbButtons) {
|
|
|
|
|
kbButton.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grabbing = false;
|
|
|
|
|
whichGrabbing = -1;
|
|
|
|
|
|
|
|
|
|
if (devices.currentText() == "Keyboard/Mouse") {
|
|
|
|
|
releaseKeyboard();
|
|
|
|
|
emit modified();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
std::array<SDL_Keycode, 18> InputSettings::GetMappedKeys() {
|
|
|
|
|
std::array<SDL_Keycode, 18> ret{};
|
|
|
|
|
|
|
|
|
|
@@ -130,21 +103,20 @@ void InputSettings::QueryDevices() noexcept {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
void InputSettings::PollGamepad() noexcept {
|
|
|
|
|
if (!selectedDeviceIsNotKeyboard)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SDL_Event e;
|
|
|
|
|
while (SDL_PollEvent(&e)) {
|
|
|
|
|
switch (e.type) {
|
|
|
|
|
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
|
|
|
|
{
|
|
|
|
|
if (!selectedDeviceIsNotKeyboard)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
JSONSetField<std::string>(settings, "input", kbButtons[whichGrabbing].getName(), k);
|
|
|
|
|
kbButtons[whichGrabbing].setLabel(k);
|
|
|
|
|
devices.setEnabled(true);
|
|
|
|
|
for (const auto &kbButton : kbButtons) {
|
|
|
|
|
for (auto &kbButton : kbButtons) {
|
|
|
|
|
kbButton.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -154,9 +126,27 @@ void InputSettings::PollGamepad() noexcept {
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SDL_EVENT_KEY_DOWN:
|
|
|
|
|
{
|
|
|
|
|
if (selectedDeviceIsNotKeyboard)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const auto k = SDL_GetKeyName(e.key.key);
|
|
|
|
|
JSONSetField<std::string>(settings, "input", kbButtons[whichGrabbing].getName(), k);
|
|
|
|
|
kbButtons[whichGrabbing].setLabel(k);
|
|
|
|
|
devices.setEnabled(true);
|
|
|
|
|
for (auto &kbButton : kbButtons) {
|
|
|
|
|
kbButton.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grabbing = false;
|
|
|
|
|
whichGrabbing = -1;
|
|
|
|
|
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|