Exemplo n.º 1
0
void ButtonBuildStructure::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() && m_Build.valid() )
	{
		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );

		// draw the eta to build this structure
		Font * pFont = windowStyle()->font();
		if ( pFont != NULL )
		{
			WideString eta;
			GameDocument * pDoc = (GameDocument *)document();

			if ( pDoc != NULL )
			{
				NounShip::Ref pShip = pDoc->ship();
				if ( pShip.valid() )
				{
					int buildTime = m_Build->buildTime()* pShip->calculateModifier(MT_BUILD_SPEED,true);
					eta.format( "%d:%2.2d", buildTime / 60, buildTime % 60);

					SizeInt etaSize( pFont->size( eta ) );
					PointInt etaPos( window.right - etaSize.width, window.bottom - etaSize.height );
					Font::push( context.display(), pFont, etaPos, eta, WHITE );
				}
			}
		}
	}
}
Exemplo n.º 2
0
void ButtonUnit::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() && m_Unit.valid() )
	{
		GameDocument * pDoc = (GameDocument *)document();
		ASSERT( pDoc );
		NounShip * pShip = pDoc->ship();
		if (! pShip )
			return;
		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );

		// draw the gadget icon
		if ( m_Icon.valid() )
		{
			RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 32, 16 ) );
			RectFloat iconUV(0,0,1,1);

			Material::push( context, m_Icon );
			PrimitiveWindow::push( pDisplay, iconBox, iconUV, 
				pShip->isFriend( m_Unit ) ? GREEN : pShip->isEnemy( m_Unit ) ? RED : YELLOW );
		}

		// draw the unit health on the button
		Font * pFont = windowStyle()->font();
		ASSERT( pFont );

		WideString sHealth;
		sHealth.format( STR("%d%%"), 100 - ((m_Unit->damage() * 100) / m_Unit->maxDamage()) );

		SizeInt szHealth( pFont->size( sHealth ) );
		PointInt ptHealth( window.right - szHealth.width, window.bottom - szHealth.height );
		Font::push( context.display(), pFont, ptHealth, sHealth, WHITE );

		// display damage bar
		if ( m_Unit->damage() > 0 )
		{
			float damage = 1.0f - (m_Unit->damage() / m_Unit->maxDamage());
			RectInt bar( window.m_Left, window.m_Bottom + 1, 
				window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );
			RectFloat barUV(0,0,1,1);

			Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
			PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
			PrimitiveWindow::push( pDisplay, bar, barUV, barColor );
		}

		// display blinking border if this unit is the current target
		if ( pDoc->target() == m_Unit && (pDoc->tick() % 10) < 6)
			renderGlow( context );
	}
}
Exemplo n.º 3
0
void ButtonCargo::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() )
	{
		Noun * pCargo = m_Cargo;
		ASSERT( pCargo );

		// display white box around cargo if current target
		GameDocument * pDoc = (GameDocument *)document();
		ASSERT( pDoc );

		if ( pDoc->target() == pCargo && (pDoc->tick() % 10) < 6 )
			renderGlow( context );

		if ( WidgetCast<CargoEnhancement>( pCargo ) )
		{
			// show the durability if an enhancement..
			CargoEnhancement * pCargoEnh = (CargoEnhancement *)pCargo;

			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			NounEnhancement * pEnhancement = pCargoEnh->enhancement();
			if ( pEnhancement != NULL )
			{
				int nMaxDamage = pEnhancement->maxDamage();
				if ( nMaxDamage > 0 )
				{
					WideString sQuantity;
					sQuantity.format( "%d/%d", nMaxDamage - pCargoEnh->damage(), nMaxDamage );

					SizeInt stringSize( pFont->size( sQuantity ) );
					PointInt stringPos( window.m_Right - stringSize.width, window.top );
					Font::push( context.display(), pFont, stringPos, sQuantity, WHITE );
				}
			}

			if ( ((CargoEnhancement *)pCargo)->quantity() <= 0 )
				destroy();
		}
		else if ( WidgetCast<NounCargo>( pCargo ) )
		{
			// draw the quantity if cargo
			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			WideString sQuantity;
			sQuantity.format( "%d", ((NounCargo *)pCargo)->quantity() );

			SizeInt stringSize( pFont->size( sQuantity ) );
			PointInt stringPos( window.m_Right - stringSize.width, window.top );
			Font::push( context.display(), pFont, stringPos, sQuantity, WHITE );

			if ( ((NounCargo *)pCargo)->quantity() <= 0 )
				destroy();
		}
		else if ( WidgetCast<NounUnit>( pCargo ) )
		{
			NounUnit * pUnit = (NounUnit *)pCargo;

			// draw the unit health on the button
			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			WideString sHealth;
			sHealth.format( "%d%%", 100 - ((pUnit->damage() * 100) / pUnit->maxDamage()) );

			PointInt ptHealth( window.right - pFont->size( sHealth ).width, window.top );
			Font::push( context.display(), pFont, ptHealth, sHealth, WHITE );

			// display damage bar
			if ( pUnit->damage() > 0 )
			{
				float damage = 1.0f - (pUnit->damage() / pUnit->maxDamage());
				RectInt bar( window.m_Left, window.m_Bottom + 1, 
					window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );
				RectFloat barUV(0,0,1,1);

				Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
				PrimitiveMaterial::push( context.display(), PrimitiveMaterial::NONE );
				PrimitiveWindow::push( context.display(), bar, barUV, barColor );
			}
		}
	}
}