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