Controller Configuration UI and JSON Config (#760)

* Initial controller hud ui

* Reverted fbdemo changes

* Moved config to json and implemented controller config

* fix build on linux, gitignore new config file

* fix build

* Fix compilation and file directory paths

* Call save on cvar save

* Fixed cvar loading and added deck slots to the config

* Changed control deck port 0 to use a physical device by default

* Added gyro and rumble & fixed loading errors

* Save config on toggle menubar

* fix linux build

* Fixed drift calculation

* Controller config now saves when pressing F1

* Removed ExitGame hook from ImGuiImpl

* Moved mappings to a map

* Added GetKeyName

* untranslate scancodes

* Fixed hud layout on keyboard device

* Fixed keyboard read on hud

* Fixed crash when reloading controllers

* Removed ConfigFile and changed file extension

* Changed Dummy to Disconnected and fixed filters

* Removed function leftover

* Changed ControllerHud to InputEditor

Co-authored-by: briaguya <briaguya@alice>
Co-authored-by: David Chavez <david@dcvz.io>
This commit is contained in:
KiritoDev
2022-07-13 22:12:11 -05:00
committed by GitHub
parent cb6876792e
commit 219804cbe4
49 changed files with 1841 additions and 896 deletions
+49 -14
View File
@@ -16,6 +16,7 @@
#include <Utils/StringHelper.h>
#include <Utils/File.h>
#include "Window.h"
#include "Lib/ImGui/imgui_internal.h"
#undef PATH_HACK
#undef Path
@@ -315,7 +316,7 @@ static bool SaveStateHandler(const std::vector<std::string>& args) {
unsigned int slot = OTRGlobals::Instance->gSaveStateMgr->GetCurrentSlot();
const SaveStateReturn rtn = OTRGlobals::Instance->gSaveStateMgr->AddRequest({ slot, RequestType::SAVE });
switch (rtn) {
switch (rtn) {
case SaveStateReturn::SUCCESS:
INFO("[SOH] Saved state to slot %u", slot);
return CMD_SUCCESS;
@@ -329,7 +330,7 @@ static bool SaveStateHandler(const std::vector<std::string>& args) {
static bool LoadStateHandler(const std::vector<std::string>& args) {
unsigned int slot = OTRGlobals::Instance->gSaveStateMgr->GetCurrentSlot();
const SaveStateReturn rtn = OTRGlobals::Instance->gSaveStateMgr->AddRequest({ slot, RequestType::LOAD });
switch (rtn) {
case SaveStateReturn::SUCCESS:
INFO("[SOH] Loaded state from slot %u", slot);
@@ -342,7 +343,7 @@ static bool LoadStateHandler(const std::vector<std::string>& args) {
return CMD_FAILED;
case SaveStateReturn::FAIL_WRONG_GAMESTATE:
ERROR("[SOH] Can not load a state outside of \"GamePlay\"");
return CMD_FAILED;
return CMD_FAILED;
}
}
@@ -360,7 +361,7 @@ static bool StateSlotSelectHandler(const std::vector<std::string>& args) {
ERROR("[SOH] SaveState slot value must be a number.");
return CMD_FAILED;
}
if (slot < 0) {
ERROR("[SOH] Invalid slot passed. Slot must be between 0 and 2");
return CMD_FAILED;
@@ -498,8 +499,7 @@ template <typename Numeric> bool is_number(const std::string& s) {
return ((std::istringstream(s) >> n >> std::ws).eof());
}
void DebugConsole_LoadCVars()
{
void DebugConsole_LoadLegacyCVars() {
auto cvarsConfig = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("cvars.cfg");
if (File::Exists(cvarsConfig)) {
const auto lines = File::ReadAllLines(cvarsConfig);
@@ -520,23 +520,58 @@ void DebugConsole_LoadCVars()
CVar_SetS32(cfg[0].c_str(), std::stoi(cfg[1]));
}
}
fs::remove("cvars.cfg");
}
}
void DebugConsole_LoadCVars() {
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
pConf->reload();
for (const auto& item : pConf->rjson["CVars"].items()) {
auto value = item.value();
switch (value.type()) {
case nlohmann::detail::value_t::array:
break;
case nlohmann::detail::value_t::string:
CVar_SetString(item.key().c_str(), value.get<std::string>().c_str());
break;
case nlohmann::detail::value_t::boolean:
CVar_SetS32(item.key().c_str(), value.get<bool>());
break;
case nlohmann::detail::value_t::number_unsigned:
case nlohmann::detail::value_t::number_integer:
CVar_SetS32(item.key().c_str(), value.get<int>());
break;
case nlohmann::detail::value_t::number_float:
CVar_SetFloat(item.key().c_str(), value.get<float>());
break;
default: ;
}
if (item.key() == "gOpenMenuBar") {
int bp = 0;
}
}
DebugConsole_LoadLegacyCVars();
}
void DebugConsole_SaveCVars()
{
std::string output;
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
for (const auto &cvar : cvars) {
if (cvar.second->type == CVAR_TYPE_STRING)
output += StringHelper::Sprintf("%s = \"%s\"\n", cvar.first.c_str(), cvar.second->value.valueStr);
const std::string key = StringHelper::Sprintf("CVars.%s", cvar.first.c_str());
if (cvar.second->type == CVAR_TYPE_STRING && cvar.second->value.valueStr != nullptr)
pConf->setString(key, std::string(cvar.second->value.valueStr));
else if (cvar.second->type == CVAR_TYPE_S32)
output += StringHelper::Sprintf("%s = %i\n", cvar.first.c_str(), cvar.second->value.valueS32);
pConf->setInt(key, cvar.second->value.valueS32);
else if (cvar.second->type == CVAR_TYPE_FLOAT)
output += StringHelper::Sprintf("%s = %f\n", cvar.first.c_str(), cvar.second->value.valueFloat);
pConf->setFloat(key, cvar.second->value.valueFloat);
}
auto cvarsConfig = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("cvars.cfg");
File::WriteAllText(cvarsConfig, output);
pConf->save();
}