Support more buttonX.png files in other places than just buttons

1008-fix
krzys-h 2018-05-10 11:24:59 +02:00
parent 05bc65a90b
commit 12cf57409c
4 changed files with 20 additions and 38 deletions

View File

@ -1004,22 +1004,9 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::I
// For whatever reason ch.c1 is a SIGNED char, we need to fix that
unsigned char icon = static_cast<unsigned char>(ch.c1);
unsigned int texID;
if ( icon >= 128 )
{
icon -= 128;
texID = m_engine->LoadTexture("textures/interface/button3.png").id;
}
else if ( icon >= 64 )
{
icon -= 64;
texID = m_engine->LoadTexture("textures/interface/button2.png").id;
}
else
{
texID = m_engine->LoadTexture("textures/interface/button1.png").id;
}
// TODO: A bit of code duplication, see CControl::SetButtonTextureForIcon()
unsigned int texID = m_engine->LoadTexture("textures/interface/button" + StrUtils::ToString<int>((icon/64) + 1) + ".png").id;
icon = icon%64;
Math::Point uv1, uv2;
uv1.x = (32.0f / 256.0f) * (icon%8);

View File

@ -519,13 +519,7 @@ void CControl::Draw()
if ( m_state & STATE_DEAD ) return;
icon = m_icon%64;
buttonFile = (m_icon/64) + 1;
if ( buttonFile != 1 )
{
m_engine->SetTexture("textures/interface/button" + StrUtils::ToString<int>(buttonFile) + ".png");
}
icon = SetButtonTextureForIcon(m_icon);
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
if ( icon != -1 )
{
@ -844,5 +838,13 @@ std::string CControl::GetResourceName(EventType eventType)
return name;
}
int CControl::SetButtonTextureForIcon(int icon)
{
int iconIdx = icon%64;
int buttonFile = (icon/64) + 1;
m_engine->SetTexture("textures/interface/button" + StrUtils::ToString<int>(buttonFile) + ".png");
return iconIdx;
}
}

View File

@ -116,6 +116,13 @@ protected:
std::string GetResourceName(EventType eventType);
/**
* \brief Set texture in m_engine to correct buttonX.png for given icon
* \param icon Icon to draw
* \return Index inside the selected texture of the icon to draw
*/
int SetButtonTextureForIcon(int icon);
protected:
Gfx::CEngine* m_engine;
Gfx::CParticle* m_particle;

View File

@ -123,21 +123,7 @@ void CShortcut::Draw()
DrawVertex(icon, 0.95f);
}
icon = m_icon;
if ( icon >= 128 )
{
icon -= 128;
m_engine->SetTexture("textures/interface/button3.png");
}
else if ( icon >= 64 )
{
icon -= 64;
m_engine->SetTexture("textures/interface/button2.png");
}
else
{
m_engine->SetTexture("textures/interface/button1.png");
}
icon = SetButtonTextureForIcon(m_icon);
if (m_icon == 58)
{
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);