From 1376e65b5d67cdca25790b67d7a23f72823b7bb3 Mon Sep 17 00:00:00 2001 From: Nichole Mattera Date: Sat, 8 Aug 2020 18:41:59 -0400 Subject: [PATCH] Added ability to bind restart to a controller. --- desktop_version/src/Game.cpp | 19 ++++++++++ desktop_version/src/Game.h | 1 + desktop_version/src/Input.cpp | 63 ++++++++++++++++++++++++++++++++-- desktop_version/src/Render.cpp | 2 ++ 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index b61359c7..affdf6c5 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -4544,6 +4544,15 @@ void Game::loadstats(int *width, int *height, bool *vsync) } } + if (pKey == "restartButton") + { + SDL_GameControllerButton newButton; + if (GetButtonFromString(pText, &newButton)) + { + controllerButton_restart.push_back(newButton); + } + } + if (pKey == "controllerSensitivity") { controllerSensitivity = help.Int(pText); @@ -4571,6 +4580,10 @@ void Game::loadstats(int *width, int *height, bool *vsync) { controllerButton_esc.push_back(SDL_CONTROLLER_BUTTON_B); } + if (controllerButton_restart.size() < 1) + { + controllerButton_restart.push_back(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); + } } void Game::savestats() @@ -4789,6 +4802,12 @@ void Game::savestats() msg->LinkEndChild(doc.NewText(help.String((int) controllerButton_esc[i]).c_str())); dataNode->LinkEndChild(msg); } + for (size_t i = 0; i < controllerButton_restart.size(); i += 1) + { + msg = doc.NewElement("restartButton"); + msg->LinkEndChild(doc.NewText(help.String((int) controllerButton_restart[i]).c_str())); + dataNode->LinkEndChild(msg); + } msg = doc.NewElement( "controllerSensitivity" ); msg->LinkEndChild( doc.NewText( help.String(controllerSensitivity).c_str())); diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 03ff695a..bdb0354d 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -374,6 +374,7 @@ public: std::vector controllerButton_map; std::vector controllerButton_flip; std::vector controllerButton_esc; + std::vector controllerButton_restart; bool skipfakeload; bool ghostsenabled; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 7c4c5291..22637caa 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -52,6 +52,13 @@ void updatebuttonmappings(int bind) game.controllerButton_esc.erase(game.controllerButton_esc.begin() + j); } } + for (size_t j = 0; j < game.controllerButton_restart.size(); j += 1) + { + if (i == game.controllerButton_restart[j]) + { + game.controllerButton_restart.erase(game.controllerButton_restart.begin() + j); + } + } } if (bind == 2) { @@ -81,6 +88,13 @@ void updatebuttonmappings(int bind) game.controllerButton_esc.erase(game.controllerButton_esc.begin() + j); } } + for (size_t j = 0; j < game.controllerButton_restart.size(); j += 1) + { + if (i == game.controllerButton_restart[j]) + { + game.controllerButton_restart.erase(game.controllerButton_restart.begin() + j); + } + } } if (bind == 3) { @@ -110,6 +124,49 @@ void updatebuttonmappings(int bind) game.controllerButton_map.erase(game.controllerButton_map.begin() + j); } } + for (size_t j = 0; j < game.controllerButton_restart.size(); j += 1) + { + if (i == game.controllerButton_restart[j]) + { + game.controllerButton_restart.erase(game.controllerButton_restart.begin() + j); + } + } + } + if (bind == 4) + { + for (size_t j = 0; j < game.controllerButton_restart.size(); j += 1) + { + if (i == game.controllerButton_restart[j]) + { + dupe = true; + } + } + if (!dupe) + { + game.controllerButton_restart.push_back(i); + music.playef(11); + } + for (size_t j = 0; j < game.controllerButton_flip.size(); j += 1) + { + if (i == game.controllerButton_flip[j]) + { + game.controllerButton_flip.erase(game.controllerButton_flip.begin() + j); + } + } + for (size_t j = 0; j < game.controllerButton_map.size(); j += 1) + { + if (i == game.controllerButton_map[j]) + { + game.controllerButton_map.erase(game.controllerButton_map.begin() + j); + } + } + for (size_t j = 0; j < game.controllerButton_esc.size(); j += 1) + { + if (i == game.controllerButton_esc[j]) + { + game.controllerButton_esc.erase(game.controllerButton_esc.begin() + j); + } + } } } } @@ -1200,7 +1257,7 @@ void menuactionpress() } break; - case 4: + case 5: music.playef(11); game.returnmenu(); break; @@ -1635,7 +1692,7 @@ void titleinput() } if ( game.currentmenuname == Menu::controller && game.currentmenuoption > 0 && - game.currentmenuoption < 4 && + game.currentmenuoption < 5 && key.controllerButtonDown() ) { updatebuttonmappings(game.currentmenuoption); @@ -1899,7 +1956,7 @@ void gameinput() } } - if (key.keymap[SDLK_r] && !game.nodeathmode)// && map.custommode) //Have fun glitchrunners! + if ((key.isDown(SDLK_r) || key.isDown(game.controllerButton_restart)) && !game.nodeathmode)// && map.custommode) //Have fun glitchrunners! { game.deathseq = 30; } diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index e636ec1e..19354d28 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -415,9 +415,11 @@ void menurender() case 1: case 2: case 3: + case 4: graphics.Print( -1, 85, "Flip is bound to: " + std::string(help.GCString(game.controllerButton_flip)) , tr, tg, tb, true); graphics.Print( -1, 95, "Enter is bound to: " + std::string(help.GCString(game.controllerButton_map)), tr, tg, tb, true); graphics.Print( -1, 105, "Menu is bound to: " + std::string(help.GCString(game.controllerButton_esc)) , tr, tg, tb, true); + graphics.Print( -1, 115, "Restart is bound to: " + std::string(help.GCString(game.controllerButton_restart)) , tr, tg, tb, true); break; }