const char * formatDate(time_t date)
{
    tm* t = localtime(&date);
    //We add 1 to to the month because it seems that january is 0, etc.
    //TODO : use a native method to format according user locales
    return ScreateF("%i/%i/%i", t->tm_mday, t->tm_mon+1, t->tm_year-100)->getCString();
}
Exemple #2
0
Image::Image(const char* filename, CCPoint location, int capacity):
imageFile(filename),
loadingImageFile(""),
isLoadingTexture(false)
{
    name = filename;
    spriteSheet = CCSpriteBatchNode::create(imageFile.append(".png").c_str(), capacity);
    imageFile.erase(imageFile.length() - 4, 4);
    spriteSheet->retain();
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(imageFile.append(".plist").c_str());
    imageFile.erase(imageFile.length() - 6, 6);
    
    spritesName = CCArray::createWithCapacity(capacity);
    spritesName->retain();
    for(int i = 1; i <= capacity; i++)
    {
        /*char num[10];
         sprintf(num, "%04d", i);*/
        spritesName->addObject(ScreateF("%s_%02d.png", filename, i));//imageFile.append(num).append(".png")));
    }
    delegate = CCSprite::create();
    delegate->retain();
    CCSpriteFrame* firstFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(((CCString*)spritesName->objectAtIndex(0))->getCString());
    delegate->setDisplayFrame(firstFrame);
    this->setPosition(location);
    spriteSheet->addChild(delegate);
    runningAnimation = NULL;
}
Exemple #3
0
void Image::loadAnimation(const char* filename, int capacity)
{
    imageFile = filename;
    spriteSheet = CCSpriteBatchNode::create(imageFile.append(".png").c_str(), capacity);
    imageFile.erase(imageFile.length() - 4, 4);
    spriteSheet->retain();
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(imageFile.append(".plist").c_str());
    imageFile.erase(imageFile.length() - 6, 6);
    
    spritesName = CCArray::createWithCapacity(capacity);
    spritesName->retain();
    for(int i = 1; i <= capacity; i++)
    {
        /*char num[10];
         sprintf(num, "%04d", i);*/
        spritesName->addObject(ScreateF("%s_%02d.png", filename, i));//imageFile.append(num).append(".png")));
    }
    CCSpriteFrame* firstFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(((CCString*)spritesName->objectAtIndex(0))->getCString());
    delegate->setDisplayFrame(firstFrame);
    CCNode* parent = delegate->getParent();
    parent->addChild(spriteSheet);
    parent->removeChild(delegate, false);
    spriteSheet->addChild(delegate);
    runningAnimation = NULL;
}
CCString* getResourcesPath(const char* file)
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
    return Screate(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(file));
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
    return ScreateF("/assets/%s", file);
#endif
}
NS_FENNEX_BEGIN
CCString* getResourcesPath(const char* file)
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
    return Screate(CCFileUtils::sharedFileUtils()->fullPathForFilename(file));
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
    return ScreateF("/assets/%s", file);
#endif
}
Exemple #6
0
CCString* changeFirstLetterCase(CCString* text, bool lower)
{
    if(text->length() > 0)
    {
        char firstChar = lower ? tolower(text->getCString()[0]) : toupper(text->getCString()[0]);
        std::string textString = std::string(text->getCString());
        std::string subString = textString.substr(1);
        const char* rest = subString.c_str();
        //reconstruct the char with first character lower cased
        text = ScreateF("%c%s", firstChar, rest);
    }
    return text;
}
CCString* getAppName()
{
    JniMethodInfo minfo;
    CCAssert(JniHelper::getStaticMethodInfo(minfo, CLASS_NAME, "getAppName", "()Ljava/lang/String;"), "Function doesn't exist");

    jstring name = (jstring) minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID);
    minfo.env->DeleteLocalRef(minfo.classID);

    const char *nativeString = minfo.env->GetStringUTFChars(name, 0);
    CCLOG("Getting app name : %s", nativeString);
    CCString* path = ScreateF("%s", nativeString);
    minfo.env->ReleaseStringUTFChars(name, nativeString);
    return path;
}
InputLabel::InputLabel(const char* placeHolder, const char* fontName, int fontSize, Vec2 location, ui::EditBox::InputMode inputMode, int maxChar, Size dimensions, TextHAlignment format)
{
    linkTo = NULL;
    isOpened = false;
    textDirty = false;
    originalInfos = NULL;
    isPassword = false;
    passwordText = NULL;
    name = placeHolder;
    ui::Scale9Sprite* sprite = ui::Scale9Sprite::create("green_edit.png", Rect(0, 0, 43, 38), Rect(4, 3, 35, 32));
    sprite->setPreferredSize(Size(43, 38));
    sprite->setOpacity(0);
    delegate = ui::EditBox::create(dimensions, sprite);
    delegate->retain();
    if(strlen(placeHolder) > 0)
    {
        CCString* placeholderWithBrackets = ScreateF("<%s>", placeHolder);
        delegate->setPlaceHolder(placeholderWithBrackets->getCString());
        this->setInitialText(placeholderWithBrackets);
    }
    delegate->setFontColor(Color3B::BLACK);
    delegate->setDelegate(this);
    
    this->setPosition(location);
    delegate->setInputMode(inputMode);
    numbersOnly = inputMode ==  ui::EditBox::InputMode::DECIMAL;
    delegate->setReturnType(ui::EditBox::KeyboardReturnType::DONE);
    delegate->setInputFlag(ui::EditBox::InputFlag::INITIAL_CAPS_SENTENCE);
    if(maxChar != -1)
    {
        delegate->setMaxLength(maxChar);
    }
    listeners.pushBack(Director::getInstance()->getEventDispatcher()->addCustomEventListener("OpenKeyboard", std::bind(&InputLabel::openKeyboard, this, std::placeholders::_1)));
    listeners.pushBack(Director::getInstance()->getEventDispatcher()->addCustomEventListener("CloseKeyboard", std::bind(&InputLabel::closeKeyboard, this, std::placeholders::_1)));
    listeners.pushBack(Director::getInstance()->getEventDispatcher()->addCustomEventListener("DisableInputs", std::bind(&InputLabel::disableInputs, this, std::placeholders::_1)));
    listeners.pushBack(Director::getInstance()->getEventDispatcher()->addCustomEventListener("EnableInputs", std::bind(&InputLabel::enableInputs, this, std::placeholders::_1)));
    
}