Fix DAS Input for menu navigation.

pull/35/head
sigonasr2 10 months ago
parent cbc4fa5470
commit b0e9799624
  1. 85
      Adventures in Lestoria/Key.cpp
  2. 13
      Adventures in Lestoria/Key.h
  3. 2
      Adventures in Lestoria/Version.h
  4. BIN
      x64/Release/Adventures in Lestoria.exe

@ -79,60 +79,6 @@ bool Input::Pressed(){
return false;
}
bool Input::PressedDAS(){
if(!game->IsFocused())return false;
bool inputPressed=false;
auto HandleDAS=[&](const HWButton&button){
if(button.bPressed){
if(initialHoldDownTime==0.f){
initialHoldDownTime="Interface.InitialScrollDelay"_F;
}
return true;
}else
if(button.bHeld&&initialHoldDownTime>0.f){
initialHoldDownTime-=game->GetElapsedTime();
if(initialHoldDownTime<=0.f){
holdDownTime="Interface.ScrollDelay"_F;
return true;
}
}else
if(button.bHeld&&holdDownTime>0.f){
holdDownTime-=game->GetElapsedTime();
if(holdDownTime<=0.f){
holdDownTime="Interface.ScrollDelay"_F;
return true;
}
}
return false;
};
switch(type){
case KEY:{
if(HandleDAS(game->GetKey(Key(key))))inputPressed=true;
}break;
case MOUSE:{
if(HandleDAS(game->GetMouse(key)))inputPressed=true;
}break;
case CONTROLLER:{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected)if(HandleDAS(gamepad->getButton(static_cast<GPButtons>(key))))inputPressed=true;
}
}break;
case ANALOG:{
//An analog input can never be "pressed". No-op.
}break;
default:{
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
}
}
if(inputPressed){
usingGamepad=type==CONTROLLER;
return true;
}
return false;
}
bool Input::Held(){
if(!game->IsFocused())return false;
bool inputHeld=false;
@ -186,7 +132,6 @@ bool Input::Released(){
}
if(inputReleased){
usingGamepad=type==CONTROLLER;
initialHoldDownTime=holdDownTime=0.f; //Reset hold times if we release the key.
return true;
}
return false;
@ -264,9 +209,28 @@ const bool InputGroup::Pressed()const{
return false;
}
const bool InputGroup::PressedDAS()const{
const bool InputGroup::PressedDAS(){
for(Input input:keys){
if(input.PressedDAS())return true;
if(input.Pressed()){
if(initialHoldDownTime==0.f){
initialHoldDownTime="Interface.InitialScrollDelay"_F;
}
return true;
}else
if(input.Held()&&initialHoldDownTime>0.f){
initialHoldDownTime-=game->GetElapsedTime();
if(initialHoldDownTime<=0.f){
holdDownTime="Interface.ScrollDelay"_F;
return true;
}
}else
if(input.Held()&&holdDownTime>0.f){
holdDownTime-=game->GetElapsedTime();
if(holdDownTime<=0.f){
holdDownTime="Interface.ScrollDelay"_F;
return true;
}
}
}
return false;
}
@ -278,9 +242,12 @@ const bool InputGroup::Held()const{
return false;
}
const bool InputGroup::Released()const{
const bool InputGroup::Released(){
for(Input input:keys){
if(input.Released())return true;
if(input.Released()){
initialHoldDownTime=holdDownTime=0.f; //Reset hold times if we release the key.
return true;
}
}
return false;
}

@ -57,18 +57,15 @@ enum InputType{
//A generic class that represents any type of input.
class Input{
friend class InputGroup;
friend class State_MainMenu;
InputType type;
int key; //This will be interpreted differently depending on input type.
static bool usingGamepad;
static void SetUsingGamepad(const bool usingGamepad);
float holdDownTime=0.f;
float initialHoldDownTime=0.f;
public:
Input(InputType type,int key);
bool Pressed();
//A version of Pressed() that will continuously return true after holding down for some time. Useful for scrolling through menus.
bool PressedDAS();
bool Held();
bool Released();
float Analog();
@ -94,11 +91,15 @@ class InputGroup{
friend class State_OverworldMap;
friend class InputListener;
friend class SaveFile;
friend class State_MainMenu;
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;
void RemovePrimaryKeybind(InputType type);
void AddPrimaryKeybind(Input key);
float holdDownTime=0.f;
float initialHoldDownTime=0.f;
public:
InputGroup();
void AddKeybind(Input bind);
@ -106,9 +107,9 @@ public:
void SetNewPrimaryKeybind(Input key);
const bool Pressed()const;
//A version of Pressed() that will continuously return true after holding down for some time. Useful for scrolling through menus.
const bool PressedDAS()const;
const bool PressedDAS();
const bool Held()const;
const bool Released()const;
const bool Released();
const float Analog()const;
std::string GetDisplayName();
//Draws an input display with accompanying text centered at given position.

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

Loading…
Cancel
Save