fix(hotkey_service): duplicate key overwrite (#643)
This commit is contained in:
parent
cab25b12f7
commit
4a22a997c5
@ -226,6 +226,7 @@ namespace big
|
||||
int menu_toggle = VK_INSERT;
|
||||
int teleport_waypoint = 0;
|
||||
int teleport_objective = 0;
|
||||
int noclip = 0;
|
||||
};
|
||||
|
||||
bool dev_dlc = false;
|
||||
@ -665,6 +666,7 @@ namespace big
|
||||
this->settings.hotkeys.menu_toggle = j["settings"]["hotkeys"]["menu_toggle"];
|
||||
this->settings.hotkeys.teleport_waypoint = j["settings"]["hotkeys"]["teleport_waypoint"];
|
||||
this->settings.hotkeys.teleport_objective = j["settings"]["hotkeys"]["teleport_objective"];
|
||||
this->settings.hotkeys.noclip = j["settings"]["hotkeys"]["noclip"];
|
||||
|
||||
this->spawn_vehicle.preview_vehicle = j["spawn_vehicle"]["preview_vehicle"];
|
||||
this->spawn_vehicle.spawn_inside = j["spawn_vehicle"]["spawn_inside"];
|
||||
@ -1012,7 +1014,8 @@ namespace big
|
||||
{ "hotkeys", {
|
||||
{ "menu_toggle", this->settings.hotkeys.menu_toggle },
|
||||
{ "teleport_waypoint", this->settings.hotkeys.teleport_waypoint },
|
||||
{ "teleport_objective", this->settings.hotkeys.teleport_objective }
|
||||
{ "teleport_objective", this->settings.hotkeys.teleport_objective },
|
||||
{ "noclip", this->settings.hotkeys.noclip }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
src/services/hotkey/hotkey_functions.cpp
Normal file
14
src/services/hotkey/hotkey_functions.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "common.hpp"
|
||||
#include "hotkey_functions.hpp"
|
||||
#include "services/notifications/notification_service.hpp"
|
||||
|
||||
namespace big::hotkey_funcs
|
||||
{
|
||||
void toggle_noclip()
|
||||
{
|
||||
const auto state = !g->self.noclip;
|
||||
g_notification_service->push("Noclip", std::format("Noclip has been {}.", state ? "enabled" : "disabled"));
|
||||
|
||||
g->self.noclip = state;
|
||||
}
|
||||
}
|
6
src/services/hotkey/hotkey_functions.hpp
Normal file
6
src/services/hotkey/hotkey_functions.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace big::hotkey_funcs
|
||||
{
|
||||
extern void toggle_noclip();
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#include "hotkey_service.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
#include "util/teleport.hpp"
|
||||
#include "hotkey_functions.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
@ -8,6 +9,7 @@ namespace big
|
||||
{
|
||||
register_hotkey("waypoint", g->settings.hotkeys.teleport_waypoint, teleport::to_waypoint);
|
||||
register_hotkey("objective", g->settings.hotkeys.teleport_objective, teleport::to_objective);
|
||||
register_hotkey("noclip", g->settings.hotkeys.noclip, hotkey_funcs::toggle_noclip);
|
||||
|
||||
g_hotkey_service = this;
|
||||
}
|
||||
@ -24,18 +26,17 @@ namespace big
|
||||
|
||||
bool hotkey_service::update_hotkey(const std::string_view name, const key_t key)
|
||||
{
|
||||
static auto update_hotkey_map = [key](hotkey_map& hotkey_map, rage::joaat_t name_hash) -> bool
|
||||
static auto update_hotkey_map = [](hotkey_map& hotkey_map, rage::joaat_t name_hash, key_t new_key) -> bool
|
||||
{
|
||||
if (const auto &it = std::find_if(hotkey_map.begin(), hotkey_map.end(), [name_hash](std::pair<key_t, hotkey> pair) -> bool
|
||||
{
|
||||
return pair.second.name_hash() == name_hash;
|
||||
}); it != hotkey_map.end())
|
||||
for (auto it = hotkey_map.begin(); it != hotkey_map.end(); ++it)
|
||||
{
|
||||
auto hotkey = it->second;
|
||||
hotkey.set_key(key);
|
||||
if (hotkey.name_hash() != name_hash)
|
||||
continue;
|
||||
|
||||
hotkey_map.emplace(key, hotkey);
|
||||
hotkey_map.erase(it);
|
||||
hotkey.set_key(new_key);
|
||||
hotkey_map.emplace(new_key, hotkey);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -43,8 +44,8 @@ namespace big
|
||||
};
|
||||
|
||||
const auto name_hash = rage::joaat(name);
|
||||
return update_hotkey_map(m_hotkeys[1], name_hash) // released
|
||||
&& update_hotkey_map(m_hotkeys[0], name_hash); // down
|
||||
return update_hotkey_map(m_hotkeys[1], name_hash, key) // released
|
||||
&& update_hotkey_map(m_hotkeys[0], name_hash, key); // down
|
||||
}
|
||||
|
||||
void hotkey_service::wndproc(eKeyState state, key_t key)
|
||||
|
@ -10,7 +10,7 @@ namespace big
|
||||
DOWN = WM_KEYDOWN
|
||||
};
|
||||
|
||||
using hotkey_map = std::map<key_t, hotkey>;
|
||||
using hotkey_map = std::multimap<key_t, hotkey>;
|
||||
|
||||
class hotkey_service final
|
||||
{
|
||||
|
@ -42,6 +42,9 @@ namespace big
|
||||
if (ImGui::Hotkey("Teleport to objective", &g->settings.hotkeys.teleport_objective))
|
||||
g_hotkey_service->update_hotkey("objective", g->settings.hotkeys.teleport_objective);
|
||||
|
||||
if (ImGui::Hotkey("Toggle Noclip", &g->settings.hotkeys.noclip))
|
||||
g_hotkey_service->update_hotkey("noclip", g->settings.hotkeys.noclip);
|
||||
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
|
Reference in New Issue
Block a user