123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415 |
- #define MPPARAMETERSCREEN_CPP
- /*************************************************************************************************\
- MPParameterScreen.cpp : Implementation of the MPParameterScreen component.
- //---------------------------------------------------------------------------//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- \*************************************************************************************************/
- #include "MPParameterScreen.h"
- #include "prefs.h"
- #include "IniFile.h"
- #include "../MCLib/UserInput.h"
- #include "..\resource.h"
- #include "assert.h"
- #include "Multplyr.h"
- #include "MechBayScreen.h"
- #include "LogisticsData.h"
- #include "Comndr.h"
- #include "MissionBriefingScreen.h"
- #include "ChatWindow.h"
- extern bool quitGame;
- #ifndef GAMESOUND_H
- #include "gamesound.h"
- #endif
- #define MP_PLAYER_PREFS 120
- #define MAP_INFO 121
- #define CHECK_BUTTON 200
- #define MP_INCREMENT_DROPWEIGHT 198
- #define MP_DECREMENT_DROPWEIGHT 199
- #define MP_INCREMENT_CBILLS 200
- #define MP_DECREMENT_CBILLS 201
- #define MP_INCREMENT_TIME 202
- #define MP_DECREMENT_TIME 203
- #define MP_INCREMENT_RP 204
- #define MP_DECREMENT_RP 205
- #define MP_AIRSTRIKES 206
- #define MP_SENSOR_PROBE 207
- #define MP_MINELAYER 208
- #define MP_REPAIR 209
- #define MP_LOCKGAME 210
- #define MP_BOOTPLAYER 211
- #define MP_SCOUTS 212
- #define MP_RECOVERY 213
- #define MP_GUARDTOWER 214
- #define MP_RESOURCE_BLDG 215
- #define MP_UNLIMITED_AMMO 216
- #define MP_VARIANTS 217
- #define MP_ALLTECH 218
- #define MP_QUICKSTART 219
- #define MP_RP_FORMMECHS 220
- #define MP_INCREMENT_PLAYER_CBILLS 250
- #define MP_DECREMENT_PLAYER_CBILLS 251
- static const int FIRST_BUTTON_ID = 1000010;
- static const int OK_BUTTON_ID = 1000001;
- static const int CANCEL_BUTTON_ID = 1000002;
- MPParameterScreen* MPParameterScreen::s_instance = NULL;
- GUID NO_VERSION_GUID = {
- 0,0,0,0,0,0,0,0,0,0,0
- };
- const char* pPurchaseFiles[5] =
- {
- "purchase_Steiner",
- "purchase_Davion",
- "purchase_Liao",
- "purchase_Clan",
- "purchase_All"
- };
- MPParameterScreen::MPParameterScreen()
- {
- status = RUNNING;
- helpTextArrayID = 12;
- bMapInfoDlg = 0;
- bShowNoMapDlg = 0;
- bBootDlg = 0;
- bErrorDlg = 0;
- bHostLeftDlg = 0;
- bDisconnectDlg = 0;
- chatToSend = IDS_MP_PARAMETER_NO_MAP_CHAT;
- s_instance = this;
- }
- MPParameterScreen::~MPParameterScreen()
- {
- //ONLY destroy the 0 member. All of the other were set equal which means deleting their pointers will crash!!
- // Well DONE.
- //
- playerParameters[0].factionDropList.destroy();
- playerParameters[0].teamNumberDropList.destroy();
- for (int i=1;i<MAX_MC_PLAYERS;i++)
- {
- playerParameters[i].factionDropList.specialDestroy();
- playerParameters[i].teamNumberDropList.specialDestroy();
- }
- }
- int MPParameterScreen::indexOfButtonWithID(int id)
- {
- int i;
- for (i = 0; i < buttonCount; i++)
- {
- if (buttons[i].getID() == id)
- {
- return i;
- }
- }
- return -1;
- }
- void MPParameterScreen::init(FitIniFile* file)
- {
- LogisticsScreen::init( *file, "Static", "Text", "Rect", "Button" );
- if ( buttonCount )
- {
- for ( int i = 0; i < buttonCount; i++ )
- {
- long id = buttons[i].getID();
- if ( (id < MP_INCREMENT_DROPWEIGHT || id > MP_DECREMENT_RP)
- && id != MP_LOCKGAME && id != MP_BOOTPLAYER )
- buttons[i].setMessageOnRelease();
- if (buttons[i].getID() == 0)
- {
- buttons[i].setID(FIRST_BUTTON_ID + i);
- }
- if ( id != MB_MSG_NEXT && id != MB_MSG_PREV
- && id != MP_PLAYER_PREFS && id != MB_MSG_MAINMENU )
- {
- buttons[i].setPressFX( LOG_VIDEOBUTTONS );
- buttons[i].setHighlightFX( LOG_DIGITALHIGHLIGHT );
- buttons[i].setDisabledFX( LOG_WRONGBUTTON );
- }
- }
- }
- int curY = 0;
- playerParameters[0].init( file, "PlayerParams" );
- for ( int i = 1; i < MAX_MC_PLAYERS; i++ )
- {
- playerParameters[i] = playerParameters[0];
- curY = i * (playerParameters[i].bottom() - playerParameters[i].top() + 5);
- playerParameters[i].move( 0, curY );
-
- }
- FullPathFileName path;
- path.init( artPath, "mcl_mp_loadmap", ".fit" );
- FitIniFile mpFile;
- if ( NO_ERR != mpFile.open( path ) )
- {
- char error[256];
- sprintf( error, "couldn't open file %s", path );
- Assert( 0, 0, error );
- return;
- }
- mpLoadMap.init( &mpFile );
- mapInfoDlg.init();
- for ( i = 0; i < editCount; i++ )
- {
- edits[i].setNumeric( true );
- edits[i].allowIME( false );
- }
- edits[0].limitEntry( 4 );
- edits[1].limitEntry( 3 );
- edits[2].limitEntry( 2 );
- edits[3].limitEntry( 6 );
- }
- void MPParameterScreen::begin()
- {
- fadeOutTime = 0.f;
- fadeTime = 0.f;
- MPlayer->setMode(MULTIPLAYER_MODE_PARAMETERS);
- playerCount = 0;
- bLoading = 0;
- bMapInfoDlg = 0;
- bShowNoMapDlg = 0;
- bBootDlg = 0;
- bErrorDlg = 0;
- bDisconnectDlg = 0;
- MPlayer->initParametersScreen();
- if ( MPlayer->isHost() )
- setMission( MPlayer->missionSettings.map, (status != UP && status != NEXT) ? 1 : 0 );
- else
- setMissionClientOnly( MPlayer->missionSettings.map );
- delayTime = 0.f;
- status = RUNNING;
- bHostLeftDlg = 0;
- bootPlayerID = -1;
- for ( int i = 0; i < MAX_MC_PLAYERS; i++ )
- {
- playerParameters[i].insigniaName.Empty();
- }
- bWaitingToStart = 0;
- }
- void MPParameterScreen::end()
- {
- if ( status == PREVIOUS )
- MPlayer->closeSession();
- else if ( status == GOTOSPLASH )
- {
- MPlayer->closeSession();
- delete MPlayer;
- MPlayer = NULL;
- }
- bLoading = 0;
- statics[15].setTexture( ( unsigned long)0 );
- delayTime = 0.f;
- bHostLeftDlg = 0;
- }
- void MPParameterScreen::render(int xOffset, int yOffset )
- {
- if ( VERSION_STATUS_UNKNOWN == MPlayer->getVersionStatus() )
- {
- if ( bErrorDlg )
- {
- LogisticsOneButtonDialog::instance()->render();
- }
- return;
- }
- if ( status == NEXT && MPlayer->missionSettings.quickStart )
- {
- xOffset = 0;
- yOffset = 0;
- }
- LogisticsScreen::render(xOffset, yOffset);
- if ( bMapInfoDlg )
- {
- mapInfoDlg.render();
- }
- else if ( bLoading )
- {
- mpLoadMap.render( );
- }
- else if ( bShowNoMapDlg || bBootDlg || bDisconnectDlg )
- {
- LogisticsOKDialog::instance()->render();
- }
- else if ( bErrorDlg )
- {
- LogisticsOneButtonDialog::instance()->render();
- }
- else if ( !xOffset && !yOffset )
- {
- aPlayerParams* pFocus = 0;
- for ( int i = 0; i < playerCount; i++ )
- {
- if ( playerParameters[i].hasFocus() )
- pFocus = & playerParameters[i];
-
- playerParameters[i].render();
-
- }
- if ( pFocus )
- pFocus->render();
- ChatWindow::instance()->render(xOffset, yOffset);
- }
- if ( bHostLeftDlg )
- {
- LogisticsOneButtonDialog::instance()->render();
- }
- }
- void MPParameterScreen::render()
- {
- render(0, 0);
- }
- int MPParameterScreen::handleMessage( unsigned long message, unsigned long who)
- {
- if ( RUNNING == status )
- {
- switch ( who )
- {
- case 57/*MB_MSG_MAINMENU*/:
- {
- getButton( 57/*MB_MSG_MAINMENU*/ )->press( 0 );
- if (MPlayer->commanderID > -1) {
- MC2Player* pInfo = MPlayer->getPlayerInfo( MPlayer->commanderID );
- if ( pInfo->ready )
- pInfo->ready = 0;
- if (!MPlayer->isHost())
- {
- MPlayer->sendPlayerUpdate( 0, 5, MPlayer->commanderID );
- }
- }
- status = MAINMENU;
- }
- break;
- case 51/*MB_MSG_PREV*/:
- {
- getButton( 51/*MB_MSG_PREV*/ )->press( 0 );
- LogisticsOKDialog::instance()->setText( IDS_PROMPT_TO_DISCONNECT, IDS_DIALOG_NO, IDS_DIALOG_YES );
- LogisticsOKDialog::instance()->begin();
- bDisconnectDlg = true;
- }
- break;
- case 50/*MB_MSG_NEXT*/:
- {
- if (MPlayer->isHost())
- MPlayer->setInProgress(true);
- delayTime += frameLength;
- char text[256];
- cLoadString( IDS_MPLAYER_GAME_ABOUT_TO_START, text, 255 );
- MPlayer->sendChat( 0, -1, text );
- }
- break;
- case 101/*load map button*/:
- {
- //load map
- getButton( 101/*load map button*/ )->press( 0 );
- bLoading = true;
- mpLoadMap.begin();
- return 1;
- }
- break;
- case 102/*add ai player*/:
- {
- //add ai
- getButton( 102/*add ai player*/ )->press( 0 );
- status = DOWN;
- return 1;
- }
- break;
- case MAP_INFO:
- bMapInfoDlg = true;
- mapInfoDlg.setMap( MPlayer->missionSettings.map );
- mapInfoDlg.begin();
- break;
- case MP_PLAYER_PREFS:
- {
- MC2Player* pInfo = MPlayer->getPlayerInfo( MPlayer->commanderID );
- if ( pInfo->ready )
- pInfo->ready = 0;
- if (!MPlayer->isHost())
- {
- MPlayer->sendPlayerUpdate( 0, 5, MPlayer->commanderID );
- }
-
- status = UP;
- }
- break;
- case MP_LOCKGAME:
- if ( getButton( MP_LOCKGAME )->isPressed() )
- {
- MPlayer->setLocked( true );
- }
- else
- MPlayer->setLocked( false );
- break;
- case MP_BOOTPLAYER:
- {
- for( int i = 0; i < playerCount; i++ )
- {
- if ( playerParameters[i].isSelected() )
- {
- if ( MPlayer->commanderID == playerParameters[i].getCommanderID() )
- {
- soundSystem->playDigitalSample( LOG_WRONGBUTTON );
- return 0;
- }
- char str[256];
- cLoadString( IDS_MP_PARAMTERS_BOOT_PROMPT, str, 255 );
- char finalStr[256];
- for ( int j = 0; j < MAX_MC_PLAYERS; j++ )
- {
- if ( MPlayer->playerList[j].commanderID
- == playerParameters[i].getCommanderID() )
- {
- sprintf( finalStr, str, MPlayer->playerList[j].name );
- LogisticsOKDialog::instance()->setText( IDS_DIALOG_OK, IDS_DIALOG_NO, IDS_DIALOG_YES );
- LogisticsOKDialog::instance()->setText( finalStr );
- LogisticsOKDialog::instance()->begin();
- bBootDlg = true;
- bootPlayerID = MPlayer->playerList[j].commanderID;
- return 0;
- }
- }
- break;
- }
- }
- // if we got here, there was no selected player
- LogisticsOneButtonDialog::instance()->setText( IDS_MP_PARAMETERS_CANT_BOOT, IDS_DIALOG_OK, IDS_DIALOG_OK );
- LogisticsOneButtonDialog::instance()->begin();
- bErrorDlg = true;
- }
- break;
- case MP_INCREMENT_DROPWEIGHT:
- MPlayer->missionSettings.dropWeight +=10;
- MPParameterScreen::resetCheckBoxes();
- if ( MPlayer->missionSettings.dropWeight > 1200 )
- MPlayer->missionSettings.dropWeight = 1200;
- break;
- case MP_DECREMENT_DROPWEIGHT:
- MPlayer->missionSettings.dropWeight -=10;
- MPParameterScreen::resetCheckBoxes();
- if ( MPlayer->missionSettings.dropWeight < 30 )
- MPlayer->missionSettings.dropWeight = 30;
- break;
- case MP_INCREMENT_CBILLS:
- MPlayer->missionSettings.defaultCBills +=5000;
- if ( MPlayer->missionSettings.defaultCBills < 50000 )
- MPlayer->missionSettings.defaultCBills = 50000;
- MPlayer->redistributeRP();
- MPParameterScreen::resetCheckBoxes();
-
-
- break;
- case MP_DECREMENT_CBILLS:
- MPlayer->missionSettings.defaultCBills -=5000;
- if ( MPlayer->missionSettings.defaultCBills < 50000 )
- MPlayer->missionSettings.defaultCBills = 50000;
- MPlayer->redistributeRP();
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_INCREMENT_TIME:
- if ( MPlayer->missionSettings.timeLimit < 0 )
- {
- MPlayer->missionSettings.timeLimit = 0;
- }
- MPlayer->missionSettings.timeLimit += 60;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_DECREMENT_TIME:
- if ( MPlayer->missionSettings.timeLimit <= 300 )
- MPlayer->missionSettings.timeLimit = -1;
- else
- MPlayer->missionSettings.timeLimit -= 60;
- MPParameterScreen::resetCheckBoxes();
- break;
- case MP_INCREMENT_RP:
- if ( MPlayer->missionSettings.resourcePoints < 0 )
- MPlayer->missionSettings.resourcePoints = 0;
- MPlayer->missionSettings.resourcePoints += 1000;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_DECREMENT_RP:
- MPlayer->missionSettings.resourcePoints -= 1000;
- if ( MPlayer->missionSettings.resourcePoints < 0 )
- MPlayer->missionSettings.resourcePoints = 0;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_AIRSTRIKES:
- MPlayer->missionSettings.airStrike ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_SENSOR_PROBE:
- MPlayer->missionSettings.sensorProbe ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_MINELAYER:
- MPlayer->missionSettings.mineLayer ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_REPAIR:
- MPlayer->missionSettings.repairVehicle ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_SCOUTS:
- MPlayer->missionSettings.scoutCopter ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_RECOVERY:
- MPlayer->missionSettings.recoveryTeam ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_GUARDTOWER:
- MPlayer->missionSettings.guardTower ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_RESOURCE_BLDG:
- MPlayer->missionSettings.resourceBuilding ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_UNLIMITED_AMMO:
- MPlayer->missionSettings.unlimitedAmmo ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_VARIANTS:
- MPlayer->missionSettings.variants ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_ALLTECH:
- MPlayer->missionSettings.allTech ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_RP_FORMMECHS:
- MPlayer->missionSettings.resourceForMechs ^= 1;
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case MP_QUICKSTART:
- MPlayer->missionSettings.quickStart ^= 1;
- MPParameterScreen::resetCheckBoxes();
- break;
- }
- }
- return 0;
- }
- void MPParameterScreen::initializeMap ( const char* fileName )
- {
- s_instance->setMission(fileName, true);
- }
- void MPParameterScreen::setMission( const char* fileName, bool resetData )
- {
- FullPathFileName path;
- path.init( missionPath, fileName, ".fit" );
- FitIniFile missionFile;
-
- if ( NO_ERR != missionFile.open( (char*)(const char*)path ) )
- {
- char errorStr[256];
- sprintf( errorStr, "couldn't open file %s", fileName );
- Assert( 0, 0, errorStr );
- return;
- }
- if ( resetData )
- {
- long result = 0;
- char missionName[256];
- result = missionFile.seekBlock( "MissionSettings" );
- Assert( result == NO_ERR, 0, "Coudln't find the mission settings block in the mission file" );
- bool bRes;
- result = missionFile.readIdBoolean( "MissionNameUseResourceString", bRes );
- Assert( result == NO_ERR, 0, "couldn't find the MissionNameUseResourceString" );
- if ( bRes )
- {
- unsigned long lRes;
- result = missionFile.readIdULong( "MissionNameResourceStringID", lRes );
- Assert( result == NO_ERR, 0, "couldn't find the MissionNameResourceStringID" );
- cLoadString( lRes, missionName, 255 );
- }
- else
- {
- result = missionFile.readIdString( "MissionName", missionName, 255 );
- Assert( result == NO_ERR, 0, "couldn't find the missionName" );
- }
-
- gosASSERT( strlen( missionName ) < MAXLEN_MAP_NAME );
- strcpy( MPlayer->missionSettings.map, fileName );
- strcpy( MPlayer->missionSettings.name, missionName );
-
- result = missionFile.readIdLong( "ResourcePoints", MPlayer->missionSettings.resourcePoints );
- result = missionFile.readIdLong("AdditionalCBills", MPlayer->missionSettings.defaultCBills );
- if (MPlayer->isHost())
- MPlayer->redistributeRP();
- float fTmp;
- result = missionFile.readIdFloat( "DropWeightLimit", fTmp );
- MPlayer->missionSettings.dropWeight = fTmp;
- result = missionFile.readIdFloat( "TimeLimit", MPlayer->missionSettings.timeLimit );
- if ( result != NO_ERR )
- MPlayer->missionSettings.timeLimit = -1.f;
- result = missionFile.readIdBoolean( "UnlimitedAmmoEnabledDefault", MPlayer->missionSettings.unlimitedAmmo );
- result = missionFile.readIdBoolean( "NoVariantsEnabledDefault", MPlayer->missionSettings.variants );
- MPlayer->missionSettings.variants ^= 1;
- result = missionFile.readIdBoolean( "AllTechEnabledDefault", MPlayer->missionSettings.allTech );
- result = missionFile.readIdBoolean( "AirStrikesEnabledDefault", MPlayer->missionSettings.airStrike );
- result = missionFile.readIdBoolean( "ArtilleryPieceEnabledDefault", MPlayer->missionSettings.guardTower );
- result = missionFile.readIdBoolean( "RepairVehicleEnabledDefault", MPlayer->missionSettings.repairVehicle );
- result = missionFile.readIdBoolean( "SalvageCraftEnabledDefault", MPlayer->missionSettings.recoveryTeam );
- result = missionFile.readIdBoolean( "SensorProbesEnabledDefault", MPlayer->missionSettings.sensorProbe );
- result = missionFile.readIdBoolean( "ScoutCoptersEnabledDefault", MPlayer->missionSettings.scoutCopter );
- result = missionFile.readIdBoolean( "MineLayersEnabledDefault", MPlayer->missionSettings.mineLayer );
- result = missionFile.readIdBoolean( "ResourceBuildingsEnabledDefault", MPlayer->missionSettings.resourceBuilding );
- result = missionFile.readIdBoolean( "ScoutCoptersEnabledDefault", MPlayer->missionSettings.scoutCopter );
- result = missionFile.readIdBoolean( "RPsForMechsEnabledDefault", MPlayer->missionSettings.resourceForMechs );
- result = missionFile.readIdString( "DownloadURL", MPlayer->missionSettings.url, 255 );
- unsigned long lTmp;
- if ( NO_ERR == missionFile.readIdULong( "MaximumNumberOfTeams", lTmp ) )
- MPlayer->missionSettings.maxTeams = lTmp;
- else
- MPlayer->missionSettings.maxTeams = 8;
- if ( NO_ERR == missionFile.readIdULong( "MaximumNumberOfPlayers", lTmp ) )
- MPlayer->missionSettings.maxPlayers = lTmp;
- else
- MPlayer->missionSettings.maxPlayers = 8;
-
- unsigned long tmp;
- result = missionFile.readIdULong( "MissionType", tmp );
- MPlayer->missionSettings.missionType = tmp;
- // divvy up the cBills!
-
- mapName = MPlayer->missionSettings.map;
- }
- long textureHandle = MissionBriefingScreen::getMissionTGA( fileName );
- statics[15].setTexture( textureHandle );
- statics[15].setUVs(0, 127, 127, 0 );
- statics[15].setColor( 0xffffffff );
- getButton( MAP_INFO )->disable( false );
- GUID tmpGuid = getGUIDFromFile( fileName );
- MPlayer->missionSettings.mapGuid = tmpGuid;
- }
- int __cdecl sortPlayers( const void* p1, const void* p2 )
- {
- MC2Player* player1 = *(MC2Player**)p1;
- MC2Player* player2 = *(MC2Player**)p2;
- if ( player1->team < player2->team )
- return -1;
- else if ( player1->team > player2->team )
- return 1;
- else if ( player1->teamSeniority > player2->teamSeniority )
- return -1;
- return 1;
-
- }
- void MPParameterScreen::update()
- {
- if ( MPlayer->commanderID < 0 ) // don't do anything until we've been initalized
- return;
- if ( VERSION_STATUS_UNKNOWN == MPlayer->getVersionStatus() )
- {
- return;
- }
- else if ( VERSION_STATUS_BAD == MPlayer->getVersionStatus() )
- {
- if ( bErrorDlg )
- {
- LogisticsOneButtonDialog::instance()->update();
- if ( LogisticsOneButtonDialog::instance()->isDone() )
- {
- LogisticsOneButtonDialog::instance()->end();
- bHostLeftDlg = 0;
- bErrorDlg = 0;
- // might need to kill the game here
- quitGame = true;
- }
- }
- else
- {
- LogisticsOneButtonDialog::instance()->setText( IDS_MP_CONNECTION_ERROR_WRONG_VERSION,
- IDS_DIALOG_OK, IDS_DIALOG_OK );
- LogisticsOneButtonDialog::instance()->begin();
- bErrorDlg = true;
- }
-
- return;
- }
-
- char text[256];
-
- // game not front and center at the top of the screen
- textObjects[0].setText( MPlayer->sessionName );
- if ( !MPlayer->sessionName || !strlen( MPlayer->sessionName ) )
- {
- if ( MPlayer->isHost() )
- textObjects[0].setText( IDS_STRING26150 );
- else
- textObjects[0].setText( IDS_WAITHOST2 );
- }
- // hack for some reason we don't get here from the zone
- userInput->mouseOn();
- userInput->setMouseCursor( mState_NORMAL );
- //Yet Another hack. FadeOutscreen will overwriting us if we were booted and rejoined.
- // If our status is RUNNING, reset the FadeOutTime.
- if (status != GOTOSPLASH)
- fadeOutTime = 0.0f;
- if ( MPlayer->missionSettings.quickStart )
- {
- getButton( MB_MSG_NEXT )->setText( IDS_STRING27171 );
- }
- else
- getButton( MB_MSG_NEXT )->setText( IDS_NEXT );
- char str[256];
- cLoadString( IDS_MP_PARAM_HOST_IP, str, 255 );
- char IPAddressStr[256];
- sprintf( IPAddressStr, str, MPlayer->sessionIPAddress );
- textObjects[11].setText( IPAddressStr );
- if ( !bWaitingToStart && MPlayer->missionSettings.inProgress )
- {
- bWaitingToStart = true;
- soundSystem->playBettySample( BETTY_DEPLOY_MSG );
- }
- else if ( !MPlayer->missionSettings.inProgress )
- {
- bWaitingToStart = false;
- }
- if ( delayTime )
- delayTime += frameLength;
- if ( delayTime > 5.f )
- {
- if ( getButton( MB_MSG_NEXT )->isEnabled() )
- {
- getButton( 50/*MB_MSG_NEXT*/ )->press( 0 );
- int faction = MPlayer->getPlayerInfo( MPlayer->commanderID )->faction;
- if ( faction < 0 )
- faction = 0;
- if ( MPlayer->missionSettings.allTech )
- LogisticsData::instance->setPurchaseFile( pPurchaseFiles[4] );
- else
- LogisticsData::instance->setPurchaseFile( pPurchaseFiles[faction] );
- LogisticsData::instance->setCurrentMission( MPlayer->missionSettings.map );
- MPlayer->sendMissionSetup(0, 6, NULL);
- status = NEXT;
-
- }
- else {
- if (MPlayer->isHost())
- MPlayer->setInProgress(false);
- delayTime = 0.f;
- bWaitingToStart = 0;
- }
- }
- if ( MPlayer )
- {
- FullPathFileName path;
- path.init( missionPath, MPlayer->missionSettings.map, ".pak" );
- if ( !fileExists( path ) ) // disable the ready button if the map isn't around...
- {
- getButton( MAP_INFO )->disable( true );
- }
- else
- {
- getButton( MAP_INFO )->disable( false );
- if ( !statics[15].getColor() )
- {
- long textureHandle = MissionBriefingScreen::getMissionTGA( MPlayer->missionSettings.map );
- if ( textureHandle )
- {
- statics[15].setTexture( textureHandle );
- statics[15].setUVs( 0, 127, 127, 0 );
- statics[15].setColor( 0xffffffff );
- }
- }
- }
- }
- // load up my own icon and send out to everyone else....
- /* MC2Player* pPlayer = MPlayer->getPlayerInfo( MPlayer->commanderID );
- if ( pPlayer && !MPlayer->insigniaList[MPlayer->commanderID])
- {
- FullPathFileName path;
- path.init( "data\\multiplayer\\insignia\\", pPlayer->insigniaFile, ".tga" );
- File file;
- if ( NO_ERR == file.open( path ) )
- {
- long size = file.getLength();
- unsigned char* pData = new unsigned char[size];
- file.read( pData, size );
- MPlayer->sendPlayerInsignia( (char*)pPlayer->insigniaFile, pData, size );
- MPlayer->insigniaList[MPlayer->commanderID] = 1;
- }
- }*/
- if ( MPlayer->launchedFromLobby )
- getButton( MB_MSG_PREV )->disable( true );
- else
- getButton( MB_MSG_PREV )->disable( false );
- if ( bMapInfoDlg )
- {
- mapInfoDlg.update();
- if ( mapInfoDlg.isDone() )
- {
- bMapInfoDlg = 0;
- }
- }
- else if ( bHostLeftDlg || bErrorDlg )
- {
- LogisticsOneButtonDialog::instance()->update();
- if ( LogisticsOneButtonDialog::instance()->isDone() )
- {
- LogisticsOneButtonDialog::instance()->end();
- bHostLeftDlg = 0;
- bErrorDlg = 0;
- }
- }
- else if ( bShowNoMapDlg || bBootDlg || bDisconnectDlg)
- {
- LogisticsOKDialog::instance()->update();
- if ( LogisticsOKDialog::instance()->isDone() )
- {
- if ( LogisticsOKDialog::instance()->getStatus() == YES )
- {
- if ( bShowNoMapDlg )
- MPlayer->launchBrowser( MPlayer->missionSettings.url );
- else if ( bBootDlg )
- {
- MC2Player* player= MPlayer->getPlayerInfo( bootPlayerID );
- MPlayer->bootPlayer( player->player );
- }
- else if ( bDisconnectDlg )
- {
- MPlayer->closeSession();
- status = PREVIOUS;
- }
- }
- LogisticsOKDialog::instance()->end();
- if ( bShowNoMapDlg )
- {
- mapName = MPlayer->missionSettings.map;
-
- char chatStr[256];
- char final[1024];
- cLoadString( chatToSend, chatStr, 255 );
- sprintf( final, chatStr, prefs.playerName[0] );
- MPlayer->sendChat( NULL, -1, final );
- }
- bShowNoMapDlg = false;
- bBootDlg = false;
- bDisconnectDlg = false;
- }
- return;
- }
- else if ( bLoading )
- {
- mpLoadMap.update();
- if ( mpLoadMap.isDone() )
- {
- if ( mpLoadMap.getStatus() == YES )
- {
- // need to pull in this map information....
- const char* pName = mpLoadMap.getMapFileName();
- LogisticsData::instance->setCurrentMission( pName );
- // now I need to update the other people....
- setMission(pName);
- resetCheckBoxes();
-
- }
- bLoading = false;
- }
- return;
- }
- else
- {
- bool bEditHasFocus = 0;
- // disable necessary stuff
- if ( !MPlayer->isHost() )
- {
- if ( MPlayer->missionSettings.mapGuid == NO_VERSION_GUID )
- {
- checkVersionClientOnly( MPlayer->missionSettings.map );
- }
- if ( MPlayer->playerInfo[MPlayer->commanderID].leftSession ) // I've been booted!
- {
- if ( status != GOTOSPLASH )
- {
- status = GOTOSPLASH;
- beginFadeOut( .5 );
- }
- return;
- }
- for ( int i = MP_INCREMENT_DROPWEIGHT; i < MP_DECREMENT_RP+1; i++ )
- {
- aButton* pButton = getButton( i );
- if ( pButton )
- {
- pButton->showGUIWindow( 0 );
- }
- }
- for ( i = MP_DECREMENT_CBILLS+1; i < MP_RP_FORMMECHS+1; i++ )
- {
- aButton* pButton = getButton( i );
- if ( pButton )
- {
- pButton->disable( true );
- }
- }
- for ( i = 0; i < 3; i++ )
- edits[i].setReadOnly( true );
- getButton( 101/*load map button*/ )->showGUIWindow( false );
- getButton( MP_LOCKGAME )->showGUIWindow( false );
- getButton( MP_BOOTPLAYER )->showGUIWindow( false );
- if ( MPlayer->startLoading || MPlayer->startLogistics )
- {
- int faction = MPlayer->getPlayerInfo( MPlayer->commanderID )->faction;
- if ( faction < 0 )
- faction = 0;
- if ( MPlayer->missionSettings.allTech )
- LogisticsData::instance->setPurchaseFile( pPurchaseFiles[4] );
- else
- LogisticsData::instance->setPurchaseFile( pPurchaseFiles[faction] );
- LogisticsData::instance->setCurrentMission( MPlayer->missionSettings.map );
- status = NEXT;
- return;
- }
- if ( mapName != MPlayer->missionSettings.map
- && strlen( MPlayer->missionSettings.map )) // check for new map
- {
- //
- setMissionClientOnly( MPlayer->missionSettings.map );
- }
-
-
- }
- else
- {
- // make sure King of the hill missions have a time limit
- if ( MPlayer->missionSettings.timeLimit < 60 &&
- (MPlayer->missionSettings.missionType == MISSION_TYPE_KING_OF_THE_HILL
- || MPlayer->missionSettings.missionType == MISSION_TYPE_LAST_MAN_ON_THE_HILL
- || MPlayer->missionSettings.missionType == MISSION_TYPE_TERRITORIES) )
- {
- MPlayer->missionSettings.timeLimit = 300;
- }
- if ( MPlayer->missionSettings.dropWeight < 30 )
- {
- MPlayer->missionSettings.dropWeight = 30;
- }
- if ( MPlayer->missionSettings.defaultCBills < 50000 )
- {
- MPlayer->missionSettings.defaultCBills = 50000;
- MPlayer->redistributeRP();
- }
- for ( int i = MP_INCREMENT_DROPWEIGHT; i < MP_RP_FORMMECHS+1; i++ )
- {
- aButton* pButton = getButton( i );
- if ( pButton )
- {
- pButton->disable( false );
- pButton->showGUIWindow( true );
- }
- }
- for ( i = 0; i < 3; i++ )
- edits[i].setReadOnly( false );
- // see if they clicked the launch button and there are too many players
- if ( playerCount > MPlayer->missionSettings.maxPlayers )
- {
- if ( userInput->isLeftClick() &&
- getButton( MB_MSG_NEXT )->pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
- {
- char errorStr[256];
- LogisticsOneButtonDialog::instance()->setText( IDS_PLAYER_LEFT,
- IDS_DIALOG_OK, IDS_DIALOG_OK );
- cLoadString( IDS_MP_PARAM_ERROR_TOO_MANY_PLAYERS, errorStr, 255 );
- LogisticsOneButtonDialog::instance()->setText( errorStr );
- LogisticsOneButtonDialog::instance()->begin();
- bErrorDlg = true;
- }
- }
- MC2Player* data = MPlayer->getPlayerInfo( MPlayer->commanderID );
- {
- if ( data )
- data->ready = true; // default to ready for host since they have to press launch anyway
- else
- return;
- }
- getButton( 101/*load map button*/ )->showGUIWindow( true );
- //now check for specifics...
- bool bDisable = MPlayer->missionSettings.timeLimit <= 0;
- getButton( MP_DECREMENT_TIME )->disable( bDisable );
- bDisable = MPlayer->missionSettings.timeLimit >= 3600.f;
- getButton( MP_INCREMENT_TIME )->disable( bDisable );
- bDisable = MPlayer->missionSettings.resourcePoints <= 0;
- getButton( MP_DECREMENT_RP )->disable( bDisable );
- bDisable = MPlayer->missionSettings.resourcePoints >= 99900.f;
- getButton( MP_INCREMENT_RP )->disable( bDisable );
-
- bDisable = MPlayer->missionSettings.defaultCBills <= 50000;
- getButton( MP_DECREMENT_CBILLS )->disable( bDisable );
- bDisable = MPlayer->missionSettings.defaultCBills >= 999000.f;
- getButton( MP_INCREMENT_CBILLS )->disable( bDisable );
- bDisable = MPlayer->missionSettings.dropWeight <= 30;
- getButton( MP_DECREMENT_DROPWEIGHT )->disable( bDisable );
- bDisable = MPlayer->missionSettings.dropWeight >= 1200.f;
- getButton( MP_INCREMENT_DROPWEIGHT )->disable( bDisable );
- getButton( MP_QUICKSTART )->disable( 0 );
- getButton( MP_LOCKGAME )->showGUIWindow( true );
- getButton( MP_BOOTPLAYER )->showGUIWindow( true );
- getButton( MP_BOOTPLAYER )->disable( false );
- for( i = 0; i < playerCount; i++ )
- {
- if ( playerParameters[i].hasFocus() )
- {
- if ( playerParameters[i].getCommanderID() == MPlayer->commanderID )
- getButton( MP_BOOTPLAYER )->disable( true );
- }
- }
-
-
- }
-
- int oldEditFocus = -1;
- for ( int i = 0; i < editCount; i++ )
- {
- if ( edits[i].hasFocus() )
- oldEditFocus = i;
- }
- if ( !ChatWindow::instance()->pointInside(userInput->getMouseX(), userInput->getMouseY()) )
- {
- LogisticsScreen::update();
- }
- if ( oldEditFocus != -1 )
- {
- bEditHasFocus = true;
- if ( !edits[oldEditFocus].hasFocus() )
- {
- EString text;
- edits[oldEditFocus].getEntry( text );
- long val = atoi( text );
- switch (oldEditFocus)
- {
- case 0:
- MPlayer->missionSettings.dropWeight = val;
- MPParameterScreen::resetCheckBoxes();
- break;
- case 1:
- MPlayer->missionSettings.defaultCBills = val * 1000;
- if (MPlayer->isHost())
- MPlayer->redistributeRP();
- MPParameterScreen::resetCheckBoxes();
-
- break;
- case 2:
- MPlayer->missionSettings.timeLimit = val * 60;
- MPParameterScreen::resetCheckBoxes();
- break;
- case 3:
- MPlayer->missionSettings.resourcePoints = val;
- MPParameterScreen::resetCheckBoxes();
- break;
- }
- }
- }
-
- /// now make all enabled so they draw correctly...
- for ( i = MP_AIRSTRIKES; i < MP_RP_FORMMECHS+1; i++ )
- {
- aButton* pButton = getButton( i );
- if ( pButton )
- {
- pButton->disable( false );
- }
- }
- getButton( MP_QUICKSTART )->disable( 0 );
- if ( MPlayer )
- {
- int oldPlayerCount = playerCount;
- const MC2Player* players = MPlayer->getPlayers(playerCount);
-
- if ( oldPlayerCount != playerCount )
- {
- // new player... need to redistribute rp
- int maxCommander = -1;
- int teamID = -1;
- for( int i = 0; i < playerCount; i++ )
- {
- if ( players[i].commanderID > maxCommander )
- {
- maxCommander = players[i].commanderID;
- teamID = players[i].team;
- }
- }
- }
- bool bReady = true;
-
- const MC2Player* sortedPlayers[MAX_MC_PLAYERS];
- for ( int i = 0; i < playerCount; i++ )
- {
- sortedPlayers[i] = &players[i];
- }
- qsort( sortedPlayers, playerCount, sizeof( MC2Player* ), sortPlayers );
- for( i = 0; i < playerCount; i++ )
- {
- playerParameters[i].setData( sortedPlayers[i] );
- }
- int team = -1;
- if ( playerCount )
- team = sortedPlayers[0]->team;
- bool bUniqueTeam = 0;
- for( i = 0; i < playerCount; i++ )
- {
- // if ( !ChatWindow::instance()->pointInside(userInput->getMouseX(), userInput->getMouseY() ) )
- playerParameters[i].update();
- bReady &= sortedPlayers[i]->ready;
- if ( !MPlayer->missionSettings.quickStart )
- bReady &= ((sortedPlayers[i]->cBills) ? 1 : 0);
- if ( playerParameters[i].hasFocus() )
- bEditHasFocus = true;
- if ( sortedPlayers[i]->team != team )
- bUniqueTeam = 1;
- }
- bReady &= !bEditHasFocus;
- bReady &= (MPlayer->isHost());
- bReady &= strlen( MPlayer->missionSettings.map ) ? 1 : 0;
- bReady &= (playerCount > 1);
- bReady &= (MPlayer->missionSettings.maxPlayers >= playerCount);
- bReady &= bUniqueTeam;
- bReady &= (MPlayer->missionSettings.dropWeight >= 30);
- bool bPress = MPlayer->missionSettings.airStrike;
- getButton( MP_AIRSTRIKES )->press( bPress );
- bPress = MPlayer->missionSettings.sensorProbe;
- getButton( MP_SENSOR_PROBE )->press( bPress );
- bPress = MPlayer->missionSettings.mineLayer;
- getButton( MP_MINELAYER )->press( bPress );
- bPress = MPlayer->missionSettings.repairVehicle;
- getButton( MP_REPAIR )->press( bPress );
- bPress = MPlayer->missionSettings.scoutCopter;
- getButton( MP_SCOUTS )->press( bPress );
- bPress = MPlayer->missionSettings.recoveryTeam;
- getButton( MP_RECOVERY )->press( bPress );
- bPress = MPlayer->missionSettings.guardTower;
- getButton( MP_GUARDTOWER )->press( bPress );
- bPress = MPlayer->missionSettings.resourceBuilding;
- getButton( MP_RESOURCE_BLDG )->press( bPress );
- bPress = MPlayer->missionSettings.unlimitedAmmo;
- getButton( MP_UNLIMITED_AMMO )->press( bPress );
- bPress = !MPlayer->missionSettings.variants;
- getButton( MP_VARIANTS )->press( bPress );
- bPress = MPlayer->missionSettings.allTech;
- getButton( MP_ALLTECH )->press( bPress );
- bPress = MPlayer->missionSettings.resourceForMechs;
- getButton( MP_RP_FORMMECHS )->press( bPress );
- bPress = MPlayer->missionSettings.quickStart;
- getButton( MP_QUICKSTART )->press( bPress );
- bPress = MPlayer->missionSettings.locked;
- getButton( MP_LOCKGAME )->press( bPress );
- if ( !strlen(MPlayer->missionSettings.map) )
- {
- getButton( MAP_INFO )->disable( true );
- }
- // else
- // getButton( MAP_INFO )->disable( false );
-
- textObjects[1].setText( MPlayer->missionSettings.name );
-
- // cLoadString( IDS_MP_LM_MAP_LIST_TYPE, tmp, 255 );
- // cLoadString( IDS_MP_LM_TYPE0 + MPlayer->missionSettings.missionType, tmp2, 127 );
- // sprintf( text, tmp, tmp2 );
- // textObjects[7].setText( text );
- sprintf( text, "%ldk", MPlayer->missionSettings.defaultCBills/1000 );
- if ( !edits[1].hasFocus() )
- edits[1].setEntry( text );
- sprintf( text, "%ld", MPlayer->missionSettings.resourcePoints );
- if ( !edits[3].hasFocus() )
- edits[3].setEntry( text );
- sprintf( text, "%.0lf", fabs(MPlayer->missionSettings.timeLimit/60.f) );
- if ( !edits[2].hasFocus() )
- {
- if ( MPlayer->missionSettings.timeLimit/60.f <= 0 )
- cLoadString( IDS_MP_PARAM_UNLIMITED, text, 255 );
- edits[2].setEntry( text );
- }
- sprintf( text, "%ld", MPlayer->missionSettings.dropWeight );
- if ( !edits[0].hasFocus() )
- edits[0].setEntry( text );
- if ( bReady )
- {
- getButton( MB_MSG_NEXT )->disable( false );
- }
- else
- {
- getButton( MB_MSG_NEXT )->disable( true );
- if ( delayTime )
- {
- char text[256];
- cLoadString( IDS_MP_LAUNCH_ABORTED, text, 255 );
- MPlayer->sendChat( 0, -1, text );
- delayTime = 0.f;
- bWaitingToStart = 0;
- MPlayer->setInProgress( 0 );
- }
- }
-
- }
- if ( !bEditHasFocus )
- ChatWindow::instance()->update();
- }
- helpTextID = 0;
- helpTextHeaderID = 0;
- /*
- for ( int i = 0; i < buttonCount; i++ )
- {
- buttons[i].update();
- if ( buttons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() )
- && userInput->isLeftClick() )
- {
- handleMessage( buttons[i].getID(), buttons[i].getID() );
- }
- }
- */
- }
- GUID MPParameterScreen::getGUIDFromFile( const char* pNewMapName)
- {
- GUID retVal;
- memset( &retVal, 0xff, sizeof( GUID ) );
- FullPathFileName path;
- path.init( missionPath, pNewMapName, ".pak" );
- PacketFile pakFile;
- if ( NO_ERR != pakFile.open( (char*)(const char*)path ) )
- {
- return retVal;
- }
- int packetCount = pakFile.getNumPackets();
- pakFile.seekPacket( packetCount - 1 );
- if ( sizeof( GUID ) == pakFile.getPacketSize( ) )
- {
- pakFile.readPacket( packetCount - 1, (unsigned char*)&retVal );
- return retVal;
- }
- else
- {
- memset( &retVal, 0, sizeof( GUID ) );
- return retVal;
- }
- }
- void MPParameterScreen::setMissionClientOnly( const char* pNewMapName )
- {
- FullPathFileName path;
- path.init( missionPath, pNewMapName, ".fit" );
- FitIniFile missionFile;
-
- if ( NO_ERR != missionFile.open( (char*)(const char*)path ) )
- {
- char tmp[256];
- char final[1024];
- cLoadString( IDS_MP_PARAM_NO_MAP, tmp, 255 );
- sprintf( final, tmp, MPlayer->missionSettings.map, MPlayer->missionSettings.url );
- LogisticsOKDialog::instance()->setFont(IDS_MP_PARAM_NO_MAP_FONT);
- LogisticsOKDialog::instance()->setText( final );
- LogisticsOKDialog::instance()->begin();
- bShowNoMapDlg = true;
- getButton( MAP_INFO )->disable( true );
- chatToSend = IDS_MP_PARAMETER_NO_MAP_CHAT;
- statics[15].setColor( 0 );
- return;
- }
- checkVersionClientOnly( pNewMapName );
- getButton( MAP_INFO )->disable( false );
- long textureHandle = MissionBriefingScreen::getMissionTGA( pNewMapName );
- if ( textureHandle )
- {
- statics[15].setTexture( textureHandle );
- statics[15].setUVs( 0, 127, 127, 0 );
- statics[15].setColor( 0xffffffff );
- }
- mapName = MPlayer->missionSettings.map;
- }
- void MPParameterScreen::checkVersionClientOnly( const char* pNewMapName )
- {
- GUID version = getGUIDFromFile( pNewMapName );
- if ( MPlayer->missionSettings.mapGuid != NO_VERSION_GUID &&
- version != MPlayer->missionSettings.mapGuid && version != NO_VERSION_GUID) // if 0 it simply wasn't in the file at all, should take this out as soon as maps are resaved
- {
- char tmp[256];
- char final[1024];
- cLoadString( IDS_MP_PARAM_MAP_WRONG_VERSION, tmp, 255 );
- sprintf( final, tmp, MPlayer->missionSettings.url );
- LogisticsOKDialog::instance()->setFont(IDS_MP_PARAM_NO_MAP_FONT);
- LogisticsOKDialog::instance()->setText( final );
- LogisticsOKDialog::instance()->begin();
- bShowNoMapDlg = true;
- getButton( MAP_INFO )->disable( true );
- chatToSend = IDS_MAP_WRONG_VERSION_CHAT;
- statics[15].setColor( 0 );
- // need to disable the ready button
- for( int i = 0; i < MAX_MC_PLAYERS; i++ )
- {
- if ( playerParameters[i].getCommanderID() == MPlayer->commanderID )
- {
- playerParameters[i].disableReadyButton();
- break;
- }
- }
- }
- }
- void MPParameterScreen::resetCheckBoxes()
- {
- if ( MPlayer->isHost() )
- {
- long playerCount = 0;
- const MC2Player* players = MPlayer->getPlayers(playerCount);
- for ( int i = 0; i < playerCount; i++ )
- {
- MC2Player* pWrite = MPlayer->getPlayerInfo( players[i].commanderID );
- if ( pWrite->commanderID != MPlayer->commanderID )
- pWrite->ready = 0;
-
- }
- }
- }
- void MPParameterScreen::setHostLeftDlg( const char* playerName )
- {
- char leaveStr[256];
- char formatStr[256];
- cLoadString( IDS_PLAYER_LEFT, leaveStr, 255 );
- sprintf( formatStr, leaveStr, playerName );
- LogisticsOneButtonDialog::instance()->setText( IDS_PLAYER_LEFT,
- IDS_DIALOG_OK, IDS_DIALOG_OK );
- LogisticsOneButtonDialog::instance()->setText( formatStr );
- LogisticsOneButtonDialog::instance()->begin();
- bHostLeftDlg = true;
- }
- aPlayerParams::aPlayerParams()
- {
- statics = 0;
- rects = 0;
- textObjects = 0;
- staticCount = rectCount = textCount = 0;
- bHasFocus = 0;
- }
- aPlayerParams::~aPlayerParams()
- {
- destroy();
- }
- aPlayerParams& aPlayerParams::operator=( const aPlayerParams& src )
- {
- aObject::operator=( src );
- addChild(&ReadyButton);
- addChild( &CBillsSpinnerDownButton );
- addChild( &CBillsSpinnerUpButton );
- addChild( &edit );
- ReadyButton = src.ReadyButton;
- CBillsSpinnerDownButton = src.CBillsSpinnerDownButton;
- CBillsSpinnerUpButton = src.CBillsSpinnerUpButton;
- edit = src.edit;
- insigniaName = src.insigniaName;
- templateItem = src.templateItem;
- staticCount = src.staticCount;
- if ( staticCount )
- {
- statics = new aObject[staticCount];
- for ( int i = 0; i < staticCount; i++ )
- {
- addChild( &statics[i] );
- statics[i] = src.statics[i];
- }
- }
- rectCount = src.rectCount;
- if ( rectCount )
- {
- rects = new aRect[rectCount];
- for ( int i = 0; i < rectCount; i++ )
- {
- addChild( &rects[i] );
- rects[i] = src.rects[i];
- }
- }
- textCount = src.textCount;
- if ( textCount )
- {
- textObjects = new aText[textCount];
- for ( int i = 0; i < textCount; i++ )
- {
- addChild( &textObjects[i] );
- textObjects[i] = src.textObjects[i];
- }
- }
- addChild(&teamNumberDropList);
- teamNumberDropList = src.teamNumberDropList;
- addChild( &factionDropList );
- factionDropList = src.factionDropList;
- return *this;
- }
- long aPlayerParams::init(long xPos, long yPos,long w, long h )
- {
- long err;
-
- err = aObject::init(xPos,yPos,w,h);
- if (err)
- return err;
- if ( !MPlayer->isHost() )
- {
- CBillsSpinnerDownButton.showGUIWindow( 0 );
- CBillsSpinnerUpButton.showGUIWindow( 0 );
- }
-
- return (NO_ERR);
- }
- void aPlayerParams::init( FitIniFile* pFile, const char* blockNameParam )
- {
- FitIniFile &file = (*pFile);
- pFile->seekBlock(blockNameParam);
- ReadyButton.init( file, "PlayerParamsReadyButton" );
- CBillsSpinnerDownButton.init( file, "PlayerParamsCBillsSpinnerDownButton" );
- CBillsSpinnerUpButton.init( file, "PlayerParamsCBillsSpinnerUpButton" );
- addChild(&ReadyButton);
- addChild( &CBillsSpinnerDownButton );
- addChild( &CBillsSpinnerUpButton );
- edit.init( pFile, "playerparamEdit0" );
- edit.setNumeric( true );
- edit.limitEntry( 3 );
- edit.allowIME( 0 );
- addChild( &edit );
- CBillsSpinnerDownButton.setPressFX( LOG_VIDEOBUTTONS );
- CBillsSpinnerUpButton.setPressFX( LOG_VIDEOBUTTONS );
- ReadyButton.setPressFX( LOG_VIDEOBUTTONS );
- CBillsSpinnerDownButton.setHighlightFX( LOG_DIGITALHIGHLIGHT );
- CBillsSpinnerUpButton.setHighlightFX( LOG_DIGITALHIGHLIGHT );
- ReadyButton.setHighlightFX( LOG_DIGITALHIGHLIGHT );
- CBillsSpinnerDownButton.setDisabledFX( LOG_WRONGBUTTON );
- CBillsSpinnerUpButton.setDisabledFX( LOG_WRONGBUTTON );
- ReadyButton.setDisabledFX( LOG_WRONGBUTTON );
- const char* staticName = "PlayerParamsStatic";
- const char* textName = "PlayerParamsText";
- const char* rectName = "PlayerParamsRect";
- char blockName[256];
- // init statics
- if ( staticName )
- {
- sprintf( blockName, "%s%c", staticName, 's' );
- if ( NO_ERR == file.seekBlock( blockName ) )
- {
- file.readIdLong( "staticCount", staticCount );
- if ( staticCount )
- {
- statics = new aObject[staticCount];
- char blockName[128];
- for ( int i = 0; i < staticCount; i++ )
- {
- sprintf( blockName, "%s%ld", staticName, i );
- statics[i].init( &file, blockName );
- addChild(&(statics[i]));
- }
-
- }
- }
- }
- if ( rectName )
- {
- // init rects
- sprintf( blockName, "%s%c", rectName, 's' );
- if ( NO_ERR == file.seekBlock( blockName ) )
- {
- file.readIdLong( "rectCount", rectCount );
- if ( rectCount )
- {
- rects = new aRect[rectCount];
- char blockName[128];
- for ( int i = 0; i < rectCount; i++ )
- {
- sprintf( blockName, "%s%ld", rectName, i );
- rects[i].init( &file, blockName );
- addChild(&(rects[i]));
- }
- }
- }
- }
- // init texts
- if ( textName )
- {
- sprintf( blockName, "%s%c", textName, 's' );
- if ( NO_ERR == file.seekBlock( blockName ) )
- {
- if ( NO_ERR != file.readIdLong( "TextEntryCount", textCount ) )
- file.readIdLong( "TextCount", textCount );
- if ( textCount )
- {
- textObjects = new aText[textCount];
- char blockName[64];
- for ( int i = 0; i < textCount; i++ )
- {
- sprintf( blockName, "%s%ld", textName, i );
- textObjects[i].init( &file, blockName );
- addChild(&(textObjects[i]));
- }
-
- }
- }
- }
-
-
- {
- char path[256];
- strcpy( path, artPath );
- strcat( path, "mcl_mp_param_droplist3.fit" );
-
- FitIniFile PNfile;
- if ( NO_ERR != PNfile.open( path ) )
- {
- char error[256];
- sprintf( error, "couldn't open file %s", path );
- Assert( 0, 0, error );
- return;
- }
- teamNumberDropList.init(&PNfile, "TeamNumberDropList");
- teamNumberDropList.ListBox().setOrange( true );
- PNfile.seekBlock( "Text0" );
- templateItem.init(&PNfile, "Text0" );
-
- }
- addChild(&teamNumberDropList);
- {
- char path[256];
- strcpy( path, artPath );
- strcat( path, "mcl_mp_param_droplist4.fit" );
-
- FitIniFile PNfile;
- if ( NO_ERR != PNfile.open( path ) )
- {
- char error[256];
- sprintf( error, "couldn't open file %s", path );
- Assert( 0, 0, error );
- return;
- }
- factionDropList.init(&PNfile, "FactionTypeDropList");
- factionDropList.ListBox().setOrange( true );
- int i;
- for (i = 0; i < 4; i += 1)
- {
- aStyle2TextListItem *pTmp2;
- pTmp2 = new aStyle2TextListItem;
- *pTmp2 = templateItem;
- pTmp2->setText( IDS_FACTION0 + i );
- pTmp2->resize( factionDropList.width() -
- factionDropList.ListBox().getScrollBarWidth() - 8,
- pTmp2->height() );
- pTmp2->sizeToText();
- factionDropList.AddItem(pTmp2);
- }
- factionDropList.SelectItem(0);
- }
- addChild(&factionDropList);
- // resize after we include drop lists
- if (true)
- {
- float x = 1000000.0;
- float y = 1000000.0;
- float w = 0.0;
- float h = 0.0;
- int i;
- for (i = 0; i < numberOfChildren(); i += 1)
- {
- aObject *pChild = child(i);
- if (x > pChild->globalX())
- {
- x = pChild->globalX();
- }
- if (y > pChild->globalY())
- {
- y = pChild->globalY();
- }
- if (w < pChild->globalRight() )
- {
- w = (pChild->globalRight());
- }
- if (h < pChild->globalBottom() - pChild->globalTop() )
- {
- h = (pChild->globalBottom() - pChild->globalTop());
- }
- }
- resize( w, h );
- moveToNoRecurse( x, y );
- }
- }
- bool aPlayerParams::hasFocus( )
- {
- if ( edit.hasFocus() )
- return true;
- if ( factionDropList.ListBox().isShowing() )
- return true;
- if ( teamNumberDropList.ListBox().isShowing() )
- return true;
- return false;
- }
- void aPlayerParams::destroy()
- {
- removeAllChildren();
- if ( statics )
- delete [] statics;
- if ( rects )
- delete [] rects;
- if ( textObjects )
- delete [] textObjects;
- statics = 0;
- rects = 0;
- textObjects = 0;
- aObject::destroy();
- }
- void aPlayerParams::update()
- {
- if ( !MPlayer->isHost() )
- {
- CBillsSpinnerDownButton.showGUIWindow( 0 );
- CBillsSpinnerUpButton.showGUIWindow( 0 );
- }
- if ( userInput->isLeftClick() )
- {
- if ( pointInside( userInput->getMouseX(), userInput->getMouseY() )
- || factionDropList.pointInside( userInput->getMouseX(), userInput->getMouseY())
- || teamNumberDropList.pointInside( userInput->getMouseX(), userInput->getMouseY()))
- bHasFocus = true;
- else
- bHasFocus = false;
- }
- if ( MPlayer->missionSettings.allTech )
- {
- if ( factionDropList.ListBox().GetItemCount() != 1 )
- {
- factionDropList.SelectItem( -1 );
- factionDropList.ListBox().removeAllItems( true );
- aStyle2TextListItem *pTmp2;
- pTmp2 = new aStyle2TextListItem;
- *pTmp2 = templateItem;
- pTmp2->setText( IDS_FACTION0 + 5 );
- pTmp2->resize( factionDropList.width() -
- factionDropList.ListBox().getScrollBarWidth() - 8,
- pTmp2->height() );
- pTmp2->sizeToText();
- factionDropList.AddItem(pTmp2);
- factionDropList.SelectItem( 0 );
- }
- }
- else if ( factionDropList.ListBox().GetItemCount() < 4 )
- {
- factionDropList.SelectItem( -1 );
- factionDropList.ListBox().removeAllItems( true );
- for ( int i = 0; i < 4; i += 1)
- {
- aStyle2TextListItem *pTmp2;
- pTmp2 = new aStyle2TextListItem;
- *pTmp2 = templateItem;
- pTmp2->setText( IDS_FACTION0 + i );
- pTmp2->resize( factionDropList.width() -
- factionDropList.ListBox().getScrollBarWidth() - 8,
- pTmp2->height() );
- pTmp2->sizeToText();
- factionDropList.AddItem(pTmp2);
- factionDropList.SelectItem( 0 );
- }
- }
- // don't accept any kind of input for anything but your own stuff....
- if ( commanderID != MPlayer->commanderID && !MPlayer->isHost() )
- {
- CBillsSpinnerUpButton.showGUIWindow( 0 );
- CBillsSpinnerDownButton.showGUIWindow( 0 );
- teamNumberDropList.disable( true );
- factionDropList.disable( true );
- rects[2].showGUIWindow( 0 );
- rects[7].showGUIWindow( 0 );
- rects[8].showGUIWindow( 0 );
- rects[1].showGUIWindow( 0 );
- return;
- }
- else
- {
- if ( MPlayer->isHost() )
- {
- CBillsSpinnerUpButton.showGUIWindow( 1 );
- CBillsSpinnerDownButton.showGUIWindow( 1 );
- }
- else
- {
- CBillsSpinnerUpButton.showGUIWindow( 0 );
- CBillsSpinnerDownButton.showGUIWindow( 0 );
- }
- teamNumberDropList.disable( 0 );
- factionDropList.disable( 0 );
- rects[2].showGUIWindow( 1 );
- rects[7].showGUIWindow( 1 );
- rects[8].showGUIWindow( 1 );
- rects[1].showGUIWindow( 1 );
- }
- if ( commanderID == MPlayer->commanderID )
- {
- if ( !MPlayer->isHost() )
- {
- FullPathFileName path;
- path.init( missionPath, MPlayer->missionSettings.map, ".fit" );
- if ( !fileExists( path ) ||
- MPParameterScreen::getGUIDFromFile( MPlayer->missionSettings.map ) != MPlayer->missionSettings.mapGuid ) // disable the ready button if the map isn't around...
- {
- ReadyButton.disable( false );
- ReadyButton.press( 0 );
- ReadyButton.disable( true );
- }
- else
- ReadyButton.disable( false );
- }
- }
- if ( !bHasFocus )
- return;
- bool bOldReady = ReadyButton.isPressed();
- if ( bOldReady ) // need to check the ready button if nothing else
- {
- ReadyButton.update();
- }
- // need to check for changes
- int oldSel = teamNumberDropList.GetSelectedItem();
- int oldFaction = factionDropList.GetSelectedItem();
- const char* pText = textObjects[1].text;
-
- long oldCBills = 0;
-
- if ( pText )
- {
- oldCBills = atoi( pText ) * 1000;
- }
-
- bool bCBillsChanged = 0;
- if ( !bOldReady || ( MPlayer->isHost() ) ) // don't do anything if all ready.
- {
- if ( (commanderID == MPlayer->commanderID || MPlayer->isHost() ) )
- {
- edit.setReadOnly( 0 );
- bool bHasFocus = edit.hasFocus();
- edit.update();
- if ( bHasFocus && !edit.hasFocus() )
- bCBillsChanged = true;
- if ( commanderID == MPlayer->commanderID )
- ReadyButton.update();
- CBillsSpinnerDownButton.update();
- CBillsSpinnerUpButton.update( );
- factionDropList.update();
- teamNumberDropList.update();
- }
- }
- else
- edit.setReadOnly( 1 );
- int newSel = teamNumberDropList.GetSelectedItem();
- int newFaction = factionDropList.GetSelectedItem();
- bool bNewReady = ReadyButton.isPressed();
- EString cBillsText;
- edit.getEntry( cBillsText );
- long newCBills = 0;
- if ( cBillsText.Length() )
- {
- newCBills = atoi( cBillsText ) * 1000;
- }
- if ( bCBillsChanged )
- {
- MC2Player* pInfo = MPlayer->getPlayerInfo( commanderID );
- pInfo->cBills = newCBills;
- MPlayer->sendPlayerUpdate( 0, 5, commanderID );
-
- char text[256];
- sprintf(text, "%ld", pInfo->cBills/5000 * (5) ); // need to round to nearest 5000
- edit.setEntry( text );
- MPParameterScreen::resetCheckBoxes();
- }
- else if ( (oldSel != newSel) || (oldFaction != newFaction) ||
- (bOldReady != bNewReady) )
- {
- // send out new info....
- if ( MPlayer )
- {
-
- MC2Player* pInfo = MPlayer->getPlayerInfo( commanderID );
- pInfo->cBills = newCBills;
- if ( MPlayer->isHost() )
- pInfo->ready = 0;
- else
- pInfo->ready = bNewReady;
- pInfo->faction = newFaction;
- if (MPlayer->isHost())
- {
- if (pInfo->team != newSel)
- MPlayer->setPlayerTeam(commanderID, newSel);
- }
- else {
- pInfo->team = newSel;
- MPlayer->sendPlayerUpdate( 0, 5, commanderID );
- }
-
- }
- bHasFocus = 0;
- }
- if ( userInput->getKeyDown( KEY_RETURN ) )
- bHasFocus = false;
- }
- void aPlayerParams::disableReadyButton()
- {
- ReadyButton.disable( true );
- }
- void aPlayerParams::setData( const _MC2Player* data)
- {
- bool bDisable = ( data->cBills <= 0 );
- CBillsSpinnerDownButton.disable( bDisable );
- bDisable = ( data->cBills >= 1000000 );
- CBillsSpinnerUpButton.disable( bDisable );
- if ( data->ready )
- {
- if ( data->commanderID != MPlayer->commanderID )
- ReadyButton.disable( false );
- ReadyButton.press( 1 );
- }
- else
- {
- if ( ReadyButton.isPressed() )
- soundSystem->playDigitalSample( LOG_UNREADY );
- ReadyButton.press( 0 );
- }
- commanderID = data->commanderID;
- long textColor = 0xff000000;
- long newColor = MPlayer->colors[data->baseColor[BASECOLOR_TEAM]];
- if ( ((newColor & 0xff) + ( (newColor & 0xff00)>>8 ) + ( (newColor & 0xff0000)>>16 ))/3 < 85 )
- textColor = 0xffffffff;
- if ( textObjects )
- {
- textObjects[0].setText( data->name );
- textObjects[1].setText( data->unitName );
- textObjects[0].setColor( textColor );
- textObjects[1].setColor( textColor );
- char text[256];
- sprintf(text, "%ld", data->cBills/5000 * 5 );
- if ( !edit.hasFocus() )
- edit.setEntry( text );
- }
- rects[4].setColor( MPlayer->colors[data->stripeColor] );
- rects[6].setColor( MPlayer->colors[data->baseColor[BASECOLOR_TEAM]] );
- // set up the insignia...
- // I really need to store this... really don't want to allocate a texture every time
- const char* pFileName = data->insigniaFile;
- if ( pFileName != insigniaName )
- {
- FullPathFileName path;
- path.init( "data\\multiplayer\\insignia\\", data->insigniaFile, ".tga" );
- if ( fileExists( path ) )
- {
- statics[0].setTexture( path );
- statics[0].setUVs( 0, 0, 32, 32 );
- insigniaName = pFileName;
- MPlayer->insigniaList[data->commanderID] = 1;
- }
- }
- if ( !teamNumberDropList.IsExpanded() )
- {
- int oldSel = teamNumberDropList.ListBox().GetSelectedItem();
- if ( teamNumberDropList.ListBox().GetItemCount() != MPlayer->missionSettings.maxTeams )
- {
- teamNumberDropList.ListBox().removeAllItems( true );
- for ( int i = 0; i < MPlayer->missionSettings.maxTeams; i ++ )
- {
- aStyle2TextListItem* pTmp2 = new aStyle2TextListItem;
- char tmpStr[32];
- sprintf(tmpStr, "%ld", i+1);
- *pTmp2 = templateItem;
- pTmp2->setText( tmpStr );
- pTmp2->resize( teamNumberDropList.width() -
- teamNumberDropList.ListBox().getScrollBarWidth() - 8, pTmp2->height() );
- pTmp2->sizeToText();
- teamNumberDropList.AddItem(pTmp2);
- }
- if ( oldSel < teamNumberDropList.ListBox().GetItemCount() )
- teamNumberDropList.SelectItem(oldSel);
- else
- teamNumberDropList.SelectItem(0);
- }
- teamNumberDropList.SelectItem( data->team );
- }
- if ( !factionDropList.IsExpanded() )
- {
- factionDropList.SelectItem( data->faction );
- }
-
- }
- int aPlayerParams::handleMessage( unsigned long message, unsigned long who )
- {
- float increment = 5000;
- if ( message == aMSG_LEFTMOUSEHELD )
- {
- increment = 1000;
- }
- switch( who )
- {
-
- case MP_INCREMENT_PLAYER_CBILLS:
- {
-
- MC2Player* pInfo = MPlayer->getPlayerInfo( commanderID );
- pInfo->cBills += increment;
-
- char text[256];
- sprintf(text, "%ld", pInfo->cBills/5000 * (5) ); // need to round to nearest 5000
- edit.setEntry( text );
- MPParameterScreen::resetCheckBoxes();
-
- break;
- }
- case MP_DECREMENT_PLAYER_CBILLS:
- {
- MC2Player* pInfo = MPlayer->getPlayerInfo( commanderID );
- pInfo->cBills -= increment;
- char text[256];
- sprintf(text, "%ld", pInfo->cBills/5000 * (5) );
- edit.setEntry( text );
- MPParameterScreen::resetCheckBoxes();
- }
- break;
- }
- return 0;
- }
- void aPlayerParams::render()
- {
- aObject::render();
- }
- void aPlayerParams::move( float offsetX, float offsetY )
- {
- aObject::move( offsetX, offsetY );
- }
- long aStyle2TextListItem::init( FitIniFile* file, const char* blockName )
- {
- file->seekBlock( blockName );
- long fontResID = 0;
- file->readIdLong( "Font", fontResID );
- long textID = 0;
- file->readIdLong( "TextID", textID );
- aTextListItem::init(fontResID);
- setText(textID);
- long color = 0xff808080;
- file->readIdLong( "Color", color );
- normalColor = color;
- setColor(color);
- char tmpStr[64];
- strcpy(tmpStr, "");
- file->readIdString( "Animation", tmpStr, 63 );
- if (0 == strcmp("", tmpStr))
- {
- hasAnimation = false;
- }
- else
- {
- hasAnimation = true;
- animGroup.init(file, tmpStr);
- }
- return 0;
- }
- void aStyle2TextListItem::render()
- {
- long color = normalColor;
- if ( hasAnimation )
- {
- if ( animGroup.getState() != getState() )
- animGroup.setState( (aAnimGroup::STATE)(long)getState() );
- animGroup.update();
- color = animGroup.getCurrentColor( animGroup.getState() );
- }
- /* if (aListItem::SELECTED == getState())
- {
- color = 0.33 * ((unsigned long)normalColor) + 0.67 * ((unsigned long)0xffffffff);
- }
- else if (aListItem::HIGHLITE == getState())
- {
- color = 0.67 * ((unsigned long)normalColor) + 0.33 * ((unsigned long)0xffffffff);
- }
- else
- {
- color = normalColor;
- }*/
- aTextListItem::setColor((unsigned long)color);
- aTextListItem::render();
- }
- CFocusManager::CFocusManager()
- {
- clear();
- }
- void CFocusManager::clear()
- {
- speciesOfTheControlWhichHasTheFocus = CS_NONE;
- pDropListThatHasTheFocus = NULL;
- listOfDropListPointers.Clear();
- }
- void *CFocusManager::registerDropList(aDropList &DropList)
- {
- listOfDropListPointers.Append(&DropList);
- return ((void *)&DropList);
- }
- void CFocusManager::unregisterDropList(aDropList &DropList)
- {
- listOfDropListPointers.Delete(listOfDropListPointers.Find(&DropList));
- }
- void CFocusManager::update()
- {
- if (userInput->isLeftClick())
- {
- /*focus may have changed*/
- if (NULL != pControlThatHasTheFocus())
- {
- if (pControlThatHasTheFocus()->pointInside(userInput->getMouseX(), userInput->getMouseY()))
- {
- /*the pointer was clicked on the control that already has the focus, so the focus
- is unaffected*/
- return;
- }
- }
- /*reset focus*/
- switch (speciesOfTheControlWhichHasTheFocus)
- {
- case CS_DROPLIST:
- pDropListThatHasTheFocus = NULL;
- break;
- }
- speciesOfTheControlWhichHasTheFocus = CS_NONE;
- /*check the droplists to see the pointer was clicked in one of them*/
- CListOfDropListPointers::EIterator DropListIter = listOfDropListPointers.Begin();
- while (!DropListIter.IsDone())
- {
- if ((*DropListIter)->pointInside(userInput->getMouseX(), userInput->getMouseY()))
- {
- pDropListThatHasTheFocus = (*DropListIter);
- speciesOfTheControlWhichHasTheFocus = CS_DROPLIST;
- break;
- }
- DropListIter++;
- }
- if (CS_NONE == speciesOfTheControlWhichHasTheFocus)
- {
- /*No droplist got the focus. Check the other control species.*/
- }
- /*make sure all drop lists that do not have focus are unexpanded*/
- DropListIter = listOfDropListPointers.Begin();
- while (!DropListIter.IsDone())
- {
- if ((CS_DROPLIST != speciesOfTheControlWhichHasTheFocus)
- || ((*DropListIter) != pDropListThatHasTheFocus))
- {
- (*DropListIter)->IsExpanded(false);
- }
- DropListIter++;
- }
- }
- }
- bool CFocusManager::somebodyHasTheFocus()
- {
- if (CS_NONE == speciesOfTheControlWhichHasTheFocus)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- aObject *CFocusManager::pControlThatHasTheFocus()
- {
- if (CS_NONE != speciesOfTheControlWhichHasTheFocus)
- {
- switch(speciesOfTheControlWhichHasTheFocus)
- {
- case CS_DROPLIST:
- return pDropListThatHasTheFocus;
- break;
- }
- assert(false);
- }
- return NULL;
- }
- //////////////////////////////////////////////
- //*************************************************************************************************
- // end of file ( MPParameterScreen.cpp )
|