Skip to content

Commit 2d7a180

Browse files
committed
Refactor options window
1 parent 1d542b3 commit 2d7a180

File tree

3 files changed

+52
-33
lines changed

3 files changed

+52
-33
lines changed

src/Options.cpp

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,63 +25,65 @@ void Options::DrawOptions() noexcept
2525

2626
if (ImGui::CollapsingHeader("General"))
2727
{
28-
DrawOption("DisableIntro", "Disable legal screen and intros");
29-
DrawOption("NoCinematicBars", "Disable cinematic bars");
30-
DrawOption("NoMotionBlur", "Disable motion blur");
28+
DrawComboOption("IntroSkip", "Legal screen and intros", { "Don't skip", "Skip legal", "Skip legal and intros" });
29+
DrawCheckOption("NoCinematicBars", "Disable cinematic bars");
30+
DrawCheckOption("NoMotionBlur", "Disable motion blur");
3131
}
3232

3333
if (ImGui::CollapsingHeader("Camera"))
3434
{
35-
DrawOption("CameraSlowSpeed", "Slow speed", 0.f, 1000.f);
36-
DrawOption("CameraNormalSpeed", "Normal speed", 0.f, 1000.f);
37-
DrawOption("CameraFastSpeed", "Fast speed", 0.f, 1000.f);
38-
DrawOption("CameraRollSpeed", "Roll speed", 0.f, 1.f);
35+
DrawSliderOption("CameraSlowSpeed", "Slow speed", 0.f, 1000.f);
36+
DrawSliderOption("CameraNormalSpeed", "Normal speed", 0.f, 1000.f);
37+
DrawSliderOption("CameraFastSpeed", "Fast speed", 0.f, 1000.f);
38+
DrawSliderOption("CameraRollSpeed", "Roll speed", 0.f, 1.f);
3939
}
4040

4141
if (ImGui::CollapsingHeader("Controls"))
4242
{
43-
DrawOption("SkewSpeed", "Vertical skew speed", 0.f, 1000.f);
43+
DrawSliderOption("SkewSpeed", "Vertical skew speed", 0.f, 1000.f);
4444
}
4545

4646
ImGui::End();
4747
}
4848

49-
void Options::DrawOption(const char* name, const char* description, float min, float max) const noexcept
49+
void Options::DrawCheckOption(const char* name, const char* description) const noexcept
5050
{
51-
// TODO use a map for better performance
52-
for (auto& option : m_options)
51+
auto option = FindOption(name);
52+
if (option == nullptr) return;
53+
54+
if (ImGui::Checkbox(description, (bool*)option->GetValuePtr()))
5355
{
54-
if (option->GetName() == name)
55-
{
56-
DrawOption(option, description, min, max);
57-
}
56+
option->SaveValue();
5857
}
5958
}
6059

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

65-
if (type == typeid(bool).hash_code())
65+
if (ImGui::SliderFloat(description, (float*)option->GetValuePtr(), min, max))
6666
{
67-
if (ImGui::Checkbox(description, (bool*)option->GetValuePtr()))
68-
{
69-
option->SaveValue();
70-
}
67+
option->SaveValue();
7168
}
69+
}
70+
71+
void Options::DrawComboOption(const char* name, const char* description, std::vector<const char*> items) const noexcept
72+
{
73+
auto option = FindOption(name);
74+
if (option == nullptr) return;
75+
76+
auto value = (int*)option->GetValuePtr();
7277

73-
if (type == typeid(float).hash_code())
78+
if (ImGui::Combo(description, value, items.data(), items.size()))
7479
{
75-
if (ImGui::SliderFloat(description, (float*)option->GetValuePtr(), min, max))
76-
{
77-
option->SaveValue();
78-
}
80+
option->SaveValue();
7981
}
8082
}
8183

82-
void Options::Show() noexcept
84+
void Options::SetVisible(bool visible) noexcept
8385
{
84-
m_show = true;
86+
m_show = visible;
8587
}
8688

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

9193
// Load the value from the registry
9294
option->LoadValue();
95+
}
96+
97+
BaseOption* Options::FindOption(const char* name) const noexcept
98+
{
99+
// TODO use a map for better performance
100+
for (auto& option : m_options)
101+
{
102+
if (option->GetName() == name)
103+
{
104+
return option;
105+
}
106+
}
107+
108+
return nullptr;
93109
}

src/Options.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ class Options : public Module
8989
bool m_show = false;
9090

9191
void DrawOptions() noexcept;
92-
void DrawOption(const char* name, const char* description, float min = 0.f, float max = 0.f) const noexcept;
93-
void DrawOption(BaseOption* option, const char* description, float min, float max) const noexcept;
92+
93+
void DrawCheckOption(const char* name, const char* description) const noexcept;
94+
void DrawSliderOption(const char* name, const char* description, float min, float max) const noexcept;
95+
void DrawComboOption(const char* name, const char* description, std::vector<const char*> items) const noexcept;
9496

9597
public:
9698
Options();
9799

98100
void OnDraw();
99-
void Show() noexcept;
101+
void SetVisible(bool visible) noexcept;
100102
void AddOption(BaseOption* option);
103+
BaseOption* FindOption(const char* name) const noexcept;
101104
};

src/menu/Menu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void Menu::DrawMenu() noexcept
119119
{
120120
if (ImGui::MenuItem("Options"))
121121
{
122-
Hook::GetInstance().GetModule<Options>()->Show();
122+
Hook::GetInstance().GetModule<Options>()->SetVisible(true);
123123
}
124124

125125
if (ImGui::MenuItem("GitHub"))

0 commit comments

Comments
 (0)