Skip to content

Commit

Permalink
Show real scriptfile name in asset view
Browse files Browse the repository at this point in the history
  • Loading branch information
alicealys committed Nov 17, 2024
1 parent 6c4aeaa commit c9a8502
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/client/component/gui/asset_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace gui::asset_list
std::string zone_name_filter[game::XAssetType::ASSET_TYPE_COUNT];

std::unordered_map<game::XAssetType, std::function<void(const std::string&)>> asset_view_callbacks;
std::unordered_map<game::XAssetType, std::function<std::string(const std::string&)>> asset_name_override_callbacks;

bool default_only[game::ASSET_TYPE_COUNT] = {};
int asset_count[game::ASSET_TYPE_COUNT] = {};
Expand Down Expand Up @@ -98,9 +99,21 @@ namespace gui::asset_list

ImGui::TableSetColumnIndex(col_index++);

if (ImGui::Button(asset_name))
std::string asset_name_view;

const auto& name_override_cb = asset_name_override_callbacks.find(type);
if (name_override_cb != asset_name_override_callbacks.end())
{
asset_name_view = name_override_cb->second.operator()(asset_name);
}
else
{
gui::copy_to_clipboard(asset_name);
asset_name_view = asset_name;
}

if (ImGui::Button(asset_name_view.data()))
{
gui::copy_to_clipboard(asset_name_view);
}

if (type == game::ASSET_TYPE_LOCALIZE_ENTRY)
Expand Down Expand Up @@ -265,6 +278,11 @@ namespace gui::asset_list
asset_view_callbacks.insert(std::make_pair(type, callback));
}

void add_asset_name_override_callback(game::XAssetType type, const std::function<std::string(const std::string&)>& callback)
{
asset_name_override_callbacks.insert(std::make_pair(type, callback));
}

class component final : public component_interface
{
public:
Expand Down
2 changes: 2 additions & 0 deletions src/client/component/gui/asset_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace gui::asset_list
{
void add_asset_view_callback(game::XAssetType, const std::function<void(const std::string&)>& callback);
void add_asset_name_override_callback(game::XAssetType type, const std::function<std::string(const std::string&)>& callback);

void add_view_button(int id, game::XAssetType type, const char* name);

template <typename T>
Expand Down
48 changes: 48 additions & 0 deletions src/client/component/gui/assets/scriptfile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"

#include "game/game.hpp"
#include "game/dvars.hpp"

#include "component/scheduler.hpp"
#include "component/command.hpp"
#include "component/fastfiles.hpp"
#include "component/gsc/script_loading.hpp"
#include "../gui.hpp"
#include "../asset_list.hpp"

#include "utils/mapents.hpp"

#include <utils/string.hpp>
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
#include <utils/io.hpp>

namespace gui::asset_list::scriptfile
{
namespace
{
std::string get_asset_display_name(const std::string& name)
{
const auto id = static_cast<std::uint32_t>(std::atoi(name.data()));

if (id == 0)
{
return name;
}

return gsc::gsc_ctx->token_name(id);
}
}

class component final : public component_interface
{
public:
void post_unpack() override
{
gui::asset_list::add_asset_name_override_callback(game::ASSET_TYPE_SCRIPTFILE, get_asset_display_name);
}
};
}

REGISTER_COMPONENT(gui::asset_list::scriptfile::component)

0 comments on commit c9a8502

Please sign in to comment.