private void HandleTouchEnded(List <CCTouch> touches, CCEvent touchEvent)
        {
            if (!touchEvent.CurrentTarget.BoundingBoxTransformedToParent.ContainsPoint(touches[0].Location))
            {
                return;
            }

            PauseListeners(true);

            var cardSprite = ChosenCard.CardSprite = new CCSprite(ChosenCard.ImageName);

            cardSprite.ContentSize = new CCSize(_cardWidth, _cardHeight);
            cardSprite.Scale       = .1f;
            cardSprite.Position    = cardSprite.BoundingBox.UpperRight;
            cardSprite.UserObject  = ChosenCard;

            touchEvent.CurrentTarget.AddChild(cardSprite, 1);

            var animateCardIn = new CCScaleTo(.5f, 1.0f);

            cardSprite.RunAction(animateCardIn);



            touchEvent.StopPropogation();
            RemoveEventListener(_touchListeners[touchEvent.CurrentTarget.Tag]);
            FlipCards(touchEvent.CurrentTarget);
            ChangeTeams();

            ScheduleOnce(GoToChooseCard, 4f);
        }
Пример #2
0
 private protected override void OnTouchesBeganUI(List <CCTouch> touches, CCEvent touchEvent)
 {
     touchEvent.StopPropogation();
     if (touches.Count > 0)
     {
         // turn darker when pressed
         Color = CCColor3B.DarkGray;
     }
 }
Пример #3
0
 internal void TouchesMoved(List <CCTouch> touches, CCEvent touchEvent)
 {
     touchEvent.StopPropogation();
     if (touches.Count > 0)
     {
         var touch = touches[0];
         // move to the position that is allowed and closest to the touch (the closest point that is still inside the ManeuverPolygon)
         MoveHeadToClosestPointInsideManeuverPolygon(touch.Location);
     }
 }
Пример #4
0
 private protected void OnTouchesMoved(List <CCTouch> touches, CCEvent touchEvent)
 {
     if (MyVisible && Pressed)
     {
         if (SwallowTouch)
         {
             touchEvent.StopPropogation();
         }
         OnTouchesMovedUI(touches, touchEvent);
     }
 }
Пример #5
0
 private protected void OnTouchesEnded(List <CCTouch> touches, CCEvent touchEvent)
 {
     if (MyVisible && (TouchMustEndOnIt ? TouchIsOnIt(touches[0]) : true) && Pressed)
     {
         if (SwallowTouch)
         {
             touchEvent.StopPropogation();
         }
         OnTouchesEndedUI(touches, touchEvent);
     }
     Pressed = false;
 }
Пример #6
0
 private protected void OnTouchesBegan(List <CCTouch> touches, CCEvent touchEvent)
 {
     if (Pressable && MyVisible && TouchStartedOnIt(touches[0]))
     {
         if (SwallowTouch)
         {
             touchEvent.StopPropogation();
         }
         Pressed = true;
         OnTouchesBeganUI(touches, touchEvent);
     }
 }
Пример #7
0
 internal void TouchesBegan(List <CCTouch> touches, CCEvent touchEvent)
 {
     touchEvent.StopPropogation();
     if (touches.Count > 0)
     {
         var touch = touches[0];
         // show alternative orders (super-speed, shield, ...)
         ShowAvailableOrders();
         // make sure no other aircrafts have their options exposed at the same time
         ((PlayLayer)Layer).TellFlightPathHeadsToShowHeadsOnly(Aircraft);
     }
 }
Пример #8
0
 internal void OnTouchesBegan(List <CCTouch> touches, CCEvent touchEvent)
 {
     if (Pressable && MyVisible && TouchStartedOnIt(touches[0]))
     {
         if (SwallowTouch)
         {
             //Console.WriteLine("SWALLOWED: "+touches[0].Location);
             touchEvent.StopPropogation();
         }
         Pressed = true;
         OnTouchesBeganUI(touches, touchEvent);
     }
 }
Пример #9
0
 private protected override void OnTouchesBeganUI(List <CCTouch> touches, CCEvent touchEvent)
 {
     touchEvent.StopPropogation();
     if (touches.Count > 0)
     {
         // turn darker when pressed
         StartSprite.Color  = CCColor3B.Gray;
         MiddleSprite.Color = CCColor3B.Gray;
         EndSprite.Color    = CCColor3B.Gray;
         label.Color        = CCColor3B.Gray;
         label2.Color       = CCColor3B.Gray;
     }
 }
Пример #10
0
 void OnTouchesBegan(List <CCTouch> touches, CCEvent touchEvent)
 {
     if (touches.Count != 0)
     {
         var button        = (NavigateButton)touchEvent.CurrentTarget;
         var buttonClicked = button.graphic.BoundingBoxTransformedToWorld.ContainsPoint(touches.First().Location);
         if (buttonClicked)
         {
             Action();
             touchEvent.StopPropogation();
         }
     }
 }
 private protected void StopSwiping(List <CCTouch> touches, CCEvent touchEvent)
 {
     if (TouchCount == 0)
     {
         if (SwipingUpDown)
         {
             touchEvent.StopPropogation();
             // since the event is stopped here the WreckCarousel has to be informed manually
             WreckageLayer.WreckCarousel.Pressed = false;
             const float actionRate = 2f;
             const float actionTime = 0.25f;
             CCAction    action;
             var         reenableCarousel = new CCCallFunc(() => { if (WreckageLayer.State == WreckageLayer.WreckageState.CAROUSEL)
                                                                   {
                                                                       WreckageLayer.WreckCarousel.Pressable = true;
                                                                   }
                                                           });
             var bounds = WreckageLayer.VisibleBoundsWorldspace;
             // release the wreck
             var wreck = WreckageLayer.MiddleAircraft;
             if (wreck.PositionWorldspace.Y > bounds.Center.Y + bounds.Size.Height * 0.25f)
             {
                 // salvage
                 WreckageLayer.WreckCarousel.Pressable = false;
                 action = new CCSequence(new CCEaseOut(new CCMoveTo(actionTime, WreckPositionOriginal + new CCPoint(0, VisibleBoundsWorldspace.Size.Height)), actionRate),
                                         new CCCallFunc(WreckageLayer.Salvage) /*,
                                                                                * reenableCarousel*/);
             }
             else if (wreck.PositionWorldspace.Y < bounds.Center.Y - bounds.Size.Height * 0.25f &&
                      WreckageLayer.GetWreckPercentile(WreckageLayer.MiddleAircraft) < WreckageLayer.GetWreckMaxPercentile(WreckageLayer.MiddleAircraft))
             {
                 // repair
                 WreckageLayer.WreckCarousel.Pressable = false;
                 action = new CCSequence(new CCEaseOut(new CCMoveTo(actionTime, WreckPositionOriginal), actionRate),
                                         new CCCallFunc(WreckageLayer.StartRepair) /*,
                                                                                    * reenableCarousel*/);
             }
             else
             {
                 // reset
                 action = new CCSequence(new CCEaseOut(new CCMoveTo(actionTime, WreckPositionOriginal), actionRate),
                                         reenableCarousel);
             }
             action.Tag = ActionTag;
             wreck.AddAction(action);
         }
         // reset flags
         SwipeIsUndecided = true;
         SwipingUpDown    = false;
     }
 }
Пример #12
0
 private protected override void OnTouchesEndedUI(List <CCTouch> touches, CCEvent touchEvent)
 {
     touchEvent.StopPropogation();
     if (touches.Count > 0)
     {
         // turn back to original color when released
         Color = CCColor3B.White;
         var touch = touches[0];
         if (TouchIsOnIt(touch))
         {
             ButtonEnded(touch);
         }
     }
 }
Пример #13
0
 private protected void OnTouchesBeganDoAccounting(List <CCTouch> touches, CCEvent touchEvent)
 {
     foreach (var touch in touches)
     {
         if (!ActiveTouches.ContainsKey(touch))
         {
             //Console.WriteLine("TOUCH ADDED, ID: " + touch.Id);
             ActiveTouches.Add(touch, touch.Location);
         }
     }
     if (touches.Count > 0)
     {
         TouchCount += touches.Count;
         // intercept all additional touches (don't allow a second touch)
         if (TouchCount > 1)
         {
             touchEvent.StopPropogation();
         }
     }
 }
Пример #14
0
 private protected override void OnTouchesEndedUI(List <CCTouch> touches, CCEvent touchEvent)
 {
     touchEvent.StopPropogation();
     if (touches.Count > 0)
     {
         // turn back to original color when released
         StartSprite.Color  = CCColor3B.White;
         MiddleSprite.Color = CCColor3B.White;
         EndSprite.Color    = CCColor3B.White;
         label.Color        = CCColor3B.White;
         label2.Color       = CCColor3B.White;
         var touch = touches[0];
         if (TouchIsOnIt(touch))
         {
             // move the popUp out of view and remove it
             RemovePerAction();
             Pressable = false;
             ClickedEvent?.Invoke(this, EventArgs.Empty);
         }
     }
 }
 /// <summary>
 /// Check whether the swipe type has to be decided and if it is an up/down-swipe intercept the event and use it.
 /// </summary>
 /// <param name="touches"></param>
 /// <param name="touchEvent"></param>
 private protected void SwipeUpDown(List <CCTouch> touches, CCEvent touchEvent)
 {
     if (touches.Count == 1)
     {
         if (WreckageLayer.State == WreckageLayer.WreckageState.CAROUSEL && WreckageLayer.WreckCarousel.MiddleNode != null)
         {
             var touch = touches[0];
             if (SwipeIsUndecided)
             {
                 if (touch.Delta != CCPoint.Zero)
                 {
                     SwipingUpDown    = Math.Abs(touch.Delta.Y) > Math.Abs(touch.Delta.X);
                     SwipeIsUndecided = false;
                 }
                 // disable the carousel when swiping up/down
                 if (SwipingUpDown)
                 {
                     WreckageLayer.WreckCarousel.Pressable = false;
                 }
                 if (SwipingUpDown && WreckageLayer.MiddleAircraft != null && (WreckageLayer.MiddleAircraft.GetActionState(ActionTag) == null || WreckageLayer.MiddleAircraft.GetActionState(ActionTag).IsDone))
                 {
                     WreckPositionOriginal = WreckageLayer.MiddleAircraft.Position;
                 }
             }
             if (SwipingUpDown)
             {
                 // move the wreckage middle node
                 WreckageLayer.MiddleAircraft.PositionY += touch.Delta.Y * 2;
                 // stop the current move-action if there is one
                 WreckageLayer.MiddleAircraft.StopAction(ActionTag);
             }
         }
     }
     if (SwipingUpDown)
     {
         // swallow the touch event
         touchEvent.StopPropogation();
     }
 }
Пример #16
0
 private protected void OnTouchesEndedDoAccounting(List <CCTouch> touches, CCEvent touchEvent)
 {
     foreach (var touch in touches)
     {
         ActiveTouches.Remove(touch);
         //Console.WriteLine("TOUCH REMOVED, ID: " + touch.Id);
         //Console.WriteLine("ActiveTouches.Count: " + ActiveTouches.Count);
     }
     if (touches.Count > 0)
     {
         TouchCount -= touches.Count;
         if (TouchCount < 0)
         {
             TouchCount = 0;
         }
         touchEvent.IsStopped = false; // workaround for a bug that is created by the swallowing of a touchMoved-event in UIElement(Node)
         // intercept the event if there are touches remaining (i.e. only the last release will be the "real" release)
         if (TouchCount > 0)
         {
             touchEvent.StopPropogation();
         }
         //Console.WriteLine("TouchCount: " + TouchCount);
     }
 }
        new private protected void OnTouchesEnded(List <CCTouch> touches, CCEvent touchEvent)
        {
            base.OnTouchesEnded(touches, touchEvent);
            switch (touches.Count)
            {
            case 1:
            {
                var touch = touches[0];
                if (DragAndDropObject != null)
                {
                    touchEvent.StopPropogation();
                    switch (HangarLayer.State)
                    {
                    case HangarLayer.HangarState.HANGAR:
                        var selectedAircraft = DragAndDropObject as Aircraft;
                        DragAndDropObject = null;
                        if (selectedAircraft != null)
                        {
                            // if an aircraft is dragged upon the takeoff node add it to the collection
                            if (!(TakeoffNode.BoundingBoxTransformedToParent.ContainsPoint(touch.Location) && TakeoffCollectionNode.AddToCollection(selectedAircraft)))
                            {
                                // if not, then place it back into the hangar
                                HangarLayer.AddAircraftChild(selectedAircraft);
                                selectedAircraft.Scale = Constants.STANDARD_SCALE;
                                HangarLayer.PlaceAircraft(selectedAircraft, HangarLayer.GUICoordinatesToHangar(selectedAircraft.Position));
                            }
                            if (TakeoffCollectionNode.Collection.Any())
                            {
                                GOButton.AddAction(HangarLayer.AddGOButton);
                                TakeoffCollectionLabel.Visible = false;
                            }
                            else if (!PopUp.TriggeredPlayLayer)
                            {
                                TakeoffCollectionLabel.Visible = true;
                            }
                        }
                        break;

                    case HangarLayer.HangarState.MODIFY_AIRCRAFT:
                    {
                        bool mounted = false;
                        HangarLayer.UpdateClosestMount();
                        // the object is a part
                        var part = (Part)DragAndDropObject;
                        DragAndDropObject = null;
                        // if it is a body and the aircraft currently has none (which means no parts at all)
                        if (HangarLayer.ModifiedAircraft.Body == null && part.Types.Contains(Part.Type.BODY) && CCPoint.IsNear(HangarLayer.GUICoordinatesToHangar(part.PositionWorldspace), HangarLayer.ModifiedAircraft.PositionWorldspace, MOUNT_DISTANCE))
                        {
                            // set it as the aircraft body
                            HangarLayer.ModifiedAircraft.InWorkshopConfiguration = false;
                            part.Scale = 1;
                            HangarLayer.ModifiedAircraft.Body = part;
                            HangarLayer.ModifiedAircraft.InWorkshopConfiguration = true;
                            HangarLayer.CalcBoundaries();                 // the aircraft has changed size, so update the boundaries
                            HangarLayer.DrawInModifyAircraftState();
                            mounted = true;
                        }
                        // check if the part is currently at a mount point where it can be mounted
                        else if (!mounted)
                        {
                            var possibleMounts = new List <PartMount>();
                            foreach (var modPart in HangarLayer.ModifiedAircraft.TotalParts)
                            {
                                foreach (var mountPoint in modPart.PartMounts)
                                {
                                    if (mountPoint.Available && mountPoint.CanMount(part))
                                    {
                                        if (CCPoint.IsNear(HangarLayer.GUICoordinatesToHangar(part.PositionWorldspace), mountPoint.PositionModifyAircraft, MOUNT_DISTANCE))
                                        {
                                            possibleMounts.Add(mountPoint);
                                        }
                                    }
                                }
                            }
                            // mount at the closest possible mount point
                            float     minDistance  = float.PositiveInfinity;
                            PartMount closestMount = null;
                            foreach (var mountPoint in possibleMounts)
                            {
                                float distance = CCPoint.Distance(HangarLayer.GUICoordinatesToHangar(part.PositionWorldspace), mountPoint.PositionModifyAircraft);
                                if (distance < minDistance)
                                {
                                    minDistance  = distance;
                                    closestMount = mountPoint;
                                }
                            }
                            if (closestMount != null)
                            {
                                // better mount in non-workshop configuration
                                HangarLayer.ModifiedAircraft.InWorkshopConfiguration = false;
                                part.Scale = 1;
                                closestMount.MyPart.MountPart(closestMount, part);
                                HangarLayer.ModifiedAircraft.InWorkshopConfiguration = true;
                                HangarLayer.CalcBoundaries();                 // the aircraft has probably changed size, so update the boundaries
                                HangarLayer.DrawInModifyAircraftState();
                                mounted = true;
                            }
                        }
                        // if the part has not been mounted the part is just dropped and added to the collection
                        if (!mounted)
                        {
                            // first disassemble it though
                            // and flip it if it is flipped
                            var totalParts = part.TotalParts;
                            part.Disassemble();
                            foreach (var singlePart in totalParts)
                            {
                                if (singlePart.Flipped)
                                {
                                    singlePart.Flip();
                                }
                                HangarLayer.AddPart(singlePart);
                            }
                        }
                    }
                    break;
                    }
                    DragAndDropObject = null;
                }
            }
            break;

            default:
                break;
            }
        }