Example #1
0
void CButton::onEvent(Uint8 eventType)
{
	if(!display) return;
	int mouse_x = event.button.x;
	int mouse_y = event.button.y;

	if(onButton(mouse_x, mouse_y))
	{
		if(eventType == SDL_MOUSEBUTTONDOWN)
			onMouseDown();
		else if(eventType == SDL_MOUSEBUTTONUP)
			onClick();
		else if(eventType == SDL_MOUSEMOTION)
			onMouseOver();
	}
	else
		setImageState(getType());
		
}
Example #2
0
void CButton::onMouseDown()
{
	setImageState(getType() + "-down");
}
Example #3
0
void CButton::onMouseOver()
{
	setImageState(getType() + "-over");
}	
Example #4
0
void CButton::onClick()
{
	setImageState(getType() + "-over");
	game.ButtonAction(this);
}
Example #5
0
bool Player::initResources(GameBase::GameBaseData *in_data)
{
   data = dynamic_cast<PlayerData *>(in_data);

   if(!Parent::initResources(in_data))
      return false;

	updateImageMass();
	setDrag(data->drag);
	setDensity(data->density);

	int rnode = image.shape->getShape().findNode("dummyalways root");
	const TMat3F& rmat = image.shape->getTransform(rnode);
	image.shape->insertOverride("lowerback",0,&PlayerViewOverride);
	image.shape->insertOverride("lowerback",1,const_cast<TMat3F*>(&rmat));
	image.shape->setOverride(2);

	// 
	myThread = createThread (0);
   viewThread = Parent::createThread(0);
   viewThread->setPriority(-1);

   looksSequence = viewThread->GetSequenceIndex("looks");
   crouchLooksSequence = viewThread->GetSequenceIndex("crouch looks");

   if(crouchLooksSequence == -1)
      crouchLooksSequence = looksSequence;

   AssertFatal(looksSequence != -1, "DOH!");
   viewThread->SetSequence( looksSequence, 0.0 );

   damageThread = 0;
   int i;
   for (i = 0; i < Player::NUM_ANIMS; i ++)
	{
		animIndex[i] = myThread->GetSequenceIndex((char *) data->animData[i].name);
      if(animIndex[i] == -1)
         animIndex[i] = 0;
   }

	Point3F pos;
	clearAnimTransform ();
   for (int j = 0; j < Player::NUM_ANIMS; j ++)
	{
      if((j >= ANIM_MOVE_FIRST && j <= ANIM_MOVE_LAST) ||
         (j >= ANIM_CROUCH_MOVE_FIRST && j <= ANIM_CROUCH_MOVE_LAST))
      {
   		myThread->setTimeScale(1.0);
   		myThread->SetSequence(animIndex[j]);
   		myThread->AdvanceTime(1.0);
   		myThread->UpdateSubscriberList();
			image.shape->animateRoot();
   		pos = getAnimTransform();
         offsetList[j].dist = pos.len();
         offsetList[j].dir = pos;
      	if(offsetList[j].dist >= 0.1)
         {
      	   if (data->animData[j].direction <= 0)
               offsetList[j].dir *= -1 / offsetList[j].dist;
            else
               offsetList[j].dir *= 1 / offsetList[j].dist;
         }
	   	clearAnimTransform();
         offsetList[j].hasOffset = true;
      }
      else
         offsetList[j].hasOffset = false;

		myThread->SetSequence(0);
   }
   if(currentAnimation != -1)
   {
      // it's a death animation: set it to the end
      myThread->SetSequence(animIndex[currentAnimation]);
   	if (data->animData[currentAnimation].direction > 0)
   		myThread->SetPosition (0.99f);
   	else
   		myThread->SetPosition (0);
      pickNewAnimation = false;
   }

   delete flameImage.shape;
   flameImage.shape = 0;
	flameThread = 0;

	if (isGhost()) {
		char name[256];
		strcpy(name, data->flameShapeName);
		strcat(name, ".dts");

		ResourceManager *rm = SimResource::get(manager);
		Resource<TSShape> shape = rm->load(name, true);
	   if(bool(shape))
	   {
	      flameImage.shape = new TSShapeInstance(shape, *rm);
         flameThread = flameImage.shape->CreateThread();
         flameThread->setTimeScale(1.0f);
         flameThread->SetSequence("activation");
	   }
	}
	
	// Container & Collision
	boundingBox.fMin.x = -data->boxWidth;
	boundingBox.fMin.y = -data->boxDepth;
	boundingBox.fMin.z = 0;
	boundingBox.fMax.x = data->boxWidth;
	boundingBox.fMax.y = data->boxDepth;
	boundingBox.fMax.z = data->boxNormalHeight;
	collisionImage.bbox.fMin = boundingBox.fMin;
	collisionImage.bbox.fMax = boundingBox.fMax;
	collisionImage.crouchBox.fMin = boundingBox.fMin;
	collisionImage.crouchBox.fMax = boundingBox.fMax;
	setBoundingBox ();
	collisionImage.sphere.radius = (collisionImage.bbox.fMax.z - collisionImage.bbox.fMin.z) / 2;
	collisionImage.sphere.center = Point3F(0.0f,0.0f, collisionImage.sphere.radius);
	collisionImage.shapeInst = image.shape;
	collisionImage.collisionDetail = 0;
	chaseNode = image.shape->getShape().findNode ("dummyalways chasecam");
	eyeNode = image.shape->getNodeAtCurrentDetail("dummy eye");

	// Resolve all the mount node indexes.
   for(i = 0; i < MaxMountPoints; i++) {
		image.shape->setDetailLevel(0);
      mountNode[i] = image.shape->getNodeAtCurrentDetail(NodeMountName[i]);

		// HACK Alert!
		// Lower detail nodes are patch to reference the same
		// transform as the highest detail.
		TS::ShapeInstance::NodeInstance *node = image.shape->getNode(mountNode[i]);
		for (int d = 1; d < image.shape->getShape().fDetails.size(); d++) {
			image.shape->setDetailLevel(d);
      	int dn = image.shape->getNodeAtCurrentDetail(NodeMountName[i]);
			if (dn != -1)
				image.shape->getNode(dn)->fpTransform = node->fpTransform;
		}
   }
   image.shape->setDetailLevel(0);

	// Update initial state of images transfered from the server.
	for (i = 0; i < MaxItemImages; i++) {
		ItemImageEntry& itemImage = itemImageList[i];
		if (itemImage.state == ItemImageEntry::Fire)
			setImageState(i,ItemImageEntry::Fire);
	}

   return true;
}