GlosSITarget: Overlay: Add button to store shortcut-settings from target

pull/179/head
Peter Repukat 2 years ago
parent 3f992c811c
commit 34fa783d09

@ -21,6 +21,7 @@ limitations under the License.
#include <codecvt>
#include "Roboto.h"
#include "Settings.h"
Overlay::Overlay(
sf::RenderWindow& window,
@ -166,6 +167,7 @@ void Overlay::update()
}
closeOverlayButton();
saveSettingsButton();
}
ImGui::SFML::Render(window_);
@ -306,3 +308,16 @@ bool Overlay::closeButton() const
ImGui::PopStyleVar();
return false;
}
void Overlay::saveSettingsButton() const
{
if (Settings::settings_path_ != "") {
ImGui::SetNextWindowPos({(window_.getSize().x - ImGui::GetWindowWidth()) / 2, (window_.getSize().y - ImGui::GetWindowHeight()) / 2}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints({192, 96}, {512, 512});
ImGui::Begin("Shortcut settings");
if (ImGui::Button("Save settings", {256, 32})) {
Settings::StoreSettings();
}
ImGui::End();
}
}

@ -50,6 +50,7 @@ class Overlay {
void showLogs();
bool closeOverlayButton() const;
[[nodiscard]] bool closeButton() const;
void saveSettingsButton() const;
bool force_enable_ = false;
bool log_expanded_ = true;

@ -52,6 +52,8 @@ inline struct Controller {
bool emulateDS4 = false;
} controller;
inline std::filesystem::path settings_path_ = "";
inline bool checkIsUwp(const std::wstring& launch_path)
{
if (launch_path.find(L"://") != std::wstring::npos) {
@ -87,6 +89,7 @@ inline void Parse(std::wstring arg1)
spdlog::error(L"Couldn't open settings file {}", path.wstring());
return;
}
settings_path_ = path;
const auto json = nlohmann::json::parse(json_file);
if (json["version"] != 1) { // TODO: versioning stuff
spdlog::warn("Config version doesn't match application version.");
@ -102,10 +105,10 @@ inline void Parse(std::wstring arg1)
value = object[key];
}
catch (const nlohmann::json::exception& e) {
spdlog::error("Err parsing \"{}\"; {}", key, e.what());
spdlog::warn("Err parsing \"{}\"; {}", key, e.what());
}
catch (const std::exception& e) {
spdlog::error("Err parsing \"{}\"; {}", key, e.what());
spdlog::warn("Err parsing \"{}\"; {}", key, e.what());
}
};
@ -154,4 +157,33 @@ inline void Parse(std::wstring arg1)
}
}
inline void StoreSettings()
{
nlohmann::json json;
json["version"] = 1;
json["launch"]["launch"] = launch.launch;
json["launch"]["launchPath"] = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().to_bytes(launch.launchPath);
json["launch"]["launchAppArgs"] = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().to_bytes(launch.launchAppArgs);
json["launch"]["closeOnExit"] = launch.closeOnExit;
json["launch"]["waitForChildProcs"] = launch.waitForChildProcs;
json["devices"]["hideDevices"] = devices.hideDevices;
json["devices"]["realDeviceIds"] = devices.realDeviceIds;
json["window"]["windowMode"] = window.windowMode;
json["window"]["maxFps"] = window.maxFps;
json["window"]["scale"] = window.scale;
json["window"]["disableOverlay"] = window.disableOverlay;
json["controller"]["maxControllers"] = controller.maxControllers;
json["controller"]["allowDesktopConfig"] = controller.allowDesktopConfig;
json["controller"]["emulateDS4"] = controller.emulateDS4;
std::ofstream json_file;
json_file.open(settings_path_);
if (!json_file.is_open()) {
spdlog::error(L"Couldn't open settings file {}", settings_path_.wstring());
return;
}
json_file << json.dump(4);
json_file.close();
}
} // namespace Settings

Loading…
Cancel
Save