|
|
|
@ -41,51 +41,77 @@ All rights reserved. |
|
|
|
|
#include "olcPGEX_Gamepad.h" |
|
|
|
|
#include "Menu.h" |
|
|
|
|
#include "GameSettings.h" |
|
|
|
|
#include <isteaminput.h> |
|
|
|
|
|
|
|
|
|
INCLUDE_game |
|
|
|
|
INCLUDE_GFX |
|
|
|
|
|
|
|
|
|
bool Input::usingGamepad; |
|
|
|
|
uint64_t Input::ingameControlsHandle; |
|
|
|
|
uint64_t Input::menuControlsHandle; |
|
|
|
|
uint64_t Input::ingameControlsHandle{0}; |
|
|
|
|
uint64_t Input::menuControlsHandle{0}; |
|
|
|
|
uint8_t activeSteamControllerIndex{0}; |
|
|
|
|
safemap<std::string,InputGroup*>InputGroup::menuNamesToInputGroups; |
|
|
|
|
std::vector<std::string>InputGroup::menuInputGroups; |
|
|
|
|
std::vector<std::string>InputGroup::gameplayInputGroups; |
|
|
|
|
std::array<InputHandle_t,16>Input::steamControllers; |
|
|
|
|
uint8_t Input::activeSteamControllerIndex; |
|
|
|
|
|
|
|
|
|
safemap<Steam::SteamInput,std::string>Input::enumToActionName; |
|
|
|
|
std::array<std::unordered_map<Steam::SteamInput,std::pair<std::string,HWButton>>,16>Input::enumToActionName; |
|
|
|
|
|
|
|
|
|
Input::Input(InputType type,int key) |
|
|
|
|
:type(type),key(key){} |
|
|
|
|
|
|
|
|
|
void Input::Initialize(){ |
|
|
|
|
enumToActionName[Steam::MOVE]="Move"; |
|
|
|
|
enumToActionName[Steam::MANUAL_AIM]="Manual Aim"; |
|
|
|
|
enumToActionName[Steam::BASIC_ATTACK]="Basic_Attack"; |
|
|
|
|
enumToActionName[Steam::DEFENSIVE]="Defensive"; |
|
|
|
|
enumToActionName[Steam::MENU_PAUSE]="Menu/Pause"; |
|
|
|
|
enumToActionName[Steam::ABILITY_1]="Ability_1"; |
|
|
|
|
enumToActionName[Steam::ABILITY_2]="Ability_2"; |
|
|
|
|
enumToActionName[Steam::ABILITY_3]="Ability_3"; |
|
|
|
|
enumToActionName[Steam::ABILITY_4]="Ability_4"; |
|
|
|
|
enumToActionName[Steam::ITEM_1]="Item_1"; |
|
|
|
|
enumToActionName[Steam::ITEM_2]="Item_2"; |
|
|
|
|
enumToActionName[Steam::ITEM_3]="Item_3"; |
|
|
|
|
enumToActionName[Steam::NAVIGATE]="Navigate"; |
|
|
|
|
enumToActionName[Steam::SCROLL]="Scroll"; |
|
|
|
|
enumToActionName[Steam::CONFIRM]="Confirm"; |
|
|
|
|
enumToActionName[Steam::BACK]="Back"; |
|
|
|
|
enumToActionName[Steam::FUNCTION_1]="Function_1"; |
|
|
|
|
enumToActionName[Steam::FUNCTION_2]="Function_2"; |
|
|
|
|
enumToActionName[Steam::UP]="Up"; |
|
|
|
|
enumToActionName[Steam::DOWN]="Down"; |
|
|
|
|
enumToActionName[Steam::LEFT]="Left"; |
|
|
|
|
enumToActionName[Steam::RIGHT]="Right"; |
|
|
|
|
enumToActionName[Steam::LOCK_UNLOCK_ACC]="Lock/Unlock Accessory"; |
|
|
|
|
enumToActionName[Steam::FAST_SCROLL_UP]="Fast_Scroll_Up"; |
|
|
|
|
enumToActionName[Steam::FAST_SCROLL_DOWN]="Fast_Scroll_Down"; |
|
|
|
|
|
|
|
|
|
enumToActionName.SetInitialized(); |
|
|
|
|
for(int i=0;i<16;i++){ |
|
|
|
|
enumToActionName[i][Steam::MOVE]={"Move",{}}; |
|
|
|
|
enumToActionName[i][Steam::MANUAL_AIM]={"Manual Aim",{}}; |
|
|
|
|
enumToActionName[i][Steam::BASIC_ATTACK]={"Basic_Attack",{}}; |
|
|
|
|
enumToActionName[i][Steam::DEFENSIVE]={"Defensive",{}}; |
|
|
|
|
enumToActionName[i][Steam::MENU_PAUSE]={"Menu/Pause",{}}; |
|
|
|
|
enumToActionName[i][Steam::ABILITY_1]={"Ability_1",{}}; |
|
|
|
|
enumToActionName[i][Steam::ABILITY_2]={"Ability_2",{}}; |
|
|
|
|
enumToActionName[i][Steam::ABILITY_3]={"Ability_3",{}}; |
|
|
|
|
enumToActionName[i][Steam::ABILITY_4]={"Ability_4",{}}; |
|
|
|
|
enumToActionName[i][Steam::ITEM_1]={"Item_1",{}}; |
|
|
|
|
enumToActionName[i][Steam::ITEM_2]={"Item_2",{}}; |
|
|
|
|
enumToActionName[i][Steam::ITEM_3]={"Item_3",{}}; |
|
|
|
|
enumToActionName[i][Steam::NAVIGATE]={"Navigate",{}}; |
|
|
|
|
enumToActionName[i][Steam::SCROLL]={"Scroll",{}}; |
|
|
|
|
enumToActionName[i][Steam::CONFIRM]={"Confirm",{}}; |
|
|
|
|
enumToActionName[i][Steam::BACK]={"Back",{}}; |
|
|
|
|
enumToActionName[i][Steam::FUNCTION_1]={"Function_1",{}}; |
|
|
|
|
enumToActionName[i][Steam::FUNCTION_2]={"Function_2",{}}; |
|
|
|
|
enumToActionName[i][Steam::UP]={"Up",{}}; |
|
|
|
|
enumToActionName[i][Steam::DOWN]={"Down",{}}; |
|
|
|
|
enumToActionName[i][Steam::LEFT]={"Left",{}}; |
|
|
|
|
enumToActionName[i][Steam::RIGHT]={"Right",{}}; |
|
|
|
|
enumToActionName[i][Steam::LOCK_UNLOCK_ACC]={"Lock/Unlock Accessory",{}}; |
|
|
|
|
enumToActionName[i][Steam::FAST_SCROLL_UP]={"Fast_Scroll_Up",{}}; |
|
|
|
|
enumToActionName[i][Steam::FAST_SCROLL_DOWN]={"Fast_Scroll_Down",{}}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Input::UpdateSteamInput(){ |
|
|
|
|
if(SteamInput()){ |
|
|
|
|
int controllerCount=SteamInput()->GetConnectedControllers(steamControllers.data()); |
|
|
|
|
for(int i=0;i<controllerCount;i++){ |
|
|
|
|
for(auto&[input,data]:enumToActionName[i]){ |
|
|
|
|
HWButton prevState=data.second; |
|
|
|
|
InputDigitalActionHandle_t inputHnd=SteamInput()->GetDigitalActionHandle(data.first.c_str()); |
|
|
|
|
InputDigitalActionData_t buttonData=SteamInput()->GetDigitalActionData(steamControllers[i],inputHnd); |
|
|
|
|
data.second.bPressed=data.second.bReleased=false; |
|
|
|
|
|
|
|
|
|
if(!data.second.bHeld&&buttonData.bState){ |
|
|
|
|
data.second.bPressed=true; |
|
|
|
|
activeSteamControllerIndex=i; |
|
|
|
|
} |
|
|
|
|
data.second.bHeld=buttonData.bState; |
|
|
|
|
if(data.second.bHeld&&!buttonData.bState){ |
|
|
|
|
data.second.bReleased=true; |
|
|
|
|
activeSteamControllerIndex=i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Input::Pressed(){ |
|
|
|
@ -99,12 +125,14 @@ bool Input::Pressed(){ |
|
|
|
|
inputPressed=game->GetMouse(key).bPressed; |
|
|
|
|
}break; |
|
|
|
|
case CONTROLLER:{ |
|
|
|
|
for(GamePad*gamepad:GamePad::getGamepads()){ |
|
|
|
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bPressed)inputPressed=true; |
|
|
|
|
if(!SteamInput()){ |
|
|
|
|
for(GamePad*gamepad:GamePad::getGamepads()){ |
|
|
|
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bPressed)inputPressed=true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case STEAM:{ |
|
|
|
|
|
|
|
|
|
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed; |
|
|
|
|
}break; |
|
|
|
|
case ANALOG:{ |
|
|
|
|
//An analog input can never be "pressed". No-op.
|
|
|
|
@ -121,7 +149,7 @@ bool Input::Pressed(){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Input::Held(){ |
|
|
|
|
if(!game->IsFocused())return false; |
|
|
|
|
//if(!game->IsFocused())return false;
|
|
|
|
|
bool inputHeld=false; |
|
|
|
|
switch(type){ |
|
|
|
|
case KEY:{ |
|
|
|
@ -131,12 +159,14 @@ bool Input::Held(){ |
|
|
|
|
inputHeld=game->GetMouse(key).bHeld; |
|
|
|
|
}break; |
|
|
|
|
case CONTROLLER:{ |
|
|
|
|
for(GamePad*gamepad:GamePad::getGamepads()){ |
|
|
|
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bHeld)inputHeld=true; |
|
|
|
|
if(!SteamInput()){ |
|
|
|
|
for(GamePad*gamepad:GamePad::getGamepads()){ |
|
|
|
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bHeld)inputHeld=true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case STEAM:{ |
|
|
|
|
|
|
|
|
|
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bHeld; |
|
|
|
|
}break; |
|
|
|
|
case ANALOG:{ |
|
|
|
|
//An analog input can never be "held". No-op.
|
|
|
|
@ -163,12 +193,14 @@ bool Input::Released(){ |
|
|
|
|
inputReleased=game->GetMouse(key).bReleased; |
|
|
|
|
}break; |
|
|
|
|
case CONTROLLER:{ |
|
|
|
|
for(GamePad*gamepad:GamePad::getGamepads()){ |
|
|
|
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bReleased)inputReleased=true; |
|
|
|
|
if(!SteamInput()){ |
|
|
|
|
for(GamePad*gamepad:GamePad::getGamepads()){ |
|
|
|
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bReleased)inputReleased=true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case STEAM:{ |
|
|
|
|
|
|
|
|
|
return enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bReleased; |
|
|
|
|
}break; |
|
|
|
|
case ANALOG:{ |
|
|
|
|
//An analog input can never be "released". No-op.
|
|
|
|
@ -188,14 +220,18 @@ float Input::Analog(){ |
|
|
|
|
if(!game->IsFocused())return false; |
|
|
|
|
switch(type){ |
|
|
|
|
case ANALOG:{ |
|
|
|
|
for(GamePad*gamepad:GamePad::getGamepads()){ |
|
|
|
|
if(gamepad->stillConnected){ |
|
|
|
|
float axisVal=gamepad->getAxis(static_cast<GPAxes>(key)); |
|
|
|
|
if(axisVal!=0.f){ |
|
|
|
|
usingGamepad=true; |
|
|
|
|
return axisVal; |
|
|
|
|
if(!SteamInput()){ |
|
|
|
|
for(GamePad*gamepad:GamePad::getGamepads()){ |
|
|
|
|
if(gamepad->stillConnected){ |
|
|
|
|
float axisVal=gamepad->getAxis(static_cast<GPAxes>(key)); |
|
|
|
|
if(axisVal!=0.f){ |
|
|
|
|
usingGamepad=true; |
|
|
|
|
return axisVal; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case KEY: |
|
|
|
|