Example #1
0
/**
* その他UI
*/
void HelloWorld::addTalkOther(const std::string& str){
	Size size = Director::getInstance()->getVisibleSize();

	DrawNode* draw = DrawNode::create();

	int originalX = OTHER_TEXT_X;
	int originalY = size.height - (TEXT_H * (index + 1));

	int x = originalX - 10;
	int y = originalY - 60;
	int w = 300;
	int h = 60;

	Vec2 points[] = {
		Vec2(x, y),
		Vec2(x + w, y),
		Vec2(x + w, y + h),
		Vec2(x, y + h),
	};

	this->addChild(draw);
	draw->drawPolygon(points, 4, Color4F(0.5, 0, 0, 1), 1, Color4F(1, 0, 0, 1));

	auto text = Text::create(str, "fronts/arial.ttf", 40);
	text->setTextHorizontalAlignment(TextHAlignment::LEFT);
	text->setAnchorPoint(Point(0.0, 1.0));
	text->setPosition(Point(originalX, originalY));
	text->setColor(Color3B(255, 255, 0));
	this->addChild(text);
	index++;
}
Example #2
0
void Text::copySpecialProperties(Widget *widget)
{
    Text* label = dynamic_cast<Text*>(widget);
    if (label)
    {
        setFontName(label->_fontName);
        setFontSize(label->getFontSize());
        setTextColor(label->getTextColor());
        setString(label->getString());
        setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled);
        setTextHorizontalAlignment(label->_labelRenderer->getHorizontalAlignment());
        setTextVerticalAlignment(label->_labelRenderer->getVerticalAlignment());
        setTextAreaSize(label->_labelRenderer->getDimensions());
        setContentSize(label->getContentSize());

        LabelEffect effectType = label->getLabelEffectType();
        if (effectType == LabelEffect::GLOW)
        {
            enableGlow(label->getEffectColor());
        }
        else if (effectType == LabelEffect::OUTLINE)
        {
            enableOutline(label->getEffectColor(),label->getOutlineSize());
        }
        if (label->isShadowEnabled())
        {
            enableShadow(label->getShadowColor(),label->getShadowOffset(),label->getShadowBlurRadius());
        }
    }
}
Example #3
0
void Text::copySpecialProperties(Widget *widget)
{
    Text* label = dynamic_cast<Text*>(widget);
    if (label)
    {
        setFontName(label->_fontName);
        setFontSize(label->_labelRenderer->getFontSize());
        setText(label->getStringValue());
        setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled);
        setTextHorizontalAlignment(label->_labelRenderer->getHorizontalAlignment());
        setTextVerticalAlignment(label->_labelRenderer->getVerticalAlignment());
        setTextAreaSize(label->_labelRenderer->getDimensions());
    }
}
Example #4
0
void MoveText::AddTextData(TextData textData)
{
    
    float new_Axis = 0.0f;
    float old_Axis = 0.0f;
    
    auto textWidget = Text::create(textData.TextInfo, m_TTFFontName, textData.FontSize);
    
    switch (textData.Direction) {
        case Direction::Up :
            if (m_LastUpTextWidget != nullptr)
            {
                new_Axis = textData.PositionY;
                old_Axis = m_LastUpTextWidget->getPositionY();
                if (old_Axis < new_Axis + m_LastUpTextWidget->getContentSize().height)
                {
                    textData.PositionY =  old_Axis - m_LastUpTextWidget->getContentSize().height;
                    if(textData.PositionX < 100)  textData.PositionX = 120;
                }
            }
            m_LastUpTextWidget = textWidget;
            break;
        case Direction::Down :
            
            if (m_LastDownTextWidget != nullptr)
            {
                new_Axis = textData.PositionY;
                old_Axis = m_LastDownTextWidget->getPositionY();
                if (old_Axis > new_Axis - m_LastDownTextWidget->getContentSize().height)// * 0.8
                {
                    textData.PositionY =  old_Axis + m_LastDownTextWidget->getContentSize().height;// * 0.8;
                    if (textData.PositionX > Director::getInstance()->getVisibleSize().height)
                    {
                        textData.PositionX = Director::getInstance()->getVisibleSize().height - 120;
                    }
                }
            }
            m_LastDownTextWidget = textWidget;
            break;
    }
    
    
//    textWidget->setScale(0.1F);
    textWidget->setColor(textData.Color);
    textWidget->setTextAreaSize(Size(450,40));
    textWidget->setTextHorizontalAlignment(TextHAlignment::CENTER);
    
    textData.TextWidget = textWidget;
    textData.ParenNode->addChild(textWidget);
    
    textWidget->setPositionX(textData.PositionX);
    textWidget->setPositionY(textData.PositionY);
    
    Vec2 movePos;
    switch (textData.Direction)
    {
        case Direction::Up :
            if (textData.isBattleText) {
                movePos = Vec2(textWidget->getPositionX(), textWidget->getPositionY() + 70);
            }
            else {
                movePos = Vec2(textWidget->getPositionX(), textWidget->getPositionY() + 200);
            }
            break;
        case Direction::Down :
            if (textData.isBattleText) {
                movePos = Vec2(textWidget->getPositionX(), textWidget->getPositionY() - 70);
            }
            else {
                movePos = Vec2(textWidget->getPositionX(), textWidget->getPositionY() - 200);
            }
            break;
    }
    //同时执行移动和渐出
//    auto spawn = Spawn::create(moveTo, fadeOut, nullptr);
//    顺序执行多个动作
//    auto seq= Sequence::create(scaleBig,scaleLitt,spawn,
    
    // best modify
    //渐出
    auto fadeOut = FadeOut::create(0.8f);
    //放大
    auto scaleBig = ScaleTo::create(0.2F, 2.5F);
    //缩小
    auto scaleLitt = ScaleTo::create(0.2F, 1.50F);
    //移动
    auto moveTo = MoveTo::create(1.5F, movePos);
    //结束回调
    auto callFunc = CallFunc::create([this, textData, textWidget]()
                                     {
                                         if (textWidget->getParent())
                                         {
                                             textWidget->stopAllActions();
                                             textWidget->removeFromParent();
                                         }
                                         
                                         switch (textData.Direction)
                                         {
                                             case Direction::Up:
                                                 if(m_LastUpTextWidget == textData.TextWidget)
                                                 {
                                                     m_LastUpTextWidget = nullptr;
                                                 }
                                                 break;
                                             case Direction::Down:
                                                 if(m_LastDownTextWidget == textData.TextWidget)
                                                 {
                                                     m_LastDownTextWidget = nullptr;
                                                 }
                                                 
                                                 break;
                                         }
                                         
                                     });
    
    if (textData.isBattleText) {
        // 战斗文字
        textWidget->setScale(1.3F);
        moveTo = MoveTo::create(0.4F, movePos);
        
        auto seq= Sequence::create(moveTo, callFunc, nullptr);
        auto seq2 = Sequence::create(DelayTime::create(1), fadeOut, nullptr);
        
        textWidget->runAction(seq);
        textWidget->runAction(seq2);
    }
    else {
        // 非战斗
        textWidget->setScale(0.1F);
        auto seq= Sequence::create(scaleBig, scaleLitt, moveTo, callFunc, nullptr);
        textWidget->runAction(seq);
    }
    
 }
void EquipmentInfo::singleEquipmentInfo(int pkID, int typeClick)
{
    equipmentPKID = pkID;
    for (unsigned int i = 0; i < tempEquipVector.size(); i ++)
    {
        if (tempEquipVector[ i ].ePKID == pkID)
        {
            auto singlePanel = dynamic_cast<Layout* >(Helper::seekWidgetByName(singleInfo, "Panel_Left"));								// 获取属性面板
            auto nameImageString = __String::createWithFormat("%d.png", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eID);
            auto nameImage = dynamic_cast<ImageView* >(Helper::seekWidgetByName(singlePanel, "Image_Equip_0"));						// 设置物品图片
            nameImage->loadTexture(nameImageString->getCString(), TextureResType::UI_TEX_TYPE_PLIST);
            nameImage->setScale(81.0f / 120.0f);
            auto nameText = dynamic_cast<Text* >(Helper::seekWidgetByName(singlePanel, "Label_Name"));								// 装备名称
            if (tempEquipVector[ i ].eLevel == 0)
            {
                auto equipLevel = __String::createWithFormat("%s", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eChinaName);
                nameText->setText(equipLevel->getCString());
            }
            else
            {
                auto equipLevel = __String::createWithFormat("%s+%d", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eChinaName, tempEquipVector[ i ].eLevel);
                nameText->setText(equipLevel->getCString());
            }
            for (int z = 60; z < 62; z ++)
            {
                singlePanel->removeChildByTag( z );
            }
            // 功能按钮
            auto equipButton = dynamic_cast<Button*>(Helper::seekWidgetByName(singlePanel, "Button_Equip"));						// 装备按钮
            equipButton->addTouchEventListener(this, toucheventselector(EquipmentInfo::equipClick));
            equipButton->setVisible(false);
            equipButton->setTouchEnabled(false);

            auto changeButton = dynamic_cast<Button*>(Helper::seekWidgetByName(singlePanel, "Button_Change"));					// 更换
            changeButton->addTouchEventListener(this, toucheventselector(EquipmentInfo::changeClick));
            changeButton->setVisible(false);
            changeButton->setTouchEnabled(false);

            auto unloadButton = dynamic_cast<Button*>(Helper::seekWidgetByName(singlePanel, "Button_Unload"));					// 卸下
            unloadButton->addTouchEventListener(this, toucheventselector(EquipmentInfo::unloadClick));
            unloadButton->setVisible(false);
            unloadButton->setTouchEnabled(false);
            if (interGeneralEquipVector[ 0 ].equipID[ DataManager::getInstance()->equipType - 1 ] == 0)							// 点击的位置没有装备
            {
                equipButton->setVisible(true);
                equipButton->setTouchEnabled(true);

                if (false == NewComer::isGuideDone(1000))						/* 引导ID为0,且未完成 */
                {
                    _comer = NewComer::create(this, 1000, 4);
                }
            }
            else
            {
                if ( interGeneralEquipVector[ 0 ].equipPKID[ DataManager::getInstance()->equipType - 1 ] == pkID )
                {
                    unloadButton->setVisible(true);
                    unloadButton->setTouchEnabled(true);
                }
                else
                {
                    changeButton->setVisible(true);
                    changeButton->setTouchEnabled(true);
                }
            }

            // 物品属性
            auto proptyLabel1 = (Text*)singlePanel->getChildByName("Label_Propty_1");
            proptyLabel1->setFontSize(FontSize);
            proptyLabel1->setVisible(false);
            auto proptyLabel2 = (Text*)singlePanel->getChildByName("Label_Propty_2");
            proptyLabel2->setFontSize(FontSize);
            proptyLabel2->setVisible(false);
            auto label1 = Label::create();
            label1->setSystemFontSize(FontSize);
            label1->setColor(Color3B(255, 76, 0));
            label1->setTag(Label1);
            singlePanel->addChild(label1, 10);
            auto label2 = Label::create();
            label2->setSystemFontSize(FontSize);
            label2->setColor(Color3B(255, 76, 0));
            label2->setTag(Label2);
            singlePanel->addChild(label2, 10);

            auto goodsTypeString = __String::createWithFormat("%s", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].ePositionName);
            auto goodsDesString = __String::createWithFormat("%s", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eDes);
            auto typeLabel = dynamic_cast<Text*>(Helper::seekWidgetByName(singlePanel, "Label_Num"));
            auto desLabel = (Text*)singlePanel->getChildByName("Label_Des");
            typeLabel->setVisible(true);
            typeLabel->setText(goodsTypeString->getCString());

            desLabel->setVisible(true);
            desLabel->ignoreContentAdaptWithSize(false);
            desLabel->setSize(Size(180, 150));
            desLabel->setTextHorizontalAlignment(TextHAlignment::LEFT);
            desLabel->setText(goodsDesString->getCString());
            switch (localEquipVector[ tempEquipVector[ i ].eID - 94001 ].ePositionType)
            {
            case PosTypeHead:
            {
                proptyLabel1->setVisible(true);
                proptyLabel2->setVisible(false);
                proptyLabel1->setText(mpFontChina->getComString("PD")->getCString());

                auto hpString = __String::createWithFormat("%d", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].ePD);
                label1->setPosition(Point(proptyLabel1->getPositionX() + proptyLabel1->getContentSize().width + 10, proptyLabel1->getPositionY()));
                label1->setString(hpString->getCString());
            }
            break;
            case PosTypeArmour:
            {
                proptyLabel1->setVisible(true);
                proptyLabel2->setVisible(false);
                proptyLabel1->setText(mpFontChina->getComString("HP")->getCString());

                auto hpString = __String::createWithFormat("%d", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eHP);
                label1->setPosition(Point(proptyLabel1->getPositionX() + proptyLabel1->getContentSize().width + 10, proptyLabel1->getPositionY()));
                label1->setString(hpString->getCString());
            }
            break;
            case PosTypeDecorations:
            {
                proptyLabel1->setVisible(true);
                proptyLabel1->setText(mpFontChina->getComString("MD")->getCString());
                proptyLabel2->setVisible(false);
                auto attackString = __String::createWithFormat("%d", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eMD);
                label1->setPosition(Point(proptyLabel1->getPositionX() + proptyLabel1->getContentSize().width + 10, proptyLabel1->getPositionY()));
                label1->setString(attackString->getCString());
            }
            break;
            case PosTypeWeapons:
            {
                proptyLabel1->setVisible(true);
                proptyLabel2->setVisible(false);
                proptyLabel1->setText(mpFontChina->getComString("Attack")->getCString());
                label1->setPosition(proptyLabel1->getPosition().x + proptyLabel1->getContentSize().width + 10, proptyLabel1->getPosition().y);
                auto hpString = __String::createWithFormat("%d", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eAtk);
                label1->setString(hpString->getCString());
            }
            break;
            case PosTypeQi:
            {
                proptyLabel1->setVisible(true);
                proptyLabel2->setVisible(true);
                proptyLabel1->setText(mpFontChina->getComString("APR")->getCString());
                label1->setPosition(proptyLabel1->getPosition().x + proptyLabel1->getContentSize().width + 10, proptyLabel1->getPosition().y);
                auto hpString = __String::createWithFormat("%.2f", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eAddCrit);
                label1->setString(hpString->getCString());

                proptyLabel2->setText(mpFontChina->getComString("RPR")->getCString());
                label2->setPosition(proptyLabel2->getPosition().x + proptyLabel2->getContentSize().width + 10, proptyLabel2->getPosition().y);
                auto hpString2 = __String::createWithFormat("%.2f", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eReduceCrit);
                label2->setString(hpString2->getCString());
            }
            break;
            case PosTypeYi:
            {
                proptyLabel1->setVisible(true);
                proptyLabel2->setVisible(true);
                proptyLabel1->setText(mpFontChina->getComString("ARH")->getCString());
                label1->setPosition(proptyLabel1->getPosition().x + proptyLabel1->getContentSize().width + 10, proptyLabel1->getPosition().y);
                auto hpString = __String::createWithFormat("%d", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eAddRealHurt);
                label1->setString(hpString->getCString());

                proptyLabel2->setText(mpFontChina->getComString("RRH")->getCString());
                label2->setPosition(proptyLabel2->getPosition().x + proptyLabel2->getContentSize().width + 10, proptyLabel2->getPosition().y);
                auto hpString2 = __String::createWithFormat("%d", localEquipVector[ tempEquipVector[ i ].eID - 94001 ].eReduceHurt);
                label2->setString(hpString2->getCString());
            }
            break;
            }
        }
    }
}