How can I use LUA to set chinese string in CEGUI

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

finezwx
Just popping in
Just popping in
Posts: 13
Joined: Fri May 23, 2008 02:20

How can I use LUA to set chinese string in CEGUI

Postby finezwx » Mon Dec 29, 2008 11:12

I make CEGUI interface use Lua.
and I need Set some chinese string in StaticText.

for Example:
cstrUIHelpWindowHelpText = "大家好"
pWindow = winMgr:getWindow("Root/MainBgImage/TextBgImage/TextWindow")

local myString2,myString = StringToUtf8(cstrUIHelpWindowHelpText,myString1)

pWindow:setText(myString)

StringToUtf8() is a C++ function. and it can work well in C++.

But It's messy code.

haihuojiming
Just popping in
Just popping in
Posts: 10
Joined: Tue Jul 01, 2008 07:57

Postby haihuojiming » Mon Dec 29, 2008 14:35

hi. i know the problem you have.

lua support the asc code, so when you translate the string to unicode, you won't have the right result.

I'm Chinese too, add me msn

haihuogeming#163.com .. maybe i can help you

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Mon Dec 29, 2008 14:54

Exactly, it's about the ascii support in lua. What i did for a project was come up with a helper function which i did bind:

Code: Select all

void Gui::setWinTextUTF8(std::string winName, std::string winText)
   {
      CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
      if (winMgr.isWindowPresent(winName))
      {
         CEGUI::Window* win = winMgr.getWindow(winName);
         win->setText((CEGUI::utf8*)winText.c_str());
      }
   }


which you could call as:

Code: Select all

gui_wrapper:setWinTextUTF8("Root/MainBgImage/TextBgImage/TextWindow", "大家好");


So that you don't have a conversion 'through' the binding. I can confirm that it works for Japanese and Korean at least.

HTH.
Check out my released snake game using Cegui!

haihuojiming
Just popping in
Just popping in
Posts: 10
Joined: Tue Jul 01, 2008 07:57

Postby haihuojiming » Tue Dec 30, 2008 16:13

the function works for Chinese too .

i add a a method setTextA to base class CEGUI::Window, it use a virtual interface to tanslate the code.

but... ... scriptkid
do you forget to use a transform funtion for ascToUTF8 ?
--------------------------------------------------------------------------------
void Gui::setWinTextUTF8(std::string winName, std::string winText)
{
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
if (winMgr.isWindowPresent(winName))
{
CEGUI::Window* win = winMgr.getWindow(winName);
--
CEGUI::String UtfText = (CEGUI::utf8*)ascToUtf8(winText.c_str());
--
win->setText(UtfText );
--
}
}
---------------------------------------------------------------------------------

finezwx
Just popping in
Just popping in
Posts: 13
Joined: Fri May 23, 2008 02:20

Postby finezwx » Wed Dec 31, 2008 01:16

thank you very much.
and I have take a try, It worked for me.

I didn't use msn. and this is my QQ:173683327


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 8 guests