//---------------------------------------------------------------------
// GetNextSelectedObject():
//---------------------------------------------------------------------
WPOBJECT *WPCONTAINER::GetNextSelectedObject(void)
{                   
   // Check if we have enough selected objects for next index.                                          
   if ((m_nCurrentSelectedObject+1)<GetSelectedObjectCount())
      return (GetSelectedObject(++m_nCurrentSelectedObject));
   else
      return (NULL);       // Return error.
}
Пример #2
0
void USelection::DeselectAll( UClass* InClass )
{
	// Fast path for deselecting all UObjects with any flags
	if ( InClass == UObject::StaticClass() )
	{
		InClass = nullptr;
	}

	bool bSelectionChanged = false;

	TSet<FSelectedClassInfo> RemovedClasses;
	// Remove from the end to minimize memmoves.
	for ( int32 i = SelectedObjects.Num()-1 ; i >= 0 ; --i )
	{
		UObject* Object = GetSelectedObject(i);

		if ( !Object )
		{		
			// Remove NULLs from SelectedObjects array.
			SelectedObjects.RemoveAt( i );
		}
		else if( !InClass || Object->IsA( InClass ) )
		{
			// if the object is of type InClass then all objects of that same type will be removed
			RemovedClasses.Add(FSelectedClassInfo(Object->GetClass()));

			GSelectedAnnotation.Clear(Object);
			SelectedObjects.RemoveAt( i );

			// Call this after the item has been removed from the selection set.
			USelection::SelectObjectEvent.Broadcast( Object );

			bSelectionChanged = true;
		}
	}

	if( InClass == nullptr )
	{
		SelectedClasses.Empty();
	}
	else
	{
		// Remove the passed in class and all child classes that were removed
		// from the list of currently selected classes
		RemovedClasses.Add(InClass);
		SelectedClasses = SelectedClasses.Difference(RemovedClasses);
	}

	if ( bSelectionChanged )
	{
		MarkBatchDirty();
		if ( !IsBatchSelecting() )
		{
			USelection::SelectionChangedEvent.Broadcast(this);
		}
	}
}
//---------------------------------------------------------------------
// GetFirstSelectedObject():
//---------------------------------------------------------------------
WPOBJECT *WPCONTAINER::GetFirstSelectedObject(void)
{                                                 
   // Reset current selected object index to the begining.
   m_nCurrentSelectedObject = 0;
   // Check if we have at least 1 selected object.
   if (GetSelectedObjectCount()>0)
      return (GetSelectedObject(0));  // Return first object in list.
   else
      return (NULL);                  // Return error.
}
Пример #4
0
bool TradeListDisplay::ChangeTradeQuantity(bool less_or_more, uint32 amount)
{
    ShopObject *obj = GetSelectedObject();
    if(obj == NULL) {
        IF_PRINT_WARNING(SHOP_DEBUG) << "function could not perform operation because list was empty" << std::endl;
        return false;
    }

    // Holds the amount that the quantity will actually increase or decrease by. May be less than the
    // amount requested if there is an limitation such as shop stock or available funds
    uint32 change_amount = amount;

    if(less_or_more == false) {
        // Ensure that at least one count of this object is already marked for purchase
        if(obj->GetTradeCount() == 0) {
            return false;
        }

        // Determine if there's a sufficient count selected to decrement by the desire amount. If not, return as many as possible
        if(amount > obj->GetTradeCount()) {
            change_amount = obj->GetTradeCount();
        }

        obj->DecrementTradeCount(change_amount);
        ShopMode::CurrentInstance()->UpdateFinances(obj->GetTradePrice() * change_amount);
        return true;
    } else {
        // Make sure that there is at least one more object in stock and the player has enough funds to purchase it
        if((obj->GetTradeCount() > obj->GetStockCount()))
            return false;

        if(obj->GetObject()->GetTradeConditions().empty())
            return false;

        for(uint32 i = 0; i < obj->GetObject()->GetTradeConditions().size(); ++i) {
            if(!GlobalManager->IsObjectInInventory(obj->GetObject()->GetTradeConditions()[i].first))
                return false;

            if(obj->GetTradeCount() * obj->GetObject()->GetTradeConditions()[i].second > GlobalManager->HowManyObjectsInInventory(obj->GetObject()->GetTradeConditions()[i].first))
                return false;
        }

        // Determine if there's enough of the object in stock to buy. If not, buy as many left as possible
        if((obj->GetStockCount() - obj->GetTradeCount()) < change_amount) {
            change_amount = obj->GetStockCount() - obj->GetTradeCount();
        }

        obj->IncrementTradeCount(change_amount);
        ShopMode::CurrentInstance()->UpdateFinances(-obj->GetTradePrice() * change_amount);
        return true;
    }
} // bool TradeListDisplay::ChangeTradeQuantity(bool less_or_more, uint32 amount)
//---------------------------------------------------------------------
// ClearSelectedObjects():
//---------------------------------------------------------------------
void WPCONTAINER::ClearSelectedObjects(BOOL fInvalidateObjects)
{     
   int      index;
    
   // If we need to invalidate selected object's icons...                   
   if (fInvalidateObjects==TRUE)
   {              
      // Loop through the whole list of selected objects. 
      for (index=0; index<GetSelectedObjectCount(); index++)
         // Invalidate selected object for update later.
         GetSelectedObject(index)->InvalidateIcon(FALSE,TRUE);
   }
   // Remove all objects in list of selected objects.
   m_SelectedObjectList.RemoveAll();
}
void CDiagramEntityContainer::MakeSameSizeSelected()
{
	if( GetSelectCount() > 1 )
	{
		CDiagramEntity* obj = GetSelectedObject();
		if( obj )
		{
			double width = obj->GetRight() - obj->GetLeft();
			double height = obj->GetBottom() - obj->GetTop();
			int count = 0;
			while (obj = GetAt( count++ ))
			{
				if (!obj->IsSelected()) continue;
				obj->SetRect( obj->GetLeft(), obj->GetTop(), obj->GetLeft() + width, obj->GetTop() + height );
			}

		}
		SetModified( TRUE );
	}
}
void CDiagramEntityContainer::BottomAlignSelected()
{
	if( GetSelectCount() > 1 )
	{
		CDiagramEntity* obj = GetSelectedObject();
		if( obj )
		{
			double bottom = obj->GetBottom();
			int count = 0;
			while (obj = GetAt( count++ ))
			{
				if (!obj->IsSelected()) continue;
				double height = obj->GetBottom() - obj->GetTop();
				double top = bottom - height;
				obj->SetRect( obj->GetLeft(), top, obj->GetRight(), bottom );
			}

		}
		SetModified( TRUE );
	}
}
void CDiagramEntityContainer::RightAlignSelected()
{
	if( GetSelectCount() > 1 )
	{
		CDiagramEntity* obj = GetSelectedObject();
		if( obj )
		{
			double right = obj->GetRight();
			int count = 0;
			while (obj = GetAt( count++ ))
			{
				if (!obj->IsSelected()) continue;
				double width = obj->GetRight() - obj->GetLeft();
				double left = right - width;
				obj->SetRect( left, obj->GetTop(), right, obj->GetBottom() );
			}

		}
		SetModified( TRUE );
	}
}
	virtual void OnEvent( int event_id, const IGUIEvent& event_info )
	{
		AUVec3f selectPos;
		char buff[16];
		event_info.GetParameter( "mouse_x", buff, sizeof(buff) );
		selectPos.SetX( (float)atof( buff ) );
		event_info.GetParameter( "mouse_y", buff, sizeof(buff) );
		selectPos.SetY( (float)atof( buff ) );
		event_info.GetParameter( "button", buff, sizeof(buff) );
		int button = atoi( buff );

		AUVec3f worldPos = m_pCameraControl->Unproject( selectPos );

		IGameObject* pGameObject = GetSelectedObject( worldPos );
		if ( button == 0 ) // left button
		{
			if ( m_pSelectedObject && pGameObject != m_pSelectedObject )
			{
				// Deselect currently selected object
				m_pSelectedObject->OnDeselect();
				m_pSelectedObject = 0;
			}

			if ( pGameObject )
			{
				// Select object
				pGameObject->OnSelect();
				m_pSelectedObject = pGameObject;
			}
		}
		else // right button
		{
			if ( m_pSelectedObject && pGameObject != m_pSelectedObject )
			{
				// Set target
				m_pSelectedObject->OnPositionRequest( worldPos );
			}
		}
	}