Co-Authored-By: Taiga <67109235+Taiga74164@users.noreply.github.com>
This commit is contained in:
Nanako
2022-08-06 15:48:03 +09:00
parent 8df2e99f8d
commit 30d55679b8
3 changed files with 56 additions and 58 deletions

View File

@ -43,8 +43,20 @@ namespace cheat::feature
f_HotkeyExit.value().PressedEvent += MY_METHOD_HANDLER(Settings::OnExitKeyPressed); f_HotkeyExit.value().PressedEvent += MY_METHOD_HANDLER(Settings::OnExitKeyPressed);
if (!std::filesystem::exists(themesDir)) if (!std::filesystem::exists(themesDir))
std::filesystem::create_directory(themesDir); std::filesystem::create_directory(themesDir);
}
bool inited = false;
void Settings::Init() {
if (this->f_DefaultTheme.value() != "Default" && !inited)
{
LOG_INFO("Loading theme: %s", themesDir / (f_DefaultTheme.value() + ".json").c_str());
if (!std::filesystem::exists(themesDir / (f_DefaultTheme.value() + ".json")))
f_DefaultTheme = "Default";
else Colors_Import(f_DefaultTheme.value());
inited = true;
}
} }
bool themeLoaded = false;
const FeatureGUIInfo& Settings::GetGUIInfo() const const FeatureGUIInfo& Settings::GetGUIInfo() const
{ {
@ -54,19 +66,19 @@ namespace cheat::feature
void Settings::Colors_Export(std::string name) void Settings::Colors_Export(std::string name)
{ {
ImGuiStyle &style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
auto colors = style.Colors; auto colors = style.Colors;
nlohmann::json json; nlohmann::json json;
for (int i = 0; i < ImGuiCol_COUNT; i++) for (int i = 0; i < ImGuiCol_COUNT; i++)
json[ImGui::GetStyleColorName((ImGuiCol)i)] = {colors[i].x, colors[i].y, colors[i].z, colors[i].w}; json[ImGui::GetStyleColorName((ImGuiCol)i)] = { colors[i].x, colors[i].y, colors[i].z, colors[i].w };
std::ofstream file(themesDir / (name + ".json")); std::ofstream file(themesDir / (name + ".json"));
file << std::setw(4) << json << std::endl; file << std::setw(4) << json << std::endl;
} }
void Settings::Colors_Import(std::string name) void Settings::Colors_Import(std::string name)
{ {
ImGuiStyle &style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
auto colors = style.Colors; auto colors = style.Colors;
nlohmann::json json; nlohmann::json json;
std::ifstream file(themesDir / (name + ".json")); std::ifstream file(themesDir / (name + ".json"));
@ -142,7 +154,7 @@ namespace cheat::feature
ImGui::BeginGroupPanel("Show Notifications"); ImGui::BeginGroupPanel("Show Notifications");
{ {
ConfigWidget(f_NotificationsShow, "Notifications on the bottom-right corner of the window will be displayed."); ConfigWidget(f_NotificationsShow, "Notifications on the bottom-right corner of the window will be displayed.");
ConfigWidget(f_NotificationsDelay, 1,1,10000, "Delay in milliseconds between notifications."); ConfigWidget(f_NotificationsDelay, 1, 1, 10000, "Delay in milliseconds between notifications.");
} }
ImGui::EndGroupPanel(); ImGui::EndGroupPanel();
@ -166,24 +178,6 @@ namespace cheat::feature
ImGui::BeginGroupPanel("Colors"); ImGui::BeginGroupPanel("Colors");
{ {
static std::string nameBuffer_; static std::string nameBuffer_;
if (this->f_DefaultTheme.value() != "Default" && !themeLoaded)
{
LOG_INFO("Loading theme: %s", themesDir / (f_DefaultTheme.value() + ".json").c_str());
if (!std::filesystem::exists(themesDir / (f_DefaultTheme.value() + ".json")))
{
LOG_ERROR("Theme file not found: %s", themesDir / (f_DefaultTheme.value() + ".json").c_str());
f_DefaultTheme = "Default";
themeLoaded = true;
}
else
{
Colors_Import(f_DefaultTheme.value());
themeLoaded = true;
LOG_INFO("Loaded theme \"%s\"", f_DefaultTheme.value().c_str());
}
}
ImGui::InputText("Name", &nameBuffer_); ImGui::InputText("Name", &nameBuffer_);
if (std::filesystem::exists(themesDir / (nameBuffer_ + ".json"))) if (std::filesystem::exists(themesDir / (nameBuffer_ + ".json")))
{ {
@ -193,7 +187,6 @@ namespace cheat::feature
if (ImGui::Button("Load")) if (ImGui::Button("Load"))
{ {
Colors_Import(nameBuffer_); Colors_Import(nameBuffer_);
themeLoaded = true;
} }
} }
else else

View File

@ -38,6 +38,7 @@ namespace cheat::feature
const FeatureGUIInfo& GetGUIInfo() const override; const FeatureGUIInfo& GetGUIInfo() const override;
void DrawMain() override; void DrawMain() override;
void Init();
void Colors_Export(std::string name); void Colors_Export(std::string name);
void Colors_Import(std::string name); void Colors_Import(std::string name);

View File

@ -12,6 +12,7 @@
#include <cheat-base/render/backend/dx12-hook.h> #include <cheat-base/render/backend/dx12-hook.h>
#include <cheat-base/ResourceLoader.h> #include <cheat-base/ResourceLoader.h>
#include <cheat-base/cheat/misc/Settings.h>
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
@ -33,7 +34,7 @@ namespace renderer
static constexpr int _fontsCount = _fontSizeMax / _fontSizeStep; static constexpr int _fontsCount = _fontSizeMax / _fontSizeStep;
static std::array<ImFont*, _fontsCount> _fonts; static std::array<ImFont*, _fontsCount> _fonts;
static Data _customFontData {}; static Data _customFontData{};
static WNDPROC OriginalWndProcHandler; static WNDPROC OriginalWndProcHandler;
static ID3D11RenderTargetView* mainRenderTargetView; static ID3D11RenderTargetView* mainRenderTargetView;
@ -253,6 +254,9 @@ namespace renderer
pContext->OMSetRenderTargets(1, &mainRenderTargetView, nullptr); pContext->OMSetRenderTargets(1, &mainRenderTargetView, nullptr);
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
auto& themes = cheat::feature::Settings::GetInstance();
themes.Init();
} }
static LRESULT CALLBACK hWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK hWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)