Skip to content

Commit

Permalink
add themes presets
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Dec 7, 2023
1 parent 538cd33 commit 6b51360
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/GUI/Imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Xash::GUI
ImGui::CreateContext();
ImGui::StyleColorsDark();
GetProcessesNames();
ApplyThemePreset();
}

void Imgui::InitWin32AndDX11(
Expand Down Expand Up @@ -91,4 +92,27 @@ namespace Xash::GUI
mProcessesNames.end()
);
}

void Imgui::ApplyThemePreset()
{
auto &imguiStyle = ImGui::GetStyle();
const auto &xashStyle = Settings::StyleSettings::GetInstance();

imguiStyle.Colors[ImGuiCol_WindowBg] = {
xashStyle.GetBackgroundColor().x, xashStyle.GetBackgroundColor().y,
xashStyle.GetBackgroundColor().z, xashStyle.GetBackgroundColor().w
};
imguiStyle.Colors[ImGuiCol_Text] = {
xashStyle.GetTextColor().x, xashStyle.GetTextColor().y,
xashStyle.GetTextColor().z, xashStyle.GetTextColor().w
};
imguiStyle.Colors[ImGuiCol_Border] = {
xashStyle.GetBorderColor().x, xashStyle.GetBorderColor().y,
xashStyle.GetBorderColor().z, xashStyle.GetBorderColor().w
};
imguiStyle.Colors[ImGuiCol_Button] = {
xashStyle.GetButtonColor().x, xashStyle.GetButtonColor().y,
xashStyle.GetButtonColor().z, xashStyle.GetButtonColor().w
};
}
} // namespace Xash::GUI
3 changes: 3 additions & 0 deletions src/GUI/Imgui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ namespace Xash
// SETTINGS
void DrawSettingsPanel();

// Themes
void ApplyThemePreset();

Injector::ModInfos mModInfos;
std::size_t mSelectedProcessIndex = 0;
std::vector<std::string> mProcessesNames;
Expand Down
40 changes: 40 additions & 0 deletions src/GUI/SettingsPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <string>
#include <functional>
#include "imgui.h"
#include "Imgui.hpp"
#include "XashSettings.hpp"
#include "StyleSettings.hpp"
#include "ThemePresets.hpp"

namespace Xash
{
Expand Down Expand Up @@ -41,12 +43,50 @@ namespace Xash
);
}

// All theme presets with associated functions
std::unordered_map<std::string, std::function<void()>> colorPresets = {
{"Default", Themes::SetDefaultColors},
{"Arcade", Themes::SetArcadeColors},
{"BlackAndWhite", Themes::SetBlackAndWhiteColors},
{"Purple", Themes::SetPurpleColors},
{"Ocean", Themes::SetOceanColors}
};

static void SetColors(const std::string &presetName)
{
auto &style = Settings::StyleSettings::GetInstance();

auto preset = colorPresets.find(presetName);
if (preset != colorPresets.end())
{
preset->second();
}
}

static void ThemePresets(const std::function<void()>& ApplyThemePreset)
{
for (const auto &preset : colorPresets)
{
if (ImGui::Button(preset.first.c_str()))
{
SetColors(preset.first);
ApplyThemePreset();
}
ImGui::SameLine();
}
}

void Imgui::DrawSettingsPanel()
{
if (ImGui::CollapsingHeader("Custom Theme"))
{
customTheme();
}
if (ImGui::CollapsingHeader("Theme Presets"))
{
auto applyThemefunc = [this]() {ApplyThemePreset();};
ThemePresets(applyThemefunc);
}
}
} // namespace GUI
} // namespace Xash
6 changes: 3 additions & 3 deletions src/settings/StyleSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ namespace Xash
StyleSettings() = default;
~StyleSettings() = default;

Vector4 mBackgroundColor = {0.0f, 0.0f, 0.0f, 1.0f};
Vector4 mBackgroundColor = {0.088f, 0.084f, 0.098f, 1.0f};
Vector4 mTextColor = {1.0f, 1.0f, 1.0f, 1.0f};
Vector4 mBorderColor = {0.5f, 0.5f, 0.5f, 1.0f};
Vector4 mButtonColor = {0.2f, 0.8f, 0.2f, 1.0f};
Vector4 mBorderColor = {0.538f, 0.538f, 0.538f, 1.0f};
Vector4 mButtonColor = {0.321f, 0.112f, 0.734f, 1.0f};
};
} // namespace Settings
} // namespace Xash
58 changes: 58 additions & 0 deletions src/settings/ThemePresets.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once

#include "StyleSettings.hpp"

// Maybe soon, themes will be in a json file

namespace Xash::Themes
{
void SetArcadeColors()
{
auto &style = Settings::StyleSettings::GetInstance();

style.SetBackgroundColor({0.09f, 0.05f, 0.201f, 1.0f});
style.SetTextColor({1.0f, 1.0f, 1.0f, 1.0f});
style.SetBorderColor({1.0f, 0.0f, 1.0f, 1.0f});
style.SetButtonColor({0.05f, 0.860f, 0.780f, 1.0f});
}

void SetBlackAndWhiteColors()
{
auto &style = Settings::StyleSettings::GetInstance();

style.SetBackgroundColor({0.076f, 0.076f, 0.076f, 1.0f});
style.SetTextColor({0.8f, 0.8f, 0.8f, 1.0f});
style.SetBorderColor({0.5f, 0.5f, 0.5f, 1.0f});
style.SetButtonColor({0.3f, 0.3f, 0.3f, 1.0f});
}

void SetPurpleColors()
{
auto &style = Settings::StyleSettings::GetInstance();

style.SetBackgroundColor({0.185f, 0.138f, 0.310f, 1.0f});
style.SetTextColor({1.0f, 1.0f, 1.0f, 1.0f});
style.SetBorderColor({0.279f, 0.189f, 0.359f, 1.0f});
style.SetButtonColor({0.322f, 0.148f, 0.620f, 1.0f});
}

void SetOceanColors()
{
auto &style = Settings::StyleSettings::GetInstance();

style.SetBackgroundColor({0.0f, 0.2f, 0.4f, 1.0f});
style.SetTextColor({1.0f, 1.0f, 1.0f, 1.0f});
style.SetBorderColor({0.3f, 0.5f, 0.7f, 1.0f});
style.SetButtonColor({0.2f, 0.5f, 0.8f, 1.0f});
}

void SetDefaultColors()
{
auto &style = Settings::StyleSettings::GetInstance();

style.SetBackgroundColor({0.088f, 0.084f, 0.098f, 1.0f});
style.SetTextColor({1.0f, 1.0f, 1.0f, 1.0f});
style.SetBorderColor({0.538f, 0.538f, 0.538f, 1.0f});
style.SetButtonColor({0.321f, 0.112f, 0.734f, 1.0f});
}
} // namespace Themes

0 comments on commit 6b51360

Please sign in to comment.