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;
|
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;
|
||||||
@ -132,6 +186,7 @@ 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;
|
||||||
@ -209,6 +264,13 @@ const bool InputGroup::Pressed()const{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool InputGroup::PressedDAS()const{
|
||||||
|
for(Input input:keys){
|
||||||
|
if(input.PressedDAS())return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const bool InputGroup::Held()const{
|
const bool InputGroup::Held()const{
|
||||||
for(Input input:keys){
|
for(Input input:keys){
|
||||||
if(input.Held())return true;
|
if(input.Held())return true;
|
||||||
|
@ -61,9 +61,14 @@ class Input{
|
|||||||
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.
|
||||||
|
bool PressedDAS();
|
||||||
bool Held();
|
bool Held();
|
||||||
bool Released();
|
bool Released();
|
||||||
float Analog();
|
float Analog();
|
||||||
@ -100,6 +105,8 @@ public:
|
|||||||
void RemoveKeybind(Input bind);
|
void RemoveKeybind(Input bind);
|
||||||
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.
|
||||||
|
const bool PressedDAS()const;
|
||||||
const bool Held()const;
|
const bool Held()const;
|
||||||
const bool Released()const;
|
const bool Released()const;
|
||||||
const float Analog()const;
|
const float Analog()const;
|
||||||
|
@ -342,7 +342,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
|||||||
if(navigationGroups.count(selectionButtonName)){
|
if(navigationGroups.count(selectionButtonName)){
|
||||||
Navigation nav=navigationGroups[selectionButtonName];
|
Navigation nav=navigationGroups[selectionButtonName];
|
||||||
|
|
||||||
if(game->KEY_UP.Pressed()){
|
if(game->KEY_UP.PressedDAS()){
|
||||||
SetMouseNavigation(false);
|
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)));
|
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
|
else
|
||||||
@ -352,7 +352,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
|||||||
SetSelection(returnData);
|
SetSelection(returnData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(game->KEY_DOWN.Pressed()){
|
if(game->KEY_DOWN.PressedDAS()){
|
||||||
SetMouseNavigation(false);
|
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)));
|
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
|
else
|
||||||
@ -362,7 +362,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
|||||||
SetSelection(returnData);
|
SetSelection(returnData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(game->KEY_LEFT.Pressed()){
|
if(game->KEY_LEFT.PressedDAS()){
|
||||||
SetMouseNavigation(false);
|
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)));
|
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
|
else
|
||||||
@ -372,7 +372,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
|||||||
SetSelection(returnData);
|
SetSelection(returnData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(game->KEY_RIGHT.Pressed()){
|
if(game->KEY_RIGHT.PressedDAS()){
|
||||||
SetMouseNavigation(false);
|
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)));
|
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
|
else
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
Interface
|
Interface
|
||||||
{
|
{
|
||||||
# In pixels/sec
|
# How long to wait for the first initial delay auto shift to occur.
|
||||||
AnalogScrollSpeed = 220
|
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.
|
# The size of each side of the 9-patch menu sprite.
|
||||||
9PatchSize = 24,24
|
9PatchSize = 24,24
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
clear
|
clear
|
||||||
source ./emsdk/emsdk_env.sh
|
source ./emsdk/emsdk_env.sh
|
||||||
emcmake cmake -DCMAKE_BUILD_TYPE=Release .
|
emcmake cmake -DCMAKE_BUILD_TYPE=Release .
|
||||||
cmake --build . -j 8
|
cmake --build . -j 20
|
@ -1,4 +1,4 @@
|
|||||||
clear
|
clear
|
||||||
source ./emsdk/emsdk_env.sh
|
source ./emsdk/emsdk_env.sh
|
||||||
emcmake cmake -DCMAKE_BUILD_TYPE=Debug -D_DEBUG=1 .
|
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