mirror of https://github.com/axmolengine/axmol.git
Merge pull request #4531 from dumganhar/extension-warning-fix
Some warning fixes in SocketIO, ContriolButton, js_manual_conversion.h/.cpp.
This commit is contained in:
commit
9c0d39c6f9
|
@ -688,7 +688,7 @@ void Sprite::updateQuadVertices()
|
|||
long offset = 0;
|
||||
setGLBufferData(&_quad, 4 * kQuadSize, 0);
|
||||
#else
|
||||
size_t offset = (size_t)&_quad;
|
||||
// size_t offset = (size_t)&_quad;
|
||||
#endif // EMSCRIPTEN
|
||||
|
||||
//TODO optimize the performance cache affineTransformation
|
||||
|
|
|
@ -69,7 +69,7 @@ Renderer::~Renderer()
|
|||
|
||||
void Renderer::initGLView()
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
#if 0//CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// listen the event when app go to background
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(Renderer::onBackToForeground),
|
||||
|
|
|
@ -625,7 +625,8 @@ static std::string visitVector(const ValueVector& v, int depth)
|
|||
return ret.str();
|
||||
}
|
||||
|
||||
static std::string visitMap(const ValueMap& v, int depth)
|
||||
template <class T>
|
||||
static std::string visitMap(const T& v, int depth)
|
||||
{
|
||||
std::stringstream ret;
|
||||
|
||||
|
@ -651,6 +652,7 @@ static std::string visit(const Value& v, int depth)
|
|||
|
||||
switch (v.getType())
|
||||
{
|
||||
case Value::Type::NONE:
|
||||
case Value::Type::BYTE:
|
||||
case Value::Type::INTEGER:
|
||||
case Value::Type::FLOAT:
|
||||
|
@ -666,8 +668,10 @@ static std::string visit(const Value& v, int depth)
|
|||
ret << visitMap(v.asValueMap(), depth);
|
||||
break;
|
||||
case Value::Type::INT_KEY_MAP:
|
||||
ret << visitMap(v.asIntKeyMap(), depth);
|
||||
break;
|
||||
default:
|
||||
CCASSERT(false, "Invalid type!");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,11 +34,11 @@ void ControlButtonLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, co
|
|||
|
||||
void ControlButtonLoader::onHandlePropTypeString(Node * pNode, Node * pParent, const char * pPropertyName, const char * pString, CCBReader * ccbReader) {
|
||||
if(strcmp(pPropertyName, PROPERTY_TITLE_NORMAL) == 0) {
|
||||
((ControlButton *)pNode)->setTitleForState(String::create(pString), Control::State::NORMAL);
|
||||
((ControlButton *)pNode)->setTitleForState(pString, Control::State::NORMAL);
|
||||
} else if(strcmp(pPropertyName, PROPERTY_TITLE_HIGHLIGHTED) == 0) {
|
||||
((ControlButton *)pNode)->setTitleForState(String::create(pString), Control::State::HIGH_LIGHTED);
|
||||
((ControlButton *)pNode)->setTitleForState(pString, Control::State::HIGH_LIGHTED);
|
||||
} else if(strcmp(pPropertyName, PROPERTY_TITLE_DISABLED) == 0) {
|
||||
((ControlButton *)pNode)->setTitleForState(String::create(pString), Control::State::DISABLED);
|
||||
((ControlButton *)pNode)->setTitleForState(pString, Control::State::DISABLED);
|
||||
} else {
|
||||
ControlLoader::onHandlePropTypeString(pNode, pParent, pPropertyName, pString, ccbReader);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ private:
|
|||
|
||||
WebSocket *_ws;
|
||||
|
||||
cocos2d::Dictionary* _clients;
|
||||
Map<std::string, SIOClient*> _clients;
|
||||
|
||||
public:
|
||||
SIOClientImpl(const std::string& host, int port);
|
||||
|
@ -95,9 +95,6 @@ SIOClientImpl::SIOClientImpl(const std::string& host, int port) :
|
|||
_host(host),
|
||||
_connected(false)
|
||||
{
|
||||
_clients = Dictionary::create();
|
||||
_clients->retain();
|
||||
|
||||
std::stringstream s;
|
||||
s << host << ":" << port;
|
||||
_uri = s.str();
|
||||
|
@ -107,9 +104,9 @@ SIOClientImpl::SIOClientImpl(const std::string& host, int port) :
|
|||
|
||||
SIOClientImpl::~SIOClientImpl()
|
||||
{
|
||||
if (_connected) disconnect();
|
||||
if (_connected)
|
||||
disconnect();
|
||||
|
||||
CC_SAFE_RELEASE(_clients);
|
||||
CC_SAFE_DELETE(_ws);
|
||||
}
|
||||
|
||||
|
@ -145,25 +142,20 @@ void SIOClientImpl::handshakeResponse(HttpClient *sender, HttpResponse *response
|
|||
log("%s completed", response->getHttpRequest()->getTag());
|
||||
}
|
||||
|
||||
int statusCode = response->getResponseCode();
|
||||
long statusCode = response->getResponseCode();
|
||||
char statusString[64] = {};
|
||||
sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag());
|
||||
log("response code: %d", statusCode);
|
||||
sprintf(statusString, "HTTP Status Code: %ld, tag = %s", statusCode, response->getHttpRequest()->getTag());
|
||||
log("response code: %ld", statusCode);
|
||||
|
||||
if (!response->isSucceed())
|
||||
{
|
||||
log("SIOClientImpl::handshake() failed");
|
||||
log("error buffer: %s", response->getErrorBuffer());
|
||||
|
||||
DictElement* el = NULL;
|
||||
|
||||
CCDICT_FOREACH(_clients, el) {
|
||||
|
||||
SIOClient* c = static_cast<SIOClient*>(el->getObject());
|
||||
|
||||
c->getDelegate()->onError(c, response->getErrorBuffer());
|
||||
|
||||
}
|
||||
for (auto iter = _clients.begin(); iter != _clients.end(); ++iter)
|
||||
{
|
||||
iter->second->getDelegate()->onError(iter->second, response->getErrorBuffer());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -258,7 +250,7 @@ void SIOClientImpl::disconnect()
|
|||
|
||||
_connected = false;
|
||||
|
||||
SocketIO::instance()->removeSocket(_uri);
|
||||
SocketIO::getInstance()->removeSocket(_uri);
|
||||
}
|
||||
|
||||
SIOClientImpl* SIOClientImpl::create(const std::string& host, int port)
|
||||
|
@ -275,12 +267,12 @@ SIOClientImpl* SIOClientImpl::create(const std::string& host, int port)
|
|||
|
||||
SIOClient* SIOClientImpl::getClient(const std::string& endpoint)
|
||||
{
|
||||
return static_cast<SIOClient*>(_clients->objectForKey(endpoint));
|
||||
return _clients.at(endpoint);
|
||||
}
|
||||
|
||||
void SIOClientImpl::addClient(const std::string& endpoint, SIOClient* client)
|
||||
{
|
||||
_clients->setObject(client, endpoint);
|
||||
_clients.insert(endpoint, client);
|
||||
}
|
||||
|
||||
void SIOClientImpl::connectToEndpoint(const std::string& endpoint)
|
||||
|
@ -294,13 +286,14 @@ void SIOClientImpl::connectToEndpoint(const std::string& endpoint)
|
|||
|
||||
void SIOClientImpl::disconnectFromEndpoint(const std::string& endpoint)
|
||||
{
|
||||
_clients->removeObjectForKey(endpoint);
|
||||
_clients.erase(endpoint);
|
||||
|
||||
if(_clients->count() == 0 || endpoint == "/")
|
||||
if (_clients.empty() || endpoint == "/")
|
||||
{
|
||||
log("SIOClientImpl::disconnectFromEndpoint out of endpoints, checking for disconnect");
|
||||
|
||||
if(_connected) this->disconnect();
|
||||
if(_connected)
|
||||
this->disconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -356,16 +349,12 @@ void SIOClientImpl::onOpen(WebSocket* ws)
|
|||
{
|
||||
_connected = true;
|
||||
|
||||
SocketIO::instance()->addSocket(_uri, this);
|
||||
SocketIO::getInstance()->addSocket(_uri, this);
|
||||
|
||||
DictElement* e = NULL;
|
||||
|
||||
CCDICT_FOREACH(_clients, e)
|
||||
for (auto iter = _clients.begin(); iter != _clients.end(); ++iter)
|
||||
{
|
||||
SIOClient *c = static_cast<SIOClient*>(e->getObject());
|
||||
|
||||
c->onOpen();
|
||||
}
|
||||
iter->second->onOpen();
|
||||
}
|
||||
|
||||
Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(SIOClientImpl::heartbeat), this, (_heartbeat * .9f), false);
|
||||
|
||||
|
@ -471,17 +460,13 @@ void SIOClientImpl::onMessage(WebSocket* ws, const WebSocket::Data& data)
|
|||
|
||||
void SIOClientImpl::onClose(WebSocket* ws)
|
||||
{
|
||||
if(_clients->count() > 0)
|
||||
if (!_clients.empty())
|
||||
{
|
||||
DictElement *e;
|
||||
|
||||
CCDICT_FOREACH(_clients, e)
|
||||
for (auto iter = _clients.begin(); iter != _clients.end(); ++iter)
|
||||
{
|
||||
SIOClient *c = static_cast<SIOClient *>(e->getObject());
|
||||
|
||||
c->receivedDisconnect();
|
||||
}
|
||||
}
|
||||
iter->second->receivedDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
this->release();
|
||||
}
|
||||
|
@ -596,23 +581,25 @@ SocketIO *SocketIO::_inst = nullptr;
|
|||
|
||||
SocketIO::SocketIO()
|
||||
{
|
||||
_sockets = Dictionary::create();
|
||||
_sockets->retain();
|
||||
}
|
||||
|
||||
SocketIO::~SocketIO(void)
|
||||
{
|
||||
CC_SAFE_RELEASE(_sockets);
|
||||
delete _inst;
|
||||
}
|
||||
|
||||
SocketIO* SocketIO::instance()
|
||||
SocketIO* SocketIO::getInstance()
|
||||
{
|
||||
if(!_inst) _inst = new SocketIO();
|
||||
if (nullptr == _inst)
|
||||
_inst = new SocketIO();
|
||||
|
||||
return _inst;
|
||||
}
|
||||
|
||||
void SocketIO::destroyInstance()
|
||||
{
|
||||
CC_SAFE_DELETE(_inst);
|
||||
}
|
||||
|
||||
SIOClient* SocketIO::connect(SocketIO::SIODelegate& delegate, const std::string& uri)
|
||||
{
|
||||
std::string host = uri;
|
||||
|
@ -654,7 +641,7 @@ SIOClient* SocketIO::connect(SocketIO::SIODelegate& delegate, const std::string&
|
|||
SIOClientImpl* socket = nullptr;
|
||||
SIOClient *c = nullptr;
|
||||
|
||||
socket = SocketIO::instance()->getSocket(s.str());
|
||||
socket = SocketIO::getInstance()->getSocket(s.str());
|
||||
|
||||
if(socket == nullptr)
|
||||
{
|
||||
|
@ -687,17 +674,17 @@ SIOClient* SocketIO::connect(SocketIO::SIODelegate& delegate, const std::string&
|
|||
|
||||
SIOClientImpl* SocketIO::getSocket(const std::string& uri)
|
||||
{
|
||||
return static_cast<SIOClientImpl*>(_sockets->objectForKey(uri));
|
||||
return _sockets.at(uri);
|
||||
}
|
||||
|
||||
void SocketIO::addSocket(const std::string& uri, SIOClientImpl* socket)
|
||||
{
|
||||
_sockets->setObject(socket, uri);
|
||||
_sockets.insert(uri, socket);
|
||||
}
|
||||
|
||||
void SocketIO::removeSocket(const std::string& uri)
|
||||
{
|
||||
_sockets->removeObjectForKey(uri);
|
||||
_sockets.erase(uri);
|
||||
}
|
||||
|
||||
}
|
|
@ -73,10 +73,8 @@ class SIOClient;
|
|||
class SocketIO
|
||||
{
|
||||
public:
|
||||
SocketIO();
|
||||
virtual ~SocketIO(void);
|
||||
|
||||
static SocketIO *instance();
|
||||
static SocketIO* getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
/**
|
||||
* @brief The delegate class to process socket.io events
|
||||
|
@ -101,16 +99,20 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
SocketIO();
|
||||
virtual ~SocketIO(void);
|
||||
|
||||
static SocketIO *_inst;
|
||||
|
||||
cocos2d::Dictionary* _sockets;
|
||||
cocos2d::Map<std::string, SIOClientImpl*> _sockets;
|
||||
|
||||
SIOClientImpl* getSocket(const std::string& uri);
|
||||
void addSocket(const std::string& uri, SIOClientImpl* socket);
|
||||
void removeSocket(const std::string& uri);
|
||||
|
||||
friend class SIOClientImpl;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(SocketIO)
|
||||
};
|
||||
|
||||
//c++11 style callbacks entities will be created using CC_CALLBACK (which uses std::bind)
|
||||
|
|
|
@ -737,7 +737,7 @@ JSBool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, Point **points, int *
|
|||
}
|
||||
|
||||
|
||||
JSBool jsval_to_ccarray(JSContext* cx, jsval v, Array** ret)
|
||||
JSBool jsval_to_ccarray(JSContext* cx, jsval v, __Array** ret)
|
||||
{
|
||||
JSObject *jsobj;
|
||||
JSBool ok = v.isObject() && JS_ValueToObject( cx, v, &jsobj );
|
||||
|
@ -746,7 +746,7 @@ JSBool jsval_to_ccarray(JSContext* cx, jsval v, Array** ret)
|
|||
|
||||
uint32_t len = 0;
|
||||
JS_GetArrayLength(cx, jsobj, &len);
|
||||
Array* arr = Array::createWithCapacity(len);
|
||||
__Array* arr = __Array::createWithCapacity(len);
|
||||
for (uint32_t i=0; i < len; i++) {
|
||||
jsval value;
|
||||
if (JS_GetElement(cx, jsobj, i, &value)) {
|
||||
|
@ -764,7 +764,7 @@ JSBool jsval_to_ccarray(JSContext* cx, jsval v, Array** ret)
|
|||
}
|
||||
else if (!JS_IsArrayObject(cx, tmp)){
|
||||
// It's a normal js object.
|
||||
Dictionary* dictVal = NULL;
|
||||
__Dictionary* dictVal = NULL;
|
||||
JSBool ok = jsval_to_ccdictionary(cx, value, &dictVal);
|
||||
if (ok) {
|
||||
arr->addObject(dictVal);
|
||||
|
@ -772,7 +772,7 @@ JSBool jsval_to_ccarray(JSContext* cx, jsval v, Array** ret)
|
|||
}
|
||||
else {
|
||||
// It's a js array object.
|
||||
Array* arrVal = NULL;
|
||||
__Array* arrVal = NULL;
|
||||
JSBool ok = jsval_to_ccarray(cx, value, &arrVal);
|
||||
if (ok) {
|
||||
arr->addObject(arrVal);
|
||||
|
|
|
@ -42,10 +42,10 @@ JSBool jsval_to_cccolor4b(JSContext *cx, jsval v, cocos2d::Color4B* ret);
|
|||
JSBool jsval_to_cccolor4f(JSContext *cx, jsval v, cocos2d::Color4F* ret);
|
||||
JSBool jsval_to_cccolor3b(JSContext *cx, jsval v, cocos2d::Color3B* ret);
|
||||
JSBool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, cocos2d::Point **points, int *numPoints);
|
||||
JSBool jsval_to_ccarray(JSContext* cx, jsval v, cocos2d::Array** ret);
|
||||
JSBool jsval_to_ccdictionary(JSContext* cx, jsval v, cocos2d::Dictionary** ret);
|
||||
JSBool jsval_to_ccarray(JSContext* cx, jsval v, cocos2d::__Array** ret);
|
||||
JSBool jsval_to_ccdictionary(JSContext* cx, jsval v, cocos2d::__Dictionary** ret);
|
||||
JSBool jsval_to_ccacceleration(JSContext* cx,jsval v, cocos2d::Acceleration* ret);
|
||||
JSBool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, cocos2d::Array** ret);
|
||||
JSBool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, cocos2d::__Array** ret);
|
||||
|
||||
// forward declaration
|
||||
js_proxy_t* jsb_get_js_proxy(JSObject* jsObj);
|
||||
|
|
|
@ -45,15 +45,10 @@ ControlButton::ControlButton()
|
|||
: _isPushed(false)
|
||||
, _parentInited(false)
|
||||
, _doesAdjustBackgroundImage(false)
|
||||
, _currentTitle(NULL)
|
||||
, _currentTitleColor(Color3B::WHITE)
|
||||
, _titleLabel(NULL)
|
||||
, _backgroundSprite(NULL)
|
||||
, _titleLabel(nullptr)
|
||||
, _backgroundSprite(nullptr)
|
||||
, _zoomOnTouchDown(false)
|
||||
, _titleDispatchTable(NULL)
|
||||
, _titleColorDispatchTable(NULL)
|
||||
, _titleLabelDispatchTable(NULL)
|
||||
, _backgroundSpriteDispatchTable(NULL)
|
||||
, _marginV(ControlButtonMarginTB)
|
||||
, _marginH(ControlButtonMarginLR)
|
||||
{
|
||||
|
@ -62,12 +57,7 @@ ControlButton::ControlButton()
|
|||
|
||||
ControlButton::~ControlButton()
|
||||
{
|
||||
CC_SAFE_RELEASE(_currentTitle);
|
||||
CC_SAFE_RELEASE(_titleLabel);
|
||||
CC_SAFE_RELEASE(_backgroundSpriteDispatchTable);
|
||||
CC_SAFE_RELEASE(_titleLabelDispatchTable);
|
||||
CC_SAFE_RELEASE(_titleColorDispatchTable);
|
||||
CC_SAFE_RELEASE(_titleDispatchTable);
|
||||
CC_SAFE_RELEASE(_backgroundSprite);
|
||||
}
|
||||
|
||||
|
@ -82,25 +72,17 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, Scale9Sprite* b
|
|||
{
|
||||
if (Control::init())
|
||||
{
|
||||
CCASSERT(node != NULL, "Label must not be nil.");
|
||||
CCASSERT(node != nullptr, "Label must not be nil.");
|
||||
LabelProtocol* label = dynamic_cast<LabelProtocol*>(node);
|
||||
RGBAProtocol* rgbaLabel = dynamic_cast<RGBAProtocol*>(node);
|
||||
CCASSERT(backgroundSprite != NULL, "Background sprite must not be nil.");
|
||||
CCASSERT(label != NULL || rgbaLabel!=NULL || backgroundSprite != NULL, "");
|
||||
CCASSERT(backgroundSprite != nullptr, "Background sprite must not be nil.");
|
||||
CCASSERT(label != nullptr || rgbaLabel!=nullptr || backgroundSprite != nullptr, "");
|
||||
|
||||
_parentInited = true;
|
||||
|
||||
// Initialize the button state tables
|
||||
this->setTitleDispatchTable(Dictionary::create());
|
||||
this->setTitleColorDispatchTable(Dictionary::create());
|
||||
this->setTitleLabelDispatchTable(Dictionary::create());
|
||||
this->setBackgroundSpriteDispatchTable(Dictionary::create());
|
||||
|
||||
_isPushed = false;
|
||||
_zoomOnTouchDown = true;
|
||||
|
||||
_currentTitle=NULL;
|
||||
|
||||
// Adjust the background image by default
|
||||
setAdjustBackgroundImage(true);
|
||||
setPreferredSize(Size::ZERO);
|
||||
|
@ -122,9 +104,7 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, Scale9Sprite* b
|
|||
|
||||
// Initialize the dispatch table
|
||||
|
||||
String* tempString = String::create(label->getString());
|
||||
//tempString->autorelease();
|
||||
setTitleForState(tempString, Control::State::NORMAL);
|
||||
setTitleForState(label->getString(), Control::State::NORMAL);
|
||||
setTitleColorForState(rgbaLabel->getColor(), Control::State::NORMAL);
|
||||
setTitleLabelForState(node, Control::State::NORMAL);
|
||||
setBackgroundSpriteForState(backgroundSprite, Control::State::NORMAL);
|
||||
|
@ -246,11 +226,10 @@ void ControlButton::setPreferredSize(const Size& size)
|
|||
else
|
||||
{
|
||||
_doesAdjustBackgroundImage = false;
|
||||
DictElement * item = NULL;
|
||||
CCDICT_FOREACH(_backgroundSpriteDispatchTable, item)
|
||||
|
||||
for (auto iter = _backgroundSpriteDispatchTable.begin(); iter != _backgroundSpriteDispatchTable.end(); ++iter)
|
||||
{
|
||||
Scale9Sprite* sprite = static_cast<Scale9Sprite*>(item->getObject());
|
||||
sprite->setPreferredSize(size);
|
||||
iter->second->setPreferredSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,33 +261,32 @@ const Point& ControlButton::getLabelAnchorPoint() const
|
|||
void ControlButton::setLabelAnchorPoint(const Point& labelAnchorPoint)
|
||||
{
|
||||
this->_labelAnchorPoint = labelAnchorPoint;
|
||||
if (_titleLabel != NULL)
|
||||
if (_titleLabel != nullptr)
|
||||
{
|
||||
this->_titleLabel->setAnchorPoint(labelAnchorPoint);
|
||||
}
|
||||
}
|
||||
|
||||
String* ControlButton::getTitleForState(State state)
|
||||
std::string ControlButton::getTitleForState(State state)
|
||||
{
|
||||
if (_titleDispatchTable != NULL)
|
||||
auto iter = _titleDispatchTable.find((int)state);
|
||||
if (iter != _titleDispatchTable.end())
|
||||
{
|
||||
String* title = static_cast<String*>(_titleDispatchTable->objectForKey((int)state));
|
||||
if (title)
|
||||
{
|
||||
return title;
|
||||
}
|
||||
return static_cast<String*>(_titleDispatchTable->objectForKey((int)Control::State::NORMAL));
|
||||
return iter->second;
|
||||
}
|
||||
return String::create("");
|
||||
|
||||
iter = _titleDispatchTable.find((int)Control::State::NORMAL);
|
||||
|
||||
return iter != _titleDispatchTable.end() ? iter->second : "";
|
||||
}
|
||||
|
||||
void ControlButton::setTitleForState(String* title, State state)
|
||||
void ControlButton::setTitleForState(const std::string& title, State state)
|
||||
{
|
||||
_titleDispatchTable->removeObjectForKey((int)state);
|
||||
_titleDispatchTable.erase((int)state);
|
||||
|
||||
if (title)
|
||||
if (!title.empty())
|
||||
{
|
||||
_titleDispatchTable->setObject(title, (int)state);
|
||||
_titleDispatchTable[(int)state] = title;
|
||||
}
|
||||
|
||||
// If the current state if equal to the given state we update the layout
|
||||
|
@ -322,33 +300,28 @@ void ControlButton::setTitleForState(String* title, State state)
|
|||
Color3B ControlButton::getTitleColorForState(State state) const
|
||||
{
|
||||
Color3B returnColor = Color3B::WHITE;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(NULL == _titleColorDispatchTable);
|
||||
Color3bObject* colorObject=(Color3bObject*)_titleColorDispatchTable->objectForKey((int)state);
|
||||
if (colorObject)
|
||||
{
|
||||
returnColor = colorObject->value;
|
||||
break;
|
||||
}
|
||||
|
||||
colorObject = (Color3bObject*)_titleColorDispatchTable->objectForKey((int)Control::State::NORMAL);
|
||||
if (colorObject)
|
||||
auto iter = _titleColorDispatchTable.find((int)state);
|
||||
if (iter != _titleColorDispatchTable.end())
|
||||
{
|
||||
returnColor = iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter = _titleColorDispatchTable.find((int)Control::State::NORMAL);
|
||||
if (iter != _titleColorDispatchTable.end())
|
||||
{
|
||||
returnColor = colorObject->value;
|
||||
returnColor = iter->second;
|
||||
}
|
||||
} while (0);
|
||||
}
|
||||
|
||||
return returnColor;
|
||||
}
|
||||
|
||||
void ControlButton::setTitleColorForState(const Color3B& color, State state)
|
||||
{
|
||||
//Color3B* colorValue=&color;
|
||||
_titleColorDispatchTable->removeObjectForKey((int)state);
|
||||
Color3bObject* pColor3bObject = new Color3bObject(color);
|
||||
pColor3bObject->autorelease();
|
||||
_titleColorDispatchTable->setObject(pColor3bObject, (int)state);
|
||||
_titleColorDispatchTable.erase((int)state);
|
||||
_titleColorDispatchTable[(int)state] = color;
|
||||
|
||||
// If the current state if equal to the given state we update the layout
|
||||
if (getState() == state)
|
||||
|
@ -359,24 +332,24 @@ void ControlButton::setTitleColorForState(const Color3B& color, State state)
|
|||
|
||||
Node* ControlButton::getTitleLabelForState(State state)
|
||||
{
|
||||
Node* titleLabel = static_cast<Node*>(_titleLabelDispatchTable->objectForKey((int)state));
|
||||
Node* titleLabel = _titleLabelDispatchTable.at((int)state);
|
||||
if (titleLabel)
|
||||
{
|
||||
return titleLabel;
|
||||
}
|
||||
return (Node*)_titleLabelDispatchTable->objectForKey((int)Control::State::NORMAL);
|
||||
return _titleLabelDispatchTable.at((int)Control::State::NORMAL);
|
||||
}
|
||||
|
||||
void ControlButton::setTitleLabelForState(Node* titleLabel, State state)
|
||||
{
|
||||
Node* previousLabel = static_cast<Node*>(_titleLabelDispatchTable->objectForKey((int)state));
|
||||
Node* previousLabel = _titleLabelDispatchTable.at((int)state);
|
||||
if (previousLabel)
|
||||
{
|
||||
removeChild(previousLabel, true);
|
||||
_titleLabelDispatchTable->removeObjectForKey((int)state);
|
||||
_titleLabelDispatchTable.erase((int)state);
|
||||
}
|
||||
|
||||
_titleLabelDispatchTable->setObject(titleLabel, (int)state);
|
||||
_titleLabelDispatchTable.insert((int)state, titleLabel);
|
||||
titleLabel->setVisible(false);
|
||||
titleLabel->setAnchorPoint(Point(0.5f, 0.5f));
|
||||
addChild(titleLabel, 1);
|
||||
|
@ -390,12 +363,8 @@ void ControlButton::setTitleLabelForState(Node* titleLabel, State state)
|
|||
|
||||
void ControlButton::setTitleTTFForState(const std::string& fntFile, State state)
|
||||
{
|
||||
String * title = this->getTitleForState(state);
|
||||
if (!title)
|
||||
{
|
||||
title = String::create("");
|
||||
}
|
||||
this->setTitleLabelForState(LabelTTF::create(title->getCString(), fntFile, 12), state);
|
||||
std::string title = this->getTitleForState(state);
|
||||
this->setTitleLabelForState(LabelTTF::create(title, fntFile, 12), state);
|
||||
}
|
||||
|
||||
const std::string& ControlButton::getTitleTTFForState(State state)
|
||||
|
@ -440,12 +409,8 @@ float ControlButton::getTitleTTFSizeForState(State state)
|
|||
|
||||
void ControlButton::setTitleBMFontForState(const std::string& fntFile, State state)
|
||||
{
|
||||
String * title = this->getTitleForState(state);
|
||||
if (!title)
|
||||
{
|
||||
title = String::create("");
|
||||
}
|
||||
this->setTitleLabelForState(LabelBMFont::create(title->getCString(), fntFile), state);
|
||||
std::string title = this->getTitleForState(state);
|
||||
this->setTitleLabelForState(LabelBMFont::create(title, fntFile), state);
|
||||
}
|
||||
|
||||
const std::string& ControlButton::getTitleBMFontForState(State state)
|
||||
|
@ -464,12 +429,12 @@ const std::string& ControlButton::getTitleBMFontForState(State state)
|
|||
|
||||
Scale9Sprite* ControlButton::getBackgroundSpriteForState(State state)
|
||||
{
|
||||
Scale9Sprite* backgroundSprite = (Scale9Sprite*)_backgroundSpriteDispatchTable->objectForKey((int)state);
|
||||
auto backgroundSprite = _backgroundSpriteDispatchTable.at((int)state);
|
||||
if (backgroundSprite)
|
||||
{
|
||||
return backgroundSprite;
|
||||
}
|
||||
return (Scale9Sprite*)_backgroundSpriteDispatchTable->objectForKey((int)Control::State::NORMAL);
|
||||
return _backgroundSpriteDispatchTable.at((int)Control::State::NORMAL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -477,14 +442,14 @@ void ControlButton::setBackgroundSpriteForState(Scale9Sprite* sprite, State stat
|
|||
{
|
||||
Size oldPreferredSize = _preferredSize;
|
||||
|
||||
Scale9Sprite* previousBackgroundSprite = (Scale9Sprite*)_backgroundSpriteDispatchTable->objectForKey((int)state);
|
||||
auto previousBackgroundSprite = _backgroundSpriteDispatchTable.at((int)state);
|
||||
if (previousBackgroundSprite)
|
||||
{
|
||||
removeChild(previousBackgroundSprite, true);
|
||||
_backgroundSpriteDispatchTable->removeObjectForKey((int)state);
|
||||
_backgroundSpriteDispatchTable.erase((int)state);
|
||||
}
|
||||
|
||||
_backgroundSpriteDispatchTable->setObject(sprite, (int)state);
|
||||
_backgroundSpriteDispatchTable.insert((int)state, sprite);
|
||||
sprite->setVisible(false);
|
||||
sprite->setAnchorPoint(Point(0.5f, 0.5f));
|
||||
addChild(sprite);
|
||||
|
@ -520,7 +485,7 @@ void ControlButton::needsLayout()
|
|||
return;
|
||||
}
|
||||
// Hide the background and the label
|
||||
if (_titleLabel != NULL) {
|
||||
if (_titleLabel != nullptr) {
|
||||
_titleLabel->setVisible(false);
|
||||
}
|
||||
if (_backgroundSprite) {
|
||||
|
@ -530,18 +495,16 @@ void ControlButton::needsLayout()
|
|||
this->setLabelAnchorPoint(this->_labelAnchorPoint);
|
||||
|
||||
// Update the label to match with the current state
|
||||
CC_SAFE_RELEASE(_currentTitle);
|
||||
_currentTitle = getTitleForState(_state);
|
||||
CC_SAFE_RETAIN(_currentTitle);
|
||||
|
||||
_currentTitleColor = getTitleColorForState(_state);
|
||||
|
||||
this->setTitleLabel(getTitleLabelForState(_state));
|
||||
|
||||
LabelProtocol* label = dynamic_cast<LabelProtocol*>(_titleLabel);
|
||||
if (label && _currentTitle)
|
||||
if (label && !_currentTitle.empty())
|
||||
{
|
||||
label->setString(_currentTitle->getCString());
|
||||
label->setString(_currentTitle);
|
||||
}
|
||||
|
||||
RGBAProtocol* rgbaLabel = dynamic_cast<RGBAProtocol*>(_titleLabel);
|
||||
|
@ -549,21 +512,21 @@ void ControlButton::needsLayout()
|
|||
{
|
||||
rgbaLabel->setColor(_currentTitleColor);
|
||||
}
|
||||
if (_titleLabel != NULL)
|
||||
if (_titleLabel != nullptr)
|
||||
{
|
||||
_titleLabel->setPosition(Point (getContentSize().width / 2, getContentSize().height / 2));
|
||||
}
|
||||
|
||||
// Update the background sprite
|
||||
this->setBackgroundSprite(this->getBackgroundSpriteForState(_state));
|
||||
if (_backgroundSprite != NULL)
|
||||
if (_backgroundSprite != nullptr)
|
||||
{
|
||||
_backgroundSprite->setPosition(Point (getContentSize().width / 2, getContentSize().height / 2));
|
||||
}
|
||||
|
||||
// Get the title label size
|
||||
Size titleLabelSize;
|
||||
if (_titleLabel != NULL)
|
||||
if (_titleLabel != nullptr)
|
||||
{
|
||||
titleLabelSize = _titleLabel->getBoundingBox().size;
|
||||
}
|
||||
|
@ -572,7 +535,7 @@ void ControlButton::needsLayout()
|
|||
if (_doesAdjustBackgroundImage)
|
||||
{
|
||||
// Add the margins
|
||||
if (_backgroundSprite != NULL)
|
||||
if (_backgroundSprite != nullptr)
|
||||
{
|
||||
_backgroundSprite->setContentSize(Size(titleLabelSize.width + _marginH * 2, titleLabelSize.height + _marginV * 2));
|
||||
}
|
||||
|
@ -580,7 +543,7 @@ void ControlButton::needsLayout()
|
|||
else
|
||||
{
|
||||
//TODO: should this also have margins if one of the preferred sizes is relaxed?
|
||||
if (_backgroundSprite != NULL)
|
||||
if (_backgroundSprite != nullptr)
|
||||
{
|
||||
Size preferredSize = _backgroundSprite->getPreferredSize();
|
||||
if (preferredSize.width <= 0)
|
||||
|
@ -598,12 +561,12 @@ void ControlButton::needsLayout()
|
|||
|
||||
// Set the content size
|
||||
Rect rectTitle;
|
||||
if (_titleLabel != NULL)
|
||||
if (_titleLabel != nullptr)
|
||||
{
|
||||
rectTitle = _titleLabel->getBoundingBox();
|
||||
}
|
||||
Rect rectBackground;
|
||||
if (_backgroundSprite != NULL)
|
||||
if (_backgroundSprite != nullptr)
|
||||
{
|
||||
rectBackground = _backgroundSprite->getBoundingBox();
|
||||
}
|
||||
|
@ -611,14 +574,14 @@ void ControlButton::needsLayout()
|
|||
Rect maxRect = ControlUtils::RectUnion(rectTitle, rectBackground);
|
||||
setContentSize(Size(maxRect.size.width, maxRect.size.height));
|
||||
|
||||
if (_titleLabel != NULL)
|
||||
if (_titleLabel != nullptr)
|
||||
{
|
||||
_titleLabel->setPosition(Point(getContentSize().width/2, getContentSize().height/2));
|
||||
// Make visible the background and the label
|
||||
_titleLabel->setVisible(true);
|
||||
}
|
||||
|
||||
if (_backgroundSprite != NULL)
|
||||
if (_backgroundSprite != nullptr)
|
||||
{
|
||||
_backgroundSprite->setPosition(Point(getContentSize().width/2, getContentSize().height/2));
|
||||
_backgroundSprite->setVisible(true);
|
||||
|
@ -634,7 +597,7 @@ bool ControlButton::onTouchBegan(Touch *pTouch, Event *pEvent)
|
|||
return false;
|
||||
}
|
||||
|
||||
for (Node *c = this->_parent; c != NULL; c = c->getParent())
|
||||
for (Node *c = this->_parent; c != nullptr; c = c->getParent())
|
||||
{
|
||||
if (c->isVisible() == false)
|
||||
{
|
||||
|
@ -712,11 +675,10 @@ void ControlButton::setOpacity(GLubyte opacity)
|
|||
// pNode->setOpacity(opacity);
|
||||
// }
|
||||
// }
|
||||
DictElement * item = NULL;
|
||||
CCDICT_FOREACH(_backgroundSpriteDispatchTable, item)
|
||||
|
||||
for (auto iter = _backgroundSpriteDispatchTable.begin(); iter != _backgroundSpriteDispatchTable.end(); ++iter)
|
||||
{
|
||||
Scale9Sprite* sprite = static_cast<Scale9Sprite*>(item->getObject());
|
||||
sprite->setOpacity(opacity);
|
||||
iter->second->setOpacity(opacity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -729,11 +691,9 @@ void ControlButton::setColor(const Color3B & color)
|
|||
{
|
||||
Control::setColor(color);
|
||||
|
||||
DictElement * item = NULL;
|
||||
CCDICT_FOREACH(_backgroundSpriteDispatchTable, item)
|
||||
for (auto iter = _backgroundSpriteDispatchTable.begin(); iter != _backgroundSpriteDispatchTable.end(); ++iter)
|
||||
{
|
||||
Scale9Sprite* sprite = static_cast<Scale9Sprite*>(item->getObject());
|
||||
sprite->setColor(color);
|
||||
iter->second->setColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -758,7 +718,7 @@ ControlButton* ControlButton::create()
|
|||
return pControlButton;
|
||||
}
|
||||
CC_SAFE_DELETE(pControlButton);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
*
|
||||
* @return The title for the specified state.
|
||||
*/
|
||||
virtual String* getTitleForState(State state);
|
||||
virtual std::string getTitleForState(State state);
|
||||
|
||||
/**
|
||||
* Sets the title string to use for the specified state.
|
||||
|
@ -85,7 +85,7 @@ public:
|
|||
* @param state The state that uses the specified title. The values are described
|
||||
* in "CCControlState".
|
||||
*/
|
||||
virtual void setTitleForState(String* title, State state);
|
||||
virtual void setTitleForState(const std::string& title, State state);
|
||||
|
||||
/**
|
||||
* Returns the title color used for a state.
|
||||
|
@ -186,6 +186,9 @@ public:
|
|||
virtual void setColor(const Color3B&) override;
|
||||
|
||||
|
||||
const std::string& getCurrentTitle() const { return _currentTitle; };
|
||||
std::string getCurrentTitle() { return _currentTitle; };
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @js ctor
|
||||
|
@ -207,7 +210,7 @@ protected:
|
|||
bool _doesAdjustBackgroundImage;
|
||||
|
||||
/** The current title that is displayed on the button. */
|
||||
CC_SYNTHESIZE_READONLY(String*, _currentTitle, CurrentTitle);
|
||||
std::string _currentTitle;
|
||||
|
||||
/** The current color used to display the title. */
|
||||
CC_SYNTHESIZE_READONLY_PASS_BY_REF(Color3B, _currentTitleColor, CurrentTitleColor);
|
||||
|
@ -226,14 +229,11 @@ protected:
|
|||
|
||||
CC_PROPERTY_PASS_BY_REF(Point, _labelAnchorPoint, LabelAnchorPoint);
|
||||
|
||||
// <ControlState, String*>
|
||||
CC_SYNTHESIZE_RETAIN(Dictionary*, _titleDispatchTable, TitleDispatchTable);
|
||||
// <ControlState, Color3bObject*>
|
||||
CC_SYNTHESIZE_RETAIN(Dictionary*, _titleColorDispatchTable, TitleColorDispatchTable);
|
||||
// <ControlState, Node*>
|
||||
CC_SYNTHESIZE_RETAIN(Dictionary*, _titleLabelDispatchTable, TitleLabelDispatchTable);
|
||||
// <ControlState, Scale9Sprite*>
|
||||
CC_SYNTHESIZE_RETAIN(Dictionary*, _backgroundSpriteDispatchTable, BackgroundSpriteDispatchTable);
|
||||
std::unordered_map<int, std::string> _titleDispatchTable;
|
||||
std::unordered_map<int, Color3B> _titleColorDispatchTable;
|
||||
|
||||
Map<int, Node*> _titleLabelDispatchTable;
|
||||
Map<int, Scale9Sprite*> _backgroundSpriteDispatchTable;
|
||||
|
||||
/* Define the button margin for Top/Bottom edge */
|
||||
CC_SYNTHESIZE_READONLY(int, _marginV, VerticalMargin);
|
||||
|
|
|
@ -32,26 +32,23 @@ bool ControlButtonTest_HelloVariableSize::init()
|
|||
auto screenSize = Director::getInstance()->getWinSize();
|
||||
|
||||
// Defines an array of title to create buttons dynamically
|
||||
auto stringArray = Array::create(
|
||||
ccs("Hello"),
|
||||
ccs("Variable"),
|
||||
ccs("Size"),
|
||||
ccs("!"),
|
||||
NULL);
|
||||
std::vector<std::string> vec;
|
||||
vec.push_back("Hello");
|
||||
vec.push_back("Variable");
|
||||
vec.push_back("Size");
|
||||
vec.push_back("!");
|
||||
|
||||
auto layer = Node::create();
|
||||
addChild(layer, 1);
|
||||
|
||||
double total_width = 0, height = 0;
|
||||
|
||||
// For each title in the array
|
||||
Object* pObj = NULL;
|
||||
int i = 0;
|
||||
CCARRAY_FOREACH(stringArray, pObj)
|
||||
|
||||
for (auto& title : vec)
|
||||
{
|
||||
auto title = static_cast<String*>(pObj);
|
||||
// Creates a button with this string as title
|
||||
ControlButton *button = standardButtonWithTitle(title->getCString());
|
||||
ControlButton *button = standardButtonWithTitle(title.c_str());
|
||||
if (i == 0)
|
||||
{
|
||||
button->setOpacity(50);
|
||||
|
|
|
@ -1369,12 +1369,11 @@ std::string BMFontOneAtlas::subtitle()
|
|||
/// BMFontUnicode
|
||||
BMFontUnicode::BMFontUnicode()
|
||||
{
|
||||
auto strings = Dictionary::createWithContentsOfFile("fonts/strings.xml");
|
||||
|
||||
const char *chinese = static_cast<String*>(strings->objectForKey("chinese1"))->_string.c_str();
|
||||
const char *japanese = static_cast<String*>(strings->objectForKey("japanese"))->_string.c_str();
|
||||
const char *russian = static_cast<String*>(strings->objectForKey("russian"))->_string.c_str();
|
||||
const char *spanish = static_cast<String*>(strings->objectForKey("spanish"))->_string.c_str();
|
||||
auto strings = FileUtils::getInstance()->getValueMapFromFile("fonts/strings.xml");
|
||||
std::string chinese = strings["chinese1"].asString();
|
||||
std::string russian = strings["russian"].asString();
|
||||
std::string spanish = strings["spanish"].asString();
|
||||
std::string japanese = strings["japanese"].asString();
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
|
|
|
@ -832,12 +832,11 @@ void LabelFNTMultiLineAlignment::snapArrowsToEdge()
|
|||
/// BMFontUnicodeNew
|
||||
LabelFNTUNICODELanguages::LabelFNTUNICODELanguages()
|
||||
{
|
||||
auto strings = Dictionary::createWithContentsOfFile("fonts/strings.xml");
|
||||
|
||||
const char *chinese = static_cast<String*>(strings->objectForKey("chinese1"))->_string.c_str();
|
||||
const char *japanese = static_cast<String*>(strings->objectForKey("japanese"))->_string.c_str();
|
||||
const char *russian = static_cast<String*>(strings->objectForKey("russian"))->_string.c_str();
|
||||
const char *spanish = static_cast<String*>(strings->objectForKey("spanish"))->_string.c_str();
|
||||
auto strings = FileUtils::getInstance()->getValueMapFromFile("fonts/strings.xml");
|
||||
std::string chinese = strings["chinese1"].asString();
|
||||
std::string russian = strings["russian"].asString();
|
||||
std::string spanish = strings["spanish"].asString();
|
||||
std::string japanese = strings["japanese"].asString();
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
|
@ -1035,12 +1034,12 @@ std::string LabelTTFDynamicAlignment::subtitle()
|
|||
//
|
||||
LabelTTFUnicodeNew::LabelTTFUnicodeNew()
|
||||
{
|
||||
auto strings = Dictionary::createWithContentsOfFile("fonts/strings.xml");
|
||||
const char *chinese = static_cast<String*>(strings->objectForKey("chinese1"))->_string.c_str();
|
||||
auto strings = FileUtils::getInstance()->getValueMapFromFile("fonts/strings.xml");
|
||||
std::string chinese = strings["chinese1"].asString();
|
||||
|
||||
//const char *russian = static_cast<String*>(strings->objectForKey("russian"))->_string.c_str();
|
||||
//const char *spanish = static_cast<String*>(strings->objectForKey("spanish"))->_string.c_str();
|
||||
//const char *japanese = static_cast<String*>(strings->objectForKey("japanese"))->_string.c_str();
|
||||
// std::string russian = strings["russian"].asString();
|
||||
// std::string spanish = strings["spanish"].asString();
|
||||
// std::string japanese = strings["japanese"].asString();
|
||||
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
||||
|
@ -1061,7 +1060,7 @@ LabelTTFUnicodeNew::LabelTTFUnicodeNew()
|
|||
addChild(label2);
|
||||
|
||||
// chinese
|
||||
auto label3 = Label::createWithTTF(chinese, "fonts/wt021.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::CUSTOM, chinese);
|
||||
auto label3 = Label::createWithTTF(chinese, "fonts/wt021.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::CUSTOM, chinese.c_str());
|
||||
label3->setPosition( Point(size.width/2, vSize - (vStep * 6.5)) );
|
||||
label3->setAnchorPoint(Point(0.5, 0.5));
|
||||
addChild(label3);
|
||||
|
|
|
@ -71,7 +71,7 @@ bool MutiTouchTestLayer::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
static Dictionary s_dic;
|
||||
static Map<int, TouchPoint*> s_map;
|
||||
|
||||
void MutiTouchTestLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ void MutiTouchTestLayer::onTouchesBegan(const std::vector<Touch*>& touches, Even
|
|||
touchPoint->setTouchColor(*s_TouchColors[touch->getID()]);
|
||||
|
||||
addChild(touchPoint);
|
||||
s_dic.setObject(touchPoint, touch->getID());
|
||||
s_map.insert(touch->getID(), touchPoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ void MutiTouchTestLayer::onTouchesMoved(const std::vector<Touch*>& touches, Even
|
|||
for( auto &item: touches)
|
||||
{
|
||||
auto touch = item;
|
||||
auto pTP = static_cast<TouchPoint*>(s_dic.objectForKey(touch->getID()));
|
||||
auto pTP = s_map.at(touch->getID());
|
||||
auto location = touch->getLocation();
|
||||
pTP->setTouchPos(location);
|
||||
}
|
||||
|
@ -105,9 +105,9 @@ void MutiTouchTestLayer::onTouchesEnded(const std::vector<Touch*>& touches, Even
|
|||
for ( auto &item: touches )
|
||||
{
|
||||
auto touch = item;
|
||||
auto pTP = static_cast<TouchPoint*>(s_dic.objectForKey(touch->getID()));
|
||||
auto pTP = s_map.at(touch->getID());
|
||||
removeChild(pTP, true);
|
||||
s_dic.removeObjectForKey(touch->getID());
|
||||
s_map.erase(touch->getID());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ const char* IterateSpriteSheet::testName()
|
|||
void IterateSpriteSheetForLoop::update(float dt)
|
||||
{
|
||||
// iterate using fast enumeration protocol
|
||||
auto children = batchNode->getChildren();
|
||||
auto& children = batchNode->getChildren();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
|
||||
|
@ -320,7 +320,7 @@ const char* IterateSpriteSheetForLoop::testName()
|
|||
void IterateSpriteSheetCArray::update(float dt)
|
||||
{
|
||||
// iterate using fast enumeration protocol
|
||||
auto children = batchNode->getChildren();
|
||||
auto& children = batchNode->getChildren();
|
||||
// Object* object = NULL;
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
|
@ -358,7 +358,7 @@ const char* IterateSpriteSheetCArray::testName()
|
|||
void IterateSpriteSheetIterator::update(float dt)
|
||||
{
|
||||
// iterate using fast enumeration protocol
|
||||
auto children = batchNode->getChildren();
|
||||
auto& children = batchNode->getChildren();
|
||||
|
||||
CC_PROFILER_START(this->profilerName());
|
||||
|
||||
|
|
|
@ -594,22 +594,20 @@ void SchedulerSchedulesAndRemove::scheduleAndUnschedule(float dt)
|
|||
// TestNode
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void TestNode::initWithString(String* pStr, int priority)
|
||||
void TestNode::initWithString(const std::string& str, int priority)
|
||||
{
|
||||
_pstring = pStr;
|
||||
_pstring->retain();
|
||||
_string = str;
|
||||
scheduleUpdateWithPriority(priority);
|
||||
}
|
||||
|
||||
TestNode::~TestNode()
|
||||
{
|
||||
_pstring->release();
|
||||
}
|
||||
|
||||
void TestNode::update(float dt)
|
||||
{
|
||||
CC_UNUSED_PARAM(dt);
|
||||
log("%s", _pstring->getCString());
|
||||
log("%s", _string.c_str());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -622,44 +620,32 @@ void SchedulerUpdate::onEnter()
|
|||
SchedulerTestLayer::onEnter();
|
||||
|
||||
auto d = new TestNode();
|
||||
auto pStr = new String("---");
|
||||
d->initWithString(pStr, 50);
|
||||
pStr->release();
|
||||
d->initWithString("---", 50);
|
||||
addChild(d);
|
||||
d->release();
|
||||
|
||||
auto b = new TestNode();
|
||||
pStr = new String("3rd");
|
||||
b->initWithString(pStr, 0);
|
||||
pStr->release();
|
||||
b->initWithString("3rd", 0);
|
||||
addChild(b);
|
||||
b->release();
|
||||
|
||||
auto a = new TestNode();
|
||||
pStr = new String("1st");
|
||||
a->initWithString(pStr, -10);
|
||||
pStr->release();
|
||||
a->initWithString("1st", -10);
|
||||
addChild(a);
|
||||
a->release();
|
||||
|
||||
auto c = new TestNode();
|
||||
pStr = new String("4th");
|
||||
c->initWithString(pStr, 10);
|
||||
pStr->release();
|
||||
c->initWithString("4th", 10);
|
||||
addChild(c);
|
||||
c->release();
|
||||
|
||||
auto e = new TestNode();
|
||||
pStr = new String("5th");
|
||||
e->initWithString(pStr, 20);
|
||||
pStr->release();
|
||||
e->initWithString("5th", 20);
|
||||
addChild(e);
|
||||
e->release();
|
||||
|
||||
auto f = new TestNode();
|
||||
pStr = new String("2nd");
|
||||
f->initWithString(pStr, -5);
|
||||
pStr->release();
|
||||
f->initWithString("2nd", -5);
|
||||
addChild(f);
|
||||
f->release();
|
||||
|
||||
|
|
|
@ -216,10 +216,10 @@ public:
|
|||
|
||||
~TestNode();
|
||||
|
||||
void initWithString(String* pStr, int priority);
|
||||
void initWithString(const std::string& str, int priority);
|
||||
virtual void update(float dt);
|
||||
private:
|
||||
String* _pstring;
|
||||
std::string _string;
|
||||
};
|
||||
|
||||
class RescheduleSelector : public SchedulerTestLayer
|
||||
|
|
|
@ -588,19 +588,11 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest()
|
|||
Size CC_UNUSED s = map->getContentSize();
|
||||
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
||||
|
||||
////----CCLOG("----> Iterating over all the group objets");
|
||||
auto group = map->getObjectGroup("Object Group 1");
|
||||
auto& objects = group->getObjects();
|
||||
|
||||
for (auto& obj : objects)
|
||||
{
|
||||
ValueMap& dict = obj.asValueMap();
|
||||
////----CCLOG("object: %x", dict);
|
||||
}
|
||||
|
||||
////----CCLOG("----> Fetching 1 object by name");
|
||||
// auto platform = group->objectNamed("platform");
|
||||
////----CCLOG("platform: %x", platform);
|
||||
Value objectsVal = Value(objects);
|
||||
CCLOG("%s", objectsVal.getDescription().c_str());
|
||||
}
|
||||
|
||||
void TMXOrthoObjectsTest::draw()
|
||||
|
@ -657,15 +649,10 @@ TMXIsoObjectsTest::TMXIsoObjectsTest()
|
|||
|
||||
auto group = map->getObjectGroup("Object Group 1");
|
||||
|
||||
//auto objects = group->objects();
|
||||
auto& objects = group->getObjects();
|
||||
//UxMutableDictionary<std::string>* dict;
|
||||
for (auto& obj : objects)
|
||||
{
|
||||
ValueMap& dict = obj.asValueMap();
|
||||
|
||||
////----CCLOG("object: %x", dict);
|
||||
}
|
||||
Value objectsVal = Value(objects);
|
||||
CCLOG("%s", objectsVal.getDescription().c_str());
|
||||
}
|
||||
|
||||
void TMXIsoObjectsTest::draw()
|
||||
|
|
Loading…
Reference in New Issue