mirror of
https://github.com/YimMenu/YimMenuV2.git
synced 2026-10-10 11:53:14 +08:00
fix: fix hotkey rendering
This commit is contained in:
@@ -94,11 +94,11 @@ namespace YimMenu
|
|||||||
{
|
{
|
||||||
while (g_Running)
|
while (g_Running)
|
||||||
{
|
{
|
||||||
if (GetForegroundWindow() == *Pointers.Hwnd && !HUD::IS_PAUSE_MENU_ACTIVE() && !HUD::IS_SOCIAL_CLUB_ACTIVE())
|
if (GetForegroundWindow() == *Pointers.Hwnd && !HUD::IS_PAUSE_MENU_ACTIVE() && !HUD::IS_SOCIAL_CLUB_ACTIVE() && !m_BeingModified)
|
||||||
{
|
{
|
||||||
for (auto& [hash, link] : m_CommandHotkeys)
|
for (auto& [hash, link] : m_CommandHotkeys)
|
||||||
{
|
{
|
||||||
if (link.m_Chain.empty() || link.m_BeingModified)
|
if (link.m_Chain.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool all_keys_pressed = true;
|
bool all_keys_pressed = true;
|
||||||
@@ -158,4 +158,9 @@ namespace YimMenu
|
|||||||
m_CommandHotkeys[std::atoi(key.data())].m_Chain = value.get<std::vector<int>>();
|
m_CommandHotkeys[std::atoi(key.data())].m_Chain = value.get<std::vector<int>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HotkeySystem::SetBeingModifed(bool being_modified)
|
||||||
|
{
|
||||||
|
g_HotkeySystem.m_BeingModified = being_modified;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
namespace YimMenu
|
namespace YimMenu
|
||||||
{
|
{
|
||||||
|
// TODO: this should be called something else
|
||||||
struct CommandLink
|
struct CommandLink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::vector<int> m_Chain{};
|
std::vector<int> m_Chain{};
|
||||||
bool m_BeingModified = false;
|
|
||||||
|
|
||||||
CommandLink() {};
|
CommandLink() {};
|
||||||
};
|
};
|
||||||
@@ -16,6 +16,7 @@ namespace YimMenu
|
|||||||
private IStateSerializer
|
private IStateSerializer
|
||||||
{
|
{
|
||||||
std::chrono::system_clock::time_point m_LastHotkeyTriggerTime;
|
std::chrono::system_clock::time_point m_LastHotkeyTriggerTime;
|
||||||
|
bool m_BeingModified;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HotkeySystem();
|
HotkeySystem();
|
||||||
@@ -31,6 +32,8 @@ namespace YimMenu
|
|||||||
|
|
||||||
virtual void SaveStateImpl(nlohmann::json& state) override;
|
virtual void SaveStateImpl(nlohmann::json& state) override;
|
||||||
virtual void LoadStateImpl(nlohmann::json& state) override;
|
virtual void LoadStateImpl(nlohmann::json& state) override;
|
||||||
|
|
||||||
|
static void SetBeingModifed(bool being_modified);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline HotkeySystem g_HotkeySystem;
|
inline HotkeySystem g_HotkeySystem;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "Items.hpp"
|
#include "Items.hpp"
|
||||||
#include "core/commands/Commands.hpp"
|
#include "core/commands/Commands.hpp"
|
||||||
#include "core/commands/Command.hpp"
|
#include "core/commands/Command.hpp"
|
||||||
|
#include "core/commands/HotkeySystem.hpp"
|
||||||
#include "core/backend/FiberPool.hpp"
|
#include "core/backend/FiberPool.hpp"
|
||||||
|
|
||||||
namespace YimMenu
|
namespace YimMenu
|
||||||
@@ -40,16 +41,21 @@ namespace YimMenu
|
|||||||
ImGui::SetNextWindowSize(ImVec2(500, 120));
|
ImGui::SetNextWindowSize(ImVec2(500, 120));
|
||||||
if (ImGui::BeginPopupModal(windowLabel.data(), nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar))
|
if (ImGui::BeginPopupModal(windowLabel.data(), nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar))
|
||||||
{
|
{
|
||||||
ImGui::BulletText("Hold the command name clicked to change its hotkey");
|
ImGui::BulletText("Enter a keystroke");
|
||||||
ImGui::BulletText("Press any registered key to remove");
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
HotkeySetter(m_Command->GetHash()).Draw();
|
HotkeySystem::SetBeingModifed(true);
|
||||||
|
|
||||||
|
if (auto it = g_HotkeySystem.m_CommandHotkeys.find(m_Command->GetHash()); it != g_HotkeySystem.m_CommandHotkeys.end())
|
||||||
|
g_HotkeySystem.CreateHotkey(it->second.m_Chain);
|
||||||
|
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
if (ImGui::Button("Close") || ((!ImGui::IsWindowHovered() && !ImGui::IsAnyItemHovered()) && ImGui::IsMouseClicked(ImGuiMouseButton_Left)))
|
if (ImGui::Button("Close") || ((!ImGui::IsWindowHovered() && !ImGui::IsAnyItemHovered()) && ImGui::IsMouseClicked(ImGuiMouseButton_Left)))
|
||||||
|
{
|
||||||
|
HotkeySystem::SetBeingModifed(false);
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
#include "Items.hpp"
|
|
||||||
#include "core/commands/Command.hpp"
|
|
||||||
#include "core/commands/Commands.hpp"
|
|
||||||
#include "core/commands/HotkeySystem.hpp"
|
|
||||||
|
|
||||||
namespace YimMenu
|
|
||||||
{
|
|
||||||
HotkeySetter::HotkeySetter(joaat_t command_id) :
|
|
||||||
m_Id(command_id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void HotkeySetter::Draw()
|
|
||||||
{
|
|
||||||
auto Command = Commands::GetCommand(m_Id);
|
|
||||||
|
|
||||||
if (!Command)
|
|
||||||
ImGui::Text("Unkown Command");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CommandLink* CommandHotkeyLink = &g_HotkeySystem.m_CommandHotkeys.at(Command->GetHash());
|
|
||||||
|
|
||||||
if (!CommandHotkeyLink)
|
|
||||||
{
|
|
||||||
ImGui::Text("Unkown CommandLink");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImGui::Button(Command->GetLabel().data());
|
|
||||||
CommandHotkeyLink->m_BeingModified = ImGui::IsItemActive();
|
|
||||||
|
|
||||||
if (CommandHotkeyLink->m_BeingModified)
|
|
||||||
{
|
|
||||||
g_HotkeySystem.CreateHotkey(CommandHotkeyLink->m_Chain);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SameLine(200);
|
|
||||||
ImGui::BeginGroup();
|
|
||||||
|
|
||||||
if (CommandHotkeyLink->m_Chain.empty())
|
|
||||||
{
|
|
||||||
if (CommandHotkeyLink->m_BeingModified)
|
|
||||||
ImGui::Text("Press any button...");
|
|
||||||
else
|
|
||||||
ImGui::Text("No Hotkey Assigned");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImGui::PushItemWidth(35);
|
|
||||||
for (auto HotkeyModifier : CommandHotkeyLink->m_Chain)
|
|
||||||
{
|
|
||||||
char KeyLabel[32];
|
|
||||||
strcpy(KeyLabel, g_HotkeySystem.GetHotkeyLabel(HotkeyModifier).data());
|
|
||||||
ImGui::InputText("##keylabel", KeyLabel, 32, ImGuiInputTextFlags_ReadOnly);
|
|
||||||
if (ImGui::IsItemClicked())
|
|
||||||
std::erase_if(CommandHotkeyLink->m_Chain, [HotkeyModifier](int i) {
|
|
||||||
return i == HotkeyModifier;
|
|
||||||
});
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
}
|
|
||||||
ImGui::PopItemWidth();
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::Button("Clear"))
|
|
||||||
{
|
|
||||||
CommandHotkeyLink->m_Chain.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndGroup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,6 +14,7 @@ namespace YimMenu
|
|||||||
class Command;
|
class Command;
|
||||||
class ColorCommand;
|
class ColorCommand;
|
||||||
class StringCommand;
|
class StringCommand;
|
||||||
|
class CommandLink;
|
||||||
|
|
||||||
class Button : public UIItem
|
class Button : public UIItem
|
||||||
{
|
{
|
||||||
@@ -134,16 +135,6 @@ namespace YimMenu
|
|||||||
std::function<void()> m_Callback;
|
std::function<void()> m_Callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HotkeySetter : public UIItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit HotkeySetter(joaat_t);
|
|
||||||
void Draw() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
joaat_t m_Id;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Group : public UIItem
|
class Group : public UIItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -11,19 +11,80 @@ namespace YimMenu::Submenus
|
|||||||
// TODO: refactor this
|
// TODO: refactor this
|
||||||
static void Hotkeys()
|
static void Hotkeys()
|
||||||
{
|
{
|
||||||
ImGui::BulletText("Hold the command name clicked to change its hotkey");
|
ImGui::BulletText("Hold the button with the command name and enter a keystroke to change its hotkey");
|
||||||
ImGui::BulletText("Press any registered key to remove");
|
ImGui::BulletText("If a command has an existing hotkey, clicking the button will remove it");
|
||||||
|
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
|
|
||||||
|
// this assumes we can't add new commands in runtime, but a lot of other subsystems assume that too
|
||||||
|
static std::map<std::string, CommandLink*> sortedCommands;
|
||||||
|
static bool commandsSorted = []() {
|
||||||
|
for (auto& [hash, command] : Commands::GetCommands())
|
||||||
|
{
|
||||||
|
if (auto it = g_HotkeySystem.m_CommandHotkeys.find(hash); it != g_HotkeySystem.m_CommandHotkeys.end())
|
||||||
|
sortedCommands.emplace(command->GetLabel(), it->second);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
|
||||||
for (auto& [Hash, Command] : Commands::GetCommands())
|
HotkeySystem::SetBeingModifed(false);
|
||||||
|
|
||||||
|
for (auto& [name, link] : sortedCommands)
|
||||||
{
|
{
|
||||||
ImGui::PushID(Hash);
|
ImGui::PushID(link);
|
||||||
|
|
||||||
if (g_HotkeySystem.m_CommandHotkeys.find(Hash) != g_HotkeySystem.m_CommandHotkeys.end())
|
ImGui::Button(name.data());
|
||||||
HotkeySetter(Hash).Draw();
|
|
||||||
|
bool active = ImGui::IsItemActive();
|
||||||
|
|
||||||
|
if (active)
|
||||||
|
{
|
||||||
|
HotkeySystem::SetBeingModifed(true);
|
||||||
|
g_HotkeySystem.CreateHotkey(link->m_Chain);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine(250);
|
||||||
|
ImGui::BeginGroup();
|
||||||
|
|
||||||
|
if (link->m_Chain.empty())
|
||||||
|
{
|
||||||
|
if (active)
|
||||||
|
ImGui::Text("Press any button...");
|
||||||
|
else
|
||||||
|
ImGui::Text("No hotkey assigned");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::PushItemWidth(35);
|
||||||
|
int i = 0;
|
||||||
|
for (auto key : link->m_Chain)
|
||||||
|
{
|
||||||
|
char key_label[32];
|
||||||
|
strcpy(key_label, g_HotkeySystem.GetHotkeyLabel(key).data());
|
||||||
|
|
||||||
|
ImGui::PushID(i);
|
||||||
|
ImGui::InputText("##keylabel", key_label, 32, ImGuiInputTextFlags_ReadOnly);
|
||||||
|
if (ImGui::IsItemClicked())
|
||||||
|
std::erase_if(link->m_Chain, [key](int j) {
|
||||||
|
return j == key;
|
||||||
|
});
|
||||||
|
ImGui::PopID();
|
||||||
|
|
||||||
|
i++;
|
||||||
|
ImGui::SameLine();
|
||||||
|
}
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Clear"))
|
||||||
|
{
|
||||||
|
link->m_Chain.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndGroup();
|
||||||
|
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user