Add DAs input functions
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
6778ffc72d
commit
cbc4fa5470
@ -79,6 +79,60 @@ 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;
|
||||
@ -132,6 +186,7 @@ bool Input::Released(){
|
||||
}
|
||||
if(inputReleased){
|
||||
usingGamepad=type==CONTROLLER;
|
||||
initialHoldDownTime=holdDownTime=0.f; //Reset hold times if we release the key.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -209,6 +264,13 @@ const bool InputGroup::Pressed()const{
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool InputGroup::PressedDAS()const{
|
||||
for(Input input:keys){
|
||||
if(input.PressedDAS())return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool InputGroup::Held()const{
|
||||
for(Input input:keys){
|
||||
if(input.Held())return true;
|
||||
|
@ -61,9 +61,14 @@ class Input{
|
||||
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();
|
||||
@ -100,6 +105,8 @@ public:
|
||||
void RemoveKeybind(Input bind);
|
||||
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 Held()const;
|
||||
const bool Released()const;
|
||||
const float Analog()const;
|
||||
|
@ -342,7 +342,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
if(navigationGroups.count(selectionButtonName)){
|
||||
Navigation nav=navigationGroups[selectionButtonName];
|
||||
|
||||
if(game->KEY_UP.Pressed()){
|
||||
if(game->KEY_UP.PressedDAS()){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.up)&&std::get<std::string>(nav.up).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.up)));
|
||||
else
|
||||
@ -352,7 +352,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
SetSelection(returnData);
|
||||
}
|
||||
}
|
||||
if(game->KEY_DOWN.Pressed()){
|
||||
if(game->KEY_DOWN.PressedDAS()){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.down)&&std::get<std::string>(nav.down).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.down)));
|
||||
else
|
||||
@ -362,7 +362,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
SetSelection(returnData);
|
||||
}
|
||||
}
|
||||
if(game->KEY_LEFT.Pressed()){
|
||||
if(game->KEY_LEFT.PressedDAS()){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.left)&&std::get<std::string>(nav.left).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.left)));
|
||||
else
|
||||
@ -372,7 +372,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
SetSelection(returnData);
|
||||
}
|
||||
}
|
||||
if(game->KEY_RIGHT.Pressed()){
|
||||
if(game->KEY_RIGHT.PressedDAS()){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.right)&&std::get<std::string>(nav.right).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.right)));
|
||||
else
|
||||
|
@ -1,7 +1,10 @@
|
||||
Interface
|
||||
{
|
||||
# In pixels/sec
|
||||
AnalogScrollSpeed = 220
|
||||
# How long to wait for the first initial delay auto shift to occur.
|
||||
InitialScrollDelay = 0.4s
|
||||
|
||||
# How long to wait for subsequent scrolling through menu items.
|
||||
ScrollDelay = 0.2s
|
||||
|
||||
# The size of each side of the 9-patch menu sprite.
|
||||
9PatchSize = 24,24
|
||||
|
@ -1,4 +1,4 @@
|
||||
clear
|
||||
source ./emsdk/emsdk_env.sh
|
||||
emcmake cmake -DCMAKE_BUILD_TYPE=Release .
|
||||
cmake --build . -j 8
|
||||
cmake --build . -j 20
|
@ -1,4 +1,4 @@
|
||||
clear
|
||||
source ./emsdk/emsdk_env.sh
|
||||
emcmake cmake -DCMAKE_BUILD_TYPE=Debug -D_DEBUG=1 .
|
||||
cmake --build . -j 8
|
||||
cmake --build . -j 20
|
Loading…
x
Reference in New Issue
Block a user