Where is UIHelper?

Hello everyone.
I am trying to use CocoStudio to make GUI of my game. I am using cocos2dx 3 (3.0rc0, but also trying 3.2rc0) I made GUI, did export and took a JSON file.
Then I tryed to use it in game, following this instruction.
But I can’t find a UIHelper class. Also I tryed this way, but i didn’t have any profit, becouse I didn’t found SceneReader.

So, how I should use .json files from cocostudio in game using cocos2dx 3.x?

Hi Garrus,

UIHelper.h is located in yourProject\cocos2d\cocos\ui
You should be able to include it with #include <ui\UIHelper.h> If not than look at the include-directories of the vs project.
Did you include libCocosStudio? The SceneReader is located in yourProject\cocos2d\cocos\editor-support\cocostudio.

So, I do this things:

include “cocos2d\cocos\ui\UIHelper.h”
include “cocos-ext.h”

then using cocos2d and cocos2d::extension namespaces.

How I need to include libCocosStudio?
I am trying this way

But I can’t build it, becouse I got too many strange errors, like

-Missing type specifier expected int
-Syntax error, “;” forgot before *
-int cocos2d::ui::Helper::Widget: redefine
-syntax error: identifier “Widget”

in UIHelper.h
(sorry, if error look strange, I’ve translated them from russian VS)

One step after another. Were you able to add libGUI libCocosStudio libExtensions to your project?
Can you see it on the left while working with Visual Studio?

Okay, that’s right.
The errors you get while building, are they from your project (BlackDiggers) or from the cocos-libs?

They are from my project, but all of them are located in UIHelper.h.

Well, I think I found solution.
VS tell me, that Widget undifined. I’m include “UIWidget.h” and It all builds succsesful.

But this is not an end:

Did you look in the UIHelper.h? it’s in the namespace ui. The class is also called Helper.
Try ui::Helper.

Well, I found this class (ui::helper).
But there only few methods

seekActionWidgetByActionTag
seekWidgetByName
seekWidgetByTag

And I can’t understand, how to use it, to use .json layot from cocostudio

In cocos2d-x 3.0 C++ you use the sceneReader to load json files. The uihelper could be used for the three methods you posted (personally I do not use UIHelper).

Read a cocostudio scene.

auto scene = cocostudio::SceneReader::getInstance()->createNodeWithSceneFile("publish/Intro.json");

You can add it like this

this->addChild(scene);

You need to include (I thinks that’s all, not 100% sure)

#include <editor-support\cocostudio\CocoStudio.h>

Additionally you need to add

$(EngineRoot)cocos\editor-support

to your C+±Include Directories.

Great thanks you! This way is really true, and I finnaly compile a program. But, exactly, compile != work. So, I faced with one more problem :frowning:

I export UI, placed it in a directory into my project, create scene with a getInstance()->createNodeWithSceneFile(%filename%);

But I get a run-time error:

  1. In SceneReader class called function createObject
  2. In this function called function getStringValue_json(dict, “classname”) of the DictionaryHelper. This function should return some string, but It returns NULL/
  3. Result of this functions used in strcmp, but it is NULL, so there is runtime error.

(File really exists, if I try to createNodeWithSceneFile of a not-existing file, this function works well and returns NULL)

I think truble in function

const char* DictionaryHelper::getStringValue_json(const rapidjson::Value& root,const char* key, const char def)
{
const char
sRet = def;
do {
CC_BREAK_IF(root.IsNull());
CC_BREAK_IF(root[key].IsNull());
sRet = root[key].GetString();
} while (0);

return sRet;

}

When I debbuging it step-by-step, I saw, than CC_BREAK_IF(root[key].IsNull()); breaks the loop and sRet is still NULL

Wait Wait Wait… You can only read jsons which were created from the Scene Editor with the cocostudio::SceneReader. If you want to read jsons which were created from the UI Editor you need the cocostudio::GUIReader

auto widget = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("ui/livingRoom/livingRoom.json");

Yeah! It’w work! Thanks you!