long MechListBox::AddItem(aListItem* itemString) { itemString->setID( ID ); MechListBoxItem* pItem = dynamic_cast<MechListBoxItem*>(itemString); EString addedName; char tmp[256]; cLoadString( pItem->getMech()->getChassisName(), tmp, 255 ); addedName = tmp; if ( pItem ) { pItem->bOrange = bOrange; pItem->bIncludeForceGroup = bIncludeForceGroup; if ( !bDeleteIfNoInventory ) { pItem->countText.setColor( 0 ); pItem->countText.showGUIWindow( 0 ); } EString chassisName; for ( int i = 0; i < itemCount; i++ ) { long ID = ((MechListBoxItem*)items[i])->pMech->getChassisName(); char tmpChassisName[256]; cLoadString( ID, tmpChassisName, 255 ); chassisName = tmpChassisName; if ( ((MechListBoxItem*)items[i])->pMech->getMaxWeight() < pItem->pMech->getMaxWeight() ) { return InsertItem( itemString, i ); break; } else if ( ((MechListBoxItem*)items[i])->pMech->getMaxWeight() == pItem->pMech->getMaxWeight() && chassisName.Compare( addedName ) > 0 ) { return InsertItem( itemString, i ); } else if ( ((MechListBoxItem*)items[i])->pMech->getMaxWeight() == pItem->pMech->getMaxWeight() && chassisName.Compare( addedName ) == 0 && ((MechListBoxItem*)itemString)->pMech->getName().Find("Prime") != -1 ) { return InsertItem( itemString, i ); } else if ( ((MechListBoxItem*)items[i])->pMech->getMaxWeight() == pItem->pMech->getMaxWeight() && chassisName.Compare( addedName ) == 0 && ( ((MechListBoxItem*)items[i])->pMech->getName().Find("Prime" ) == -1 ) && ((MechListBoxItem*)items[i])->pMech->getName().Compare( pItem->pMech->getName() ) > 0 ) { return InsertItem( itemString, i ); } } } return aListBox::AddItem( itemString ); }
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::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; }