Beispiel #1
0
bool CustomInput::onAssignCCBCustomProperty(CCObject* pTarget, const char* pMemberVariableName, const cocos2d::Value& pCCBValue)
{
    CustomInput* target = dynamic_cast<CustomInput*>(pTarget);
    if(pCCBValue.getType() == cocos2d::Value::Type::INTEGER && strcmp(pMemberVariableName, "maxChar") == 0)
    {
        target->setMaxChar(pCCBValue.asInt());
    }
    else if(pCCBValue.getType() == cocos2d::Value::Type::INTEGER && strcmp(pMemberVariableName, "fontSize") == 0)
    {
        target->setFontSize(pCCBValue.asInt());
    }
    else if(pCCBValue.getType() == cocos2d::Value::Type::STRING && strcmp(pMemberVariableName, "placeHolder") == 0)
    {
        target->setPlaceHolder(Screate(pCCBValue.asString()));
    }
    else if(pCCBValue.getType() == cocos2d::Value::Type::STRING && strcmp(pMemberVariableName, "fontName") == 0)
    {
        target->setFontName(Screate(pCCBValue.asString()));
    }
    else if(pCCBValue.getType() == cocos2d::Value::Type::BOOLEAN && strcmp(pMemberVariableName, "numbers") == 0)
    {
        target->setNumbersOnly(pCCBValue.asBool());
    }
    else
    {
        CustomBaseNode::onAssignCCBCustomProperty(pTarget, pMemberVariableName, pCCBValue);
    }
    return false;
}
Beispiel #2
0
CCString* upperCaseString(CCString* text)
{
    timeval startTime;
    gettimeofday(&startTime, NULL);
    //TODO : speed up by sorting the vector and doing a better search
    static std::vector<std::pair<std::string, std::string>> conversions = getConversions();
    if(conversions.size() == 0)
    {
        CCLOG("Warning: missing file letters_conversion.txt, required for upperCaseString, string %s not converted", text->getCString());
        return text;
    }
    std::string from = text->getCString();
    std::string to;
    for(int i = 0; i < from.length(); i+= utf8_chsize(&from[i]))
    {
        long charLength = utf8_chsize(&from[i]);
        std::string charString = from.substr(i, charLength);
        int conversionIndex = 0;
        while(conversionIndex < conversions.size() && conversions[conversionIndex].second != charString)
        {
            conversionIndex++;
        }
        if(conversionIndex < conversions.size())
        {
            to += conversions[conversionIndex].first;
        }
        else
        {
            to += charString;
        }
    }
    timeval endTime;
    gettimeofday(&endTime, NULL);
    return Screate(to.c_str());
}
void SwipeRecognizer::onTouchEnded(Touch *touch, Event *pEvent)
{
#if VERBOSE_TOUCH_RECOGNIZERS
    CCLOG("linked ? %s", mainLinker->linkedObjectOf(touch) == NULL ? "yes" : "no");
    CCLOG("is in start ? %s", touchStart.find(touch->getID()) != touchStart.end() ? "yes" : "no");
    CCLOG("time ? %s", (TIME - touchStart.at(touch->getID())) < 2.0 ? "yes" : "no");
    CCLOG("initial position : %f, %f, current : %f, %f", touchInitialPosition.at(touch->getID()).x, touchInitialPosition.at(touch->getID()).y, Scene::touchPosition(touch).x, Scene::touchPosition(touch).y);
#endif
    if(mainLinker != NULL
       && mainLinker->linkedObjectOf(touch) == NULL
       && touchStart.find(touch->getID()) != touchStart.end())
    {
        Vec2 initialPosition = touchInitialPosition.at(touch->getID());
        Vec2 currentPosition = Scene::touchPosition(touch);
        if(fabsf(initialPosition.x - currentPosition.x) >= minMovement * RESOLUTION_MULTIPLIER &&
           fabsf(initialPosition.y - currentPosition.y) <= fabsf(initialPosition.x - currentPosition.x) &&
           fabsf(initialPosition.x - currentPosition.x) > fabsf(initialPosition.y - currentPosition.y) &&
           fabsf(initialPosition.x - currentPosition.x) / (TIME - touchStart.at(touch->getID())) > minSpeed * RESOLUTION_MULTIPLIER)
        {
            CCDictionary* infos = CCDictionary::create();
            infos->setObject(touch, "Touch");
            infos->setObject(initialPosition.x > currentPosition.x ? Screate("Left") : Screate("Right"), "Direction");
            infos->setObject(Fcreate(initialPosition.x), "InitialPositionX");
            infos->setObject(Fcreate(initialPosition.y), "InitialPositionY");
            Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("SwipeRecognized", infos);
        }
        
    }
    touchStart.erase(touch->getID());
    touchInitialPosition.erase(touch->getID());
}
Beispiel #4
0
void Scene::switchButton(Image* obj, bool state, Touch* touch)
{
    if(state)
    {
        if(obj->getEventInfos()->objectForKey("_OriginalImageFile") == NULL)
        {
            obj->setEventInfo(Screate(obj->getImageFile()), "_OriginalImageFile");
            obj->replaceTexture(obj->getImageFile() + "-on");
        }
        //If it was actually replaced, it will end by -on
        char *end = strrchr(obj->getImageFile().c_str(), '-');
        if (end && strcmp(end, "-on") == 0)
        {
            linker->linkTouch(touch, obj);
        }
        else
        {
            obj->removeEventInfo("_OriginalImageFile");
        }
    }
    else
    {
        if(obj->getEventInfos()->objectForKey("_OriginalImageFile") != NULL)
        {
            obj->replaceTexture(TOCSTRING(obj->getEventInfos()->objectForKey("_OriginalImageFile")));
            obj->removeEventInfo("_OriginalImageFile");
        }
        linker->unlinkObject(obj);
    }
}
void InputLabel::setLinkTo(LabelTTF* var)
{
    linkTo = var;
    delegate->setFontColor(((Label*)var->getNode())->getColor());
    delegate->setPlaceHolder("");
    delegate->setText("");
    this->setInitialText(Screate(var->getLabelValue()));
}
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
}
Beispiel #7
0
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
}
NS_FENNEX_BEGIN
void CustomScaleSpriteLoader::onHandlePropTypeSpriteFrame(CCNode * pNode, CCNode * pParent, const char* pPropertyName, CCSpriteFrame * pCCSpriteFrame, CCBReader * pCCBReader)
{
    if(strcmp(pPropertyName, "spriteFrame") == 0)
    {
        ((CustomScaleSprite*)pNode)->getParameters()->setObject(Screate(CCTextureCache::sharedTextureCache()->keyForTexture(pCCSpriteFrame->getTexture())), "spriteFrame");
    }
    
    CCScale9SpriteLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pCCSpriteFrame, pCCBReader);
}
void InputLabel::editBoxEditingDidEnd(ui::EditBox* editBox)
{
    CCLOG("Edit Box editing did end");
    if(isOpened)
    { //on dealloc, the isOpened flag will be false to prevent this code from being executed (could be used for a cancel method too)
        isOpened = false;
        if(linkTo != NULL)
        {
            if(strlen(delegate->getText()) > 0)
            {
                if(isPassword)
                {
                    IFEXIST(passwordText)->autorelease();
                    passwordText = new CCString(delegate->getText());
                    std::string bulletString;
                    for(int i = 0; i < (int)strlen(delegate->getText()); i++)
                    {
                        bulletString.append("●");
                    }
                    linkTo->setLabelValue(bulletString.c_str());
                }
                else
                {
                    linkTo->setLabelValue(delegate->getText());
                }
            }
            else
            {
                linkTo->setLabelValue(initialText->getCString());
            }
            delegate->setText("");
            linkTo->setVisible(true);
        }
        CCDictionary* param = this->getEventInfos();
        param->setObject(Screate(this->getLabelValue()), "Text");
        Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("TextAdded", param);
    }
    delegate->detachWithIME();
}
void SelectionRecognizer::checkForSelection(CCObject* obj)
{
    CCTouch* touch = (CCTouch*)obj;
    //the touch could have been discarded in the meantime
    if(isTouchInSelection(touch))
    {
        CCPoint currentLocation = Scene::touchPosition(touch);
        CCPoint touchOrigin = TOPOINT(storedTouches->objectForKey(touch->getID()));
        CCObject* target = mainLinker->linkedObjectOf(touch);
        if(ccpDistance(Scene::touchPosition(touch), touchOrigin) <= maxMovement)
        {
            CCNotificationCenter::sharedNotificationCenter()->postNotification("SelectionRecognized", DcreateP(touch, Screate("Touch"), target, Screate("Target"), NULL));
        }
        else
        {
            CCNotificationCenter::sharedNotificationCenter()->postNotification("SelectionCanceled", DcreateP(touch, Screate("Touch"), storedTouches->objectForKey(touch->getID()), Screate("Origin"), target, Screate("Target"), NULL));
        }
        
        storedTouches->removeObjectForKey(touch->getID());
    }
}
void SelectionRecognizer::cancelSelectionForTouch(CCTouch* touch)
{
    if(isTouchInSelection(touch))
    {
        CCNotificationCenter::sharedNotificationCenter()->postNotification("SelectionCanceled", DcreateP(touch, Screate("Touch"), storedTouches->objectForKey(touch->getID()), Screate("Origin"), NULL));
        storedTouches->removeObjectForKey(touch->getID());
    }
}
void SelectionRecognizer::ccTouchMoved(CCTouch *touch, CCEvent *pEvent)
{
    if(isTouchInSelection(touch))
    {
        CCPoint touchOrigin = TOPOINT(storedTouches->objectForKey(touch->getID()));
        if(ccpDistance(Scene::touchPosition(touch), touchOrigin) > maxMovement)
        {
            cancelSelectionForTouch(touch);
        }
        else
        {
            CCNotificationCenter::sharedNotificationCenter()->postNotification("SelectionMoved", DcreateP(touch, Screate("Touch"), NULL));
        }
    }
}
bool SelectionRecognizer::ccTouchBegan(CCTouch *touch, CCEvent *pEvent)
{
    storedTouches->setObject(Pcreate(Scene::touchPosition(touch)), touch->getID());
    performSelectorAfterDelay(this, callfuncO_selector(SelectionRecognizer::checkForSelection), duration, touch);
    CCNotificationCenter::sharedNotificationCenter()->postNotification("SelectionStarted", DcreateP(touch, Screate("Touch"), NULL));
    return true;
}
Beispiel #14
0
const char* changeFirstLetterCase(const char* text, bool lower)
{
    return changeFirstLetterCase(Screate(text), lower)->getCString();
}
Beispiel #15
0
const char* upperCaseString(const char* text)
{
    return upperCaseString(Screate(text))->getCString();
}
void InputLabel::editBoxEditingDidBegin(ui::EditBox* editBox)
{
    if(locks.size() > 0)
    {
        closeKeyboard(EventCustom::create("CloseKeyboard", DcreateP(Icreate(this->getID()), Screate("Sender"), NULL)));
        return;
    }
    if(!isOpened && delegate->isEnabled())
    {
        isOpened = true;
        Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("InputLabelBeginEdit", DcreateP(Icreate(identifier), Screate("Sender"), NULL));
    }
}
Beispiel #17
0
void notifyLicenseStatusNative(bool authorized)
{
    LOGD("Notifying license status : %s", authorized ? "Authorized" : "Locked");
    DelayedDispatcher::eventAfterDelay("LicenseStatusUpdate", DcreateP(Bcreate(authorized), Screate("Authorized"), NULL), 0.01);
}
Beispiel #18
0
void notifyInAppEventNative(std::string name, std::string argument)
{
    LOGD("Notifying in app event : %s", name.c_str());
    DelayedDispatcher::eventAfterDelay(name, DcreateP(Screate(argument), Screate("ProductID"), NULL), 0.01);
}