示例#1
0
        public void RemoveTargetWithActionForControlEvent(object target, Action <object, CCControlEvent> action, CCControlEvent controlEvent)
        {
            // Retrieve all invocations for the given control event
            //<CCInvocation*>
            CCRawList <CCInvocation> eventInvocationList = DispatchListforControlEvent(controlEvent);

            //remove all invocations if the target and action are null
            if (target == null && action == null)
            {
                //remove objects
                eventInvocationList.Clear();
            }
            else
            {
                //normally we would use a predicate, but this won't work here. Have to do it manually
                foreach (CCInvocation invocation in eventInvocationList)
                {
                    bool shouldBeRemoved = true;
                    if (target != null)
                    {
                        shouldBeRemoved = (target == invocation.Target);
                    }
                    if (action != null)
                    {
                        shouldBeRemoved = (shouldBeRemoved && (action == invocation.Action));
                    }
                    // Remove the corresponding invocation object
                    if (shouldBeRemoved)
                    {
                        eventInvocationList.Remove(invocation);
                    }
                }
            }
        }
示例#2
0
        public override void RemoveAllChildrenWithCleanup(bool cleanup)
        {
            // Invalidate atlas index. issue #569
            // useSelfRender should be performed on all descendants. issue #1216
            CCSprite[] elements = m_pobDescendants.Elements;
            for (int i = 0, count = m_pobDescendants.count; i < count; i++)
            {
                elements[i].BatchNode = null;
            }

            base.RemoveAllChildrenWithCleanup(cleanup);

            m_pobDescendants.Clear();
            m_pobTextureAtlas.RemoveAllQuads();
        }
示例#3
0
 public void RemoveAllQuads()
 {
     m_pQuads.Clear();
     Dirty = true;
 }
        /** Clear the geometry in the node's buffer. */

        public void Clear()
        {
            m_pVertices.Clear();
        }
示例#5
0
        protected void UpdateLabel()
        {
            SetString(m_sInitialString, true);

            if (m_fWidth > 0)
            {
                // Step 1: Make multiline
                string str_whole        = m_sString;
                int    stringLength     = m_sString.Length;
                var    multiline_string = new StringBuilder(stringLength);
                var    last_word        = new StringBuilder(stringLength);

                int   line = 1, i = 0;
                bool  start_line = false, start_word = false;
                float startOfLine = -1, startOfWord = -1;
                int   skip = 0;

                CCRawList <CCNode> children = m_pChildren;
                for (int j = 0; j < children.count; j++)
                {
                    CCSprite characterSprite;

                    while ((characterSprite = (CCSprite)GetChildByTag(j + skip)) == null)
                    {
                        skip++;
                    }

                    if (!characterSprite.Visible)
                    {
                        continue;
                    }

                    if (i >= stringLength)
                    {
                        break;
                    }

                    char character = str_whole[i];

                    if (!start_word)
                    {
                        startOfWord = GetLetterPosXLeft(characterSprite);
                        start_word  = true;
                    }
                    if (!start_line)
                    {
                        startOfLine = startOfWord;
                        start_line  = true;
                    }

                    // Newline.
                    if (character == '\n')
                    {
                        int len = last_word.Length;
                        while (len > 0 && Char.IsWhiteSpace(last_word[len - 1]))
                        {
                            len--;
                            last_word.Remove(len, 1);
                        }

                        multiline_string.Append(last_word);
                        multiline_string.Append('\n');

#if XBOX || XBOX360
                        last_word.Length = 0;
#else
                        last_word.Clear();
#endif

                        start_word  = false;
                        start_line  = false;
                        startOfWord = -1;
                        startOfLine = -1;
                        i++;
                        line++;

                        if (i >= stringLength)
                        {
                            break;
                        }

                        character = str_whole[i];

                        if (startOfWord == 0)
                        {
                            startOfWord = GetLetterPosXLeft(characterSprite);
                            start_word  = true;
                        }
                        if (startOfLine == 0)
                        {
                            startOfLine = startOfWord;
                            start_line  = true;
                        }
                    }

                    // Whitespace.
                    if (Char.IsWhiteSpace(character))
                    {
                        last_word.Append(character);
                        multiline_string.Append(last_word);
#if XBOX || XBOX360
                        last_word.Length = 0;
#else
                        last_word.Clear();
#endif
                        start_word  = false;
                        startOfWord = -1;
                        i++;
                        continue;
                    }

                    // Out of bounds.
                    if (GetLetterPosXRight(characterSprite) - startOfLine > m_fWidth)
                    {
                        if (!m_bLineBreakWithoutSpaces)
                        {
                            last_word.Append(character);

                            int len = multiline_string.Length;
                            while (len > 0 && Char.IsWhiteSpace(multiline_string[len - 1]))
                            {
                                len--;
                                multiline_string.Remove(len, 1);
                            }

                            if (multiline_string.Length > 0)
                            {
                                multiline_string.Append('\n');
                            }

                            line++;
                            start_line  = false;
                            startOfLine = -1;
                            i++;
                        }
                        else
                        {
                            int len = last_word.Length;
                            while (len > 0 && Char.IsWhiteSpace(last_word[len - 1]))
                            {
                                len--;
                                last_word.Remove(len, 1);
                            }

                            multiline_string.Append(last_word);
                            multiline_string.Append('\n');

#if XBOX || XBOX360
                            last_word.Length = 0;
#else
                            last_word.Clear();
#endif

                            start_word  = false;
                            start_line  = false;
                            startOfWord = -1;
                            startOfLine = -1;
                            line++;

                            if (i >= stringLength)
                            {
                                break;
                            }

                            if (startOfWord == 0)
                            {
                                startOfWord = GetLetterPosXLeft(characterSprite);
                                start_word  = true;
                            }
                            if (startOfLine == 0)
                            {
                                startOfLine = startOfWord;
                                start_line  = true;
                            }

                            j--;
                        }

                        continue;
                    }
                    else
                    {
                        // Character is normal.
                        last_word.Append(character);
                        i++;
                        continue;
                    }
                }

                multiline_string.Append(last_word);

                m_sString = multiline_string.ToString();

                UpdateString(true);
            }

            // Step 2: Make alignment
            if (m_pAlignment != CCTextAlignment.CCTextAlignmentLeft)
            {
                int i = 0;

                int lineNumber = 0;
                int str_len    = m_sString.Length;
                var last_line  = new CCRawList <char>();
                for (int ctr = 0; ctr <= str_len; ++ctr)
                {
                    if (ctr == str_len || m_sString[ctr] == '\n')
                    {
                        float lineWidth   = 0.0f;
                        int   line_length = last_line.Count;
                        // if last line is empty we must just increase lineNumber and work with next line
                        if (line_length == 0)
                        {
                            lineNumber++;
                            continue;
                        }
                        int index = i + line_length - 1 + lineNumber;
                        if (index < 0)
                        {
                            continue;
                        }

                        var lastChar = (CCSprite)GetChildByTag(index);
                        if (lastChar == null)
                        {
                            continue;
                        }

                        lineWidth = lastChar.Position.X + lastChar.ContentSize.Width / 2.0f;

                        float shift = 0;
                        switch (m_pAlignment)
                        {
                        case CCTextAlignment.CCTextAlignmentCenter:
                            shift = ContentSize.Width / 2.0f - lineWidth / 2.0f;
                            break;

                        case CCTextAlignment.CCTextAlignmentRight:
                            shift = ContentSize.Width - lineWidth;
                            break;

                        default:
                            break;
                        }

                        if (shift != 0)
                        {
                            for (int j = 0; j < line_length; j++)
                            {
                                index = i + j + lineNumber;
                                if (index < 0)
                                {
                                    continue;
                                }

                                var characterSprite = (CCSprite)GetChildByTag(index);
                                characterSprite.Position = characterSprite.Position + new CCPoint(shift, 0.0f);
                            }
                        }

                        i += line_length;
                        lineNumber++;

                        last_line.Clear();
                        continue;
                    }

                    last_line.Add(m_sString[ctr]);
                }
            }
        }