diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a4ec707..c1106e2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -450,6 +450,7 @@ target_sources(lego1 PRIVATE LEGO1/lego/legoomni/src/entity/legoworld.cpp LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp LEGO1/lego/legoomni/src/input/legoinputmanager.cpp + LEGO1/lego/legoomni/src/input/legokeymaps.cpp LEGO1/lego/legoomni/src/main/legomain.cpp LEGO1/lego/legoomni/src/main/scripts.cpp LEGO1/lego/legoomni/src/paths/legoanimactor.cpp @@ -639,6 +640,7 @@ if (ISLE_BUILD_CONFIG) qt_add_executable(isle-config WIN32 LEGO1/mxdirectx/mxdirectxinfo.cpp LEGO1/mxdirectx/legodxinfo.cpp + LEGO1/lego/legoomni/src/input/legokeymaps.cpp CONFIG/config.cpp CONFIG/AboutDlg.cpp CONFIG/MainDlg.cpp @@ -654,6 +656,7 @@ if (ISLE_BUILD_CONFIG) list(APPEND isle_targets isle-config) target_compile_definitions(isle-config PRIVATE _AFXDLL MXDIRECTX_FOR_CONFIG) target_include_directories(isle-config PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/LEGO1") + target_include_directories(isle-config PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/LEGO1/lego/legoomni/include") target_include_directories(isle-config PUBLIC "$") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) target_link_libraries(isle-config PRIVATE DirectX5::DirectX5) diff --git a/CONFIG/MainDlg.cpp b/CONFIG/MainDlg.cpp index 73a85ab3..730cf208 100644 --- a/CONFIG/MainDlg.cpp +++ b/CONFIG/MainDlg.cpp @@ -73,6 +73,17 @@ CMainDialog::CMainDialog(QWidget* pParent) : QDialog(pParent) connect(m_ui->cancelButton, &QPushButton::clicked, this, &CMainDialog::reject); connect(m_ui->launchButton, &QPushButton::clicked, this, &CMainDialog::launch); + connect(m_ui->keyForward_1, &QPushButton::clicked, this, &CMainDialog::ForwardKeyChanged); + connect(m_ui->keyForward_2, &QPushButton::clicked, this, &CMainDialog::ForwardKeyChangedAlt); + connect(m_ui->keyBack_1, &QPushButton::clicked, this, &CMainDialog::BackwardKeyChanged); + connect(m_ui->keyBack_2, &QPushButton::clicked, this, &CMainDialog::BackwardKeyChangedAlt); + connect(m_ui->keyLeft_1, &QPushButton::clicked, this, &CMainDialog::LeftKeyChanged); + connect(m_ui->keyLeft_2, &QPushButton::clicked, this, &CMainDialog::LeftKeyChangedAlt); + connect(m_ui->keyRight_1, &QPushButton::clicked, this, &CMainDialog::RightKeyChanged); + connect(m_ui->keyRight_2, &QPushButton::clicked, this, &CMainDialog::RightKeyChangedAlt); + connect(m_ui->keySprint_1, &QPushButton::clicked, this, &CMainDialog::SprintKeyChanged); + connect(m_ui->keySprint_2, &QPushButton::clicked, this, &CMainDialog::SprintKeyChangedAlt); + connect(m_ui->dataPathOpen, &QPushButton::clicked, this, &CMainDialog::SelectDataPathDialog); connect(m_ui->savePathOpen, &QPushButton::clicked, this, &CMainDialog::SelectSavePathDialog); @@ -181,16 +192,18 @@ bool CMainDialog::OnInitDialog() m_ui->exFullResComboBox->clear(); int displayModeCount; - displayModes = SDL_GetFullscreenDisplayModes(SDL_GetPrimaryDisplay(), &displayModeCount); + m_displayModes = SDL_GetFullscreenDisplayModes(SDL_GetPrimaryDisplay(), &displayModeCount); for (int i = 0; i < displayModeCount; ++i) { - QString mode = - QString("%1x%2 @ %3Hz").arg(displayModes[i]->w).arg(displayModes[i]->h).arg(displayModes[i]->refresh_rate); + QString mode = QString("%1x%2 @ %3Hz") + .arg(m_displayModes[i]->w) + .arg(m_displayModes[i]->h) + .arg(m_displayModes[i]->refresh_rate); m_ui->exFullResComboBox->addItem(mode); - if ((displayModes[i]->w == currentConfigApp->m_exf_x_res) && - (displayModes[i]->h == currentConfigApp->m_exf_y_res) && - (displayModes[i]->refresh_rate == currentConfigApp->m_exf_fps)) { + if ((m_displayModes[i]->w == currentConfigApp->m_exf_x_res) && + (m_displayModes[i]->h == currentConfigApp->m_exf_y_res) && + (m_displayModes[i]->refresh_rate == currentConfigApp->m_exf_fps)) { m_ui->exFullResComboBox->setCurrentIndex(i); } } @@ -348,6 +361,22 @@ void CMainDialog::UpdateInterface() m_ui->msaaNum->setNum(currentConfigApp->m_msaa); m_ui->AFSlider->setValue(log2(currentConfigApp->m_anisotropy)); m_ui->AFNum->setNum(currentConfigApp->m_anisotropy); + + m_ui->keyForward_1->setText(GetKeyName(g_keyMaps.k_forward[0])); + m_ui->keyForward_2->setText(GetKeyName(g_keyMaps.k_forward[1])); + m_ui->keyBack_1->setText(GetKeyName(g_keyMaps.k_back[0])); + m_ui->keyBack_2->setText(GetKeyName(g_keyMaps.k_back[1])); + m_ui->keyLeft_1->setText(GetKeyName(g_keyMaps.k_left[0])); + m_ui->keyLeft_2->setText(GetKeyName(g_keyMaps.k_left[1])); + m_ui->keyRight_1->setText(GetKeyName(g_keyMaps.k_right[0])); + m_ui->keyRight_2->setText(GetKeyName(g_keyMaps.k_right[1])); + m_ui->keySprint_1->setText(GetKeyName(g_keyMaps.k_sprint[0])); + m_ui->keySprint_2->setText(GetKeyName(g_keyMaps.k_sprint[1])); +} + +QString CMainDialog::GetKeyName(SDL_Scancode key) +{ + return QString(SDL_GetKeyName(SDL_GetKeyFromScancode(key, 0, true))); } // FUNCTION: CONFIG 0x004045e0 @@ -488,9 +517,9 @@ void CMainDialog::TransitionTypeChanged(int index) void CMainDialog::ExclusiveResolutionChanged(int index) { - currentConfigApp->m_exf_x_res = displayModes[index]->w; - currentConfigApp->m_exf_y_res = displayModes[index]->h; - currentConfigApp->m_exf_fps = displayModes[index]->refresh_rate; + currentConfigApp->m_exf_x_res = m_displayModes[index]->w; + currentConfigApp->m_exf_y_res = m_displayModes[index]->h; + currentConfigApp->m_exf_fps = m_displayModes[index]->refresh_rate; m_modified = true; UpdateInterface(); } @@ -635,12 +664,8 @@ void CMainDialog::TexturePathEdited() 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", - data_path.absolutePath(), - "Interleaf files (*.si)" - ); + QStringList new_files = + QFileDialog::getOpenFileNames(this, "Open File(s)", data_path.absolutePath(), "Interleaf files (*.si)"); if (!new_files.isEmpty()) { for (QString& item : new_files) { item = data_path.relativeFilePath(item); @@ -719,7 +744,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: { @@ -738,9 +766,6 @@ void CMainDialog::EnsureAspectRatio() } } } - else { - m_ui->xResSpinBox->setReadOnly(false); - } } void CMainDialog::FramerateChanged(int i) @@ -749,3 +774,115 @@ void CMainDialog::FramerateChanged(int i) m_modified = true; UpdateInterface(); } + +void CMainDialog::ForwardKeyChanged() +{ + RebindInput(m_ui->keyForward_1, g_keyMaps.k_forward[0]); +} + +void CMainDialog::ForwardKeyChangedAlt() +{ + RebindInput(m_ui->keyForward_2, g_keyMaps.k_forward[1]); +} + +void CMainDialog::BackwardKeyChanged() +{ + RebindInput(m_ui->keyBack_1, g_keyMaps.k_back[0]); +} + +void CMainDialog::BackwardKeyChangedAlt() +{ + RebindInput(m_ui->keyBack_2, g_keyMaps.k_back[1]); +} + +void CMainDialog::LeftKeyChanged() +{ + RebindInput(m_ui->keyLeft_1, g_keyMaps.k_left[0]); +} + +void CMainDialog::LeftKeyChangedAlt() +{ + RebindInput(m_ui->keyLeft_2, g_keyMaps.k_left[1]); +} + +void CMainDialog::RightKeyChanged() +{ + RebindInput(m_ui->keyRight_1, g_keyMaps.k_right[0]); +} + +void CMainDialog::RightKeyChangedAlt() +{ + RebindInput(m_ui->keyRight_2, g_keyMaps.k_right[1]); +} + +void CMainDialog::SprintKeyChanged() +{ + RebindInput(m_ui->keySprint_1, g_keyMaps.k_sprint[0]); +} + +void CMainDialog::SprintKeyChangedAlt() +{ + RebindInput(m_ui->keySprint_2, g_keyMaps.k_sprint[1]); +} + +void CMainDialog::RebindInput(QPushButton*& button, SDL_Scancode& key) +{ + SDL_InitSubSystem(SDL_INIT_EVENTS); + button->setText(QString("Press a key...")); + m_currentKeyBind = &key; + + m_inputWindow = SDL_CreateWindow( + "Press a key...", + 256, + 128, + SDL_WINDOW_HIDDEN | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_UTILITY | + SDL_WINDOW_KEYBOARD_GRABBED + ); +#ifdef MINIWIN + m_hWnd = reinterpret_cast(m_inputWindow); +#else + m_hWnd = + (HWND) SDL_GetPointerProperty(SDL_GetWindowProperties(m_inputWindow), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); +#endif + + inputTimeout.setSingleShot(false); + inputTimeout.setInterval(1000); + sdlPoller.setSingleShot(false); + sdlPoller.setInterval(10); + connect(&inputTimeout, &QTimer::timeout, this, &CMainDialog::RebindTimeout); + connect(&sdlPoller, &QTimer::timeout, this, &CMainDialog::PollInputs); + SDL_ShowWindow(m_inputWindow); + SDL_RaiseWindow(m_inputWindow); + timeoutCountdown = 3; + sdlPoller.start(); + inputTimeout.start(); +} + +void CMainDialog::PollInputs() +{ + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_EVENT_KEY_DOWN || event.type == SDL_EVENT_QUIT) { + if (event.type == SDL_EVENT_KEY_DOWN && event.key.scancode != SDL_SCANCODE_ESCAPE) { + SDL_Scancode sc = event.key.scancode; + *m_currentKeyBind = sc; + m_modified = true; + } + sdlPoller.disconnect(); + inputTimeout.disconnect(); + SDL_DestroyWindow(m_inputWindow); + UpdateInterface(); + } + } +} + +void CMainDialog::RebindTimeout() +{ + timeoutCountdown -= 1; + if (timeoutCountdown <= 0) { + sdlPoller.disconnect(); + inputTimeout.disconnect(); + SDL_DestroyWindow(m_inputWindow); + UpdateInterface(); + } +} diff --git a/CONFIG/MainDlg.h b/CONFIG/MainDlg.h index 22cf7895..e4b17e9a 100644 --- a/CONFIG/MainDlg.h +++ b/CONFIG/MainDlg.h @@ -5,8 +5,16 @@ #include "decomp.h" #include "res/resource.h" +#ifdef MINIWIN +#include "miniwin/d3d.h" +#else +#include +#endif + #include #include +#include +#include #include namespace Ui @@ -31,10 +39,17 @@ class CMainDialog : public QDialog { bool m_advanced = false; QStringList assetPaths = QStringList(); Ui::MainDialog* m_ui = nullptr; - SDL_DisplayMode** displayModes; + SDL_DisplayMode** m_displayModes; + SDL_Window* m_inputWindow; + HWND m_hWnd; + QTimer sdlPoller; + QTimer inputTimeout; + int timeoutCountdown = 0; + SDL_Scancode* m_currentKeyBind = nullptr; void keyReleaseEvent(QKeyEvent* event) override; bool OnInitDialog(); + QString GetKeyName(SDL_Scancode key); private slots: void OnList3DevicesSelectionChanged(int row); void OnCheckbox3DSound(bool checked); @@ -76,6 +91,19 @@ private slots: void AspectRatioChanged(int index); void EnsureAspectRatio(); void FramerateChanged(int i); + void RebindInput(QPushButton*& button, SDL_Scancode& key); + void PollInputs(); + void RebindTimeout(); + void ForwardKeyChanged(); + void ForwardKeyChangedAlt(); + void BackwardKeyChanged(); + void BackwardKeyChangedAlt(); + void LeftKeyChanged(); + void LeftKeyChangedAlt(); + void RightKeyChanged(); + void RightKeyChangedAlt(); + void SprintKeyChanged(); + void SprintKeyChangedAlt(); }; // SYNTHETIC: CONFIG 0x00403de0 diff --git a/CONFIG/config.cpp b/CONFIG/config.cpp index 4e9d414d..122e12ce 100644 --- a/CONFIG/config.cpp +++ b/CONFIG/config.cpp @@ -199,6 +199,18 @@ bool CConfigApp::ReadRegisterSettings() m_exf_y_res = iniparser_getint(dict, "isle:Exclusive Y Resolution", m_exf_y_res); m_exf_fps = iniparser_getdouble(dict, "isle:Exclusive Framerate", m_exf_fps); m_frame_delta = iniparser_getdouble(dict, "isle:Frame Delta", m_frame_delta); + + g_keyMaps.k_forward[0] = (SDL_Scancode) iniparser_getint(dict, "input:Forward", g_keyMaps.k_forward[0]); + g_keyMaps.k_forward[1] = (SDL_Scancode) iniparser_getint(dict, "input:Forward Alt", g_keyMaps.k_forward[1]); + g_keyMaps.k_back[0] = (SDL_Scancode) iniparser_getint(dict, "input:Backward", g_keyMaps.k_back[0]); + g_keyMaps.k_back[1] = (SDL_Scancode) iniparser_getint(dict, "input:Backward Alt", g_keyMaps.k_back[1]); + g_keyMaps.k_left[0] = (SDL_Scancode) iniparser_getint(dict, "input:Left", g_keyMaps.k_left[0]); + g_keyMaps.k_left[1] = (SDL_Scancode) iniparser_getint(dict, "input:Left Alt", g_keyMaps.k_left[1]); + g_keyMaps.k_right[0] = (SDL_Scancode) iniparser_getint(dict, "input:Right", g_keyMaps.k_right[0]); + g_keyMaps.k_right[1] = (SDL_Scancode) iniparser_getint(dict, "input:Right Alt", g_keyMaps.k_right[1]); + g_keyMaps.k_sprint[0] = (SDL_Scancode) iniparser_getint(dict, "input:Sprint", g_keyMaps.k_sprint[0]); + g_keyMaps.k_sprint[1] = (SDL_Scancode) iniparser_getint(dict, "input:Sprint Alt", g_keyMaps.k_sprint[1]); + iniparser_freedict(dict); return true; } @@ -370,6 +382,7 @@ void CConfigApp::WriteRegisterSettings() const iniparser_set(dict, "extensions", NULL); iniparser_set(dict, "texture loader", NULL); iniparser_set(dict, "si loader", NULL); + iniparser_set(dict, "input", NULL); if (m_device_enumerator->FormatDeviceName(buffer, m_driver, m_device) >= 0) { iniparser_set(dict, "isle:3D Device ID", buffer); @@ -419,6 +432,17 @@ void CConfigApp::WriteRegisterSettings() const iniparser_set(dict, "isle:Exclusive Framerate", std::to_string(m_exf_fps).c_str()); iniparser_set(dict, "isle:Frame Delta", std::to_string(m_frame_delta).c_str()); + SetIniInt(dict, "input:Forward", g_keyMaps.k_forward[0]); + SetIniInt(dict, "input:Forward Alt", g_keyMaps.k_forward[1]); + SetIniInt(dict, "input:Backward", g_keyMaps.k_back[0]); + SetIniInt(dict, "input:Backward Alt", g_keyMaps.k_back[1]); + SetIniInt(dict, "input:Left", g_keyMaps.k_left[0]); + SetIniInt(dict, "input:Left Alt", g_keyMaps.k_left[1]); + SetIniInt(dict, "input:Right", g_keyMaps.k_right[0]); + SetIniInt(dict, "input:Right Alt", g_keyMaps.k_right[1]); + SetIniInt(dict, "input:Sprint", g_keyMaps.k_sprint[0]); + SetIniInt(dict, "input:Sprint Alt", g_keyMaps.k_sprint[1]); + #undef SetIniBool #undef SetIniInt @@ -481,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; diff --git a/CONFIG/config.h b/CONFIG/config.h index 71e876f6..a3d87e99 100644 --- a/CONFIG/config.h +++ b/CONFIG/config.h @@ -4,6 +4,7 @@ #include "AboutDlg.h" #include "compat.h" #include "decomp.h" +#include "legokeymaps.h" #ifdef MINIWIN #include "miniwin/d3d.h" @@ -11,6 +12,7 @@ #include #endif +#include #include class LegoDeviceEnumerate; diff --git a/CONFIG/res/maindialog.ui b/CONFIG/res/maindialog.ui index 99931197..bd77fd1a 100644 --- a/CONFIG/res/maindialog.ui +++ b/CONFIG/res/maindialog.ui @@ -7,7 +7,7 @@ 0 0 640 - 480 + 502 @@ -955,6 +955,123 @@ The game will gradually increase the number of actors until this maximum is reac Controls + + + + true + + + Keyboard Mappings + + + + + + Forward + + + + + + + Back + + + + + + + Left + + + + + + + Right + + + + + + + Sprint + + + + + + + Up + + + + + + + Numpad 8 + + + + + + + Down + + + + + + + Numpad 2 + + + + + + + Left + + + + + + + Numpad 4 + + + + + + + Right + + + + + + + Numpad 6 + + + + + + + Left Control + + + + + + + Right Control + + + + + + @@ -1036,7 +1153,7 @@ The game will gradually increase the number of actors until this maximum is reac 0 0 449 - 369 + 391 @@ -1326,6 +1443,16 @@ Double-click a path to edit it. exFullResComboBox msaaSlider AFSlider + keyForward_1 + keyForward_2 + keyBack_1 + keyBack_2 + keyLeft_1 + keyLeft_2 + keyRight_1 + keyRight_2 + keySprint_1 + keySprint_2 touchComboBox rumbleCheckBox scrollArea diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index c7444362..a7905c9d 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -9,6 +9,7 @@ #include "legobuildingmanager.h" #include "legogamestate.h" #include "legoinputmanager.h" +#include "legokeymaps.h" #include "legomain.h" #include "legomodelpresenter.h" #include "legopartpresenter.h" @@ -46,6 +47,7 @@ #define SDL_MAIN_USE_CALLBACKS #include #include +#include #include #include #include @@ -1090,6 +1092,18 @@ bool IsleApp::LoadConfig() iniparser_set(dict, "isle:MSAA", SDL_itoa(m_msaaSamples, buf, 10)); iniparser_set(dict, "isle:Anisotropic", SDL_itoa(m_anisotropic, buf, 10)); + iniparser_set(dict, "input", NULL); + iniparser_set(dict, "input:Forward", SDL_itoa(g_keyMaps.k_forward[0], buf, 10)); + iniparser_set(dict, "input:Forward Alt", SDL_itoa(g_keyMaps.k_forward[1], buf, 10)); + iniparser_set(dict, "input:Backward", SDL_itoa(g_keyMaps.k_back[0], buf, 10)); + iniparser_set(dict, "input:Backward Alt", SDL_itoa(g_keyMaps.k_back[1], buf, 10)); + iniparser_set(dict, "input:Left", SDL_itoa(g_keyMaps.k_left[0], buf, 10)); + iniparser_set(dict, "input:Left Alt", SDL_itoa(g_keyMaps.k_left[1], buf, 10)); + iniparser_set(dict, "input:Right", SDL_itoa(g_keyMaps.k_right[0], buf, 10)); + iniparser_set(dict, "input:Right Alt", SDL_itoa(g_keyMaps.k_right[1], buf, 10)); + iniparser_set(dict, "input:Sprint", SDL_itoa(g_keyMaps.k_sprint[0], buf, 10)); + iniparser_set(dict, "input:Sprint Alt", SDL_itoa(g_keyMaps.k_sprint[1], buf, 10)); + #ifdef EXTENSIONS iniparser_set(dict, "extensions", NULL); for (const char* key : Extensions::availableExtensions) { @@ -1167,6 +1181,17 @@ bool IsleApp::LoadConfig() m_videoParam.SetMSAASamples((m_msaaSamples = iniparser_getint(dict, "isle:MSAA", m_msaaSamples))); m_videoParam.SetAnisotropic((m_anisotropic = iniparser_getdouble(dict, "isle:Anisotropic", m_anisotropic))); + g_keyMaps.k_forward[0] = (SDL_Scancode) iniparser_getint(dict, "input:Forward", g_keyMaps.k_forward[0]); + g_keyMaps.k_forward[1] = (SDL_Scancode) iniparser_getint(dict, "input:Forward Alt", g_keyMaps.k_forward[1]); + g_keyMaps.k_back[0] = (SDL_Scancode) iniparser_getint(dict, "input:Backward", g_keyMaps.k_back[0]); + g_keyMaps.k_back[1] = (SDL_Scancode) iniparser_getint(dict, "input:Backward Alt", g_keyMaps.k_back[1]); + g_keyMaps.k_left[0] = (SDL_Scancode) iniparser_getint(dict, "input:Left", g_keyMaps.k_left[0]); + g_keyMaps.k_left[1] = (SDL_Scancode) iniparser_getint(dict, "input:Left Alt", g_keyMaps.k_left[1]); + g_keyMaps.k_right[0] = (SDL_Scancode) iniparser_getint(dict, "input:Right", g_keyMaps.k_right[0]); + g_keyMaps.k_right[1] = (SDL_Scancode) iniparser_getint(dict, "input:Right Alt", g_keyMaps.k_right[1]); + g_keyMaps.k_sprint[0] = (SDL_Scancode) iniparser_getint(dict, "input:Sprint", g_keyMaps.k_sprint[0]); + g_keyMaps.k_sprint[1] = (SDL_Scancode) iniparser_getint(dict, "input:Sprint Alt", g_keyMaps.k_sprint[1]); + const char* deviceId = iniparser_getstring(dict, "isle:3D Device ID", NULL); if (deviceId != NULL) { m_deviceId = SDL_strdup(deviceId); diff --git a/ISLE/isleapp.h b/ISLE/isleapp.h index 0e0700e8..bbdbeedb 100644 --- a/ISLE/isleapp.h +++ b/ISLE/isleapp.h @@ -4,6 +4,7 @@ #include "cursor.h" #include "lego1_export.h" #include "legoinputmanager.h" +#include "legokeymaps.h" #include "legoutils.h" #include "mxtransitionmanager.h" #include "mxtypes.h" diff --git a/LEGO1/lego/legoomni/include/legoinputmanager.h b/LEGO1/lego/legoomni/include/legoinputmanager.h index f8a4bb0a..c2a91c3b 100644 --- a/LEGO1/lego/legoomni/include/legoinputmanager.h +++ b/LEGO1/lego/legoomni/include/legoinputmanager.h @@ -4,6 +4,7 @@ #include "decomp.h" #include "lego1_export.h" #include "legoeventnotificationparam.h" +#include "legokeymaps.h" #include "mxlist.h" #include "mxpresenter.h" #include "mxqueue.h" @@ -12,6 +13,7 @@ #include #include #include +#include #include #ifdef MINIWIN #include "miniwin/windows.h" @@ -87,7 +89,7 @@ class LegoInputManager : public MxPresenter { c_right = 0x02, c_up = 0x04, c_down = 0x08, - c_ctrl = 0x10, + c_sprint = 0x10, c_leftOrRight = c_left | c_right, c_upOrDown = c_up | c_down diff --git a/LEGO1/lego/legoomni/include/legokeymaps.h b/LEGO1/lego/legoomni/include/legokeymaps.h new file mode 100644 index 00000000..fbb2a281 --- /dev/null +++ b/LEGO1/lego/legoomni/include/legokeymaps.h @@ -0,0 +1,29 @@ +#ifndef LEGOKEYMAPS_H +#define LEGOKEYMAPS_H + +#include "decomp.h" +#include "lego1_export.h" + +#include +#include +#include +#ifdef MINIWIN +#include "miniwin/windows.h" +#else +#include +#endif + +#include +#include + +struct KeyMaps { + SDL_Scancode k_forward[2]; + SDL_Scancode k_back[2]; + SDL_Scancode k_left[2]; + SDL_Scancode k_right[2]; + SDL_Scancode k_sprint[2]; +}; + +extern KeyMaps g_keyMaps; + +#endif diff --git a/LEGO1/lego/legoomni/src/entity/legonavcontroller.cpp b/LEGO1/lego/legoomni/src/entity/legonavcontroller.cpp index 4591fc88..fb8c93ae 100644 --- a/LEGO1/lego/legoomni/src/entity/legonavcontroller.cpp +++ b/LEGO1/lego/legoomni/src/entity/legonavcontroller.cpp @@ -623,8 +623,8 @@ MxResult LegoNavController::ProcessKeyboardInput() break; } - MxFloat maxAccelDivisor = keyFlags & LegoInputManager::c_ctrl ? 1.0f : 4.0f; - MxFloat minAccelDivisor = keyFlags & LegoInputManager::c_ctrl ? 1.0f : 2.0f; + MxFloat maxAccelDivisor = keyFlags & LegoInputManager::c_sprint ? 1.0f : 4.0f; + MxFloat minAccelDivisor = keyFlags & LegoInputManager::c_sprint ? 1.0f : 2.0f; if (!skipRotationVelAndAccelCalc) { m_targetRotationalVel = CalculateNewTargetVel(hMax, m_hMax / 2, m_maxRotationalVel); diff --git a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp index 613e5b9f..c4fb564f 100644 --- a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp +++ b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp @@ -134,24 +134,24 @@ MxResult LegoInputManager::GetNavigationKeyStates(MxU32& p_keyFlags) MxU32 keyFlags = 0; - if (m_keyboardState[SDL_SCANCODE_KP_8] || m_keyboardState[SDL_SCANCODE_UP]) { + if (m_keyboardState[g_keyMaps.k_forward[0]] || m_keyboardState[g_keyMaps.k_forward[1]]) { keyFlags |= c_up; } - if ((m_keyboardState[SDL_SCANCODE_KP_2] || m_keyboardState[SDL_SCANCODE_DOWN])) { + if ((m_keyboardState[g_keyMaps.k_back[0]] || m_keyboardState[g_keyMaps.k_back[1]])) { keyFlags |= c_down; } - if ((m_keyboardState[SDL_SCANCODE_KP_4] || m_keyboardState[SDL_SCANCODE_LEFT])) { + if ((m_keyboardState[g_keyMaps.k_left[0]] || m_keyboardState[g_keyMaps.k_left[1]])) { keyFlags |= c_left; } - if ((m_keyboardState[SDL_SCANCODE_KP_6] || m_keyboardState[SDL_SCANCODE_RIGHT])) { + if ((m_keyboardState[g_keyMaps.k_right[0]] || m_keyboardState[g_keyMaps.k_right[1]])) { keyFlags |= c_right; } - if (m_keyboardState[SDL_SCANCODE_LCTRL] || m_keyboardState[SDL_SCANCODE_RCTRL]) { - keyFlags |= c_ctrl; + if (m_keyboardState[g_keyMaps.k_sprint[0]] || m_keyboardState[g_keyMaps.k_sprint[1]]) { + keyFlags |= c_sprint; } GetNavigationTouchStates(keyFlags); diff --git a/LEGO1/lego/legoomni/src/input/legokeymaps.cpp b/LEGO1/lego/legoomni/src/input/legokeymaps.cpp new file mode 100644 index 00000000..668e9995 --- /dev/null +++ b/LEGO1/lego/legoomni/src/input/legokeymaps.cpp @@ -0,0 +1,11 @@ +#include "legokeymaps.h" + +#include + +KeyMaps g_keyMaps = { + {SDL_SCANCODE_UP, SDL_SCANCODE_KP_8}, + {SDL_SCANCODE_DOWN, SDL_SCANCODE_KP_2}, + {SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_4}, + {SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_6}, + {SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL} +};