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

pull/35/head
sigonasr2 1 year ago
parent 2da6c455b6
commit 3fff17417e
  1. 4
      Adventures in Lestoria/Adventures in Lestoria.vcxproj
  2. 3
      Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters
  3. 4
      Adventures in Lestoria/AdventuresInLestoria.cpp
  4. 46
      Adventures in Lestoria/InputControllerWindow.cpp
  5. 6
      Adventures in Lestoria/InputDisplayComponent.h
  6. 19
      Adventures in Lestoria/InputKeyboardWindow.cpp
  7. 27
      Adventures in Lestoria/Key.cpp
  8. 6
      Adventures in Lestoria/Key.h
  9. 1
      Adventures in Lestoria/Menu.cpp
  10. 2
      Adventures in Lestoria/Menu.h
  11. 5
      Adventures in Lestoria/MenuType.h
  12. 4
      Adventures in Lestoria/SettingsWindow.cpp
  13. 2
      Adventures in Lestoria/Version.h
  14. 1
      Adventures in Lestoria/olcPGEX_Gamepad.h

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

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

@ -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;

@ -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});
}

@ -41,11 +41,13 @@ All rights reserved.
class InputDisplayComponent:public MenuComponent{
const InputGroup&input;
const InputType type;
InputType type;
public:
inline InputDisplayComponent(geom2d::rect<float>pos,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);

@ -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<float>{{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;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.
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;
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;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;
std::string inputDisplayName="Inputs.Gameplay Input Names"_s[inputID];

@ -555,3 +555,30 @@ void InputGroup::SetNewPrimaryKeybind(Input key){
RemovePrimaryKeybind(key.GetType());
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
}

@ -86,6 +86,7 @@ class InputGroup{
friend class AiL;
friend class Menu;
friend class State_OverworldMap;
friend class InputListener;
std::set<Input>keys;
std::vector<Input>keyOrder; //A list of keys inserted in order, for primary key mapping.
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.
};
class InputListener{
public:
static void Update();
};
const bool operator<(const InputGroup&group1,const InputGroup&group2);
const bool operator<(const InputEngageGroup&group1,const InputEngageGroup&group2);

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

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

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

@ -93,8 +93,8 @@ void Menu::InitializeSettingsWindow(){
},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 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("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("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 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){
Menu::CloseMenu();

@ -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

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

Loading…
Cancel
Save