Exemple #1
0
        public static CCPoint CCPointFromString(string pszContent)
        {
            CCPoint       cCPoint = new CCPoint();
            List <string> strs    = new List <string>();

            if (CCNS.splitWithForm(pszContent, strs))
            {
                float single  = ccUtils.ccParseFloat(strs[0]);
                float single1 = ccUtils.ccParseFloat(strs[1]);
                cCPoint = new CCPoint(single, single1);
            }
            return(cCPoint);
        }
Exemple #2
0
        public static CCRect CCRectFromString(string pszContent)
        {
            CCRect cCRect = new CCRect(0f, 0f, 0f, 0f);

            if (pszContent != null)
            {
                string str  = pszContent;
                int    num  = str.IndexOf('{');
                int    num1 = str.IndexOf('}');
                for (int i = 1; i < 3 && num1 != -1; i++)
                {
                    num1 = str.IndexOf('}', num1 + 1);
                }
                if (num != -1 && num1 != -1)
                {
                    str = str.Substring(num + 1, num1 - num - 1);
                    int num2 = str.IndexOf('}');
                    if (num2 != -1)
                    {
                        num2 = str.IndexOf(',', num2);
                        if (num2 != -1)
                        {
                            string        str1 = str.Substring(0, num2);
                            string        str2 = str.Substring(num2 + 1);
                            List <string> strs = new List <string>();
                            if (CCNS.splitWithForm(str1, strs))
                            {
                                List <string> strs1 = new List <string>();
                                if (CCNS.splitWithForm(str2, strs1))
                                {
                                    float single  = ccUtils.ccParseFloat(strs[0]);
                                    float single1 = ccUtils.ccParseFloat(strs[1]);
                                    float single2 = ccUtils.ccParseFloat(strs1[0]);
                                    float single3 = ccUtils.ccParseFloat(strs1[1]);
                                    cCRect = new CCRect(single, single1, single2, single3);
                                }
                            }
                        }
                    }
                }
            }
            return(cCRect);
        }
Exemple #3
0
        public static bool splitWithForm(string pStr, List <string> strs)
        {
            bool flag = false;

            if (pStr != null)
            {
                string str = pStr;
                if (str.Length != 0)
                {
                    int num  = str.IndexOf('{');
                    int num1 = str.IndexOf('}');
                    if (num != -1 && num1 != -1 && num <= num1)
                    {
                        string str1 = str.Substring(num + 1, num1 - num - 1);
                        if (str1.Length != 0)
                        {
                            int num2 = str1.IndexOf('{');
                            int num3 = str1.IndexOf('}');
                            if (num2 == -1 && num3 == -1)
                            {
                                CCNS.split(str1, ",", strs);
                                if (strs.Count != 2 || strs[0].Length == 0 || strs[1].Length == 0)
                                {
                                    strs.Clear();
                                }
                                else
                                {
                                    flag = true;
                                }
                            }
                        }
                    }
                }
            }
            return(flag);
        }
        /// <summary>
        /// Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
        /// </summary>
        public void addSpriteFramesWithDictionary(Dictionary <string, Object> pobDictionary, CCTexture2D pobTexture)
        {
            /*
             * Supported Zwoptex Formats:
             *
             * ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
             * ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
             * ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
             * ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
             */
            Dictionary <string, Object> metadataDict = null;

            if (pobDictionary.Keys.Contains("metadata"))
            {
                metadataDict = (Dictionary <string, Object>)pobDictionary["metadata"];
            }

            Dictionary <string, Object> framesDict = null;

            if (pobDictionary.Keys.Contains("frames"))
            {
                framesDict = (Dictionary <string, Object>)pobDictionary["frames"];
            }

            int format = 0;

            // get the format
            if (metadataDict != null)
            {
                format = ccUtils.ccParseInt(metadataDict["format"].ToString());
            }

            // check the format
            Debug.Assert(format >= 0 && format <= 3);

            foreach (var key in framesDict.Keys)
            {
                Dictionary <string, Object> frameDict = framesDict[key] as Dictionary <string, Object>;
                CCSpriteFrame spriteFrame             = new CCSpriteFrame();

                if (format == 0)
                {
                    float x  = ccUtils.ccParseFloat(frameDict["x"].ToString());
                    float y  = ccUtils.ccParseFloat(frameDict["y"].ToString());
                    float w  = ccUtils.ccParseFloat(frameDict["width"].ToString());
                    float h  = ccUtils.ccParseFloat(frameDict["height"].ToString());
                    float ox = ccUtils.ccParseFloat(frameDict["offsetX"].ToString());
                    float oy = ccUtils.ccParseFloat(frameDict["offsetY"].ToString());
                    int   ow = ccUtils.ccParseInt(frameDict["originalWidth"].ToString());
                    int   oh = ccUtils.ccParseInt(frameDict["originalHeight"].ToString());
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        CCLog.Log("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
                    }
                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);
                    // create frame
                    spriteFrame = new CCSpriteFrame();
                    spriteFrame.initWithTexture(pobTexture,
                                                new CCRect(x, y, w, h),
                                                false,
                                                new CCPoint(ox, oy),
                                                new CCSize((float)ow, (float)oh)
                                                );
                }
                else if (format == 1 || format == 2)
                {
                    CCRect frame   = CCNS.CCRectFromString(frameDict["frame"].ToString());
                    bool   rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        if (frameDict.Keys.Contains("rotated"))
                        {
                            rotated = ccUtils.ccParseInt(valueForKey("rotated", frameDict)) == 0 ? false : true;
                        }
                    }

                    CCPoint offset     = CCNS.CCPointFromString(valueForKey("offset", frameDict));
                    CCSize  sourceSize = CCNS.CCSizeFromString(valueForKey("sourceSize", frameDict));

                    // create frame
                    spriteFrame = new CCSpriteFrame();
                    spriteFrame.initWithTexture(pobTexture,
                                                frame,
                                                rotated,
                                                offset,
                                                sourceSize
                                                );
                }
                else
                if (format == 3)
                {
                    // get values
                    CCSize  spriteSize       = CCNS.CCSizeFromString(valueForKey("spriteSize", frameDict));
                    CCPoint spriteOffset     = CCNS.CCPointFromString(valueForKey("spriteOffset", frameDict));
                    CCSize  spriteSourceSize = CCNS.CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
                    CCRect  textureRect      = CCNS.CCRectFromString(valueForKey("textureRect", frameDict));
                    bool    textureRotated   = false;
                    if (frameDict.Keys.Contains("textureRotated"))
                    {
                        textureRotated = ccUtils.ccParseInt(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
                    }

                    // get aliases
                    var           list     = frameDict["aliases"];
                    List <object> aliases  = (frameDict["aliases"] as List <object>);
                    string        frameKey = key;
                    foreach (var item2 in aliases)
                    {
                        string oneAlias = item2.ToString();
                        if (m_pSpriteFramesAliases.Keys.Contains(oneAlias))
                        {
                            if (m_pSpriteFramesAliases[oneAlias] != null)
                            {
                                CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", oneAlias);
                            }
                        }
                        if (!m_pSpriteFramesAliases.Keys.Contains(frameKey))
                        {
                            m_pSpriteFramesAliases.Add(frameKey, oneAlias);
                        }
                    }

                    // create frame
                    spriteFrame = new CCSpriteFrame();
                    spriteFrame.initWithTexture(pobTexture,
                                                new CCRect(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
                                                textureRotated,
                                                spriteOffset,
                                                spriteSourceSize);
                }

                // add sprite frame
                if (!m_pSpriteFrames.Keys.Contains(key))
                {
                    m_pSpriteFrames.Add(key, spriteFrame);
                }
            }
        }
        public void addSpriteFramesWithDictionary(Dictionary <string, object> pobDictionary, CCTexture2D pobTexture)
        {
            Dictionary <string, object> item = null;

            if (pobDictionary.Keys.Contains <string>("metadata"))
            {
                item = (Dictionary <string, object>)pobDictionary["metadata"];
            }
            Dictionary <string, object> strs = null;

            if (pobDictionary.Keys.Contains <string>("frames"))
            {
                strs = (Dictionary <string, object>)pobDictionary["frames"];
            }
            int num = 0;

            if (item != null)
            {
                num = ccUtils.ccParseInt(item["format"].ToString());
            }
            foreach (string key in strs.Keys)
            {
                Dictionary <string, object> item1 = strs[key] as Dictionary <string, object>;
                CCSpriteFrame cCSpriteFrame       = new CCSpriteFrame();
                if (num == 0)
                {
                    float single  = ccUtils.ccParseFloat(item1["x"].ToString());
                    float single1 = ccUtils.ccParseFloat(item1["y"].ToString());
                    float single2 = ccUtils.ccParseFloat(item1["width"].ToString());
                    float single3 = ccUtils.ccParseFloat(item1["height"].ToString());
                    float single4 = ccUtils.ccParseFloat(item1["offsetX"].ToString());
                    float single5 = ccUtils.ccParseFloat(item1["offsetY"].ToString());
                    int   num1    = ccUtils.ccParseInt(item1["originalWidth"].ToString());
                    int   num2    = ccUtils.ccParseInt(item1["originalHeight"].ToString());
                    if (num1 == 0 || num2 == 0)
                    {
                        CCLog.Log("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
                    }
                    num1          = Math.Abs(num1);
                    num2          = Math.Abs(num2);
                    cCSpriteFrame = new CCSpriteFrame();
                    cCSpriteFrame.initWithTexture(pobTexture, new CCRect(single, single1, single2, single3), false, new CCPoint(single4, single5), new CCSize((float)num1, (float)num2));
                }
                else if (num == 1 || num == 2)
                {
                    CCRect cCRect = CCNS.CCRectFromString(item1["frame"].ToString());
                    bool   flag   = false;
                    if (num == 2 && item1.Keys.Contains <string>("rotated"))
                    {
                        flag = (ccUtils.ccParseInt(this.valueForKey("rotated", item1)) == 0 ? false : true);
                    }
                    CCPoint cCPoint = CCNS.CCPointFromString(this.valueForKey("offset", item1));
                    CCSize  cCSize  = CCNS.CCSizeFromString(this.valueForKey("sourceSize", item1));
                    cCSpriteFrame = new CCSpriteFrame();
                    cCSpriteFrame.initWithTexture(pobTexture, cCRect, flag, cCPoint, cCSize);
                }
                else if (num == 3)
                {
                    CCSize  cCSize1  = CCNS.CCSizeFromString(this.valueForKey("spriteSize", item1));
                    CCPoint cCPoint1 = CCNS.CCPointFromString(this.valueForKey("spriteOffset", item1));
                    CCSize  cCSize2  = CCNS.CCSizeFromString(this.valueForKey("spriteSourceSize", item1));
                    CCRect  cCRect1  = CCNS.CCRectFromString(this.valueForKey("textureRect", item1));
                    bool    flag1    = false;
                    if (item1.Keys.Contains <string>("textureRotated"))
                    {
                        flag1 = (ccUtils.ccParseInt(this.valueForKey("textureRotated", item1)) == 0 ? false : true);
                    }
                    object        obj  = item1["aliases"];
                    List <object> objs = item1["aliases"] as List <object>;
                    string        str  = key;
                    foreach (object obj1 in objs)
                    {
                        string str1 = obj1.ToString();
                        if (this.m_pSpriteFramesAliases.Keys.Contains <string>(str1) && this.m_pSpriteFramesAliases[str1] != null)
                        {
                            CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", new object[] { str1 });
                        }
                        if (this.m_pSpriteFramesAliases.Keys.Contains <string>(str))
                        {
                            continue;
                        }
                        this.m_pSpriteFramesAliases.Add(str, str1);
                    }
                    cCSpriteFrame = new CCSpriteFrame();
                    cCSpriteFrame.initWithTexture(pobTexture, new CCRect(cCRect1.origin.x, cCRect1.origin.y, cCSize1.width, cCSize1.height), flag1, cCPoint1, cCSize2);
                }
                if (this.m_pSpriteFrames.Keys.Contains <string>(key))
                {
                    continue;
                }
                this.m_pSpriteFrames.Add(key, cCSpriteFrame);
            }
        }