hotkey save
This commit is contained in:
@@ -5,11 +5,18 @@
|
||||
|
||||
namespace blitz {
|
||||
|
||||
|
||||
enum class KeyAction { Avancer = 0, Reculer, Droite, Gauche, nb_actions };
|
||||
typedef std::array<int, static_cast<std::size_t>(KeyAction::nb_actions)> Keybinds;
|
||||
|
||||
class BlitzConfig {
|
||||
private:
|
||||
std::array<char, 256> m_Pseudo;
|
||||
bool m_VSync;
|
||||
bool m_DisplayFps;
|
||||
KeyAction m_CurrentAction;
|
||||
Keybinds m_Keybinds{};
|
||||
|
||||
|
||||
public:
|
||||
BlitzConfig();
|
||||
@@ -35,6 +42,10 @@ class BlitzConfig {
|
||||
m_DisplayFps = display;
|
||||
}
|
||||
|
||||
Keybinds& GetKeys() {
|
||||
return m_Keybinds;
|
||||
}
|
||||
|
||||
private:
|
||||
void LoadConfig();
|
||||
void LoadDefaultConfig();
|
||||
|
||||
@@ -19,7 +19,6 @@ class OptionsMenu : public GuiWidget {
|
||||
bool m_IsOpen;
|
||||
utils::Timer m_Timer{100};
|
||||
KeyAction m_CurrentAction;
|
||||
std::array<int, static_cast<std::size_t>(KeyAction::nb_actions)> m_Keybinds{};
|
||||
|
||||
public:
|
||||
OptionsMenu(GuiWidget* parent, Client* client);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "client/config/BlitzConfig.h"
|
||||
|
||||
#include "blitz/misc/Log.h"
|
||||
#include "imgui.h"
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -36,6 +37,7 @@ void BlitzConfig::LoadConfig() {
|
||||
std::memcpy(m_Pseudo.data(), pseudo.data(), pseudo.size() + 1);
|
||||
jsonInput.at("vsync").get_to<bool>(m_VSync);
|
||||
jsonInput.at("fps").get_to<bool>(m_DisplayFps);
|
||||
jsonInput.at("keys").get_to<Keybinds>(m_Keybinds);
|
||||
} catch (std::exception& e) {
|
||||
utils::LOGE("Failed to load config !");
|
||||
}
|
||||
@@ -46,6 +48,7 @@ void BlitzConfig::LoadDefaultConfig() {
|
||||
m_VSync = true;
|
||||
const char defaultPseudo[] = "Pseudo";
|
||||
std::memcpy(m_Pseudo.data(), defaultPseudo, sizeof(defaultPseudo));
|
||||
m_Keybinds = {ImGuiKey_Z, ImGuiKey_S, ImGuiKey_Q, ImGuiKey_D};
|
||||
}
|
||||
|
||||
void BlitzConfig::SaveConfig() {
|
||||
@@ -59,6 +62,7 @@ void BlitzConfig::SaveConfig() {
|
||||
{"pseudo", GetPseudo().data()},
|
||||
{"vsync", IsVSyncEnabled()},
|
||||
{"fps", IsFPSDisplayEnabled()},
|
||||
{"keys", GetKeys()},
|
||||
};
|
||||
|
||||
file << jsonOutput;
|
||||
|
||||
@@ -30,14 +30,14 @@ static std::string GetImGuiKeyName(int key) {
|
||||
}
|
||||
|
||||
void OptionsMenu::HotkeyBindingButton() {
|
||||
for (int i = 0; i < m_Keybinds.size(); i++) {
|
||||
for (int i = 0; i < m_Client->GetConfig()->GetKeys().size(); i++) {
|
||||
if (ImGui::Button(utils::Format("%s##%i", GetKeyActionCodeName(KeyAction(i)).c_str(), i).c_str())) {
|
||||
m_IsOpen = true;
|
||||
m_CurrentAction = KeyAction(i);
|
||||
ImGui::OpenPopup("Changer de touche");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(GetActionName(KeyAction(i)).c_str());
|
||||
ImGui::Text("%s", GetActionName(KeyAction(i)).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ void OptionsMenu::OnKeyEvent(int key) {
|
||||
return;
|
||||
}
|
||||
if (m_IsOpen) {
|
||||
m_Keybinds[static_cast<std::size_t>(m_CurrentAction)] = key;
|
||||
m_Client->GetConfig()->GetKeys()[static_cast<std::size_t>(m_CurrentAction)] = key;
|
||||
m_IsOpen = false;
|
||||
}
|
||||
utils::LOG(std::to_string(key));
|
||||
@@ -85,7 +85,7 @@ void OptionsMenu::OnKeyEvent(int key) {
|
||||
|
||||
|
||||
std::string OptionsMenu::GetKeyActionCodeName(KeyAction act) {
|
||||
return GetImGuiKeyName(static_cast<int>(m_Keybinds[static_cast<std::size_t>(act)]));
|
||||
return GetImGuiKeyName(static_cast<int>(m_Client->GetConfig()->GetKeys()[static_cast<std::size_t>(act)]));
|
||||
}
|
||||
void OptionsMenu::Render() {
|
||||
GuiWidget::Render();
|
||||
|
||||
Reference in New Issue
Block a user