Example #1
0
    virtual public void HandleSingleTouchMoved(FTouch touch)
    {
        Vector2 touchPos = GetLocalTouchPosition(touch);

        //expand the hitrect so that it has more error room around the edges
        //this is what Apple does on iOS and it makes for better usability
        Rect expandedRect = _hitRect.CloneWithExpansion(expansionAmount);

        if (expandedRect.Contains(touchPos))
        {
            _sprite.element = _downElement;
            if (_shouldUseCustomColors)
            {
                _sprite.color = _downColor;
            }
            isTouchOver  = true;
            _isTouchDown = true;
        }
        else
        {
            _sprite.element = _upElement;
            if (_shouldUseCustomColors)
            {
                _sprite.color = _upColor;
            }
            isTouchOver  = false;
            _isTouchDown = false;
        }
    }
    public bool HandleSingleTouchBegan(FTouch touch)
    {
        touchWasUsedCorrectly = false;

        if (blackallDoneAnimatingIn && tesserDoneAnimatingIn && !(numTrebellaLettersInPlace == 8 && numNonTrebellaLettersLeft == 0))
        {
            HandleTouchOnBlackallAndTesser(touch);
        }

        if (trebellaLettersDoneSolidifying && !trebellaLettersDoneTurningIntoHearts)
        {
            touchWasUsedCorrectly = true;
            foreach (FLabel letter in trebellaLetters)
            {
                if (letter.textRect.Contains(letter.GlobalToLocal(touch.position)))
                {
                    numTrebellaLettersTurnedIntoHearts++;
                    letter.RemoveFromContainer();
                    trebellaLetters.Remove(letter);
                    ExplodeHeartsFromPoint(touch.position);
                    FSoundManager.PlaySound("success");
                    break;
                }
            }

            if (numTrebellaLettersTurnedIntoHearts == 8)
            {
                trebellaLettersDoneTurningIntoHearts = true;
            }
        }

        return(true);
    }
Example #3
0
 public void HandleMultiTouch(FTouch[] touches)
 {
     foreach(FTouch touch in touches)
     {
         if (touch.phase == TouchPhase.Ended) {
             if (_draw!=null) {
                 _draw.RemoveFromContainerAnimated();
                 _draw=null;
             }
         } else if (touch.phase == TouchPhase.Began) {
             if (_draw==null) {
                 float c0=RXRandom.Float();
                 float c1=RXRandom.Float();
                 float c2=RXRandom.Float();
                 float c3=RXRandom.Float();
                 float c4=RXRandom.Float();
                 float c5=RXRandom.Float();
                 _draw = new FMotionStreakWithBorderSprite("Futile_White", // texture name
                     10+RXRandom.Int(20),  //Number of quads in the trail
                     x => 15.0f*(float)Math.Sin (1.0f*x*x*x*Math.PI),  // width of the band function, x represents the offset in the band and 0<= x <=1
                     x => new Color(c0,c1,c2,(float)Math.Sin (1.0f*x*Math.PI)),  //color of the band function, x represents the offset in the band and 0<= x <=1
                     x => 10f*(float)Math.Sin (1.0f*x*Math.PI),
                     x => new Color(c3,c4,c5,(float)Math.Sin (1.0f*x*Math.PI))
                     );
                 AddChild(_draw);
             }
             _draw.PushPosition(touch.position);
         } else if (touch.phase == TouchPhase.Moved) {
             if (_draw!=null) _draw.PushPosition(touch.position);
         }
     }
 }
Example #4
0
    bool FSmartTouchableInterface.HandleSmartTouchBegan(int touchIndex, FTouch touch)
    {
        if (!_isEnabled)
        {
            return(false);
        }
        if (!_isTouchable)
        {
            return(false);
        }
        if (touchIndex > 0)
        {
            return(false);                       //we only want the first touch for now
        }
        _isTouchInBounds = GetLocalRect().Contains(GetLocalTouchPosition(touch));

        if (_isTouchInBounds)
        {
            _theTouch = touch;
            if (SignalPress != null)
            {
                SignalPress(this);
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #5
0
    public bool HandleTouchBegan(FTouch touch)
    {
        foreach (ImTableCell cell in tableCells)
        {
            if (cell.LocalRectContainsTouch(touch))
            {
                if (cell.item != null)
                {
                    cell.UseItem(correspondingEntity);
                    if (SignalItemUsed != null)
                    {
                        SignalItemUsed(cell.item);
                    }
                    RemoveTableCell(cell);
                    if (SignalNeedsInventoryRefresh != null)
                    {
                        SignalNeedsInventoryRefresh(this);
                    }
                }
                else if (cell.tableCellType == TableCellType.Done)
                {
                    Dismiss();
                }
                return(true);
            }
        }

        return(false);
    }
        bool TouchIsWithinRange(FTouch touch)
        {
            var distance = Futile.screen.halfWidth;
            var origin   = new Vector2(-Futile.screen.halfWidth, -Futile.screen.halfHeight);

            return((touch.position - origin).sqrMagnitude <= (distance * distance));
        }
Example #7
0
    public void HandleSingleTouchEnded(FTouch touch)
    {
        isTouchOver = false;

        _bg.element = _upElement;
        _bg.color   = _upColor;

        Vector2 touchPos = _bg.GlobalToLocal(touch.position);

        //expand the hitrect so that it has more error room around the edges
        //this is what Apple does on iOS and it makes for better usability
        Rect expandedRect = _bg.textureRect.CloneWithExpansion(expansionAmount);

        if (expandedRect.Contains(touchPos))
        {
            if (SignalRelease != null)
            {
                SignalRelease(this);
            }
        }
        else
        {
            if (SignalReleaseOutside != null)
            {
                SignalReleaseOutside(this);
            }
        }
    }
Example #8
0
    public void HandleMultiTouch(FTouch[] touches)
    {
        foreach(FTouch touch in touches)
        {
            if(touch.phase == TouchPhase.Began)
            {

                //we go reverse order so that if we remove a banana it doesn't matter
                //and also so that that we check from front to back

                for (int b = _bananas.Count-1; b >= 0; b--)
                {
                    BBanana banana = _bananas[b];

                    Vector2 touchPos = banana.GlobalToLocal(touch.position);

                    if(banana.textureRect.Contains(touchPos))
                    {
                        HandleGotBanana(banana);
                        break; //break so that a touch can only hit one banana at a time
                    }
                }
            }
        }
    }
    public bool HandleSingleTouchBegan(FTouch touch)
    {
        if (gameIsOver && !initiatedSceneSwitch)
        {
            FSoundManager.StopMusic();
            initiatedSceneSwitch = true;
            if (goalType == GoalType.GoalOne)
            {
                TMain.SwitchToScene(TMain.SceneType.PeopleSceneGoalOne);
            }
            else if (goalType == GoalType.GoalTwo)
            {
                TMain.SwitchToScene(TMain.SceneType.PeopleSceneGoalTwo);
            }
            else if (goalType == GoalType.GoalThree)
            {
                TMain.SwitchToScene(TMain.SceneType.PeopleSceneGoalThree);
            }
        }

        if (readyToStartOver && !initiatedSceneSwitch)
        {
            initiatedSceneSwitch = true;
            TMain.SwitchToScene(TMain.SceneType.PeopleSceneGoalOne);
        }

        return(true);
    }
Example #10
0
    public bool HandleSingleTouchBegan(FTouch touch)
    {
        if (!_isTouchable)
        {
            return(false);
        }
        if (!_isEnabled)
        {
            return(false);
        }

        Vector2 touchPos = _bg.GlobalToLocal(touch.position);

        if (_bg.textureRect.Contains(touchPos))
        {
            isTouchOver = true;
            _bg.element = _downElement;
            _bg.color   = _downColor;

            if (_soundName != null)
            {
                FSoundManager.PlaySound(_soundName);
            }

            if (SignalPress != null)
            {
                SignalPress(this);
            }

            return(true);
        }

        return(false);
    }
 public void HandleMultiTouch(FTouch[] touches)
 {
     foreach(FTouch touch in touches){
         if(touch.phase == TouchPhase.Ended){
         }
     }
 }
Example #12
0
    public bool HandleSingleTouchBegan(FTouch touch)
    {
        _shouldCheckForHoverState = false;

        Vector2 touchPos = _bg.GlobalToLocal(touch.position);

        if (_bg.textureRect.Contains(touchPos))
        {
            _bg.element = _downElement;

            if (_soundName != null)
            {
                FSoundManager.PlaySound(_soundName);
            }

            if (SignalPress != null)
            {
                SignalPress(this);
            }

            return(true);
        }

        return(false);
    }
Example #13
0
    public void HandleSingleTouchEnded(FTouch touch)
    {
        if (shouldReturnToUpElementAfterTouch)
        {
            _bg.element = _upElement;
        }

        Vector2 touchPos = _bg.GlobalToLocal(touch.position);

        //expand the hitrect so that it has more error room around the edges
        //this is what Apple does on iOS and it makes for better usability
        Rect expandedRect = _bg.textureRect.CloneWithExpansion(expansionAmount);

        if (expandedRect.Contains(touchPos))
        {
            if (SignalRelease != null)
            {
                SignalRelease(this);
            }
        }
        else
        {
            if (SignalReleaseOutside != null)
            {
                SignalReleaseOutside(this);
            }
            _shouldCheckForHoverState = true;
        }
    }
Example #14
0
 void FSmartTouchableInterface.HandleSmartTouchCanceled(int touchIndex, FTouch touch)
 {
     if (SignalReleaseOutside != null)
     {
         SignalReleaseOutside(this);
     }
 }
Example #15
0
    public void HandleSingleTouchEnded(FTouch touch)
    {
        _isTouchDown = false;

        _sprite.element = _upElement;

        Vector2 touchPos = _sprite.GlobalToLocal(touch.position);

        //expand the hitrect so that it has more error room around the edges
        //this is what Apple does on iOS and it makes for better usability
        Rect expandedRect = _hitRect.CloneWithExpansion(expansionAmount);

        if (expandedRect.Contains(touchPos))
        {
            if (SignalRelease != null)
            {
                SignalRelease(this);
            }

            if (_supportsOver && _hitRect.Contains(touchPos))            //go back to the over image if we're over the button
            {
                _sprite.element = _overElement;
            }
        }
        else
        {
            if (SignalReleaseOutside != null)
            {
                SignalReleaseOutside(this);
            }
        }
    }
Example #16
0
    public void HandleSingleTouchEnded(FTouch touch)
    {
        var handler = this.TouchEnded;

        if (handler != null)
        {
            handler(this, new TouchEventArgs()
            {
                Touch = touch
            });
        }

        var   gridVector = this.Map.GlobalToGrid(touch.position);
        var   curTeam    = this.CurrentTeam;
        Actor tempActor;

        Debug.Log("[[Touch Detected]]: World Coordinates: " + touch.position + ", Map Coordinates: " + gridVector);
        if (this.SelectedActor == null)
        {
            if (this.Map.TryGetActor(gridVector, out tempActor))
            {
                if (tempActor.Team == curTeam && tempActor.TurnState == ActorState.CommandsAvailable)
                {
                    this.SelectedActor           = tempActor;
                    this.SelectedActor.TurnState = ActorState.AwaitingCommand;
                    Debug.Log("[[Actor Turn Start]]: Actor " + this.SelectedActor);
                    this.showButtonStrip(this.SelectedActor);
                }
            }
        }
    }
 public void HandleSingleTouchEnded(FTouch touch)
 {
     if (!touchWasUsedCorrectly)
     {
         FSoundManager.PlaySound("error");
     }
 }
    //SINGLE TOUCH DELEGATE

    public bool HandleSingleTouchBegan(FTouch touch)
    {
        isDragging = true;
        lastX      = GetLocalTouchPosition(touch).x;
        lastY      = GetLocalTouchPosition(touch).y;

        return(true);
    }
Example #19
0
    public void LogFTouch(Touch touch, string target, string time)
    {
        FTouch newFTouch = new FTouch(touch, target, time);

        //AppendToFile(LogPath, ",", "TOUCH", time, touch.fingerId.ToString(), touch.position.x.ToString(), touch.position.y.ToString(), controller.ToString());
        FTouches.Add(newFTouch);
        //Debug.Log("Add");
    }
Example #20
0
 public void HandleSingleTouchCanceled(FTouch touch)
 {
     _bg.element = _upElement;
     if (SignalReleaseOutside != null)
     {
         SignalReleaseOutside(this);
     }
 }
Example #21
0
 public void HandleMultiTouch(FTouch[] touches)
 {
     foreach(FTouch touch in touches)
     {
         if (touch.phase == TouchPhase.Ended) {
             //Click(touch.position);
         }
     }
 }
Example #22
0
 public void HandleMultiTouch(FTouch[] touches)
 {
     foreach(FTouch touch in touches)
     {
         if (touch.phase == TouchPhase.Ended) {
             TestSpeechBubbles(touch.position);
         }
     }
 }
Example #23
0
 public void HandleMultiTouch(FTouch[] touches)
 {
     if (touches.Length > 0){
         touchPos = touches[0].position;
     }
     if (touches.Length > 1){
         shoot();
     }
 }
    public bool HandleSingleTouchBegan(FTouch touch)
    {
        // for now, just do dragging, not tracking

        //originalTouchPoint_ = touch.position;
        lastTouchPoint_ = touch.position;

        return(true);
    }
Example #25
0
 public void HandleSingleTouchCanceled(FTouch touch)
 {
     _bg.element = _upElement;
     if (SignalReleaseOutside != null)
     {
         SignalReleaseOutside(this);
     }
     _shouldCheckForHoverState = true;
 }
Example #26
0
 public void HandleSingleTouchCanceled(FTouch touch)
 {
     isTouchOver = false;
     _bg.element = _upElement;
     _bg.color   = _upColor;
     if (SignalReleaseOutside != null)
     {
         SignalReleaseOutside(this);
     }
 }
Example #27
0
 /**
  * Targeted touch disabling, intended to ensure none of a particular set of buttons
  * is signalled to release by the currently-active touch.
  */
 public bool CancelSingleTouches(ICollection <FSingleTouchableInterface> targets, FTouch touch)
 {
     if (targets.Contains(_theSingleTouchable))
     {
         _theSingleTouchable.HandleSingleTouchCanceled(touch);
         _theSingleTouchable = null;
         return(true);
     }
     return(false);
 }
Example #28
0
 /**
  * Targeted touch disabling, intended to ensure a particular button is not
  * signalled to release by the currently-active touch.
  */
 public bool CancelSingleTouch(FSingleTouchableInterface target, FTouch touch)
 {
     if (target == _theSingleTouchable)
     {
         _theSingleTouchable.HandleSingleTouchCanceled(touch);
         _theSingleTouchable = null;
         return(true);
     }
     return(false);
 }
Example #29
0
    public void HandleSingleTouchCanceled(FTouch touch)
    {
        _isTouchDown = false;

        _sprite.element = _upElement;
        if (SignalReleaseOutside != null)
        {
            SignalReleaseOutside(this);
        }
    }
Example #30
0
 public bool HandleSingleTouchBegan(FTouch touch)
 {
     if (this.SelectedActor != null && this.SelectedActor.TurnState == ActorState.AwaitingCommand)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Example #31
0
 public void HandleMultiTouch(FTouch[] touches)
 {
     foreach(FTouch touch in touches)
     {
         if (touch.phase == TouchPhase.Ended) {
             ChangeSplitRatio(touch.position);
         } else if (touch.phase == TouchPhase.Moved) {
             ChangeSplitRatio(touch.position);
         }
     }
 }
Example #32
0
 public bool HandleSingleTouchBegan(FTouch touch)
 {
     if (this.selectedActor != null && this.selectedActor.TurnState == ActorState.AwaitingCommand)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
    public void HandleSingleTouchMoved(FTouch touch)
    {
        rejector++;

        if (rejector > 0)        // Nevermind this. I'm trying to figure out why touches cause lag on android
        {
            float xPos = mBombaNode.GlobalToLocal(touch.position).x;

            mPepper.setPosition(xPos);
            rejector = 0;
        }
    }
    public void HandleSingleTouchMoved(FTouch touch)
    {
        rejector++;

        if(rejector > 0) // Nevermind this. I'm trying to figure out why touches cause lag on android
        {
            float xPos = mBombaNode.GlobalToLocal(touch.position).x;

            mPepper.setPosition(xPos);
            rejector = 0;
        }
    }
Example #35
0
    virtual public bool HandleSingleTouchBegan(FTouch touch)
    {
        if (!buttonEnabled)
        {
            return(false);
        }

        _isTouchDown = false;

        if (!IsAncestryVisible())
        {
            return(false);
        }

        if (!_shouldUseCustomHitRect)
        {
            _hitRect = _sprite.textureRect;
        }

        Vector2 touchPos = _sprite.GetLocalTouchPosition(touch);

        if (_hitRect.Contains(touchPos))
        {
            if (_isEnabled)            //swallow touches all the time, but only listen to them when enabled
            {
                _sprite.element = _downElement;
                if (_shouldUseCustomColors)
                {
                    _sprite.color = _downColor;
                }

                if (_clickSoundName != null)
                {
                    FSoundManager.PlaySound(_clickSoundName);
                }

                if (SignalPress != null)
                {
                    SignalPress(this);
                }

                _isTouchDown = true;

                Debug.Log("HandleSingleTouchBegan - Button tapped!");
                _isEnabled = false;
            }

            return(true);
        }

        return(false);
    }
    public bool HandleSingleTouchBegan(FTouch touch)
    {
        foreach (FSprite sprite in compartmentSprites) {
            /*if (sprite.textureRect.Contains(sprite.GlobalToLocal(touch.position))) {
                if (sprite.color == Color.blue) sprite.color = Color.red;
                else sprite.color = Color.blue;
            }*/
            Debug.Log(sprite.textureRect);
            //Debug.Log(sprite.element.atlas.texture.GetPixel((int)touch.position.x, (int)touch.position.y));
        }

        return true;
    }
Example #37
0
    public bool LocalRectContainsTouch(FTouch touch)
    {
        Vector2 localPos = backgroundSpriteComponent.sprite.GlobalToLocal(touch.position);

        if (backgroundSpriteComponent.sprite.localRect.Contains(localPos))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #38
0
    public virtual bool HandleSingleTouchBegan(FTouch touch)
    {
        Vector2 touchPos = base.GetLocalTouchPosition(touch);

        if (_hitRect.Contains(touchPos))
        {
            indicatorValue = Mathf.Abs((base.x - _hitRect.width / 2) - _movableIndicator.x) / _hitRect.width;
            _movableIndicator.x = Mathf.Clamp(LocalToGlobal(touchPos).x, (base.x - _hitRect.width / 2) + _movableIndicator.width / 2, (base.x + _hitRect.width / 2) - _movableIndicator.width / 2);
            return true;
        }

        return false;
    }
Example #39
0
 /**
  * Targeted touch disabling, intended to ensure none of a particular set of buttons
  * is signalled to release by the currently-active touch.  Overload is included to
  * circumvent Mono's inability to recognized an ICollection<FSingleTouchableInterface>
  * in a Dictionary<string, FButton>.ValueCollection.
  */
 public bool CancelSingleTouches(ICollection targets, FTouch touch)
 {
     foreach (object obj in targets)
     {
         if (obj == _theSingleTouchable)
         {
             _theSingleTouchable.HandleSingleTouchCanceled(touch);
             _theSingleTouchable = null;
             return(true);
         }
     }
     return(false);
 }
Example #40
0
    public bool ContainsTouch(FTouch touch)
    {
        FSliceSprite sprite   = SliceSpriteComponents()[0].sprite;
        Vector2      localPos = GlobalToLocal(touch.position);

        if (sprite.localRect.Contains(localPos))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #41
0
    public void HandleMultiTouch(FTouch[] touches)
    {
        foreach(FTouch touch in touches)
        {
            {

                //we go reverse order so that if we remove a banana it doesn't matter
                //and also so that that we check from front to back
                terrain.Update((this.GetLocalTouchPosition(touch)));
            terrain.RemoveTiles();

            }
        }
    }
Example #42
0
    virtual public void HandleSingleTouchCanceled(FTouch touch)
    {
        _isTouchDown = false;

        _sprite.element = _upElement;
        if (_shouldUseCustomColors)
        {
            _sprite.color = _upColor;
        }
        if (SignalReleaseOutside != null)
        {
            SignalReleaseOutside(this);
        }
    }
Example #43
0
    public void HandleSingleTouchEnded(FTouch touch)
    {
        var gridVector = this.map.GlobalToGrid(touch.position);
        Debug.Log("Touch at: " + touch.position + ", map grid: " + gridVector);

        if (this.selectedActor != null)
        {
            var actorState = this.selectedActor.TurnState;
            if (actorState == ActorState.SelectingDestination)
            {
                if (this.pathfindResults != null && this.pathfindResults.VisitablePoints.Contains(gridVector))
                {
                    this.selectedActor.HasMovedThisTurn = true;
                    this.selectedActor.TurnState = ActorState.AwaitingCommand;
                    this.map.UpdateLocation(this.selectedActor, gridVector);

                    // Recompute the set of attackable points, since the actor has moved.
                    var tempEnum = MoveAndAttackHelper.GetAttackablePoints(this.map, gridVector, 1, 6);
                    this.localAttackablePoints = new HashSet<Vector2i>(tempEnum);
                    this.showButtonStrip(this.selectedActor);
                    this.clearHighlights();
                }
            }
            else if(actorState == ActorState.SelectingEnemy)
            {
                if (this.localAttackablePoints.Contains(gridVector))
                {
                    Debug.Log("Attacking point: " + gridVector);
                    Vector2 source = new Vector2(this.selectedActor.x, this.selectedActor.y);
                    Vector2 dest = this.map.GridToGlobal(gridVector);
                    this.ShootLaser(source, dest);
                }
            }
        }
        else if (this.map.TryGetActor(gridVector, out this.selectedActor))
        {
            var actorState = this.selectedActor.TurnState;
            if (actorState == ActorState.TurnStart)
            {
                this.selectedActor.TurnState = ActorState.AwaitingCommand;
                this.pathfindResults = MoveAndAttackHelper.Pathfind(this.map, this.selectedActor);
                var tempEnum = MoveAndAttackHelper.GetAttackablePoints(this.map, gridVector, 1, 6);
                this.localAttackablePoints = new HashSet<Vector2i>(tempEnum);
                this.showButtonStrip(this.selectedActor);
            }
        }
    }
Example #44
0
    public virtual void HandleTouch(FTouch touch)
    {
        Vector2 touchPos = this.GlobalToLocal(touch.position);

        Rect expandedRect = _hitRect.CloneWithExpansion(expansionAmount);

        if (expandedRect.Contains(touchPos))
        {
            if (!continuousTouch) {
                if (touch.phase != TouchPhase.Began) {
                    return;
                }
            }
            if (SignalPress != null) SignalPress();
            alpha = 1f;
        }
    }
Example #45
0
    public void HandleMultiTouch(FTouch[] touches)
    {
        foreach(FTouch touch in touches) {
            if (touch.phase == TouchPhase.Began) {
                for (int i = thingies.Count - 1; i >= 0; i--) {
                    Thingy thingy = thingies[i];
                    FSprite sprite = thingy.GetChildAt(0) as FSprite;
                    Vector2 touchPos = sprite.GlobalToLocal(touch.position);
                    Rect rect = sprite.textureRect;

                    if (rect.Contains(touchPos)) {
                        HandleGotThingy(thingy);
                        break;
                    }
                }
            }
        }
    }
Example #46
0
    public void HandleMultiTouch(FTouch[] touches)
    {
        foreach(FTouch touch in touches)
        {
            {

                if((this.localRect.CloneAndMultiply(4)).Contains(this.GetLocalTouchPosition(touch))) {
                    p = touch.position;
                    p = Vector3.Max(p, new Vector3(-Futile.screen.halfWidth+32, -Futile.screen.halfHeight + 32, 0));
                    p = Vector3.Min(p, new Vector3(Futile.screen.halfWidth-32, Futile.screen.halfHeight - 32, 0));
                    float dist = Vector2.Distance(new Vector2(this.x, this.y), new Vector2(p.x, p.y));

                    Go.killAllTweensWithTarget(this);
                    Go.to(this, 1.0f / dist, new TweenConfig().floatProp("x", p.x).floatProp("y", p.y));
                    break;
                }

            }
        }
    }
Example #47
0
    public virtual void HandleSingleTouchEnded(FTouch touch)
    {
        Vector2 touchPos = base.GetLocalTouchPosition(touch);

        //expand the hitrect so that it has more error room around the edges
        //this is what Apple does on iOS and it makes for better usability
        Rect expandedRect = _hitRect.CloneWithExpansion(expansionAmount);

        if (expandedRect.Contains(touchPos))
        {
            if (SignalRelease != null) SignalRelease();
            indicatorValue = Mathf.Abs((base.x - _hitRect.width / 2) - _movableIndicator.x) / _hitRect.width;
            _movableIndicator.x = Mathf.Clamp(LocalToGlobal(touchPos).x, (base.x - _hitRect.width / 2) + _movableIndicator.width / 2, (base.x + _hitRect.width / 2) - _movableIndicator.width / 2);
            indicatorValue = indicatorValue >= 0.92 ? indicatorValue + 0.1f : indicatorValue;
            indicatorValue = Mathf.Clamp(indicatorValue, 0, 1);
        }
        else
        {
        }
    }
Example #48
0
    public void HandleMultiTouch(FTouch[] touches)
    {
        foreach(FTouch touch in touches)
        {
            if (touch.phase == TouchPhase.Ended) {
                if (_draw!=null) {
                    _draw.Flush();
                }
            } else if (touch.phase == TouchPhase.Began) {
                if (_draw!=null) {
                    _draw.RemoveFromContainer();
                    _draw=null;
                }
                _draw=new FDrawingSprite("Futile_White");
                AddChild(_draw);

                _draw.SetLineThickness(RXRandom.Range(4f,10f));
                Color color=RandomUtils.RandomColor();
                color.a=1f;
                _draw.SetLineColor(color);

                _draw.PushBorder (RXRandom.Range(2f,5f),RandomUtils.RandomColor(),RXRandom.Float()<0.5f?true:false);
                _draw.PushTopBorder (RXRandom.Range(2f,5f),RandomUtils.RandomColor(),RXRandom.Float()<0.5f?true:false);
                //_draw.PushBorder (4,new Color(1f,1f,0f,1f),false);
                if (RXRandom.Float()<0.5f) {
                    _draw.PushBorder (RXRandom.Range(1f,4f),RandomUtils.RandomColor(),RXRandom.Float()<0.5f?true:false);
                    if (RXRandom.Float()<0.5f) {
                        _draw.PushBorder (RXRandom.Range(1f,4f),RandomUtils.RandomColor(),RXRandom.Float()<0.5f?true:false);
                        if (RXRandom.Float()<0.5f) {
                            _draw.PushBorder (RXRandom.Range(1f,4f),RandomUtils.RandomColor(),RXRandom.Float()<0.5f?true:false);
                        }
                    }
                }

                _draw.MoveTo(touch.position.x,touch.position.y);
            } else if (touch.phase == TouchPhase.Moved) {
                if (_draw==null) return;
                _draw.LineTo(touch.position.x,touch.position.y);
            }
        }
    }
    public override void onUpdate(FTouch[] touches)
    {
        //If not starting
        if (m_StartTime > START_DURATION) {
            //Manage blinking
            m_Time -= Time.deltaTime;
            m_Instruction1.isVisible = m_Time > BLINK_DURATION;
            if (m_Time < 0) m_Time += BLINK_DURATION * 2;

            //if game exist
            if (m_Game != null) {
                //For each touch,
                for (int i = 0; i < touches.Length; i++) {
                    //If released
                    if (touches[i].phase == TouchPhase.Ended) {
                        //SFX
                        FSoundManager.PlaySound("success");

                        //Start
                        m_StartTime = START_DURATION;
                        RemoveAllChildren();
                        AddChild(m_Title);
                    }
                }
            }
        } else {
            //Reduce start duration
            m_StartTime -= Time.deltaTime;
            if (m_StartTime < 0) {
                //Start game
                m_Active = false;
                m_Game.start();
            } else {
                //Move
                m_Title.y = Futile.screen.height * 0.6f;
                m_Title.y += ((Futile.screen.height * 0.4f) + (m_Title.textureRect.height / 2)) * (START_DURATION - m_StartTime) / START_DURATION;
            }
        }
    }
Example #50
0
        void UpdateWithTouch( FTouch touch )
        {
            if (touchId == -1 && TouchIsBegan( touch ) && TouchIsWithinRange( touch ))
            {
                touchId = touch.fingerId;
                SetPosition( touch.position );
            }

            if (touchId == touch.fingerId)
            {
                if (TouchIsEnded( touch ))
                {
                    delta = Vector2.zero;
                    value = Vector2.zero;
                    touchId = -1;
                    return;
                }

                delta = Vector2.ClampMagnitude( touch.position - GetPosition(), 64.0f );
                value = delta / 64.0f;

                return;
            }
        }
Example #51
0
        void UpdateWithTouch( FTouch touch )
        {
            if (touchId == touch.fingerId)
            {
                if (TouchIsEnded( touch ))
                {
                    touchId = -1;
                    return;
                }

                value = 1.0f;
                return;
            }

            if (!TouchIsEnded( touch ) && TouchIsWithinDistance( touch, 32.0f ))
            {
                if (TouchIsBegan( touch ) && touchId == -1)
                {
                    touchId = touch.fingerId;
                }

                value = 1.0f;
            }
        }
Example #52
0
 public override void HandleSingleTouchMoved(FTouch touch)
 {
     isAdding = true;
 }
Example #53
0
 public override void HandleSingleTouchEnded(FTouch touch)
 {
     isAdding = false;
 }
Example #54
0
    public virtual void Update()
    {
        if (!isEnabled) return;

        _isUpdating = true;

        if(_needsPrioritySort)
        {
            UpdatePrioritySorting();
        }

        float touchScale = 1.0f/Futile.displayScale;

        //the offsets account for the camera's 0,0 point (eg, center, bottom left, etc.)
        float offsetX = -Futile.screen.originX * Futile.screen.pixelWidth;
        float offsetY = -Futile.screen.originY * Futile.screen.pixelHeight;

        //Debug.Log ("Touch offset " + offsetX + " , " + offsetY);

        bool wasMouseTouch = false;
        FTouch mouseTouch = new FTouch();

        if(shouldMouseEmulateTouch)
        {
            mouseTouch.position = new Vector2((Input.mousePosition.x+offsetX)*touchScale, (Input.mousePosition.y+offsetY)*touchScale);

            mouseTouch.fingerId = 0;
            mouseTouch.tapCount = 1;
            mouseTouch.deltaTime = Time.deltaTime;

            if(Input.GetMouseButtonDown(0))
            {
                mouseTouch.deltaPosition = new Vector2(0,0);
                _previousMousePosition = mouseTouch.position;

                mouseTouch.phase = TouchPhase.Began;
                wasMouseTouch = true;
            }
            else if(Input.GetMouseButtonUp(0))
            {
                mouseTouch.deltaPosition = new Vector2(mouseTouch.position.x - _previousMousePosition.x, mouseTouch.position.y - _previousMousePosition.y);
                _previousMousePosition = mouseTouch.position;
                mouseTouch.phase = TouchPhase.Ended;
                wasMouseTouch = true;
            }
            else if(Input.GetMouseButton(0))
            {
                mouseTouch.deltaPosition = new Vector2(mouseTouch.position.x - _previousMousePosition.x, mouseTouch.position.y - _previousMousePosition.y);
                _previousMousePosition = mouseTouch.position;

                mouseTouch.phase = TouchPhase.Moved;
                wasMouseTouch = true;
            }
        }

        int touchCount = Input.touchCount;
        int offset = 0;

        if(wasMouseTouch) touchCount++;

        FTouch[] touches = new FTouch[touchCount];

        if(wasMouseTouch)
        {
            touches[0] = mouseTouch;
            offset = 1;
        }

        for (int i = 0; i < Input.touchCount; ++i)
        {
            Touch sourceTouch = Input.GetTouch (i);
            FTouch resultTouch = new FTouch();

            resultTouch.deltaPosition = new Vector2(sourceTouch.deltaPosition.x*touchScale, sourceTouch.deltaPosition.y*touchScale);
            resultTouch.deltaTime = sourceTouch.deltaTime;
            resultTouch.fingerId = sourceTouch.fingerId+offset;
            resultTouch.phase = sourceTouch.phase;
            resultTouch.position = new Vector2((sourceTouch.position.x+offsetX)*touchScale, (sourceTouch.position.y+offsetY)*touchScale);
            resultTouch.tapCount = sourceTouch.tapCount;

            touches[i+offset] = resultTouch;
        }

        int singleTouchableCount = _singleTouchables.Count;

        int lowestFingerId = int.MaxValue;

        for(int t = 0; t<touchCount; t++)
        {
            FTouch touch = touches[t];
            if(touch.fingerId < lowestFingerId)
            {
                lowestFingerId = touch.fingerId;
            }
        }

        for(int t = 0; t<touchCount; t++)
        {
            FTouch touch = touches[t];

            if(touch.fingerId == lowestFingerId) // we only care about the first touch for the singleTouchables
            {
                if(touch.phase == TouchPhase.Began)
                {
                    for(int s = 0; s<singleTouchableCount; s++)
                    {
                        FSingleTouchableInterface singleTouchable = _singleTouchables[s];
                        if(singleTouchable.HandleSingleTouchBegan(touch)) //the first touchable to return true becomes theSingleTouchable
                        {
                            _theSingleTouchable = singleTouchable;
                            break;
                        }
                    }
                }
                else if(touch.phase == TouchPhase.Ended)
                {
                    if(_theSingleTouchable != null)
                    {
                        _theSingleTouchable.HandleSingleTouchEnded(touch);
                    }
                    _theSingleTouchable = null;
                }
                else if(touch.phase == TouchPhase.Canceled)
                {
                    if(_theSingleTouchable != null)
                    {
                        _theSingleTouchable.HandleSingleTouchCanceled(touch);
                    }
                    _theSingleTouchable = null;
                }
                else //moved or stationary
                {
                    if(_theSingleTouchable != null)
                    {
                        _theSingleTouchable.HandleSingleTouchMoved(touch);
                    }
                }

                break; //break out from the foreach, once we've found the first touch we don't care about the others
            }
        }

        if(touchCount > 0)
        {
            int multiTouchableCount = _multiTouchables.Count;
            for(int m = 0; m<multiTouchableCount; m++)
            {
                _multiTouchables[m].HandleMultiTouch(touches);
            }
        }

        //now add or remove anything that was changed while we were looping through

        for(int s = 0; s<_singleTouchablesToRemove.Count; s++)
        {
            _singleTouchables.Remove(_singleTouchablesToRemove[s]);
        }

        for(int s = 0; s<_singleTouchablesToAdd.Count; s++)
        {
            _singleTouchables.Add(_singleTouchablesToAdd[s]);
        }

        for(int m = 0; m<_multiTouchablesToRemove.Count; m++)
        {
            _multiTouchables.Remove(_multiTouchablesToRemove[m]);
        }

        for(int m = 0; m<_multiTouchablesToAdd.Count; m++)
        {
            _multiTouchables.Add(_multiTouchablesToAdd[m]);
        }

        _singleTouchablesToRemove.Clear();
        _singleTouchablesToAdd.Clear();
        _multiTouchablesToRemove.Clear();
        _multiTouchablesToAdd.Clear();

        _isUpdating = false;
    }
 public void HandleMultiTouch(FTouch[] touches)
 {
     foreach(FTouch touch in touches){
     }
 }
    public void HandleSingleTouchMoved(FTouch touch)
    {
        Vector2 touchPos = _bg.GlobalToLocal(touch.position);

        //expand the hitrect so that it has more error room around the edges
        //this is what Apple does on iOS and it makes for better usability
        Rect expandedRect = _bg.textureRect.CloneWithExpansion(expansionAmount);

        if(expandedRect.Contains(touchPos))
        {
            _bg.element = _downElement;
            _bg.color = _downColor;
        }
        else
        {
            _bg.element = _upElement;
            _bg.color = _upColor;
        }
    }
 public void HandleSingleTouchCanceled(FTouch touch)
 {
     _bg.element = _upElement;
     _bg.color = _upColor;
     if(SignalReleaseOutside != null) SignalReleaseOutside(this);
 }
    public bool HandleSingleTouchBegan(FTouch touch)
    {
        if(!_isEnabled) return false;

        Vector2 touchPos = _bg.GlobalToLocal(touch.position);

        if(_bg.textureRect.Contains(touchPos))
        {
            _bg.element = _downElement;
            _bg.color = _downColor;

            if(_soundName != null) FSoundManager.PlaySound(_soundName);

            if(SignalPress != null) SignalPress(this);

            return true;
        }

        return false;
    }
Example #59
0
	virtual public void HandleSingleTouchCanceled(FTouch touch)
	{
		_isTouchDown = false;
		
		_sprite.element = _upElement;
		if (_shouldUseCustomColors)
		{
			_sprite.color = _upColor;
		}
		if(SignalReleaseOutside != null) SignalReleaseOutside(this);
	}
Example #60
0
	virtual public void HandleSingleTouchEnded(FTouch touch)
	{
		_isTouchDown = false;
		
		_sprite.element = _upElement;
		if (_shouldUseCustomColors)
		{
			_sprite.color = _upColor;
		}
		
        Vector2 touchPos = _sprite.GetLocalTouchPosition(touch);
		
		//expand the hitrect so that it has more error room around the edges
		//this is what Apple does on iOS and it makes for better usability
		Rect expandedRect = _hitRect.CloneWithExpansion(expansionAmount);
		
		if(expandedRect.Contains(touchPos))
		{
			if(SignalRelease != null) SignalRelease(this);
			
			if(_supportsOver && _hitRect.Contains(touchPos)) //go back to the over image if we're over the button
			{
				_sprite.element = _overElement;	
				if (_shouldUseCustomColors)
				{
					_sprite.color = _overColor;
				}
			}
		}
		else
		{
			if(SignalReleaseOutside != null) SignalReleaseOutside(this);	
		}
	}