Exemple #1
0
// Update the skeleton transforms based on the dragger.
void IvObjectDragger::UpdateSkeleton()
{
    ItemPtr selectedItem = GetSelectedItem();
    if( !selectedItem ) {
        return;
    }
    RaveTransform<float> tbox;
    const float* q = _transformBox->rotation.getValue().getValue();
    tbox.rot = Vector(q[3], q[0], q[1], q[2]);
    SbVec3f v = _transformBox->translation.getValue();
    tbox.trans = Vector(v[0], v[1], v[2]);

    Transform told; told.trans = -_ab.pos;

    RaveTransform<float> tnew = tbox*told*_toffset;
    SetSoTransform(selectedItem->GetIvTransform(), tnew);

    KinBodyItemPtr pbody = boost::dynamic_pointer_cast<KinBodyItem>(selectedItem);
    if( !!pbody ) {
        pbody->UpdateFromIv();
        CheckCollision(_checkCollision);
    }
    // other motion handler calls
    _viewer.lock()->_UpdateCameraTransform(0);
}
void Menu::insertMenuItem( HMENU hmenu, int index, ItemPtr item )
{
    MENUITEMINFO info = { sizeof( info ), MIIM_STRING | MIIM_ID | MIIM_DATA, 0, 0,
                          item->commandID(), NULL, NULL, NULL, (DWORD)item.getObject(), "menu"
                        };
    InsertMenuItem( hmenu, index, MF_BYPOSITION, &info );
}
Exemple #3
0
void IvObjectDragger::GetMessage(ostream& sout)
{
    ItemPtr selectedItem = GetSelectedItem();
    if( !selectedItem ) {
        return;
    }
    KinBodyItemPtr pbody = boost::dynamic_pointer_cast<KinBodyItem>(selectedItem);
    if( !pbody ) {
        return;
    }

    Transform t = pbody->GetTransform();
    sout << "Selected " << selectedItem->GetName() << " (id=" << pbody->GetNetworkId() << ")" << endl
         << "  translation = ("
         << std::fixed << std::setprecision(5)
         << std::setw(8) << std::left << t.trans.x << ", "
         << std::setw(8) << std::left << t.trans.y << ", "
         << std::setw(8) << std::left << t.trans.z << ")" << endl
         << "  quaternion = ("
         << std::fixed << std::setprecision(5)
         << std::setw(8) << std::left << t.rot.x << ", "
         << std::setw(8) << std::left << t.rot.y << ", "
         << std::setw(8) << std::left << t.rot.z << ", "
         << std::setw(8) << std::left << t.rot.w << ")" << endl;
}
void Menu::updateAction( HMENU hmenu, int& index, ItemPtr item, const MENUITEMINFO& info )
{
    if( !info.dwTypeData || buildMenuText( item ) != (LPCTSTR)info.dwTypeData )
        ModifyMenu( hmenu, index, MF_BYPOSITION | MF_STRING, item->commandID(),
                    buildMenuText( item ).c_str() );
    EnableMenuItem( hmenu, index, MF_BYPOSITION | ( item->update() ? MF_ENABLED : MF_GRAYED ) );
}
Exemple #5
0
bool Tile::isFullGround()
{
    ItemPtr ground = getGround();
    if(ground && ground->isFullGround())
        return true;
    return false;
}
void Item::add( ItemPtr item )
{
	if( isAncestor( item.getObject() ) )
		throw 1;
	subitems_.push_back( item );
	item->addParent( this );
}
Exemple #7
0
void Space::Intersects( ItemPtr item )
{
    switch( item->Behavior() ) {
        case Nothing:
            L_("I'm a master of nothing!\n");
            break;
        case AddJunk:
            JunkAdded( 1 );
            break;
        case Hurts:
            satellite.ChangeLife( -TWEAKS->GetNum( "asteroid_damage" ) );
            hit_snd.Play();
            break;
        case Heal:
            satellite.ChangeLife( TWEAKS->GetNum( "asteroid_damage" ) );
            heal_snd.Play();
            break;
        case AddCovet:
            coveted_snd.Play();
            satellite.ChangeCoveted( 1 );
            break;
        default: break;
    }

    item->Kill();
}
/*static*/
int Toolbar::getToolbarsCount( const std::string appTbsSection )
{
	ItemPtr appTbsItem = getToolbarsItem( appTbsSection );
	if ( !appTbsItem )
		return 0;

	return appTbsItem->num();
}
Exemple #9
0
void
Item::extractVariables( VariableSet &vs ) const
{
	ItemPtr i = getParent();
	if ( i )
		i->extractVariables( vs );
	for ( auto x = myVariables.begin(); x != myVariables.end(); ++x )
		vs.emplace( std::make_pair( x->first, x->second ) );
}
void Menu::updateToggle( HMENU hmenu, int& index, ItemPtr item, const MENUITEMINFO& info )
{
    if( !info.dwTypeData || buildMenuText( item ) != (LPCTSTR)info.dwTypeData )
        ModifyMenu( hmenu, index, MF_BYPOSITION | MF_STRING, item->commandID(),
                    buildMenuText( item ).c_str() );
    if( item->num() != 2 )// exactly 2
        throw 1;
    EnableMenuItem( hmenu, index, MF_BYPOSITION | ( item->update() ? MF_ENABLED : MF_GRAYED ) );
    CheckMenuItem( hmenu, index, MF_BYPOSITION | ( ( *item )[ 0 ]->update() ? MF_UNCHECKED : MF_CHECKED ) );
}
bool operator<(const ItemPtr& itemptr1, const ItemPtr& itemptr2)
{
	if (itemptr1.getPtr()->getTitle() < itemptr2.getPtr()->getTitle()) 
	{
		return true;
	} else 
	{
		return false;
	}
}
ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id)
{
    if(id == 0)
        id = msg.getU16();

    ItemPtr item = Item::create(id);
    if(item->isStackable() || item->isFluidContainer() || item->isFluid())
        item->setData(msg.getU8());

    return item;
}
Exemple #13
0
void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
{
    if(!canPerformGameAction() || !item || !toThing)
        return;

    Position pos = item->getPosition();
    if(!pos.isValid()) // virtual item
        pos = Position(0xFFFF, 0, 0); // means that is a item in inventory

    m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackPos(), toThing->getPosition(), toThing->getId(), toThing->getStackPos());
}
Exemple #14
0
void
Item::extractVariablesExcept( VariableSet &vs, const std::set<std::string> &vl ) const
{
	ItemPtr i = getParent();
	if ( i )
		i->extractVariablesExcept( vs, vl );
	for ( auto x = myVariables.begin(); x != myVariables.end(); ++x )
	{
		if ( vl.find( x->first ) == vl.end() )
			vs.emplace( std::make_pair( x->first, x->second ) );
	}
}
		virtual void shortcutPressed( ItemPtr item )
		{
			if( item->update() )
			{
				for( unsigned int i = 0; i < item->num(); ++i )
					if( ( *item )[ i ]->update() )
					{
						( *item )[ ( i + 1 ) % item->num() ]->act();
						break;
					}
			}
		}
		virtual bool act( ItemPtr item )
		{
			bool enabled = false;
			for( unsigned int i = 0; i < item->parentNum(); ++i )
			{
				Item* parent = item->parent( i );
				enabled = enabled || parent->update();
			}
			if( enabled && !item->action().empty() )
				return Manager::instance().functors().act( item->action(), item );
			return false;
		}
Exemple #17
0
IvObjectDragger::~IvObjectDragger()
{
    _SetColor(_normalColor);

    _transformBox->removeMotionCallback(_MotionHandler, this);
    if( _draggerRoot != NULL ) {
        ItemPtr selectedItem = GetSelectedItem();
        if( !!selectedItem ) {
            selectedItem->GetIvRoot()->removeChild(_draggerRoot);
        }
    }
}
bool WorldRosItem::deleteModel(gazebo_msgs::DeleteModel::Request &req,
                               gazebo_msgs::DeleteModel::Response &res)
{
  ItemPtr item = world->findItem(req.model_name);
  if (!item)
  {
    ROS_ERROR("DeleteModel: model [%s] does not exist", req.model_name.c_str());
    res.success = false;
    res.status_message = "DeleteModel: model does not exist";
    return true;
  }
  item->detachFromParentItem();
  return true;
}
Exemple #19
0
int Game::open(const ItemPtr& item, const ContainerPtr& previousContainer)
{
    if(!canPerformGameAction() || !item)
        return -1;

    int id = 0;
    if(!previousContainer)
        id = findEmptyContainerId();
    else
        id = previousContainer->getId();

    m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackPos(), id);
    return id;
}
void Container::SplitItem(ItemPtr item)
{
   auto itemLocation = std::find(this->Contents.begin(), this->Contents.end(), item);
   if (itemLocation == this->Contents.end()) {
      return;
   }

   auto newItem = Item::Clone(item);
   auto splitSize = item->GetCount() / 2;
   auto difference = (item->GetCount() - splitSize); // We don't want rounding issues
   item->SetCount(splitSize);
   newItem->SetCount(difference);
   this->Contents.insert(itemLocation + 1, newItem);
}
void Toolbar::changed( unsigned int& index, ItemPtr item )
{
	static const unsigned int MAX_MENU_TEXT = 1024;
	char txtBuf[ MAX_MENU_TEXT + 1 ];
	for( unsigned int i = 0; i < item->num(); ++i, ++index )
	{
		TBBUTTONINFO info;
		memset( &info, 0, sizeof( info ) );
		info.cbSize = sizeof( info );
		info.dwMask = TBIF_BYINDEX | TBIF_COMMAND | TBIF_IMAGE | TBIF_LPARAM
			| TBIF_SIZE | TBIF_STATE | TBIF_STYLE | TBIF_TEXT;
		info.pszText = txtBuf;
		txtBuf[0] = 0;
		info.cchText = MAX_MENU_TEXT;

		sendMessage( TB_GETBUTTONINFO, index, (LPARAM)&info );

		ItemPtr subItem = ( *item )[ i ];
		if( subItem->type() == "SEPARATOR" )
			updateSeparator( index, subItem, info );
		else if( subItem->type() == "GROUP" )
			updateGroup( index, subItem, info );
		else if( subItem->type() == "ACTION" )
			updateAction( index, subItem, info );
		else if( subItem->type() == "TOGGLE" )
			updateToggle( index, subItem, info );
		else if( subItem->type() == "CHOICE" )
			updateChoice( index, subItem, info );
		else if( subItem->type() == "EXPANDED_CHOICE" )
			updateExpandedChoice( index, subItem, info );
	}
	--index;
}
void Menu::updateGroup( HMENU hmenu, int& index, ItemPtr item, const MENUITEMINFO& info )
{
    HMENU sub = info.hSubMenu;
    if( !info.dwTypeData || buildMenuText( item ) != (LPCTSTR)info.dwTypeData )
        ModifyMenu( hmenu, index, MF_BYPOSITION | MF_STRING, item->commandID(),
                    buildMenuText( item ).c_str() );
    if( sub == NULL )
    {
        MENUITEMINFO info = { sizeof( info ), MIIM_SUBMENU };
        info.hSubMenu = ( sub = CreateMenu() );
        SetMenuItemInfo( hmenu, index, TRUE, &info );
    }
    EnableMenuItem( hmenu, index, MF_BYPOSITION | ( item->update() ? MF_ENABLED : MF_GRAYED ) );
    changed( sub, item );
}
Exemple #23
0
void Game::open(const ItemPtr& item, const ContainerPtr& previousContainer)
{
    if(!canPerformGameAction() || !item)
        return;

    int id = 0;
    if(!previousContainer) {
        // find a free container id
        while(m_containers[id] != nullptr)
            id++;
    } else {
        id = previousContainer->getId();
    }

    m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), id);
}
Exemple #24
0
void Game::processInventoryChange(int slot, const ItemPtr& item)
{
    if(item)
        item->setPosition(Position(65535, slot, 0));

    m_localPlayer->setInventoryItem((Otc::InventorySlot)slot, item);
}
void Plantable::Plant(ItemPtr sourceItem)
{
    auto x = Player::Get().GetPositionX();
    auto y = Player::Get().GetPositionY();
    auto currentLandmark = GameState::Get().GetCurrentLandmark();
    auto currentTile = currentLandmark->GetTile(x, y);

    if (currentTile.TileType != TileType::Tilled) {
        GameState::Get().AddLogMessage("You can only plant on tilled land!");
        return;
    }

    auto item = currentLandmark->GetItem(x, y);
    if (item != nullptr) {
        GameState::Get().AddLogMessageFmt("Cannot plant, %s is on the ground here.", item->GetName().c_str());
        return;
    }

    auto crop = GameState::Get().GetItemFromItemDatabase(this->Crop);
    crop->SetCount(1);
    currentLandmark->AddItem(x, y, crop);

    auto growableInterface = crop->GetInterface<Growable>(ItemInterfaceType::Growable);
    if (growableInterface != nullptr) {
        growableInterface->StartGrowing(crop);
    }

    sourceItem->RemoveOne();

}
void Toolbar::updateSeparator( unsigned int& index, ItemPtr item, TBBUTTONINFO& info )
{
	int width = item->exist( "width" )	?	atoi( (*item)[ "width" ].c_str() )	:
											6;
	if( ( info.fsStyle & BTNS_SEP ) == 0 //  not a separator
		|| info.lParam != 0 // a place-holder separator
		|| info.iImage != width ) // width, will be configurable in future
	{
		TBBUTTON button;
		memset(	&button, 0, sizeof(button) );
		button.iBitmap = width; // width of the separatar, could be configurable in future
		button.idCommand = 0;
		button.fsState = 0;
		button.fsStyle = BTNS_SEP;
		button.dwData = 0;
		button.iString = -1;

		sendMessage( TB_INSERTBUTTON, index, (LPARAM)&button );
	}
	TBBUTTONINFO buttonInfo = { sizeof( buttonInfo ), TBIF_BYINDEX | TBIF_STATE };
	buttonInfo.fsState = 0;
	if ( sendMessage( WM_CGUITOOLBAR_USE_WRAP, 0, 0 ) &&
		( info.fsState & TBSTATE_WRAP ) )
		buttonInfo.fsState |= TBSTATE_WRAP;

	if( forceChanged_ || info.fsState != buttonInfo.fsState )
		sendMessage( TB_SETBUTTONINFO, index, (LPARAM)&buttonInfo );
}
/*static*/
bool Toolbar::createToolbars(
	const std::string appTbsSection, const HwndVector& appTbsData, int iconSize /*=16*/ )
{
	ItemPtr appTbsItem = getToolbarsItem( appTbsSection );
	if ( !appTbsItem )
		return false;

	HwndVector::const_iterator hwndIt = appTbsData.begin();
	for( int i = 0; i < (int)appTbsItem->num() && hwndIt != appTbsData.end(); ++i, ++hwndIt )
	{
		Manager::instance().add(
			new Toolbar( (*appTbsItem)[ i ]->name(), *hwndIt, iconSize ) );
	}

	return true;
}
Exemple #28
0
std::shared_ptr<BuildItem>
CodeFilter::transform( TransformSet &xform ) const
{
	std::shared_ptr<BuildItem> ret = xform.getTransform( this );
	if ( ret )
		return ret;

	DEBUG( "transform CodeFilter " << getName() );
	ret = std::make_shared<BuildItem>( getName(), getDir() );
	ret->setUseName( false );

	VariableSet buildvars;
	extractVariables( buildvars );
	ret->setVariables( std::move( buildvars ) );

	if ( myTool )
	{
		ItemPtr genExe = myTool->getGeneratedExecutable();
		if ( genExe )
		{
			std::shared_ptr<BuildItem> exeDep = genExe->transform( xform );
			ret->addDependency( DependencyType::IMPLICIT, exeDep );
		}

		for ( const ItemPtr &i: myItems )
		{
			// huh, we can't call transform on these because then
			// cpp files we're going to filter will be transformed to
			// .o files.
			auto inp = std::make_shared<BuildItem>( i->getName(), i->getDir() );
			inp->setUseName( false );
			inp->setOutputDir( getDir() );
			inp->setOutputs( { i->getName() } );
			ret->addDependency( DependencyType::EXPLICIT, inp );
		}
		
		ret->setTool( myTool );
		auto outd = getDir()->reroot( xform.getArtifactDir() );
		ret->setOutputDir( outd );
		ret->setVariable( "current_output_dir", outd->fullpath() );
		ret->setOutputs( myOutputs );
	}

	xform.recordTransform( this, ret );

	return ret;
}
Exemple #29
0
bool
Item::hasToolOverride( const std::string &opt, std::string &val ) const
{
	auto x = myOverrideToolOptions.find( opt );
	if ( x != myOverrideToolOptions.end() )
	{
		val = x->second;
		return true;
	}

	ItemPtr i = getParent();
	if ( i )
		return i->hasToolOverride( opt, val );

	val.clear();
	return false;
}
void Choppable::Chop(ItemPtr sourceItem, ChoppingTool* choppingTool)
{
   if (this->GetChopPoints() < choppingTool->GetStrength()) {
      sourceItem->Destruct(true);
      return;
   }

   this->SetChopPoints(this->GetChopPoints() - choppingTool->GetStrength());
}