Save/Load Game Keybind settings. Release build 6872.

pull/35/head
sigonasr2 10 months ago
parent 4015f485ea
commit 331a8c7941
  1. 1
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 5
      Adventures in Lestoria/InputDisplayComponent.h
  3. 4
      Adventures in Lestoria/Key.cpp
  4. 2
      Adventures in Lestoria/Key.h
  5. 66
      Adventures in Lestoria/SaveFile.cpp
  6. 2
      Adventures in Lestoria/Version.h
  7. BIN
      x64/Release/Adventures in Lestoria.exe

@ -2458,6 +2458,7 @@ void AiL::InitializeDefaultKeybinds(){
Player::KEY_ITEM2.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::L3)});
Player::KEY_ITEM3.AddKeybind({KEY,K3});
Player::KEY_ITEM3.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::R3)});
KEY_ATTACK.AddKeybind({KEY,SHIFT});
KEY_ATTACK.AddKeybind({MOUSE,Mouse::LEFT});
KEY_ATTACK.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::L2)});
KEY_LEFT.AddKeybind({KEY,A});

@ -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::rect<float>pos,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);

@ -592,3 +592,7 @@ void InputListener::Update(){
}
#pragma endregion
}
const int Input::GetKeyCode()const{
return key;
}

@ -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::set<Input>keys;
std::vector<Input>keyOrder; //A list of keys inserted in order, for primary key mapping.
static safemap<std::string,InputGroup*>menuNamesToInputGroups;

@ -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<menuRowCount;row++){
for(int col=0;col<menuColCount;col++){
int inputID=row*menuColCount+col;
if(DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==1&&col==1&&row==menuRowCount-1)continue; //We only continue on a blank space when we have an odd number of elements.
saveFile["Menu Keyboard Input_"+"Inputs.Menu Input Names"_s[inputID]].SetInt(Component<InputDisplayComponent>(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<InputDisplayComponent>(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<ingameControlsRowCount;row++){
for(int col=0;col<ingameControlsColCount;col++){
int inputID=row*menuColCount+col;
if(DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()%2==1&&col==1&&row==ingameControlsRowCount-1)continue; //We only continue on a blank space when we have an odd number of elements.
saveFile["Gameplay Keyboard Input_"+"Inputs.Gameplay Input Names"_s[inputID]].SetInt(Component<InputDisplayComponent>(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<InputDisplayComponent>(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<menuRowCount;row++){
for(int col=0;col<menuColCount;col++){
int inputID=row*menuColCount+col;
if(DATA.GetProperty("Inputs.Menu Input Names").GetValueCount()%2==1&&col==1&&row==menuRowCount-1)continue; //We only continue on a blank space when we have an odd number of elements.
std::string keyName="Menu Keyboard Input_"+"Inputs.Menu Input Names"_s[inputID];
if(loadFile.HasProperty(keyName)){
InputGroup&group=Component<InputDisplayComponent>(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<InputDisplayComponent>(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<ingameControlsRowCount;row++){
for(int col=0;col<ingameControlsColCount;col++){
int inputID=row*ingameControlsColCount+col;
if(DATA.GetProperty("Inputs.Gameplay Input Names").GetValueCount()%2==1&&col==1&&row==ingameControlsRowCount-1)continue; //We only continue on a blank space when we have an odd number of elements.
std::string keyName="Gameplay Keyboard Input_"+"Inputs.Gameplay Input Names"_s[inputID];
if(loadFile.HasProperty(keyName)){
InputGroup&group=Component<InputDisplayComponent>(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<InputDisplayComponent>(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<<std::format("WARNING! File {} does not exist for loading!","save_file_path"_S+std::format("save.{:04}",saveFileID))<<std::endl;

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 3
#define VERSION_PATCH 0
#define VERSION_BUILD 6866
#define VERSION_BUILD 6872
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save