Beispiel #1
0
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;
}
int	MechPurchaseScreen::handleMessage( unsigned long what, unsigned long who )
{
	if ( status == RUNNING )
	{
		switch (who)
		{
			case MB_MSG_ADD:
				if ( INVENTORY_ID == what )
				{
					int index = inventoryListBox.GetSelectedItem();
					if ( index != -1 )
					{
						aListItem* pItem = inventoryListBox.GetItem( index );
						if ( pItem )
						{
							LogisticsMech* pMech = ((MechListBoxItem*)pItem)->getMech();
							int oldCount = LogisticsData::instance->getVariantsInInventory( pMech->getVariant(), true );
							if ( NO_ERR == LogisticsData::instance->sellMech( pMech ) && ( oldCount < 2 ) )
								((MechListBoxItem*)pItem)->resetMech( );
							soundSystem->playDigitalSample( LOG_SELECT );		
						}                                    
					}
				}

				else
					addSelectedMech();
					soundSystem->playDigitalSample( LOG_SELECT );		
				break;
			case MB_MSG_REMOVE:
				removeSelectedMech();
				break;
			case MB_MSG_NEXT:
				acceptPressed = true;
				status = DOWN;
				break;
			case MB_MSG_PREV:
				status = DOWN;
				break;
			case MB_MSG_MAINMENU:
				status = MAINMENU;
				break;
		}
	}

	return 0;

}
Beispiel #3
0
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();



}