Exemplo n.º 1
0
        protected virtual BlockCCControlData ParsePropTypeBlockCcControl(CCNode node, CCNode parent, CCBReader reader)
        {
            string selectorName = reader.ReadCachedString();
            var selectorTarget = (CCBTargetType) reader.ReadInt(false);
            var controlEvents = (CCControlEvent) reader.ReadInt(false);

            if (selectorTarget != CCBTargetType.None)
            {
                if (!reader.IsJSControlled())
                {
                    object target = null;
                    if (selectorTarget == CCBTargetType.DocumentRoot)
                    {
                        target = reader.AnimationManager.RootNode;
                    }
                    else if (selectorTarget == CCBTargetType.Owner)
                    {
                        target = reader.Owner;
                    }

                    if (target != null)
                    {
                        if (selectorName.Length > 0)
                        {
                            Action<object, CCControlEvent> selCCControlHandler = null;

                            var targetAsCCBSelectorResolver = target as ICCBSelectorResolver;
                            if (targetAsCCBSelectorResolver != null)
                            {
                                selCCControlHandler = targetAsCCBSelectorResolver.OnResolveCCBCCControlSelector(target,
                                                                                                                selectorName);
                            }
                            if (selCCControlHandler == null)
                            {
                                ICCBSelectorResolver 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.");
                    }
                }
                else
                {
                    if (selectorTarget == CCBTargetType.DocumentRoot)
                    {
                        reader.AddDocumentCallbackNode(node);
                        reader.AddDocumentCallbackName(selectorName);

                    }
                    else
                    {
                        reader.AddOwnerCallbackNode(node);
                        reader.AddOwnerCallbackName(selectorName);
                    }
                }
            }

            return null;
        }
Exemplo n.º 2
0
        protected virtual CCNode ParsePropTypeCcbFile(CCNode node, CCNode parent, CCBReader pCCBReader)
        {
            string ccbFileName = pCCBReader.ReadCachedString();

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

            // Load sub file
            string path = CCFileUtils.FullPathFromRelativePath(ccbFileName);
            //long size = 0;
            byte[] pBytes = CCFileUtils.GetFileBytes(path);
            var reader = new CCBReader(pCCBReader);

            reader.AnimationManager.RootContainerSize = parent.ContentSize;

            reader._bytes = pBytes;
            reader._currentByte = 0;
            reader._currentBit = 0;
            reader._owner = pCCBReader._owner;

            reader.AnimationManager._owner = reader._owner;

            CCNode ccbFileNode = reader.ReadFileWithCleanUp(false, pCCBReader.AnimationManagers);

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

            if (reader.IsJSControlled() && pCCBReader.IsJSControlled() && null != reader._owner)
            {
                //set variables and callback to owner
                //set callback
                var ownerCallbackNames = reader.OwnerCallbackNames;
                var ownerCallbackNodes = reader.OwnerCallbackNodes;
                if (null != ownerCallbackNames && ownerCallbackNames.Count > 0 &&
                    null != ownerCallbackNodes && ownerCallbackNodes.Count > 0)
                {
                    Debug.Assert(ownerCallbackNames.Count == ownerCallbackNodes.Count);
                    int nCount = ownerCallbackNames.Count;
                    for (int i = 0; i < nCount; i++)
                    {
                        pCCBReader.AddOwnerCallbackName(ownerCallbackNames[i]);
                        pCCBReader.AddOwnerCallbackNode(ownerCallbackNodes[i]);
                    }
                }
                //set variables
                var ownerOutletNames = reader.OwnerOutletNames;
                var ownerOutletNodes = reader.OwnerOutletNodes;
                if (null != ownerOutletNames && ownerOutletNames.Count > 0 &&
                    null != ownerOutletNodes && ownerOutletNodes.Count > 0)
                {
                    Debug.Assert(ownerOutletNames.Count == ownerOutletNodes.Count);
                    int nCount = ownerOutletNames.Count;
                    for (int i = 0; i < nCount; i++)
                    {
                        pCCBReader.AddOwnerOutletName(ownerOutletNames[i]);
                        pCCBReader.AddOwnerOutletNode(ownerOutletNodes[i]);
                    }
                }
            }

            return ccbFileNode;
        }
Exemplo n.º 3
0
        protected virtual BlockData ParsePropTypeBlock(CCNode node, CCNode parent, CCBReader reader)
        {
            string selectorName = reader.ReadCachedString();
            var selectorTarget = (CCBTargetType) reader.ReadInt(false);

            if (selectorTarget != CCBTargetType.None)
            {
                object target = null;
                if (!reader.IsJSControlled())
                {
                    if (selectorTarget == CCBTargetType.DocumentRoot)
                    {
                        target = reader.AnimationManager.RootNode;
                    }
                    else if (selectorTarget == CCBTargetType.Owner)
                    {
                        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 = (ICCBScriptOwnerProtocol) reader.Owner;
                            if (proxy != null)
                            {
                                target = proxy.CreateNew() as object;
                            }
                        }
                    }

                    if (target != null)
                    {
                        if (selectorName.Length > 0)
                        {
                            Action<object> selMenuHandler = null;

                            var targetAsCCBSelectorResolver = target as ICCBSelectorResolver;

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

                            if (selMenuHandler == null)
                            {
                                CCLog.Log("Skipping selector '{0}' 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.");
                    }
                }
                else
                {
                    if (selectorTarget == CCBTargetType.DocumentRoot)
                    {
                        reader.AddDocumentCallbackNode(node);
                        reader.AddDocumentCallbackName(selectorName);

                    }
                    else
                    {
                        reader.AddOwnerCallbackNode(node);
                        reader.AddOwnerCallbackName(selectorName);
                    }
                }
            }

            return null;
        }