diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index a25446c5..2311201a 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -2458,6 +2458,7 @@ void AiL::InitializeDefaultKeybinds(){ Player::KEY_ITEM2.AddKeybind({CONTROLLER,static_cast(GPButtons::L3)}); Player::KEY_ITEM3.AddKeybind({KEY,K3}); Player::KEY_ITEM3.AddKeybind({CONTROLLER,static_cast(GPButtons::R3)}); + KEY_ATTACK.AddKeybind({KEY,SHIFT}); KEY_ATTACK.AddKeybind({MOUSE,Mouse::LEFT}); KEY_ATTACK.AddKeybind({CONTROLLER,static_cast(GPButtons::L2)}); KEY_LEFT.AddKeybind({KEY,A}); diff --git a/Adventures in Lestoria/InputDisplayComponent.h b/Adventures in Lestoria/InputDisplayComponent.h index 123c466e..f5d6139c 100644 --- a/Adventures in Lestoria/InputDisplayComponent.h +++ b/Adventures in Lestoria/InputDisplayComponent.h @@ -40,7 +40,7 @@ All rights reserved. #include "MenuComponent.h" class InputDisplayComponent:public MenuComponent{ - const InputGroup&input; + InputGroup&input; InputType type; public: inline InputDisplayComponent(geom2d::rectpos,InputGroup&input,InputType type,MenuFunc onClick) @@ -51,6 +51,9 @@ public: inline const InputType GetType()const{ return type; } + inline InputGroup&GetInput()const{ + return input; + } protected: inline void DrawDecal(ViewPort&window,bool focused)override{ MenuComponent::DrawDecal(window,focused); diff --git a/Adventures in Lestoria/Key.cpp b/Adventures in Lestoria/Key.cpp index 4f00c0a6..43c76d27 100644 --- a/Adventures in Lestoria/Key.cpp +++ b/Adventures in Lestoria/Key.cpp @@ -591,4 +591,8 @@ void InputListener::Update(){ } } #pragma endregion +} + +const int Input::GetKeyCode()const{ + return key; } \ No newline at end of file diff --git a/Adventures in Lestoria/Key.h b/Adventures in Lestoria/Key.h index 25eb96ff..fcdfea26 100644 --- a/Adventures in Lestoria/Key.h +++ b/Adventures in Lestoria/Key.h @@ -79,6 +79,7 @@ public: const std::string str()const; const bool HasIcon()const; const Renderable&GetIcon()const; + const int GetKeyCode()const; friend const bool operator==(const Input&input1,const Input&input2); }; @@ -87,6 +88,7 @@ class InputGroup{ friend class Menu; friend class State_OverworldMap; friend class InputListener; + friend class SaveFile; std::setkeys; std::vectorkeyOrder; //A list of keys inserted in order, for primary key mapping. static safemapmenuNamesToInputGroups; diff --git a/Adventures in Lestoria/SaveFile.cpp b/Adventures in Lestoria/SaveFile.cpp index e7c40f20..35168722 100644 --- a/Adventures in Lestoria/SaveFile.cpp +++ b/Adventures in Lestoria/SaveFile.cpp @@ -46,6 +46,7 @@ All rights reserved. #include "ScrollableWindowComponent.h" #include "LoadFileButton.h" #include "Checkbox.h" +#include "InputDisplayComponent.h" INCLUDE_game @@ -121,6 +122,31 @@ const void SaveFile::SaveGame(){ saveFile["Save Name"].SetString(std::string(GetSaveFileName())); saveFile["Game Time"].SetReal(game->GetRuntime()); saveFile["TravelingMerchant"].SetString(std::string(Merchant::GetCurrentTravelingMerchant().GetKeyName())); + + #pragma region Save Keyboard/Controller mappings + //NOTE: We are shadowing code from InputKeyboardWindow! If at some point the retrival method for getting input displays changes, we likely will be changing the code here as well! + const int menuRowCount=DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==0?DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2:DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2+1; + const int menuColCount=2; + for(int row=0;row(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput().GetPrimaryKey(KEY).value().GetKeyCode()); + saveFile["Menu Controller Input_"+"Inputs.Menu Input Names"_s[inputID]].SetInt(Component(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput().GetPrimaryKey(CONTROLLER).value().GetKeyCode()); + } + } + const int ingameControlsRowCount=DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()%2==0?DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()/2:DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()/2+1; + const int ingameControlsColCount=2; + for(int row=0;row(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Gameplay Input Displayer",row,col))->GetInput().GetPrimaryKey(KEY).value().GetKeyCode()); + saveFile["Gameplay Controller Input_"+"Inputs.Gameplay Input Names"_s[inputID]].SetInt(Component(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Gameplay Input Displayer",row,col))->GetInput().GetPrimaryKey(CONTROLLER).value().GetKeyCode()); + } + } + #pragma endregion + utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); utils::datafile metadata; if(onlineMode){ @@ -250,6 +276,46 @@ void SaveFile::LoadFile(){ game->GetPlayer()->RecalculateEquipStats(); if(loadFile.HasProperty("TravelingMerchant"))Merchant::SetTravelingMerchant(loadFile["TravelingMerchant"].GetString()); + #pragma region Load Keyboard/Controller mappings + //NOTE: We are shadowing code from InputKeyboardWindow! If at some point the retrival method for getting input displays changes, we likely will be changing the code here as well! + const int menuRowCount=DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==0?DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2:DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()/2+1; + const int menuColCount=2; + for(int row=0;row(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput(); + group.SetNewPrimaryKeybind({KEY,loadFile[keyName].GetInt()}); + } + keyName="Menu Controller Input_"+"Inputs.Menu Input Names"_s[inputID]; + if(loadFile.HasProperty(keyName)){ + InputGroup&group=Component(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Input Displayer",row,col))->GetInput(); + group.SetNewPrimaryKeybind({CONTROLLER,loadFile[keyName].GetInt()}); + } + } + } + const int ingameControlsRowCount=DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()%2==0?DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()/2:DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()/2+1; + const int ingameControlsColCount=2; + for(int row=0;row(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Gameplay Input Displayer",row,col))->GetInput(); + group.SetNewPrimaryKeybind({KEY,loadFile[keyName].GetInt()}); + } + keyName="Gameplay Controller Input_"+"Inputs.Gameplay Input Names"_s[inputID]; + if(loadFile.HasProperty(keyName)){ + InputGroup&group=Component(INPUT_KEY_DISPLAY,std::format("Input_{}_{} Gameplay Input Displayer",row,col))->GetInput(); + group.SetNewPrimaryKeybind({CONTROLLER,loadFile[keyName].GetInt()}); + } + } + } + #pragma endregion + GameState::ChangeState(States::OVERWORLD_MAP,0.5f); }else{ std::cout<