Ejemplo n.º 1
0
void MainFrame::OnClose() 
{
	int res = IDNO;
	if (EditorInterface::instance() && EditorInterface::instance()->ThisIsInitialized()
		&& EditorData::instance) {
		res = EditorInterface::instance()->PromptAndSaveIfNecessary();
	}
	if (IDCANCEL != res) {
		if (EditorInterface::instance()) {
			EditorInterface::instance()->SetBusyMode();
		}
		gos_TerminateApplication();
		PostQuitMessage(0);
		if (EditorInterface::instance()) {
			EditorInterface::instance()->UnsetBusyMode();
		}
	}
}
Ejemplo n.º 2
0
void DoGameLogic()
{

	//-------------------------------------
	// Get me the current frameRate.
	// Convert to frameLength and any other timing stuff.
	//if (frameRate < 15.0)
	//	frameRate = 15.0;
	frameLength = 1.0 / frameRate;
	if (frameLength > 0.25f)
		frameLength = 0.25f;

	//-------------------------------------
	// Poll devices for this frame.
	//userInput->update();

	//----------------------------------------
	// Update the Sound System for this frame
	//soundSystem->update();
		
	//-----------------------------------------------------
	// Update Mission and Logistics here.
	if (logistics)
	{
		long result = logistics->update();
		if (result == log_DONE)
		{
			logistics->stop();
		}
	}

	//---------------------------------------------------
	// Update heap instrumentation.
	if (turn > 3)
		globalHeapList->update();

	//---------------------------------------------------------------
	// Somewhere in all of the updates, we have asked to be excused!
	if (quitGame)
	{
		//EnterWindowMode();				//Game crashes if _TerminateApp called from fullScreen
		gos_TerminateApplication();
	}
}
Ejemplo n.º 3
0
//------------------------------------------------------------
void __stdcall DoGameLogic()
{
	//---------------------------------------------------------------
	// Somewhere in all of the updates, we have asked to be excused!
	if(quitGame)
	{
		//EnterWindowMode(); //Game crashes if _TerminateApp called from fullScreen
		gos_TerminateApplication();
	}
	if(frameRate < Stuff::SMALL)
		frameRate = 4.0f;
	frameLength = 1.0 / frameRate;
	if(frameLength > 0.25f)
		frameLength = 0.25f;
	userInput->update();
	soundSystem->update();
	pMechlopedia->update();
	if(LogisticsScreen::RUNNING != pMechlopedia->getStatus())
		quitGame = true;
}
Ejemplo n.º 4
0
void MainMenu::update()
{

	if ( bDrawBackground || MPlayer || LogisticsData::instance->isSingleMission() )
	{
		getButton( MM_MSG_SAVE )->disable( true );
	}
	else
		getButton( MM_MSG_SAVE )->disable( false );

	getButton( MM_MSG_MULTIPLAYER )->disable( true );

	if ( introMovie )
	{
		userInput->mouseOff();

		if (userInput->getKeyDown(KEY_SPACE) || userInput->getKeyDown(KEY_ESCAPE) || userInput->getKeyDown(KEY_LMOUSE))
		{
			introMovie->stop();
		}

		bool result = introMovie->update();
		if (result)
		{
			
			//Movie's Over.
			//Whack it.
			delete introMovie;
			introMovie = NULL;
		}

		return;
	}

	if (!musicStarted)
	{
		musicStarted = true;
		soundSystem->setMusicVolume( prefs.MusicVolume );
		soundSystem->playDigitalMusic(tuneId);
	}

	if ( endAnim.isDone() )
	{
		status = endResult;
	}

	if ( bDrawMechlopedia )
	{
		mechlopedia->update();
		if ( mechlopedia->getStatus() == NEXT )
		{
			beginFadeIn( 0 );
			bDrawMechlopedia = 0;
			if ( !bDrawBackground )
				status = NEXT;
		}
		return;
	}

	if ( bOptions )
	{
		OptionsScreenWrapper::status_type result = optionsScreenWrapper->update();
		if (result == OptionsScreenWrapper::opt_DONE)
		{
			optionsScreenWrapper->end();
			bOptions = 0;
		}

		return;
	}

	if ( (bSave || bLoad || bLoadCampaign) && endAnim.isDone() )
	{
		LogisticsSaveDialog::instance()->update();

		if ( LogisticsSaveDialog::instance()->getStatus() == LogisticsScreen::YES 
			&& LogisticsSaveDialog::instance()->isDone() )
		{
			
			char name[1024];
			strcpy( name, savePath );
			strcat( name, LogisticsSaveDialog::instance()->getFileName() );
			int index = strlen( name ) - 4;
			if ( _stricmp( &name[index], ".fit" ) !=0 ) 
				strcat( name, ".fit" );

			
			FitIniFile file;
			if ( bSave )
			{
				// make sure the save game directory exists, if not create it
				CreateDirectory( savePath, NULL );

				if ( NO_ERR != file.createWithCase( name ) )
				{
					char errorStr[1024];
					sprintf( errorStr, "couldn't open the file %s", name );
					Assert( 0, 0, errorStr );
				}
				else
				{
					LogisticsData::instance->save( file );
					LogisticsSaveDialog::instance()->end();
					file.close();
				}
				bSave = bLoad = 0;
				status = NEXT;
				

			}
			else if ( bLoadCampaign )
			{
				LogisticsData::instance->startNewCampaign( LogisticsSaveDialog::instance()->getFileName());
				status = endResult = RESTART;
//				background.beginFadeOut( 1.0f );
//				beginFadeOut( 1.0f );
				bLoadCampaign = 0;
			}
			else
			{
				if ( NO_ERR != file.open( name ) )
				{
					char errorStr[1024];
					sprintf( errorStr, "couldn't open the file %s", name );
					Assert( 0, 0, errorStr );
				}
				else
					LogisticsData::instance->load( file );
				LogisticsSaveDialog::instance()->end();
				bSave = bLoad = 0;
				status = RESTART;
				file.close();

			}
		}
		else if ( LogisticsSaveDialog::instance()->getStatus() == LogisticsScreen::NO &&
			LogisticsSaveDialog::instance()->isDone())
		{
			LogisticsSaveDialog::instance()->end();
			bSave = bLoad = bLoadCampaign = 0 ;
			if ( !bDrawBackground )
				status = NEXT;
			else
			{
				beginAnim.begin();
				endAnim.end();
			}
		}
		return;
	}
	else if ( bLoadSingle && endAnim.isDone())
	{
		singleLoadDlg.update();
		if ( singleLoadDlg.isDone() )
		{
			if ( singleLoadDlg.getStatus() == YES )
			{
				const char* pName = singleLoadDlg.getMapFileName();
				if (pName)
				{
					LogisticsData::instance->setSingleMission( pName );
					status = SKIPONENEXT;
				}
			}

			bLoadSingle = 0;
			beginAnim.begin();
			endAnim.end();
		}
	}

	else if ( promptToQuit )
	{
		LogisticsOKDialog::instance()->update();
		{
			if ( LogisticsOKDialog::instance()->getStatus() == LogisticsScreen::YES )
			{
				soundSystem->playDigitalSample( LOG_EXITGAME );
				gos_TerminateApplication();
				promptToQuit = 0;

			}
			else if ( LogisticsOKDialog::instance()->getStatus() == LogisticsScreen::NO)
			{
				if ( LogisticsOKDialog::instance()->isDone() )
					promptToQuit = 0;
			}

			

		}
	}
	else if ( bLegal )
	{
		LogisticsLegalDialog::instance()->update();
		if ( LogisticsLegalDialog::instance()->isDone() )
		{
			LogisticsLegalDialog::instance()->end();
			bLegal = 0;
		}
	}
	else if ( bHostLeftDlg )
	{
		LogisticsOneButtonDialog::instance()->update();
		if ( LogisticsOneButtonDialog::instance()->isDone() )
		{
			LogisticsOneButtonDialog::instance()->end();
			bHostLeftDlg = 0;
		}

		if ( MPlayer ) // has to be done, but can't be done when initialized
		{
			MPlayer->closeSession();
			delete MPlayer;
			MPlayer = NULL;
		}
	}
	else if ( promptToDisconnect )
	{
		LogisticsOKDialog::instance()->update();
		if ( LogisticsOKDialog::instance()->isDone() )
		{
			if ( YES == LogisticsOKDialog::instance()->getStatus() )
			{
				if ( MPlayer )
				{
					MPlayer->closeSession();
					delete MPlayer;
					MPlayer = NULL;
				}
				long oldRes = endResult;
				endResult = 0;

				handleMessage( oldRes, oldRes );

				setDrawBackground( true );
			}
			else
				handleMessage( NEXT, NEXT );
			
			promptToDisconnect = 0;
		}
	}
	else
	{
		if ( bDrawBackground  )
		{
			if ( !intro.animObjects[0].isDone() )
			{
				intro.update();
				background.update();
				if (userInput->getKeyDown(KEY_ESCAPE) || (Environment.Renderer == 3))
				{
					introOver = true;
					userInput->mouseOn();
					soundSystem->playDigitalSample( LOG_MAINMENUBUTTON );

				}
				else if ( !introOver )
					return;
			}
			else
			{
				background.update();
				if ( !introOver )
					soundSystem->playDigitalSample( LOG_MAINMENUBUTTON );

				introOver = true;
				userInput->mouseOn();

			}
		}

		beginAnim.update();
		endAnim.update();

		LogisticsScreen::update();
		if ( (!bLoadSingle) && userInput->isLeftClick() && !inside( userInput->getMouseX(), userInput->getMouseY() ) )
		{
			handleMessage( 0, MM_MSG_RETURN_TO_GAME );
		}
	}
}
Ejemplo n.º 5
0
void PauseWindow::update()
{
    if ( bPromptToQuit || bPromptToAbort )
    {
        LogisticsOKDialog::instance()->update();
        if ( LogisticsOKDialog::instance()->getStatus() == LogisticsScreen::YES )
        {
            if ( bPromptToQuit )
                gos_TerminateApplication();
            else {
                //if (MPlayer) {
                //	MPlayer->leaveSession();
                //	}
                //else
                scenarioResult = mis_PLAYER_LOST_BIG;
                aborted = true;
            }

            bPromptToQuit = bPromptToAbort = 0;
        }
        else if ( LogisticsOKDialog::instance()->getStatus() == LogisticsScreen::NO )
        {
            if ( LogisticsOKDialog::instance()->isDone() )
                bPromptToQuit = bPromptToAbort = 0;
        }

    }

    long mouseX = userInput->getMouseX();
    long mouseY = userInput->getMouseY();

    gosEnum_KeyIndex key;
    bool bShift, bCtrl, bAlt;
    MissionInterfaceManager::instance()->getHotKey( OBJECTVIES_COMMAND_KEY, key, bShift, bCtrl, bAlt );


    // hack, mission gui message isn't getting here...
    if ( gos_GetKeyStatus( key ) != KEY_HELD
            && gos_GetKeyStatus( key ) == KEY_PRESSED )
    {
        buttons[OBJECTIVES].toggle(); // big big hack.
    }


    if ( currentTime != 0 )
    {
        currentTime += frameLength;
        float p0 = 0.f;
        float p1 = 0.f;
        float t0 = 0.f;
        float t1 = 0.f;
        // figure out position based on time
        for ( int j = 0; j < 7; j++ )
        {
            if ( moveInfo[j].time <= currentTime && moveInfo[j+1].time > currentTime )
            {
                t0 = moveInfo[j].time;
                t1 = moveInfo[j + 1].time;
                //p0 = -(800.f - moveInfo[j].position)  + ((float)Environment.screenWidth);
                //p1 = -(800.f - moveInfo[j + 1].position) + ((float)Environment.screenWidth);
                //magic 05032012 begin
                p0 = -(850.f - moveInfo[j].position)  + ((float)Environment.screenWidth);
                p1 = -(850.f - moveInfo[j + 1].position) + ((float)Environment.screenWidth);
                //magic 05032012 end
                break;
            }
        }
        if ( p1 )
        {
            float dT = currentTime - t0;
            float currentPosition = p0 + dT * ( (p1 - p0)/(t1 -t0) );
            float delta = currentPosition - currentPos;
            currentPos += delta;

            for ( int i = 0; i < buttonCount; i++ )
            {
                buttons[i].move( delta, 0 );
            }

            for ( i = 0; i < staticCount; i++ )
            {
                statics[i].move( delta, 0 );
            }


            for ( i = 0; i < 2; i++ )
            {
                float dif = backgrounds[i].right - backgrounds[i].left;
                backgrounds[i].left = .5 + currentPos;
                backgrounds[i].right = .5 + currentPos + dif;
            }
        }
    }



    for ( int i = 0; i < buttonCount; i++ )
    {
        if ( buttons[i].location[0].x <= mouseX && mouseX <= buttons[i].location[2].x
                && mouseY >= buttons[i].location[0].y && mouseY <= buttons[i].location[1].y  )
        {
            if ( buttons[i].isEnabled() )
            {
                helpTextHeaderID = buttonData[i].helpTextHeader;
                helpTextID = buttonData[i].helpTextID;

                long lastX = mouseX - userInput->getMouseXDelta();
                long lastY = mouseY - userInput->getMouseYDelta();

                if ( buttons[i].location[0].x >= lastX || lastX >= buttons[i].location[2].x
                        || lastY <= buttons[i].location[0].y || lastY >= buttons[i].location[1].y )
                {
                    soundSystem->playDigitalSample( LOG_HIGHLIGHTBUTTONS );
                }

                if ( buttons[i].state != ControlButton::PRESSED )
                    buttons[i].makeAmbiguous( true );
            }
            else
            {
                helpTextHeaderID = 0;
                helpTextID = 0;
                continue;
            }

            if ( userInput->leftMouseReleased() && !wasDragging )
            {
                {
                    handleClick( buttons[i].ID );
                }
            }
        }
        else if ( buttons[i].isEnabled() && buttons[i].state != ControlButton::PRESSED  )
            buttons[i].makeAmbiguous( 0 );
    }

    if ( currentTime == 0 )
    {
        currentTime = .0001f;
        currentPos = -(800 - PauseWindow::moveInfo[0].position) + ((float)Environment.screenWidth);
        float delta = backgrounds[0].left - currentPos;

        for ( int i = 0; i < buttonCount; i++ )
        {
            for ( int j = 0; j < 4; j++ )
            {
                buttons[i].location[j].x -= delta;
            }
        }

        for ( i = 0; i < staticCount; i++ )
        {
            for ( int j = 0; j < 4; j++ )
            {
                statics[i].location[j].x -= delta;
            }
        }


        for ( i = 0; i < 2; i++ )
        {
            float dif = backgrounds[i].right - backgrounds[i].left;
            backgrounds[i].left = .5 + currentPos;
            backgrounds[i].right = .5 + currentPos + dif;
        }


    }

    wasDragging = userInput->wasLeftDrag();

    const char * campaignName = LogisticsData::instance->getCampaignName().Data();
    char campName[1024];
    _splitpath(campaignName,NULL,NULL,campName,NULL);
    if ( MPlayer ||
            LogisticsData::instance->isSingleMission() ||
            (stricmp("tutorial",campName) == 0))
    {
        buttons[ SAVE ].disable( true );
        buttons[ LOAD ].disable( true );
    }
    if ( MPlayer )
    {
        buttons[OPTIONS].disable( true );
    }

}