Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

MainFuncs.h File Reference


Detailed Description

declare all the functions for all the different modes of main (menu, credit, multiplayer menu, etc) also some constants needed by main also a few helper functions.

Definition in file MainFuncs.h.

#include "..\AEngine\AEngine.h"

Include dependency graph for MainFuncs.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Namespaces

namespace  MainModes

Functions

void switchToMainMenu ()
void updateMainMenu ()
void renderMainMenu ()
void switchToMultiplayMenu ()
void updateMultiplayMenu ()
void renderMultiplayMenu ()
void switchToCredit ()
void updateCredit ()
void renderCredit ()
void switchToSponsor ()
void updateSponsor ()
void renderSponsor ()
void drawBox (Box &b, Vec3D color)
string & stripComments (string &str)

Variables

int mode


Function Documentation

void drawBox Box   b,
Vec3D    color
 

Definition at line 40 of file Helper.cpp.

References Box::bottom, Box::left, overlay_rect(), Box::right, Box::top, and Vec2D.

Referenced by renderMainMenu(), and renderMultiplayMenu().

00041 {
00042         overlay_rect( Vec2D(b.left, b.top), Vec2D(b.right, b.bottom), false, color );
00043 }

void renderCredit  
 

Definition at line 51 of file MainCredit.cpp.

References Overhead::renderCredit().

Referenced by main_render().

00052 {
00053         Overhead::renderCredit();
00054 }

void renderMainMenu  
 

Definition at line 66 of file MainMenu.cpp.

References Globals::artWork, butMainCredit(), butMainExit(), butMainMultiPlayer(), butMainSinglePLayer(), drawBox(), input_getMouseX(), input_getMouseY(), Box::isContain(), overlay_image(), and Vec2D.

Referenced by main_render().

00067 {
00068         Vec2D mouse( input_getMouseX(), input_getMouseY() );                                            // Mouse Cursor
00069         overlay_image( Globals::artWork->mouse, mouse+Vec2D(0.025f,0.025f), Vec2D(0.05f,0.05f), BlendModes::KEY );
00070 
00071         // main menu screen
00072         overlay_image( artWork->main_menuTex, Vec2D(0.5f,0.5f), Vec2D(1.0f,1.0f) );
00073 
00074         // highlight the button that the mouse is currently over
00075         if( butMainSinglePLayer.isContain(mouse) )      drawBox( butMainSinglePLayer, Colors::yellow );
00076         if( butMainMultiPlayer.isContain(mouse) )       drawBox( butMainMultiPlayer, Colors::yellow );
00077         if( butMainCredit.isContain(mouse) )            drawBox( butMainCredit, Colors::yellow );
00078         if( butMainExit.isContain(mouse) )                      drawBox( butMainExit, Colors::yellow );
00079 }

void renderMultiplayMenu  
 

Definition at line 192 of file MainMultiplay.cpp.

References Globals::artWork, butMultiAbort(), butMultiChat(), butMultiChatMsg(), butMultiHost(), butMultiIP(), butMultiJoin(), butMultiLaunch(), butMultiName(), chatLog, drawBox(), Typer::getString(), input_getMouseX(), input_getMouseY(), Box::isContain(), Box::left, net_getAllPlayers(), overlay_image(), overlay_text(), overlay_textOut(), pTyper, step, Box::top, typerChatMsg, typerIP, typerName, UINT, and Vec2D.

Referenced by main_render().

00193 {
00194         Vec2D mouse( input_getMouseX(), input_getMouseY() );                                            // Mouse Cursor
00195         overlay_image( Globals::artWork->mouse, mouse+Vec2D(0.025f,0.025f), Vec2D(0.05f,0.05f), BlendModes::KEY );
00196 
00197         // main menu screen
00198         overlay_image( artWork->main_multiplayTex, Vec2D(0.5f,0.5f), Vec2D(1.0f,1.0f) );
00199 
00200         // highlight the button that the mouse is currently over
00201         if( butMultiName.isContain(mouse) )             drawBox( butMultiName, Colors::gray );
00202         if( butMultiHost.isContain(mouse) )             drawBox( butMultiHost, Colors::yellow );
00203         if( butMultiJoin.isContain(mouse) )             drawBox( butMultiJoin, Colors::yellow );
00204         if( butMultiIP.isContain(mouse) )               drawBox( butMultiIP, Colors::gray );
00205         if( butMultiChatMsg.isContain(mouse) )  drawBox( butMultiChatMsg, Colors::gray );
00206         if( butMultiChat.isContain(mouse) )             drawBox( butMultiChat, Colors::yellow );
00207         if( butMultiLaunch.isContain(mouse) )   drawBox( butMultiLaunch, Colors::yellow );
00208         if( butMultiAbort.isContain(mouse) )    drawBox( butMultiAbort, Colors::yellow );
00209 
00210         // typer strings
00211         overlay_text() << typerName.getString();
00212         overlay_textOut( Vec2D( butMultiName.left+0.008f, butMultiName.top+0.017f), 1.0f, Colors::white );
00213         overlay_text() << typerIP.getString();
00214         overlay_textOut( Vec2D( butMultiIP.left+0.008f, butMultiIP.top+0.017f), 1.0f, Colors::white );
00215         overlay_text() << typerChatMsg.getString();
00216         overlay_textOut( Vec2D( butMultiChatMsg.left+0.008f, butMultiChatMsg.top+0.017f), 1.0f, Colors::white );
00217 
00218         // selected typer
00219         if( pTyper==&typerName )                drawBox( butMultiName, Colors::white );
00220         if( pTyper==&typerIP )                  drawBox( butMultiIP, Colors::white );
00221         if( pTyper==&typerChatMsg )             drawBox( butMultiChatMsg, Colors::white );
00222 
00223         // player list
00224         if( step==Steps::readyToLaunch )
00225         {
00226                 vector<string> &playersList = net_getAllPlayers();
00227                 for( UINT i=0; i<playersList.size(); i++ )
00228                         overlay_text() << playersList[i] << endl;
00229                 overlay_textOut( Vec2D(0.065f, 0.522f) );
00230         }
00231 
00232         // chat log
00233         while( chatLog.size()>9 ) chatLog.pop_front();
00234         for( list<string>::iterator iter=chatLog.begin(); iter!=chatLog.end(); iter++ ) 
00235                 overlay_text() << (*iter) << endl;
00236         overlay_textOut( Vec2D( 0.440f, 0.527f ), 1.0f, Colors::white );        
00237 }

void renderSponsor  
 

Definition at line 61 of file MainSponsor.cpp.

References Helper::abs(), Globals::artWork, ATexture, overlay_image(), PERIOD, time, and Vec2D.

Referenced by main_render().

00062 {
00063         int t = time % PERIOD;
00064         FLOAT alpha = abs(PERIOD/2 - t) * 2.0f / PERIOD;
00065         alpha = sqrtf( 1.0f - alpha );
00066 
00067         ATexture img;
00068         if( time < PERIOD )                     img = artWork->main_leftField;
00069         else if( time < 2*PERIOD )  img = artWork->main_sponsorMS;
00070         else if( time < 3*PERIOD )  img = artWork->main_sponsorNV;
00071         else                                            img = artWork->main_sponsorPF;
00072 
00073                 overlay_image( img, Vec2D(0.5f,0.5f), Vec2D(1.0f,1.0f), BlendModes::MIX, alpha );
00074 }

string& stripComments string &    str
 

Definition at line 28 of file Helper.cpp.

Referenced by Overhead::initData(), Overhead::initHUD(), and main_init().

00029 {
00030         size_t start;
00031         size_t end;
00032         while( (start = str.find("//")) != string::npos )
00033         {
00034                 end = str.find("\n", start)+1;
00035                 str.erase(start, end-start);
00036         }
00037         return str;
00038 }

void switchToCredit  
 

Definition at line 39 of file MainCredit.cpp.

References Overhead::mainMenuCredit().

Referenced by updateMainMenu().

00040 {
00041         mode = MainModes::credit;
00042         Overhead::mainMenuCredit();
00043 }

void switchToMainMenu  
 

Definition at line 44 of file MainMenu.cpp.

Referenced by updateCredit(), updateMultiplayMenu(), and updateSponsor().

00045 {
00046         mode = MainModes::mainMenu;
00047 }

void switchToMultiplayMenu  
 

Definition at line 59 of file MainMultiplay.cpp.

References pTyper, step, typerChatMsg, typerIP, and typerName.

Referenced by updateMainMenu().

00060 {
00061         mode = MainModes::multiplayMenu;
00062 
00063         typerName = Typer("Your Name");
00064         typerIP   = Typer("Host IP");
00065         typerChatMsg = Typer("Hello!");
00066         pTyper = &typerName;    
00067 
00068         step = Steps::enterName;
00069 }

void switchToSponsor  
 

Definition at line 39 of file MainSponsor.cpp.

References time.

Referenced by main_init().

00040 {
00041         mode = MainModes::sponsor;
00042         time = 0;
00043 }

void updateCredit  
 

Definition at line 45 of file MainCredit.cpp.

References input_isKeyPressed(), switchToMainMenu(), and Overhead::updateCredit().

Referenced by main_update().

00046 {
00047         if( input_isKeyPressed(KeyCodes::key_ESCAPE) ) switchToMainMenu();
00048         Overhead::updateCredit();
00049 }

void updateMainMenu  
 

Definition at line 49 of file MainMenu.cpp.

References butMainCredit(), butMainExit(), butMainMultiPlayer(), butMainSinglePLayer(), input_getMouseX(), input_getMouseY(), input_isMouseLBClicked(), Box::isContain(), net_runAsFakeServer(), Overhead::overhead_init(), switchToCredit(), switchToMultiplayMenu(), sys_terminate(), and Vec2D.

Referenced by main_update().

00050 {
00051         Vec2D mouse( input_getMouseX(), input_getMouseY() );
00052         if( input_isMouseLBClicked() )
00053         {
00054                 if( butMainSinglePLayer.isContain(mouse) )
00055                 {
00056                         net_runAsFakeServer("Fake Server Player",8);
00057                         overhead_init();                                // switch to overhead
00058                         mode = MainModes::overhead;
00059                 }
00060                 if( butMainMultiPlayer.isContain(mouse) )       switchToMultiplayMenu();
00061                 if( butMainCredit.isContain(mouse) )            switchToCredit();
00062                 if( butMainExit.isContain(mouse) )                      sys_terminate();
00063         }
00064 }

void updateMultiplayMenu  
 

Definition at line 106 of file MainMultiplay.cpp.

References butMultiAbort(), butMultiChat(), butMultiChatMsg(), butMultiHost(), butMultiIP(), butMultiJoin(), butMultiLaunch(), butMultiName(), chatLog, NetworkMessages::COMMAND_CHAT(), NetworkMessages::COMMAND_START_GAME(), NetworkMessages::COMMIT_TIME(), Globals::currGameTick, Typer::getString(), Typer::input(), input_getMouseX(), input_getMouseY(), input_isKeyPressed(), input_isMouseLBClicked(), Box::isContain(), net_acceptMorePlayers(), net_amIServer(), net_connectToServer(), net_finalizeGame(), net_getSelfIP(), net_runAsServer(), net_send(), processIncomingMessages(), pTyper, NetworkMessages::RANDOM_SEED_VALUE(), step, switchToMainMenu(), sys_randInt(), typerChatMsg, typerIP, typerName, and Vec2D.

Referenced by main_update().

00107 {
00108         Vec2D mouse( input_getMouseX(), input_getMouseY() );
00109         if( input_isMouseLBClicked() )
00110         {
00111                 if( butMultiAbort.isContain(mouse) )                    // abort
00112                 {
00113                         //net_disconnect();
00114                         switchToMainMenu();
00115                         step = Steps::enterName;
00116                         return;
00117                 }
00118 
00119                 // select typer
00120                 if( butMultiName.isContain(mouse) )             pTyper = &typerName;
00121                 if( butMultiIP.isContain(mouse) )               pTyper = &typerIP;
00122                 if( butMultiChatMsg.isContain(mouse) )  pTyper = &typerChatMsg;
00123 
00124                 // host or join
00125                 if(step==Steps::enterName && typerName.getString() != "Your Name") step = Steps::hostOrJoin;
00126                 if( step==Steps::hostOrJoin )
00127                 {
00128                         if( butMultiHost.isContain(mouse) )                             // Host Game
00129                         {
00130                                 step = Steps::readyToLaunch;                            
00131                                 net_runAsServer( net_getSelfIP(), typerName.getString(), 8 );
00132                                 chatLog.push_back( "Hosting Process Complete.  IP = " + net_getSelfIP() );
00133                         }
00134 
00135                         if( butMultiJoin.isContain(mouse) )                             // Join Game
00136                         {                               
00137                                 if( !net_connectToServer( typerIP.getString(), typerName.getString() ))
00138                                 {
00139                                         chatLog.push_back( "Cannot Join with That Host" );
00140                                         return;
00141                                 }
00142                                 chatLog.push_back( "Joining Process Complete." );
00143                                 step = Steps::readyToLaunch;
00144                         }
00145                 }
00146 
00147                 // launch
00148                 if( step==Steps::readyToLaunch && butMultiLaunch.isContain(mouse) )
00149                         if( net_amIServer() )
00150                         {                               
00151                                 currGameTick = 0;
00152                                 stringstream sstr;
00153                                 
00154                                 if( net_amIServer() ) net_finalizeGame();
00155 
00156                                 sstr << COMMAND_START_GAME << " " << COMMIT_TIME << " " << currGameTick << " " << RANDOM_SEED_VALUE << " " << sys_randInt();
00157                                 net_send(sstr.str());
00158                         }
00159 
00160                 // chat by clicking Chat button
00161                 if( step==Steps::readyToLaunch && butMultiChat.isContain(mouse) )
00162                 {
00163                         ostringstream strm;
00164                         strm << COMMAND_CHAT << " [" << typerName.getString() << "] " << typerChatMsg.getString();
00165                         net_send(strm.str());
00166                         typerChatMsg = Typer();
00167                 }
00168         }
00169 
00170         // type to InputString Typer Box
00171         if( step==Steps::enterName || step==Steps::hostOrJoin )                 // type name or ip
00172                 if( pTyper==&typerName || pTyper==&typerIP )
00173                         pTyper->input();
00174         if( step==Steps::readyToLaunch && pTyper==&typerChatMsg )               // type chat
00175                 pTyper->input();
00176 
00177         // chat by pressing enter while chat box is active
00178         if( step==Steps::readyToLaunch && input_isKeyPressed(KeyCodes::key_RETURN) && pTyper==&typerChatMsg )
00179         {
00180                 ostringstream strm;
00181                 strm << COMMAND_CHAT << " [" << typerName.getString() << "] " << typerChatMsg.getString();
00182                 net_send(strm.str());
00183                 typerChatMsg = Typer();
00184         }
00185 
00186         // check for more players
00187         if( step==Steps::readyToLaunch ) net_acceptMorePlayers();
00188 
00189         processIncomingMessages();
00190 }

void updateSponsor  
 

Definition at line 45 of file MainSponsor.cpp.

References input_isKeyPressed(), PERIOD, Sound::playMusic(), switchToMainMenu(), and time.

Referenced by main_update().

00046 {
00047         time++;
00048         if( input_isKeyPressed(KeyCodes::key_ESCAPE) )                  // skip by pressing ESC
00049                 if( time < PERIOD ) time = PERIOD;
00050                 else if( time <2*PERIOD ) time = 2*PERIOD;
00051                 else if( time <3*PERIOD ) time = 3*PERIOD;
00052                 else if( time <4*PERIOD ) time = 4*PERIOD;
00053 
00054         if( time >= 4*PERIOD )
00055         {
00056                 Sound::playMusic( Sound::SMPL_SONG_MENU );
00057                 switchToMainMenu();                             // end of sponsor               
00058         }
00059 }


Variable Documentation

int mode
 

Definition at line 42 of file MainFuncs.h.


Generated on Wed Apr 23 05:51:25 2003 for Modern Warfare by doxygen1.3-rc2