예제 #1
0
 void MouseUp()
 {
     EclRemoveWindow( "LOBBY" );        
     EclRemoveWindow( m_parent->m_name );
     
     g_app->ShutdownCurrentGame();
 }
예제 #2
0
void EclRemoveAllWindows()
{
    while( windows.ValidIndex(0) )
    {
        EclRemoveWindow( windows[0]->m_name );
    }
}
예제 #3
0
void UnitPlacementButton::MouseUp()
{
#ifndef NON_PLAYABLE
    if( g_app->GetWorld()->GetTimeScaleFactor() == 0 )
    {
        return;
    }
	if( !m_disabled )
	{
		if( !EclGetWindow( "Placement" ) )
		{
            SidePanel *parent = (SidePanel *)m_parent;
            parent->m_mode = SidePanel::ModeUnitPlacement;
			PlacementIconWindow *icon = new PlacementIconWindow( "Placement", m_unitType );
			EclRegisterWindow( icon, m_parent );

			g_app->GetMapRenderer()->m_showTeam[ g_app->GetWorld()->m_myTeamId ] = true;
            if( m_unitType == WorldObject::TypeRadarStation )
            {
                g_app->GetMapRenderer()->m_showRadar = true;
            }
            InfoWindow *info = (InfoWindow *)EclGetWindow("Info");
            if( info )
            {
                info->SwitchInfoDisplay( m_unitType, -1 );
            }
		}
		else
		{
	        EclRemoveWindow( "Placement" );
		}
	}
#endif
}
void LocationEditor::AdvanceModeLandFlat()
{
	Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d();

	int newSelectionId = -1;
	if ( g_inputManager->controlEvent( ControlTileSelect ) )
	{
		Vector3 mousePos = g_app->m_userInput->GetMousePos3d();
		newSelectionId = IsPosInFlattenArea(mousePos);
	}

	if (m_selectionId == -1)
	{
		// If there isn't currently any selection, then check for a new one
		if (newSelectionId != -1)
		{
			m_selectionId = newSelectionId;
			m_waitingForRelease = true;
			
			EclWindow *cw = EclGetWindow("editor_landscape");
			AppDebugAssert(cw);
			LandscapeFlattenAreaEditWindow *ew = new LandscapeFlattenAreaEditWindow("Flatten Area", newSelectionId);
			ew->m_w = cw->m_w;
			ew->m_h = 100;
			ew->m_x = 0;
			EclRegisterWindow(ew);
			ew->m_y = cw->m_y - ew->m_h - 10;
		}
	}
	else
	{
		Location *location = g_app->m_location;

		if ( g_inputManager->controlEvent( ControlTileSelect ) )
		{
			if (newSelectionId == m_selectionId)
			{
				// The user "grabs" the landscape at this position
				LandscapeDef *landscapeDef = &(g_app->m_location->m_levelFile->m_landscape);
				LandscapeFlattenArea *areaDef = g_app->m_location->m_levelFile->m_landscape.m_flattenAreas.GetData(m_selectionId);
				m_landscapeGrabX = mousePos3D.x - areaDef->m_centre.x;
				m_landscapeGrabZ = mousePos3D.z - areaDef->m_centre.z;
			}
			else
			{
				// The user has deselected the flatten area
				m_selectionId = newSelectionId;
				m_waitingForRelease = true;
				EclRemoveWindow("Flatten Area");
			}
		}
		else if ( g_inputManager->controlEvent( ControlTileDrag ) )
		{
			// The user "drags" the flatten area around
			LandscapeFlattenArea *areaDef = g_app->m_location->m_levelFile->m_landscape.m_flattenAreas.GetData(m_selectionId);
			areaDef->m_centre.x = mousePos3D.x - m_landscapeGrabX;
			areaDef->m_centre.z = mousePos3D.z - m_landscapeGrabZ;
		}
	}
}
	void MouseUp()
	{
		if (stricmp(m_name, LANGUAGEPHRASE("editor_generate")) == 0)
		{
			LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape;
			g_app->m_location->m_landscape.Init(def);
		}
		else if (stricmp(m_name, LANGUAGEPHRASE("editor_randomise")) == 0)
		{
			m_def->m_randomSeed = (int)(GetHighResTime() * 1000.0f);
			InputField *randomSeed = (InputField *)m_parent->GetButton(LANGUAGEPHRASE("editor_seed"));
			if (randomSeed)
			{
				randomSeed->Refresh();
			}
			LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape;
			g_app->m_location->m_landscape.Init(def);
		}
        else if( stricmp(m_name, LANGUAGEPHRASE("editor_delete")) == 0 )
        {
            int tileId = ((LandscapeTileEditWindow *) m_parent)->m_tileId;
            g_app->m_location->m_landscape.DeleteTile( tileId );
            EclRemoveWindow( m_parent->m_name );
        }
        else if( stricmp(m_name, LANGUAGEPHRASE("editor_clone")) == 0 )
        {
            Vector3 rayStart;
	        Vector3 rayDir;
	        g_app->m_camera->GetClickRay(g_app->m_renderer->ScreenW()/2, g_app->m_renderer->ScreenH()/2, &rayStart, &rayDir);
            Vector3 _pos;
            g_app->m_location->m_landscape.RayHit( rayStart, rayDir, &_pos );

            LandscapeDef *landscapeDef = &(g_app->m_location->m_levelFile->m_landscape);
    	    LandscapeTile *tile = new LandscapeTile();
    	    g_app->m_location->m_levelFile->m_landscape.m_tiles.PutDataAtEnd(tile);
            tile->m_size = m_def->m_size;
            tile->m_posX = _pos.x - tile->m_size/2;
            tile->m_posY = m_def->m_posY;
            tile->m_posZ = _pos.z - tile->m_size/2;
            tile->m_fractalDimension = m_def->m_fractalDimension;
            tile->m_heightScale = m_def->m_heightScale;
            tile->m_desiredHeight = m_def->m_desiredHeight;
            tile->m_randomSeed = m_def->m_randomSeed;
            tile->m_lowlandSmoothingFactor = m_def->m_lowlandSmoothingFactor;
            tile->m_generationMethod = m_def->m_generationMethod;

		    LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape;
            g_app->m_location->m_landscape.Init(def);

        }
        else if( stricmp(m_name, LANGUAGEPHRASE("editor_guidegrid")) == 0 )
        {
            int tileId = ((LandscapeTileEditWindow *) m_parent)->m_tileId;
            LandscapeGuideGridWindow *guide = new LandscapeGuideGridWindow(LANGUAGEPHRASE("editor_guidegrid"), tileId );
            guide->SetSize( 300, 300 );
            guide->SetPosition( m_parent->m_x + m_parent->m_w + 10, m_parent->m_y );
            EclRegisterWindow( guide, m_parent );
        }
	}
void EclRemovePopup ()
{
    if( EclGetWindow( popupWindow ) )
    {
        EclRemoveWindow( popupWindow );
    }
    strcpy( popupWindow, "None" );
}
LocationEditor::~LocationEditor()
{
	MainEditWindow *mainWin = (MainEditWindow *)EclGetWindow("editor_mainedit");

	// Remove current tool window
    if( mainWin )
    {
	    if (mainWin->m_currentEditWindow)
	    {
		    EclRemoveWindow(mainWin->m_currentEditWindow->m_name);
		    mainWin->m_currentEditWindow = NULL;
	    }
    }

	// Remove main edit window
	EclRemoveWindow("editor_mainedit");
}
void LocationEditor::AdvanceModeInstantUnit()
{
	Camera *cam = g_app->m_camera;

	int newSelectionId = -1;
	if ( g_inputManager->controlEvent( ControlTileSelect ) ) // TODO: Should be something else?
	{
		Vector3 rayStart, rayDir;
		cam->GetClickRay( g_target->X(), g_target->Y(), &rayStart, &rayDir );
		newSelectionId = DoesRayHitInstantUnit(rayStart, rayDir);
	}

	if (m_selectionId == -1)
	{
		if (newSelectionId != -1)
		{
			m_selectionId = newSelectionId;
			EclWindow *cw = EclGetWindow("editor_instantunits");
			AppDebugAssert(cw);
			InstantUnitEditWindow *ew = new InstantUnitEditWindow("editor_instantuniteditor");
			ew->m_w = cw->m_w;
			ew->m_h = 160;
			ew->m_x = cw->m_x;
			EclRegisterWindow(ew);
			ew->m_y = cw->m_y - ew->m_h - 10;
			m_waitingForRelease = true;
		}
	}
	else 
	{
		if ( g_inputManager->controlEvent( ControlTileSelect ) ) // TODO: Something else?
		{
			if (newSelectionId != m_selectionId)
			{
				m_selectionId = -1;
				EclRemoveWindow("editor_instantuniteditor");
			}
		}
		else if ( g_inputManager->controlEvent( ControlTileDrag ) ) // TODO: Something else?
		{
			InstantUnit *iu = g_app->m_location->m_levelFile->m_instantUnits.GetData(m_selectionId);
			switch (m_tool)
			{
				case ToolMove:
				{
					Vector3 mousePos = g_app->m_userInput->GetMousePos3d();
					iu->m_posX = mousePos.x;
					iu->m_posZ = mousePos.z;
					break;
				}
			}
		}
	}
}
// *** Advance
void UserInput::Advance()
{
    START_PROFILE(g_app->m_profiler, "Advance UserInput");

	g_inputManager->Advance();

	if (m_removeTopLevelMenu)
	{
		EclWindow *win = EclGetWindow(LANGUAGEPHRASE("dialog_toolsmenu"));
		if (win)
		{
			EclRemoveWindow(win->m_name);
		}
		m_removeTopLevelMenu = false;
	}

	AdvanceMenus();

    bool modsEnabled = g_prefsManager->GetInt( "ModSystemEnabled", 0 ) != 0;


    if( g_inputManager->controlEvent( ControlGamePause ) )	g_app->m_clientToServer->RequestPause();

//    if (g_keyDeltas[KEY_F2]) DebugKeyBindings::DebugCameraButton();
#ifdef LOCATION_EDITOR
    if( modsEnabled )
    {
        if ( g_inputManager->controlEvent( ControlToggleEditor ) ) DebugKeyBindings::EditorButton();
    }
#endif
//
#ifdef CHEATMENU_ENABLED
    if( g_inputManager->controlEvent( ControlToggleCheatMenu ) ) DebugKeyBindings::CheatButton();
#endif

//
//    if (g_keyDeltas[KEY_F5]) DebugKeyBindings::FPSButton();
//#ifdef PROFILER_ENABLED
//	if (g_keyDeltas[KEY_F10]) DebugKeyBindings::ProfileButton();
//#endif // PROFILER_ENABLED


#ifdef SOUND_EDITOR
    if( modsEnabled )
    {
//        if (g_keyDeltas[KEY_F7]) DebugKeyBindings::SoundStatsButton();
//        if (g_keyDeltas[KEY_F11]) DebugKeyBindings::SoundEditorButton();
//        if (g_keyDeltas[KEY_F9]) DebugKeyBindings::SoundProfileButton();
    }
#endif // SOUND_EDITOR

    END_PROFILE(g_app->m_profiler, "Advance UserInput");
}
예제 #10
0
    void MouseUp()
    {
        CeaseFireWindow *parent = (CeaseFireWindow *)m_parent;
        int teamId = parent->m_teamId;
        Team *myTeam = g_app->GetWorld()->GetMyTeam();
        Team *thisTeam = g_app->GetWorld()->GetTeam(teamId);

        if( myTeam &&
            thisTeam &&
            myTeam != thisTeam )
        {
            g_app->GetClientToServer()->RequestCeaseFire( myTeam->m_teamId, teamId );
            EclRemoveWindow( m_parent->m_name );
        }
    }
예제 #11
0
void PlayDemoButton::MouseUp()
{
    if( IsVisible() )
    {
        char authKey[256];
        Authentication_GenerateKey( authKey, true );
        Authentication_SetKey( authKey );
        Authentication_SaveKey( authKey, App::GetAuthKeyPath() );
    
        EclRemoveWindow( m_parent->m_name );


        //EclRegisterWindow( new WelcomeToDemoWindow() );
    }
}
 void MouseUp()
 {
     if( m_safetyCatch )
     {
         SetCaption(LANGUAGEPHRASE("editor_deletenow"));
         m_safetyCatch = false;
     }
     else
     {
         g_app->m_location->m_levelFile->RemoveBuilding( g_app->m_locationEditor->m_selectionId );
 	    EclRemoveWindow(LANGUAGEPHRASE("editor_buildingid"));
         g_app->m_locationEditor->m_tool = LocationEditor::ToolNone;
         g_app->m_locationEditor->m_selectionId = -1;
     }
 }
void GameMenu::CreateMenu()
{
    g_app->m_renderer->StartFadeIn(0.25f);
    // close all currently open windows
    LList<EclWindow *> *windows = EclGetWindows();
	while (windows->Size() > 0) {
		EclWindow *w = windows->GetData(0);
		EclRemoveWindow(w->m_name);
	}

    // create the actual menu window
    EclRegisterWindow( new GameMenuWindow() );

    // set the camera to a position with a good view of the internet
    g_app->m_camera->RequestMode(Camera::ModeMainMenu);
    g_app->m_camera->SetDebugMode(Camera::DebugModeNever);
    g_app->m_camera->SetTarget(Vector3(-900000, 3000000, 397000), Vector3(0,0.5f,-1));
    g_app->m_camera->CutToTarget();

    if( g_app->m_tutorial )
    {
        // its possible that the player has loaded the prologue, then returned to the main menu
        // if so, delete the tutorial
        delete g_app->m_tutorial;
        g_app->m_tutorial = NULL;
    }

    if( g_app->m_demoEndSequence )
    {
        delete g_app->m_demoEndSequence;
        g_app->m_demoEndSequence = NULL;
    }

    /*if( g_app->m_multiwinia )
    {
        delete g_app->m_multiwinia;
        g_app->m_multiwinia = NULL;
    }*/

    g_app->m_gameMode = App::GameModeNone;

    m_menuCreated = true;
}
예제 #14
0
void FleetPlacementButton::MouseUp()
{
    if( g_app->GetWorld()->GetTimeScaleFactor() == 0 )
    {
        return;
    }
	if( !m_disabled )
	{
        if( !EclGetWindow( "Placement" ) )
		{
            g_app->GetMapRenderer()->m_showTeam[ g_app->GetWorld()->m_myTeamId ] = true;
            SidePanel *parent = (SidePanel *)m_parent;
			FleetPlacementIconWindow *icon = new FleetPlacementIconWindow( "Placement", parent->m_currentFleetId );
			EclRegisterWindow( icon, m_parent );
		}
		else
		{
	        EclRemoveWindow( "Placement" );
		}
		
	}
}
	void MouseUp()
	{
		g_app->m_location->m_levelFile->m_landscape.m_flattenAreas.RemoveData(m_areaId);
		g_app->m_locationEditor->m_selectionId = -1;
        EclRemoveWindow( m_parent->m_name );
	}
BuildingsCreateWindow::~BuildingsCreateWindow()
{
	g_app->m_locationEditor->RequestMode(LocationEditor::ModeNone);
	EclRemoveWindow(LANGUAGEPHRASE("editor_buildingid"));
}
    void MouseUp()
    {
		EclRemoveWindow(m_parent->m_name);
    }
예제 #18
0
파일: game.cpp 프로젝트: cahocachi/DEFCON
void Game::Update()
{
    //
    // If there is a real-world timer, update it

    if( m_winner == -1 && m_maxGameTime > 0 )
    {
        m_maxGameTime -= SERVER_ADVANCE_PERIOD;
        m_maxGameTime = max( m_maxGameTime, 0 );

        if( !m_gameTimeWarning && 
            m_maxGameTime <= (10 * 60) &&
            g_app->GetGame()->GetOptionValue("MaxGameRealTime") >= 10 )
        {
            g_app->GetInterface()->ShowMessage( 0, 0, -1, LANGUAGEPHRASE("message_ten_minute_warning"), true );
            m_gameTimeWarning = true;

            if( g_app->m_hidden )
            {
                g_app->GetStatusIcon()->SetSubIcon( STATUS_ICON_TIMER );
                g_app->GetStatusIcon()->SetCaption( LANGUAGEPHRASE("tray_icon_ten_minute_warning") );
            }
        }
    }


    // Remove all remaining units and calculate total nukes when Defcon 3 hits

    int defcon = g_app->GetWorld()->GetDefcon();
    if( defcon != m_lastKnownDefcon )
    {
        if( !g_app->GetTutorial() ||
            g_app->GetTutorial()->GetCurrentLevel() == 7 )
        {
            if( defcon == 3 )
            {
                for( int i = 0; i < g_app->GetWorld()->m_teams.Size(); ++i )
                {
                    Team *team = g_app->GetWorld()->m_teams[i];
                    team->m_unitCredits = 0;
                    for( int j = 0; j < WorldObject::NumObjectTypes; ++j )
                    {
                        team->m_unitsAvailable[j] = 0;
                    }
                
                }

                CountNukes();
                for( int i = 0; i < g_app->GetWorld()->m_teams.Size(); ++i )
                {
                    Team *team = g_app->GetWorld()->m_teams[i];
                    m_totalNukes[team->m_teamId] = m_nukeCount[team->m_teamId];
                }

                EclRemoveWindow( "Side Panel" );
                EclRemoveWindow( "Placement" );                
            }
        }
        m_lastKnownDefcon = defcon;
    }


    //
    // Has somebody won?

    if( m_winner == -1 )
    {
        //
        // If the game is counting down...

        if( m_victoryTimer > 0 )
        {
            m_victoryTimer -= SERVER_ADVANCE_PERIOD * g_app->GetWorld()->GetTimeScaleFactor();
            m_victoryTimer = max( m_victoryTimer, 0 );
        }

        m_recalcTimer -= SERVER_ADVANCE_PERIOD;
        if( m_recalcTimer <= 0 )
        {
            m_recalcTimer = 3;

            //
            // Recalculate the scores

            CountNukes();
            CalculateScores();
    
    
            //
            // Look at nukes remaining
            // If there are few enough nukes, start the timer
            if( !m_lockVictoryTimer &&
                 m_victoryTimer < 0 )
            {            
                int totalNukeCount = 0;
                int totalMaxNukeCount = 0;
                int numTeams = g_app->GetWorld()->m_teams.Size();
                for( int t = 0; t < numTeams; ++t )
                {
                    Team *team = g_app->GetWorld()->m_teams[t];
                    totalNukeCount += m_nukeCount[team->m_teamId];
                    totalMaxNukeCount += m_totalNukes[team->m_teamId];
                }

                float averageNukeCount = totalNukeCount / (float) numTeams;
                float averageTotalCount = totalMaxNukeCount / (float) numTeams;
                float victoryNukeCount = averageTotalCount * GetOptionValue("VictoryTrigger") / 100.0f;

                if( averageNukeCount <= victoryNukeCount )
                {
                    m_victoryTimer = GetOptionValue("VictoryTimer");
                    m_victoryTimer *= 60;       //to get it into minutes

                    if( m_victoryTimer > 0 )
                    {
                        g_app->GetInterface()->ShowMessage( 0, 0, -1, LANGUAGEPHRASE("message_victory_timer"), true );
                        g_soundSystem->TriggerEvent( "Interface", "DefconChange" );

                        if( g_app->m_hidden )
                        {
                            g_app->GetStatusIcon()->SetSubIcon( STATUS_ICON_TIMER );
                            g_app->GetStatusIcon()->SetCaption( LANGUAGEPHRASE("tray_icon_victory_timer") );
                        }
                    }
                }
            }

            //
            // If the countdown has finished
            // Declare the winner now!

            if( m_victoryTimer == 0 || m_maxGameTime == 0 )
            {
                CalculateScores();
    
                m_winner = -1;
                int winningScore = 0;
                for( int t = 0; t < g_app->GetWorld()->m_teams.Size(); ++t )
                {
                    Team *team = g_app->GetWorld()->m_teams[t];
                    int score = GetScore(team->m_teamId);
                    g_app->GetClientToServer()->SendTeamScore( team->m_teamId, score );
                    if( score > winningScore )
                    {
                        winningScore = score;
                        m_winner = team->m_teamId;
                    }
                }

                int numPlayers = g_app->GetWorld()->m_teams.Size();

                char msg[128];
                if( m_winner != -1 )
                {
                    strcpy(msg, LANGUAGEPHRASE("message_victory"));
                    LPREPLACESTRINGFLAG( 'T', g_app->GetWorld()->GetTeam(m_winner)->GetTeamName(), msg );
                    
                    if( m_winner == g_app->GetWorld()->m_myTeamId &&
                        numPlayers > 1 )
                    {
                    }
                }
                else
                {
                    strcpy(msg, LANGUAGEPHRASE("message_stalemate"));
                    m_winner = 999;
                }
                strupr(msg);
                g_app->GetInterface()->ShowMessage( 0, 0, m_winner, msg, true );

                g_app->GetMapRenderer()->m_renderEverything = true;
                for( int i = 0; i < g_app->GetWorld()->m_teams.Size(); ++i )
                {
                    g_app->GetWorld()->m_teams[i]->m_desiredGameSpeed = 0;
                }

                if( !EclGetWindow( "Stats" ) )
                {
                    EclRegisterWindow( new StatsWindow()  );
                }

                g_soundSystem->StopAllSounds( SoundObjectId(), "StartMusic StartMusic" );
                g_soundSystem->TriggerEvent( "Interface", "GameOver" );

                int specVisible = g_app->GetGame()->GetOptionValue("SpectatorChatChannel");
                if( specVisible == 0 &&
                    g_app->GetWorld()->m_spectators.Size() )
                {
                    g_app->GetWorld()->AddChatMessage( -1, CHATCHANNEL_PUBLIC, LANGUAGEPHRASE("message_spectators_chat_players"), -1, false );
                }
            }
        }
    }
}
void LocationEditor::AdvanceModeBuilding()
{
	BuildingEditWindow *ew = (BuildingEditWindow *)EclGetWindow("editor_buildingid");
	if (ew && EclMouseInWindow(ew))	return;
	
	Camera *cam = g_app->m_camera;

	// Find the ID of the building the user is clicking on
	int newSelectionId = -1;
	if ( g_inputManager->controlEvent( ControlTileSelect ) )
	{
		Vector3 rayStart, rayDir;
		cam->GetClickRay( g_target->X(), g_target->Y(), &rayStart, &rayDir );
		newSelectionId = DoesRayHitBuilding(rayStart, rayDir);
	}

	if (m_selectionId == -1)
	{
		// If there isn't currently any selection, then check for a new one
		if (newSelectionId != -1)
		{
			m_selectionId = newSelectionId;
			BuildingsCreateWindow *cw = (BuildingsCreateWindow*)EclGetWindow("editor_buildings");
			AppDebugAssert(!ew);
			AppDebugAssert(cw);
			BuildingEditWindow *bew = new BuildingEditWindow("editor_buildingid");
			bew->m_w = cw->m_w;
			bew->m_h = 140;
			bew->m_x = cw->m_x;
			EclRegisterWindow(bew);
			bew->m_y = cw->m_y - bew->m_h - 10;
			m_waitingForRelease = true;

            Location *location = g_app->m_location;
		    Building *building = location->GetBuilding(m_selectionId);            
            if( building->m_type == Building::TypeTree )
            {
                TreeWindow *tw = new TreeWindow( "editor_treeditor" );
                tw->m_w = cw->m_w;
                tw->m_h = 230;
                tw->m_y = bew->m_y - tw->m_h - 10;
                tw->m_x = bew->m_x;
                EclRegisterWindow( tw );
            }
		}
	}
	else 
	{
		Location *location = g_app->m_location;
		Building *building = location->GetBuilding(m_selectionId);
	
		
		if ( g_inputManager->controlEvent( ControlTileSelect ) )                  // If left mouse is clicked then consider creating a new link
		{
			if (newSelectionId == -1)
			{
				EclRemoveWindow("editor_buildingid");
				m_selectionId = -1;
			}
			else if (m_tool == ToolLink)
			{
				building->SetBuildingLink(newSelectionId);
				m_tool = ToolNone;
			}
		}		
		else if ( g_inputManager->controlEvent( ControlTileDrag ) && newSelectionId == -1 )  // Otherwise consider rotation and movement
		{
			switch (m_tool)
			{
				case ToolMove:
				{
					Vector3 mousePos = g_app->m_userInput->GetMousePos3d();
					building->m_pos = mousePos;
					break;
				}
				case ToolRotate:
				{
					Vector3 front = building->m_front;
					front.RotateAroundY((float)g_target->dX() * 0.01);
					building->m_front = front;
					break;
				}
			}
		}
	}
}
예제 #20
0
파일: defcon.cpp 프로젝트: cahocachi/DEFCON
bool ProcessServerLetters( Directory *letter )
{
    if( strcmp( letter->m_name, NET_DEFCON_MESSAGE ) != 0 ||
        !letter->HasData( NET_DEFCON_COMMAND ) )
    { 
        AppDebugOut( "Client received bogus message, discarded (4)\n" );
        return true;
    }


    char *cmd = letter->GetDataString( NET_DEFCON_COMMAND );


    if( strcmp( cmd, NET_DEFCON_CLIENTHELLO ) == 0 )
    {
        int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID);
        if( clientId == g_app->GetClientToServer()->m_clientId )
        {
            g_app->GetClientToServer()->m_connectionState = ClientToServer::StateConnected;
            AppDebugOut( "CLIENT : Received HelloClient from Server\n" );
            if( !g_app->GetTutorial() )
            {
                g_app->GetClientToServer()->RequestTeam( Team::TypeLocalPlayer );
            }
        }

        // If this is a Demo client, make a note of that
        if( letter->HasData( NET_DEFCON_CLIENTISDEMO ) )
        {
            g_app->GetClientToServer()->SetClientDemo( clientId );
        }

        // This might be a client rejoining the game
        // Need to give him his teams back
        g_app->GetWorld()->ReassignTeams( clientId );        

        return true;
    }
    else if( strcmp( cmd, NET_DEFCON_CLIENTGOODBYE ) == 0 )
    {
        int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID);
        int reason = letter->GetDataInt(NET_DEFCON_DISCONNECT);

        AppDebugOut( "CLIENT : Client %d left the game\n", clientId );
        g_app->GetWorld()->RemoveTeams( clientId, reason );
        g_app->GetWorld()->RemoveSpectator( clientId );
        g_app->GetClientToServer()->SetSyncState( clientId, true );
        return true;
    }
    else if( strcmp( cmd, NET_DEFCON_CLIENTID ) == 0 )
    {
        int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID);        
        AppDebugOut( "CLIENT : Received ClientID of %d\n", clientId );        

        if( g_app->GetClientToServer()->m_clientId != -1 )
        {
            AppAssert( g_app->GetClientToServer()->m_clientId == clientId );
            return true;
        }

        g_app->GetClientToServer()->m_clientId = clientId;
        g_app->GetClientToServer()->m_connectionState = ClientToServer::StateHandshaking;
        g_lastProcessedSequenceId = -1;

        if( letter->HasData( NET_DEFCON_VERSION, DIRECTORY_TYPE_STRING ) )
        {
            char *serverVersion = letter->GetDataString( NET_DEFCON_VERSION );
            strcpy( g_app->GetClientToServer()->m_serverVersion, serverVersion );
            AppDebugOut( "CLIENT : Server version is %s\n", serverVersion );
        }

        if( !VersionManager::DoesSupportModSystem( g_app->GetClientToServer()->m_serverVersion ) )
        {
            // This server is too old to support Mods, so make sure we de-activate any critical ones
            g_modSystem->DeActivateAllCriticalMods();
            if( g_modSystem->CommitRequired() )
            {
                g_modSystem->Commit();
				g_app->RestartAmbienceMusic();
            }
        }

        return true;
    }
    else if( strcmp( cmd, NET_DEFCON_TEAMASSIGN ) == 0 )
    {
        int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID);        
        int teamId   = letter->GetDataInt(NET_DEFCON_TEAMID);
        int teamType = letter->GetDataInt(NET_DEFCON_TEAMTYPE);

        if( teamType != Team::TypeAI &&
            clientId != g_app->GetClientToServer()->m_clientId )
        {
            teamType = Team::TypeRemotePlayer;
        }

        g_app->GetWorld()->InitialiseTeam(teamId, teamType, clientId );
        return true;
    }
    else if( strcmp( cmd, NET_DEFCON_SPECTATORASSIGN ) == 0 )
    {
        int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID);        
        g_app->GetWorld()->InitialiseSpectator(clientId);

        if( clientId == g_app->GetClientToServer()->m_clientId )
        {            
            AppDebugOut( "CLIENT: I am a spectator\n" );
        }
				
        return true;
    }
    else if( strcmp( cmd, NET_DEFCON_NETSYNCERROR ) == 0 )
    {
        int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID);        
        AppDebugOut( "SYNCERROR Server informed us that Client %d is out of Sync\n", clientId );

        g_app->GetClientToServer()->SetSyncState( clientId, false );

        char *syncId = letter->GetDataString( NET_DEFCON_SYNCERRORID );
        DumpSyncLogs(syncId);

        return true;
    }
    else if( strcmp( cmd, NET_DEFCON_NETSYNCFIXED ) == 0 )
    {
        int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID);        
        AppDebugOut( "SYNCFIXED Server informed us that Client %d has repaired his Sync Error\n", clientId );
        g_app->GetClientToServer()->SetSyncState( clientId, true );
        return true;
    }
    else if( strcmp( cmd, NET_DEFCON_DISCONNECT ) == 0 )
    {
        if( g_app->GetClientToServer()->m_connectionState > ClientToServer::StateDisconnected )
        {
            g_app->ShutdownCurrentGame();
            if ( EclGetWindow("LOBBY") )
				EclRemoveWindow( "LOBBY" );
			if ( EclGetWindow("Comms Window") )
				EclRemoveWindow( "Comms Window" );
			if ( EclGetWindow("Preparing Game...") )
				EclRemoveWindow("Preparing Game..." );

            g_app->GetInterface()->OpenSetupWindows();

            char *reason;
			char *reasonLanguagePhrase;
            int reasonDisconnectInt = letter->GetDataInt(NET_DEFCON_DISCONNECT);
            switch( reasonDisconnectInt )
            {
                case Disconnect_ClientLeave:            reason = "You have left the game";
					                                    reasonLanguagePhrase = "dialog_disconnect_client_leave";         break;
                case Disconnect_ServerShutdown:         reason = "The server has shutdown";
					                                    reasonLanguagePhrase = "dialog_disconnect_server_shutdown";      break;
                case Disconnect_InvalidKey:             reason = "You are using an invalid key";
					                                    reasonLanguagePhrase = "dialog_disconnect_invalid_key";          break;
                case Disconnect_DuplicateKey:           reason = "You are using a duplicate key";
					                                    reasonLanguagePhrase = "dialog_disconnect_duplicate_key";        break;
                case Disconnect_KeyAuthFailed:          reason = "Key authentication failed";
					                                    reasonLanguagePhrase = "dialog_disconnect_key_auth_failed";      break;
                case Disconnect_BadPassword:            reason = "Invalid Password Entered";
					                                    reasonLanguagePhrase = "dialog_disconnect_bad_password";         break;
                case Disconnect_GameFull:               reason = "Game is already full";
					                                    reasonLanguagePhrase = "dialog_disconnect_game_full";            break;
                case Disconnect_KickedFromGame:         reason = "Kicked by the Server";
					                                    reasonLanguagePhrase = "dialog_disconnect_kicked_from_game";     break;
                case Disconnect_DemoFull:               reason = "Too many Demo Players already";
					                                    reasonLanguagePhrase = "dialog_disconnect_demo_full";            break;
				default:                                reason = "Unknown";
					                                    reasonLanguagePhrase = "dialog_disconnect_unknown";              break;
            }

            if( reasonDisconnectInt == Disconnect_KeyAuthFailed ||
                reasonDisconnectInt == Disconnect_InvalidKey ||
                reasonDisconnectInt == Disconnect_DuplicateKey )
            {
                char authKey[256];
				if( Authentication_IsKeyFound() )
				{
					Authentication_GetKey( authKey );
				}
				else
				{
					sprintf( authKey, LANGUAGEPHRASE("dialog_authkey_not_found") );
				}

                BadKeyWindow *badKey = new BadKeyWindow();

				sprintf( badKey->m_extraMessage, LANGUAGEPHRASE("dialog_auth_error") );
				LPREPLACESTRINGFLAG( 'E', LANGUAGEPHRASE(reasonLanguagePhrase), badKey->m_extraMessage );
				LPREPLACESTRINGFLAG( 'K', authKey, badKey->m_extraMessage );

				EclRegisterWindow(badKey);
            }
            else if( reasonDisconnectInt == Disconnect_DemoFull )
            {
                int maxGameSize;
                int maxDemoPlayers;
                bool allowDemoServers;
                g_app->GetClientToServer()->GetDemoLimitations( maxGameSize, maxDemoPlayers, allowDemoServers );
                BadKeyWindow *badKey = new BadKeyWindow();

                sprintf( badKey->m_extraMessage, LANGUAGEPHRASE("dialog_server_demo_restricted") );
                LPREPLACEINTEGERFLAG( 'N', maxDemoPlayers, badKey->m_extraMessage );

                badKey->m_offerDemo = false;
                EclRegisterWindow(badKey);                
            }
            else
            {
                MessageDialog *dialog = new MessageDialog( "Disconnected", reasonLanguagePhrase, true, "dialog_disconnected", true );
                EclRegisterWindow( dialog );
            }

            AppDebugOut( "CLIENT : Received Disconnect from server : %s\n", reason );

#ifdef TESTBED
            if( letter->GetDataInt(NET_DEFCON_DISCONNECT) == Disconnect_ServerShutdown )
            {
                RestartTestBed(1, "Client Disconnect");
            }
#endif

        }
        return true;            
    }
    else if( strcmp( cmd, NET_DEFCON_SETMODPATH ) == 0 )
    {
        char *modPath = letter->GetDataString( NET_DEFCON_SETMODPATH );
        AppDebugOut( "Server has set the MOD path: '%s'\n", modPath );
        
        if( !g_modSystem->IsCriticalModPathSet( modPath ) )
        {
            if( g_modSystem->CanSetModPath( modPath ) )
            {
                g_modSystem->DeActivateAllCriticalMods();
                g_modSystem->SetModPath( modPath );
            }
            else
            {
                char reason[8192];
                sprintf( reason, LANGUAGEPHRASE("dialog_error_mod_path_caption") );

                char modPathCopy[4096];
                strcpy( modPathCopy, modPath );
                LList<char *> *tokens = g_modSystem->ParseModPath( modPathCopy );

                for( int i = 0; i < tokens->Size(); i+=2 )
                {
                    char *modName = tokens->GetData(i);
                    char *version = tokens->GetData(i+1);

                    strcat( reason, modName );
                    strcat( reason, " " );
                    strcat( reason, version );

                    if( !g_modSystem->IsModInstalled( modName, version ) )
                    {
                        strcat( reason, "    " );
                        strcat( reason, LANGUAGEPHRASE("dialog_mod_not_installed") );
                    }
                    
                    strcat( reason, "\n" );
                }

                delete tokens;
                
                MessageDialog *dialog = new MessageDialog( "Error setting MOD path", reason, false, "dialog_error_mod_path_title", true );
                EclRegisterWindow( dialog );
            }
        }

        return true;
    }
    else
    {
        return false;
    }
}
void LocationEditor::AdvanceModeLandTile()
{
	Vector3 mousePos3D = g_app->m_userInput->GetMousePos3d();

	int newSelectionId = -1;
	if ( g_inputManager->controlEvent( ControlTileSelect ) )
	{
		newSelectionId = IsPosInLandTile(mousePos3D);
	}

	if (m_selectionId == -1)
	{
		// No selection

		Landscape *land = &g_app->m_location->m_landscape;
		LList<LandscapeTile *> *tiles = &g_app->m_location->m_levelFile->m_landscape.m_tiles;
		
		// Has the user selected a tile
		if (newSelectionId != -1) 
		{
			LandscapeTile *tile = tiles->GetData(newSelectionId);
			m_tool = ToolMove;
			m_selectionId = newSelectionId;
			m_newLandscapeX = tile->m_posX;
			m_newLandscapeZ = tile->m_posZ;
			m_waitingForRelease = true;

			EclWindow *cw = EclGetWindow("editor_landscape");
			AppDebugAssert(cw);
			LandscapeTileEditWindow *ew = new LandscapeTileEditWindow("editor_landscapetile", newSelectionId);
			ew->m_w = cw->m_w;
			ew->m_h = 150;
			ew->m_x = cw->m_x;
			EclRegisterWindow(ew);
			ew->m_y = cw->m_y - ew->m_h - 10;
		}
	}
	
	if (m_selectionId != -1)
	{
		// There is a current selection

		if( g_inputManager->controlEvent( ControlTileDrop ) )
		{
			// Move the selected landscape to the new position and regenerate it
			LandscapeTile *tileDef = g_app->m_location->m_levelFile->m_landscape.m_tiles.GetData(m_selectionId);
			if( m_newLandscapeX != tileDef->m_posX ||
				m_newLandscapeZ != tileDef->m_posZ )
			{
                if( m_moveBuildingsWithLandscape )
                {
                    MoveBuildingsInTile( tileDef, m_newLandscapeX - tileDef->m_posX, m_newLandscapeZ - tileDef->m_posZ );
                }

				tileDef->m_posX = m_newLandscapeX;
				tileDef->m_posZ = m_newLandscapeZ;
				LandscapeDef *def = &g_app->m_location->m_levelFile->m_landscape;
				g_app->m_location->m_landscape.Init(def);
                delete g_app->m_location->m_water;
                g_app->m_location->m_water = new Water();
			}
		}
		if( g_inputManager->controlEvent( ControlTileSelect ) ) // TODO: Should this be ControlTileGrab?
		{
			if (newSelectionId == m_selectionId)
			{
				// The user "grabs" the landscape at this position
				LandscapeDef *landscapeDef = &(g_app->m_location->m_levelFile->m_landscape);
				LandscapeTile *tileDef = g_app->m_location->m_levelFile->m_landscape.m_tiles.GetData(m_selectionId);
				m_landscapeGrabX = mousePos3D.x - tileDef->m_posX;
				m_landscapeGrabZ = mousePos3D.z - tileDef->m_posZ;
			}
			else
			{
				// The user has deselected the landscape
				m_tool = ToolNone;
				m_selectionId = -1;
				m_waitingForRelease = true;
				EclRemoveWindow("editor_landscapetile");
                EclRemoveWindow("editor_guidegrid");
			}
		}
		else if ( g_inputManager->controlEvent( ControlTileDrag ) )
		{
			// The user "drags" the landscape around
			m_newLandscapeX = mousePos3D.x - m_landscapeGrabX;
			m_newLandscapeZ = mousePos3D.z - m_landscapeGrabZ;        
		}
	}
}
void LocationEditor::CreateEditWindowForMode(int _mode)
{
	MainEditWindow *mainWin = (MainEditWindow *)EclGetWindow("editor_mainedit");

	// Remove existing window
	if (mainWin->m_currentEditWindow)
	{
		EclRemoveWindow(mainWin->m_currentEditWindow->m_name);
		mainWin->m_currentEditWindow = NULL;
	}

	DarwiniaWindow *window = NULL;
	switch(_mode)
	{
		case LocationEditor::ModeLandTile:
			window = new LandscapeEditWindow("editor_landscape");
			window->m_w = 220;
			break;
		case LocationEditor::ModeLandFlat:
			window = new LandscapeEditWindow("editor_landscape");
			window->m_w = 220;
			break;
		case LocationEditor::ModeLight:
			window = new LightsEditWindow("editor_lights");
			window->m_w = 220;
			break;
		case LocationEditor::ModeBuilding:
			window = new BuildingsCreateWindow("editor_buildings");
			window->m_w = 220;
			break;
		case LocationEditor::ModeInstantUnit:
			window = new InstantUnitCreateWindow("editor_instantunits");
			window->m_w = 220;
			break;
		case LocationEditor::ModeCameraMount:
			{
				window = new CameraMountEditWindow("editor_cameramounts");
				window->m_w = 320;
//				DarwiniaWindow *otherWin = new CameraAnimMainEditWindow(LANGUAGEPHRASE("editor_cameraanims"));
//				otherWin->m_w = 270;
//				otherWin->m_h = 100;
//				otherWin->m_x = 340;
//				otherWin->m_y = g_app->m_renderer->ScreenH() - window->m_h;
//				EclRegisterWindow(otherWin);
			}
			break;
        case LocationEditor::ModeMultiwinia:
            window = new MultiwiniaOptionsWindow();
            window->m_w = 300;
            break;

        case LocationEditor::ModeInvalidCrates:
            window = new InvalidCratesWindow();
            window->m_w = 300;
            break;

	}

	window->m_h = 100;
	window->m_x = 0;
	window->m_y = g_app->m_renderer->ScreenH() - window->m_h;
	EclRegisterWindow(window);
	
	mainWin->m_currentEditWindow = window;
}
void GameMenu::DestroyMenu()
{
    m_menuCreated = false;
    EclRemoveWindow("GameMenu");
    g_app->m_renderer->StartFadeOut();
}
void CloseButton::MouseUp()
{
    EclRemoveWindow( m_parent->m_name );
}
예제 #25
0
void ConnectingWindow::Render( bool _hasFocus )
{
    InterfaceWindow::Render( _hasFocus );


    float yPos = m_y + 40;


    //
    // Render our connection state

    g_renderer->SetFont( "kremlin" );


    float fraction = 0.0f;
    char *caption = NULL;
    Colour col;

    switch( g_app->GetClientToServer()->m_connectionState )
    {
        case ClientToServer::StateDisconnected:     
            col.Set(255,0,0,255);
            caption = LANGUAGEPHRASE("dialog_state_disconnected");
            fraction = 0.0f;
            break;

        case ClientToServer::StateConnecting:
            col.Set(255,255,0,255);
            caption = LANGUAGEPHRASE("dialog_state_connecting");
            fraction = 0.5f;
            break;

        case ClientToServer::StateHandshaking:
        case ClientToServer::StateConnected:
            col.Set(0,255,0,255);
            caption = LANGUAGEPHRASE("dialog_state_connected");
            fraction = 1.0f;
            break;
    }

    g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption );

    yPos += 20;

    if( fraction > 0.0f )
    {
        g_renderer->RectFill( m_x + 30, yPos, (m_w-60)*fraction, 20, col );
        g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White );

        int numConnectionAttempts = g_app->GetClientToServer()->m_connectionAttempts;
        if( fraction < 1.0f && numConnectionAttempts > 0 )
        {
			char caption[512];
			sprintf( caption, LANGUAGEPHRASE("dialog_state_attempts") );
			LPREPLACEINTEGERFLAG( 'A', numConnectionAttempts, caption );
            g_renderer->TextCentreSimple( m_x + m_w/2, m_y + m_h - 60, White, 14, caption );
        }
    }


    //
    // Render our sync status (ie receiving all data from the server)

    yPos += 40;

    if( g_app->GetClientToServer()->IsConnected() )
    {
        if( m_stage == 0 )
        {
            m_stage = 1;
            m_stageStartTime = GetHighResTime();
        }

        int serverSeqId = g_app->GetClientToServer()->m_serverSequenceId;
        int latestSeqId = g_app->GetClientToServer()->m_lastValidSequenceIdFromServer;
        int numRemaining = serverSeqId-latestSeqId;
        numRemaining--;

        if( numRemaining > m_maxUpdatesRemaining )
        {
            m_maxUpdatesRemaining = numRemaining;
        }

        if( m_maxUpdatesRemaining > 0 )
        {
            fraction = numRemaining / (float) m_maxUpdatesRemaining;
        }
        else
        {
            fraction = 0.0f;
        }

        Clamp( fraction, 0.0f, 1.0f );
        fraction = 1.0f - fraction;
        
        col.Set( (1-fraction)*255, fraction*255, 0, 255 );

        const char *caption = numRemaining > 5 ? LANGUAGEPHRASE("dialog_state_receiving") : LANGUAGEPHRASE("dialog_state_received");
        g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption );

        yPos += 20;
    
        g_renderer->RectFill( m_x+30, yPos, (m_w-60)*fraction, 20, col );
        g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White );

        if( m_stage == 1 )
        {
            RenderTimeRemaining(fraction);
        }

        //
        // Render how much of the received data we have successfully parsed

        int lagRemaining = 0;
        if( g_lastProcessedSequenceId > 0 && numRemaining < 10 )
        {
            if( m_stage != 2 )
            {
                m_stage = 2;
                m_stageStartTime = GetHighResTime();
            }

            yPos += 40;
        
            int serverSeqId = g_app->GetClientToServer()->m_serverSequenceId;
            lagRemaining = serverSeqId - g_lastProcessedSequenceId;
            lagRemaining --;
        
            if( lagRemaining > m_maxLagRemaining )
            {
                m_maxLagRemaining = lagRemaining;
            }

            fraction = lagRemaining / (float) m_maxLagRemaining;
            Clamp( fraction, 0.0f, 1.0f );
            fraction = 1.0f - fraction;
        
            col.Set( (1-fraction)*255, fraction*255, 0, 255 );

            const char *caption = lagRemaining > 5 ? LANGUAGEPHRASE("dialog_state_synchronising") : LANGUAGEPHRASE("dialog_state_synchronised");
            g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption );

            yPos += 20;
    
            g_renderer->RectFill( m_x+30, yPos, (m_w-60)*fraction, 20, col );
            g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White );

            if( m_stage == 2 )
            {
                RenderTimeRemaining( fraction );
            }
        }

    
        //
        // Connection is done, we can shut down now
        // Pop up lobby if we were asked to do so

        if( g_app->GetClientToServer()->m_connectionState == ClientToServer::StateConnected )
        {
            if( m_popupLobbyAtEnd )
            {
                if( !EclGetWindow( "LOBBY" ) )              
                {
                    LobbyWindow *lobby = new LobbyWindow();                   
                    ChatWindow *chat = new ChatWindow();

                    chat->SetPosition( g_windowManager->WindowW()/2 - chat->m_w/2, 
                                       g_windowManager->WindowH() - chat->m_h - 30 );
                    EclRegisterWindow( chat );

                    float lobbyX = g_windowManager->WindowW()/2 - lobby->m_w/2;
                    float lobbyY = chat->m_y - lobby->m_h - 30;
                    lobbyY = std::max( lobbyY, 0.0f );
                    lobby->SetPosition(lobbyX, lobbyY);
                    EclRegisterWindow( lobby );
                }
            }

            if( numRemaining < 5 && lagRemaining < 5 )
            {
                EclRemoveWindow(m_name);
            }
        }

    }
    else
    {
        if( g_app->GetClientToServer()->m_connectionState == ClientToServer::StateDisconnected )
        {
            EclRemoveWindow(m_name);
        }
    }

    g_renderer->SetFont();
}
LandscapeEditWindow::~LandscapeEditWindow()
{
	g_app->m_locationEditor->RequestMode(LocationEditor::ModeNone);
	EclRemoveWindow(LANGUAGEPHRASE("editor_landscapetile"));
    EclRemoveWindow(LANGUAGEPHRASE("editor_guidegrid"));
}
예제 #27
0
void Interface::Update()
{
    START_PROFILE( "EclUpdate" );
    EclUpdate();
    END_PROFILE( "EclUpdate" );
    
    

    //
    // Screenshot?

    if( g_keyDeltas[KEY_P] &&
        !UsingChatWindow() &&
        g_app->m_gameRunning )
    {
        g_renderer->SaveScreenshot();

        if( g_app->GetWorld()->AmISpectating() )
        {
            int teamId = g_app->GetClientToServer()->m_clientId;
            g_app->GetClientToServer()->SendChatMessageReliably( teamId, 100, LANGUAGEPHRASE("dialog_saved_screenshot"), true );
        }
        else
        {
            int teamId = g_app->GetWorld()->m_myTeamId;
            g_app->GetClientToServer()->SendChatMessageReliably( teamId, 100, LANGUAGEPHRASE("dialog_saved_screenshot"), false );
        }
    }


    //
    // Pop up main menu?

    if( m_escTimer > 0.0f )
    {
        m_escTimer -= g_advanceTime;
    }


	if (QuitKeyPressed())
		ConfirmExit( NULL );	
	
	if (QuitImmediatelyKeyPressed() || g_inputManager->m_quitRequested) 
	{
		g_inputManager->m_quitRequested = false;
		AttemptQuitImmediately();
	}
	
	if (ToggleFullscreenKeyPressed() || s_toggleFullscreen)
	{
		g_preferences->SetInt( PREFS_SCREEN_WINDOWED, !g_preferences->GetInt( PREFS_SCREEN_WINDOWED ));
		g_app->ReinitialiseWindow();
		s_toggleFullscreen = false;
	}
		
	if( g_keyDeltas[KEY_ESC] )
    {
        //
        // panic key (double esc)

        bool panicKeyEnabled = g_preferences->GetInt(PREFS_INTERFACE_PANICKEY);
        bool officeMode = (g_app->GetGame()->GetOptionValue("GameMode") == GAMEMODE_OFFICEMODE);
        if( officeMode ) panicKeyEnabled = true;

        if( panicKeyEnabled && m_escTimer > 0.0f )
        {
            g_app->HideWindow();
            m_escTimer = 0.0f;
            g_keys[KEY_ESC] = 0;
            g_keyDeltas[KEY_ESC] = 0;
        }        
        
        if( !EclGetWindow( "Main Menu" ) )
        {
            EclRegisterWindow( new MainMenu() );
        }
        else
        {
            EclRemoveWindow( "Main Menu" );
        }

        m_escTimer = 0.5f;
    }


    if( !g_app->m_gameRunning &&
        EclGetWindows()->Size() == 0 )
    {
        EclRegisterWindow( new MainMenu() );
    }

}
예제 #28
0
void EclRemoveAllWindowsExclude( char *exclude){
	while( windows.ValidIndex(0) )
    {
        EclRemoveWindow( windows[0]->m_name );
    }
}
예제 #29
0
void SidePanel::Render( bool hasFocus )
{
    int currentSelectionId = g_app->GetMapRenderer()->GetCurrentSelectionId();
    if( currentSelectionId == -1 )
    {
        if( m_mode != ModeUnitPlacement &&
            m_mode != ModeFleetPlacement )
        {
            ChangeMode( ModeUnitPlacement );
            m_currentFleetId = -1;
        }
    }
    Team *myTeam = g_app->GetWorld()->GetMyTeam();

    if( m_mode == ModeUnitPlacement )
    {
        PanelModeButton *button = (PanelModeButton *)GetButton("FleetMode");
        //if( !button->m_disabled )
        {
            int shipsRemaining = 0;
            if( myTeam )
            {
                shipsRemaining += myTeam->m_unitsAvailable[WorldObject::TypeBattleShip];
                shipsRemaining += myTeam->m_unitsAvailable[WorldObject::TypeCarrier];
                shipsRemaining += myTeam->m_unitsAvailable[WorldObject::TypeSub];

                bool unplacedFleets = false;
                bool outOfCredits = myTeam->m_unitCredits <= 0;
                if( !g_app->GetGame()->GetOptionValue("VariableUnitCounts") ) outOfCredits = false;

                if( myTeam->m_fleets.Size() > 0 &&
                    myTeam->GetFleet( myTeam->m_fleets.Size() - 1 )->m_active == false )
                {
                    unplacedFleets = true;
                }
                if( (shipsRemaining <= 0 ||
                    myTeam->m_unitCredits <= 0 )&&
                    !unplacedFleets )
                {
                    button->m_disabled = true;
                }
                else
                {
                    button->m_disabled = false;
                }
            }
        }
    }

    int w = m_w;
    m_w = 100;
    FadingWindow::Render( hasFocus, true );    
    m_w = w;
        
    char text[128];
    switch(m_mode)
    {
        case ModeUnitPlacement:     sprintf(text, LANGUAGEPHRASE("dialog_placeunit"));   break;
        case ModeFleetPlacement:    sprintf(text, LANGUAGEPHRASE("dialog_createfleet"));  break;
    }
    g_renderer->TextCentreSimple(m_x+50, m_y+10, White, m_fontsize, text );

    if( m_mode == ModeFleetPlacement )
    {
        if( m_currentFleetId != -1 )
        {
            int x = 0;
            int y = 0;
            int yMod = 0;
            
            Team *myTeam = g_app->GetWorld()->GetTeam( g_app->GetWorld()->m_myTeamId );
            if( myTeam && myTeam->m_fleets.ValidIndex(m_currentFleetId) )
            {
                if( m_mode == ModeFleetPlacement )
                {
                    x = m_x + 120;
                    y = m_y + 20;
                    yMod = 50;

                    for( int i = 0; i < 6; ++i )
                    {
                        g_renderer->RectFill( x, y, 40, 40, Colour(90,90,170,200) );
                        g_renderer->Rect(x, y, 40, 40, White );
                        y += yMod;
                    }
                    y = m_y+20;
                }
                else
                {
                    x = m_x + 10;
                    y = m_y + 40;
                    yMod = 60;
                }

                for( int i = 0; i < myTeam->m_fleets[ m_currentFleetId ]->m_memberType.Size(); ++i )
                {
                    int type = myTeam->m_fleets[ m_currentFleetId ]->m_memberType[i];
                    Image *bmpImage	= g_resource->GetImage( g_app->GetMapRenderer()->m_imageFiles[type] );
                    g_renderer->SetBlendMode( Renderer::BlendModeAdditive );
                    g_renderer->Blit( bmpImage, x+3, y, 35, 35, myTeam->GetTeamColour() );
                    g_renderer->SetBlendMode( Renderer::BlendModeNormal );
                    y += yMod;
                }
            }
        }
    }
    int variableTeamUnits = g_app->GetGame()->GetOptionValue("VariableUnitCounts");
    if( myTeam )
    {
        if( variableTeamUnits == 1 )
        {
            Colour col = Colour(255,255,0,255);
            char msg[128];
            sprintf( msg, LANGUAGEPHRASE("dialog_credits_1") );
            LPREPLACEINTEGERFLAG( 'C', myTeam->m_unitCredits, msg );
            g_renderer->TextCentreSimple( m_x+50, m_y+m_h-28, col, m_fontsize, msg );

            sprintf( msg, LANGUAGEPHRASE("dialog_credits_2"));
            g_renderer->TextCentreSimple( m_x+50, m_y+m_h-15, col, m_fontsize, msg );
        }

        int totalUnits = 0;
        for( int i = 0; i < WorldObject::NumObjectTypes; ++i )
        {
            totalUnits += myTeam->m_unitsAvailable[i];
        }

        if( totalUnits == 0 &&
            m_previousUnitCount > 0 &&
            m_currentFleetId == -1 &&
            !g_app->GetTutorial() )
        {
            EclRemoveWindow("Side Panel" );
            return;
        }
        m_previousUnitCount = totalUnits;
    }
}