diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 4e78f3c4..89bb9153 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -333,7 +333,7 @@ bool AiL::OnUserCreate(){ } if(SteamInput()!=nullptr){ SteamInput()->Init(false); - + SteamInput()->RunFrame(); Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls"); Input::menuControlsHandle=SteamInput()->GetActionSetHandle("MenuControls"); } @@ -356,7 +356,11 @@ bool AiL::OnUserCreate(){ bool AiL::OnUserUpdate(float fElapsedTime){ levelTime+=fElapsedTime; SteamAPI_RunCallbacks(); - if(SteamInput())SteamInput()->ActivateActionSet(STEAM_INPUT_HANDLE_ALL_CONTROLLERS,Input::menuControlsHandle); + if(SteamInput()){ + SteamInput()->ActivateActionSet(STEAM_INPUT_HANDLE_ALL_CONTROLLERS,Input::menuControlsHandle); + SteamInput()->RunFrame(); + Input::UpdateSteamInput(); + } if(GetMousePos()!=lastMousePos){ lastMouseMovement=0.f; @@ -645,6 +649,9 @@ void AiL::HandleUserInput(float fElapsedTime){ } } } + + + if(SteamInput())SteamInput()->ActivateActionSet(STEAM_INPUT_HANDLE_ALL_CONTROLLERS,Input::menuControlsHandle); } void AiL::UpdateCamera(float fElapsedTime){ @@ -3298,6 +3305,8 @@ void AiL::RenderVersionInfo(){ DrawShadowStringDecal({4.f,4.f},"Save Complete.",{255,255,255,alpha},{0,0,0,alpha}); } + DrawShadowStringDecal({0.f,0.f},"Holding down A: "+std::to_string(KEY_CONFIRM.Held())); + std::string versionStr("v" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH) + "." + std::to_string(VERSION_BUILD)); DrawShadowStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4f,versionStr,WHITE,BLACK,{0.4f,0.4f},std::numeric_limits::max(),0.4f); } diff --git a/Adventures in Lestoria/Key.cpp b/Adventures in Lestoria/Key.cpp index 8540b226..ceeb85f1 100644 --- a/Adventures in Lestoria/Key.cpp +++ b/Adventures in Lestoria/Key.cpp @@ -41,51 +41,77 @@ All rights reserved. #include "olcPGEX_Gamepad.h" #include "Menu.h" #include "GameSettings.h" -#include 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}; safemapInputGroup::menuNamesToInputGroups; std::vectorInputGroup::menuInputGroups; std::vectorInputGroup::gameplayInputGroups; +std::arrayInput::steamControllers; +uint8_t Input::activeSteamControllerIndex; -safemapInput::enumToActionName; +std::array>,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;iGetDigitalActionHandle(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(key)).bPressed)inputPressed=true; + if(!SteamInput()){ + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected&&gamepad->getButton(static_cast(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(key)).bHeld)inputHeld=true; + if(!SteamInput()){ + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected&&gamepad->getButton(static_cast(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(key)).bReleased)inputReleased=true; + if(!SteamInput()){ + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected&&gamepad->getButton(static_cast(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(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(key)); + if(axisVal!=0.f){ + usingGamepad=true; + return axisVal; + } } } + }else{ + } }break; case KEY: diff --git a/Adventures in Lestoria/Key.h b/Adventures in Lestoria/Key.h index 804467ee..76644255 100644 --- a/Adventures in Lestoria/Key.h +++ b/Adventures in Lestoria/Key.h @@ -46,6 +46,7 @@ All rights reserved. #include "IconType.h" #include "olcPGEX_ViewPort.h" #include "UndefKeys.h" +#include class AiL; @@ -61,7 +62,7 @@ enum InputType{ namespace Steam{ enum SteamInput{ //Gameplay Inputs - MOVE, + MOVE, //This is the left stick analog input. Whenever we use this, we assume left stick is being used. MANUAL_AIM, BASIC_ATTACK, DEFENSIVE, @@ -75,7 +76,7 @@ namespace Steam{ ITEM_3, //Menu Inputs NAVIGATE, - SCROLL, + SCROLL, //This is the right stick analog input. Whenever we use this, we assume right stick is being used. CONFIRM, BACK, FUNCTION_1, @@ -101,8 +102,11 @@ class Input{ static uint64_t menuControlsHandle; static bool usingGamepad; static void SetUsingGamepad(const bool usingGamepad); - static safemapenumToActionName; + static std::array>,16>enumToActionName; static void Initialize(); + static void UpdateSteamInput(); + static std::arraysteamControllers; + static uint8_t activeSteamControllerIndex; public: Input(InputType type,int key); bool Pressed(); diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index f2fd4af3..fa5093d9 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 5 #define VERSION_PATCH 1 -#define VERSION_BUILD 8238 +#define VERSION_BUILD 8264 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Adventures in Lestoria/controller_config/game_actions_2895980.vdf b/Adventures in Lestoria/controller_config/game_actions_2895980.vdf index f9829518..454b2315 100644 --- a/Adventures in Lestoria/controller_config/game_actions_2895980.vdf +++ b/Adventures in Lestoria/controller_config/game_actions_2895980.vdf @@ -116,5 +116,12 @@ "path" "controller_generic.vdf" } } + "controller_switch_pro" + { + "0" + { + "path" "controller_generic.vdf" + } + } } } \ No newline at end of file diff --git a/x64/Release/Adventures in Lestoria.exe b/x64/Release/Adventures in Lestoria.exe index 0e01599c..49037246 100644 Binary files a/x64/Release/Adventures in Lestoria.exe and b/x64/Release/Adventures in Lestoria.exe differ