From 3fff17417e30a3deeab1f823479329b91211bd2b Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 7 Feb 2024 17:58:29 -0600 Subject: [PATCH] Refactored the input display menu to allow for dynamic changing of row displays. Remove controller specific keybinding menu, integrating with initial keyboard menu. --- .../Adventures in Lestoria.vcxproj | 4 -- .../Adventures in Lestoria.vcxproj.filters | 3 -- .../AdventuresInLestoria.cpp | 4 +- .../InputControllerWindow.cpp | 46 ------------------- .../InputDisplayComponent.h | 6 ++- .../InputKeyboardWindow.cpp | 21 +++++---- Adventures in Lestoria/Key.cpp | 27 +++++++++++ Adventures in Lestoria/Key.h | 6 +++ Adventures in Lestoria/Menu.cpp | 1 - Adventures in Lestoria/Menu.h | 2 +- Adventures in Lestoria/MenuType.h | 5 +- Adventures in Lestoria/SettingsWindow.cpp | 4 +- Adventures in Lestoria/Version.h | 2 +- Adventures in Lestoria/olcPGEX_Gamepad.h | 1 + 14 files changed, 59 insertions(+), 73 deletions(-) delete mode 100644 Adventures in Lestoria/InputControllerWindow.cpp diff --git a/Adventures in Lestoria/Adventures in Lestoria.vcxproj b/Adventures in Lestoria/Adventures in Lestoria.vcxproj index 45da9deb..831304d7 100644 --- a/Adventures in Lestoria/Adventures in Lestoria.vcxproj +++ b/Adventures in Lestoria/Adventures in Lestoria.vcxproj @@ -590,10 +590,6 @@ - - - - diff --git a/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters b/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters index 802feda9..5678257d 100644 --- a/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters +++ b/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters @@ -788,9 +788,6 @@ Source Files\Interface - - Source Files\Interface - Source Files\Interface diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 51c6b308..a25446c5 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -283,6 +283,7 @@ bool AiL::OnUserUpdate(float fElapsedTime){ if(!GamePaused()){ GameState::STATE->OnUserUpdate(this); } + InputListener::Update(); Audio::Update(); RenderWorld(GetElapsedTime()); GameState::STATE->Draw(this); @@ -3081,7 +3082,8 @@ const uint8_t AiL::BossEncounterMobCount()const{ void AiL::GetAnyKeyRelease(Key key){ if(key!=0){ #pragma region New keyboard input binding listener - if(Menu::IsMenuOpen()&&Menu::stack.back()==Menu::menus[NEW_INPUT]){ //We are requesting a brand new input. + using A=Attribute; + if(Menu::IsMenuOpen()&&Menu::stack.back()==Menu::menus[NEW_INPUT]&&Menu::menus[NEW_INPUT]->B(A::IS_KEYBOARD)){ //We are requesting a brand new input. if(key==ESCAPE){ //If we hit escape we don't bother with setting the input and leave immediately. Menu::CloseMenu(); return; diff --git a/Adventures in Lestoria/InputControllerWindow.cpp b/Adventures in Lestoria/InputControllerWindow.cpp deleted file mode 100644 index f01d4252..00000000 --- a/Adventures in Lestoria/InputControllerWindow.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#pragma region License -/* -License (OLC-3) -~~~~~~~~~~~~~~~ - -Copyright 2024 Joshua Sigona - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions or derivations of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions or derivative works in binary form must reproduce the above -copyright notice. This list of conditions and the following disclaimer must be -reproduced in the documentation and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors may -be used to endorse or promote products derived from this software without specific -prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - -Portions of this software are copyright © 2024 The FreeType -Project (www.freetype.org). Please see LICENSE_FT.txt for more information. -All rights reserved. -*/ -#pragma endregion - -#include "Menu.h" -#include "DEFINES.h" - -INCLUDE_WINDOW_SIZE - -void Menu::InitializeControllerInputWindow(){ - Menu*inputKeyboardWindow=CreateMenu(INPUT_CONTROLLER,CENTERED,WINDOW_SIZE-vf2d{28,28}); -} \ No newline at end of file diff --git a/Adventures in Lestoria/InputDisplayComponent.h b/Adventures in Lestoria/InputDisplayComponent.h index 681c937c..c29fde9f 100644 --- a/Adventures in Lestoria/InputDisplayComponent.h +++ b/Adventures in Lestoria/InputDisplayComponent.h @@ -41,11 +41,13 @@ All rights reserved. class InputDisplayComponent:public MenuComponent{ const InputGroup&input; - const InputType type; + InputType type; public: inline InputDisplayComponent(geom2d::rectpos,InputGroup&input,InputType type,MenuFunc onClick) :MenuComponent(pos,"",onClick,ButtonAttr::NONE),input(input),type(type){} - + inline void SetKeyType(const InputType type){ + this->type=type; + } protected: inline void DrawDecal(ViewPort&window,bool focused)override{ MenuComponent::DrawDecal(window,focused); diff --git a/Adventures in Lestoria/InputKeyboardWindow.cpp b/Adventures in Lestoria/InputKeyboardWindow.cpp index 687e9144..f790b3af 100644 --- a/Adventures in Lestoria/InputKeyboardWindow.cpp +++ b/Adventures in Lestoria/InputKeyboardWindow.cpp @@ -45,11 +45,12 @@ All rights reserved. using A=Attribute; INCLUDE_WINDOW_SIZE +INCLUDE_DATA void Menu::InitializeKeyboardInputWindow(){ vf2d menuSize={WINDOW_SIZE.x-52.f,176.f}; - Menu*inputKeyboardWindow=CreateMenu(INPUT_KEYBOARD,CENTERED,menuSize); + Menu*inputKeyboardWindow=CreateMenu(INPUT_KEY_DISPLAY,CENTERED,menuSize); float inputWindowWidth=menuSize.x-8; @@ -57,9 +58,11 @@ void Menu::InitializeKeyboardInputWindow(){ inputKeyboardWindow->ADD("Menu Inputs Background",MenuLabel)(geom2d::rect{{4,32},{menuSize.x-8,56.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; - for(int row=0;row<4;row++){ - for(int col=0;col<2;col++){ - if(col==1&&row==3)continue; + const int menuRowCount=DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==0?DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2:DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2+1; + const int menuColCount=2; + for(int row=0;rowADD("Controller Inputs Background",MenuLabel)(geom2d::rect{{4,100},{menuSize.x-8,68.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; - - for(int row=0;row<5;row++){ - for(int col=0;col<2;col++){ - if(col==1&&row==4)continue; + + const int ingameControlsRowCount=DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()%2==0?DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()/2:DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()/2+1; + const int ingameControlsColCount=2; + for(int row=0;rowB(A::IS_KEYBOARD)){ //We are requesting a brand new controller input. + if(InputGroup::menuNamesToInputGroups.count(Menu::menus[NEW_INPUT]->S(A::KEYBIND))){ + for(GamePad*gamepad:GamePad::getGamepads()){ + for(size_t button=0;bool hasButton:gamepad->availableButtons){ + GPButtons releasedButton=olc::GPButtons(button); + if(hasButton&&gamepad->getButton(releasedButton).bReleased){ + if(releasedButton==GPButtons::SELECT){ //If we hit select we don't bother with setting the input and leave immediately. + Menu::CloseMenu(); + return; + } + + InputGroup::menuNamesToInputGroups[Menu::menus[NEW_INPUT]->S(A::KEYBIND)]->SetNewPrimaryKeybind(Input{CONTROLLER,int(button)}); + Menu::alreadyClicked=true; + Menu::CloseMenu(); + return; + } + button++; + } + } + } + } + #pragma endregion } \ No newline at end of file diff --git a/Adventures in Lestoria/Key.h b/Adventures in Lestoria/Key.h index 2d993be5..25eb96ff 100644 --- a/Adventures in Lestoria/Key.h +++ b/Adventures in Lestoria/Key.h @@ -86,6 +86,7 @@ class InputGroup{ friend class AiL; friend class Menu; friend class State_OverworldMap; + friend class InputListener; std::setkeys; std::vectorkeyOrder; //A list of keys inserted in order, for primary key mapping. static safemapmenuNamesToInputGroups; @@ -134,6 +135,11 @@ public: static std::map,KeyInfo>keyLiteral; //The displayed text for a given key for a given input type. }; +class InputListener{ +public: + static void Update(); +}; + const bool operator<(const InputGroup&group1,const InputGroup&group2); const bool operator<(const InputEngageGroup&group1,const InputEngageGroup&group2); diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index 4422463a..7ac8ed39 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -101,7 +101,6 @@ void Menu::InitializeMenus(){ InitializeSettingsWindow(); InitializeShermanWindow(); InitializeKeyboardInputWindow(); - InitializeControllerInputWindow(); InitializeNewKeybindInputWindow(); for(MenuType type=MenuType(int(MenuType::ENUM_START)+1);typeADD("Keyboard Play Auto-Aim Label",MenuLabel)(geom2d::rect{{windowSize.x/2-68.f,104},{windowSize.x/2+54.f,16.f}},"Keyboard Aim Assist\n (For Keyboard Only Players)",1.f,ComponentAttr::SHADOW)END; - settingsWindow->ADD("Keyboard Bindings Label",MenuComponent)(geom2d::rect{{28,132.f},vf2d{windowSize.x-32,24}},"Keyboard Bindings",MenuType::INPUT_KEYBOARD,DO_NOTHING,vf2d{1.5f,2.f})END; - settingsWindow->ADD("Controller Bindings Label",MenuComponent)(geom2d::rect{{28,160.f},vf2d{windowSize.x-32,24}},"Controller Bindings",MenuType::INPUT_CONTROLLER,DO_NOTHING,vf2d{1.5f,2.f})END; + settingsWindow->ADD("Keyboard Bindings Button",MenuComponent)(geom2d::rect{{28,132.f},vf2d{windowSize.x-32,24}},"Keyboard Bindings",MenuType::INPUT_KEY_DISPLAY,DO_NOTHING,vf2d{1.5f,2.f})END; + settingsWindow->ADD("Controller Bindings Button",MenuComponent)(geom2d::rect{{28,160.f},vf2d{windowSize.x-32,24}},"Controller Bindings",MenuType::INPUT_KEY_DISPLAY,DO_NOTHING,vf2d{1.5f,2.f})END; settingsWindow->ADD("Go Back",MenuComponent)(geom2d::rect{vf2d{windowSize.x/2.f,windowSize.y}-vf2d{36,16},{72,12}},"Go Back",[](MenuFuncData data){ Menu::CloseMenu(); diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index c6ebaf5b..a0711560 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 3 #define VERSION_PATCH 0 -#define VERSION_BUILD 6854 +#define VERSION_BUILD 6859 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Adventures in Lestoria/olcPGEX_Gamepad.h b/Adventures in Lestoria/olcPGEX_Gamepad.h index 76a3b1b5..2e16383a 100644 --- a/Adventures in Lestoria/olcPGEX_Gamepad.h +++ b/Adventures in Lestoria/olcPGEX_Gamepad.h @@ -156,6 +156,7 @@ namespace olc { class GamePad : public olc::PGEX { friend class Input; + friend class InputListener; public: #ifdef WIN32 GamePad(LPCDIDEVICEINSTANCEA lpddi);