public HangarGUILayer(HangarLayer hangarLayer) : base(CCColor4B.Transparent, countTouches: true) { HangarLayer = hangarLayer; Scroller = null; PartCarousel = new NonScalingCarousel(new CCSize(Constants.COCOS_WORLD_WIDTH, Constants.COCOS_WORLD_HEIGHT / 3)); PartCarousel.SpacingFactor = 0.2f; PartCarousel.MiddleChangedEvent += (sender, args) => { foreach (var node in PartCarousel.CollectionNode.Children) { PartCarouselNode pNode = (PartCarouselNode)node; pNode.PartCollectionNode.Pressable = false; } ((PartCarouselNode)PartCarousel.MiddleNode).PartCollectionNode.Pressable = true; }; PartCarousel.IsHorizontal = false; PartCarousel.AnchorPoint = CCPoint.AnchorUpperLeft; PartCarousel.Position = new CCPoint(0, Constants.COCOS_WORLD_HEIGHT); foreach (Part.Type type in Enum.GetValues(typeof(Part.Type))) { PartCarousel.AddToCollection(new PartCarouselNode(type)); } PartCarousel.Visible = false; AddChild(PartCarousel); // add a touch listener var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesBegan = base.OnTouchesBegan; touchListener.OnTouchesMoved = OnTouchesMoved; touchListener.OnTouchesEnded = OnTouchesEnded; touchListener.OnTouchesCancelled = OnTouchesEnded; AddEventListener(touchListener, this); }
protected override void AddedToScene() { base.AddedToScene(); // DEBUG: test out the PopUp //PopUp.ShowPopUp(this, "This is a test."); var bounds = VisibleBoundsWorldspace; // move the part carousel away as the hangar does not start there PartCarousel.PositionY += PartCarousel.ContentSize.Height * 1.5f; HangarOptionHangar = new HangarOptionHangar(); HangarOptionWorkshop = new HangarOptionWorkshop(); HangarOptionScrapyard = new HangarOptionScrapyard(); HangarOptionCarousel = new Carousel(new CCSize(bounds.Size.Width, HangarOptionHangar.BoundingBoxTransformedToWorld.Size.Height)); HangarOptionCarousel.NodeAnchor = CCPoint.AnchorMiddleTop; AddChild(HangarOptionCarousel); HangarOptionCarousel.AnchorPoint = CCPoint.AnchorUpperLeft; HangarOptionCarousel.Position = new CCPoint(0, bounds.MaxY); HangarOptionCarousel.AddToCollection(HangarOptionHangar); HangarOptionCarousel.AddToCollection(HangarOptionWorkshop); HangarOptionCarousel.AddToCollection(HangarOptionScrapyard); TakeoffCollectionNode = new ScrollableCollectionNode(new CCSize(bounds.Size.Width, bounds.Size.Height / 7)); float borderToCollection = 15f; TakeoffNode.Position = CCPoint.Zero; TakeoffNode.AnchorPoint = CCPoint.AnchorLowerLeft; TakeoffNode.AddChild(TakeoffCollectionNode); TakeoffCollectionNode.PositionY = borderToCollection; TakeoffCollectionNode.Columns = HangarLayer.UnlockedPlaneSlots; // start off with only one plane slot unlocked TakeoffCollectionNode.Rows = 1; TakeoffCollectionNode.BoxSize = new CCSize(TakeoffCollectionNode.ContentSize.Height, TakeoffCollectionNode.ContentSize.Height); AddChild(TakeoffNode, zOrder: 1); TakeoffNode.ContentSize = new CCSize(TakeoffCollectionNode.ContentSize.Width, TakeoffCollectionNode.ContentSize.Height + 2 * borderToCollection); var drawNode = new CCDrawNode(); TakeoffNode.AddChild(drawNode, zOrder: -1); drawNode.DrawRect(TakeoffNode.BoundingBoxTransformedToWorld, CCColor4B.Black); drawNode.DrawLine(new CCPoint(0, TakeoffNode.BoundingBoxTransformedToWorld.UpperRight.Y), TakeoffNode.BoundingBoxTransformedToWorld.UpperRight, 8f, CCColor4B.White); drawNode.DrawLine(CCPoint.Zero, new CCPoint(TakeoffNode.BoundingBoxTransformedToWorld.MaxX, 0), 8f, CCColor4B.White); TakeoffNode.ContentSize = new CCSize(TakeoffNode.ContentSize.Width, TakeoffNode.ContentSize.Height + 2 * 4f); TakeoffNode.PositionY += 8f; TakeoffNode.AddChild(TakeoffCollectionLabel); TakeoffCollectionLabel.VerticalAlignment = CCVerticalTextAlignment.Center; TakeoffCollectionLabel.HorizontalAlignment = CCTextAlignment.Center; TakeoffCollectionLabel.Color = CCColor3B.White; TakeoffCollectionLabel.Scale = 2.5f; if (PopUp.TriggeredPlayLayer) { TakeoffCollectionLabel.Visible = false; } TakeoffCollectionLabel.AnchorPoint = CCPoint.AnchorMiddle; TakeoffCollectionLabel.Position = (CCPoint)TakeoffNode.ContentSize / 2; GOButton = new GOButton(); AddChild(GOButton); // place the go button a bit higher than the rest (in ZOrder) GOButton.Visible = false; GOButton.Position = GOButtonOutPosition; // let the hangar listen to the TakeoffCollectionNode TakeoffCollectionNode.CollectionRemovalEvent += HangarLayer.ReceiveAircraftFromCollection; // let the hangar listen to the Carousel for a change of the middle node HangarOptionCarousel.MiddleChangedEvent += HangarLayer.MiddleNodeChanged; // listen to the part carousel for a change of the middle node PartCarousel.MiddleChangedEvent += (sender, args) => { if (HangarLayer.State == HangarLayer.HangarState.MODIFY_AIRCRAFT) { HangarLayer.DrawInModifyAircraftState(); } }; // also listen to each part carousel node's collectionNode foreach (var node in PartCarousel.CollectionNode.Children) { PartCarouselNode pNode = (PartCarouselNode)node; pNode.PartCollectionNode.CollectionRemovalEvent += HangarLayer.ReceivePartFromCollection; } }