12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- /*************************************************************************************************\
- MechBayScreen.cpp : Implementation of the MechBayScreen component.
- //---------------------------------------------------------------------------//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- \*************************************************************************************************/
- #include "MechBayScreen.h"
- #include "LogisticsMech.h"
- #include "LogisticsData.h"
- #include "LogisticsMechIcon.h"
- #include "..\resource.h"
- #include "SimpleCamera.h"
- #include "windows.h"
- #include "gameSound.h"
- #include "multPlyr.h"
- #include "ChatWindow.h"
- #include "Prefs.h"
- MechBayScreen* MechBayScreen::s_instance = NULL;
- MechBayScreen::MechBayScreen() : mechListBox( 1, 0 )
- {
- pCurMech = NULL;
- pIcons = NULL;
- status = LogisticsScreen::RUNNING;
- s_instance = this;
- forceGroupCount = 0;
- mechCamera = new SimpleCamera;
- addWeightAmount = 0;
- removeWeightAmount = 0;
- pDragMech = 0;
- dragLeft = 0;
- helpTextArrayID = 13;
- }
- MechBayScreen::~MechBayScreen()
- {
- if ( mechCamera )
- delete mechCamera;
- if ( pIcons )
- delete[] pIcons;
- mechListBox.destroy();
- }
- void MechBayScreen::init(FitIniFile* file)
- {
- // init button, texts, statics, rects
- LogisticsScreen::init( *file, "MechBayStatic", "MechBayTextEntry", "MechBayRect", "MechBayButton" );
-
- // initialize the list box
- mechListBox.init();
- mechListBox.setHelpID( IDS_HELP_MECHSTORAGE );
- loadoutListBox.init( rects[3].left(), rects[3].top(), rects[3].width(), rects[3].height() );
- // fill the mech list box
- ((aObject*)&mechListBox)->init( rects[0].left(), rects[0].top(), rects[0].width(), rects[0].height() );
- // initialize little icons
- FitIniFile iconFile;
- char path[256];
- strcpy( path, artPath );
- strcat( path, "mcl_gn_deploymentteams.fit" );
- strlwr( path );
- if ( NO_ERR != iconFile.open( path ) )
- {
- gosASSERT( "couldn't open the MCL_GN_DevploymentTeams file" );
- return;
- }
- LogisticsMechIcon::init(iconFile);
- pIcons = new LogisticsMechIcon[ICON_COUNT];
- int count = 0;
-
- long x = 0;
- long y = 0;
- for ( int j = 0; j < ICON_COUNT_Y; j++ )
- {
- for ( int i = 0; i < ICON_COUNT_X; i++ )
- {
- pIcons[count].setMech( 0 );
- pIcons[count].move( x, y );
- x+= pIcons[count].width();
- x+=4;
- count++;
- }
- y+= pIcons[i].height();
- y += 5;
- x = 0;
- }
-
- mechListBox.drawCBills( 0 );
- mechListBox.setScrollBarOrange();
- // initialize the attribute meeters
- attributeMeters[0].init( file, "AttributeMeter0" );
- attributeMeters[1].init( file, "AttributeMeter1" );
- attributeMeters[2].init( file, "AttributeMeter2" );
- dropWeightMeter.init( file, "DropWeightMeter" );
- file->readIdLong( "RayCenterX", weightCenterX );
- file->readIdLong( "RayCenterY", weightCenterY );
- file->readIdLong( "RayStartColor ", weightStartColor );
- file->readIdLong( "RayEndColor ", weightEndColor );
- file->seekBlock( "weightAddAnimation" );
- addWeightAnim.init( file, "" );
- file->seekBlock( "weightRemoveAnimation" );
- removeWeightAnim.init( file, "" );
- file->seekBlock( "FRectAnim" );
- mechCamera->init( rects[1].left(), rects[1].top(), rects[2].right(), rects[1].bottom() );
-
-
- for ( int i= 0; i < buttonCount; i++ )
- buttons[i].setMessageOnRelease();
- textObjects[7].setText( "" );
- textObjects[8].setText( "" );
- textObjects[9].setText( "" );
- textObjects[10].setText( "" );
- textObjects[11].setText( "" );
- textObjects[12].setText( "" );
- textObjects[14].setText( "" );
- for ( i = 0; i < 3; i++ )
- {
- attributeMeters[i].setValue(0);
- }
- setMech( NULL, 0 );
- }
- void MechBayScreen::begin()
- {
- status = RUNNING;
- pDragMech = NULL;
- mechListBox.removeAllItems( true );
- reinitMechs();
- int mechCount[256];
- memset( mechCount, 0, sizeof ( int ) * 256 );
- bool bCurMechIsValid = 0;
- // initialize both the inventory and icon lists
- EList< LogisticsMech*, LogisticsMech* > mechList;
- LogisticsData::instance->getInventory( mechList );
-
- for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = mechList.Begin();
- !iter.IsDone(); iter++ )
- {
- if ( *iter == pCurMech )
- bCurMechIsValid = true;
- if ( !(*iter)->getForceGroup() )
- {
- bool bFound = 0;
- for ( int i = 0; i < mechListBox.GetItemCount(); i++ )
- {
- if ( ((MechListBoxItem*)mechListBox.GetItem(i))->getMech()->getVariant()
- == (*iter)->getVariant() )
- bFound = true;
- }
- if ( !bFound )
- {
- MechListBoxItem* item = new MechListBoxItem( (*iter), 1 );
- mechListBox.AddItem( item );
- }
- }
- }
-
-
- // reset the old mech to NULL to make sure everything gets set
-
- mechListBox.drawCBills( 0 );
- mechListBox.setOrange( true );
- if ( !pCurMech || !bCurMechIsValid )
- {
- if ( !selectFirstFGItem() )
- {
- if ( !selectFirstViableLBMech() )
- setMech( NULL );
- }
- }
- else
- {
- LogisticsMech* pMech = pCurMech;
- setMech( NULL ); // need to make sure the guy is still running
- setMech( pMech );
- bool bFound = 0;
- for ( int i = 0; i < mechListBox.GetItemCount(); i++ )
- {
- MechListBoxItem* pItem = (MechListBoxItem*)mechListBox.GetItem( i );
- if ( pItem && pItem->getMech() == pCurMech )
- {
- mechListBox.SelectItem( i );
- bFound = true;
- }
- }
- if ( !bFound )
- {
- for ( int i = 0; i < ICON_COUNT; i++ )
- {
- if ( pIcons[i].getMech() == pMech )
- {
- pIcons[i].select( true );
- break;
- }
- }
- }
- }
-
- }
- void MechBayScreen::render(int xOffset, int yOffset)
- {
- mechListBox.move( xOffset, yOffset );
- mechListBox.render();
- mechListBox.move( -xOffset, -yOffset );
- loadoutListBox.move( xOffset, yOffset );
- loadoutListBox.render();
- loadoutListBox.move( -xOffset, -yOffset );
- if ( !xOffset && !yOffset && pCurMech)
- mechCamera->render();
- for ( int i = 0; i < 3; i++ )
- {
- attributeMeters[i].render(xOffset, yOffset);
- }
- drawWeightMeter(xOffset, yOffset);
- LogisticsScreen::render(xOffset, yOffset);
- for ( i = 0; i < ICON_COUNT; i++ )
- {
- pIcons[i].render( xOffset, yOffset );
- }
- if ( MPlayer && ChatWindow::instance() )
- ChatWindow::instance()->render(xOffset, yOffset);
- if ( pDragMech )
- dragIcon.render();
- }
- void MechBayScreen::drawWeightMeter(long xOffset, long yOffset)
- {
- // there are 20 rays, each 9 degrees
- // they should be 50 pixels long
- float currentDropWeight = LogisticsData::instance->getCurrentDropWeight();
- float maxDropWeight = LogisticsData::instance->getMaxDropWeight();
- long numAddBars = 0;
- long numRemoveBars = 0;
- long addColor = 0;
- long removeColor = 0;
- long numberOfBars = 20;
- if ( maxDropWeight != 0 )
- {
- float percent = currentDropWeight/maxDropWeight;
- percent *= 20.f;
- numberOfBars = percent + .5;
- }
- if ( addWeightAnim.isAnimating() && !addWeightAnim.isDone() )
- {
- addColor = addWeightAnim.getColor();
- float percent = (currentDropWeight - addWeightAmount) / maxDropWeight;
- percent *= 20.f;
- numAddBars = percent + .5;
- numAddBars = numberOfBars - numAddBars;
- }
- if ( removeWeightAnim.isAnimating() && !removeWeightAnim.isDone() )
- {
- addColor = removeWeightAnim.getColor();
- float percent = removeWeightAmount / maxDropWeight;
- percent *= 20.f;
- numRemoveBars = percent + .5;
- }
- gos_VERTEX v[3];
- for ( int i = 0; i <3; i++ )
- {
- v[i].u = 0.f;
- v[i].v = 0.f;
- v[i].rhw = .5;
- v[i].z = 0.f;
- v[i].argb = 0;
- v[i].frgb = 0;
- v[i].x = weightCenterX + xOffset;
- v[i].y = weightCenterY + yOffset;
- }
-
- float curArc = 180.f;
- float curX = 50.f * cos( DEGREES_TO_RADS * curArc );
- float curY = 50.f * sin( DEGREES_TO_RADS * curArc );
- for ( i= 0; i < numberOfBars + numRemoveBars; i++ )
- {
- v[1].x = curX + weightCenterX + xOffset;
- v[1].y = curY + weightCenterY + yOffset;
- curArc += 9.f;
- curX = 50.f * cos( DEGREES_TO_RADS * curArc );
- curY = 50.f * sin( DEGREES_TO_RADS * curArc );
- v[2].x = curX + weightCenterX + xOffset;
- v[2].y = curY + weightCenterY + yOffset;
- if ( i >= numberOfBars - numAddBars )
- v[0].argb = v[1].argb = v[2].argb = addColor;
- else if ( i >= numberOfBars )
- v[0].argb = v[1].argb = v[2].argb = removeColor;
- else
- v[0].argb = v[1].argb = v[2].argb = interpolateColor( weightStartColor, weightEndColor, i * .05 );
- gos_DrawTriangles( v, 3 );
-
- }
- dropWeightMeter.render(xOffset, yOffset);
- }
- void MechBayScreen::update()
- {
- mechListBox.disableItemsThatCanNotGoInFG();
- if ( !pIcons[0].getMech() )
- getButton( MB_MSG_REMOVE )->disable( true );
- // update current text
- char str[64];
- // RP
- sprintf( str, "%ld ", LogisticsData::instance->getCBills() );
- textObjects[1].setText( str );
- long mouseX = userInput->getMouseX();
- long mouseY = userInput->getMouseY();
- if ( userInput->isLeftClick() && dropWeightMeter.pointInside( mouseX, mouseY ) )
- {
- soundSystem->playDigitalSample( LOG_WRONGBUTTON );
- }
-
- // current drop weight
- char tmpStr[128];
- cLoadString( IDS_MB_WEIGHT, tmpStr, 63 );
- long currentDropWeight = LogisticsData::instance->getCurrentDropWeight();
- long maxDropWeight = LogisticsData::instance->getMaxDropWeight();
- sprintf( str, tmpStr, currentDropWeight, maxDropWeight );
- textObjects[6].setText( str );
- // update drag and drop
- // must be done before Icon's are updated, or we can get out of sync
- if ( pDragMech )
- {
- dragIcon.moveTo( userInput->getMouseX() - dragIcon.width() / 2,
- userInput->getMouseY() - dragIcon.height() / 2 );
- bool bLeft = 0;
- bool bRight = 0;
-
- GUI_RECT testRect;
- testRect.left = mechListBox.globalX();
- testRect.right = mechListBox.globalX() + mechListBox.width();
- testRect.top = mechListBox.globalY();
- testRect.bottom = mechListBox.globalY() + mechListBox.height();
- if ( dragIcon.rectIntersect( testRect ) )
- {
- // set the focus
- } bRight = true;
- testRect.left = pIcons[0].globalX();
- testRect.right = pIcons[ICON_COUNT - 1].globalX() + pIcons[0].width();
- testRect.top = pIcons[0].globalY();
- testRect.bottom = pIcons[ICON_COUNT-1].globalY() + pIcons[0].height();
- if ( dragIcon.rectIntersect( testRect ) )
- {
- bLeft = true;
- }
- else
- bLeft = 0;
- if ( userInput->leftMouseReleased() || userInput->isLeftDoubleClick() )
- {
- if ( dragLeft )
- {
- if ( bLeft )
- {
- LogisticsData::instance->removeMechFromForceGroup( pDragMech, false );
- LogisticsData::instance->addMechToForceGroup( pDragMech, forceGroupCount+1 );
- forceGroupCount++;
- reinitMechs();
- }
- else
- {
- if ( 0 == LogisticsData::instance->getVariantsInInventory( pDragMech->getVariant(), 0 ) )
- {
- MechListBoxItem* item = new MechListBoxItem( pDragMech, 0 );
- int index = mechListBox.AddItem( item );
- mechListBox.SelectItem( index );
- }
- LogisticsData::instance->removeMechFromForceGroup( pDragMech, true );
- forceGroupCount--;
- reinitMechs();
- removeWeightAmount = pDragMech->getMaxWeight();
- removeWeightAnim.begin();
- addWeightAnim.end();
- }
- }
- else
- {
- if ( bLeft )
- {
- reinitMechs();
- addWeightAmount = pDragMech->getMaxWeight();
- addWeightAnim.begin();
- removeWeightAnim.end();
-
- }
- else
- {
- if ( 0 == LogisticsData::instance->getVariantsInInventory( pDragMech->getVariant(), 0 ) )
- {
- MechListBoxItem* item = new MechListBoxItem( pDragMech, 0 );
- int index = mechListBox.AddItem( item );
- mechListBox.SelectItem( index );
- }
- LogisticsData::instance->removeMechFromForceGroup( pDragMech, true );
- reinitMechs();
- }
- }
-
- pDragMech = 0;
- }
- }
- // update icon selection
- int newSel = -1;
- int oldSel = -1;
- int removeMech = -1;
- for ( int i = 0; i < ICON_COUNT; i++ )
- {
- pIcons[i].update();
- if ( pIcons[i].justSelected() )
- newSel = i;
- else if ( pIcons[i].isSelected() )
- oldSel = i;
- bool bInside = pIcons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() );
- if ( bInside && userInput->isLeftDoubleClick() && pIcons[i].getMech() )
- {
- removeMech = i;
- }
- else if ( userInput->isLeftDrag()
- && pIcons[i].pointInside( userInput->getMouseDragX(), userInput->getMouseDragY() ) )
- {
- beginDrag( pIcons[i].getMech() );
- }
- }
- if ( newSel != -1 )
- {
- if ( oldSel != -1 )
- pIcons[oldSel].select( 0 );
- mechListBox.SelectItem( -1 );
-
- }
- if ( removeMech != -1 )
- {
- removeSelectedMech();
- }
- if ( !MPlayer || !ChatWindow::instance()->pointInside(userInput->getMouseX(), userInput->getMouseY()) )
- LogisticsScreen::update();
-
- if ( newSel == -1 && oldSel == -1 )
- {
- // disable the remove button
- getButton( MB_MSG_REMOVE )->disable(1);
- }
- else
- getButton( MB_MSG_REMOVE )->disable(0);
-
- // update list box,
- oldSel = mechListBox.GetSelectedItem();
- mechListBox.update();
- newSel = mechListBox.GetSelectedItem( );
- // did anything change?
- if ( oldSel != newSel && newSel != -1)
- {
- unselectDeploymentTeam();
- }
- // component list box
- loadoutListBox.update();
- addWeightAnim.update();
- removeWeightAnim.update();
- LogisticsMech* pTmp = mechListBox.getCurrentMech();
- if ( !pTmp )
- {
- pTmp = getFGSelMech();
- }
- if ( pTmp )
- setMech( pTmp, 0);
- // update buttons!
- if ( newSel == -1 || !LogisticsData::instance->canAddMechToForceGroup( mechListBox.getCurrentMech() ) )
- {
- // disable the add button
- getButton( MB_MSG_ADD )->disable(1);
- }
- else
- getButton( MB_MSG_ADD )->disable(0);
-
- if ( MPlayer && ( !MPlayer->missionSettings.variants || !pCurMech ) )
- {
- getButton( MB_MSG_CHANGE_LOADOUT )->disable( true );
- }
- else if ( LogisticsData::instance->skipPurchasing() )
- {
- getButton( MB_MSG_CHANGE_LOADOUT )->disable( true );
- getButton( MB_MSG_BUY )->disable( true );
- }
- else
- {
- getButton( MB_MSG_CHANGE_LOADOUT )->disable( false );
- getButton( MB_MSG_BUY )->disable( false );
- if ( !pCurMech )
- getButton( MB_MSG_CHANGE_LOADOUT )->disable( true );
- else
- {
- getButton( MB_MSG_CHANGE_LOADOUT )->disable( false );
- mechCamera->update();
- }
- }
- if ( MPlayer && ChatWindow::instance() )
- ChatWindow::instance()->update();
- }
- int MechBayScreen::handleMessage( unsigned long message, unsigned long who )
- {
- if ( status != RUNNING )
- return 0;
- switch( who )
- {
- case MB_MSG_NEXT:
- status = NEXT;
- break;
- case MB_MSG_PREV:
- status = PREVIOUS;
- break;
- case MB_MSG_ADD:
-
- addSelectedMech();
- soundSystem->playDigitalSample( LOG_SELECT );
- break;
- case MB_MSG_REMOVE:
- removeSelectedMech();
- break;
- case MB_MSG_BUY:
- status = UP;
- break;
- case MB_MSG_CHANGE_LOADOUT:
- status = DOWN;
- if ( pCurMech )
- {
- LogisticsData::instance->setMechToModify( pCurMech );
- }
- break;
- case MB_MSG_BUY_SELL:
- break;
- case MB_MSG_MAINMENU:
- status = MAINMENU;
- break;
- }
- return 0;
- }
- void MechBayScreen::addSelectedMech()
- {
- if ( mechListBox.getCurrentMech() )
- {
- if ( !LogisticsData::instance->canAddMechToForceGroup( mechListBox.getCurrentMech() ) )
- return;
- if ( NO_ERR != LogisticsData::instance->addMechToForceGroup( mechListBox.getCurrentMech(),
- forceGroupCount + 1 ) )
- {
- // its already in the force group, add probably called 2x'2
- return;
- }
- if ( forceGroupCount > 11 )
- return;
- unselectDeploymentTeam();
- forceGroupCount++;
- reinitMechs();
- addWeightAmount = pCurMech->getMaxWeight();
- addWeightAnim.begin();
- removeWeightAnim.end();
- bool bFound = 0;
- for ( int i = 0; i < mechListBox.GetItemCount(); i++ )
- {
- if ( LogisticsData::instance->canAddMechToForceGroup(
- ((MechListBoxItem*)mechListBox.GetItem( i ))->getMech() ) )
- {
- bFound = true;
- }
- }
- if ( !bFound ) // select first thing in FG
- {
- selectFirstFGItem();
- mechListBox.SelectItem( -1 );
- }
- }
- }
- void MechBayScreen::removeSelectedMech()
- {
- for ( int i = 0; i < ICON_COUNT; i++ )
- {
- if ( pIcons[i].isSelected() )
- {
- LogisticsMech* pMech = pIcons[i].getMech();
- if ( !pMech )
- return;
- if ( 0 == LogisticsData::instance->getVariantsInInventory( pMech->getVariant(), 0 ) )
- {
- MechListBoxItem* item = new MechListBoxItem( pMech, 0 );
- mechListBox.AddItem( item );
- }
- LogisticsData::instance->removeMechFromForceGroup( pMech, true );
-
- forceGroupCount--;
- removeWeightAmount = pMech->getMaxWeight();
- removeWeightAnim.begin();
- addWeightAnim.end();
- if ( i >= forceGroupCount )
- {
- if ( !selectFirstFGItem() )
- {
- selectFirstViableLBMech();
- }
- }
- else
- pIcons[i].select( true );
- break;
- }
- }
-
- for ( ; i < ICON_COUNT - 1; i++ )
- {
- LogisticsData::instance->removeMechFromForceGroup(pIcons[i+1].getMech(), false);
- LogisticsData::instance->addMechToForceGroup(pIcons[i+1].getMech(), i+1);
- }
- reinitMechs();
- if ( !forceGroupCount )
- selectFirstViableLBMech();
- }
- void MechBayScreen::end()
- {
- mechCamera->setMech( NULL );
- }
- void MechBayScreen::setMech( LogisticsMech* pMech, bool bCommandFromLB )
- {
- if ( pMech == pCurMech || status != RUNNING)
- return;
- pCurMech = pMech;
- if ( pMech )
- {
- loadoutListBox.setMech( pMech->getVariant() );
- EString fileName = pMech->getFileName();
- int index = fileName.Find( '.' );
- fileName = fileName.Left( index );
- index = fileName.ReverseFind( '\\' );
- fileName = fileName.Right( fileName.Length() - index - 1 );
- mechCamera->setMech( fileName, prefs.baseColor, prefs.highlightColor, prefs.highlightColor );
- mechCamera->setScale( pMech->getVariant()->getChassis()->getScale() );
- }
- else
- loadoutListBox.setMech( 0 );
- if ( bCommandFromLB ) // clicked on a disabled mech
- {
- unselectDeploymentTeam();
- mechListBox.SelectItem( -1 );
- }
- if ( pCurMech )
- {
- char tmpStr[256];
- // update current text
- char str[64];
- // weight
- cLoadString( IDS_MB_MECH_WEIGHT, tmpStr, 63 );
- sprintf( str, tmpStr, pCurMech->getMaxWeight(), (const char*)pCurMech->getMechClass() );
- textObjects[7].setText( str );
- // firing range
- long tmpColor;
- textObjects[14].setText( pCurMech->getVariant()->getOptimalRangeString( tmpColor ) );
- textObjects[14].setColor( tmpColor );
- // armor
- int armor = pCurMech->getArmor();
- sprintf( str, "%ld", armor );
- textObjects[8].setText( str );
- attributeMeters[0].setValue( armor/MAX_ARMOR_RANGE );
- // speed
- int speed = pCurMech->getDisplaySpeed();
- sprintf( str, "%ld", speed );
- textObjects[9].setText( str );
- attributeMeters[1].setValue( pCurMech->getSpeed()/MAX_SPEED_RANGE );
- // jump
- int jumpRange = pCurMech->getJumpRange();
- sprintf( str, "%ld", jumpRange * 25 );
- textObjects[10].setText( str );
- attributeMeters[2].setValue( jumpRange * 25 / MAX_JUMP_RANGE );
- textObjects[11].setText( pCurMech->getChassisName() );
- textObjects[12].setText( pCurMech->getName() );
- }
- else
- {
- textObjects[7].setText( "" );
- textObjects[8].setText( "" );
- textObjects[9].setText( "" );
- textObjects[10].setText( "" );
- textObjects[11].setText( "" );
- textObjects[12].setText( "" );
- textObjects[14].setText( "" );
- for ( int i = 0; i < 3; i++ )
- {
- attributeMeters[i].setValue(0);
- }
- }
- }
- void MechBayScreen::beginDrag( LogisticsMech* pMech )
- {
- if ( pDragMech || status != RUNNING )
- return;
- if ( !pMech )
- return;
- // need to set the uv's of the mech icon
- MechListBox::initIcon( pMech, dragIcon );
- dragIcon.moveTo( userInput->getMouseX() - dragIcon.width() / 2,
- userInput->getMouseY() - dragIcon.height() / 2 );
- pDragMech = pMech;
- // figure out where the mech came from
- if ( mechListBox.pointInside( userInput->getMouseDragX(), userInput->getMouseDragY() ) )
- {
- if ( pMech->getForceGroup() )
- {
- pMech = LogisticsData::instance->getMechWithoutForceGroup( pMech );
- }
- pDragMech = pMech;
- if ( !LogisticsData::instance->canAddMechToForceGroup( pMech ) )
- {
- pDragMech = 0;
- return;
- }
- LogisticsData::instance->addMechToForceGroup( pMech, forceGroupCount+1 );
- dragLeft = 0;
-
- }
- else
- {
- for ( int i = 0; i < ICON_COUNT; i++ )
- {
- if ( pIcons[i].pointInside( userInput->getMouseDragX(), userInput->getMouseDragY() ) )
- {
- forceGroupCount--;
- // select the next one
- if ( i == forceGroupCount && forceGroupCount )
- {
- pIcons[i].select( 0 );
- pIcons[0].select( true );
- }
- else if ( !forceGroupCount)
- pIcons[i].select( 0 );
-
- for ( ; i < ICON_COUNT - 1; i++ )
- {
- LogisticsData::instance->removeMechFromForceGroup( pIcons[i+1].getMech(), false );
- LogisticsData::instance->addMechToForceGroup( pIcons[i+1].getMech(), i+1 );
- pIcons[i].setMech( pIcons[i+1].getMech() );
- pIcons[i].setPilot( pIcons[i+1].getPilot() );
- }
- if ( i < ICON_COUNT )
- {
- pIcons[i].setMech( NULL );
- pIcons[i].setPilot( NULL );
- }
- break;
- }
- }
- dragLeft = 1;
- }
-
- }
- void MechBayScreen::reinitMechs()
- {
-
- int count = 0;
-
- int maxUnits = 12;
- if ( MPlayer )
- {
- long playerCount;
- MPlayer->getPlayers( playerCount );
- if ( playerCount )
- maxUnits = MAX_MULTIPLAYER_MECHS_IN_LOGISTICS/playerCount;
- if ( maxUnits > 12 )
- maxUnits = 12;
- }
- for ( int j = 0; j < ICON_COUNT_Y; j++ )
- {
- for ( int i = 0; i < ICON_COUNT_X; i++ )
- {
- pIcons[count].setMech( 0 );
- if ( count >= maxUnits )
- pIcons[count].disable( true );
- else
- pIcons[count].disable( 0 );
- count++;
- }
- }
- forceGroupCount = 0;
- // initialize both the inventory and icon lists
- EList< LogisticsMech*, LogisticsMech* > mechList;
- LogisticsData::instance->getInventory( mechList );
-
-
- for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = mechList.Begin();
- !iter.IsDone(); iter++ )
- {
- if ( (*iter)->getForceGroup() )
- {
- long FG = (*iter)->getForceGroup();
- if ( FG <= maxUnits )
- {
-
- pIcons[FG-1].setMech( (*iter) );
- pIcons[FG-1].setPilot( (*iter)->getPilot() );
- forceGroupCount++;
- }
- else
- (*iter)->setForceGroup( 0 );
-
- }
- }
- }
- void MechBayScreen::unselectDeploymentTeam()
- {
- int count = 0;
- for ( int j = 0; j < ICON_COUNT_Y; j++ )
- {
- for ( int i = 0; i < ICON_COUNT_X; i++ )
- {
- pIcons[count].select( 0 );
- count++;
- }
- }
- }
- bool MechBayScreen::selectFirstFGItem()
- {
- bool bRetVal = false;
- for ( int i = 0; i < ICON_COUNT_X * ICON_COUNT_Y; i++ )
- {
- if ( pIcons[i].getMech() && !bRetVal )
- {
- pIcons[i].select( true );
- bRetVal = true;
- }
- else
- pIcons[i].select( false );
- }
- return bRetVal;
- }
- bool MechBayScreen::selectFirstViableLBMech()
- {
- for ( int i = 0; i < mechListBox.GetItemCount(); i++ )
- {
- if ( mechListBox.GetItem( i )->getState() != aListItem::DISABLED )
- {
- mechListBox.SelectItem( i );
- return true;
- }
- }
- return 0;
- }
- LogisticsMech* MechBayScreen::getFGSelMech()
- {
- for ( int i = 0; i < ICON_COUNT_X * ICON_COUNT_Y; i++ )
- {
- if ( pIcons[i].getMech() && pIcons[i].isSelected() )
- return pIcons[i].getMech();
- }
- return NULL;
- }
|