input settings should be complete now
This commit is contained in:
@@ -70,6 +70,8 @@ struct Combobox {
|
|||||||
void setEnabled(bool v) { enabled = v; }
|
void setEnabled(bool v) { enabled = v; }
|
||||||
bool isEnabled() { return enabled; }
|
bool isEnabled() { return enabled; }
|
||||||
|
|
||||||
|
const std::string& getCurrentlySelected() { return items[current_index].getLabel(); }
|
||||||
|
|
||||||
void setCurrentIndex(int v) { current_index = v; }
|
void setCurrentIndex(int v) { current_index = v; }
|
||||||
int getCurrentIndex() { return current_index; }
|
int getCurrentIndex() { return current_index; }
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
|||||||
@@ -10,24 +10,17 @@ InputSettings::InputSettings(nlohmann::json &settings) : settings(settings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|
||||||
JSONSetField<std::string>(settings, "input", "Device", text.toStdString());
|
|
||||||
emit modified();
|
|
||||||
});
|
|
||||||
|
|
||||||
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
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() {
|
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;
|
int i = 0;
|
||||||
for(auto& kb : kbButtons) {
|
for(auto& kb : kbButtons) {
|
||||||
if(kb.render()) {
|
if(kb.render()) {
|
||||||
@@ -35,10 +28,12 @@ bool InputSettings::render() {
|
|||||||
for (auto &otherKb : kbButtons) {
|
for (auto &otherKb : kbButtons) {
|
||||||
otherKb.setEnabled(false);
|
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
|
if(i % 2 != 0) // only go down every 2 buttons... just... i like it this way
|
||||||
ImGui::SameLine();
|
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> InputSettings::GetMappedKeys() {
|
||||||
std::array<SDL_Keycode, 18> ret{};
|
std::array<SDL_Keycode, 18> ret{};
|
||||||
|
|
||||||
@@ -130,21 +103,39 @@ void InputSettings::QueryDevices() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void InputSettings::PollGamepad() noexcept {
|
void InputSettings::PollGamepad() noexcept {
|
||||||
if (!selectedDeviceIsNotKeyboard)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e)) {
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||||
{
|
{
|
||||||
|
if (!selectedDeviceIsNotKeyboard)
|
||||||
|
return;
|
||||||
|
|
||||||
const auto k = SDL_GetGamepadStringForButton(static_cast<SDL_GamepadButton>(e.gbutton.button));
|
const auto k = SDL_GetGamepadStringForButton(static_cast<SDL_GamepadButton>(e.gbutton.button));
|
||||||
JSONSetField<std::string>(settings, "input", buttonLabels[whichGrabbing]->text().toStdString(), k);
|
JSONSetField<std::string>(settings, "input", kbButtons[whichGrabbing].getName(), k);
|
||||||
kbButtons[whichGrabbing].setText(k);
|
kbButtons[whichGrabbing].setLabel(k);
|
||||||
devices.setEnabled(true);
|
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);
|
kbButton.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,4 +150,3 @@ void InputSettings::PollGamepad() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user