Ejemplo n.º 1
0
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);

    // health rect is based on background rect, so no worries
    Rect healthRect = backgroundRect.expanded(-1);
    healthRect.setWidth((m_healthPercent / 100.0) * 25);

    // draw
    if(g_game.getFeature(Otc::GameBlueNpcNameColor) && isNpc() && m_healthPercent == 100 && !useGray)
        fillColor = Color(0x66, 0xcc, 0xff);

    if(drawFlags & Otc::DrawBars && (!isNpc() || !g_game.getFeature(Otc::GameHideNpcNames))) {
        g_painter->setColor(Color::black);
        g_painter->drawFilledRect(backgroundRect);

        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);
    }
}
Ejemplo n.º 2
0
void Creature::drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags)
{

    Color fillColor = Color(96, 96, 96);

    if(!useGray)
        fillColor = m_informationColor;

		
    // calculate main rects
    Rect backgroundRect = Rect(point.x-(31), point.y-5, 60, 8);

    Size nameSize = m_nameCache.getTextSize();
    Rect textRect = Rect(point.x - nameSize.width() / 2.0, point.y-17, nameSize);

    // distance them
    if(textRect.top() == parentRect.top())
        backgroundRect.moveTop(textRect.top() + 8);
    if(backgroundRect.bottom() == parentRect.bottom())
        textRect.moveTop(backgroundRect.top() - 8);
		
	const std::string& filename = "/images/game/bars/background_bar";
    m_backgroundTexture = g_textures.getTexture(filename);

		
    // health rect is based on background rect, so no worries
	
    Rect healthRect = Rect(point.x-(25), point.y-4, 50, 3);
	healthRect.setWidth((m_healthPercent / 100.0) * 50);
	if(m_healthPercent < 35)
	{
		const std::string& filename2 = "/images/game/bars/health_bar_red";
		m_healthTexture = g_textures.getTexture(filename2);
	}
	else if(m_healthPercent < 70)
	{
		const std::string& filename2 = "/images/game/bars/health_bar_yellow";
		m_healthTexture = g_textures.getTexture(filename2);
	}
	else
	{
		const std::string& filename2 = "/images/game/bars/health_bar";
		m_healthTexture = g_textures.getTexture(filename2);
	}
	
	uint8 m_healthHalfPercent;
	
    // health rect is based on background rect, so no worries
    Rect healthRect2 = Rect(point.x-(25), point.y-1, 24, 3);
	if(m_healthPercent > 50)
		m_healthHalfPercent = 50;
	else
		m_healthHalfPercent = m_healthPercent;
		
	healthRect2.setWidth((m_healthHalfPercent / 50.0) * 24);
	if(m_healthPercent < 35)
	{
		const std::string& filename3 = "/images/game/bars/health_bar2_red";
		m_healthHalfTexture = g_textures.getTexture(filename3);
	}
	else if(m_healthPercent < 70)
	{
		const std::string& filename3 = "/images/game/bars/health_bar2_yellow";
		m_healthHalfTexture = g_textures.getTexture(filename3);
	}
	else
	{
		const std::string& filename3 = "/images/game/bars/health_bar2";
		m_healthHalfTexture = g_textures.getTexture(filename3);
	}
	
	
    Rect barrierRect = Rect(point.x-(25), point.y-1, 24, 3);
	barrierRect.setWidth((m_barrierPercent / 100.0) * 24);
	const std::string& filename4 = "/images/game/bars/barrier_bar";
    m_barrierTexture = g_textures.getTexture(filename4);

    Rect shieldBackgroundRect = Rect(point.x-3, point.y, 28, 3);
	const std::string& filename5 = "/images/game/bars/shieldbackground_bar";
    m_shieldBackgroundTexture = g_textures.getTexture(filename5);

	
    Rect shieldRect = Rect(point.x-1, point.y, 24, 3);
	shieldRect.setWidth((m_shieldPercent / 100.0) * 24);
	const std::string& filename6 = "/images/game/bars/shield_bar";
    m_shieldTexture = g_textures.getTexture(filename6);


    // draw
    if(g_game.getFeature(Otc::GameBlueNpcNameColor) && isNpc() && m_healthPercent == 100 && !useGray)
        fillColor = Color(0x66, 0xcc, 0xff);
		
	if(m_healthPercent > 0) {
		if(drawFlags & Otc::DrawBars && (!isNpc() || !g_game.getFeature(Otc::GameHideNpcNames))) {
			g_painter->setColor(Color::white);
			g_painter->drawTexturedRect(backgroundRect, m_backgroundTexture);
			g_painter->setColor(Color::white);
			g_painter->drawTexturedRect(healthRect, m_healthTexture);
			g_painter->setColor(Color::white);
			g_painter->drawTexturedRect(healthRect2, m_healthHalfTexture);
			if(m_barrierPercent > 0) {
				g_painter->setColor(Color::white);
				g_painter->drawTexturedRect(barrierRect, m_barrierTexture);
			}
			if(m_shieldPercent > 0) {
				g_painter->setColor(Color::white);
				g_painter->drawTexturedRect(shieldBackgroundRect, m_shieldBackgroundTexture);
				g_painter->setColor(Color::white);
				g_painter->drawTexturedRect(shieldRect, m_shieldTexture);
			}
		// old bars
			//g_painter->setColor(Color::black);
			//g_painter->drawFilledRect(backgroundRect);

			//g_painter->setColor(fillColor);
			//g_painter->drawFilledRect(healthRect);
		}


		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() + 20.5 + 24, backgroundRect.y() + 8, m_skullTexture->getSize());
			g_painter->drawTexturedRect(skullRect, m_skullTexture);
		}
		if(m_Pshield != Otc::PshieldNone && m_PshieldTexture && m_showPshieldTexture) {
			g_painter->setColor(Color::white);
			Rect PshieldRect = Rect(backgroundRect.x() + 20.5 + 13 , backgroundRect.y() + 8, m_PshieldTexture->getSize());
			g_painter->drawTexturedRect(PshieldRect, m_PshieldTexture);
		}
		if(m_emblem != Otc::EmblemNone && m_emblemTexture) {
			g_painter->setColor(Color::white);
			Rect emblemRect = Rect(backgroundRect.x() + 20.5 + 24, backgroundRect.y() + 16, m_emblemTexture->getSize());
			g_painter->drawTexturedRect(emblemRect, m_emblemTexture);
		}
		if(m_icon != Otc::NpcIconNone && m_iconTexture) {
			g_painter->setColor(Color::white);
			Rect iconRect = Rect(backgroundRect.x() + 13.5 + 4, backgroundRect.y() + 35, m_iconTexture->getSize());
			g_painter->drawTexturedRect(iconRect, m_iconTexture);
		}
	}
}