Files
PuzGame/src/game/Tools.cpp
2025-03-28 04:28:06 +01:00

65 lines
2.0 KiB
C++

#include "Global.h"
#include "Instance.h"
#include "Tools.h"
#include "rendering/Rendering.h"
#include <imgui.h>
namespace Tools
{
const char* GetAssetPath(Generated::AssetHandle assetHandle)
{
const auto& inst = Game::GetInstance();
for (int32_t j = 0; j < inst.DebugData.AssetCount; ++j)
{
if (inst.DebugData.AssetHandles[j] == assetHandle)
{
return inst.DebugData.AssetHandlePaths[j];
}
}
return "---";
}
void ModelDropdown(Generated::ModelHandle& modelHandle)
{
auto& R = Game::GameRendering::Get();
const char* name = GetAssetPath(modelHandle.Asset);
if (ImGui::BeginCombo("Model", name))
{
for (int32_t i = 0; i < R.ModelCount; ++i)
{
if (ImGui::Selectable(GetAssetPath(R.Models[i].Handle.Asset), i == modelHandle.ModelIdx))
{
modelHandle = R.Models[i].Handle;
}
}
ImGui::EndCombo();
}
}
void TextureDropdown(Generated::TextureHandle& texHandle)
{
auto& R = Game::GameRendering::Get();
const char* name = GetAssetPath(texHandle.Asset);
if (ImGui::BeginCombo("Texture", name))
{
for (int32_t i = 0; i < R.MaxTextures; ++i)
{
if (!IsValid(R.Textures[i].TexHandle)) continue;
ImGui::PushID(i);
ImVec2 pos = ImGui::GetCursorScreenPos();
if (ImGui::Selectable("", i == texHandle.TextureIdx, ImGuiSelectableFlags_AllowOverlap, {0, 64}))
{
texHandle = R.Textures[i].TexHandle;
}
ImGui::SetCursorScreenPos(pos);
ImGui::Image(R.Textures[i].RenderHandle.idx, {64, 64});
ImGui::SameLine();
ImGui::Text("%s", GetAssetPath(R.Textures[i].TexHandle.Asset));
ImGui::PopID();
}
ImGui::EndCombo();
}
}
} // namespace Tools