示例#1
0
        private void ReturnToHangar()
        {
            var hangarLayer = new HangarLayer(true);

            foreach (var part in TotalSalvagedParts)
            {
                hangarLayer.AddPart(part);
            }
            TransitionFadingFromTo(this.GUILayer, hangarLayer.GUILayer, this, hangarLayer, 2f);

            // unsubscribe from all events
            MathChallengeNode.UnlockedAddSubSlotEvent -= UnlockSlot;
            MathChallengeNode.UnlockedMulDivSlotEvent -= UnlockSlot;
            MathChallengeNode.UnlockedSolveSlotEvent  -= UnlockSlot;

            /*
             * var parent = Parent;
             * RemoveAllListeners();
             * GUILayer.RemoveAllListeners();
             * Parent.RemoveChild(GUILayer);
             * Parent.RemoveChild(this);
             * parent.AddChild(HangarLayer.GlobalHangarLayer.GUILayer);
             * parent.AddChild(HangarLayer.GlobalHangarLayer, zOrder: int.MinValue);
             */
        }
        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;
            }
        }