Refactored the input display menu to allow for dynamic changing of row displays. Remove controller specific keybinding menu, integrating with initial keyboard menu.

This commit is contained in:
sigonasr2 2024-02-07 17:58:29 -06:00
parent 2da6c455b6
commit 3fff17417e
14 changed files with 59 additions and 73 deletions

View File

@ -590,10 +590,6 @@
</SubType> </SubType>
</ClCompile> </ClCompile>
<ClCompile Include="GameState.cpp" /> <ClCompile Include="GameState.cpp" />
<ClCompile Include="InputControllerWindow.cpp">
<SubType>
</SubType>
</ClCompile>
<ClCompile Include="InputHelper.cpp"> <ClCompile Include="InputHelper.cpp">
<SubType> <SubType>
</SubType> </SubType>

View File

@ -788,9 +788,6 @@
<ClCompile Include="InputKeyboardWindow.cpp"> <ClCompile Include="InputKeyboardWindow.cpp">
<Filter>Source Files\Interface</Filter> <Filter>Source Files\Interface</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="InputControllerWindow.cpp">
<Filter>Source Files\Interface</Filter>
</ClCompile>
<ClCompile Include="InputNewKeybindWindow.cpp"> <ClCompile Include="InputNewKeybindWindow.cpp">
<Filter>Source Files\Interface</Filter> <Filter>Source Files\Interface</Filter>
</ClCompile> </ClCompile>

View File

@ -283,6 +283,7 @@ bool AiL::OnUserUpdate(float fElapsedTime){
if(!GamePaused()){ if(!GamePaused()){
GameState::STATE->OnUserUpdate(this); GameState::STATE->OnUserUpdate(this);
} }
InputListener::Update();
Audio::Update(); Audio::Update();
RenderWorld(GetElapsedTime()); RenderWorld(GetElapsedTime());
GameState::STATE->Draw(this); GameState::STATE->Draw(this);
@ -3081,7 +3082,8 @@ const uint8_t AiL::BossEncounterMobCount()const{
void AiL::GetAnyKeyRelease(Key key){ void AiL::GetAnyKeyRelease(Key key){
if(key!=0){ if(key!=0){
#pragma region New keyboard input binding listener #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. if(key==ESCAPE){ //If we hit escape we don't bother with setting the input and leave immediately.
Menu::CloseMenu(); Menu::CloseMenu();
return; return;

View File

@ -1,46 +0,0 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
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});
}

View File

@ -41,11 +41,13 @@ All rights reserved.
class InputDisplayComponent:public MenuComponent{ class InputDisplayComponent:public MenuComponent{
const InputGroup&input; const InputGroup&input;
const InputType type; InputType type;
public: public:
inline InputDisplayComponent(geom2d::rect<float>pos,InputGroup&input,InputType type,MenuFunc onClick) inline InputDisplayComponent(geom2d::rect<float>pos,InputGroup&input,InputType type,MenuFunc onClick)
:MenuComponent(pos,"",onClick,ButtonAttr::NONE),input(input),type(type){} :MenuComponent(pos,"",onClick,ButtonAttr::NONE),input(input),type(type){}
inline void SetKeyType(const InputType type){
this->type=type;
}
protected: protected:
inline void DrawDecal(ViewPort&window,bool focused)override{ inline void DrawDecal(ViewPort&window,bool focused)override{
MenuComponent::DrawDecal(window,focused); MenuComponent::DrawDecal(window,focused);

View File

@ -45,11 +45,12 @@ All rights reserved.
using A=Attribute; using A=Attribute;
INCLUDE_WINDOW_SIZE INCLUDE_WINDOW_SIZE
INCLUDE_DATA
void Menu::InitializeKeyboardInputWindow(){ void Menu::InitializeKeyboardInputWindow(){
vf2d menuSize={WINDOW_SIZE.x-52.f,176.f}; 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; float inputWindowWidth=menuSize.x-8;
@ -57,9 +58,11 @@ void Menu::InitializeKeyboardInputWindow(){
inputKeyboardWindow->ADD("Menu Inputs Background",MenuLabel)(geom2d::rect<float>{{4,32},{menuSize.x-8,56.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; inputKeyboardWindow->ADD("Menu Inputs Background",MenuLabel)(geom2d::rect<float>{{4,32},{menuSize.x-8,56.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END;
for(int row=0;row<4;row++){ 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;
for(int col=0;col<2;col++){ const int menuColCount=2;
if(col==1&&row==3)continue; for(int row=0;row<menuRowCount;row++){
for(int col=0;col<menuColCount;col++){
if(DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==1&&col==1&&row==menuRowCount-1)continue; //We only continue on a blank space when we have an odd number of elements.
//Exclude the very last item because we only have 9 inputs to list. //Exclude the very last item because we only have 9 inputs to list.
int inputID=row*2+col; int inputID=row*2+col;
@ -83,9 +86,11 @@ void Menu::InitializeKeyboardInputWindow(){
inputKeyboardWindow->ADD("Controller Inputs Background",MenuLabel)(geom2d::rect<float>{{4,100},{menuSize.x-8,68.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; inputKeyboardWindow->ADD("Controller Inputs Background",MenuLabel)(geom2d::rect<float>{{4,100},{menuSize.x-8,68.f}},"",1.f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END;
for(int row=0;row<5;row++){ 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;
for(int col=0;col<2;col++){ const int ingameControlsColCount=2;
if(col==1&&row==4)continue; for(int row=0;row<ingameControlsRowCount;row++){
for(int col=0;col<ingameControlsColCount;col++){
if(DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()%2==1&&col==1&&row==ingameControlsRowCount-1)continue; //We only continue on a blank space when we have an odd number of elements.
int inputID=row*2+col; int inputID=row*2+col;
std::string inputDisplayName="Inputs.Gameplay Input Names"_s[inputID]; std::string inputDisplayName="Inputs.Gameplay Input Names"_s[inputID];

View File

@ -555,3 +555,30 @@ void InputGroup::SetNewPrimaryKeybind(Input key){
RemovePrimaryKeybind(key.GetType()); RemovePrimaryKeybind(key.GetType());
AddPrimaryKeybind(key); AddPrimaryKeybind(key);
} }
void InputListener::Update(){
#pragma region New controller input binding listener
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 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
}

View File

@ -86,6 +86,7 @@ class InputGroup{
friend class AiL; friend class AiL;
friend class Menu; friend class Menu;
friend class State_OverworldMap; friend class State_OverworldMap;
friend class InputListener;
std::set<Input>keys; std::set<Input>keys;
std::vector<Input>keyOrder; //A list of keys inserted in order, for primary key mapping. std::vector<Input>keyOrder; //A list of keys inserted in order, for primary key mapping.
static safemap<std::string,InputGroup*>menuNamesToInputGroups; static safemap<std::string,InputGroup*>menuNamesToInputGroups;
@ -134,6 +135,11 @@ public:
static std::map<std::pair<InputType,int>,KeyInfo>keyLiteral; //The displayed text for a given key for a given input type. static std::map<std::pair<InputType,int>,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 InputGroup&group1,const InputGroup&group2);
const bool operator<(const InputEngageGroup&group1,const InputEngageGroup&group2); const bool operator<(const InputEngageGroup&group1,const InputEngageGroup&group2);

View File

@ -101,7 +101,6 @@ void Menu::InitializeMenus(){
InitializeSettingsWindow(); InitializeSettingsWindow();
InitializeShermanWindow(); InitializeShermanWindow();
InitializeKeyboardInputWindow(); InitializeKeyboardInputWindow();
InitializeControllerInputWindow();
InitializeNewKeybindInputWindow(); InitializeNewKeybindInputWindow();
for(MenuType type=MenuType(int(MenuType::ENUM_START)+1);type<MenuType::ENUM_END;type=MenuType(int(type+1))){ for(MenuType type=MenuType(int(MenuType::ENUM_START)+1);type<MenuType::ENUM_END;type=MenuType(int(type+1))){

View File

@ -113,12 +113,12 @@ class Menu:public IAttributable{
static void InitializeSettingsWindow(); static void InitializeSettingsWindow();
static void InitializeShermanWindow(); static void InitializeShermanWindow();
static void InitializeKeyboardInputWindow(); static void InitializeKeyboardInputWindow();
static void InitializeControllerInputWindow();
static void InitializeNewKeybindInputWindow(); static void InitializeNewKeybindInputWindow();
friend class AiL; friend class AiL;
friend class ItemInfo; friend class ItemInfo;
friend class EntityStats; friend class EntityStats;
friend class InputListener;
float buttonHoldTime=0; float buttonHoldTime=0;
static vi2d lastActiveMousePos; static vi2d lastActiveMousePos;

View File

@ -37,8 +37,6 @@ All rights reserved.
#pragma endregion #pragma endregion
#pragma once #pragma once
#undef INPUT_KEYBOARD //Stupid Windows.
enum MenuType{ enum MenuType{
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
/*DO NOT REMOVE!!*/ENUM_START,/////////////////////////////// /*DO NOT REMOVE!!*/ENUM_START,///////////////////////////////
@ -65,8 +63,7 @@ enum MenuType{
USER_ID, USER_ID,
SETTINGS, SETTINGS,
SHERMAN, SHERMAN,
INPUT_KEYBOARD, INPUT_KEY_DISPLAY,
INPUT_CONTROLLER,
NEW_INPUT, NEW_INPUT,
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
/*DO NOT REMOVE!!*/ENUM_END//////////////////////////////// /*DO NOT REMOVE!!*/ENUM_END////////////////////////////////

View File

@ -93,8 +93,8 @@ void Menu::InitializeSettingsWindow(){
},false)END; },false)END;
settingsWindow->ADD("Keyboard Play Auto-Aim Label",MenuLabel)(geom2d::rect<float>{{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 Play Auto-Aim Label",MenuLabel)(geom2d::rect<float>{{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<float>{{28,132.f},vf2d{windowSize.x-32,24}},"Keyboard Bindings",MenuType::INPUT_KEYBOARD,DO_NOTHING,vf2d{1.5f,2.f})END; settingsWindow->ADD("Keyboard Bindings Button",MenuComponent)(geom2d::rect<float>{{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 Label",MenuComponent)(geom2d::rect<float>{{28,160.f},vf2d{windowSize.x-32,24}},"Controller Bindings",MenuType::INPUT_CONTROLLER,DO_NOTHING,vf2d{1.5f,2.f})END; settingsWindow->ADD("Controller Bindings Button",MenuComponent)(geom2d::rect<float>{{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<float>{vf2d{windowSize.x/2.f,windowSize.y}-vf2d{36,16},{72,12}},"Go Back",[](MenuFuncData data){ settingsWindow->ADD("Go Back",MenuComponent)(geom2d::rect<float>{vf2d{windowSize.x/2.f,windowSize.y}-vf2d{36,16},{72,12}},"Go Back",[](MenuFuncData data){
Menu::CloseMenu(); Menu::CloseMenu();

View File

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 3 #define VERSION_MINOR 3
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 6854 #define VERSION_BUILD 6859
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

View File

@ -156,6 +156,7 @@ namespace olc {
class GamePad : public olc::PGEX { class GamePad : public olc::PGEX {
friend class Input; friend class Input;
friend class InputListener;
public: public:
#ifdef WIN32 #ifdef WIN32
GamePad(LPCDIDEVICEINSTANCEA lpddi); GamePad(LPCDIDEVICEINSTANCEA lpddi);