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(); }
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 MechPurchaseScreen::update() { if(!MPlayer || !ChatWindow::instance()->pointInside(userInput->getMouseX(), userInput->getMouseY())) LogisticsScreen::update(); // update CBills int32_t amount = LogisticsData::instance->getCBills(); int32_t color = 0xff005392; if(amount != oldCBillsAmount) { previousAmount = oldCBillsAmount - amount; curCount = .00001f; oldCBillsAmount = amount; if(previousAmount < 0) soundSystem->playDigitalSample(WINDOW_OPEN); else soundSystem->playDigitalSample(WINDOW_CLOSE); } if(curCount && curCount + frameLength < countDownTime) { curCount += frameLength; float curAmount = previousAmount - (curCount / countDownTime * previousAmount); amount += curAmount; color = 0xffc8e100; if(curAmount > 0) color = 0xffa21600; } else if(flashTime) { flashTime += frameLength; if(flashTime < .125 || (flashTime > .25 && flashTime < .3875) || (flashTime > .5 && flashTime < .6625)) { color = 0xff000000; } else if(flashTime > .75) { flashTime = 0; } else { color = 0xffff0000; } } char tmp[64]; sprintf(tmp, "%ld ", amount); textObjects[1].setText(tmp); textObjects[1].setColor(color); int32_t oldSell = inventoryListBox.GetSelectedItem(); inventoryListBox.update(); int32_t newSell = inventoryListBox.GetSelectedItem(); if(oldSell != newSell && newSell != -1) { variantListBox.SelectItem(-1); } oldSell = variantListBox.GetSelectedItem(); variantListBox.update(); newSell = variantListBox.GetSelectedItem(); if(oldSell != newSell && newSell != -1) { inventoryListBox.SelectItem(-1); } variantListBox.disableItemsThatCostMoreThanRP(); LogisticsMech* pCurSell = inventoryListBox.getCurrentMech(); LogisticsMech* pCurBuy = variantListBox.getCurrentMech(); // disable the sell button buttons[2].disable(pCurSell ? 0 : 1); if(pCurBuy) { if(pCurBuy->getCost() > LogisticsData::instance->getCBills()) { pCurBuy = nullptr; } setMech(pCurBuy); } else if(pCurSell) setMech(pCurSell); buttons[1].disable(pCurBuy ? 0 : 1); if(!pCurBuy && userInput->isLeftClick() && buttons[1].pointInside(userInput->getMouseX(), userInput->getMouseY())) { if(!flashTime) flashTime = .0001f; } // drag and drop // update drag and drop if(pDragMech) { dragIcon.moveTo(userInput->getMouseX() - dragIcon.width() / 2, userInput->getMouseY() - dragIcon.height() / 2); if(userInput->leftMouseReleased()) { endDrag(); } } mechDisplay.update(); inventoryListBox.enableAllItems(); if(MPlayer && ChatWindow::instance()) ChatWindow::instance()->update(); }
void MechPurchaseScreen::begin() { variantListBox.removeAllItems(true); inventoryListBox.removeAllItems(true); // initialize both the inventory and icon lists EList< LogisticsMech*, LogisticsMech* > mechList; LogisticsData::instance->getInventory(mechList); prevInventory.Clear(); LogisticsMech* pSelMech = 0; oldCBillsAmount = LogisticsData::instance->getCBills(); for(EList< LogisticsMech*, LogisticsMech* >::EIterator iter = mechList.Begin(); !iter.IsDone(); iter++) { if((*iter)->getForceGroup()) continue; prevInventory.Append(*(*iter)); bool bFound = 0; for(size_t i = 0; i < inventoryListBox.GetItemCount(); i++) { if(((MechListBoxItem*)inventoryListBox.GetItem(i))->getMech()->getVariant() == (*iter)->getVariant()) bFound = true; } if(!bFound) { MechListBoxItem* item = new MechListBoxItem((*iter), 1); inventoryListBox.AddItem(item); } } MechListBoxItem* item = (MechListBoxItem*)inventoryListBox.GetItem(0); if(item) { inventoryListBox.SelectItem(0); pSelMech = item->getMech(); } LogisticsVariant* pVariants[256]; int32_t count = 256; LogisticsData::instance->getPurchasableMechs(pVariants, count); for(size_t i = 0; i < count; i++) { if(!MPlayer || MPlayer->missionSettings.variants || pVariants[i]->isDesignerMech()) { LogisticsMech* pMech = new LogisticsMech(pVariants[i], -1); MechListBoxItem* item = new MechListBoxItem(pMech, 1); variantListBox.AddItem(item); } } if(!pSelMech) { MechListBoxItem* item = (MechListBoxItem*)variantListBox.GetItem(0); if(item) { variantListBox.SelectItem(0); pSelMech = item->getMech(); } } status = RUNNING; acceptPressed = 0; inventoryListBox.drawCBills(1); variantListBox.drawCBills(1); variantListBox.setOrange(0); inventoryListBox.setOrange(1); setMech(pSelMech); pDragMech = nullptr; }
void MechListBoxItem::update() { char text[32]; int oldMechCount = mechCount; if ( !pMech ) { mechCount = 0; return; } mechCount = LogisticsData::instance->getVariantsInInventory( pMech->getVariant(), bIncludeForceGroup ); if ( oldMechCount != mechCount ) { animTime = .0001f; } sprintf( text, "%ld", mechCount ); countText.setText( text ); if ( animTime ) { if ( animTime < .25f || ( animTime > .5f && animTime <= .75f ) ) { countText.setColor( 0 ); } else countText.setColor( 0xffffffff ); animTime += g_deltaTime; if ( animTime > 1.0f ) animTime = 0.f; } bool isInside = pointInside( userInput->getMouseX(), userInput->getMouseY() ); for ( int i = 0; i < ANIMATION_COUNT; i++ ) animations[bOrange][i].update(); if ( state == aListItem::SELECTED ) { for ( int i = 0; i < ANIMATION_COUNT; i++ ) animations[bOrange][i].setState( aAnimGroup::PRESSED ); // if ( userInput->isLeftClick() && isInside ) // setMech(); if ( userInput->isLeftDrag() && pointInside( userInput->getMouseDragX(), userInput->getMouseDragY() ) ) startDrag(); } else if ( state == aListItem::HIGHLITE ) { for ( int i = 0; i < ANIMATION_COUNT; i++ ) animations[bOrange][i].setState( aAnimGroup::HIGHLIGHT ); } else if ( state == aListItem::DISABLED && isShowing() ) { if ( userInput->isLeftClick() && isInside ) { soundSystem->playDigitalSample( LOG_WRONGBUTTON ); setMech(); // need to call explicitly } for ( int i = 0; i < ANIMATION_COUNT; i++ ) animations[bOrange][i].setState( aAnimGroup::DISABLED ); } else { for ( int i = 0; i < ANIMATION_COUNT; i++ ) animations[bOrange][i].setState( aAnimGroup::NORMAL ); } if ( userInput->isLeftDoubleClick() && isInside && state != aListItem::DISABLED && isShowing() ) doAdd(); aObject::update(); }
void PilotReadyScreen::update() { if ( MPlayer ) { if ( MPlayer->playersReadyToLoad() ) status = NEXT; } if ( getButton( MB_MSG_PREV )->isEnabled() ) // this is disabled if the user has already pressed launch ) { // update current text char str[64]; // RP sprintf( str, "%ld ", LogisticsData::instance->getCBills() ); textObjects[1].setText( str ); for ( int i = 0; i < 4; i++ ) skillIcons[i].update(); // desel icons if necessary bool bAllFull = 1; int newSel = -1; int oldSel = -1; bool bHasMech = 0; int newRightSel = -1; for ( 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 ( userInput->isLeftDoubleClick() && bInside && pIcons[i].getMech() ) { removeSelectedPilot(); } if ( userInput->isRightClick() && bInside && pIcons[i].getMech() ) { newRightSel = i; } else if ( userInput->isLeftDrag() && bInside && pIcons[i].pointInside( userInput->getMouseDragX(), userInput->getMouseDragY() ) && pIcons[i].getMech() ) { beginDrag( pIcons[i].getMech()->getPilot() ); pIcons[i].dimPilot( true ); pIcons[i].setPilot( NULL ); } if ( pIcons[i].getMech() && !pIcons[i].getPilot() ) bAllFull = 0; if ( pIcons[i].getMech() ) bHasMech = true; } if ( newSel != -1 ) { if ( oldSel != -1 ) pIcons[oldSel].select( 0 ); if ( pIcons[newSel].getPilot() ) { setPilot( pIcons[newSel].getPilot() ); } else setMech( pIcons[newSel].getMech() ); } if ( newRightSel != -1 ) { setMech( pIcons[newRightSel].getMech() ); } long curSel = newSel == -1 ? oldSel : newSel; if ( !MPlayer || !ChatWindow::instance()->pointInside(userInput->getMouseX(), userInput->getMouseY()) ) LogisticsScreen::update(); if ( mechSelected && ( !MPlayer || !ChatWindow::instance()->pointInside(userInput->getMouseX(), userInput->getMouseY()) )) { if ( userInput->getMouseY() > 317 ) { helpID = 0; textObjects[helpTextArrayID].setText( "" ); } mechDisplay.update(); } if ( !bAllFull ) // disable the next button until all have pilots { buttons[1].disable( 1 ); if ( curSel == -1 || pIcons[curSel].getPilot() ) buttons[2].disable( 1 ); else buttons[2].disable( 0 ); } else { if ( bHasMech ) buttons[1].disable( 0 ); else buttons[1].disable( 1 ); buttons[2].disable( 1 ); } if ( ( newSel == -1 && oldSel == -1 )|| !pIcons[curSel].getPilot()) { // disable the remove button buttons[3].disable(1); } else buttons[3].disable(0); for ( i = 0; i < MAX_MEDAL; i++ ) // so we get rollovers medalIcons[i].update(); // update drag and drop if ( pDragPilot ) { dragIcon.moveTo( userInput->getMouseX() - dragIcon.width() / 2, userInput->getMouseY() - dragIcon.height() / 2 ); LogisticsMechIcon* pSelIcon = 0; for ( int i = 0; i < ICON_COUNT; i++ ) { if ( pIcons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() ) && pIcons[i].getMech() ) { pSelIcon = &pIcons[i]; break; } } if ( userInput->leftMouseReleased( ) ) { endDrag(pSelIcon); } } pilotListBox.update(); } if ( MPlayer && ChatWindow::instance() ) ChatWindow::instance()->update(); }