Ejemplo n.º 1
0
	/**
	 * Process gesture (scale, rotate)
	 * Else move.
	 */
	function onTouchMove(event)
	{
		event.stopImmediatePropagation();

		var touches = event.originalEvent.touches;

		Mouse.screen.x = touches[0].pageX;
		Mouse.screen.y = touches[0].pageY;

		// Not in gesture, just process
		if (!_processGesture) {
			return;
		}

		var scale = touchDistance(touches) - _scale;
		//var angle = touchAngle(touches) / _angle;
		var x     = Math.abs(touchTranslationX(_touches, touches));
		var y     = Math.abs(touchTranslationY(_touches, touches));

		if (!Camera.action.active && (x > 10 || y > 10)) {
			KEYS.SHIFT = (y > x);
			Camera.rotate(true);
			return;
		}

		// Process zoom
		if (Math.abs(scale) > 10) {
			Camera.zoomFinal += scale * 0.1;
			Camera.zoomFinal = Math.min( Camera.zoomFinal, Math.abs(Camera.altitudeTo-Camera.altitudeFrom) * Camera.MAX_ZOOM );
			Camera.zoomFinal = Math.max( Camera.zoomFinal,  2.0 );
		}
	}
Ejemplo n.º 2
0
	/**
	 * What to do when clicking on the map ?
	 */
	function onMouseDown( event )
	{
		var action = event && event.which || 1;

		Session.moveAction = null;

		if (!Mouse.intersect) {
			return;
		}

		switch (action) {

			// Left click
			case 1:
				var entityFocus = EntityManager.getFocusEntity();
				var entityOver  = EntityManager.getOverEntity();
				var stop        = false;

				if (entityFocus && entityFocus != entityOver) {
					entityFocus.onFocusEnd();
					EntityManager.setFocusEntity(null);
				}

				// Entity picking ?
				if (entityOver) {
					stop = stop || entityOver.onMouseDown();
					stop = stop || entityOver.onFocus();
					EntityManager.setFocusEntity(entityOver);

					// Know if propagate to map mousedown
					if (stop) {
						return;
					}
				}

				// Start walking
				if (this.onRequestWalk) {
					this.onRequestWalk();
				}
				break;

			// Right Click
			case 3:
				_rightClickPosition[0] = Mouse.screen.x;
				_rightClickPosition[1] = Mouse.screen.y;

				Cursor.setType( Cursor.ACTION.ROTATE );
				Camera.rotate( true );
				break;
		}
	}
Ejemplo n.º 3
0
	/**
	 * What to do when stop clicking on the map ?
	 */
	function onMouseUp( event )
	{
		var entity;
		var action = event && event.which || 1;

		// Not rendering yet
		if (!Mouse.intersect) {
			return;
		}

		switch (action) {

			// Left click
			case 1:
				// Remove entity picking ?
				entity = EntityManager.getFocusEntity();

				if (entity) {
					entity.onMouseUp();

					// Entity lock is only on MOB type
					if (Preferences.noctrl === false || entity.objecttype !== entity.constructor.TYPE_MOB) {
						EntityManager.setFocusEntity(null);
						entity.onFocusEnd();
					}
				}

				// stop walking
				if (this.onRequestStopWalk) {
					this.onRequestStopWalk();
				}
				break;

			// Right Click
			case 3:
				Cursor.setType( Cursor.ACTION.DEFAULT );
				Camera.rotate( false );

				// Seems like it's how the official client handle the contextmenu
				// Just check for the same position on mousedown and mouseup
				if (_rightClickPosition[0] === Mouse.screen.x && _rightClickPosition[1] === Mouse.screen.y) {
					entity = EntityManager.getOverEntity();

					if (entity && entity !== Session.Entity) {
						entity.onContextMenu();
					}
				}
				break;
		}
	}
Ejemplo n.º 4
0
	/**
	 * Hook touch end to know when a gesture end
	 * process OnMouseUp if no gesture detected
	 */
	function onTouchEnd(event)
	{
		if (_processGesture) {
			_processGesture = false;
			KEYS.SHIFT      = false;
			Camera.rotate(false);
			return;
		}

		if (_timer > -1) {
			_intersect = false;
			return;
		}

		if (Mobile.onTouchEnd) {
			Mobile.onTouchEnd();
		}

		Mouse.intersect = false;
	}