示例#1
0
//扣血值
void HeroBase::subBlood(EnemyBase *enemy)
{
    //log("Enemy::subHp(%f,%d,%d)",subHp,m_State,m_EnemyModel->CurrHP);
    if (m_BodyState==GameEnum::BodyState::Die) {
        return;
    }
    
    int def=m_HeroModel->Def;
    //伤害 = 攻击方攻击力*(1-(挨打方防御力*0.05/(0.05*挨打方防御力+1)))+攻击方攻击力*0.025
    auto enemyModel=enemy->getEnemyModel();
    int attack=enemyModel->Attack;
    int attackResult=attack * (1 - (def * 0.05 / (0.05 * def + 1))) + attack * 0.025;
    int randAttack=attackResult * APTools::getRandFloat(-0.1, 0.1);
    attackResult+=randAttack;
    m_HeroModel->CurrHp-=attackResult;
    
    float percent=getHpPercent();
    m_HealthBar->setHpPercentage(percent);
    
    if (m_isMainHero) {
        GameBLL::instance()->m_GameUILayer->updateHeroState(this);
    }
    if (m_HeroModel->CurrHp > 0) {
        //播放掉血数字
        int orderZ=getLocalZOrder();
        Vec2 vPos=getPosition();
        auto ggl=GameBLL::instance()->m_GameLayer;
        ggl->subCurrHp(vPos,20,attackResult,orderZ);
    }
    
    if (m_HeroModel->CurrHp <= 0) {
        die();
    }
}
示例#2
0
void CCSlot::_replaceDisplay(void* value, bool isArmatureDisplayContainer)
{
    const auto container = static_cast<CCArmatureDisplay*>(this->_armature->_display);
    const auto prevDisplay = isArmatureDisplayContainer ? static_cast<cocos2d::Node*>(static_cast<CCArmatureDisplay*>(value)) : static_cast<cocos2d::Node*>(value); // static_cast<cocos2d::Node*>(isArmatureDisplayContainer ? static_cast<CCArmatureDisplay*>(value) : value); // WTF
    container->addChild(_renderDisplay, prevDisplay->getLocalZOrder());
    container->removeChild(prevDisplay);
}
//界面裁剪这段直接copy scrollview代码
void UINumberPicker::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4 &parentTransform, uint32_t parentFlags)
{
    // quick return if not visible
    if (!isVisible() || !isVisitableByVisitingCamera())
    {
        return;
    }
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);
    
    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when seting matrix stack");
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    this->beforeDraw();
    bool visibleByCamera = isVisitableByVisitingCamera();
    
    if (!_children.empty())
    {
        int i=0;
        
        // draw children zOrder < 0
        for( ; i < _children.size(); i++ )
        {
            auto child = _children.at(i);
            if ( child->getLocalZOrder() < 0 )
            {
                child->visit(renderer, _modelViewTransform, flags);
            }
            else
            {
                break;
            }
        }
        
        // this draw
        if (visibleByCamera)
            this->draw(renderer, _modelViewTransform, flags);
        
        // draw children zOrder >= 0
        for( ; i < _children.size(); i++ )
        {
            auto child = _children.at(i);
            child->visit(renderer, _modelViewTransform, flags);
        }
    }
    else if (visibleByCamera)
    {
        this->draw(renderer, _modelViewTransform, flags);
    }
    
    this->afterDraw();
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
示例#4
0
void BillBoard::visit(Renderer *renderer, const Mat4& parentTransform, uint32_t parentFlags)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }
    bool visibleByCamera = isVisitableByVisitingCamera();
    // quick return if not visible by camera and has no children.
    if (!visibleByCamera && _children.empty())
    {
        return;
    }
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);
    
    //Add 3D flag so all the children will be rendered as 3D object
    flags |= FLAGS_RENDER_AS_3D;
    
    //Update Billboard transform
    bool dirty = calculateBillboardTransform();
    if(dirty)
    {
        flags |= FLAGS_TRANSFORM_DIRTY;
    }
    
    Director* director = Director::getInstance();
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    int i = 0;
    
    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for(auto size = _children.size(); i < size; ++i)
        {
            auto node = _children.at(i);
            
            if (node && node->getLocalZOrder() < 0)
                node->visit(renderer, _modelViewTransform, flags);
            else
                break;
        }
        // self draw
        if (visibleByCamera)
            this->draw(renderer, _modelViewTransform, flags);

        for(auto it=_children.cbegin()+i, itCend = _children.cend(); it != itCend; ++it)
            (*it)->visit(renderer, _modelViewTransform, flags);
    }
    else if (visibleByCamera)
    {
        this->draw(renderer, _modelViewTransform, flags);
    }
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
示例#5
0
void BoneNode::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }

    uint32_t flags = processParentFlags(parentTransform, parentFlags);

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    _director->pushMatrix(cocos2d::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    _director->loadMatrix(cocos2d::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);

    bool visibleByCamera = isVisitableByVisitingCamera();
    bool isdebugdraw = visibleByCamera && _isRackShow && nullptr == _rootSkeleton;
    int i = 0;

    if (!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for (; i < _children.size(); i++)
        {
            auto node = _children.at(i);
            if (_rootSkeleton != nullptr && _boneSkins.contains(node)) // skip skin when bone is in a skeleton
                continue;
            if (node && node->getLocalZOrder() < 0)
                node->visit(renderer, _modelViewTransform, flags);
            else
                break;
        }
        // self draw
        if (isdebugdraw)
            this->draw(renderer, _modelViewTransform, flags);

        for (auto it = _children.cbegin() + i; it != _children.cend(); ++it)
        {
            auto node = (*it);
            if (_rootSkeleton != nullptr && _boneSkins.contains(node)) // skip skin when bone is in a skeleton
                continue;
            node->visit(renderer, _modelViewTransform, flags);
        }
    }
    else if (isdebugdraw)
    {
        this->draw(renderer, _modelViewTransform, flags);
    }

    _director->popMatrix(cocos2d::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);

    // FIX ME: Why need to set _orderOfArrival to 0??
    // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
    // reset for next frame
    // _orderOfArrival = 0;
}
示例#6
0
/**
	@brief		キャンバス初期化
	@param[in]	なし
	@return		なし
*/
void RelayGameLayer::_NextCanvas()
{
	auto oldCanvas = this->getChildByName("Canvas");
	//-----------------------------------------------------
	// 新規キャンバスを既存キャンバスの下に
	auto layerCanvas = LayerCanvas::create();
	if (layerCanvas && layerCanvas->createSprite("canvas.png"))
	{
		this->addChild(layerCanvas, oldCanvas->getLocalZOrder()-1, "NewCanvas");

		layerCanvas->setPosition(oldCanvas->getPosition());
		//layerCanvas->setVisible(false);
	}

	//-----------------------------------------------------
	// DrawNode
	auto drawNode = DrawNode::create();
	{
		drawNode->setAnchorPoint(Vec2::ZERO);
		auto canvas = layerCanvas->getSprite();
		//layerCanvas->addChild(m_pDrawNode, 1);
		drawNode->setPosition(
			-(layerCanvas->getPositionX() - layerCanvas->getAnchorPoint().x*layerCanvas->getContentSize().width),
			-(layerCanvas->getPositionY() - layerCanvas->getAnchorPoint().y*layerCanvas->getContentSize().height)
			);
		canvas->addChild(drawNode, 1, "DrawNode");
	}

	oldCanvas->runAction(
		Sequence::create(
			PageTurn3D::create(0.5f, Size(24.f, 32.f)),
			CallFunc::create([this, oldCanvas, layerCanvas, drawNode](){
				// キャンバスの入れ替え
				//this->removeChild(oldCanvas);
				oldCanvas->setName(oldCanvas->getName() + std::to_string(m_nowPage));
				oldCanvas->setVisible(false);

				layerCanvas->setLocalZOrder(ZOrder::CANVAS);
				layerCanvas->setName("Canvas");
				//--------------------------
				// DrawNode入れ替え
				//m_pDrawNode->release();
				m_pDrawNode = drawNode;
				//--------------------------
				// ページ追加
				m_nowPage++;
				m_touchPoints.push_back(page_t());
				m_nowLine = 0;
				//--------------------------
				// 解答ボックス初期化
				m_pEditBox->setText("");
			}),
			nullptr
		)
	);

}
示例#7
0
	virtual void visit(Renderer *renderer,
		const Mat4& parentTransform, uint32_t parentFlags) override
	{
		m_renderTexture->beginWithClear(0, 0, 0, 0);
		Node::visit(renderer, parentTransform, parentFlags);
		m_renderTexture->end();

		m_renderTexture->getSprite()->setBlendFunc(m_blendFunc);
		m_renderTexture->setLocalZOrder(getLocalZOrder());
		m_renderTexture->visit(renderer, Mat4::IDENTITY, 0);
	}
示例#8
0
void SmartScene::blockTopLayer()
{
	if( _stack.empty() == false )
	{
		_nowBlockedTopLayer = true;
		auto top = _stack.back();
		assert( top->isRunning() );
		top->onExit();
		_shadow->setLocalZOrder( top->getLocalZOrder() + 1 );
	}
}
示例#9
0
void SmartScene::unblockTopLayer()
{
	if( _stack.empty() == false )
	{
		auto top = _stack.back();
		//assert( top->isRunning() == false );
        if(top->isRunning() == false)
            top->onEnter();
		_shadow->setLocalZOrder( top->getLocalZOrder() - 1 );
		_nowBlockedTopLayer = false;
	}
}
void GameplayLayer::_handleActionDiceDragEnded(EventCustom* event) {
  auto data = (ActionDiceDragData*) event->getUserData();
  auto sprite = data->getSprite();
  auto dice = sprite->getDice();
  
  sprite->setLocalZOrder(sprite->getLocalZOrder() - DRAG_Z_ORDER_DELTA);
  
  OverlayUtil::removeOverlay(this);
  
  auto handler = DiceDragHandlerFactory::getHandler(dice);
  bool docked = handler->dragEnded(data, this, this->_getDockableContainer());
  
  if (!docked) {
    sprite->restoreOriginalPosition();
  }
}
示例#11
0
void Sprite3D::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4 &parentTransform, uint32_t parentFlags)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);
    flags |= FLAGS_RENDER_AS_3D;
    
    //
    Director* director = Director::getInstance();
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    bool visibleByCamera = isVisitableByVisitingCamera();
    
    int i = 0;
    
    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for( ; i < _children.size(); i++ )
        {
            auto node = _children.at(i);
            
            if (node && node->getLocalZOrder() < 0)
                node->visit(renderer, _modelViewTransform, flags);
            else
                break;
        }
        // self draw
        if (visibleByCamera)
            this->draw(renderer, _modelViewTransform, flags);
        
        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
            (*it)->visit(renderer, _modelViewTransform, flags);
    }
    else if (visibleByCamera)
    {
        this->draw(renderer, _modelViewTransform, flags);
    }
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
示例#12
0
void TestController::menuCallback(Ref * sender)
{
	Director::getInstance()->purgeCachedData();

    // get the userdata, it's the index of the menu item clicked
    auto menuItem = static_cast<MenuItem *>(sender);
    int idx = menuItem->getLocalZOrder() - 10000;

    // create the test scene and run it
    auto scene = g_aTestNames[idx].callback();

    if (scene)
    {
        scene->runThisTest();
        scene->release();
    }
}
示例#13
0
void UnitTestLayer::menuCallback(Ref * sender)
{
	Director::getInstance()->purgeCachedData();
    
    // get the userdata, it's the index of the menu item clicked
    auto menuItem = static_cast<MenuItem *>(sender);
    int idx = menuItem->getLocalZOrder() - 10000;
    
    // create the test scene and run it
    auto scene = tests[idx].generator();
    
    if (scene)
    {
        scene->runThisTest();
        Director::getInstance()->pushScene(scene);
    }
}
示例#14
0
void SmartScene::pushLayer( Layer* layer, bool exitPrevios )
{
	shadow_appearance();
	if( layer )
	{
		assert( _stack.empty() == false );
		auto top = _stack.back();
		int z = top->getLocalZOrder() + 2;
		_shadow->setLocalZOrder( z - 1 );

		layer->setOnExitCallback( std::bind( &SmartScene::on_layerClosed, this, layer ) );
		addChild( layer, z );

		_stack.push_back( layer );
		if( exitPrevios )
			top->onExit();
	}
}
示例#15
0
void SmartScene::on_layerClosed( Layer* layer )
{
	if( _nowBlockedTopLayer )return;

	if( layer == _stack.back() )
	{
		assert( _stack.size() >= 2 );
		_stack.pop_back();
		_stack.back()->onEnter();
	}
	if( _stack.empty() == false )
	{
		auto top = _stack.back();
		_shadow->setLocalZOrder( top->getLocalZOrder() - 1 );
	}
	if( _stack.size() == 1 )
	{
		shadow_disappearance();
	}
	//removeChild( layer );
}
示例#16
0
///selectively copies parts of the given Sprite
Sprite* StaticHelpers::duplicateSprite(Sprite *sprite)
{
    Sprite* pRet = Sprite::createWithTexture(sprite->getTexture());
    if (sprite->getChildrenCount() > 0) {
        auto children = sprite->getChildren();
        for (auto child : children) {
            auto spriteChild = dynamic_cast<Sprite*>(child);
            if (! spriteChild) continue;
            auto clone = duplicateSprite(spriteChild);
            // can't set boundingBox
            //might need to set textureRect, scale, rotation
            //clone->boundingBox() = spriteChild->boundingBox();
            clone->setContentSize(spriteChild->getContentSize());
            clone->setPosition(spriteChild->getPosition());
            clone->setAnchorPoint(spriteChild->getAnchorPoint());
            clone->setLocalZOrder(spriteChild->getLocalZOrder());
            clone->setTag(spriteChild->getTag());
            pRet->addChild(clone);
        }
    }
    return pRet;
}
示例#17
0
void ShaderNode::visit(Renderer *renderer, const Mat4& parentTransform, uint32_t parentFlags)
{
    if (!_visible)
        return;
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);
    
    _director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    _director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    bool visibleByCamera = isVisitableByVisitingCamera();
    int i = 0;
    _rendertTexture->beginWithClear(0, 0, 0, 0);
    if (!_children.empty())
    {
        sortAllChildren();
        for( ; i < _children.size(); i++ )
        {
            auto node = _children.at(i);
            
            if (node && node->getLocalZOrder() < 0)
                node->visit(renderer, Mat4::IDENTITY, flags);
            else
                break;
        }
        
        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
            (*it)->visit(renderer, Mat4::IDENTITY, flags);
    }
    _rendertTexture->end();
    
    if (visibleByCamera)
    {
        this->draw(renderer, _modelViewTransform, flags);
    }
}
示例#18
0
void NodeGrid::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }

    bool dirty = (parentFlags & FLAGS_TRANSFORM_DIRTY) || _transformUpdated;
    if(dirty)
        _modelViewTransform = this->transform(parentTransform);
    _transformUpdated = false;
    
    _groupCommand.init(_globalZOrder);
    renderer->addCommand(&_groupCommand);
    renderer->pushGroup(_groupCommand.getRenderQueueID());

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when setting matrix stack");
    
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);

    Director::Projection beforeProjectionType = Director::Projection::DEFAULT;
    if(_nodeGrid && _nodeGrid->isActive())
    {
        beforeProjectionType = Director::getInstance()->getProjection();
        _nodeGrid->set2DProjection();
    }

    _gridBeginCommand.init(_globalZOrder);
    _gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this);
    renderer->addCommand(&_gridBeginCommand);


    if(_gridTarget)
    {
        _gridTarget->visit(renderer, _modelViewTransform, dirty);
    }
    
    int i = 0;
    bool visibleByCamera = isVisitableByVisitingCamera();

    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for( ; i < _children.size(); i++ )
        {
            auto node = _children.at(i);

            if ( node && node->getLocalZOrder() < 0 )
                node->visit(renderer, _modelViewTransform, dirty);
            else
                break;
        }
        // self draw,currently we have nothing to draw on NodeGrid, so there is no need to add render command
        if (visibleByCamera)
            this->draw(renderer, _modelViewTransform, dirty);

        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) {
            (*it)->visit(renderer, _modelViewTransform, dirty);
        }
    }
    else if (visibleByCamera)
    {
        this->draw(renderer, _modelViewTransform, dirty);
    }
    
    // FIX ME: Why need to set _orderOfArrival to 0??
    // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
    // setOrderOfArrival(0);
    
    if(_nodeGrid && _nodeGrid->isActive())
    {
        // restore projection
        director->setProjection(beforeProjectionType);
    }

    _gridEndCommand.init(_globalZOrder);
    _gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this);
    renderer->addCommand(&_gridEndCommand);

    renderer->popGroup();
 
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
示例#19
0
void ClippingNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
    if(!_visible)
        return;
    
    bool dirty = parentTransformUpdated || _transformUpdated;
    if(dirty)
        _modelViewTransform = transform(parentTransform);
    _transformUpdated = false;

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);

    //Add group command
        
    _groupCommand.init(_globalZOrder);
    renderer->addCommand(&_groupCommand);

    renderer->pushGroup(_groupCommand.getRenderQueueID());

    _beforeVisitCmd.init(_globalZOrder);
    _beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this);
    renderer->addCommand(&_beforeVisitCmd);
    if (_alphaThreshold < 1)
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#else
        // since glAlphaTest do not exists in OES, use a shader that writes
        // pixel only if greater than an alpha threshold
        GLProgram *program = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV);
        GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
        // set our alphaThreshold
        program->use();
        program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
        // we need to recursively apply this shader to all the nodes in the stencil node
        // XXX: we should have a way to apply shader to all nodes without having to do this
        setProgram(_stencil, program);
        
#endif

    }
    _stencil->visit(renderer, _modelViewTransform, dirty);

    _afterDrawStencilCmd.init(_globalZOrder);
    _afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
    renderer->addCommand(&_afterDrawStencilCmd);

    int i = 0;
    
    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for( ; i < _children.size(); i++ )
        {
            auto node = _children.at(i);
            
            if ( node && node->getLocalZOrder() < 0 )
                node->visit(renderer, _modelViewTransform, dirty);
            else
                break;
        }
        // self draw
        this->draw(renderer, _modelViewTransform, dirty);
        
        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
            (*it)->visit(renderer, _modelViewTransform, dirty);
    }
    else
    {
        this->draw(renderer, _modelViewTransform, dirty);
    }

    _afterVisitCmd.init(_globalZOrder);
    _afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this);
    renderer->addCommand(&_afterVisitCmd);

    renderer->popGroup();
    
    kmGLPopMatrix();
}
示例#20
0
 void Scale9Sprite::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
 {
     
     // quick return if not visible. children won't be drawn.
     if (!_visible)
     {
         return;
     }
     
     uint32_t flags = processParentFlags(parentTransform, parentFlags);
     
     // IMPORTANT:
     // To ease the migration to v3.0, we still support the Mat4 stack,
     // but it is deprecated and your code should not rely on it
     Director* director = Director::getInstance();
     CCASSERT(nullptr != director, "Director is null when seting matrix stack");
     director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
     director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
     
     int i = 0;      // used by _children
     int j = 0;      // used by _protectedChildren
     
     sortAllChildren();
     sortAllProtectedChildren();
     
     //
     // draw children and protectedChildren zOrder < 0
     //
     for( ; i < _children.size(); i++ )
     {
         auto node = _children.at(i);
         
         if ( node && node->getLocalZOrder() < 0 )
             node->visit(renderer, _modelViewTransform, flags);
         else
             break;
     }
     
     if (_scale9Enabled)
     {
         for( ; j < _protectedChildren.size(); j++ )
         {
             auto node = _protectedChildren.at(j);
             
             if ( node && node->getLocalZOrder() < 0 )
                 node->visit(renderer, _modelViewTransform, flags);
             else
                 break;
         }
     }
     else
     {
         if (_scale9Image && _scale9Image->getLocalZOrder() < 0 )
         {
             _scale9Image->visit(renderer, _modelViewTransform, flags);
         }
     }
     
     //
     // draw self
     //
     if (isVisitableByVisitingCamera())
         this->draw(renderer, _modelViewTransform, flags);
     
     //
     // draw children and protectedChildren zOrder >= 0
     //
     if (_scale9Enabled)
     {
         for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it)
             (*it)->visit(renderer, _modelViewTransform, flags);
     }
     else
     {
         if (_scale9Image && _scale9Image->getLocalZOrder() >= 0 )
         {
             _scale9Image->visit(renderer, _modelViewTransform, flags);
         }
     }
     
     
     for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
         (*it)->visit(renderer, _modelViewTransform, flags);
     
     // FIX ME: Why need to set _orderOfArrival to 0??
     // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
     // setOrderOfArrival(0);
     
     director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
     
 }
示例#21
0
void NodeGrid::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }
    
    _groupCommand.init(_globalZOrder);
    renderer->addCommand(&_groupCommand);
    renderer->pushGroup(_groupCommand.getRenderQueueID());

    bool dirty = parentTransformUpdated || _transformUpdated;
    if(dirty)
        _modelViewTransform = this->transform(parentTransform);
    _transformUpdated = false;

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);

    Director::Projection beforeProjectionType;
    if(_nodeGrid && _nodeGrid->isActive())
    {
        beforeProjectionType = Director::getInstance()->getProjection();
        _nodeGrid->set2DProjection();
    }

    _gridBeginCommand.init(_globalZOrder);
    _gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this);
    renderer->addCommand(&_gridBeginCommand);


    if(_gridTarget)
    {
        _gridTarget->visit(renderer, _modelViewTransform, dirty);
    }
    
    int i = 0;

    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for( ; i < _children.size(); i++ )
        {
            auto node = _children.at(i);

            if ( node && node->getLocalZOrder() < 0 )
                node->visit(renderer, _modelViewTransform, dirty);
            else
                break;
        }
        // self draw,currently we have nothing to draw on NodeGrid, so there is no need to add render command
        this->draw(renderer, _modelViewTransform, dirty);

        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) {
            (*it)->visit(renderer, _modelViewTransform, dirty);
        }
    }
    else
    {
        this->draw(renderer, _modelViewTransform, dirty);
    }
    
    // reset for next frame
    _orderOfArrival = 0;
    
    if(_nodeGrid && _nodeGrid->isActive())
    {
        // restore projection
        Director *director = Director::getInstance();
        director->setProjection(beforeProjectionType);
    }

    _gridEndCommand.init(_globalZOrder);
    _gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this);
    renderer->addCommand(&_gridEndCommand);

    renderer->popGroup();
 
    kmGLPopMatrix();
}
示例#22
0
bool LayerUserInfo::init()
{
    if(!BaseLayer::init())
    {
        return false;
    }
    
    auto root = CSLoader::createNode("LayerFriendDetails.csb");
    addChild(root);
    auto btnBack = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_back"));
    auto tmpImgIcon = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root, "image_user_avatar"));
    auto imgHead = ShaderSprite::createAndDownload("Default/image_defualt_user_icon_large.png", "Default/image_defualt_user_icon_large.png", "Default/image_mask_circle.png");
    imgHead->setPosition(tmpImgIcon->getPosition());
    root->addChild(imgHead, tmpImgIcon->getLocalZOrder());
    tmpImgIcon->removeFromParent();
    
    auto text_title= dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_title"));
    auto nickName = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_nick_name"));
    auto account = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_account"));
    auto spriteSex = dynamic_cast<Sprite*>(CSLoader::seekNodeByName(root, "sprite_sex"));
    auto textNickname = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_nike_name"));
    auto textAccount = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_account"));
    auto textSex = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_friend_session"));
    auto titleDiamond = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_diamond"));
    auto imgTextfieldBg = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root, "img_diamond_bg"));
    auto textfieldDiamond = dynamic_cast<TextField*>(CSLoader::seekNodeByName(root, "textfield_diamond"));
    mBtnConfirm = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_diamond"));
    
    text_title->setString(tools::local_string("personal_info","个人资料"));
    nickName->setString(tools::local_string("nickname","昵称"));
    account->setString(tools::local_string("account","账号"));
    mBtnConfirm->setTitleText(tools::local_string("confirm_change_password","确定"));
    titleDiamond->setString(tools::local_string("give_diamond","赠送钻石"));
    mCheckboxHiteMoments = dynamic_cast<CheckBox*>(CSLoader::seekNodeByName(root, "checkbox_friend_session"));
    mBtnSendMsg = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_send_message"));
    mBtnDeleteFriend = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_delete_friend"));
    
    btnBack->addClickEventListener([&](Ref *ref)
    {
        if(IsInvitation)
        {
            auto layer = dynamic_cast<LayerInvitationList*>(this->getParent());
            if(layer)
            {
                layer->refresh_deal_data();
            }
        }
        this->removeFromParent();
    });
    imgHead->setSpriteTexture(mInfo.picname());
    spriteSex->setTexture(mInfo.sex() == msg::Sex::MALE ? gMaleIcon : gFemaleIcon);
    textSex->setString(mInfo.sex() == msg::Sex::MALE ? tools::local_string("block_his_moment", "屏蔽他的朋友圈") : tools::local_string("block_her_moment", "屏蔽她的朋友圈"));
    textNickname->setString(mInfo.nickname());
    spriteSex->setPositionX(textNickname->getPositionX() - textNickname->getContentSize().width - 30);
    textAccount->setString(tools::to_string(mInfo.userid()));
    mCheckboxHiteMoments->setSelected(false);
    setCheckBoxTextures(mCheckboxHiteMoments);
    mCheckboxHiteMoments->addClickEventListener([&](Ref *ref)
    {
        auto checkbox = dynamic_cast<CheckBox*>(ref);
        bool isSelect = checkbox->isSelected();
        
        
        
        int userId = mInfo.userid();
        log("屏蔽userId = %d", userId);
        auto processor = PM->BlockUser_up(userId, isSelect);
        send_data(processor, REQ_SHIELD_FRIEND);
    });
    mEditboxtDiamond = GameTools::createEditBoxFromTextField(imgTextfieldBg, textfieldDiamond);
    mEditboxtDiamond->setInputMode(EditBox::InputMode::NUMERIC);
    mEditboxtDiamond->setReturnType(EditBox::KeyboardReturnType::DONE);
    mEditboxtDiamond->setMaxLength(10);
    mEditboxtDiamond->setFontColor(Color3B::WHITE);
    mEditboxtDiamond->setPlaceHolder("0");
    mEditboxtDiamond->setDelegate(this);
    
    mBtnConfirm->addClickEventListener([&](Ref *ref){
        
        log("send Diamond: %s, len = %d", mEditboxtDiamond->getText(), strlen(mEditboxtDiamond->getText()));
        if(strlen(mEditboxtDiamond->getText()) <= 0 || !GameTools::isRegexMath(mEditboxtDiamond->getText(), GameTools::INPUT_TYPE::NUMBER))
        {
            Toast::ToastShow(tools::local_string("input_whole","只支持数字"));
            return;
        }
        GameTools::editBoxLoseInputFocus();
        requestDiamond();
        
    });
    //处理搜索消息
    if(!IsInvitation)
        InitNormal();
    else
    {
        
        //处理请求消息
        mBtnSendMsg->setTitleText(tools::local_string("operate", "同意"));
        mBtnSendMsg->addClickEventListener([&](Ref *ref)
                                          {
                                              sendInvitationFriend(true);
                                          });
        mBtnDeleteFriend->setTitleText(tools::local_string("disagree_friend_request", "拒绝"));
        mBtnDeleteFriend->addClickEventListener([&](Ref *ref)
                                          {
                                              sendInvitationFriend(false);
                                          });
        
    }
    send_data(PM->null_up(), REQ_MOMENT_BLOCK_LIST);//每次都请求已屏蔽的朋友圈列表
    return true;
}
示例#23
0
文件: CCLabel.cpp 项目: wade0317/Calc
void Label::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
    if (! _visible || (_utf8Text.empty() && _children.empty()) )
    {
        return;
    }
    
    if (_systemFontDirty || _contentDirty)
    {
        updateContent();
    }
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);

    if (!_utf8Text.empty() && _shadowEnabled && (_shadowDirty || (flags & FLAGS_DIRTY_MASK)))
    {
        _position.x += _shadowOffset.width;
        _position.y += _shadowOffset.height;
        _transformDirty = _inverseDirty = true;

        _shadowTransform = transform(parentTransform);

        _position.x -= _shadowOffset.width;
        _position.y -= _shadowOffset.height;
        _transformDirty = _inverseDirty = true;

        _shadowDirty = false;
    }

    bool visibleByCamera = isVisitableByVisitingCamera();
    if (_children.empty() && !_textSprite && !visibleByCamera)
    {
        return;
    }

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    _director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    _director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    if (!_children.empty())
    {
        sortAllChildren();

        int i = 0;
        // draw children zOrder < 0
        for (; i < _children.size(); i++)
        {
            auto node = _children.at(i);

            if (node && node->getLocalZOrder() < 0)
                node->visit(renderer, _modelViewTransform, flags);
            else
                break;
        }
        
        this->drawSelf(visibleByCamera, renderer, flags);

        for (auto it = _children.cbegin() + i; it != _children.cend(); ++it)
        {
            (*it)->visit(renderer, _modelViewTransform, flags);
        }
            
    }
    else
    {
        this->drawSelf(visibleByCamera, renderer, flags);
    }

    _director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
//裁切
void CNFServerChangeScrollLayer::visit(Renderer *renderer, const Mat4& parentTransform, uint32_t parentFlags)
{
    if (!_visible)
    {
        return;
    }
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);
    
    
    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    Director* director = Director::getInstance();
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    bool visibleByCamera = isVisitableByVisitingCamera();
    
 
    
    
    glEnable(GL_SCISSOR_TEST);
    
    Size size=Director::getInstance()->getOpenGLView()->getFrameSize();
    
    float fScaleX=size.width/SCREEN_WIDTH;
    float fScaleY=size.height/SCREEN_HEIGHT;
    
    glScissor(m_DisPlayRect.origin.x*fScaleX,m_DisPlayRect.origin.y*fScaleY,m_DisPlayRect.size.width*fScaleX,m_DisPlayRect.size.height*fScaleY);
    
    
    
    int i = 0;
    
    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for( ; i < _children.size(); i++ )
        {
            auto node = _children.at(i);
            
            if ( node && node->getLocalZOrder() < 0 )
                node->visit(renderer, _modelViewTransform, flags);
            else
                break;
        }
        // self draw
        if (visibleByCamera)
            this->draw(renderer, _modelViewTransform, flags);
        
        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
            (*it)->visit(renderer, _modelViewTransform, flags);
    }
    else if (visibleByCamera)
    {
        this->draw(renderer, _modelViewTransform, flags);
    }
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    
    glDisable(GL_SCISSOR_TEST);
    
   
}
void ProtectedNode::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }

    uint32_t flags = processParentFlags(parentTransform, parentFlags);

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    CCASSERT(nullptr != _director, "Director is null when setting matrix stack");
    _director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    _director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);

    int i = 0;      // used by _children
    int j = 0;      // used by _protectedChildren

    sortAllChildren();
    sortAllProtectedChildren();

    //
    // draw children and protectedChildren zOrder < 0
    //
    for( ; i < _children.size(); i++ )
    {
        auto node = _children.at(i);

        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, flags);
        else
            break;
    }

    for( ; j < _protectedChildren.size(); j++ )
    {
        auto node = _protectedChildren.at(j);

        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, flags);
        else
            break;
    }

    //
    // draw self
    //
    draw(renderer, _modelViewTransform, flags);

    //
    // draw children and protectedChildren zOrder >= 0
    //
    for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, flags);

    for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, flags);

    _director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
示例#26
0
void ProtectedNode::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }
    
    bool dirty = _transformUpdated || parentTransformUpdated;
    if(dirty)
        _modelViewTransform = this->transform(parentTransform);
    _transformUpdated = false;
    
    
    // IMPORTANT:
    // To ease the migration to v3.0, we still support the kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);
    
    int i = 0;      // used by _children
    int j = 0;      // used by _protectedChildren
    
    sortAllChildren();
    sortAllProtectedChildren();
    
    //
    // draw children and protectedChildren zOrder < 0
    //
    for( ; i < _children.size(); i++ )
    {
        auto node = _children.at(i);
        
        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, dirty);
        else
            break;
    }
    
    for( ; j < _protectedChildren.size(); j++ )
    {
        auto node = _protectedChildren.at(j);
        
        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, dirty);
        else
            break;
    }
    
    //
    // draw self
    //
    this->draw(renderer, _modelViewTransform, dirty);
    
    //
    // draw children and protectedChildren zOrder >= 0
    //
    for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, dirty);
    
    for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, dirty);
    
    // reset for next frame
    _orderOfArrival = 0;
    
    kmGLPopMatrix();
}
示例#27
0
void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
    if (!_visible || !hasContent())
        return;
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when setting matrix stack");
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);

    //Add group command
        
    _groupCommand.init(_globalZOrder);
    renderer->addCommand(&_groupCommand);

    renderer->pushGroup(_groupCommand.getRenderQueueID());

    _beforeVisitCmd.init(_globalZOrder);
    _beforeVisitCmd.func = CC_CALLBACK_0(StencilStateManager::onBeforeVisit, _stencilStateManager);
    renderer->addCommand(&_beforeVisitCmd);
    
    auto alphaThreshold = this->getAlphaThreshold();
    if (alphaThreshold < 1)
    {
#if CC_CLIPPING_NODE_OPENGLES
        // since glAlphaTest do not exists in OES, use a shader that writes
        // pixel only if greater than an alpha threshold
        GLProgram *program = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV);
        GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
        // set our alphaThreshold
        program->use();
        program->setUniformLocationWith1f(alphaValueLocation, alphaThreshold);
        // we need to recursively apply this shader to all the nodes in the stencil node
        // FIXME: we should have a way to apply shader to all nodes without having to do this
        setProgram(_stencil, program);
#endif

    }
    _stencil->visit(renderer, _modelViewTransform, flags);

    _afterDrawStencilCmd.init(_globalZOrder);
    _afterDrawStencilCmd.func = CC_CALLBACK_0(StencilStateManager::onAfterDrawStencil, _stencilStateManager);
    renderer->addCommand(&_afterDrawStencilCmd);

    int i = 0;
    bool visibleByCamera = isVisitableByVisitingCamera();
    
    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for(auto size = _children.size(); i < size; ++i)
        {
            auto node = _children.at(i);
            
            if ( node && node->getLocalZOrder() < 0 )
                node->visit(renderer, _modelViewTransform, flags);
            else
                break;
        }
        // self draw
        if (visibleByCamera)
            this->draw(renderer, _modelViewTransform, flags);

        for(auto it=_children.cbegin()+i, itCend = _children.cend(); it != itCend; ++it)
            (*it)->visit(renderer, _modelViewTransform, flags);
    }
    else if (visibleByCamera)
    {
        this->draw(renderer, _modelViewTransform, flags);
    }

    _afterVisitCmd.init(_globalZOrder);
    _afterVisitCmd.func = CC_CALLBACK_0(StencilStateManager::onAfterVisit, _stencilStateManager);
    renderer->addCommand(&_afterVisitCmd);

    renderer->popGroup();
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
示例#28
0
// on "init" you need to initialize your instance
bool RelayGameLayer::init()
{
	//////////////////////////////
	// 1. super init first
	if (!GridLayer::init())
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	_SetDefaultValues();


	//-----------------------------------------------------
	// 背景
	auto spriteBack = Sprite::create("MainBackAll.png");
	if(spriteBack)
	{
		// add "canvas" splash screen"

		spriteBack->setScale(
			this->getContentSize().width / spriteBack->getContentSize().width,
			this->getContentSize().height / spriteBack->getContentSize().height);
		// position the sprite on the center of the screen
		spriteBack->setPosition(
			origin.x + visibleSize.width / 2.f + origin.x,
			origin.y + visibleSize.height / 2.f + origin.y);

		spriteBack->setName("Back");

		// add the sprite as a child to this layer
		this->addChild(spriteBack, ZOrder::BACK);
	}

	//-----------------------------------------------------
	// キャンバス
	auto layerCanvas = LayerCanvas::create();
	if (layerCanvas && layerCanvas->createSprite("canvas.png"))
	{
		this->addChild(layerCanvas, ZOrder::CANVAS, "Canvas");

		layerCanvas->setPosition(
			origin + visibleSize / 2.f
			);
		layerCanvas->setVisible(false);

	}
	//-----------------------------------------------------
	// テーマ発表用
	auto spriteBoard = Sprite::create("BigBoard.png");
	if (spriteBoard)
	{
		spriteBoard->setPosition(
			origin + visibleSize/ 2.f
			);
		spriteBack->setVisible(true);		// 非表示
		this->addChild(spriteBoard, ZOrder::BIGBOARD, "BigBoard");
		auto size = spriteBoard->getContentSize();
		// 表示ラベル設定 余白 x:90*y:60
		// 上
		auto labelTop = Label::createWithSystemFont("描く順番と解答者の発表です", "GenShinGothic-Regular.ttf", calcFontSize(40.f));
		if (labelTop)
		{
			// 中央揃え上揃え
			labelTop->setAlignment(TextHAlignment::CENTER, TextVAlignment::TOP);

			labelTop->setPosition(
				size.width / 2.f,
				size.height - labelTop->getContentSize().height/2.f - 60.f
				);

			spriteBoard->addChild(labelTop, 0, "TopLabel");
		}
		// 中央
		auto labelMiddle = Label::createWithSystemFont("", "GenShinGothic-Medium.ttf", calcFontSize(80.f));
		labelMiddle->setName("MiddleLabel");
		auto itemLabel = MenuItemLabel::create(labelMiddle, [this](Ref* pSender){
			// 検索窓開く
			std::stringstream url;
			url << "https://www.google.co.jp/search?tbm=isch&q=" << m_nowTheme.theme;
			Application::getInstance()->openURL(url.str().c_str());
		});
		if (itemLabel)
		{
			m_pMiddleLabel = itemLabel;
			// 始めのうちは反応なし
			m_pMiddleLabel->setEnabled(false);
			// 中央揃え中央揃え
			labelMiddle->setAlignment(TextHAlignment::CENTER, TextVAlignment::BOTTOM);

			labelMiddle->setColor(Color3B(250, 210, 10));
			m_pMiddleLabel->setColor(Color3B(250, 210, 10));


			labelMiddle->setDimensions(size.width - 90, 0);
			m_pMiddleLabel->setName("ItemMiddleLabel");
			auto menu = Menu::create(m_pMiddleLabel, nullptr);
			menu->setPosition(
				size / 2.f
				);
			spriteBoard->addChild(menu, 0, "MenuMiddleLabel");
		}
		// 下
		auto labelBottom = Label::createWithSystemFont("1人目の人から順に\n画面をタッチしてください", "GenShinGothic-Regular.ttf", calcFontSize(37.f));
		if (labelBottom)
		{
			// 中央揃え下揃え
			labelBottom->setAlignment(TextHAlignment::CENTER, TextVAlignment::BOTTOM);

			labelBottom->setAnchorPoint(Vec2(0.5f, 0.0f));

			labelBottom->setPosition(
				size.width / 2.f,
				labelBottom->getContentSize().height / 2.f + 60.f
				);

			spriteBoard->addChild(labelBottom, 0, "BottomLabel");
		}
	}

	//-----------------------------------------------------
	// ラベル用
	auto spriteSmallBoard = Sprite::create("board.png");
	if (spriteSmallBoard)
	{
		spriteSmallBoard->setPosition(
			origin.x + visibleSize.width / 2.f,
			origin.y + visibleSize.height - spriteSmallBoard->getContentSize().height / 2.f
			);
		this->addChild(spriteSmallBoard, ZOrder::TOPBOARD, "SmallBoard");
	}



	//-----------------------------------------------------
	// ラベル設定
	// アナウンス
	auto label = Label::createWithSystemFont(" ", "GenShinGothic-Medium.ttf", calcFontSize(30.f));
	{
		label->setColor(Color3B(250, 250, 250));	// 白文字
		label->enableOutline(Color4B::BLACK, 3);	// 黒枠線

		label->setHorizontalAlignment(TextHAlignment::CENTER);
		spriteSmallBoard->addChild(label, 10, "Label");
		label->setPosition(spriteSmallBoard->getAnchorPointInPoints());
		m_pLabel = label;			// キャッシュ
	}
	//-----------------------------------------------------


	//-----------------------------------------------------
	// ボタン
	auto nextButton = MenuItemImage::create("button.png",
											"button2.png",
											[this](Ref* pSender)
	{
		if (FlowPhase::ANSWERED == m_flowPhase)
		{
			// タイトルへ
			dynamic_cast<SceneAtelierMain*>(this->getParent()->getParent())->toTitle();
		}
		else
		{
			// 全消去
			m_touchPoints[m_nowPage].clear();
			m_pDrawNode->clear();
		}
	});
	if (nextButton)
	{
		m_pNextButton = nextButton;
		nextButton->setName("NextButton");
		// ボタン非表示
		//nextButton->setVisible(false);
		auto size = nextButton->getContentSize();
		nextButton->setPosition(
			origin.x + visibleSize.width - size.width / 2.f,
			origin.y + size.height / 2.f);
		auto label = Label::createWithSystemFont("全消去", "GenShinGothic-Medium.ttf", calcFontSize(20.f));
		if (label)
		{
			m_pButtonLabel = label;
			label->setPosition(nextButton->getContentSize() / 2.f);
			label->setHorizontalAlignment(TextHAlignment::CENTER);
			// ラベル非表示
			//label->setVisible(false);
			label->setColor(Color3B(5, 5, 5));
			nextButton->addChild(label, ZOrder::NEXTBUTTONLABEL, "ButtonLabel");
	
		}
	}


	auto menuButtons = Menu::create(nextButton, nullptr);
	if (menuButtons)
	{
		menuButtons->setPosition(Vec2::ZERO);
		menuButtons->setVisible(false);
		this->addChild(menuButtons, ZOrder::MENUBUTTONS, "MenuButtons");
	}


	//-----------------------------------------------------
	// 前後ボタン
	// 前
	auto itemBack = MenuItemImage::create("BackButton.png",
										  "BackButton2.png",
										  [this](Ref* pSender){

		auto button = dynamic_cast<MenuItemImage*>(pSender);
		if (0 < m_nowPage)
		{
			// 戻るよ!
			auto oldCanvas = this->getChildByName("Canvas");
			if (!oldCanvas)
				oldCanvas = this->getChildByName("Canvas" + std::to_string(m_nowPage));



			--m_nowPage;
			std::stringstream ss;
			ss << "Canvas" << m_nowPage;
			auto layerCanvas = this->getChildByName(ss.str());
			layerCanvas->setLocalZOrder(oldCanvas->getLocalZOrder() + 1);
			auto drawNode = layerCanvas->getChildByName<DrawNode*>("DrawNode");
			layerCanvas->setVisible(true);
			layerCanvas->runAction(
				Sequence::create(
					ReverseTime::create(PageTurn3D::create(0.5f, Size(24.f, 32.f))),
					CallFunc::create([this, layerCanvas, drawNode](){
						// キャンバスの入れ替え
						
						//--------------------------
						// DrawNode入れ替え
						m_pDrawNode = drawNode;
						//--------------------------
					}),
					nullptr
				)
			);

			if (0 == m_nowPage)
			{
				// もう戻れないよ!
				button->setVisible(false);
			}
			button->getParent()->getChildByName("LastNextButton")->setVisible(true);
		}
	
	});
	{
		itemBack->setName("LastBackButton");
	}
	auto itemNext = MenuItemImage::create("NextButton.png",
										  "NextButton2.png",
										  [this](Ref* pSender){
		auto button = dynamic_cast<MenuItemImage*>(pSender);
		const auto maxPage = m_touchPoints.size() - 1;
		if (maxPage > m_nowPage)
		{
			// 進むよ!
			auto oldCanvas = this->getChildByName("Canvas");
			if (!oldCanvas)
				oldCanvas = this->getChildByName("Canvas" + std::to_string(m_nowPage));


			++m_nowPage;
			std::stringstream ss;
			ss << "Canvas" << m_nowPage;
			auto layerCanvas = this->getChildByName(ss.str());
			layerCanvas->setLocalZOrder(oldCanvas->getLocalZOrder() - 1);
			auto drawNode = layerCanvas->getChildByName<DrawNode*>("DrawNode");
			layerCanvas->setVisible(true);
			
			oldCanvas->runAction(
				Sequence::create(
					PageTurn3D::create(0.5f, Size(24.f, 32.f)),
					CallFunc::create([this, layerCanvas, drawNode](){
						// キャンバスの入れ替え
						
						//--------------------------
						// DrawNode入れ替え
						m_pDrawNode = drawNode;
						//--------------------------
					}),
					nullptr
				)
			);

			if (maxPage == m_nowPage)
			{
				// もう進めないよ!
				button->setVisible(false);
			}
			button->getParent()->getChildByName("LastBackButton")->setVisible(true);
		}

	});
	{
		itemNext->setName("LastNextButton");
		itemNext->setVisible(false);
	}
	auto menuLastButtons = Menu::create(itemBack, itemNext, nullptr);
	{
		// 縦一列,間隔
		const float padding = 10.f;
		menuLastButtons->alignItemsVerticallyWithPadding(padding);

		// 非表示
		menuLastButtons->setVisible(false);

		auto canvas = layerCanvas->getSprite();
		Vec2 leftBottom = canvas->convertToWorldSpace(Vec2::ZERO);

		auto size = itemBack->getContentSize();
		menuLastButtons->setPosition(leftBottom.x / 2.f,
									 leftBottom.y + size.height + padding / 2.f);

		this->addChild(menuLastButtons, ZOrder::MENULASTBUTTONS, "MenuLastButtons");
	}
	//-----------------------------------------------------
	m_pDrawNode = DrawNode::create();
	{
		m_pDrawNode->setAnchorPoint(Vec2::ZERO);
		auto canvas = layerCanvas->getSprite();
		//layerCanvas->addChild(m_pDrawNode, 1);
		m_pDrawNode->setPosition(
			-(layerCanvas->getPositionX() - layerCanvas->getAnchorPoint().x*layerCanvas->getContentSize().width ),
			-(layerCanvas->getPositionY() - layerCanvas->getAnchorPoint().y*layerCanvas->getContentSize().height)
			);
		canvas->addChild(m_pDrawNode, 1, "DrawNode");
	}


	//-----------------------------------------------------
	// 描きすぎレイヤー
	auto layerTouch = Layer::create();
	{
		layerTouch->setVisible(false);

		auto sprite = Sprite::create();	// 背景用
		sprite->setTextureRect(Rect(0, 0, visibleSize.width, visibleSize.height));
		sprite->setPosition(visibleSize / 2.f);
		sprite->setColor(Color3B::BLACK);
		sprite->setOpacity(192);
		layerTouch->addChild(sprite, 0);

		this->addChild(layerTouch, ZOrder::MOST_FRONT, "OverTouchLayer");
		auto label = Label::createWithSystemFont("一人の持ち時間を使い果たしました\n"
												 "\n次の人に回してタッチしてください\n",
												 "GenShinGothic-Medium.ttf", calcFontSize(40.f));
		{
			label->setPosition(layerTouch->getContentSize() / 2.f);
			label->setAlignment(TextHAlignment::CENTER, TextVAlignment::CENTER);
			label->setColor(Color3B(250, 250, 15));
			layerTouch->addChild(label, 10, "Label");
		}

		auto listener = EventListenerTouchOneByOne::create();
		listener->setSwallowTouches(false);
		listener->onTouchBegan = [this, layerTouch](Touch* touch, Event* event){
			if (layerTouch->isVisible())
			{
				return true;
			}
			return false;
		};
		listener->onTouchEnded = [this, layerTouch](Touch* touch, Event* event){
			//layerTouch->setVisible(false);
			//m_pListener->setSwallowTouches(false);
			// 描きすぎレイヤー非表示
			this->_SetOverTouchLayerVisible(false);
			if (m_nowPage >= m_playerNum - 2)
			{
				// 全員描いた場合
				// キャンバスめくらない
				m_flowPhase = FlowPhase::JUDGE;

				// 解答ボックス出現
				auto visibleSize = Director::getInstance()->getVisibleSize();
				m_pEditBox->runAction(
					Sequence::create(
						CallFunc::create([this]{ m_pEditBox->setEnabled(false); }),
						EaseBackOut::create(
							MoveTo::create(0.5f,
								Vec2(visibleSize.width / 2.f,
								m_pEditBox->getPositionY()
								)	// 画面中央まで
							)
						),
						CallFunc::create([this]{ m_pEditBox->setEnabled(true); }),
						nullptr
					)
				);

				// 全消去無効化
				m_pNextButton->setVisible(false);


				// ラベルの設定
				m_pLabel->setString("テーマを答えてください");

			}
			else
			{
				// 前の人の絵を見せる
				m_flowPhase = FlowPhase::SHOW;
				m_pLabel->setString("見終わったらタッチして描き始めてください");
			}

			// 全員描いた場合
			//if (m_nowPage >= m_playerNum - 1)
			//{
			//	// フェーズ
			//	m_flowPhase = FlowPhase::JUDGE;
			//
			//	// 解答ボックス出現
			//	auto visibleSize = Director::getInstance()->getVisibleSize();
			//	m_pEditBox->runAction(
			//		Sequence::create(
			//			CallFunc::create([this]{ m_pEditBox->setEnabled(false); }),
			//			EaseBackOut::create(
			//				MoveTo::create(0.5f,
			//					Vec2(visibleSize.width / 2.f,
			//					m_pEditBox->getPositionY()
			//					)	// 画面中央まで
			//				)
			//			),
			//			CallFunc::create([this]{ m_pEditBox->setEnabled(true); }),
			//			nullptr
			//		)
			//	);
			//
			//	// ラベルの設定
			//	m_pLabel->setString("テーマを答えてください");
			//
			//
			//}

		};
		this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, layerTouch);
		m_pListener = listener;
	}

	
	//-----------------------------------------------------
	// 解答入力ボックス
	m_pEditBox = EditBox::create(spriteSmallBoard->getContentSize(), Scale9Sprite::create("board.png"));
	{
		// box
		auto size = m_pEditBox->getContentSize();
		m_pEditBox->setPreferredSize(spriteSmallBoard->getContentSize());
		m_pEditBox->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
		m_pEditBox->setPosition(Vec2(
			origin.x + visibleSize.width + size.width / 2.f,
			origin.y + size.height / 2.f));
		//m_pEditBox->setPosition(Vec2(
		//	origin.x + visibleSize.width / 2.f,
		//	origin.y + size.height / 2.f));
		// 内部ラベル
		m_pEditBox->setFontName("GenShinGothic-Regular.ttf");	// ファミリー
		m_pEditBox->setFontSize(static_cast<int>(calcFontSize(25.f)));		// サイズ
		m_pEditBox->setFontColor(Color3B(250, 250, 250));				// 色
		m_pEditBox->getLabel()->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
		m_pEditBox->getLabel()->setPosition(spriteSmallBoard->getContentSize() / 2.f);
		// 初期ラベル
		m_pEditBox->setPlaceHolder("ここをタッチして解答 (全てひらがなで、数字は半角で入力)");	// 例等初期値(入力時に消える)
		m_pEditBox->setPlaceholderFontColor(Color3B(5, 5, 5));
		m_pEditBox->getPlaceHolderLabel()->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
		m_pEditBox->getPlaceHolderLabel()->setPosition(spriteSmallBoard->getContentSize() / 2.f);

		// Box自体の設定
		m_pEditBox->setMaxLength(20);	// 文字数
		m_pEditBox->setReturnType(EditBox::KeyboardReturnType::DEFAULT);	// Returnキーが押された時
		m_pEditBox->setInputMode(EditBox::InputMode::SINGLE_LINE);			// 1行,自由文字列

		// メソッド
		m_pEditBox->setDelegate(this);

		this->addChild(m_pEditBox, ZOrder::BOX, "EditBox");
	}
	
	//-----------------------------------------------------
	// 間違え
	auto spriteCrossCanvas = Sprite::create("CrossCanvas.png");
	{
		spriteCrossCanvas->setPosition(visibleSize / 2.f);
		spriteCrossCanvas->setVisible(false);
		this->addChild(spriteCrossCanvas, ZOrder::MOST_FRONT, "CrossCanvas");
	}
	//-----------------------------------------------------
	// 正解
	auto spriteCircleCanvas = Sprite::create("CircleCanvas.png");
	{
		spriteCircleCanvas->setPosition(visibleSize / 2.f);
		spriteCircleCanvas->setVisible(false);
		this->addChild(spriteCircleCanvas, ZOrder::MOST_FRONT, "CircleCanvas");
	}


	return true;
}
示例#29
0
void Layout::stencilClippingVisit(Renderer *renderer, const Mat4& parentTransform, uint32_t parentFlags)
{
    if(!_visible)
        return;
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when seting matrix stack");
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    //Add group command

    _groupCommand.init(_globalZOrder);
    renderer->addCommand(&_groupCommand);
    
    renderer->pushGroup(_groupCommand.getRenderQueueID());
    
    _beginStencilCommand.init(_globalZOrder, false, 1, _clippingStencil);
    renderer->addCommand(&_beginStencilCommand);
    
    _clippingStencil->visit(renderer, _modelViewTransform, flags);
    
    _afterStencilCommand.init(_globalZOrder);
    renderer->addCommand(&_afterStencilCommand);
    
    int i = 0;      // used by _children
    int j = 0;      // used by _protectedChildren
    
    sortAllChildren();
    sortAllProtectedChildren();
    
    //
    // draw children and protectedChildren zOrder < 0
    //
    for( ; i < _children.size(); i++ )
    {
        auto node = _children.at(i);
        
        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, flags);
        else
            break;
    }
    
    for( ; j < _protectedChildren.size(); j++ )
    {
        auto node = _protectedChildren.at(j);
        
        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, flags);
        else
            break;
    }
    
    //
    // draw self
    //
    this->draw(renderer, _modelViewTransform, flags);
    
    //
    // draw children and protectedChildren zOrder >= 0
    //
    for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, flags);
    
    for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, flags);

    
    _endStencilCommand.init(_globalZOrder);
    renderer->addCommand(&_endStencilCommand);
    
    renderer->popGroup();
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
void ProtectedNode::visit(Renderer* renderer, const Matrix &parentTransform, bool parentTransformUpdated)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }
    
    bool dirty = _transformUpdated || parentTransformUpdated;
    if(dirty)
        _modelViewTransform = this->transform(parentTransform);
    _transformUpdated = false;
    
    
    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Matrix stack,
    // but it is deprecated and your code should not rely on it
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when seting matrix stack");
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    int i = 0;      // used by _children
    int j = 0;      // used by _protectedChildren
    
    sortAllChildren();
    sortAllProtectedChildren();
    
    //
    // draw children and protectedChildren zOrder < 0
    //
    for( ; i < _children.size(); i++ )
    {
        auto node = _children.at(i);
        
        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, dirty);
        else
            break;
    }
    
    for( ; j < _protectedChildren.size(); j++ )
    {
        auto node = _protectedChildren.at(j);
        
        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, dirty);
        else
            break;
    }
    
    //
    // draw self
    //
    this->draw(renderer, _modelViewTransform, dirty);
    
    //
    // draw children and protectedChildren zOrder >= 0
    //
    for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, dirty);
    
    for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, dirty);
    
    // reset for next frame
    _orderOfArrival = 0;
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}