Пример #1
0
        public void onAnimationsTestClicked(object pSender, CCControlEvent pCCControlEvent)
        {
            // Load node graph (TestAnimations is a sub class of CCLayer) and retrieve the ccb action manager
            CCBAnimationManager actionManager = null;

            /* Create an autorelease CCNodeLoaderLibrary. */
            CCNodeLoaderLibrary ccNodeLoaderLibrary = CCNodeLoaderLibrary.NewDefaultCCNodeLoaderLibrary();

            ccNodeLoaderLibrary.RegisterCCNodeLoader("TestHeaderLayer", new Loader<TestHeaderLayer>());
            ccNodeLoaderLibrary.RegisterCCNodeLoader("TestAnimationsLayer", new Loader<AnimationsTestLayer>());

            /* Create an autorelease CCBReader. */
            var ccbReader = new CCBReader(ccNodeLoaderLibrary);

            /* Read a ccbi file. */
            // Load the scene from the ccbi-file, setting this class as
            // the owner will cause lblTestTitle to be set by the CCBReader.
            // lblTestTitle is in the TestHeader.ccbi, which is referenced
            // from each of the test scenes.
            CCNode animationsTest = ccbReader.ReadNodeGraphFromFile("ccb/ccb/TestAnimations.ccbi", this, ref actionManager);
            ((AnimationsTestLayer) animationsTest).setAnimationManager(actionManager);

            mTestTitleLabelTTF.Label = ("TestAnimations.ccbi");

            CCScene scene = new CCScene();
            scene.AddChild(animationsTest);

            /* Push the new scene with a fancy transition. */
            CCColor3B transitionColor;
            transitionColor.R = 0;
            transitionColor.G = 0;
            transitionColor.B = 0;

            CCDirector.SharedDirector.PushScene(new CCTransitionFade(0.5f, scene, transitionColor));
        }
Пример #2
0
        public override void runThisTest()
        {
            /* Create an autorelease CCNodeLoaderLibrary. */
            CCNodeLoaderLibrary ccNodeLoaderLibrary = CCNodeLoaderLibrary.NewDefaultCCNodeLoaderLibrary();

            ccNodeLoaderLibrary.RegisterCCNodeLoader("HelloCocosBuilderLayer", new Loader<HelloCocosBuilderLayer>());

            /* Create an autorelease CCBReader. */
            var ccbReader = new CCBReader(ccNodeLoaderLibrary);

            /* Read a ccbi file. */
            CCNode node = ccbReader.ReadNodeGraphFromFile("ccb/HelloCocosBuilder.ccbi", this);

            foreach (CCNode c in node.Children)
            {
                CCLog.Log("Node is at {0},{1}", c.PositionX, c.PositionY);
            }

            if (node != null)
            {
                AddChild(node);
            }

            CCDirector.SharedDirector.ReplaceScene(this);
        }
Пример #3
0
 protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame,
                                                     CCBReader reader)
 {
     if (propertyName == PROPERTY_NORMALDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetNormalSpriteFrame(spriteFrame);
         }
     }
     else if (propertyName == PROPERTY_SELECTEDDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetSelectedSpriteFrame(spriteFrame);
         }
     }
     else if (propertyName == PROPERTY_DISABLEDDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetDisabledSpriteFrame(spriteFrame);
         }
     }
     else
     {
         base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader);
     }
 }
Пример #4
0
 protected override void OnHandlePropTypeFloat(CCNode node, CCNode parent, string propertyName, float pFloat, CCBReader reader)
 {
     if (propertyName == PROPERTY_SCALE)
     {
         node.Scale = pFloat;
     }
     else
     {
         base.OnHandlePropTypeFloat(node, parent, propertyName, pFloat, reader);
     }
 }
Пример #5
0
 protected override void OnHandlePropTypeSize(CCNode node, CCNode parent, string propertyName, CCSize pSize, CCBReader reader)
 {
     if (propertyName == PROPERTY_CONTENTSIZE)
     {
         ((CCScrollView) node).ViewSize = pSize;
     }
     else
     {
         base.OnHandlePropTypeSize(node, parent, propertyName, pSize, reader);
     }
 }
Пример #6
0
 protected override void OnHandlePropTypeCheck(CCNode node, CCNode parent, string propertyName, bool pCheck, CCBReader reader)
 {
     if (propertyName == PROPERTY_ISENABLED)
     {
         ((CCMenuItem) node).Enabled = pCheck;
     }
     else
     {
         base.OnHandlePropTypeCheck(node, parent, propertyName, pCheck, reader);
     }
 }
Пример #7
0
 protected override void OnHandlePropTypeCCBFile(CCNode node, CCNode parent, string propertyName, CCNode fileNode, CCBReader reader)
 {
     if (propertyName == PROPERTY_CONTAINER)
     {
         ((CCScrollView) node).Container = fileNode;
         ((CCScrollView) node).UpdateInset();
     }
     else
     {
         base.OnHandlePropTypeCCBFile(node, parent, propertyName, fileNode, reader);
     }
 }
Пример #8
0
 protected override void OnHandlePropTypeIntegerLabeled(CCNode node, CCNode parent, string propertyName, int pIntegerLabeled,
                                                        CCBReader reader)
 {
     if (propertyName == PROPERTY_DIRECTION)
     {
         ((CCScrollView) node).Direction = (CCScrollViewDirection) pIntegerLabeled;
     }
     else
     {
         base.OnHandlePropTypeFloatScale(node, parent, propertyName, pIntegerLabeled, reader);
     }
 }
Пример #9
0
 protected override void OnHandlePropTypeBlock(CCNode node, CCNode parent, string propertyName, BlockData pBlockData, CCBReader reader)
 {
     if (propertyName == PROPERTY_BLOCK)
     {
         if (null != pBlockData) // Add this condition to allow CCMenuItemImage without target/selector predefined
         {
             ((CCMenuItem) node).SetTarget(pBlockData.mSELMenuHandler);
         }
     }
     else
     {
         base.OnHandlePropTypeBlock(node, parent, propertyName, pBlockData, reader);
     }
 }
Пример #10
0
 protected override void OnHandlePropTypeCheck(CCNode node, CCNode parent, string propertyName, bool pCheck, CCBReader reader)
 {
     if (propertyName == PROPERTY_CLIPSTOBOUNDS)
     {
         ((CCScrollView) node).ClippingToBounds = pCheck;
     }
     else if (propertyName == PROPERTY_BOUNCES)
     {
         ((CCScrollView) node).Bounceable = pCheck;
     }
     else
     {
         base.OnHandlePropTypeCheck(node, parent, propertyName, pCheck, reader);
     }
 }
Пример #11
0
        protected virtual float[] ParsePropTypeScaleLock(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            float x = reader.ReadFloat();
            float y = reader.ReadFloat();

            var type = (kCCBScaleType) reader.ReadInt(false);

            CCBHelper.SetRelativeScale(node, x, y, type, propertyName);

            if (reader.AnimatedProperties.Contains(propertyName))
            {
                var baseValue = new List<CCBValue>
                    {
                        CCBValue.Create(x),
                        CCBValue.Create(y),
                        CCBValue.Create((int) type)
                    };
                reader.AnimationManager.SetBaseValue(baseValue, node, propertyName);
            }

            if (type == kCCBScaleType.kCCBScaleTypeMultiplyResolution)
            {
                x *= CCBReader.ResolutionScale;
                y *= CCBReader.ResolutionScale;
            }

            var scaleLock = new float[2];
            scaleLock[0] = x;
            scaleLock[1] = y;

            return scaleLock;
        }
Пример #12
0
        protected virtual CCPoint ParsePropTypePosition(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            float x = reader.ReadFloat();
            float y = reader.ReadFloat();

            var type = (kCCBPositionType) reader.ReadInt(false);

            CCSize containerSize = reader.AnimationManager.GetContainerSize(parent);

            CCPoint pt = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, containerSize, propertyName);
            node.Position = CCBHelper.GetAbsolutePosition(pt, type, containerSize, propertyName);

            if (reader.AnimatedProperties.Contains(propertyName))
            {
                var baseValue = new List<CCBValue>
                    {
                        CCBValue.Create(x),
                        CCBValue.Create(y),
                        CCBValue.Create((int) type)
                    };
                reader.AnimationManager.SetBaseValue(baseValue, node, propertyName);
            }

            return pt;
        }
Пример #13
0
        protected virtual CCPoint ParsePropTypePointLock(CCNode node, CCNode parent, CCBReader reader)
        {
            float x = reader.ReadFloat();
            float y = reader.ReadFloat();

            return new CCPoint(x, y);
        }
Пример #14
0
 protected virtual int ParsePropTypeIntegerLabeled(CCNode node, CCNode parent, CCBReader reader)
 {
     return reader.ReadInt(true);
 }
Пример #15
0
        protected virtual bool ParsePropTypeCheck(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            bool ret = reader.ReadBool();

            if (reader.AnimatedProperties.Contains(propertyName))
            {
                CCBValue value = CCBValue.Create(ret);
                reader.AnimationManager.SetBaseValue(value, node, propertyName);
            }

            return ret;
        }
Пример #16
0
        protected virtual CCAnimation ParsePropTypeAnimation(CCNode node, CCNode parent, CCBReader reader)
        {
            string animationFile = reader.ReadCachedString();
            string animation = reader.ReadCachedString();

            CCAnimation ccAnimation = null;

            // Support for stripping relative file paths, since ios doesn't currently
            // know what to do with them, since its pulling from bundle.
            // Eventually this should be handled by a client side asset manager
            // interface which figured out what resources to load.
            // TODO Does this problem exist in C++?
            animation = CCBReader.LastPathComponent(animation);
            animationFile = CCBReader.LastPathComponent(animationFile);

            if (!String.IsNullOrEmpty(animation))
            {
                CCAnimationCache animationCache = CCAnimationCache.SharedAnimationCache;
                animationCache.AddAnimationsWithFile(animationFile);

                ccAnimation = animationCache.AnimationByName(animation);
            }
            return ccAnimation;
        }
Пример #17
0
        protected virtual BlockData ParsePropTypeBlock(CCNode node, CCNode parent, CCBReader reader)
        {
            string selectorName = reader.ReadCachedString();
            var selectorTarget = (kCCBTargetType) reader.ReadInt(false);

            if (selectorTarget != kCCBTargetType.kCCBTargetTypeNone)
            {
                object target = null;
                if (selectorTarget == kCCBTargetType.kCCBTargetTypeDocumentRoot)
                {
                    target = reader.AnimationManager.RootNode;
                }
                else if (selectorTarget == kCCBTargetType.kCCBTargetTypeOwner)
                {
                    target = reader.Owner;

                    /* Scripting specific code because selector function is common for all callbacks.
                     * So if we had 1 target and 1 selector function, the context (callback function name)
                     * would get lost. Hence the need for a new target for each callback.
                     */
                    if (reader.hasScriptingOwner)
                    {
                        var proxy = (CCBScriptOwnerProtocol) reader.Owner;
                        if (proxy != null)
                        {
                            target = proxy.CreateNew() as object;
                        }
                    }
                }

                if (target != null)
                {
                    if (selectorName.Length > 0)
                    {
                        SEL_MenuHandler selMenuHandler = null;

                        var targetAsCCBSelectorResolver = target as CCBSelectorResolver;

                        if (targetAsCCBSelectorResolver != null)
                        {
                            selMenuHandler = targetAsCCBSelectorResolver.OnResolveCCBCCMenuItemSelector(target, selectorName);
                        }
                        if (selMenuHandler == null)
                        {
                            CCBSelectorResolver ccbSelectorResolver = reader.SelectorResolver;
                            if (ccbSelectorResolver != null)
                            {
                                selMenuHandler = ccbSelectorResolver.OnResolveCCBCCMenuItemSelector(target, selectorName);
                            }
                        }

                        if (selMenuHandler == null)
                        {
                            CCLog.Log("Skipping selector '%s' since no CCBSelectorResolver is present.", selectorName);
                        }
                        else
                        {
                            var blockData = new BlockData();
                            blockData.mSELMenuHandler = selMenuHandler;

                            blockData.mTarget = target;

                            return blockData;
                        }
                    }
                    else
                    {
                        CCLog.Log("Unexpected empty selector.");
                    }
                }
                else
                {
                    CCLog.Log("Unexpected NULL target for selector.");
                }
            }

            return null;
        }
Пример #18
0
        protected virtual float ParsePropTypeFloatScale(CCNode node, CCNode parent, CCBReader reader)
        {
            float f = reader.ReadFloat();

            int type = reader.ReadInt(false);

            if ((kCCBScaleType) type == kCCBScaleType.kCCBScaleTypeMultiplyResolution)
            {
                f *= CCBReader.ResolutionScale;
            }

            return f;
        }
Пример #19
0
        protected virtual byte ParsePropTypeByte(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            byte ret = reader.ReadByte();

            if (reader.AnimatedProperties.Contains(propertyName))
            {
                reader.AnimationManager.SetBaseValue(CCBValue.Create(ret), node, propertyName);
            }

            return ret;
        }
Пример #20
0
        protected virtual bool[] ParsePropTypeFlip(CCNode node, CCNode parent, CCBReader reader)
        {
            bool flipX = reader.ReadBool();
            bool flipY = reader.ReadBool();

            var arr = new bool[2];
            arr[0] = flipX;
            arr[1] = flipY;

            return arr;
        }
Пример #21
0
        protected virtual float ParsePropTypeDegrees(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            float ret = reader.ReadFloat();
            if (reader.AnimatedProperties.Contains(propertyName))
            {
                CCBValue value = CCBValue.Create(ret);
                reader.AnimationManager.SetBaseValue(value, node, propertyName);
            }

            return ret;
        }
Пример #22
0
        protected virtual CCColor4F[] ParsePropTypeColor4FVar(CCNode node, CCNode parent, CCBReader reader)
        {
            float red = reader.ReadFloat();
            float green = reader.ReadFloat();
            float blue = reader.ReadFloat();
            float alpha = reader.ReadFloat();
            float redVar = reader.ReadFloat();
            float greenVar = reader.ReadFloat();
            float blueVar = reader.ReadFloat();
            float alphaVar = reader.ReadFloat();

            var colors = new CCColor4F[2];
            colors[0].R = red;
            colors[0].G = green;
            colors[0].B = blue;
            colors[0].A = alpha;

            colors[1].R = redVar;
            colors[1].G = greenVar;
            colors[1].B = blueVar;
            colors[1].A = alphaVar;

            return colors;
        }
Пример #23
0
        protected virtual CCColor3B ParsePropTypeColor3(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            byte red = reader.ReadByte();
            byte green = reader.ReadByte();
            byte blue = reader.ReadByte();

            var color = new CCColor3B(red, green, blue);
            if (reader.AnimatedProperties.Contains(propertyName))
            {
                ccColor3BWapper value = ccColor3BWapper.Create(color);
                reader.AnimationManager.SetBaseValue(value, node, propertyName);
            }
            return color;
        }
Пример #24
0
        protected virtual BlockCCControlData ParsePropTypeBlockCcControl(CCNode node, CCNode parent, CCBReader reader)
        {
            string selectorName = reader.ReadCachedString();
            var selectorTarget = (kCCBTargetType) reader.ReadInt(false);
            var controlEvents = (CCControlEvent) reader.ReadInt(false);

            if (selectorTarget != kCCBTargetType.kCCBTargetTypeNone)
            {
                object target = null;
                if (selectorTarget == kCCBTargetType.kCCBTargetTypeDocumentRoot)
                {
                    target = reader.AnimationManager.RootNode;
                }
                else if (selectorTarget == kCCBTargetType.kCCBTargetTypeOwner)
                {
                    target = reader.Owner;
                }

                if (target != null)
                {
                    if (selectorName.Length > 0)
                    {
                        SEL_CCControlHandler selCCControlHandler = null;

                        var targetAsCCBSelectorResolver = target as CCBSelectorResolver;
                        if (targetAsCCBSelectorResolver != null)
                        {
                            selCCControlHandler = targetAsCCBSelectorResolver.OnResolveCCBCCControlSelector(target, selectorName);
                        }
                        if (selCCControlHandler == null)
                        {
                            CCBSelectorResolver ccbSelectorResolver = reader.SelectorResolver;
                            if (ccbSelectorResolver != null)
                            {
                                selCCControlHandler = ccbSelectorResolver.OnResolveCCBCCControlSelector(target, selectorName);
                            }
                        }

                        if (selCCControlHandler == null)
                        {
                            CCLog.Log("Skipping selector '{0}' since no CCBSelectorResolver is present.", selectorName);
                        }
                        else
                        {
                            var blockCCControlData = new BlockCCControlData();
                            blockCCControlData.mSELCCControlHandler = selCCControlHandler;

                            blockCCControlData.mTarget = target;
                            blockCCControlData.mControlEvents = controlEvents;

                            return blockCCControlData;
                        }
                    }
                    else
                    {
                        CCLog.Log("Unexpected empty selector.");
                    }
                }
                else
                {
                    CCLog.Log("Unexpected NULL target for selector.");
                }
            }

            return null;
        }
Пример #25
0
        protected virtual float[] ParsePropTypeFloatVar(CCNode node, CCNode parent, CCBReader reader)
        {
            float f = reader.ReadFloat();
            float fVar = reader.ReadFloat();

            var arr = new float[2];
            arr[0] = f;
            arr[1] = fVar;

            return arr;
        }
Пример #26
0
 protected virtual string ParsePropTypeFntFile(CCNode node, CCNode parent, CCBReader reader)
 {
     return reader.ReadCachedString();
 }
Пример #27
0
        protected virtual CCBlendFunc ParsePropTypeBlendFunc(CCNode node, CCNode parent, CCBReader reader)
        {
            int source = reader.ReadInt(false);
            int destination = reader.ReadInt(false);

            CCBlendFunc blendFunc;
            blendFunc.Source = source;
            blendFunc.Destination = destination;

            return blendFunc;
        }
Пример #28
0
        protected virtual string ParsePropTypeFontTTF(CCNode node, CCNode parent, CCBReader reader)
        {
            string fontTTF = reader.ReadCachedString();

            // CCString * ttfEnding = CCString.Create(".ttf");

            // TODO Fix me if it is wrong
            /* If the fontTTF comes with the ".ttf" extension, prepend the absolute path.
             * System fonts come without the ".ttf" extension and do not need the path prepended. */
            /*
            if(CCBReader.endsWith(CCBReader.toLowerCase(fontTTF), ttfEnding)){
                fontTTF = CCBReader.concat(reader.getCCBRootPath(), fontTTF);
            }
             */

            return fontTTF;
        }
Пример #29
0
 protected virtual float ParsePropTypeFloat(CCNode node, CCNode parent, CCBReader reader)
 {
     return reader.ReadFloat();
 }
Пример #30
0
        protected virtual CCNode ParsePropTypeCcbFile(CCNode node, CCNode parent, CCBReader reader)
        {
            string ccbFileName = reader.ReadCachedString();

            /* Change path extension to .ccbi. */
            string ccbFileWithoutPathExtension = CCBReader.DeletePathExtension(ccbFileName);
            ccbFileName = ccbFileWithoutPathExtension + ".ccbi";

            // Load sub file
            string path = CCFileUtils.FullPathFromRelativePath(ccbFileName);
            var ccbReader = new CCBReader(reader);

            byte[] pBytes = CCFileUtils.GetFileBytes(path);
            ccbReader.InitWithData(pBytes, reader.Owner);
            ccbReader.AnimationManager.RootContainerSize = parent.ContentSize;

            CCNode ccbFileNode = ccbReader.ReadFileWithCleanUp(false);

            if (ccbFileNode != null && ccbReader.AnimationManager.AutoPlaySequenceId != -1)
            {
                // Auto play animations
                ccbReader.AnimationManager.RunAnimations(ccbReader.AnimationManager.AutoPlaySequenceId, 0);
            }

            return ccbFileNode;
        }