Add flag, equipment, and quest status editors (#164)
This commit is contained in:
@@ -179,21 +179,46 @@ namespace SohImGui {
|
||||
stbi_image_free(img_data);
|
||||
}
|
||||
|
||||
void LoadResource(const std::string& name, const std::string& path) {
|
||||
void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint) {
|
||||
GfxRenderingAPI* api = gfx_get_current_rendering_api();
|
||||
const auto res = static_cast<Ship::Texture*>(GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(normalize(path)).get());
|
||||
|
||||
if (res->texType != Ship::TextureType::RGBA32bpp) {
|
||||
std::vector<uint8_t> texBuffer;
|
||||
texBuffer.reserve(res->width * res->height * 4);
|
||||
|
||||
switch (res->texType) {
|
||||
case Ship::TextureType::RGBA32bpp:
|
||||
texBuffer.assign(res->imageData, res->imageData + (res->width * res->height * 4));
|
||||
break;
|
||||
case Ship::TextureType::GrayscaleAlpha8bpp:
|
||||
for (int32_t i = 0; i < res->width * res->height; i++) {
|
||||
uint8_t ia = res->imageData[i];
|
||||
uint8_t color = ((ia >> 4) & 0xF) * 255 / 15;
|
||||
uint8_t alpha = (ia & 0xF) * 255 / 15;
|
||||
texBuffer.push_back(color);
|
||||
texBuffer.push_back(color);
|
||||
texBuffer.push_back(color);
|
||||
texBuffer.push_back(alpha);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// TODO convert other image types
|
||||
SPDLOG_WARN("SohImGui::LoadResource: Attempting to load unsupporting image type %s", path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t pixel = 0; pixel < texBuffer.size() / 4; pixel++) {
|
||||
texBuffer[pixel * 4 + 0] *= tint.x;
|
||||
texBuffer[pixel * 4 + 1] *= tint.y;
|
||||
texBuffer[pixel * 4 + 2] *= tint.z;
|
||||
texBuffer[pixel * 4 + 3] *= tint.w;
|
||||
}
|
||||
|
||||
const auto asset = new GameAsset{ api->new_texture() };
|
||||
|
||||
api->select_texture(0, asset->textureId);
|
||||
api->set_sampler_parameters(0, false, 0, 0);
|
||||
api->upload_texture(res->imageData, res->width, res->height);
|
||||
api->upload_texture(texBuffer.data(), res->width, res->height);
|
||||
|
||||
DefaultAssets[name] = asset;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Lib/ImGui/imgui.h"
|
||||
#include "SohConsole.h"
|
||||
|
||||
struct GameAsset {
|
||||
@@ -63,7 +64,7 @@ namespace SohImGui {
|
||||
void ShowCursor(bool hide, Dialogues w);
|
||||
void BindCmd(const std::string& cmd, CommandEntry entry);
|
||||
void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc);
|
||||
void LoadResource(const std::string& name, const std::string& path);
|
||||
void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint = ImVec4(1, 1, 1, 1));
|
||||
ImTextureID GetTextureByID(int id);
|
||||
ImTextureID GetTextureByName(const std::string& name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user