Exemplo n.º 1
0
/*
Ham xay dung noi dung cua dialog
*/
void SkillDetailDialog::createDisplaySkillInfo(Sprite* parent)
{
	// Create skill image
	auto skillImage = Sprite::create(_skillInfo.imagePath);
	skillImage->setPosition(Vec2(skillImage->getContentSize().width + 40, parent->getContentSize().height / 2));
	skillImage->setScale(2.0f);
	parent->addChild(skillImage);

	std::stringstream info;
	info << "Name : " << _skillInfo.name << "\nId: " << _skillInfo.id << "\nMP: " << _skillInfo.mp_cost;
	_statusLabel = LabelTTF::create(info.str().c_str(), "fonts/arial.ttf", 30);
	_statusLabel->setColor(Color3B::RED);
	_statusLabel->setHorizontalAlignment(TextHAlignment::LEFT);

	// create scroll view info
	if (_statusLabel->getContentSize().height > (parent->getContentSize().height - 200))
	{
		// Create scroll
		auto scrollInfo = extension::ScrollView::create();
		scrollInfo->setDirection(extension::ScrollView::Direction::VERTICAL); // cho scroll di chuyen theo chieu doc
		scrollInfo->setViewSize(Size(parent->getContentSize().width / 2, 300));
		scrollInfo->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
		scrollInfo->setPosition(Vec2(parent->getContentSize().width / 2 - 70, 30));
		scrollInfo->updateInset();
		scrollInfo->setVisible(true);
		parent->addChild(scrollInfo);

		// Add layer to scroll
		auto layer = Layer::create();
		layer->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
		layer->setContentSize(Size(parent->getContentSize().width / 2, _statusLabel->getContentSize().height + 50));
		layer->setPosition(Vec2(0, -(layer->getContentSize().height / 2)));

		scrollInfo->setContainer(layer);

		// Add _statusLabel to layer
		auto height = layer->getContentSize().height;
		scrollInfo->setContentOffset(scrollInfo->minContainerOffset());
		_statusLabel->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
		_statusLabel->setPosition(Vec2(0, height - 20));
		layer->addChild(_statusLabel);
	}
	else
	{
		_statusLabel->setPosition(Vec2(parent->getContentSize().width / 2 - 70, parent->getContentSize().height - 100));
		_statusLabel->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);

		parent->addChild(_statusLabel);
	}
}
Exemplo n.º 2
0
CCPoint CCScrollView::getNodeFullyVisibleOffset(CCNode* node) {
    // get node bound in container
    CCRect nodeBound = CCRectMake(0, 0, node->getContentSize().width, node->getContentSize().height);
    CCAffineTransform t = node->nodeToAncestorTransform(getContainer());
    nodeBound = CCRectApplyAffineTransform(nodeBound, t);
    
    // get offset
    float scale = getZoomScale();
    CCPoint offset = ccp(-nodeBound.origin.x / scale, -nodeBound.origin.y / scale);
    
    // clamp offset
    const CCPoint minOffset = minContainerOffset();
    const CCPoint maxOffset = maxContainerOffset();
    offset.x = MAX(minOffset.x, MIN(maxOffset.x, offset.x));
    offset.y = MAX(minOffset.y, MIN(maxOffset.y, offset.y));
    
    // return
    return offset;
}
Exemplo n.º 3
0
void ScrollView::onTouchMoved(Touch* touch, Event* event)
{
    if (!this->isVisible())
    {
        return;
    }

    if (std::find(_touches.begin(), _touches.end(), touch) != _touches.end())
    {
        if (_touches.size() == 1 && _dragging)
        { // scrolling
            Vec2 moveDistance, newPoint;
            Rect  frame;
            float newX, newY;
            
            frame = getViewRect();

            newPoint     = this->convertTouchToNodeSpace(_touches[0]);
            moveDistance = newPoint - _touchPoint;
            
            float dis = 0.0f;
            if (_direction == Direction::VERTICAL)
            {
                dis = moveDistance.y;
                float pos = _container->getPosition().y;
                if (!(minContainerOffset().y <= pos && pos <= maxContainerOffset().y)) {
                    moveDistance.y *= BOUNCE_BACK_FACTOR;
                }
            }
            else if (_direction == Direction::HORIZONTAL)
            {
                dis = moveDistance.x;
                float pos = _container->getPosition().x;
                if (!(minContainerOffset().x <= pos && pos <= maxContainerOffset().x)) {
                    moveDistance.x *= BOUNCE_BACK_FACTOR;
                }
            }
            else
            {
                dis = sqrtf(moveDistance.x*moveDistance.x + moveDistance.y*moveDistance.y);
                
                float pos = _container->getPosition().y;
                if (!(minContainerOffset().y <= pos && pos <= maxContainerOffset().y)) {
                    moveDistance.y *= BOUNCE_BACK_FACTOR;
                }
                
                pos = _container->getPosition().x;
                if (!(minContainerOffset().x <= pos && pos <= maxContainerOffset().x)) {
                    moveDistance.x *= BOUNCE_BACK_FACTOR;
                }
            }

            if (!_touchMoved && fabs(convertDistanceFromPointToInch(dis)) < MOVE_INCH )
            {
                //CCLOG("Invalid movement, distance = [%f, %f], disInch = %f", moveDistance.x, moveDistance.y);
                return;
            }
            
            if (!_touchMoved)
            {
                moveDistance = Vec2::ZERO;
            }
            
            _touchPoint = newPoint;
            _touchMoved = true;
            
            if (_dragging)
            {
                switch (_direction)
                {
                    case Direction::VERTICAL:
                        moveDistance = Vec2(0.0f, moveDistance.y);
                        break;
                    case Direction::HORIZONTAL:
                        moveDistance = Vec2(moveDistance.x, 0.0f);
                        break;
                    default:
                        break;
                }

                newX     = _container->getPosition().x + moveDistance.x;
                newY     = _container->getPosition().y + moveDistance.y;

                _scrollDistance = moveDistance;
                this->setContentOffset(Vec2(newX, newY));
            }
        }
        else if (_touches.size() == 2 && !_dragging)
        {
            const float len = _container->convertTouchToNodeSpace(_touches[0]).getDistance(
                                            _container->convertTouchToNodeSpace(_touches[1]));
            this->setZoomScale(this->getZoomScale()*len/_touchLength);
        }
    }
}