Skip to content

Commit

Permalink
Merge pull request #35 from RaidcoreGG/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DeltaGW2 authored Apr 11, 2024
2 parents 19877d1 + b1a8d89 commit 00722b4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
64 changes: 42 additions & 22 deletions src/GUI/Widgets/Options/COptionsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ namespace GUI
float kbButtonWidth = ImGui::CalcTextSize("XXXXXXXXXXXXXXXXXXXXXXXX").x;

bool openEditor = false;
bool deleteStaleBind = false;
std::string staleBindIdentifier;

Keybinds::Mutex.lock();
{
Expand All @@ -435,46 +437,64 @@ namespace GUI
}
for (std::string cat : categories)
{
ImGui::TextDisabled(cat.c_str());
if (ImGui::BeginTable(("table_keybinds##" + cat).c_str(), 3, ImGuiTableFlags_BordersInnerH))
if (ImGui::CollapsingHeader(cat != "(null)" ? cat.c_str() : "Inactive", ImGuiTreeNodeFlags_DefaultOpen))
{
for (auto& [identifier, keybind] : Keybinds::Registry)
if (ImGui::BeginTable(("table_keybinds##" + cat).c_str(), 3, ImGuiTableFlags_BordersInnerH))
{
if (Loader::GetOwner(keybind.Handler) != cat) { continue; }

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text(Language.Translate(identifier.c_str()));

ImGui::TableSetColumnIndex(1);
if (ImGui::Button((keybind.Bind.ToString(true) + "##" + identifier).c_str(), ImVec2(kbButtonWidth, 0.0f)))
for (auto& [identifier, keybind] : Keybinds::Registry)
{
CurrentlyEditing = identifier;
openEditor = true;
if (Loader::GetOwner(keybind.Handler) != cat) { continue; }

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text(Language.Translate(identifier.c_str()));

ImGui::TableSetColumnIndex(1);
if (ImGui::Button((keybind.Bind.ToString(true) + "##" + identifier).c_str(), ImVec2(kbButtonWidth, 0.0f)))
{
CurrentlyEditing = identifier;
openEditor = true;
}

ImGui::TableSetColumnIndex(2);
if (keybind.Handler == nullptr)
{
if (ImGui::SmallButton(("X##" + identifier).c_str()))
{
deleteStaleBind = true;
staleBindIdentifier = identifier;
}
ImGui::SameLine();
ImGui::TextDisabled(Language.Translate("((000061))"));
}
}

ImGui::TableSetColumnIndex(2);
if (keybind.Handler == nullptr)
{
ImGui::TextDisabled(Language.Translate("((000061))"));
}
ImGui::EndTable();
}

ImGui::EndTable();
}
}
}
Keybinds::Mutex.unlock();

if (deleteStaleBind && !staleBindIdentifier.empty())
{
Keybinds::Delete(staleBindIdentifier);
deleteStaleBind = false;
staleBindIdentifier.clear();
}

std::string kbModalTitle = Language.Translate("((000062))");
kbModalTitle.append(Language.Translate(CurrentlyEditing.c_str()));

if (openEditor)
{
openEditor = false;
ImGui::OpenPopup((Language.Translate("((000062))") + CurrentlyEditing).c_str(), ImGuiPopupFlags_AnyPopupLevel);
ImGui::OpenPopup(kbModalTitle.c_str(), ImGuiPopupFlags_AnyPopupLevel);
}

ImVec2 center(Renderer::Width * 0.5f, Renderer::Height * 0.5f);
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal((Language.Translate("((000062))") + CurrentlyEditing).c_str(), NULL, WindowFlags_Default))
if (ImGui::BeginPopupModal(kbModalTitle.c_str(), NULL, WindowFlags_Default))
{
Keybinds::IsSettingKeybind = true;
if (Keybinds::CurrentKeybind == Keybind{})
Expand Down
12 changes: 10 additions & 2 deletions src/Keybinds/KeybindHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ namespace Keybinds

if (res != aIdentifier && res != "") { return; }

const std::lock_guard<std::mutex> lock(Mutex);
{
const std::lock_guard<std::mutex> lock(Mutex);

Registry[aIdentifier].Bind = aKeybind;
Registry[aIdentifier].Bind = aKeybind;
}

Save();
}
Expand All @@ -356,6 +358,12 @@ namespace Keybinds
return called;
}

void Delete(std::string aIdentifier)
{
const std::lock_guard<std::mutex> lock(Mutex);
Registry.erase(aIdentifier);
}

int Verify(void* aStartAddress, void* aEndAddress)
{
int refCounter = 0;
Expand Down
9 changes: 8 additions & 1 deletion src/Keybinds/KeybindHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,17 @@ namespace Keybinds

///----------------------------------------------------------------------------------------------------
/// Invoke:
/// Invokes the action on the corresponding keybind handler. Returns true if the keybind was dispatched.
/// Invokes the action on the corresponding keybind handler.
/// Returns true if the keybind was dispatched.
///----------------------------------------------------------------------------------------------------
bool Invoke(std::string aIdentifier);

///----------------------------------------------------------------------------------------------------
/// Deletes:
/// Deletes a keybind entirely.
///----------------------------------------------------------------------------------------------------
void Delete(std::string aIdentifier);

///----------------------------------------------------------------------------------------------------
/// Verify:
/// Removes all KeybindHandlers that are within the provided address space.
Expand Down

0 comments on commit 00722b4

Please sign in to comment.