mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
fixes in uicreature rendering
This commit is contained in:
@@ -86,8 +86,8 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.width(), m_size.height(), 0, format, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
// disable texture border
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
setupFilters();
|
||||
|
||||
|
@@ -248,8 +248,10 @@ void OTClient::registerLuaFunctions()
|
||||
|
||||
g_lua.registerClass<UICreature, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UICreature>("create", []{ return UICreaturePtr(new UICreature); } );
|
||||
g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);
|
||||
g_lua.bindClassMemberFunction<UICreature>("setCreature", &UICreature::setCreature);
|
||||
g_lua.bindClassMemberFunction<UICreature>("setFixedCreatureSize", &UICreature::setFixedCreatureSize);
|
||||
g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);
|
||||
g_lua.bindClassMemberFunction<UICreature>("isFixedCreatureSize", &UICreature::isFixedCreatureSize);
|
||||
|
||||
g_lua.registerClass<UIMap, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );
|
||||
|
@@ -28,13 +28,31 @@ void UICreature::draw()
|
||||
{
|
||||
drawSelf();
|
||||
|
||||
//TODO: cache with framebuffer
|
||||
if(m_creature) {
|
||||
g_painter.setColor(Fw::white);
|
||||
|
||||
Rect drawRect = getChildrenRect();
|
||||
float scaleFactor = drawRect.width() / (float)m_creature->getExactSize();
|
||||
m_creature->draw(drawRect.bottomRight() - Point(32, 32) * scaleFactor , scaleFactor, false);
|
||||
|
||||
float scaleFactor = drawRect.width();
|
||||
if(m_fixedCreatureSize)
|
||||
scaleFactor /= Otc::TILE_PIXELS;
|
||||
else
|
||||
scaleFactor /= m_creature->getExactSize();
|
||||
|
||||
Point dest = drawRect.bottomRight() - (Point(1,1)*Otc::TILE_PIXELS - m_creature->getDisplacement()) * scaleFactor;
|
||||
m_creature->draw(dest, scaleFactor, false);
|
||||
}
|
||||
|
||||
drawChildren();
|
||||
}
|
||||
|
||||
void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||
{
|
||||
UIWidget::onStyleApply(styleName, styleNode);
|
||||
|
||||
for(const OTMLNodePtr& node : styleNode->children()) {
|
||||
if(node->tag() == "fixed-creature-size")
|
||||
setFixedCreatureSize(node->value<bool>());
|
||||
}
|
||||
}
|
||||
|
@@ -33,11 +33,16 @@ public:
|
||||
void draw();
|
||||
|
||||
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
||||
void setFixedCreatureSize(bool fixed) { m_fixedCreatureSize = fixed; }
|
||||
|
||||
CreaturePtr getCreature() { return m_creature; }
|
||||
bool isFixedCreatureSize() { return m_fixedCreatureSize; }
|
||||
|
||||
protected:
|
||||
void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
||||
|
||||
CreaturePtr m_creature;
|
||||
Boolean<false> m_fixedCreatureSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user