Fix DAS Input for menu navigation.
This commit is contained in:
parent
cbc4fa5470
commit
b0e9799624
@ -79,60 +79,6 @@ bool Input::Pressed(){
|
|||||||
return false;
|
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(){
|
bool Input::Held(){
|
||||||
if(!game->IsFocused())return false;
|
if(!game->IsFocused())return false;
|
||||||
bool inputHeld=false;
|
bool inputHeld=false;
|
||||||
@ -186,7 +132,6 @@ bool Input::Released(){
|
|||||||
}
|
}
|
||||||
if(inputReleased){
|
if(inputReleased){
|
||||||
usingGamepad=type==CONTROLLER;
|
usingGamepad=type==CONTROLLER;
|
||||||
initialHoldDownTime=holdDownTime=0.f; //Reset hold times if we release the key.
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -264,9 +209,28 @@ const bool InputGroup::Pressed()const{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool InputGroup::PressedDAS()const{
|
const bool InputGroup::PressedDAS(){
|
||||||
for(Input input:keys){
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -278,9 +242,12 @@ const bool InputGroup::Held()const{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool InputGroup::Released()const{
|
const bool InputGroup::Released(){
|
||||||
for(Input input:keys){
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -57,18 +57,15 @@ enum InputType{
|
|||||||
//A generic class that represents any type of input.
|
//A generic class that represents any type of input.
|
||||||
class Input{
|
class Input{
|
||||||
friend class InputGroup;
|
friend class InputGroup;
|
||||||
|
friend class State_MainMenu;
|
||||||
InputType type;
|
InputType type;
|
||||||
int key; //This will be interpreted differently depending on input type.
|
int key; //This will be interpreted differently depending on input type.
|
||||||
static bool usingGamepad;
|
static bool usingGamepad;
|
||||||
static void SetUsingGamepad(const bool usingGamepad);
|
static void SetUsingGamepad(const bool usingGamepad);
|
||||||
|
|
||||||
float holdDownTime=0.f;
|
|
||||||
float initialHoldDownTime=0.f;
|
|
||||||
public:
|
public:
|
||||||
Input(InputType type,int key);
|
Input(InputType type,int key);
|
||||||
bool Pressed();
|
bool Pressed();
|
||||||
//A version of Pressed() that will continuously return true after holding down for some time. Useful for scrolling through menus.
|
//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 Held();
|
||||||
bool Released();
|
bool Released();
|
||||||
float Analog();
|
float Analog();
|
||||||
@ -94,11 +91,15 @@ class InputGroup{
|
|||||||
friend class State_OverworldMap;
|
friend class State_OverworldMap;
|
||||||
friend class InputListener;
|
friend class InputListener;
|
||||||
friend class SaveFile;
|
friend class SaveFile;
|
||||||
|
friend class State_MainMenu;
|
||||||
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;
|
||||||
void RemovePrimaryKeybind(InputType type);
|
void RemovePrimaryKeybind(InputType type);
|
||||||
void AddPrimaryKeybind(Input key);
|
void AddPrimaryKeybind(Input key);
|
||||||
|
|
||||||
|
float holdDownTime=0.f;
|
||||||
|
float initialHoldDownTime=0.f;
|
||||||
public:
|
public:
|
||||||
InputGroup();
|
InputGroup();
|
||||||
void AddKeybind(Input bind);
|
void AddKeybind(Input bind);
|
||||||
@ -106,9 +107,9 @@ public:
|
|||||||
void SetNewPrimaryKeybind(Input key);
|
void SetNewPrimaryKeybind(Input key);
|
||||||
const bool Pressed()const;
|
const bool Pressed()const;
|
||||||
//A version of Pressed() that will continuously return true after holding down for some time. Useful for scrolling through menus.
|
//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 Held()const;
|
||||||
const bool Released()const;
|
const bool Released();
|
||||||
const float Analog()const;
|
const float Analog()const;
|
||||||
std::string GetDisplayName();
|
std::string GetDisplayName();
|
||||||
//Draws an input display with accompanying text centered at given position.
|
//Draws an input display with accompanying text centered at given position.
|
||||||
|
@ -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 6915
|
#define VERSION_BUILD 6923
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user