input settings should be complete now

This commit is contained in:
SimoZ64
2025-05-07 16:11:36 +02:00
parent 3759be86a1
commit 4d10495c88
4 changed files with 40 additions and 46 deletions

View File

@@ -70,6 +70,8 @@ struct Combobox {
void setEnabled(bool v) { enabled = v; }
bool isEnabled() { return enabled; }
const std::string& getCurrentlySelected() { return items[current_index].getLabel(); }
void setCurrentIndex(int v) { current_index = v; }
int getCurrentIndex() { return current_index; }
private:

View File

@@ -1,3 +1,4 @@
#pragma once
#include <imgui.h>
#include <string>
#include <functional>

View File

@@ -1,3 +1,4 @@
#pragma once
#include <imgui.h>
#include <functional>

View File

@@ -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,39 @@ 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);
}
grabbing = false;
whichGrabbing = -1;
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);
}
@@ -159,4 +150,3 @@ void InputSettings::PollGamepad() noexcept {
}
}
}
*/