Skip to content

Commit

Permalink
Refactor options window
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Apr 28, 2024
1 parent 1d542b3 commit 2d7a180
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 33 deletions.
74 changes: 45 additions & 29 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,65 @@ void Options::DrawOptions() noexcept

if (ImGui::CollapsingHeader("General"))
{
DrawOption("DisableIntro", "Disable legal screen and intros");
DrawOption("NoCinematicBars", "Disable cinematic bars");
DrawOption("NoMotionBlur", "Disable motion blur");
DrawComboOption("IntroSkip", "Legal screen and intros", { "Don't skip", "Skip legal", "Skip legal and intros" });
DrawCheckOption("NoCinematicBars", "Disable cinematic bars");
DrawCheckOption("NoMotionBlur", "Disable motion blur");
}

if (ImGui::CollapsingHeader("Camera"))
{
DrawOption("CameraSlowSpeed", "Slow speed", 0.f, 1000.f);
DrawOption("CameraNormalSpeed", "Normal speed", 0.f, 1000.f);
DrawOption("CameraFastSpeed", "Fast speed", 0.f, 1000.f);
DrawOption("CameraRollSpeed", "Roll speed", 0.f, 1.f);
DrawSliderOption("CameraSlowSpeed", "Slow speed", 0.f, 1000.f);
DrawSliderOption("CameraNormalSpeed", "Normal speed", 0.f, 1000.f);
DrawSliderOption("CameraFastSpeed", "Fast speed", 0.f, 1000.f);
DrawSliderOption("CameraRollSpeed", "Roll speed", 0.f, 1.f);
}

if (ImGui::CollapsingHeader("Controls"))
{
DrawOption("SkewSpeed", "Vertical skew speed", 0.f, 1000.f);
DrawSliderOption("SkewSpeed", "Vertical skew speed", 0.f, 1000.f);
}

ImGui::End();
}

void Options::DrawOption(const char* name, const char* description, float min, float max) const noexcept
void Options::DrawCheckOption(const char* name, const char* description) const noexcept
{
// TODO use a map for better performance
for (auto& option : m_options)
auto option = FindOption(name);
if (option == nullptr) return;

if (ImGui::Checkbox(description, (bool*)option->GetValuePtr()))
{
if (option->GetName() == name)
{
DrawOption(option, description, min, max);
}
option->SaveValue();
}
}

void Options::DrawOption(BaseOption* option, const char* description, float min, float max) const noexcept
void Options::DrawSliderOption(const char* name, const char* description, float min, float max) const noexcept
{
auto type = option->GetType();
auto option = FindOption(name);
if (option == nullptr) return;

if (type == typeid(bool).hash_code())
if (ImGui::SliderFloat(description, (float*)option->GetValuePtr(), min, max))
{
if (ImGui::Checkbox(description, (bool*)option->GetValuePtr()))
{
option->SaveValue();
}
option->SaveValue();
}
}

void Options::DrawComboOption(const char* name, const char* description, std::vector<const char*> items) const noexcept
{
auto option = FindOption(name);
if (option == nullptr) return;

auto value = (int*)option->GetValuePtr();

if (type == typeid(float).hash_code())
if (ImGui::Combo(description, value, items.data(), items.size()))
{
if (ImGui::SliderFloat(description, (float*)option->GetValuePtr(), min, max))
{
option->SaveValue();
}
option->SaveValue();
}
}

void Options::Show() noexcept
void Options::SetVisible(bool visible) noexcept
{
m_show = true;
m_show = visible;
}

void Options::AddOption(BaseOption* option)
Expand All @@ -90,4 +92,18 @@ void Options::AddOption(BaseOption* option)

// Load the value from the registry
option->LoadValue();
}

BaseOption* Options::FindOption(const char* name) const noexcept
{
// TODO use a map for better performance
for (auto& option : m_options)
{
if (option->GetName() == name)
{
return option;
}
}

return nullptr;
}
9 changes: 6 additions & 3 deletions src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ class Options : public Module
bool m_show = false;

void DrawOptions() noexcept;
void DrawOption(const char* name, const char* description, float min = 0.f, float max = 0.f) const noexcept;
void DrawOption(BaseOption* option, const char* description, float min, float max) const noexcept;

void DrawCheckOption(const char* name, const char* description) const noexcept;
void DrawSliderOption(const char* name, const char* description, float min, float max) const noexcept;
void DrawComboOption(const char* name, const char* description, std::vector<const char*> items) const noexcept;

public:
Options();

void OnDraw();
void Show() noexcept;
void SetVisible(bool visible) noexcept;
void AddOption(BaseOption* option);
BaseOption* FindOption(const char* name) const noexcept;
};
2 changes: 1 addition & 1 deletion src/menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void Menu::DrawMenu() noexcept
{
if (ImGui::MenuItem("Options"))
{
Hook::GetInstance().GetModule<Options>()->Show();
Hook::GetInstance().GetModule<Options>()->SetVisible(true);
}

if (ImGui::MenuItem("GitHub"))
Expand Down

0 comments on commit 2d7a180

Please sign in to comment.