CheatMenuSA/src/hotkeys.cpp
Grinch_ 600ef84cef 1. Rename 'Auto heal' -> 'Health regen'
2. Block VCMP for VC build
3. Refactor code
2022-01-13 19:57:08 +06:00

126 lines
2.3 KiB
C++

#include "pch.h"
#include "hotkeys.h"
bool Hotkey::DrawUI(const char* label)
{
bool active = (m_CurrentHotkey == label);
bool state = false;
if (active)
{
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyle().Colors[ImGuiCol_ButtonActive]);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyle().Colors[ImGuiCol_ButtonActive]);
for (int key = 3; key != 135; ++key)
{
if (KeyPressed(key))
{
m_key1 = key;
break;
}
}
for (int key = 135; key != 3; --key)
{
if (KeyPressed(key))
{
m_key2 = key;
break;
}
}
}
std::string text;
if (m_key1 != VK_NONE)
{
text = key_names[m_key1 - 1];
}
else
{
text = "None";
}
if (m_key1 != m_key2)
{
text += (" + " + key_names[m_key2 - 1]);
}
if (ImGui::Button((text + std::string("##") + std::string(label)).c_str(),
ImVec2(ImGui::GetWindowContentRegionWidth() / 3.5, ImGui::GetFrameHeight()*1.35f)))
{
if (!active)
{
m_CurrentHotkey = label;
}
}
if (active && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
{
m_CurrentHotkey = "";
state = true;
}
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
{
if (ImGui::IsItemHovered())
{
m_key1 = VK_NONE;
m_key2 = VK_NONE;
}
else
{
m_CurrentHotkey = "";
}
state = true;
}
ImGui::SameLine();
ImGui::Text(label);
if (active)
{
ImGui::PopStyleColor(2);
}
return state;
}
bool Hotkey::Pressed()
{
if (KeyPressed(m_key1) && KeyPressed(m_key2))
{
m_bPressed = true;
}
else
{
if (m_bPressed)
{
m_bPressed = false;
return (m_CurrentHotkey == "");
}
}
return false;
}
std::string Hotkey::GetNameString()
{
std::string text;
if (m_key1 != VK_NONE)
{
text = key_names[m_key1 - 1];
}
else
{
text = "None";
}
if (m_key1 != m_key2)
{
text += (" + " + key_names[m_key2 - 1]);
}
return text;
}