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