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