Only draw font icons when material exists
This commit is contained in:
parent
c30bb4f93c
commit
9cb8a02546
@ -96,32 +96,6 @@ namespace Components
|
|||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextRenderer::IsFontIcon(const char*& text, std::string& fontIconName)
|
|
||||||
{
|
|
||||||
const auto* curPos = text;
|
|
||||||
|
|
||||||
while(*curPos != ' ' && *curPos != ':' && *curPos != 0)
|
|
||||||
curPos++;
|
|
||||||
|
|
||||||
if (*curPos != ':')
|
|
||||||
return false;
|
|
||||||
|
|
||||||
fontIconName = std::string(text, static_cast<size_t>(curPos - text));
|
|
||||||
text = curPos + 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Game::GfxImage* TextRenderer::GetFontIconColorMap(Game::Material* fontIconMaterial)
|
|
||||||
{
|
|
||||||
for(auto i = 0u; i < fontIconMaterial->textureCount; i++)
|
|
||||||
{
|
|
||||||
if (fontIconMaterial->textureTable[i].nameHash == COLOR_MAP_HASH)
|
|
||||||
return fontIconMaterial->textureTable[i].u.image;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextRenderer::GlowColor(Game::GfxColor* result, const Game::GfxColor baseColor, const Game::GfxColor forcedGlowColor, int renderFlags)
|
void TextRenderer::GlowColor(Game::GfxColor* result, const Game::GfxColor baseColor, const Game::GfxColor forcedGlowColor, int renderFlags)
|
||||||
{
|
{
|
||||||
if (renderFlags & Game::TEXT_RENDERFLAG_GLOW_FORCE_COLOR)
|
if (renderFlags & Game::TEXT_RENDERFLAG_GLOW_FORCE_COLOR)
|
||||||
@ -149,13 +123,43 @@ namespace Components
|
|||||||
Game::RB_DrawStretchPicRotate(material, x, y, w, h, static_cast<float>(charIndex % 16) * 0.0625f, 0.0f, static_cast<float>(charIndex % 16) * 0.0625f + 0.0625f, 1.0f, sinAngle, cosAngle, color);
|
Game::RB_DrawStretchPicRotate(material, x, y, w, h, static_cast<float>(charIndex % 16) * 0.0625f, 0.0f, static_cast<float>(charIndex % 16) * 0.0625f + 0.0625f, 1.0f, sinAngle, cosAngle, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
float TextRenderer::DrawFontIcon(const std::string& fontIconName, float x, float y, float sinAngle, float cosAngle, const Game::Font_s* font, float xScale, const float yScale, unsigned color)
|
Game::GfxImage* TextRenderer::GetFontIconColorMap(Game::Material* fontIconMaterial)
|
||||||
{
|
{
|
||||||
|
for (auto i = 0u; i < fontIconMaterial->textureCount; i++)
|
||||||
|
{
|
||||||
|
if (fontIconMaterial->textureTable[i].nameHash == COLOR_MAP_HASH)
|
||||||
|
return fontIconMaterial->textureTable[i].u.image;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextRenderer::IsFontIcon(const char*& text, Game::Material*& fontIconMaterial)
|
||||||
|
{
|
||||||
|
const auto* curPos = text;
|
||||||
|
|
||||||
|
while (*curPos != ' ' && *curPos != ':' && *curPos != 0)
|
||||||
|
curPos++;
|
||||||
|
|
||||||
|
if (*curPos != ':')
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const std::string fontIconName(text, curPos - text);
|
||||||
|
|
||||||
auto* material = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, fontIconName.data()).material;
|
auto* material = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, fontIconName.data()).material;
|
||||||
if (material == nullptr || material->techniqueSet == nullptr || material->techniqueSet->name == nullptr || strcmp(material->techniqueSet->name, "2d") != 0)
|
if (material == nullptr || material->techniqueSet == nullptr || material->techniqueSet->name == nullptr || strcmp(material->techniqueSet->name, "2d") != 0)
|
||||||
material = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "default").material;
|
return false;
|
||||||
|
if (Game::DB_IsXAssetDefault(Game::ASSET_TYPE_MATERIAL, material->info.name))
|
||||||
|
return false;
|
||||||
|
|
||||||
const auto* colorMap = GetFontIconColorMap(material);
|
text = curPos + 1;
|
||||||
|
fontIconMaterial = material;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TextRenderer::DrawFontIcon(Game::Material* fontIconMaterial, const float x, const float y, const float sinAngle, const float cosAngle, const Game::Font_s* font, const float xScale, const float yScale, const unsigned color)
|
||||||
|
{
|
||||||
|
const auto* colorMap = GetFontIconColorMap(fontIconMaterial);
|
||||||
if (colorMap == nullptr)
|
if (colorMap == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -163,7 +167,7 @@ namespace Components
|
|||||||
const auto w = static_cast<float>(font->pixelHeight) * (static_cast<float>(colorMap->width) / static_cast<float>(colorMap->height)) * xScale;
|
const auto w = static_cast<float>(font->pixelHeight) * (static_cast<float>(colorMap->width) / static_cast<float>(colorMap->height)) * xScale;
|
||||||
|
|
||||||
const auto yy = y - (h + yScale * static_cast<float>(font->pixelHeight)) * 0.5f;
|
const auto yy = y - (h + yScale * static_cast<float>(font->pixelHeight)) * 0.5f;
|
||||||
Game::RB_DrawStretchPicRotate(material, x, yy, w, h, 0.0, 0.0, 1.0, 1.0, sinAngle, cosAngle, color);
|
Game::RB_DrawStretchPicRotate(fontIconMaterial, x, yy, w, h, 0.0, 0.0, 1.0, 1.0, sinAngle, cosAngle, color);
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
@ -351,11 +355,11 @@ namespace Components
|
|||||||
|
|
||||||
if(letter == ':')
|
if(letter == ':')
|
||||||
{
|
{
|
||||||
std::string fontIconName;
|
Game::Material* fontIconMaterial;
|
||||||
if(IsFontIcon(curText, fontIconName))
|
if(IsFontIcon(curText, fontIconMaterial))
|
||||||
{
|
{
|
||||||
RotateXY(cosAngle, sinAngle, startX, startY, xa, xy, &xRot, &yRot);
|
RotateXY(cosAngle, sinAngle, startX, startY, xa, xy, &xRot, &yRot);
|
||||||
xa += DrawFontIcon(fontIconName, xRot, yRot, sinAngle, cosAngle, font, xScale, yScale, ColorRgba(255, 255, 255, finalColor.array[3]));
|
xa += DrawFontIcon(fontIconMaterial, xRot, yRot, sinAngle, cosAngle, font, xScale, yScale, ColorRgba(255, 255, 255, finalColor.array[3]));
|
||||||
|
|
||||||
if (renderFlags & Game::TEXT_RENDERFLAG_PADDING)
|
if (renderFlags & Game::TEXT_RENDERFLAG_PADDING)
|
||||||
xa += xScale * padding;
|
xa += xScale * padding;
|
||||||
|
@ -76,13 +76,15 @@ namespace Components
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
static unsigned HsvToRgb(HsvColor hsv);
|
static unsigned HsvToRgb(HsvColor hsv);
|
||||||
static float GetMonospaceWidth(Game::Font_s* font, int rendererFlags);
|
|
||||||
static bool IsFontIcon(const char*& text, std::string& fontIconName);
|
|
||||||
static Game::GfxImage* GetFontIconColorMap(Game::Material* fontIconMaterial);
|
static Game::GfxImage* GetFontIconColorMap(Game::Material* fontIconMaterial);
|
||||||
|
static bool IsFontIcon(const char*& text, Game::Material*& fontIconMaterial);
|
||||||
|
static float DrawFontIcon(Game::Material* fontIconMaterial, float x, float y, float sinAngle, float cosAngle, const Game::Font_s* font, float xScale, float yScale, unsigned color);
|
||||||
|
|
||||||
|
static float GetMonospaceWidth(Game::Font_s* font, int rendererFlags);
|
||||||
static void GlowColor(Game::GfxColor* result, Game::GfxColor baseColor, Game::GfxColor forcedGlowColor, int renderFlags);
|
static void GlowColor(Game::GfxColor* result, Game::GfxColor baseColor, Game::GfxColor forcedGlowColor, int renderFlags);
|
||||||
static unsigned R_FontGetRandomLetter(int seed);
|
static unsigned R_FontGetRandomLetter(int seed);
|
||||||
static void DrawTextFxExtraCharacter(Game::Material* material, int charIndex, float x, float y, float w, float h, float sinAngle, float cosAngle, unsigned color);
|
static void DrawTextFxExtraCharacter(Game::Material* material, int charIndex, float x, float y, float w, float h, float sinAngle, float cosAngle, unsigned color);
|
||||||
static float DrawFontIcon(const std::string& fontIconName, float x, float y, float sinAngle, float cosAngle, const Game::Font_s* font, float xScale, float yScale, unsigned color);
|
|
||||||
static float DrawHudIcon(const char*& text, float x, float y, float sinAngle, float cosAngle, const Game::Font_s* font, float xScale, float yScale, unsigned color);
|
static float DrawHudIcon(const char*& text, float x, float y, float sinAngle, float cosAngle, const Game::Font_s* font, float xScale, float yScale, unsigned color);
|
||||||
static void RotateXY(float cosAngle, float sinAngle, float pivotX, float pivotY, float x, float y, float* outX, float* outY);
|
static void RotateXY(float cosAngle, float sinAngle, float pivotX, float pivotY, float x, float y, float* outX, float* outY);
|
||||||
static void UpdateColorTable();
|
static void UpdateColorTable();
|
||||||
|
Loading…
Reference in New Issue
Block a user