So does CS and cocos2d-x(like cocos console). It has a hidden silent switch, which was discussed in the forum and they promised change/clearing up. But it’s just metric about your PC, not the created software.
Go cocos2d-x/SDL then It does not make a product out of you
If you want to avoid metric and “the human product” stuff, stay away from third party SDKs and roll your own stuff.
Ah, I missed your point. Your mystery was about the automatic binding to the implementation/code. My conentration is sometimes lacking cause of “multitasking”
They would need some sort of reflection in C++ like in Java,
To solve that mystery for now: it seems it isn’t implemented yet. They just pass a nullptr
if there is no callback. The Nodes itself are not even implementing the WidgetCallBackHandlerProtocol
.
Node* CSLoader::nodeWithFlatBuffersFile(const std::string &fileName)
{
return nodeWithFlatBuffersFile(fileName, nullptr);
}
Node* CSLoader::createNodeWithFlatBuffersFile(const std::string &filename, const ccNodeLoadCallback &callback)
{
Node* node = nodeWithFlatBuffersFile(filename, callback);
/* To reconstruct nest node as WidgetCallBackHandlerProtocol. */
auto callbackHandler = dynamic_cast<WidgetCallBackHandlerProtocol *>(node);
if (callbackHandler)
{
_callbackHandlers.popBack();
if (_callbackHandlers.empty())
{
_rootNode = nullptr;
CCLOG("Call back handler container has been clear.");
}
else
{
_rootNode = _callbackHandlers.back();
CCLOG("after pop back _rootNode name = %s", _rootNode->getName().c_str());
}
}
/**/
return node;
}
Widget* widget = dynamic_cast<Widget*>(node);
if (widget)
{
std::string callbackName = widget->getCallbackName();
std::string callbackType = widget->getCallbackType();
bindCallback(callbackName, callbackType, widget, _rootNode);
}
bool CSLoader::bindCallback(const std::string &callbackName,
const std::string &callbackType,
cocos2d::ui::Widget *sender,
cocos2d::Node *handler)
{
auto callbackHandler = dynamic_cast<WidgetCallBackHandlerProtocol *>(handler);
if (callbackHandler) //The handler can handle callback
{
if (callbackType == "Click")
{
Widget::ccWidgetClickCallback callbackFunc = callbackHandler->onLocateClickCallback(callbackName);
if (callbackFunc)
{
sender->addClickEventListener(callbackFunc);
return true;
}
}
else if (callbackType == "Touch")
{
Widget::ccWidgetTouchCallback callbackFunc = callbackHandler->onLocateTouchCallback(callbackName);
if (callbackFunc)
{
sender->addTouchEventListener(callbackFunc);
return true;
}
}
else if (callbackType == "Event")
{
Widget::ccWidgetEventCallback callbackFunc = callbackHandler->onLocateEventCallback(callbackName);
if (callbackFunc)
{
sender->addCCSEventListener(callbackFunc);
return true;
}
}
}
CCLOG("callBackName %s cannot be found", callbackName.c_str());
return false;
}
As you can see, it’s just returning a nullptr, if it’s not implemented. None of the widgets is implementing it.
namespace cocostudio {
class CC_STUDIO_DLL WidgetCallBackHandlerProtocol
{
public:
WidgetCallBackHandlerProtocol() {};
virtual ~WidgetCallBackHandlerProtocol() {};
virtual cocos2d::ui::Widget::ccWidgetTouchCallback onLocateTouchCallback(const std::string &callBackName){ return nullptr; };
virtual cocos2d::ui::Widget::ccWidgetClickCallback onLocateClickCallback(const std::string &callBackName){ return nullptr; };
virtual cocos2d::ui::Widget::ccWidgetEventCallback onLocateEventCallback(const std::string &callBackName){ return nullptr; };
};
}
It suggests it does automatic binding, but it doesn’t. You would have to implement the lookup yourself like in the example:
Widget::ccWidgetTouchCallback CustomRootNode::onLocateTouchCallback(const string &callBackName)
{
if (callBackName == "onTouch")
{
return CC_CALLBACK_2(CustomRootNode::onTouch, this);
}
return nullptr;
}
This way you don’t need RTTI/reflection, because you delegate it in the code by hand. It’s just compile-time binding, not runtime-binding.
Thanks! I have to admit, that sometimes I realize that I posted a little BS and have to clean up afterwards