Grouped filters by categories

This commit is contained in:
Andrei Abrudan 2022-07-05 01:53:32 +01:00
parent 2de9b3eab7
commit c7a31d9d15
2 changed files with 73 additions and 47 deletions

View File

@ -6,6 +6,18 @@
#include <cheat/game/EntityManager.h> #include <cheat/game/EntityManager.h>
#include <cheat/game/util.h> #include <cheat/game/util.h>
// Returns the unique categories (i.e. the third element of every tuple) in a filter object.
static std::vector<std::string> uniqueCategories(const std::vector<std::tuple<config::Field<bool>, std::string, std::string>>& filter)
{
std::vector<std::string> result;
std::transform(filter.begin(), filter.end(), std::back_inserter(result),
[](const auto& item) {return std::get<2>(item); });
std::sort(result.begin(), result.end());
auto it = std::unique(result.begin(), result.end());
result.erase(it, result.end());
return result;
}
namespace cheat::feature namespace cheat::feature
{ {
VacuumLoot::VacuumLoot() : Feature(), VacuumLoot::VacuumLoot() : Feature(),
@ -23,21 +35,31 @@ namespace cheat::feature
void VacuumLoot::DrawMain() void VacuumLoot::DrawMain()
{ {
if (ImGui::BeginGroupPanel("Vacuum Loot", false)) if (ImGui::BeginGroupPanel("Vacuum Loot", false))
{ {
ConfigWidget("Enabled", f_Enabled, "Vacuum Loot drops"); ConfigWidget("Enabled", f_Enabled, "Vacuum Loot drops");
if (ImGui::TreeNode(this, "Loot Types")) if (ImGui::TreeNode(this, "Loot Types"))
{ {
for (auto& [field, name] : m_Filters) for (const auto& groupCategory : uniqueCategories(m_Filters))
{ {
ImGui::PushID(name.c_str()); if (ImGui::BeginGroupPanel(groupCategory.c_str(), false))
ConfigWidget(field); {
ImGui::PopID(); for (auto& [field, name, category] : m_Filters)
} {
ImGui::TreePop(); if (category == groupCategory)
} {
} ImGui::PushID(name.c_str());
ImGui::EndGroupPanel(); ConfigWidget(field);
ImGui::PopID();
}
}
}
ImGui::EndGroupPanel();
}
ImGui::TreePop();
}
}
ImGui::EndGroupPanel();
} }
bool VacuumLoot::NeedStatusDraw() const bool VacuumLoot::NeedStatusDraw() const
@ -62,9 +84,9 @@ namespace cheat::feature
auto distance = manager.avatar()->distance(entity); auto distance = manager.avatar()->distance(entity);
float radius = 100.0f; float radius = 100.0f;
for (const auto& lootItem : m_Filters) for (const auto& [field, name, category] : m_Filters)
if (lootItem.first.value()) if (field.value())
if (entity->name().find(lootItem.second) != std::string::npos) if (entity->name().find(name) != std::string::npos)
return distance <= radius; return distance <= radius;
return false; return false;
@ -91,41 +113,43 @@ namespace cheat::feature
nextTime = currentTime + 1000; nextTime = currentTime + 1000;
} }
void VacuumLoot::AddFilter(const std::string& friendName, const std::string& name) void VacuumLoot::AddFilter(const std::string& friendName,
const std::string& name,
const std::string& category)
{ {
m_Filters.push_back({ m_Filters.push_back({
config::CreateField<bool>(friendName, name, config::CreateField<bool>(friendName, name,
fmt::format("VacuumLoot::Filters::{}", name), fmt::format("VacuumLoot::Filters::{}", name),
false, true), false, true),
name name, category
}); });
} }
void VacuumLoot::InstallFilters() void VacuumLoot::InstallFilters()
{ {
AddFilter("General loot", "SceneObj_DropItem" ); AddFilter("General loot", "SceneObj_DropItem" ,"General");
AddFilter("Ore Drops", "SceneObj_Ore_Drop" ); AddFilter("Ore Drops", "SceneObj_Ore_Drop" ,"Ore");
AddFilter("Magic Crystal", "_DropMagicCrystal" ); AddFilter("Magic Crystal", "_DropMagicCrystal" ,"Ore");
AddFilter("Amethyst Lump", "_Thundercrystaldrop" ); AddFilter("Amethyst Lump", "_Thundercrystaldrop" ,"Ore");
AddFilter("Electro Crystal", "_Ore_ElectricRock" ); AddFilter("Electro Crystal", "_Ore_ElectricRock" ,"Ore");
AddFilter("Starsilver Ore", "_DropMoonMeteor_" ); AddFilter("Starsilver Ore", "_DropMoonMeteor_" ,"Ore");
AddFilter("Noctilucous Jade", "NightBerth" ); AddFilter("Noctilucous Jade", "NightBerth" ,"Ore");
AddFilter("Potatoes", "_Potato" ); AddFilter("Potatoes", "_Potato" ,"Food");
AddFilter("Radish", "_Radish02_Clear" ); AddFilter("Radish", "_Radish02_Clear" ,"Food");
AddFilter("Cabbage", "_Cabbage" ); AddFilter("Cabbage", "_Cabbage" ,"Food");
AddFilter("Carrot", "_Carrot02_Clear" ); AddFilter("Carrot", "_Carrot02_Clear" ,"Food");
AddFilter("Wheat", "_Wheat" ); AddFilter("Wheat", "_Wheat" ,"Food");
AddFilter("Crystalflies", "Wisp" ); AddFilter("Crystalflies", "Wisp" ,"General");
AddFilter("Meat & Fowl", "Meat" ); AddFilter("Meat & Fowl", "Meat" ,"Food");
AddFilter("Fishmeat", "Fishmeat" ); AddFilter("Fishmeat", "Fishmeat" ,"Food");
AddFilter("Crab", "Crab" ); AddFilter("Crab", "Crab" ,"Food");
AddFilter("Eel", "Eel_" ); AddFilter("Eel", "Eel_" ,"Food");
AddFilter("Lizard", "Lizard" ); AddFilter("Lizard", "Lizard" ,"General");
AddFilter("Swords", "Equip_Sword" ); AddFilter("Swords", "Equip_Sword" ,"Equipment");
AddFilter("Poles", "Equip_Pole" ); AddFilter("Poles", "Equip_Pole" ,"Equipment");
AddFilter("Bows", "Equip_Bow" ); AddFilter("Bows", "Equip_Bow" ,"Equipment");
AddFilter("Catalysts", "Equip_Catalyst" ); AddFilter("Catalysts", "Equip_Catalyst" ,"Equipment");
AddFilter("Claymores", "Equip_Claymore" ); AddFilter("Claymores", "Equip_Claymore" ,"Equipment");
AddFilter("Butterflies & Fireflies", "Eff_Animal" ); AddFilter("Butterflies & Fireflies", "Eff_Animal" ,"General");
} }
} }

View File

@ -25,12 +25,14 @@ namespace cheat::feature
void OnGameUpdate(); void OnGameUpdate();
private: private:
std::vector<std::pair<config::Field<bool>, std::string>> m_Filters; // Tuple of: enabled flag, human-readable name, filter category
using LootFilter = std::tuple<config::Field<bool>, std::string, std::string>;
std::vector<LootFilter> m_Filters;
int nextTime = 0; int nextTime = 0;
VacuumLoot(); VacuumLoot();
void InstallFilters(); void InstallFilters();
void AddFilter(const std::string& friendName, const std::string& name); void AddFilter(const std::string& friendName, const std::string& name, const std::string& category);
bool IsEntityForVac(cheat::game::Entity* entity); bool IsEntityForVac(cheat::game::Entity* entity);
}; };
} }