Esempio n. 1
0
void Blink1Pattern::play(QColor currentVirtualBlinkColor)
{
    if(mplaying) return;
    mplaycount=0;
    mplaypos=0;
    mplaying=true;
    emit updatePlayIconOnUi();
    t=new QTimer(this);

    count=activeTime()*1000/50;
    currentColor=0;
    startR=currentVirtualBlinkColor.red();
    startG=currentVirtualBlinkColor.green();
    startB=currentVirtualBlinkColor.blue();
    if(count==0){
        deltaR=(activeColor().red()-currentVirtualBlinkColor.red())*1.0;
        deltaG=(activeColor().green()-currentVirtualBlinkColor.green())*1.0;
        deltaB=(activeColor().blue()-currentVirtualBlinkColor.blue())*1.0;
    }else{
        deltaR=(activeColor().red()-currentVirtualBlinkColor.red())*1.0/count;
        deltaG=(activeColor().green()-currentVirtualBlinkColor.green())*1.0/count;
        deltaB=(activeColor().blue()-currentVirtualBlinkColor.blue())*1.0/count;
    }

    t->setInterval(50);
    t->setSingleShot(true);

    connect(t,SIGNAL(timeout()),this,SLOT(update()));
    t->start();

    emit changeColorOnVirtualBlink(QColor(startR,startG,startB),activeTime());
    emit setColor(activeColor(),mname,activeTime()*1000); // convert to millis
}
Esempio n. 2
0
void Blink1Pattern::update()
{
    if(!mplaying) return;
    t->stop();
    delete t;
    t=NULL;

    currentColor++;
    if(currentColor<count){
        startR+=deltaR;
        startG+=deltaG;
        startB+=deltaB;
        t=new QTimer(this);
        t->setInterval(50);
        t->setSingleShot(true);
        connect(t,SIGNAL(timeout()),this,SLOT(update()));
        t->start();
        emit changeColorOnVirtualBlink(QColor(startR,startG,startB),activeTime());
    }else{
        currentColor=0;
        mplaypos++;
        if(mplaypos==colors.count()){
            mplaypos=0;
            mplaycount++;
        }
        count=activeTime()*1000/50;
        currentColor=0;
        startR+=deltaR;
        startG+=deltaG;
        startB+=deltaB;
        if(count==0){
            deltaR=(activeColor().red()-startR)*1.0;
            deltaG=(activeColor().green()-startG)*1.0;
            deltaB=(activeColor().blue()-startB)*1.0;
        }else{
            deltaR=(activeColor().red()-startR)*1.0/count;
            deltaG=(activeColor().green()-startG)*1.0/count;
            deltaB=(activeColor().blue()-startB)*1.0/count;
        }
        t=new QTimer(this);
        t->setInterval(50);
        t->setSingleShot(true);
        connect(t,SIGNAL(timeout()),this,SLOT(update()));
        t->start();
        emit changeColorOnVirtualBlink(QColor(startR,startG,startB),activeTime());

        if(mplaycount==mrepeats+(mrepeats!=-1)?1:0){
            stop();
            return;
        }
        emit setColor(activeColor(),mname,activeTime()*1000); // convert to millis
    }
}
Esempio n. 3
0
void WindowMission::onUpdate( float t )
{
	NodeWindow::onUpdate( t );

	if ( visible() )
	{
		if ( activeTime() > UPDATE_MISSION_WINDOW )
		{

			setActiveTime( 0 );
		}
	}
}
Esempio n. 4
0
void ViewEngineering::ButtonGadget::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() )
	{
		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );
		Font * pFont = windowStyle()->font();
		ASSERT( pFont );

		// display damage percentage
		String status;
		status.format( "%d%%", int( m_rGadget->damageRatioInv() * 100) );

		SizeInt stringSize( pFont->size( status ) );
		PointInt stringPos( window.m_Right - stringSize.width, window.top );
		Font::push( pDisplay, pFont, stringPos, status, YELLOW );

		// display the damage bar
		if ( m_rGadget->damage() > 0 )
		{
			if ( fmod( activeTime(), 1.0f ) < 0.5f )		// make the bar blink
			{
				float damage = m_rGadget->damageRatioInv();
				RectInt bar( window.m_Left, window.m_Bottom + 1, 
					window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );

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

		// display white blinking box around gadget currently at the top of the queue
		NounShip * pShip = WidgetCast<NounShip>( m_rGadget->parentBody() );
		if ( pShip != NULL && pShip->repairCount() > 0 && pShip->repair( 0 ) == m_rGadget && fmod( activeTime(), 1.0f ) < 0.5f )
			renderGlow( context );
	}
}
Esempio n. 5
0
void TextMission::onUpdate( float t )
{
	WindowText::onUpdate( t );

	if ( visible() )
	{
		if ( activeTime() > UPDATE_MISSION_TEXT )
		{
			GameDocument * pDoc = WidgetCast<GameDocument>( document() );
			ASSERT( pDoc );
			NounShip * pShip = pDoc->ship();
			if (! pShip )
				return;

			static char * ORDER_DESC[] =
			{
				"NO ORDER %s",								// NOORDER
				"Engage %s and destroy.",					// ATTACK
				"Defend %s from attack by enemy ships.",	// DEFEND
				"Capture %s.",								// CAPTURE
				"Proceed to %s.",							// MOVE
				"Reload and repair %s.",					// RELOAD
				"Attach beacon to %s.",						// BEACON
				"Hold current position %s.",				// HOLD
				"Trade %s",									// TRADE
				"Recon enemy positions at %s.",				// RECON
				"Build structures on %s.",					// BUILD
				"Fallback and repair at %s."				// FALLBACK
			};

			CharString sText;
			sText.format( ORDER_DESC[ pShip->order() ], pShip->orderTarget() ? pShip->orderTarget()->name() : "" );

			setText( sText );
			setActiveTime( 0 );
		}
	}
}
Esempio n. 6
0
void TextNavigation::onUpdate( float t )
{
	WindowText::onUpdate( t );

	if ( visible() && activeTime() > UPDATE_NAV_TEXT )
	{
		setActiveTime( 0 );

		GameDocument * pDoc = (GameDocument *)document();
		ASSERT( pDoc );

		CharString sText;
		if ( pDoc->isTeamValid() )
		{
			GameContext * pContext = pDoc->context();
			ASSERT( pContext );

			Hash< dword, Array<NounPlanet *> >	factionPlanets;
			Hash< dword, Array<NounShip *> >	factionShips;

			int	nStars = 0;
			int	nAsteroids = 0;
			int	nGates = 0;

			// get the players teamId
			int nFactionId = pDoc->factionId();
			// push all detected objects
			for(int z=0;z<pContext->zoneCount();z++)
			{
				NodeZone * pZone = pContext->zone( z );
				for(int i=0;i<pZone->childCount();i++)
				{
					NounGame * pNoun = WidgetCast<NounGame>( pZone->child(i) );
					if (! pNoun )
						continue;

					if ( pNoun->isDetected( nFactionId ) )
					{
						if ( WidgetCast<NounShip>( pNoun ) )
							factionShips[ pNoun->factionId() ].push( (NounShip *)pNoun );
						else if ( WidgetCast<NounPlanet>( pNoun ) )
							factionPlanets[ pNoun->factionId() ].push( (NounPlanet *)pNoun );
						else if ( WidgetCast<NounStar>( pNoun ) )
							nStars++;
						else if ( WidgetCast<NounAsteroid>( pNoun ) )
							nAsteroids++;
						else if ( WidgetCast<NounJumpGate>( pNoun ) )
							nGates++;
					}
				}
			}

			// update navigation text information
			const GameContext::Team & fleet = pContext->team( pDoc->teamId() );
			sText += CharString().format( "<b;l>%s</b;/l>:\n", fleet.name );

			Array< NounShip * > & ships = factionShips[ fleet.factionId ];

			sText += CharString().format("<x;10>Ships:<x;150>%d\n", ships.size() );
			for(int k=0;k<NounShip::TYPE_COUNT;k++)
			{
				// how many ships of this type
				int count = 0;
				for(int j=0;j<ships.size();j++)
					if ( ships[j]->type() == (NounShip::Type)k )
						count++;

				if ( count > 0 )
					sText += CharString().format( "<X;20>%s:<X;150>%d\n", NounShip::typeText( (NounShip::Type)k ), count );
			}

			if ( factionPlanets.find( fleet.factionId ).valid() )
			{
				Array< NounPlanet *> & planets = factionPlanets[ fleet.factionId ];
				sText += CharString().format("<X;10>Planets:<X;150>%d\n", planets.size() );

				int population = 0;
				int ports = 0;
				int depots = 0;
				int yards = 0;
				int units = 0;

				for(int j=0;j<planets.size();j++)
				{
					NounPlanet * pPlanet = planets[ j ];
					population += pPlanet->population();
					units += pPlanet->friendlyUnitCount();

					if ( pPlanet->flags() & NounPlanet::FLAG_HAS_DEPOT )
						depots++;
					if ( pPlanet->flags() & NounPlanet::FLAG_HAS_PORT )
						ports++;
					if ( pPlanet->flags() & NounPlanet::FLAG_HAS_SHIPYARD )
						yards++;
				}

				if ( population > 0 )
					sText += CharString().format( "<X;20>Population:<X;150>%d\n", population );
				if ( units > 0 )
					sText += CharString().format( "<X;20>Units:<X;150>%d\n", units );
				if ( ports > 0 )
					sText += CharString().format( "<X;20>Ports:<X;150>%d\n", ports );
				if ( depots > 0 )
					sText += CharString().format( "<X;20>Depots:<X;150>%d\n", depots );
				if ( yards > 0 )
					sText += CharString().format( "<X;20>Ship Yards:<X;150>%d\n", yards );
			}
		}

		setText( sText );
	}
}