Exemplo n.º 1
0
        // CCLayer
        public override void onEnter()
        {
            base.onEnter();

            m_nCharLimit = 12;

            m_pTextFieldAction = CCRepeatForever.actionWithAction(
                (CCActionInterval)CCSequence.actions(
                    CCFadeOut.actionWithDuration(0.25f),
                    CCFadeIn.actionWithDuration(0.25f)));
            //m_pTextFieldAction->retain();
            m_bAction = false;

            // add CCTextFieldTTF
            CCSize s = CCDirector.sharedDirector().getWinSize();

            m_pTextField = CCTextFieldTTF.textFieldWithPlaceHolder("<click here for input>",
                                                                   TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);
            addChild(m_pTextField);

            //m_pTextField.setDelegate(this);


            //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
            //    // on android, CCTextFieldTTF cannot auto adjust its position when soft-keyboard pop up
            //    // so we had to set a higher position
            //    m_pTextField->setPosition(new CCPoint(s.width / 2, s.height/2 + 50));
            //#else
            //    m_pTextField->setPosition(ccp(s.width / 2, s.height / 2));
            //#endif

            m_pTrackNode = m_pTextField;
        }
Exemplo n.º 2
0
 // CCTextFieldDelegate
 public virtual bool onTextFieldAttachWithIME(CCTextFieldTTF pSender)
 {
     if (m_bAction != null)
     {
         m_pTextField.runAction(m_pTextFieldAction);
         m_bAction = true;
     }
     return(false);
 }
Exemplo n.º 3
0
 public virtual bool onTextFieldDetachWithIME(CCTextFieldTTF pSender)
 {
     if (m_bAction != null)
     {
         m_pTextField.stopAction(m_pTextFieldAction);
         m_pTextField.Opacity = 255;
         m_bAction            = false;
     }
     return(false);
 }
Exemplo n.º 4
0
        public static CCTextFieldTTF textFieldWithPlaceHolder(string placeholder, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize)
        {
            CCTextFieldTTF cCTextFieldTTF = new CCTextFieldTTF();

            if (cCTextFieldTTF == null || !cCTextFieldTTF.initWithPlaceHolder("", dimensions, alignment, fontName, fontSize))
            {
                return(null);
            }
            if (placeholder != null)
            {
                cCTextFieldTTF.PlaceHolder = placeholder;
            }
            return(cCTextFieldTTF);
        }
Exemplo n.º 5
0
        public static CCTextFieldTTF textFieldWithPlaceHolder(string placeholder, string fontName, float fontSize)
        {
            CCTextFieldTTF cCTextFieldTTF = new CCTextFieldTTF();

            if (cCTextFieldTTF == null || !cCTextFieldTTF.initWithString("", fontName, fontSize))
            {
                return(null);
            }
            if (placeholder != null)
            {
                cCTextFieldTTF.PlaceHolder = placeholder;
            }
            return(cCTextFieldTTF);
        }
Exemplo n.º 6
0
        public virtual bool onTextFieldInsertText(CCTextFieldTTF pSender, string text, int nLen)
        {
            // if insert enter, treat as default to detach with ime
            if ("\n" == text)
            {
                return(false);
            }

            // if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
            if (pSender.CharCount >= m_nCharLimit)
            {
                return(true);
            }

            // create a insert text sprite and do some action
            CCLabelTTF label = CCLabelTTF.labelWithString(text, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);

            this.addChild(label);
            ccColor3B color = new ccColor3B {
                r = 226, g = 121, b = 7
            };

            label.Color = color;

            // move the sprite from top to position
            CCPoint endPos = pSender.position;

            if (pSender.CharCount > 0)
            {
                endPos.x += pSender.contentSize.width / 2;
            }
            CCSize  inputTextSize = label.contentSize;
            CCPoint beginPos      = new CCPoint(endPos.x, CCDirector.sharedDirector().getWinSize().height - inputTextSize.height * 2);

            float duration = 0.5f;

            label.position = beginPos;
            label.scale    = 8;

            CCAction seq = CCSequence.actions(
                CCSpawn.actions(
                    CCMoveTo.actionWithDuration(duration, endPos),
                    CCScaleTo.actionWithDuration(duration, 1),
                    CCFadeOut.actionWithDuration(duration)),
                CCCallFuncN.actionWithTarget(this, callbackRemoveNodeWhenDidAction));

            label.runAction(seq);
            return(false);
        }
Exemplo n.º 7
0
 /** creates a CCLabelTTF from a fontname and font size */
 public static CCTextFieldTTF textFieldWithPlaceHolder(string placeholder, string fontName, float fontSize)
 {
     CCTextFieldTTF pRet = new CCTextFieldTTF();
     if (pRet != null && pRet.initWithString("", fontName, fontSize))
     {
         //pRet->autorelease();
         if (placeholder != null)
         {
             pRet.PlaceHolder = placeholder;
         }
         return pRet;
     }
     //CC_SAFE_DELETE(pRet);
     return null;
     //throw new NotFiniteNumberException();
 }
Exemplo n.º 8
0
        /** creates a CCLabelTTF from a fontname and font size */
        public static CCTextFieldTTF textFieldWithPlaceHolder(string placeholder, string fontName, float fontSize)
        {
            CCTextFieldTTF pRet = new CCTextFieldTTF();

            if (pRet != null && pRet.initWithString("", fontName, fontSize))
            {
                //pRet->autorelease();
                if (placeholder != null)
                {
                    pRet.PlaceHolder = placeholder;
                }
                return(pRet);
            }
            //CC_SAFE_DELETE(pRet);
            return(null);
            //throw new NotFiniteNumberException();
        }
Exemplo n.º 9
0
        public virtual void onClickTrackNode(bool bClicked)
        {
            CCTextFieldTTF pTextField = (CCTextFieldTTF)m_pTrackNode;

            if (bClicked)
            {
                // TextFieldTTFTest be clicked
                CCLog.Log("TextFieldTTFDefaultTest:CCTextFieldTTF attachWithIME");
                pTextField.attachWithIME();
            }
            else
            {
                // TextFieldTTFTest not be clicked
                CCLog.Log("TextFieldTTFDefaultTest:CCTextFieldTTF detachWithIME");
                pTextField.detachWithIME();
            }
        }
Exemplo n.º 10
0
        public virtual void onClickTrackNode(bool bClicked)
        {
            CCTextFieldTTF pTextField = (CCTextFieldTTF)m_pTrackNode;

            if (bClicked)
            {
                // TextFieldTTFTest be clicked
                Debug.WriteLine("TextFieldTTFActionTest:CCTextFieldTTF attachWithIME");
                pTextField.attachWithIME();
            }
            else
            {
                // TextFieldTTFTest not be clicked
                Debug.WriteLine("TextFieldTTFActionTest:CCTextFieldTTF detachWithIME");
                pTextField.detachWithIME();
            }
        }
Exemplo n.º 11
0
        // CCLayer
        public override void onEnter()
        {
            base.onEnter();

            // add CCTextFieldTTF
            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCTextFieldTTF pTextField = CCTextFieldTTF.textFieldWithPlaceHolder("<click here for input>",
                                                                                TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);

            addChild(pTextField);

            //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
            //    // on android, CCTextFieldTTF cannot auto adjust its position when soft-keyboard pop up
            //    // so we had to set a higher position to make it visable
            //    pTextField->setPosition(ccp(s.width / 2, s.height/2 + 50));
            //#else
            //    pTextField->setPosition(ccp(s.width / 2, s.height / 2));
            //#endif

            m_pTrackNode = pTextField;
        }
Exemplo n.º 12
0
        public virtual bool onTextFieldDeleteBackward(CCTextFieldTTF pSender, string delText, int nLen)
        {
            // create a delete text sprite and do some action
            CCLabelTTF label = CCLabelTTF.labelWithString(delText, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);

            this.addChild(label);

            // move the sprite to fly out
            CCPoint beginPos      = pSender.position;
            CCSize  textfieldSize = pSender.contentSize;
            CCSize  labelSize     = label.contentSize;

            beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f;

            int    RAND_MAX = 32767;
            Random rand     = new Random();

            CCSize  winSize        = CCDirector.sharedDirector().getWinSize();
            CCPoint endPos         = new CCPoint(-winSize.width / 4.0f, winSize.height * (0.5f + (float)rand.Next() / (2.0f * RAND_MAX)));
            float   duration       = 1;
            float   rotateDuration = 0.2f;
            int     repeatTime     = 5;

            label.position = beginPos;

            CCAction seq = CCSequence.actions(
                CCSpawn.actions(
                    CCMoveTo.actionWithDuration(duration, endPos),
                    CCRepeat.actionWithAction(
                        CCRotateBy.actionWithDuration(rotateDuration, (rand.Next() % 2 > 0) ? 360 : -360),
                        (uint)repeatTime),
                    CCFadeOut.actionWithDuration(duration)),
                CCCallFuncN.actionWithTarget(this, callbackRemoveNodeWhenDidAction));

            label.runAction(seq);
            return(false);
        }
Exemplo n.º 13
0
        public virtual bool onTextFieldInsertText(CCTextFieldTTF pSender, string text, int nLen)
        {
            // if insert enter, treat as default to detach with ime
            if ("\n" == text)
            {
                return false;
            }

            // if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
            if (pSender.CharCount >= m_nCharLimit)
            {
                return true;
            }

            // create a insert text sprite and do some action
            CCLabelTTF label = new CCLabelTTF(text, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);
            this.AddChild(label);
            CCColor3B color = new CCColor3B { R = 226, G = 121, B = 7 };
            label.Color = color;

            // move the sprite from top to position
            CCPoint endPos = pSender.Position;
            if (pSender.CharCount > 0)
            {
                endPos.X += pSender.ContentSize.Width / 2;
            }
            CCSize inputTextSize = label.ContentSize;
            CCPoint beginPos = new CCPoint(endPos.X, CCDirector.SharedDirector.WinSize.Height - inputTextSize.Height * 2);

            float duration = 0.5f;
            label.Position = beginPos;
            label.Scale = 8;

            CCAction seq = CCSequence.FromActions(
                CCSpawn.FromActions(
                    new CCMoveTo (duration, endPos),
                    new CCScaleTo(duration, 1),
                    new CCFadeOut  (duration)),
                new CCCallFuncN(callbackRemoveNodeWhenDidAction));
            label.RunAction(seq);
            return false;
        }
Exemplo n.º 14
0
        public virtual bool onTextFieldDeleteBackward(CCTextFieldTTF pSender, string delText, int nLen)
        {
            // create a delete text sprite and do some action
            CCLabelTTF label = new CCLabelTTF(delText, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);
            this.AddChild(label);

            // move the sprite to fly out
            CCPoint beginPos = pSender.Position;
            CCSize textfieldSize = pSender.ContentSize;
            CCSize labelSize = label.ContentSize;
            beginPos.X += (textfieldSize.Width - labelSize.Width) / 2.0f;

            int RAND_MAX = 32767;
            Random rand = new Random();

            CCSize winSize = CCDirector.SharedDirector.WinSize;
            CCPoint endPos = new CCPoint(-winSize.Width / 4.0f, winSize.Height * (0.5f + (float)Random.Next() / (2.0f * RAND_MAX)));
            float duration = 1;
            float rotateDuration = 0.2f;
            int repeatTime = 5;
            label.Position = beginPos;

            CCAction seq = CCSequence.FromActions(
                CCSpawn.FromActions(
                    new CCMoveTo (duration, endPos),
                    new CCRepeat (
                        new CCRotateBy (rotateDuration, (Random.Next() % 2 > 0) ? 360 : -360),
                        (uint)repeatTime),
                    new CCFadeOut  (duration)),
                new CCCallFuncN(callbackRemoveNodeWhenDidAction));
            label.RunAction(seq);
            return false;
        }
Exemplo n.º 15
0
        public virtual bool onTextFieldDeleteBackward(CCTextFieldTTF pSender, string delText, int nLen)
        {
            // create a delete text sprite and do some action
            CCLabelTTF label = CCLabelTTF.labelWithString(delText, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);
            this.addChild(label);

            // move the sprite to fly out
            CCPoint beginPos = pSender.position;
            CCSize textfieldSize = pSender.contentSize;
            CCSize labelSize = label.contentSize;
            beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f;

            int RAND_MAX = 32767;
            Random rand = new Random();

            CCSize winSize = CCDirector.sharedDirector().getWinSize();
            CCPoint endPos = new CCPoint(-winSize.width / 4.0f, winSize.height * (0.5f + (float)rand.Next() / (2.0f * RAND_MAX)));
            float duration = 1;
            float rotateDuration = 0.2f;
            int repeatTime = 5;
            label.position = beginPos;

            CCAction seq = CCSequence.actions(
                CCSpawn.actions(
                    CCMoveTo.actionWithDuration(duration, endPos),
                    CCRepeat.actionWithAction(
                        CCRotateBy.actionWithDuration(rotateDuration, (rand.Next() % 2 > 0) ? 360 : -360),
                        (uint)repeatTime),
                    CCFadeOut.actionWithDuration(duration)),
                CCCallFuncN.actionWithTarget(this, callbackRemoveNodeWhenDidAction));
            label.runAction(seq);
            return false;
        }
Exemplo n.º 16
0
 public virtual bool onTextFieldDetachWithIME(CCTextFieldTTF pSender)
 {
     if (m_bAction != null)
     {
         m_pTextField.stopAction(m_pTextFieldAction);
         m_pTextField.Opacity = 255;
         m_bAction = false;
     }
     return false;
 }
Exemplo n.º 17
0
        // CCLayer
        public override void onEnter()
        {
            base.onEnter();

            m_nCharLimit = 12;

            m_pTextFieldAction = CCRepeatForever.actionWithAction(
                (CCActionInterval)CCSequence.actions(
                    CCFadeOut.actionWithDuration(0.25f),
                    CCFadeIn.actionWithDuration(0.25f)));
            //m_pTextFieldAction->retain();
            m_bAction = false;

            // add CCTextFieldTTF
            CCSize s = CCDirector.sharedDirector().getWinSize();

            m_pTextField = CCTextFieldTTF.textFieldWithPlaceHolder("<click here for input>",
            TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);
            addChild(m_pTextField);

            //m_pTextField.setDelegate(this);


            //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)	
            //    // on android, CCTextFieldTTF cannot auto adjust its position when soft-keyboard pop up
            //    // so we had to set a higher position
            //    m_pTextField->setPosition(new CCPoint(s.width / 2, s.height/2 + 50));
            //#else
            //    m_pTextField->setPosition(ccp(s.width / 2, s.height / 2));
            //#endif

            m_pTrackNode = m_pTextField;
        }
Exemplo n.º 18
0
 // CCTextFieldDelegate
 public virtual bool onTextFieldAttachWithIME(CCTextFieldTTF pSender)
 {
     if (m_bAction != null)
     {
         m_pTextField.runAction(m_pTextFieldAction);
         m_bAction = true;
     }
     return false;
 }
Exemplo n.º 19
0
 public virtual bool onDraw(CCTextFieldTTF pSender)
 {
     return(false);
 }
Exemplo n.º 20
0
        public virtual bool onTextFieldInsertText(CCTextFieldTTF pSender, string text, int nLen)
        {
            // if insert enter, treat as default to detach with ime
            if ("\n" == text)
            {
                return false;
            }

            // if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
            if (pSender.CharCount >= m_nCharLimit)
            {
                return true;
            }

            // create a insert text sprite and do some action
            CCLabelTTF label = CCLabelTTF.labelWithString(text, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);
            this.addChild(label);
            ccColor3B color = new ccColor3B { r = 226, g = 121, b = 7 };
            label.Color = color;

            // move the sprite from top to position
            CCPoint endPos = pSender.position;
            if (pSender.CharCount > 0)
            {
                endPos.x += pSender.contentSize.width / 2;
            }
            CCSize inputTextSize = label.contentSize;
            CCPoint beginPos = new CCPoint(endPos.x, CCDirector.sharedDirector().getWinSize().height - inputTextSize.height * 2);

            float duration = 0.5f;
            label.position = beginPos;
            label.scale = 8;

            CCAction seq = CCSequence.actions(
                CCSpawn.actions(
                    CCMoveTo.actionWithDuration(duration, endPos),
                    CCScaleTo.actionWithDuration(duration, 1),
                    CCFadeOut.actionWithDuration(duration)),
                CCCallFuncN.actionWithTarget(this, callbackRemoveNodeWhenDidAction));
            label.runAction(seq);
            return false;
        }
Exemplo n.º 21
0
 public static CCTextFieldTTF TextFieldWithPlaceHolder(string placeholder, string fontName, float fontSize)
 {
     var pRet = new CCTextFieldTTF();
     pRet.InitWithString("", fontName, fontSize);
     if (placeholder != null)
     {
         pRet.PlaceHolder = placeholder;
     }
     return pRet;
 }
Exemplo n.º 22
0
 public virtual bool onDraw(CCTextFieldTTF pSender)
 {
     return false;
 }
Exemplo n.º 23
0
 public static CCTextFieldTTF TextFieldWithPlaceHolder(string placeholder, CCSize dimensions, CCTextAlignment alignment, string fontName,
                                                       float fontSize)
 {
     var pRet = new CCTextFieldTTF();
     pRet.InitWithPlaceHolder("", dimensions, alignment, fontName, fontSize);
     if (placeholder != null)
     {
         pRet.PlaceHolder = placeholder;
     }
     return pRet;
 }