Browse Source

- Sandbox toys are now automatically added as an input listener on the SandboxWindow object therefore they receive direct input events without the need to use the messy "package" stuff.
- Sandbox manipulation system is now an input listener of the SandboxWindow.

MelvMay-GG 12 years ago
parent
commit
3c0acab

+ 3 - 15
modules/CompositeSpriteToy/1/main.cs

@@ -22,9 +22,6 @@
 
 function CompositeSpriteToy::create( %this )
 {
-    // Activate the package.
-    activatePackage( CompositeSpriteToyPackage );
-    
     // Load scripts.
     exec( "./scripts/noLayout.cs" );
     exec( "./scripts/rectLayout.cs" );
@@ -49,7 +46,7 @@ function CompositeSpriteToy::create( %this )
     addNumericOption("Maximum Sprite Count", 10, 1000, 10, "setSpriteCount", CompositeSpriteToy.SpriteCount, true, "Sets the maximum number of sprites to create." );
     addNumericOption("Angular Velocity", -180, 180, 20, "setAngularVelocity", CompositeSpriteToy.AngularVelocity, false, "Sets the rate at which the composite sprite spins." );    
     addFlagOption("Render Isolated", "setRenderIsolated", CompositeSpriteToy.RenderIsolated, true , "Whether the composite renders its sprites isolated from the scene layer it occupies or not.");
-        
+    
     // Reset the toy.
     %this.reset();     
 }
@@ -58,8 +55,6 @@ function CompositeSpriteToy::create( %this )
 
 function CompositeSpriteToy::destroy( %this )
 {
-    // Deactivate the package.
-    deactivatePackage( CompositeSpriteToyPackage );    
 }
 
 //-----------------------------------------------------------------------------
@@ -141,15 +136,10 @@ function CompositeSpriteToy::createBackground(%this)
     SandboxScene.add( %obj );   
 }
 
+//-----------------------------------------------------------------------------
 
-package CompositeSpriteToyPackage
-{
-
-function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
+function CompositeSpriteToy::onTouchDown(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchDown(%this, %touchID, %worldPosition );
-    
     // Fetch the composite sprite.
     %compositeSprite = CompositeSpriteToy.CompositeSprite;
     
@@ -176,5 +166,3 @@ function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
         %compositeSprite.removeSprite();
     }
 }
-  
-};

+ 4 - 39
modules/DeathBallToy/1/main.cs

@@ -29,9 +29,6 @@ function DeathBallToy::create( %this )
     exec("./scripts/moveTowardBehavior.cs");
     exec("./scripts/spawnAreaBehavior.cs");
 
-    // Activate the package.
-    activatePackage( DeathBallToyPackage );
-
     // Initialize the toys settings.
     DeathBallToy.WorldTop = 35;
     DeathBallToy.WorldBottom = -110;
@@ -68,9 +65,6 @@ function DeathBallToy::destroy( %this )
 {
     // Cancel any pending events.
     DeathBallToy::cancelPendingEvents();
-
-    // Deactivate the package.
-    deactivatePackage( DeathBallToyPackage );
 }
 
 //-----------------------------------------------------------------------------
@@ -453,14 +447,8 @@ function DeathBallToy::cancelPendingEvents()
 
 //-----------------------------------------------------------------------------
 
-package DeathBallToyPackage
+function DeathBallToy::onTouchDown(%this, %touchID, %worldPosition)
 {
-
-function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
-{
-    // Call parent.
-    Parent::onTouchDown(%this, %touchID, %worldPosition );
-    
     %origin = Deathball.getPosition();
     %angle = -mRadToDeg( mAtan( getWord(%worldPosition,0)-getWord(%origin,0), getWord(%worldPosition,1)-getWord(%origin,1) ) );
 
@@ -477,11 +465,8 @@ function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
 
 //-----------------------------------------------------------------------------
 
-function SandboxWindow::onTouchUp(%this, %touchID, %worldPosition)
+function DeathBallToy::onTouchUp(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchUp(%this, %touchID, %worldPosition );
-    
     %origin = Deathball.getPosition();
     %angle = -mRadToDeg( mAtan( getWord(%worldPosition,0)-getWord(%origin,0), getWord(%worldPosition,1)-getWord(%origin,1) ) );
 
@@ -494,11 +479,8 @@ function SandboxWindow::onTouchUp(%this, %touchID, %worldPosition)
 
 //-----------------------------------------------------------------------------
 
-function SandboxWindow::onTouchDragged(%this, %touchID, %worldPosition)
-{
-    // Call parent.
-    Parent::onTouchDragged(%this, %touchID, %worldPosition );
-    
+function DeathBallToy::onTouchDragged(%this, %touchID, %worldPosition)
+{    
     %origin = Deathball.getPosition();
     %angle = -mRadToDeg( mAtan( getWord(%worldPosition,0)-getWord(%origin,0), getWord(%worldPosition,1)-getWord(%origin,1) ) );
 
@@ -512,20 +494,3 @@ function SandboxWindow::onTouchDragged(%this, %touchID, %worldPosition)
 
     Deathball.setLinearVelocity( getWord(%scaledVelocity, 0), getWord(%scaledVelocity, 1) );
 }
-
-
-//-----------------------------------------------------------------------------
-
-/*function SandboxWindow::onMouseWheelUp(%this, %modifier, %mousePoint, %mouseClickCount)
-{
-    // Don't allow zooming
-}
-
-//-----------------------------------------------------------------------------
-
-function SandboxWindow::onMouseWheelDown(%this, %modifier, %mousePoint, %mouseClickCount)
-{
-    // Don't allow zooming
-}         */
-
-};

+ 2 - 18
modules/MoveToToy/1/main.cs

@@ -22,9 +22,6 @@
 
 function MoveToToy::create( %this )
 {
-    // Activate the package.
-    activatePackage( MoveToToyPackage );    
-
     // Initialize the toys settings.
     MoveToToy.moveSpeed = 50;
     MoveToToy.trackMouse = true;
@@ -41,8 +38,6 @@ function MoveToToy::create( %this )
 
 function MoveToToy::destroy( %this )
 {
-    // Deactivate the package.
-    deactivatePackage( MoveToToyPackage );
 }
 
 //-----------------------------------------------------------------------------
@@ -164,14 +159,8 @@ function MoveToToy::setTrackMouse( %this, %value )
 
 //-----------------------------------------------------------------------------
 
-package MoveToToyPackage
-{
-
-function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
+function MoveToToy::onTouchDown(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchDown(%this, %touchID, %worldPosition );
-    
     // Set the target to the touched position.
     MoveToToy.TargetObject.Position = %worldPosition;
     
@@ -181,11 +170,8 @@ function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
 
 //-----------------------------------------------------------------------------
 
-function SandboxWindow::onTouchMoved(%this, %touchID, %worldPosition)
+function MoveToToy::onTouchMoved(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchMoved(%this, %touchID, %worldPosition );
-    
     // Finish if not tracking the mouse.
     if ( !MoveToToy.trackMouse )
         return;
@@ -196,5 +182,3 @@ function SandboxWindow::onTouchMoved(%this, %touchID, %worldPosition)
     // Move the sight to the touched position.
     MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveSpeed );     
 }
-    
-};

+ 1 - 12
modules/PointForceControllerToy/1/main.cs

@@ -22,9 +22,6 @@
 
 function PointForceControllerToy::create( %this )
 {
-    // Activate the package.
-    activatePackage( PointForceControllerToyPackage );    
-    
     // Set the sandbox drag mode availability.
     Sandbox.allowManipulation( pull );
     
@@ -322,14 +319,8 @@ function PointForceControllerToy::setAsteroidSpeed( %this, %value )
 
 //-----------------------------------------------------------------------------
 
-package PointForceControllerToyPackage
-{
-
-function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
+function PointForceControllerToy::onTouchDown(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchDown(%this, %touchID, %worldPosition );
-
     // Create an asteroid.
     %object = PointForceControllerToy.createAsteroid( %worldPosition );
     
@@ -338,5 +329,3 @@ function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
     else
         %object.setLinearVelocity( -PointForceControllerToy.asteroidSpeed, 0 );    
 }
-    
-};

+ 2 - 18
modules/RotateToToy/1/main.cs

@@ -22,9 +22,6 @@
 
 function RotateToToy::create( %this )
 {        
-    // Activate the package.
-    activatePackage( RotateToToyPackage );    
-    
     // Initialize the toys settings.
     RotateToToy.rotateSpeed = 360;
     RotateToToy.trackMouse = true;
@@ -42,8 +39,6 @@ function RotateToToy::create( %this )
 
 function RotateToToy::destroy( %this )
 {
-    // Deactivate the package.
-    deactivatePackage( RotateToToyPackage );
 }
 
 //-----------------------------------------------------------------------------
@@ -128,14 +123,8 @@ function RotateToToy::setTrackMouse( %this, %value )
 
 //-----------------------------------------------------------------------------
 
-package RotateToToyPackage
-{
-
-function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
+function RotateToToy::onTouchDown(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchDown(%this, %touchID, %worldPosition );
-    
     // Calculate the angle to the mouse.
     %origin = RotateToToy.TargetObject.getPosition();
     %angle = -mRadToDeg( mAtan( %worldPosition.x-%origin.x, %worldPosition.y-%origin.y ) );
@@ -146,11 +135,8 @@ function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
 
 //-----------------------------------------------------------------------------
 
-function SandboxWindow::onTouchMoved(%this, %touchID, %worldPosition)
+function RotateToToy::onTouchMoved(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchMoved(%this, %touchID, %worldPosition );
-    
     // Finish if not tracking the mouse.
     if ( !RotateToToy.trackMouse )
         return;
@@ -162,5 +148,3 @@ function SandboxWindow::onTouchMoved(%this, %touchID, %worldPosition)
     //Rotate to the touched angle.
     RotateToToy.TargetObject.RotateTo( %angle, RotateToToy.rotateSpeed );        
 }
-    
-};

+ 3 - 0
modules/Sandbox/1/main.cs

@@ -55,6 +55,9 @@ function Sandbox::create( %this )
     // Initialize the toolbox.    
     initializeToolbox();
     
+    // Initialize the input controller.
+    Sandbox.InputController.initialize();
+    
     // Initialize the "cannot render" proxy.
     new RenderProxy(CannotRenderProxy)
     {

+ 199 - 217
modules/Sandbox/1/scripts/manipulation.cs

@@ -30,9 +30,9 @@ Sandbox.ManipulationMode = "off";
 Sandbox.ManipulationPullMaxForce = 1000;
 
 // Reset the touch events.
-Sandbox.TouchController = new ScriptObject()
+Sandbox.InputController = new ScriptObject()
 {
-    class = SandboxTouchGesture;
+    class = SandboxInputController;
     TouchEventCount = 0;
     TouchEventActive[0] = false;
     TouchEventActive[1] = false;
@@ -45,100 +45,240 @@ Sandbox.TouchController = new ScriptObject()
 
 //-----------------------------------------------------------------------------
 
-function SandboxTouchGesture::onTouchDownEvent( %this, %touchId, %worldPosition )
+function SandboxInputController::initialize( %this )
 {
-    //echo( "SandboxTouchGesture::onTouchDownEvent(" @ %touchId @ "," @ %worldPosition @ ")" );
+    // Add sandbox touch gester as an input listener.
+    SandboxWindow.addInputListener( %this );
+}
+
+//-----------------------------------------------------------------------------
 
+function SandboxInputController::onTouchDown(%this, %touchID, %worldPosition)
+{
+    // Finish if the drag mode is off.
+    if ( Sandbox.ManipulationMode $= "off" )
+        return;
+        
     // Sanity!
     if ( %this.TouchEventActive[%touchId] == true )
     {
-        error( "SandboxTouchGesture::onTouchDownEvent() - Touch Id already active." );
-        return;        
+        error( "SandboxInputController::onTouchDown() - Touch Id already active." );
     }
+    else
+    {
+        // Calculate window position.
+        %windowPosition = SandboxWindow.getWindowPoint( %worldPosition );
 
-    // Calculate window position.
-    %windowPosition = SandboxWindow.getWindowPoint( %worldPosition );
-
-    // Store the new touch position.
-    %this.NewTouchPosition[%touchId] = %windowPosition;
+        // Store the new touch position.
+        %this.NewTouchPosition[%touchId] = %windowPosition;
+            
+        // Set the old touch position as new touch position.
+        %this.OldTouchPosition[%touchId] = %windowPosition;
         
-    // Set the old touch position as new touch position.
-    %this.OldTouchPosition[%touchId] = %windowPosition;
-    
-    // Flag event as active.
-    %this.TouchEventActive[%touchId] = true;
+        // Flag event as active.
+        %this.TouchEventActive[%touchId] = true;
 
-    // Insert the new touch Id.
-    %this.PreviousTouchId = %this.CurrentTouchId;
-    %this.CurrentTouchId = %touchId;
+        // Insert the new touch Id.
+        %this.PreviousTouchId = %this.CurrentTouchId;
+        %this.CurrentTouchId = %touchId;
 
-    // Increase event count.
-    %this.TouchEventCount++;
+        // Increase event count.
+        %this.TouchEventCount++;           
+    }
+                      
+           
+    // Handle "pull" mode.
+    if ( Sandbox.ManipulationMode $= "pull" )
+    {
+        // Reset the pull
+        Sandbox.ManipulationPullObject[%touchID] = "";
+        Sandbox.ManipulationPullJointId[%touchID] = "";
+        
+        // Pick an object.
+        %picked = SandboxScene.pickPoint( %worldPosition );
+        
+        // Finish if nothing picked.
+        if ( %picked $= "" )
+            return;
+        
+        // Fetch the pick count.
+        %pickCount = %picked.Count;
+        
+        for( %n = 0; %n < %pickCount; %n++ )
+        {
+            // Fetch the picked object.
+            %pickedObject = getWord( %picked, %n );
+            
+            // Skip if the object is static.
+            if ( %pickedObject.getBodyType() $= "static" )
+                continue;
+                
+            // Set the pull object.
+            Sandbox.ManipulationPullObject[%touchID] = %pickedObject;
+            Sandbox.ManipulationPullJointId[%touchID] = SandboxScene.createTargetJoint( %pickedObject, %worldPosition, Sandbox.ManipulationPullMaxForce );            
+            return;
+        }
+        
+        return;
+    }    
 }
 
 //-----------------------------------------------------------------------------
 
-function SandboxTouchGesture::onTouchUpEvent( %this, %touchId, %worldPosition )
+function SandboxInputController::onTouchUp(%this, %touchID, %worldPosition)
 {
-    //echo( "SandboxTouchGesture::onTouchUpEvent(" @ %touchId @ "," @ %worldPosition @ ")" );
-
+    // Finish if the drag mode is off.
+    if ( Sandbox.ManipulationMode $= "off" )
+        return;
+        
     // Sanity!
     if ( %this.TouchEventActive[%touchId] == false )
     {
-        error( "SandboxTouchGesture::onTouchUpEvent() - Touch Id not active." );
-        return;        
+        error( "SandboxInputController::onTouchUp() - Touch Id not active." );
     }
+    else
+    {    
+        // Reset previous touch.
+        %this.OldTouchPosition[%touchId] = "";
         
-    // Reset previous touch.
-    %this.OldTouchPosition[%touchId] = "";
-    
-    // Reset current touch.
-    %this.NewTouchPosition[%touchId] = "";
-    
-    // Flag event as inactive.
-    %this.TouchEventActive[%touchId] = false;
+        // Reset current touch.
+        %this.NewTouchPosition[%touchId] = "";
+        
+        // Flag event as inactive.
+        %this.TouchEventActive[%touchId] = false;
 
-    // Remove the touch Id.
-    if ( %this.PreviousTouchId == %touchId )
-    {
-         %this.PreviousTouchId = "";
-    }
-    if ( %this.CurrentTouchId == %touchId )
-    {
-         %this.CurrentTouchId = %this.PreviousTouchId;
-         %this.PreviousTouchId = "";
+        // Remove the touch Id.
+        if ( %this.PreviousTouchId == %touchId )
+        {
+             %this.PreviousTouchId = "";
+        }
+        if ( %this.CurrentTouchId == %touchId )
+        {
+             %this.CurrentTouchId = %this.PreviousTouchId;
+             %this.PreviousTouchId = "";
+        }
+
+        // Decrease event count.
+        %this.TouchEventCount--;
     }
 
-    // Decrease event count.
-    %this.TouchEventCount--;
+    // Handle "pull" mode.
+    if ( Sandbox.ManipulationMode $= "pull" )
+    {       
+        // Finish if nothing is being pulled.
+        if ( !isObject(Sandbox.ManipulationPullObject[%touchID]) )
+            return;
+        
+        // Reset the pull object.
+        Sandbox.ManipulationPullObject[%touchID] = "";
+        
+        // Remove the pull joint.
+        SandboxScene.deleteJoint( Sandbox.ManipulationPullJointId[%touchID] );
+        Sandbox.ManipulationPullJointId[%touchID] = "";        
+        return;
+    }      
 }
 
 //-----------------------------------------------------------------------------
 
-function SandboxTouchGesture::onTouchDraggedEvent( %this, %touchId, %worldPosition )
+function SandboxInputController::onTouchDragged(%this, %touchID, %worldPosition)
 {
-    //echo( "SandboxTouchGesture::onTouchDraggedEvent(" @ %touchId @ "," @ %worldPosition @ ")" );
+    // Finish if the drag mode is off.
+    if ( Sandbox.ManipulationMode $= "off" )
+        return;
 
     // Sanity!
     if ( %this.TouchEventActive[%touchId] == false )
     {
-        error( "SandboxTouchGesture::onTouchDraggedEvent() - Touch Id not active." );
-        return;        
+        error( "SandboxInputController::onTouchDraggedEvent() - Touch Id not active." );
     }
+    else
+    {
+        // Calculate window position.
+        %windowPosition = SandboxWindow.getWindowPoint( %worldPosition );
 
-    // Calculate window position.
-    %windowPosition = SandboxWindow.getWindowPoint( %worldPosition );
+        // Set the current touch as the previous touch.
+        %this.OldTouchPosition[%touchId] = %this.NewTouchPosition[%touchId];
+        
+        // Store the touch event.
+        %this.NewTouchPosition[%touchId] = %windowPosition;
+    }
+        
+    // Handle "pan" mode.
+    if ( Sandbox.ManipulationMode $= "pan" )
+    {
+        // Fetch the touch event count.
+        %touchEventCount = Sandbox.InputController.TouchEventCount;
+        
+        // Do we have a single touch event?
+        if ( %touchEventCount == 1 )
+        {
+            // Yes, so perform pan gesture.
+            Sandbox.InputController.performPanGesture();
+            
+            return;
+        }
+        
+        // Do we have two event counts?
+        if ( %touchEventCount == 2 )
+        {
+            // Yes, so perform zoom gesture.
+            Sandbox.InputController.performZoomGesture();
 
-    // Set the current touch as the previous touch.
-    %this.OldTouchPosition[%touchId] = %this.NewTouchPosition[%touchId];
+            return;
+        }
+    }
     
-    // Store the touch event.
-    %this.NewTouchPosition[%touchId] = %windowPosition;
+    // Handle "pull" mode.
+    if ( Sandbox.ManipulationMode $= "pull" )
+    {
+        // Finish if nothing is being pulled.
+        if ( !isObject(Sandbox.ManipulationPullObject[%touchID]) )
+            return;
+              
+        // Set a new target for the target joint.
+        SandboxScene.setTargetJointTarget( Sandbox.ManipulationPullJointId[%touchID], %worldPosition );
+        
+        return;
+    }
+}
+
+//-----------------------------------------------------------------------------
+
+function SandboxInputController::onTouchMoved(%this, %touchID, %worldPosition)
+{
+    // Finish if the drag mode is off.
+    if ( Sandbox.ManipulationMode $= "off" )
+        return;
+}
+
+//-----------------------------------------------------------------------------
+
+function SandboxInputController::onMouseWheelUp(%this, %modifier, %mousePoint, %mouseClickCount)
+{
+    // Finish if the drag mode is not "pan".
+    if ( !Sandbox.ManipulationMode $= "pan" )
+        return;
+        
+    // Increase the zoom.
+    SandboxWindow.setCameraZoom( SandboxWindow.getCameraZoom() + $pref::Sandbox::cameraMouseZoomRate );
 }
 
 //-----------------------------------------------------------------------------
 
-function SandboxTouchGesture::performPanGesture( %this )
+function SandboxInputController::onMouseWheelDown(%this, %modifier, %mousePoint, %mouseClickCount)
+{
+    // Finish if the drag mode is not "pan".
+    if ( !Sandbox.ManipulationMode $= "pan" )
+        return;
+
+    // Increase the zoom.
+    SandboxWindow.setCameraZoom( SandboxWindow.getCameraZoom() - $pref::Sandbox::cameraMouseZoomRate );
+}
+
+//-----------------------------------------------------------------------------
+
+function SandboxInputController::performPanGesture( %this )
 {
     // Finish if we don't have two touch events.
     if ( %this.TouchEventCount != 1 )
@@ -150,7 +290,7 @@ function SandboxTouchGesture::performPanGesture( %this )
     // Sanity!
     if ( %touchId $= "" )
     {
-        error( "SandboxTouchGesture::performPanGesture() - Current touch Id not available." );
+        error( "SandboxInputController::performPanGesture() - Current touch Id not available." );
         return;
     }
 
@@ -169,7 +309,7 @@ function SandboxTouchGesture::performPanGesture( %this )
 
 //-----------------------------------------------------------------------------
 
-function SandboxTouchGesture::performZoomGesture( %this )
+function SandboxInputController::performZoomGesture( %this )
 {
     // Finish if we don't have two touch events.
     if ( %this.TouchEventCount != 2 )
@@ -182,7 +322,7 @@ function SandboxTouchGesture::performZoomGesture( %this )
     // Finish if we don't have touch Ids active.
     if ( !%this.TouchEventActive[%currentTouchId] || !%this.TouchEventActive[%previousTouchId] )
     {
-        error( "SandboxTouchGesture::performZoomGesture() - Current or previous touch events were no active." );
+        error( "SandboxInputController::performZoomGesture() - Current or previous touch events were no active." );
         return;
     }
 
@@ -327,161 +467,3 @@ function cycleManipulation( %make )
         Sandbox.useManipulation("off");
     }          
 }
-
-//-----------------------------------------------------------------------------
-
-function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
-{
-    // Finish if the drag mode is off.
-    if ( Sandbox.ManipulationMode $= "off" )
-        return;
-        
-    // Set touch event.
-    Sandbox.TouchController.onTouchDownEvent( %touchID, %worldPosition );
-           
-    // Handle "pull" mode.
-    if ( Sandbox.ManipulationMode $= "pull" )
-    {
-        // Reset the pull
-        Sandbox.ManipulationPullObject[%touchID] = "";
-        Sandbox.ManipulationPullJointId[%touchID] = "";
-        
-        // Pick an object.
-        %picked = SandboxScene.pickPoint( %worldPosition );
-        
-        // Finish if nothing picked.
-        if ( %picked $= "" )
-            return;
-        
-        // Fetch the pick count.
-        %pickCount = %picked.Count;
-        
-        for( %n = 0; %n < %pickCount; %n++ )
-        {
-            // Fetch the picked object.
-            %pickedObject = getWord( %picked, %n );
-            
-            // Skip if the object is static.
-            if ( %pickedObject.getBodyType() $= "static" )
-                continue;
-                
-            // Set the pull object.
-            Sandbox.ManipulationPullObject[%touchID] = %pickedObject;
-            Sandbox.ManipulationPullJointId[%touchID] = SandboxScene.createTargetJoint( %pickedObject, %worldPosition, Sandbox.ManipulationPullMaxForce );            
-            return;
-        }
-        
-        return;
-    }    
-}
-
-//-----------------------------------------------------------------------------
-
-function SandboxWindow::onTouchUp(%this, %touchID, %worldPosition)
-{
-    // Finish if the drag mode is off.
-    if ( Sandbox.ManipulationMode $= "off" )
-        return;
-        
-    // Set touch event.
-    Sandbox.TouchController.onTouchUpEvent( %touchID, %worldPosition );
-
-    // Handle "pull" mode.
-    if ( Sandbox.ManipulationMode $= "pull" )
-    {       
-        // Finish if nothing is being pulled.
-        if ( !isObject(Sandbox.ManipulationPullObject[%touchID]) )
-            return;
-        
-        // Reset the pull object.
-        Sandbox.ManipulationPullObject[%touchID] = "";
-        
-        // Remove the pull joint.
-        SandboxScene.deleteJoint( Sandbox.ManipulationPullJointId[%touchID] );
-        Sandbox.ManipulationPullJointId[%touchID] = "";        
-        return;
-    }      
-}
-
-//-----------------------------------------------------------------------------
-
-function SandboxWindow::onTouchMoved(%this, %touchID, %worldPosition)
-{
-    // Finish if the drag mode is off.
-    if ( Sandbox.ManipulationMode $= "off" )
-        return;
-}
-
-//-----------------------------------------------------------------------------
-
-function SandboxWindow::onTouchDragged(%this, %touchID, %worldPosition)
-{
-    // Finish if the drag mode is off.
-    if ( Sandbox.ManipulationMode $= "off" )
-        return;
-
-    // Set touch event.
-    Sandbox.TouchController.onTouchDraggedEvent( %touchID, %worldPosition );
-    
-    // Handle "pan" mode.
-    if ( Sandbox.ManipulationMode $= "pan" )
-    {
-        // Fetch the touch event count.
-        %touchEventCount = Sandbox.TouchController.TouchEventCount;
-        
-        // Do we have a single touch event?
-        if ( %touchEventCount == 1 )
-        {
-            // Yes, so perform pan gesture.
-            Sandbox.TouchController.performPanGesture();
-            
-            return;
-        }
-        
-        // Do we have two event counts?
-        if ( %touchEventCount == 2 )
-        {
-            // Yes, so perform zoom gesture.
-            Sandbox.TouchController.performZoomGesture();
-
-            return;
-        }
-    }
-    
-    // Handle "pull" mode.
-    if ( Sandbox.ManipulationMode $= "pull" )
-    {
-        // Finish if nothing is being pulled.
-        if ( !isObject(Sandbox.ManipulationPullObject[%touchID]) )
-            return;
-              
-        // Set a new target for the target joint.
-        SandboxScene.setTargetJointTarget( Sandbox.ManipulationPullJointId[%touchID], %worldPosition );
-        
-        return;
-    }
-}
-
-//-----------------------------------------------------------------------------
-
-function SandboxWindow::onMouseWheelUp(%this, %modifier, %mousePoint, %mouseClickCount)
-{
-    // Finish if the drag mode is not "pan".
-    if ( !Sandbox.ManipulationMode $= "pan" )
-        return;
-        
-    // Increase the zoom.
-    SandboxWindow.setCameraZoom( SandboxWindow.getCameraZoom() + $pref::Sandbox::cameraMouseZoomRate );
-}
-
-//-----------------------------------------------------------------------------
-
-function SandboxWindow::onMouseWheelDown(%this, %modifier, %mousePoint, %mouseClickCount)
-{
-    // Finish if the drag mode is not "pan".
-    if ( !Sandbox.ManipulationMode $= "pan" )
-        return;
-
-    // Increase the zoom.
-    SandboxWindow.setCameraZoom( SandboxWindow.getCameraZoom() - $pref::Sandbox::cameraMouseZoomRate );
-}

+ 4 - 1
modules/Sandbox/1/scripts/toys.cs

@@ -85,7 +85,10 @@ function loadToy( %moduleDefinition )
     }
     
     // Add the scene so it's unloaded when the toy module is.
-    %moduleDefinition.ScopeSet.add( SandboxScene );        
+    %moduleDefinition.ScopeSet.add( SandboxScene );    
+    
+    // Add toy scope-set as a listener.
+    SandboxWindow.addInputListener( %moduleDefinition.ScopeSet );        
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 15
modules/ScrollerToy/1/main.cs

@@ -22,9 +22,6 @@
 
 function ScrollerToy::create( %this )
 {
-    // Activate the package.
-    activatePackage( ScrollerToyPackage );  
-    
     // Reset the toy.
     ScrollerToy.reset();
 }
@@ -33,8 +30,6 @@ function ScrollerToy::create( %this )
 
 function ScrollerToy::destroy( %this )
 {
-    // Deactivate the package.
-    deactivatePackage( ScrollerToyPackage );    
 }
 
 //-----------------------------------------------------------------------------
@@ -151,14 +146,8 @@ function ScrollerToy::createNearScroller( %this )
 
 //-----------------------------------------------------------------------------
 
-package ScrollerToyPackage
-{
-
-function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
+function ScrollerToy::onTouchDown(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchDown(%this, %touchID, %worldPosition );
-
     // Set the scrollers speed to be the distance from the farground scrollers origin.
     // Also use the sign to control the direction of scrolling.
     %scrollerSpeed = %worldPosition.x - ScrollerToy.FarScroller.Position.x;
@@ -167,6 +156,3 @@ function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
     ScrollerToy.FarScroller.ScrollX = %scrollerSpeed;
     ScrollerToy.NearScroller.ScrollX = %scrollerSpeed * 1.5;
 }
-    
-};
-

+ 2 - 15
modules/TruckToy/1/main.cs

@@ -22,9 +22,6 @@
 
 function TruckToy::create( %this )
 {        
-    // Activate the package.
-    activatePackage( TruckToyPackage );
-
     TruckToy.ObstacleFriction = 1.5;
     TruckToy.CameraWidth = 20;
     TruckToy.CameraHeight = 15;
@@ -932,14 +929,8 @@ function TruckToy::setRotateCamera( %this, %value )
 
 //-----------------------------------------------------------------------------
 
-package TruckToyPackage
-{
-
-function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
+function TruckToy::onTouchDown(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchDown(%this, %touchID, %worldPosition );
-    
     // Finish if truck is already moving.
     if ( TruckToy.TruckMoving )
         return;
@@ -957,13 +948,9 @@ function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
 
 //-----------------------------------------------------------------------------
 
-function SandboxWindow::onTouchUp(%this, %touchID, %worldPosition)
+function TruckToy::onTouchUp(%this, %touchID, %worldPosition)
 {
-    // Call parent.
-    Parent::onTouchUp(%this, %touchID, %worldPosition );
-    
     // Stop the truck.
     TruckToy.truckStop();
 }
     
-};