h2-mod/src/client/component/gui_asset_list.cpp

101 lines
2.2 KiB
C++
Raw Normal View History

2021-12-19 19:53:01 -05:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "scheduler.hpp"
#include "command.hpp"
#include "gui.hpp"
2022-01-02 17:51:38 -05:00
#include "fastfiles.hpp"
2021-12-19 19:53:01 -05:00
#include <utils/string.hpp>
#include <utils/hook.hpp>
namespace asset_list
{
namespace
{
2021-12-20 20:00:22 -05:00
bool shown_assets[game::XAssetType::ASSET_TYPE_COUNT];
2021-12-28 11:14:47 -05:00
std::string asset_type_filter;
2022-01-03 17:32:53 -05:00
std::string assets_name_filter[game::XAssetType::ASSET_TYPE_COUNT];
2021-12-20 20:00:22 -05:00
2021-12-19 19:53:01 -05:00
void on_frame()
{
2022-03-27 13:29:28 -04:00
static auto* enabled = &gui::enabled_menus["asset_list"];
if (!*enabled)
2021-12-19 19:53:01 -05:00
{
return;
}
2022-03-27 13:29:28 -04:00
ImGui::Begin("Asset list", enabled);
2021-12-19 19:53:01 -05:00
2022-03-27 13:29:28 -04:00
ImGui::InputText("asset type", &asset_type_filter);
ImGui::BeginChild("asset type list");
2021-12-22 16:25:41 -05:00
2022-03-27 13:29:28 -04:00
for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++)
{
const auto name = game::g_assetNames[i];
const auto type = static_cast<game::XAssetType>(i);
2021-12-19 19:53:01 -05:00
2022-06-18 14:02:09 -04:00
if (utils::string::strstr_lower(name, asset_type_filter.data()))
2022-03-27 13:29:28 -04:00
{
ImGui::Checkbox(name, &shown_assets[type]);
2021-12-19 19:53:01 -05:00
}
}
2022-03-27 13:29:28 -04:00
ImGui::EndChild();
ImGui::End();
2021-12-19 19:53:01 -05:00
for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++)
{
const auto name = game::g_assetNames[i];
const auto type = static_cast<game::XAssetType>(i);
if (!shown_assets[type])
{
continue;
}
ImGui::SetNextWindowSizeConstraints(ImVec2(500, 500), ImVec2(1000, 1000));
ImGui::Begin(name, &shown_assets[type]);
2022-01-03 17:32:53 -05:00
ImGui::InputText("asset name", &assets_name_filter[type]);
2021-12-22 16:25:41 -05:00
ImGui::BeginChild("assets list");
2021-12-19 19:53:01 -05:00
size_t asset_num{};
fastfiles::enum_assets(type, [type, &asset_num](const game::XAssetHeader header)
2021-12-19 19:53:01 -05:00
{
const auto asset = game::XAsset{type, header};
auto asset_name = game::DB_GetXAssetName(&asset);
if (asset_name[0] == '\0')
{
asset_name = utils::string::va("__%i", asset_num);
}
2021-12-19 19:53:01 -05:00
2022-06-18 14:02:09 -04:00
if (utils::string::strstr_lower(asset_name, assets_name_filter[type].data()) && ImGui::Button(asset_name))
2021-12-19 19:53:01 -05:00
{
2021-12-21 09:21:50 -05:00
gui::copy_to_clipboard(asset_name);
2021-12-19 19:53:01 -05:00
}
asset_num++;
2021-12-19 19:53:01 -05:00
}, true);
2021-12-22 16:25:41 -05:00
ImGui::EndChild();
2021-12-19 19:53:01 -05:00
ImGui::End();
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
gui::on_frame(on_frame);
}
};
}
REGISTER_COMPONENT(asset_list::component)