Example #1
0
void NDUITableLayer::MoveSection(unsigned int sectionIndex, int moveLen)
{
    if (moveLen == 0)
        return;

    NDUISectionTitle* sectionTitle = m_sectionTitles.at(sectionIndex);
    CGRect sectionRect = sectionTitle->GetFrameRect();
    sectionTitle->SetFrameRect(CGRectMake(sectionRect.origin.x, sectionRect.origin.y + moveLen, sectionRect.size.width, sectionRect.size.height));

    NDUIRecttangle* background = m_backgrounds.at(sectionIndex);
    CGRect bkgRect = background->GetFrameRect();
    background->SetFrameRect(CGRectMake(bkgRect.origin.x, bkgRect.origin.y + moveLen, bkgRect.size.width, bkgRect.size.height));

    if (m_scrollBarVisibled)
    {
        NDUIVerticalScrollBar* scrollBar = m_scrollBars.at(sectionIndex);
        CGRect sbRect = scrollBar->GetFrameRect();
        scrollBar->SetFrameRect(CGRectMake(sbRect.origin.x, sbRect.origin.y + moveLen, sbRect.size.width, sbRect.size.height));
    }

    NDSection* section = m_dataSource->Section(sectionIndex);
    for (unsigned int j = 0; j < section->Count(); j++)
    {
        NDUINode* uiNode = section->Cell(j);

        CGRect nodeRect = uiNode->GetFrameRect();
        uiNode->SetFrameRect(CGRectMake(nodeRect.origin.x, nodeRect.origin.y + moveLen, nodeRect.size.width, nodeRect.size.height));
    }
}
Example #2
0
void CUIDialog::SetTitle(const char* title)
{
	NDUINode* node = (NDUINode*)this->GetChild(ID_TASKCHAT_CTRL_TEXT_NPC_NAME);
	if (!node || !node->IsKindOfClass(RUNTIME_CLASS(NDUILabel)))
	{
		return;
	}
	((NDUILabel*)node)->SetText(title);
}
Example #3
0
void CUIDialog::SetPicture(NDPicture* pic)
{
	NDUINode* node = (NDUINode*)this->GetChild(ID_TASKCHAT_CTRL_PICTURE_NPC);
	if (!node || !node->IsKindOfClass(RUNTIME_CLASS(NDUIImage)))
	{
		return;
	}
	
	((NDUIImage*)node)->SetPicture(pic, true);
}
Example #4
0
//是否允许裁剪
bool DrawAni::isAllowScissor()
{
	if (m_pkInstance && m_pkInstance->getOwnerNode())
	{
		NDNode* ownerNode = m_pkInstance->getOwnerNode();
		if (ownerNode->IsA(RTCLS(NDUINode)))
		{
			NDUINode* uiNode = static_cast<NDUINode*>(ownerNode);
			if (uiNode->IsInView())
				return true;
		}
	}
	return false;
}
Example #5
0
bool CUIChatText::OnTextClick(CCPoint touchPos)
{
	int index = 0;
	bool isfound = false;

	std::vector<NDNode*> vChildren = this->GetChildren();
	for (std::vector<NDNode*>::iterator it = vChildren.begin(); it != vChildren.end(); it++)
	{
		NDUINode* uinode = dynamic_cast<NDUINode*> (*it);
		if (uinode && IsPointInside(touchPos, uinode->GetScreenRect()))
		{
			//NDLog(@"click on chat ui node");
			isfound=true;
			break;
		}
		index++;
	}

	if(!isfound)
	{
		return false;
	}

	ChatNode cnode = this->textNodeList[index];

	if (cnode.textType==ChatSpeaker)
	{
		//NDLog(@"click on chat speaker:%d",cnode.content_id);
		BaseScriptMgrObj.excuteLuaFunc<bool>("OnChatNodeClick", "ChatDataFunc",
			(int)cnode.textType,cnode.content_id,this->speakerName);
	}
	else if(cnode.textType==ChatItem)
	{
		//NDLog(@"click on chat item:%d",cnode.content_id);
		BaseScriptMgrObj.excuteLuaFunc<bool>("OnChatNodeClick", "ChatDataFunc",
			(int)cnode.textType,cnode.content_id,"");
	}
	else if (cnode.textType==ChatRole)
	{
		//NDLog(@"click on chat Role:%d",cnode.content_id);
		BaseScriptMgrObj.excuteLuaFunc<bool>("OnChatNodeClick", "ChatDataFunc",
			(int)cnode.textType,cnode.content_id,cnode.content_str);
	}
	else
	{
		//NDLog(@"click nothing");
	}
	return true;
}
Example #6
0
bool NDUITableLayer::DispatchTouchEndEvent(CGPoint beginTouch, CGPoint endTouch)
{
    if (NDUILayer::DispatchTouchEndEvent(beginTouch, endTouch))
        return true;

    if (m_curSection)
    {
        for (unsigned int i = 0; i < m_curSection->Count(); i++)
        {
            NDUINode* cell = m_curSection->Cell(i);
            CGRect rect = cell->GetScreenRect();

            if (CGRectContainsPoint(rect, m_endTouch))
            {
                if (CGRectContainsPoint(rect, beginTouch))
                {
                    if (m_curSection->GetFocusCellIndex() != i)
                    {
                        this->SetFocusOnCell(i);
                    }

                    if (!m_selectEventFocustFirst || m_curSection->GetFocusCellIndex() == i)
                    {
                        NDUITableLayerDelegate* delegate = dynamic_cast<NDUITableLayerDelegate*> (this->GetDelegate());
                        if (delegate)
                        {
                            delegate->OnTableLayerCellSelected(this, cell, i, m_curSection);
                        }
                        else
                        {
                            NDUITargetDelegate* targetDelegate = this->GetTargetDelegate();
                            if (targetDelegate)
                            {
                                targetDelegate->OnTargetTableEvent(this, cell, i, m_curSection);
                            }
                        }
                    }

                    return true;
                }
            }
        }
    }

    return false;
}
Example #7
0
void CUIDialog::SetUIText(const char* text, int nTag)
{
	NDUINode* node = (NDUINode*)this->GetChild(nTag);
	if (!node || !node->IsKindOfClass(RUNTIME_CLASS(NDUIText)))
	{
		return;
	}
	
	CCRect rect					= node->GetFrameRect();
	unsigned int uiFontSize		= ((NDUIText*)node)->GetFontSize();
	ccColor4B color				= ((NDUIText*)node)->GetFontColor();
	
	this->RemoveChild(nTag, true);
	
	if (!text || 0 == strlen(text))
	{
		NDUIText *uitext = new NDUIText;
		uitext->Initialization(false);
		uitext->SetFrameRect(rect);
		uitext->SetFontSize(uiFontSize);
		uitext->SetFontColor(color);
		uitext->SetTag(nTag);
		this->AddChild(uitext);
		uitext->SetVisible(this->IsVisibled());
		return;
	}
	
	NDUIText* uitext = NDUITextBuilder::DefaultBuilder()->Build(
						text, uiFontSize, rect.size, color, false, false);
	uitext->SetFrameRect(rect);	
	uitext->SetTag(nTag);
	uitext->SetFontSize(uiFontSize);
	uitext->SetFontColor(color);
	this->AddChild(uitext);
	uitext->SetVisible(this->IsVisibled());
}
Example #8
0
void CUIDialog::AddOpt(const char* text, int nAction)
{
	if (!text)
	{
		return;
	}
	
	NDUINode* node = (NDUINode*)this->GetChild(ID_TASKCHAT_CTRL_PICTURE_7);
	if (!node || !node->IsKindOfClass(RUNTIME_CLASS(NDUIImage)))
	{
		return;
	}
	
	CCRect rectNode		= node->GetFrameRect();
	//CCSize winsize		= CCDirector::sharedDirector()->getWinSizeInPixels();
	float fScale = ANDROID_SCALE;
	CCRect rect;
	cocos2d::CCLog("tzq fScale = %05f, x = %05f, y = %05f, w = %05f, h = %05f, m_uiOptHeight = %u", 
		              fScale, rectNode.origin.x, rectNode.origin.y, rectNode.size.width, rectNode.size.height, m_uiOptHeight);
	rect.origin			= ccpAdd(rectNode.origin, ccp(0, m_vUiOpt.size() * m_uiOptHeight));
	rect.size			= CCSizeMake(rectNode.size.width*1.1, m_uiOptHeight);
	
	CUIDlgOptBtn *uiOpt	= new CUIDlgOptBtn;
	uiOpt->Initialization();  
	uiOpt->SetFrameRect(rect);
	uiOpt->SetBoundRect(rect);
	//uiOpt->SetLinkTextFontSize(13*fScale);
	uiOpt->SetLinkTextFontSize(12);
	uiOpt->SetLinkTextColor(ccc4(255, 255, 0, 255));
	uiOpt->SetLinkText(text);
	uiOpt->SetDelegate(this);
	this->AddChild(uiOpt);
	
	m_vUiOpt.push_back(uiOpt);
	m_vId.push_back(nAction);
}
Example #9
0
void NDUITableLayer::OnSectionTitleClick(NDUISectionTitle* sectionTitle)
{
    if (m_dataSource)
    {
        for (unsigned int i = 0; i < m_sectionTitles.size(); i++)
        {
            NDUISectionTitle* section = m_sectionTitles.at(i);
            if (sectionTitle == section)
            {
                if (i == m_curSectionIndex && i+1 < m_sectionTitles.size())
                    m_curSectionIndex = i+1;
                else
                    m_curSectionIndex = i;
                m_curSection = m_dataSource->Section(m_curSectionIndex);
            }
        }

        for (unsigned int i = 0; i < m_sectionTitles.size(); i++)
        {
            NDUISectionTitle* section = m_sectionTitles.at(i);
            if (i == m_curSectionIndex)
            {
                section->OnTouchDown(true);
            }
            else
            {
                section->OnTouchDown(false);
            }
        }

        for (unsigned int i = 0 ; i <= m_curSectionIndex; i++)
        {
            CGRect sectionTitleRect = m_sectionTitles.at(i)->GetFrameRect();
            this->MoveSection(i, i * m_sectionTitlesHeight - sectionTitleRect.origin.y);
        }

        CGRect rect = this->GetFrameRect();
        for (unsigned int i = m_dataSource->Count() -1 ; i > m_curSectionIndex; i--)
        {
            CGRect sectionTitleRect = m_sectionTitles.at(i)->GetFrameRect();

            this->MoveSection(i, rect.size.height - sectionTitleRect.origin.y - sectionTitleRect.size.height);

            rect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height - sectionTitleRect.size.height);
        }

        //set enable draw
        for (unsigned int i = 0 ; i < m_dataSource->Count(); i++)
        {
            NDUIRecttangle* background = m_backgrounds.at(i);
            if (i == m_curSectionIndex)
                background->EnableDraw(true);
            else
                background->EnableDraw(false);

            NDSection* section = m_dataSource->Section(i);
            for (unsigned int j = 0; j < section->Count(); j++)
            {
                NDUINode* uiNode = section->Cell(j);

                if (i == m_curSectionIndex && CGRectIntersectsRect(background->GetFrameRect(), uiNode->GetFrameRect()))
                    uiNode->EnableDraw(true);
                else
                    uiNode->EnableDraw(false);
            }
        }

        //set focus
        this->SetFocusOnCell(m_curSection->GetFocusCellIndex());

    }
}
Example #10
0
CGRect NDUITableLayer::GetCellRectWithIndex(unsigned int sectionIndex, unsigned int cellIndex)
{
    CGRect rect = CGRectZero;

    NDSection* section = m_dataSource->Section(sectionIndex);
    if (section)
    {
        //get rect.origin.x
        int row = section->Count() / section->GetColumnCount() + 1;
        int columnIndex = cellIndex / row;
        CGFloat cellWitdh;
        if (m_scrollBarVisibled)
        {
            cellWitdh = (this->GetFrameRect().size.width - m_scrollBarWidth) / section->GetColumnCount();
        }
        else
        {
            cellWitdh = this->GetFrameRect().size.width / section->GetColumnCount();
        }
        rect.origin.x = columnIndex * cellWitdh + m_cellsLeftDistance;

        //get rect.origin.y
        if (m_sectionTitleVisibled)
        {
            rect.origin.y = (sectionIndex + 1) * m_sectionTitlesHeight;
        }

        if (section->IsUseCellHeight())
        {
            rect.origin.y += m_cellsInterval;

            for (unsigned int i = 0; i < cellIndex; i++)
            {
                NDUINode* uiNode = section->Cell(i);
                if (uiNode)
                {
                    rect.origin.y += uiNode->GetFrameRect().size.height + m_cellsInterval;
                }
            }
        }
        else
        {
            int rowIndex = cellIndex / section->GetColumnCount();
            rect.origin.y += rowIndex * (section->GetRowHeight() + m_cellsInterval) + m_cellsInterval;
        }

        //get rect.size.width
        rect.size.width = cellWitdh - m_cellsLeftDistance - m_cellsRightDistance;

        //get rect.size.height
        if (section->IsUseCellHeight())
        {
            NDUINode* uiNode = section->Cell(cellIndex);
            rect.size.height = uiNode->GetFrameRect().size.height;
        }
        else
        {
            rect.size.height = section->GetRowHeight();
        }
    }


    return rect;
}
Example #11
0
bool NDUITableLayer::TouchMoved(NDTouch* touch)
{
    NDUILayer::TouchMoved(touch);

    if (m_sectionTitleVisibled)
    {
        for (unsigned int i = 0; i < m_sectionTitles.size(); i++)
        {
            NDUISectionTitle* sectionTitle = m_sectionTitles.at(i);
            CGRect rect = sectionTitle->GetScreenRect();
            if (CGRectContainsPoint(rect, m_beginTouch))
                return false;
        }
    }

    //this->SetFocusOnCell(m_curSection->GetFocusCellIndex());

    if (m_curSection)
    {
        CGPoint prePos = touch->GetPreviousLocation();
        CGPoint curPos = touch->GetLocation();
        CGFloat subValue = curPos.y - prePos.y;

        if (m_sectionTitles.size() > m_curSectionIndex)
        {
            NDUISectionTitle* sectionTitle = m_sectionTitles.at(m_curSectionIndex);
            CGRect sectionTitleRect = sectionTitle->GetFrameRect();

            if (m_curSection->Count() > 0)
            {
                if (subValue > 0)
                {
                    NDUINode* firstCell = m_curSection->Cell(0);
                    if (m_sectionTitleVisibled)
                    {
                        if (firstCell->GetFrameRect().origin.y + subValue  > sectionTitle->GetFrameRect().origin.y + sectionTitle->GetFrameRect().size.height)
                        {
                            subValue = sectionTitle->GetFrameRect().origin.y + sectionTitle->GetFrameRect().size.height - firstCell->GetFrameRect().origin.y + m_cellsInterval;
                        }
                    }
                    else
                    {
                        if (firstCell->GetFrameRect().origin.y + subValue  > sectionTitle->GetFrameRect().origin.y)
                        {
                            subValue = sectionTitle->GetFrameRect().origin.y  - firstCell->GetFrameRect().origin.y + m_cellsInterval;
                        }
                    }

                    if (subValue <= 0)
                        return false;
                }
                else
                {
                    NDUINode* lastCell = m_curSection->Cell(m_curSection->Count() - 1);
                    CGFloat sectionBottom = this->GetFrameRect().size.height;
                    if (m_curSectionIndex + 1 < m_dataSource->Count())
                    {
                        NDUISectionTitle* nextSectionTitle = m_sectionTitles.at(m_curSectionIndex + 1);
                        sectionBottom = nextSectionTitle->GetFrameRect().origin.y - m_cellsInterval;
                    }
                    if (lastCell->GetFrameRect().origin.y + lastCell->GetFrameRect().size.height + subValue < sectionBottom)
                    {
                        subValue = sectionBottom - lastCell->GetFrameRect().origin.y - lastCell->GetFrameRect().size.height - m_cellsInterval;
                    }

                    if (subValue >= 0)
                        return false;
                }
            }
        }

        if (m_backgrounds.size() > m_curSectionIndex)
        {
            NDUIRecttangle* cellBackground = m_backgrounds.at(m_curSectionIndex);
            for (unsigned int i = 0; i < m_curSection->Count(); i++)
            {
                NDUINode* uiNode = m_curSection->Cell(i);
                CGRect nodeRect = uiNode->GetFrameRect();
                uiNode->SetFrameRect(CGRectMake(nodeRect.origin.x, nodeRect.origin.y + subValue, nodeRect.size.width, nodeRect.size.height));
                bool bDraw = CGRectIntersectsRect(cellBackground->GetFrameRect(), uiNode->GetFrameRect());
                uiNode->EnableDraw(bDraw);
            }
        }


        if (m_scrollBars.size() > m_curSectionIndex)
        {
            if (m_scrollBarVisibled)
            {
                NDUIVerticalScrollBar* scrollBar = m_scrollBars.at(m_curSectionIndex);
                scrollBar->SetCurrentContentY(scrollBar->GetCurrentContentY() - subValue);
            }
        }

    }

    return true;
}
Example #12
0
void NDUITableLayer::ReflashData()
{
    if (!m_dataSource)
        return;

    m_sectionTitles.clear();
    m_backgrounds.clear();
    m_scrollBars.clear();

    for (unsigned int i = 0; i < m_dataSource->Count(); i++)
    {
        NDSection* section = m_dataSource->Section(i);
        for (unsigned int j = 0; j < section->Count(); j++)
        {
            NDUINode* uiNode = section->Cell(j);
            if (uiNode->GetParent())
            {
                uiNode->RemoveFromParent(false);
            }
        }
    }

    this->RemoveAllChildren(true);

    CGRect thisRect = this->GetFrameRect();
    CGSize winSize = NDDirector::DefaultDirector()->GetWinSize();

    //draw sections
    for (unsigned int i = 0; i < m_dataSource->Count(); i++)
    {
        NDSection* section = m_dataSource->Section(i);

        //draw background
        this->DrawBackground(i);

        //draw scrollbar
        if (m_scrollBarVisibled)
        {
            if (section->Count() > 0)
            {
                NDUIVerticalScrollBar* scrollBar = this->DrawScrollbar(i);
                //scrollBar->SetContentHeight((row - 1) * (section->GetRowHeight() + m_cellsInterval));
                CGRect lastCellRect = this->GetCellRectWithIndex(i, section->Count()-1);
                if (m_sectionTitleVisibled)
                    scrollBar->SetContentHeight(lastCellRect.origin.y + lastCellRect.size.height - (i + 1) * m_sectionTitlesHeight);
                else
                    scrollBar->SetContentHeight(lastCellRect.origin.y + lastCellRect.size.height);
            }
        }

        for (unsigned int j = 0; j < section->Count(); j++)
        {
            NDUINode* uiNode = section->Cell(j);

            //防止uilayer拦截行选择事件
            if (uiNode->IsKindOfClass(RUNTIME_CLASS(NDUILayer)) && !uiNode->IsKindOfClass(RUNTIME_CLASS(NDUITableLayer)))
            {
                NDUILayer* uiLayer = (NDUILayer*)uiNode;
                uiLayer->SetTouchEnabled(false);
            }

            CGRect cellRect = this->GetCellRectWithIndex(i, j);
            bool bDraw = CGRectIntersectsRect(m_backgrounds.at(i)->GetFrameRect(), cellRect) && (i == m_dataSource->Count() - 1);

            //draw cell
            uiNode->SetFrameRect(cellRect);
            uiNode->EnableDraw(bDraw);
            this->AddChild(uiNode);
        }
    }

    if (m_dataSource->Count() > 0)
    {
        m_curSectionIndex = m_dataSource->Count()-1;
        m_curSection = m_dataSource->Section(m_curSectionIndex);

        //draw section titles
        for (unsigned int i = 0; i < m_dataSource->Count(); i++)
        {
            this->DrawSectionTitle(i);
        }
        if (m_dataSource->Count() > 0)
        {
            NDUISectionTitle* sectionTitle = m_sectionTitles.at(m_curSectionIndex);
            sectionTitle->OnTouchDown(true);
        }
        this->SetFocusOnCell(m_curSection->GetFocusCellIndex());
    }
    else
    {
        m_curSection = NULL;
    }

}
Example #13
0
bool NDUIXBoardHitProxy::UITouchBegin(NDTouch* pkTouch)
{
	NDUILayer* pkLayer = 0;

	if (!canProcessTouch(pkLayer))
	{
		if (pkLayer)
		{
			bool ret = pkLayer->UITouchBegin(pkTouch);

			return ret;
		}
	}

	assert(m_pkOwner && pkTouch);

	if (!IsVisible())
	{
		return false;
	}

	//判断是否点击在其他ZOrder比较高的控件上
	NDUIDialog* pkOwnerDialog = getOwnerDlg();
	if (pkOwnerDialog)
	{
		const vector<NDNode*>& kChildrenVector = pkOwnerDialog->GetChildren();
		for (int i = 0; i < kChildrenVector.size(); i++)
		{
			NDNode* pkNode = kChildrenVector[i];
			if (pkNode && pkNode->IsA(RTCLS(NDUINode)))
			{
				NDUINode* pkUINode = static_cast<NDUINode*>(pkNode);
				if (pkUINode != this && pkUINode != GetParent()
					&& pkUINode->IsA(RTCLS(NDUINode))
					&& pkUINode->GetZOrder() > GetZOrder()
					&& pkUINode->GetEnabled()
					&& pkUINode->GetScreenRect().containsPoint(
					pkTouch->GetLocation()))
				{
					return false;
				}
			}
		}
	}

	//------------------------------------------------------------
	m_kTouchDownLocalPos = pkTouch->GetLocation();
	m_pkTouchDownView = NULL;

	if (!hitTest(pkTouch->GetLocation()))
		return false;

	for (int i = 0; i < m_pkOwner->getViewCount(); i++)
	{
		NDUIXView* pkView = m_pkOwner->getViewAt(i);
		if (pkView && pkView->GetEnabled()
			&& pkView->GetScreenRect().containsPoint(
			pkTouch->GetLocation()))
		{
			m_pkTouchDownView = pkView;
			bool ret = pkView->UITouchBegin(pkTouch);
			//return ret;
		}
	}

	return true;
	//return NDUILayer::UITouchBegin(touch);
}