Skip to content

Commit

Permalink
Fixed settings menu crashing without registered commands
Browse files Browse the repository at this point in the history
  • Loading branch information
DayibBaba committed Sep 6, 2023
1 parent 2a3f2bd commit 63411b3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/game/frontend/manager/UIManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

namespace YimMenu
{
class Option
{
public:
virtual void Draw() = 0;
};

class MiniSubmenu
{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/game/frontend/manager/Widgets/HotkeySetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace YimMenu
}
else
{
ImGui::PushItemWidth(50);
ImGui::PushItemWidth(35);
for (auto hotkey_modifier : command_hotkey_link->Hotkey)
{
char key_label[32];
Expand Down
8 changes: 8 additions & 0 deletions src/game/frontend/manager/Widgets/Widgets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

namespace YimMenu
{
//Preferably, all options could be saved in a global instance to make UI elements searchable.
//Preferably, most if not all elements should be done through a widget to have them mapped.
class Option
{
public:
virtual void Draw() = 0;
};

class Button : public Option
{
public:
Expand Down
8 changes: 7 additions & 1 deletion src/game/frontend/menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace YimMenu
static auto SettingsSubmenu = std::make_shared<Settings>();
SettingsSubmenu->LoadSubmenus(); //Loads mini submenus into memory.



Renderer::AddRendererCallBack(
[&] {
if (!GUI::IsOpen())
Expand All @@ -22,7 +24,7 @@ namespace YimMenu
//Think this add HTML&PHP with no CSS. Lol just for testing.

ImGui::SetNextWindowSize(ImVec2(610, 610 /*add auto resize*/), ImGuiCond_Once);
if (ImGui::Begin("Main Window"))
if (ImGui::Begin("HorseMenu"))
{
const auto& pos = ImGui::GetCursorPos();

Expand All @@ -34,6 +36,8 @@ namespace YimMenu

if (ImGui::BeginChild("##submenus", ImVec2(120, 0), true))
{
//Arguably the only place this file should be edited at for more menus

g_SubmenuHandler.SubmenuOption("L" /*Logo Font*/, "Self", SelfSubmenu); //Ideally with the logo you'd have them squares that fit perfectly.
g_SubmenuHandler.SubmenuOption("L" /*Logo Font*/, "Settings", SettingsSubmenu);
}
Expand Down Expand Up @@ -64,5 +68,7 @@ namespace YimMenu
}
},
-1);

//Menu::ApplyTheme();
}
}
11 changes: 7 additions & 4 deletions src/game/frontend/menu/settings/Settings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "settings.hpp"
#include "core/commands/HotkeySystem.hpp"
#include "core/commands/Commands.hpp"
#include "core/commands/HotkeySystem.hpp"
#include "core/commands/LoopedCommand.hpp"
#include "game/frontend/manager/Widgets/Widgets.hpp"

Expand All @@ -11,19 +11,22 @@ namespace YimMenu
{
ImGui::BulletText("Hover over the command name to change its hotkey");
ImGui::BulletText("Press any registered key to remove");

ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();

for (auto [hash, command] : Commands::GetCommands())
{
ImGui::PushID(hash);

HotkeySetter(hash).Draw();
if (g_HotkeySystem.m_CommandHotkeys.find(hash) != g_HotkeySystem.m_CommandHotkeys.end())
HotkeySetter(hash).Draw();

ImGui::Spacing();

ImGui::PopID();
}

};

//Init mini submenus
Expand All @@ -34,7 +37,7 @@ namespace YimMenu
m_DefaultMiniSubmenu = m_MiniSubMenus.front();
}

//Script Tick If Needed
//Script Tick If Needed
void Settings::Update()
{
//TODO
Expand Down

0 comments on commit 63411b3

Please sign in to comment.