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); }
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); }
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()); }
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); }
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; } }