VS build Lua development environment and Luabridge Register C + + class (COCOS2DX project) (iii) Add event to EditBox

Source: Internet
Author: User
Tags addchild gettext lua

Directly post the implementation code

1 voidScriptmanager::addeditboxevent (luaeditbox* UI, std::stringfunname)2 {3STD::stringEditboxeditingdidbegin = Funname +"_editboxeditingdidbegin";4STD::stringEditboxeditingdidend = Funname +"_editboxeditingdidend";5STD::stringeditboxtextchanged = Funname +"_editboxtextchanged";6STD::stringEditboxreturn = Funname +"_editboxreturn";7 8Auto DBG =NewLuaref (Getglobal (Luastate, Editboxeditingdidbegin.c_str ()));9Auto Ded =NewLuaref (Getglobal (Luastate, Editboxeditingdidend.c_str ()));TenAuto TC =NewLuaref (Getglobal (Luastate, Editboxtextchanged.c_str ())); OneAuto BR =NewLuaref (Getglobal (Luastate, Editboxreturn.c_str ())); A  -     Try -     { the         if(dbg->isfunction ()) -         { -ui->dbg = [DBG] () {(*dbg) (); }; -         } +         if(ded->isfunction ()) -         { +ui->ded = [Ded] () {(*ded) (); }; A         } at         if(tc->isfunction ()) -         { -UI->TC = [TC] () {(*TC) (); }; -         } -         if(br->isfunction ()) -         { inUI->BR = [BR] () {(*BR) (); }; -         } to     } +     Catch(luaexception&e) -     { theCclog ("Lua Error:%s", E.what ()); *     } $ Panax Notoginseng}

Here is the EditBox package class

1 classLuaeditbox: PublicLayer, PublicEditboxdelegate, Publicimedelegate2 {3  Public:4 Luaeditbox ();5~Luaeditbox ();6 7     Staticluaeditbox* Create (node* Node,intflag, Vec2 POS);8 9STD::stringgetName ();Ten  OneSTD::stringGetText (); A  -     Static intBoxnumber; - //luaeditbox* createeditbox (node* node,int flag, Vec2 pos = VEC2 (0,0)); the  -     voidEditboxeditingdidbegin (editbox*editbox) -     { -         if(DBG) {dbg ();}; +     }; -     voidEditboxeditingdidend (editbox*editbox) +     { A         if(ded) {ded ();}; at     }; -     voidEditboxtextchanged (editbox* EditBox,ConstSTD::string&text) -     {  -         if(TC) -         { - TC (); in         };  -     }; to     voidEditboxreturn (editbox*editbox) +     { -         if(BR) {br ();}; the     }; *     Virtual voidKeyboardwillshow (imekeyboardnotificationinfo&info) {}; $ Panax Notoginseng     /*void (*dbg) (); - void (*ded) (); the void (*TC) (); + void (*BR) ();*/ A  thestd::function<void() >dbg; +std::function<void() >ded; -std::function<void() >TC; $std::function<void() >BR; $  - protected: -editbox*M_editbox; the Private: - WuyiSTD::string_name; the  -};
header File
1#include"LuaEditBox.h"2#include"UIManager.h"3 4 intLuaeditbox::boxnumber =0;5 Luaeditbox::luaeditbox (): M_editbox (nullptr)6 {7_name ="Luaeditbox_"+Boxnumber;8 }9 Ten  Oneluaeditbox::~Luaeditbox () A { - } -  theluaeditbox* luaeditbox::create (node* Node,intflag, Vec2 POS) - { -luaeditbox* Pluaeditbox =NewLuaeditbox (); -  +Auto Editboxsize = Size (228, +); -STD::stringPnormalsprite = Fileutils::getinstance ()->fullpathforfilename ("Inputbg.png"); +Pluaeditbox->m_editbox =editbox::create (Editboxsize, Scale9sprite::create (Pnormalsprite)); A     //m_editbox->setposition (POS); atPluaeditbox->m_editbox->setfontname ("Microsoft Ya-Black"); -Pluaeditbox->m_editbox->setfontsize ( -); -Pluaeditbox->m_editbox->Setfontcolor (color3b::white); -     //M_editbox->setplaceholder ("Name:"); -Pluaeditbox->m_editbox->Setplaceholderfontcolor (color3b::white); -Pluaeditbox->m_editbox->setmaxlength (8); inPluaeditbox->m_editbox->Setreturntype (editbox::keyboardreturntype::D one); -Pluaeditbox->m_editbox->Setinputflag (Editbox::inputflag (flag)); toPluaeditbox->m_editbox->setdelegate (pluaeditbox); +  -Pluaeditbox->addchild (pluaeditbox->m_editbox); thePluaeditbox->setposition (POS); *  $Node->AddChild (pluaeditbox);Panax Notoginseng     if(Pluaeditbox) -     { thePluaeditbox->autorelease (); +         returnPluaeditbox; A     } the     Else +     { - Delete Pluaeditbox; $Pluaeditbox =NULL; $         returnNULL; -     } - } the  -STD::stringLuaeditbox::getname ()Wuyi { the     return_name; - } Wu  -STD::stringLuaeditbox::gettext () About { $STD::stringstr = m_editbox->GetText (); -     returnstr; -}
CPP File

VS build Lua development environment and Luabridge Register C + + class (COCOS2DX project) (iii) Add event to EditBox

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.