creature.cpp Creature::drawInformation void Creature::drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags) { if(m_healthPercent < 1) // creature is dead return; Color fillColor = Color(96, 96, 96); if(!useGray) fillColor = m_informationColor; // calculate main rects Rect backgroundRect = Rect(point.x-(13.5), point.y, 27, 4); backgroundRect.bind(parentRect); Size nameSize = m_nameCache.getTextSize(); Rect textRect = Rect(point.x - nameSize.width() / 2.0, point.y-12, nameSize); textRect.bind(parentRect); // distance them uint32 offset = 12; if(isLocalPlayer()) { offset *= 2; } if(textRect.top() == parentRect.top()) backgroundRect.moveTop(textRect.top() + offset); if(backgroundRect.bottom() == parentRect.bottom()) textRect.moveTop(backgroundRect.top() - offset); //pegando a barra e ajustando o tamanho ( PARTE IMPORTANTE) TexturePtr barTexture = g_game.getBarTerxutre(); Rect healthRect; Rect barTextureRect; bool useBarTexture = false; if (barTexture != nullptr && isPlayer()){ useBarTexture = true; textRect = Rect(point.x - nameSize.width() / 2.0 , point.y-24, nameSize); barTextureRect = Rect(point.x - 69/2, textRect.bottom(), 69, 12); //textRect.setLeft(textRect.left() - 27.5); healthRect = barTextureRect; healthRect.expandLeft(-2); healthRect.expandRight(-2); healthRect.expandTop(-2); healthRect.expandBottom(-5); healthRect.setWidth((m_healthPercent / 100.0) * healthRect.width()); }else{ // health rect is based on background rect, so no worries healthRect = backgroundRect.expanded(-1); healthRect.setWidth((m_healthPercent / 100.0) * 25); } // fim da parte importante if(drawFlags & Otc::DrawBars && (!isNpc() || !g_game.getFeature(Otc::GameHideNpcNames))) { if(!useBarTexture){ g_painter->setColor(Color::black); g_painter->drawFilledRect(backgroundRect); }else{ //desenhando a barrra ( PARTE IMPORTANTE Rect textureRect(0, 0, 69, 12); g_painter->setColor(Color::white); g_painter->drawTexturedRect(barTextureRect, barTexture, textureRect); } g_painter->setColor(fillColor); g_painter->drawFilledRect(healthRect); if(drawFlags & Otc::DrawManaBar && isLocalPlayer()) { LocalPlayerPtr player = g_game.getLocalPlayer(); if(player) { backgroundRect.moveTop(backgroundRect.bottom()); g_painter->setColor(Color::black); g_painter->drawFilledRect(backgroundRect); Rect manaRect = backgroundRect.expanded(-1); double maxMana = player->getMaxMana(); if(maxMana == 0) { manaRect.setWidth(25); } else { manaRect.setWidth(player->getMana() / (maxMana * 1.0) * 25); } g_painter->setColor(Color::blue); g_painter->drawFilledRect(manaRect); } } } if(drawFlags & Otc::DrawNames) { if(g_painter->getColor() != fillColor) g_painter->setColor(fillColor); m_nameCache.draw(textRect); } if(m_skull != Otc::SkullNone && m_skullTexture) { g_painter->setColor(Color::white); Rect skullRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_skullTexture->getSize()); g_painter->drawTexturedRect(skullRect, m_skullTexture); } if(m_shield != Otc::ShieldNone && m_shieldTexture && m_showShieldTexture) { g_painter->setColor(Color::white); Rect shieldRect = Rect(backgroundRect.x() + 13.5, backgroundRect.y() + 5, m_shieldTexture->getSize()); g_painter->drawTexturedRect(shieldRect, m_shieldTexture); } if(m_emblem != Otc::EmblemNone && m_emblemTexture) { g_painter->setColor(Color::white); Rect emblemRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 16, m_emblemTexture->getSize()); g_painter->drawTexturedRect(emblemRect, m_emblemTexture); } if(m_type != Proto::CreatureTypeUnknown && m_typeTexture) { g_painter->setColor(Color::white); Rect typeRect = Rect(backgroundRect.x() + 13.5 + 12 + 12, backgroundRect.y() + 16, m_typeTexture->getSize()); g_painter->drawTexturedRect(typeRect, m_typeTexture); } if(m_icon != Otc::NpcIconNone && m_iconTexture) { g_painter->setColor(Color::white); Rect iconRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_iconTexture->getSize()); g_painter->drawTexturedRect(iconRect, m_iconTexture); } } // game.h e game.cpp private: void setAttackingCreature(const CreaturePtr& creature); void setFollowingCreature(const CreaturePtr& creature); TexturePtr m_barTexture; // (PARTE IMPORTANTE public: bool setHealthBarTexture(const std::string& path); TexturePtr getBarTerxutre() { return m_barTexture;} bool Game::setHealthBarTexture(const std::string& path){ m_barTexture = g_textures.getTexture(path); return m_barTexture == nullptr ? false : true; } //luafunctions.cpp g_lua.bindSingletonFunction("g_game", "setHealthBarTexture", &Game::setHealthBarTexture, &g_game); //otclientrc.lua print 'Startup done :]' print("setHealthBar", g_game.setHealthBarTexture("bar.png"))