diff --git a/CONFIG/MainDlg.cpp b/CONFIG/MainDlg.cpp index b5a6a502..dbbe4bc0 100644 --- a/CONFIG/MainDlg.cpp +++ b/CONFIG/MainDlg.cpp @@ -639,7 +639,7 @@ void CMainDialog::AddCustomAssetPath() QDir data_path = QDir(QString::fromStdString(currentConfigApp->m_cd_path)); QStringList new_files = QFileDialog::getOpenFileNames( this, - "Select one or more files to open", + "Open File(s)", data_path.absolutePath(), "Interleaf files (*.si)" ); @@ -721,7 +721,10 @@ void CMainDialog::YResChanged(int i) void CMainDialog::EnsureAspectRatio() { - if (currentConfigApp->m_aspect_ratio != 3) { + if (currentConfigApp->m_aspect_ratio == 3) { + m_ui->xResSpinBox->setReadOnly(false); + } + else { m_ui->xResSpinBox->setReadOnly(true); switch (currentConfigApp->m_aspect_ratio) { case 0: { @@ -740,9 +743,6 @@ void CMainDialog::EnsureAspectRatio() } } } - else { - m_ui->xResSpinBox->setReadOnly(false); - } } void CMainDialog::FramerateChanged(int i) @@ -753,10 +753,43 @@ void CMainDialog::FramerateChanged(int i) } void CMainDialog::ForwardKeyChanged() { - RebindInput(m_ui->keyForward_1); + RebindInput(m_ui->keyForward_1, g_keyMaps.k_forward[0]); } -void CMainDialog::RebindInput(QPushButton* &button) +void CMainDialog::RebindInput(QPushButton* &button, SDL_Scancode &key) { button->setText(QString("Press a key...")); + currentKeyBind = &key; + inputTimeout.setSingleShot(true); + inputTimeout.setInterval(3 * 1000); + sdlPoller.setSingleShot(false); + sdlPoller.setInterval(10); + connect(&inputTimeout, &QTimer::timeout, this, &CMainDialog::RebindTimeout); + connect(&sdlPoller, &QTimer::timeout, this, &CMainDialog::PollInputs); + SDL_InitSubSystem(SDL_INIT_EVENTS); + sdlPoller.start(); + inputTimeout.start(); +} + +void CMainDialog::PollInputs() +{ + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_EVENT_KEY_DOWN) { + SDL_Log("Key down!"); + SDL_Scancode sc = event.key.scancode; + *currentKeyBind = sc; + sdlPoller.disconnect(); + inputTimeout.disconnect(); + UpdateInterface(); + } + } +} + +void CMainDialog::RebindTimeout() +{ + SDL_Log("Timeout"); + sdlPoller.disconnect(); + inputTimeout.disconnect(); + UpdateInterface(); } diff --git a/CONFIG/MainDlg.h b/CONFIG/MainDlg.h index cffb4298..5663e6f7 100644 --- a/CONFIG/MainDlg.h +++ b/CONFIG/MainDlg.h @@ -7,6 +7,7 @@ #include #include +#include #include namespace Ui @@ -32,6 +33,9 @@ class CMainDialog : public QDialog { QStringList assetPaths = QStringList(); Ui::MainDialog* m_ui = nullptr; SDL_DisplayMode** displayModes; + QTimer sdlPoller; + QTimer inputTimeout; + SDL_Scancode* currentKeyBind = nullptr; void keyReleaseEvent(QKeyEvent* event) override; bool OnInitDialog(); @@ -77,7 +81,9 @@ private slots: void EnsureAspectRatio(); void FramerateChanged(int i); void ForwardKeyChanged(); - void RebindInput(QPushButton* &button); + void RebindInput(QPushButton* &button, SDL_Scancode &key); + void PollInputs(); + void RebindTimeout(); }; // SYNTHETIC: CONFIG 0x00403de0 diff --git a/CONFIG/config.cpp b/CONFIG/config.cpp index 5f6441e0..c10ebad5 100644 --- a/CONFIG/config.cpp +++ b/CONFIG/config.cpp @@ -505,6 +505,11 @@ int main(int argc, char* argv[]) } qInfo() << "INI path =" << QString::fromStdString(g_theApp.GetIniPath()); + if (SDL_InitSubSystem(SDL_INIT_EVENTS) != true) { + qDebug() << "SDL_Init Error:" << SDL_GetError(); + //return 1; + } + int result = 1; if (g_theApp.InitInstance()) { CMainDialog main_dialog;