Refactor asset view stuff
This commit is contained in:
parent
9e17d7fc10
commit
ca4cdc31ff
@ -1,9 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "game/structs.hpp"
|
||||
#include "gui.hpp"
|
||||
|
||||
namespace gui::asset_list
|
||||
{
|
||||
void add_asset_view_callback(game::XAssetType, const std::function<void(const std::string&)>& callback);
|
||||
void add_view_button(int id, game::XAssetType type, const char* name);
|
||||
|
||||
template <typename T>
|
||||
void add_asset_view(game::XAssetType type, const std::function<void(T*)>& draw_callback)
|
||||
{
|
||||
static std::unordered_set<std::string> opened_assets;
|
||||
add_asset_view_callback(type, [](const std::string& name)
|
||||
{
|
||||
opened_assets.insert(name);
|
||||
});
|
||||
|
||||
gui::register_callback([=]()
|
||||
{
|
||||
for (auto i = opened_assets.begin(); i != opened_assets.end(); )
|
||||
{
|
||||
const auto& name = *i;
|
||||
const auto header = reinterpret_cast<T*>(game::DB_FindXAssetHeader(type, name.data(), 0).data);
|
||||
if (header == nullptr)
|
||||
{
|
||||
i = opened_assets.erase(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto is_open = true;
|
||||
if (ImGui::Begin(name.data(), &is_open))
|
||||
{
|
||||
draw_callback(header);
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
if (is_open)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = opened_assets.erase(i);
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,10 @@
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace gui::asset_list::assets::material
|
||||
namespace gui::asset_list::material
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::unordered_set<std::string> opened_assets;
|
||||
|
||||
std::unordered_map<unsigned char, std::string> image_type_names =
|
||||
{
|
||||
{0x0, "2D"},
|
||||
@ -38,11 +36,6 @@ namespace gui::asset_list::assets::material
|
||||
{0xE, "PARALLAX_MAP"},
|
||||
};
|
||||
|
||||
void add_material_view(const std::string& name)
|
||||
{
|
||||
opened_assets.insert(name);
|
||||
}
|
||||
|
||||
std::string get_image_type_name(unsigned char type)
|
||||
{
|
||||
if (!image_type_names.contains(type))
|
||||
@ -53,16 +46,7 @@ namespace gui::asset_list::assets::material
|
||||
return image_type_names[type];
|
||||
}
|
||||
|
||||
bool draw_material_window(const std::string& name)
|
||||
{
|
||||
const auto asset = game::DB_FindXAssetHeader(game::ASSET_TYPE_MATERIAL, name.data(), 0).material;
|
||||
if (asset == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto is_open = true;
|
||||
if (ImGui::Begin(name.data(), &is_open))
|
||||
void draw_material_window(game::Material* asset)
|
||||
{
|
||||
ImGui::SetNextItemOpen(true, ImGuiCond_FirstUseEver);
|
||||
if (ImGui::TreeNode("textures"))
|
||||
@ -116,26 +100,6 @@ namespace gui::asset_list::assets::material
|
||||
DRAW_ASSET_PROPERTY(layerCount, "%i");
|
||||
DRAW_ASSET_PROPERTY(assetFlags, "%X");
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
|
||||
return is_open;
|
||||
}
|
||||
|
||||
void draw_materials()
|
||||
{
|
||||
for (auto i = opened_assets.begin(); i != opened_assets.end(); )
|
||||
{
|
||||
if (!draw_material_window(*i))
|
||||
{
|
||||
i = opened_assets.erase(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -143,10 +107,9 @@ namespace gui::asset_list::assets::material
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
gui::asset_list::add_asset_view_callback(game::ASSET_TYPE_MATERIAL, add_material_view);
|
||||
gui::register_callback(draw_materials, false);
|
||||
gui::asset_list::add_asset_view<game::Material>(game::ASSET_TYPE_MATERIAL, draw_material_window);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(gui::asset_list::assets::material::component)
|
||||
REGISTER_COMPONENT(gui::asset_list::material::component)
|
||||
|
@ -13,17 +13,10 @@
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace gui::asset_list::assets::xmodel
|
||||
namespace gui::asset_list::xmodel
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::unordered_set<std::string> opened_assets;
|
||||
|
||||
void add_xmodel_view(const std::string& name)
|
||||
{
|
||||
opened_assets.insert(name);
|
||||
}
|
||||
|
||||
ImVec2 project_vertex(game::vec3_t v, bool flip_axis, float scale = 1.f,
|
||||
bool rotate = false, float rotation_speed = 0.f)
|
||||
{
|
||||
@ -184,16 +177,7 @@ namespace gui::asset_list::assets::xmodel
|
||||
}
|
||||
}
|
||||
|
||||
bool draw_material_window(const std::string& name)
|
||||
{
|
||||
const auto asset = game::DB_FindXAssetHeader(game::ASSET_TYPE_XMODEL, name.data(), 0).model;
|
||||
if (asset == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto is_open = true;
|
||||
if (ImGui::Begin(name.data(), &is_open))
|
||||
void draw_xmodel_window(game::XModel* asset)
|
||||
{
|
||||
static bool flip_axis = false;
|
||||
ImGui::Checkbox("flip axis", &flip_axis);
|
||||
@ -297,26 +281,6 @@ namespace gui::asset_list::assets::xmodel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
|
||||
return is_open;
|
||||
}
|
||||
|
||||
void draw_xmodels()
|
||||
{
|
||||
for (auto i = opened_assets.begin(); i != opened_assets.end(); )
|
||||
{
|
||||
if (!draw_material_window(*i))
|
||||
{
|
||||
i = opened_assets.erase(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -324,10 +288,9 @@ namespace gui::asset_list::assets::xmodel
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
gui::asset_list::add_asset_view_callback(game::ASSET_TYPE_XMODEL, add_xmodel_view);
|
||||
gui::register_callback(draw_xmodels, false);
|
||||
gui::asset_list::add_asset_view<game::XModel>(game::ASSET_TYPE_XMODEL, draw_xmodel_window);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(gui::asset_list::assets::xmodel::component)
|
||||
REGISTER_COMPONENT(gui::asset_list::xmodel::component)
|
||||
|
Loading…
Reference in New Issue
Block a user