Example #1
0
 protected virtual string ParsePropTypeFntFile(CCNode node, CCNode parent, CCBReader reader)
 {
     return reader.ReadCachedString();
 }
Example #2
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;
        }
Example #3
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;
        }
Example #4
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;
        }
Example #5
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;
        }
Example #6
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;
        }
Example #7
0
        public virtual void ParseProperties(CCNode node, CCNode parent, CCBReader reader)
        {
            int numRegularProps = reader.ReadInt(false);
            int numExturaProps = reader.ReadInt(false);
            int propertyCount = numRegularProps + numExturaProps;

            for (int i = 0; i < propertyCount; i++)
            {
                bool isExtraProp = (i >= numRegularProps);
                int type = reader.ReadInt(false);
                string propertyName = reader.ReadCachedString();

                // Check if the property can be set for this platform
                bool setProp = false;

                var platform = (kCCBPlatform) reader.ReadByte();
                if (platform == kCCBPlatform.kCCBPlatformAll)
                {
                    setProp = true;
                }
            #if __CC_PLATFORM_IOS
            if(platform == kCCBPlatform.kCCBPlatformIOS)
            {
            setProp = true;
            }
            #elif __CC_PLATFORM_MAC
            if(platform == kCCBPlatform.kCCBPlatformMac)
            {
            setProp = true;
            }
            #endif

                // Forward properties for sub ccb files
                if (node is CCBFile)
                {
                    var ccbNode = (CCBFile) node;
                    if (ccbNode.FileNode != null && isExtraProp)
                    {
                        node = ccbNode.FileNode;

                        // Skip properties that doesn't have a value to override
                        var extraPropsNames = (List<string>) node.UserObject;
                        setProp &= extraPropsNames.Contains(propertyName);
                    }
                }
                else if (isExtraProp && node == reader.AnimationManager.RootNode)
                {
                    var extraPropsNames = (List<string>) node.UserObject;
                    if (extraPropsNames == null)
                    {
                        extraPropsNames = new List<string>();
                        node.UserObject = extraPropsNames;
                    }

                    extraPropsNames.Add(propertyName);
                }

                switch ((kCCBPropType) type)
                {
                    case kCCBPropType.kCCBPropTypePosition:
                        {
                            CCPoint position = ParsePropTypePosition(node, parent, reader, propertyName);
                            if (setProp)
                            {
                                OnHandlePropTypePosition(node, parent, propertyName, position, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypePoint:
                        {
                            CCPoint point = ParsePropTypePoint(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypePoint(node, parent, propertyName, point, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypePointLock:
                        {
                            CCPoint pointLock = ParsePropTypePointLock(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypePointLock(node, parent, propertyName, pointLock, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeSize:
                        {
                            CCSize size = ParsePropTypeSize(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeSize(node, parent, propertyName, size, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeScaleLock:
                        {
                            float[] scaleLock = ParsePropTypeScaleLock(node, parent, reader, propertyName);
                            if (setProp)
                            {
                                OnHandlePropTypeScaleLock(node, parent, propertyName, scaleLock, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeFloat:
                        {
                            float f = ParsePropTypeFloat(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeFloat(node, parent, propertyName, f, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeDegrees:
                        {
                            float degrees = ParsePropTypeDegrees(node, parent, reader, propertyName);
                            if (setProp)
                            {
                                OnHandlePropTypeDegrees(node, parent, propertyName, degrees, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeFloatScale:
                        {
                            float floatScale = ParsePropTypeFloatScale(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeFloatScale(node, parent, propertyName, floatScale, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeInteger:
                        {
                            int integer = ParsePropTypeInteger(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeInteger(node, parent, propertyName, integer, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeIntegerLabeled:
                        {
                            int integerLabeled = ParsePropTypeIntegerLabeled(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeIntegerLabeled(node, parent, propertyName, integerLabeled, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeFloatVar:
                        {
                            float[] floatVar = ParsePropTypeFloatVar(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeFloatVar(node, parent, propertyName, floatVar, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeCheck:
                        {
                            bool check = ParsePropTypeCheck(node, parent, reader, propertyName);
                            if (setProp)
                            {
                                OnHandlePropTypeCheck(node, parent, propertyName, check, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeSpriteFrame:
                        {
                            CCSpriteFrame ccSpriteFrame = ParsePropTypeSpriteFrame(node, parent, reader, propertyName);
                            if (setProp)
                            {
                                OnHandlePropTypeSpriteFrame(node, parent, propertyName, ccSpriteFrame, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeAnimation:
                        {
                            CCAnimation ccAnimation = ParsePropTypeAnimation(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeAnimation(node, parent, propertyName, ccAnimation, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeTexture:
                        {
                            CCTexture2D ccTexture2D = ParsePropTypeTexture(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeTexture(node, parent, propertyName, ccTexture2D, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeByte:
                        {
                            byte b = ParsePropTypeByte(node, parent, reader, propertyName);
                            if (setProp)
                            {
                                OnHandlePropTypeByte(node, parent, propertyName, b, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeColor3:
                        {
                            CCColor3B color3B = ParsePropTypeColor3(node, parent, reader, propertyName);
                            if (setProp)
                            {
                                OnHandlePropTypeColor3(node, parent, propertyName, color3B, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeColor4FVar:
                        {
                            CCColor4F[] color4FVar = ParsePropTypeColor4FVar(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeColor4FVar(node, parent, propertyName, color4FVar, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeFlip:
                        {
                            bool[] flip = ParsePropTypeFlip(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeFlip(node, parent, propertyName, flip, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeBlendmode:
                        {
                            CCBlendFunc blendFunc = ParsePropTypeBlendFunc(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeBlendFunc(node, parent, propertyName, blendFunc, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeFntFile:
                        {
                            string fntFile = ParsePropTypeFntFile(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeFntFile(node, parent, propertyName, fntFile, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeFontTTF:
                        {
                            string fontTTF = ParsePropTypeFontTTF(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeFontTTF(node, parent, propertyName, fontTTF, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeString:
                        {
                            string s = ParsePropTypeString(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeString(node, parent, propertyName, s, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeText:
                        {
                            string text = ParsePropTypeText(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeText(node, parent, propertyName, text, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeBlock:
                        {
                            BlockData blockData = ParsePropTypeBlock(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeBlock(node, parent, propertyName, blockData, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeBlockCCControl:
                        {
                            BlockCCControlData blockCCControlData = ParsePropTypeBlockCcControl(node, parent, reader);
                            if (setProp && blockCCControlData != null)
                            {
                                OnHandlePropTypeBlockCcControl(node, parent, propertyName, blockCCControlData, reader);
                            }
                            break;
                        }
                    case kCCBPropType.kCCBPropTypeCCBFile:
                        {
                            CCNode ccbFileNode = ParsePropTypeCcbFile(node, parent, reader);
                            if (setProp)
                            {
                                OnHandlePropTypeCCBFile(node, parent, propertyName, ccbFileNode, reader);
                            }
                            break;
                        }
                    default:
                        //ASSERT_FAIL_UNEXPECTED_PROPERTYTYPE(type);
                        break;
                }
            }
        }
Example #8
0
        protected virtual CCTexture2D ParsePropTypeTexture(CCNode node, CCNode parent, CCBReader reader)
        {
            string spriteFile = reader.ReadCachedString();

            if (!String.IsNullOrEmpty(spriteFile))
            {
                return CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile));
            }
            return null;
        }
Example #9
0
        protected virtual CCSpriteFrame ParsePropTypeSpriteFrame(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            string spriteSheet = reader.ReadCachedString();
            string spriteFile = reader.ReadCachedString();

            CCSpriteFrame spriteFrame = null;
            if (spriteFile.Length != 0)
            {
                if (spriteSheet.Length == 0)
                {
                    CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile));
                    var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height);
                    spriteFrame = CCSpriteFrame.Create(texture, bounds);
                }
                else
                {
                    CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

                    // Load the sprite sheet only if it is not loaded
                    if (!reader.LoadedSpriteSheet.Contains(spriteSheet))
                    {
                        frameCache.AddSpriteFramesWithFile(spriteSheet);
                        reader.LoadedSpriteSheet.Add(spriteSheet);
                    }

                    spriteFrame = frameCache.SpriteFrameByName(spriteFile);
                }

                if (reader.AnimatedProperties.Contains(propertyName))
                {
                    reader.AnimationManager.SetBaseValue(spriteFrame, node, propertyName);
                }
            }

            return spriteFrame;
        }