GUISpinView::GUISpinView(CCRect viewFrame, float itemHeight, GUISpinViewDelegate * delegate): m_delegate(NULL), m_mainNode(NULL), m_itemHeight(0), m_itemCount(0), m_targetRow(0), m_currentRow(0) { m_delegate = delegate; m_viewFrame = viewFrame; m_itemHeight = itemHeight; m_mainNode = CCNode::create(); m_mainNode->setAnchorPoint(ccp(0.5f, 0.5f)); m_mainNode->setPosition(ccpAdd(viewFrame.origin, ccp(viewFrame.size.width/2, viewFrame.size.height/2))); addChild(m_mainNode); m_itemCount = m_delegate->itemsCountForSpinView(this); for (int i = 0; i < m_itemCount; i++) { CCNode * node = m_delegate->createItemForSpinView(this, i); m_mainNode->addChild(node, 0, i); node->setAnchorPoint(ccp(0, 0.5f)); CCPoint p = ccp(0, - m_itemHeight * i); if (p.y + m_itemHeight * 0.5f < - m_viewFrame.size.height * 0.5f) { p.y = m_itemHeight * (m_itemCount - i); } node->setPosition(p); } }
void NestedTest::setup() { static int depth = 9; CCNode *parent = this; for (int i = 0; i < depth; i++) { int size = 225 - i * (225 / (depth * 2)); CCClippingNode *clipper = CCClippingNode::create(); clipper->setContentSize(CCSizeMake(size, size)); clipper->setAnchorPoint(ccp(0.5, 0.5)); clipper->setPosition( ccp(parent->getContentSize().width / 2, parent->getContentSize().height / 2) ); clipper->setAlphaThreshold(0.05f); clipper->runAction(CCRepeatForever::create(CCRotateBy::create(i % 3 ? 1.33 : 1.66, i % 2 ? 90 : -90))); parent->addChild(clipper); CCNode *stencil = CCSprite::create(s_pPathGrossini); stencil->setScale( 2.5 - (i * (2.5 / depth)) ); stencil->setAnchorPoint( ccp(0.5, 0.5) ); stencil->setPosition( ccp(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) ); stencil->setVisible(false); stencil->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(i), CCShow::create())); clipper->setStencil(stencil); clipper->addChild(stencil); parent = clipper; } }
bool MainLayer::init() { /*-- 设置整体层属性 --*/ this->setTouchMode(kCCTouchesOneByOne); this->setTouchEnabled(true); this->scheduleUpdate(); CCSize s = CCDirector::sharedDirector()->getWinSize(); this->ignoreAnchorPointForPosition(true); setAnchorPoint(ccp(0.5f, 0.5f)); this->setContentSize(s); setPosition(ccp(s.width / 2, s.height / 2)); CCSize vsize = CCDirector::sharedDirector()->getVisibleSize(); float width = vsize.width / 2; float height = vsize.height / 2; Counter *counter = Counter::sharedCounter(); counter->clearScore(); if (counter->isSound() && !SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bgm.mp3", true); } /*-- door --*/ CCAnimation *doorAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("door"); //左侧 CCSprite *leftDoor = CCSprite::createWithSpriteFrameName("door_1.png"); leftDoor->setPosition(ccp(-200, -50)); leftDoor->setAnchorPoint(ccp(0.5, 0.5)); this->addChild(leftDoor); leftDoor->runAction( CCRepeatForever::create(CCAnimate::create(doorAnimation))); //右侧 CCSprite *rightDoor = CCSprite::createWithSpriteFrameName("door_1.png"); rightDoor->setPosition(ccp(200, -50)); rightDoor->setAnchorPoint(ccp(0.5, 0.5)); this->addChild(rightDoor); rightDoor->runAction( CCRepeatForever::create(CCAnimate::create(doorAnimation))); /*-- 分数 --*/ CCLabelTTF *titletxt = CCLabelTTF::create(counter->getStringByKey("score"), counter->getStringByKey("font"), 46); titletxt->setColor(ccc3(98, 104, 191)); titletxt->setAnchorPoint(ccp(0.5, 0.5)); titletxt->setPosition(ccp(0, height - 130)); this->addChild(titletxt); CCNode *scoreLabel = counter->create_label(); scoreLabel->setPosition(ccp(0, height - 200)); scoreLabel->setAnchorPoint(ccp(0.5, 1)); this->addChild(scoreLabel, 3, TAG_SCORE); /*-- role --*/ return true; }
void VEScrollView::reArrange() { CCArray *children = m_pContainer->getChildren(); float posX = -m_viewSize.width/2.f; float posY = m_viewSize.height/2.f; for(int i = 0; i < m_pContainer->getChildrenCount(); i++) { CCNode *node = (CCNode*)children->objectAtIndex(i); CCSize nodeSize = node->getContentSize(); node->setAnchorPoint(ccp(0.5, 0.5)); switch (m_eType) { case SCROLLVIEW_HORIZONTAL: node->setPositionX(posX+nodeSize.width/2.f); posX += nodeSize.width; break; case SCROLLVIEW_VERTICAL: node->setPositionY(posY-nodeSize.height/2.f); posY -= nodeSize.height; break; default: CCLOG("wrong scroll type"); break; } //float nodeY = m_pContainer->getPositionY()+h; //node->setVisible(nodeY<nodeSize.height && nodeY>-m_viewSize.height); //if(dynamic_cast<CCLayer*>(node)) // dynamic_cast<CCLayer*>(node)->setTouchEnabled(nodeY<nodeSize.height && nodeY>-m_viewSize.height); } switch (m_eType) { case SCROLLVIEW_HORIZONTAL: posX += m_viewSize.width/2.f; m_contentSize.width = abs(posX); m_contentSize.height = m_viewSize.height; break; case SCROLLVIEW_VERTICAL: posY -= m_viewSize.height/2.f; m_contentSize.width = m_viewSize.width; m_contentSize.height = abs(posY); break; default: CCLOG("wrong scroll type"); break; } }
void GUISpinView::refresh() { m_mainNode->removeAllChildren(); m_itemCount = m_delegate->itemsCountForSpinView(this); for (int i = 0; i < m_itemCount; i++) { CCNode * node = m_delegate->createItemForSpinView(this, i); m_mainNode->addChild(node, 0, i); node->setAnchorPoint(ccp(0, 0.5f)); CCPoint p = ccp(0, - m_itemHeight * i); if (p.y + m_itemHeight * 0.5f < - m_viewFrame.size.height * 0.5f) { p.y = m_itemHeight * (m_itemCount - i); } node->setPosition(p); } }
void CMainCityUI::runMovePreAction(int tag) { CCNode *sBtn = dynamic_cast<CCNode*>( m_ui->getChildByTag(tag)); sBtn->setVisible(true); CCArray *children = sBtn->getChildren(); for (int i = 0; i < sBtn->getChildrenCount(); i++) { CCNode *child = (CCNode*)children->objectAtIndex(i); CCMoveBy *move = CCMoveBy::create(0.3f,ccp(-m_moveX[tag-1],0)); child->runAction(move); child->setAnchorPoint(CCPointCenter); child->setVisible(true); } }
bool CCControlPotentiometerTest::init() { if (CCControlScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); CCNode *layer = CCNode::create(); layer->setPosition(ccp (screenSize.width / 2, screenSize.height / 2)); this->addChild(layer, 1); double layer_width = 0; // Add the black background for the text CCScale9Sprite *background = CCScale9Sprite::create("extensions/buttonBackground.png"); background->setContentSize(CCSizeMake(80, 50)); background->setPosition(ccp(layer_width + background->getContentSize().width / 2.0f, 0)); layer->addChild(background); layer_width += background->getContentSize().width; this->setDisplayValueLabel(CCLabelTTF::create("", "HelveticaNeue-Bold", 30)); m_pDisplayValueLabel->setPosition(background->getPosition()); layer->addChild(m_pDisplayValueLabel); // Add the slider CCControlPotentiometer *potentiometer = CCControlPotentiometer::create("extensions/potentiometerTrack.png" ,"extensions/potentiometerProgress.png" ,"extensions/potentiometerButton.png"); potentiometer->setPosition(ccp (layer_width + 10 + potentiometer->getContentSize().width / 2, 0)); // When the value of the slider will change, the given selector will be call potentiometer->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlPotentiometerTest::valueChanged), CCControlEventValueChanged); layer->addChild(potentiometer); layer_width += potentiometer->getContentSize().width; // Set the layer size layer->setContentSize(CCSizeMake(layer_width, 0)); layer->setAnchorPoint(ccp (0.5f, 0.5f)); // Update the value label this->valueChanged(potentiometer, CCControlEventValueChanged); return true; } return false; }
void MessageView::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data) { // 背景 CCSprite* cellBg = CCSprite::create("bg_listview_item.png") ; const float cell_width = cellBg->getContentSize().width+15 ; const float cell_height = cellBg->getContentSize().height+10 ; CCListViewCell* cell = CCListViewCell::node() ; cell->setContentSize(CCSizeMake(cell_width, cell_height)) ; cell->setOpacity(0) ; // cell->setSelectionColor(ccc4(255, 0, 0, 255)) ; cell->setSelectionColor(ccc4(103, 102, 204, 255)) ; data->cell = cell ; CCNode* cellNode = CCNode::create() ; cellNode->setContentSize(CCSizeMake(cell_width, cell_height)) ; cellNode->setAnchorPoint(ccp(0, 0)) ; cellNode->setPosition(ccp(0, 0)) ; cell->addChild(cellNode) ; // 背景 cellBg->setAnchorPoint(ccp(0.5, 0.5)) ; cellBg->setPosition(ccp(cell_width*0.5, cell_height*0.5)) ; cellNode->addChild(cellBg) ; // icon CCSprite* iconMsg = CCSprite::create("icon_msg.png") ; iconMsg->setAnchorPoint(ccp(0, 0.5)) ; iconMsg->setPosition(ccp(20, cell_height*0.5)) ; cellNode->addChild(iconMsg, 1) ; // 主题 CCLabelTTF* themeLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币","font01.ttf", 24.0f,CCSizeMake(cell_width, 50), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ; themeLabel->setColor(ccc3(255, 215, 0)) ; themeLabel->setAnchorPoint(ccp(0, 1)) ; themeLabel->setPosition(ccp(120, cell_height-8)) ; cellNode->addChild(themeLabel, 1) ; // 内容 CCLabelTTF* contentLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币,蛇年贺新春,免费拿九玩币","font01.ttf", 20.0f,CCSizeMake(cell_width, 50), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ; contentLabel->setAnchorPoint(ccp(0, 0)) ; contentLabel->setPosition(ccp(120, 8)) ; cellNode->addChild(contentLabel, 1) ; }
//地面生成 CCNode* ObjectManager::initGround(){ //物理ボディ生成 b2Body* body = _gameL->getWorld()->CreateBody(&groundBodyDef()); // 地面の形と大きさの定義 b2EdgeShape groundBox = groundShape(); //物理性質 b2FixtureDef fixtureDef; fixtureDef.shape = &groundBox; fixtureDef.density = 0.5; fixtureDef.restitution = 0.5; fixtureDef.friction = 0.8; body->CreateFixture(&fixtureDef); //地面ノード作成 CCNode* node = CCNode::create(); node->setAnchorPoint(ccp(0.5, 0.5)); node->setPosition(ccp(_gameL->getBgTag()->getContentSize().width / 2, 25)); _gameL->setNode(node); return node; }
bool CCCGameScrollView::createContainer(CCCGameScrollViewDelegate *pDele, int nCount, const cocos2d::CCSize &oSize ) { CCAssert(m_bSetDirection, "must call setDirection first!!!"); m_nPageCount = nCount; m_CellSize = oSize; setDelegate(pDele); if (nCount==1) { } CCLayer *pContainer = CCLayer::create(); CCSize winSize =CCSizeZero ; //CCDirector::sharedDirector()->getVisibleSize(); for (int i = 0; i < nCount; ++i) { CCNode *pNode = CCNode::create(); pNode->setAnchorPoint(ccp(0, 0)); pDele->scrollViewInitPage(this, pNode, i); if (m_eDirection == kCCScrollViewDirectionHorizontal) { pNode->setPosition(ccp( i * oSize.width, 0)); } else { pNode->setPosition(ccp(0,i * oSize.height)); } pNode->setContentSize(m_CellSize); pNode->setTag(i); pContainer->addChild(pNode); } setViewSize(m_CellSize); setContainer(pContainer); return true; }
/** * 初始化方法,继承CCLayer的方法 */ bool LoginView::init() { if(!CCLayer::init()) { return false ; } CCSize winSize = CCDirector::sharedDirector()->getWinSize() ; // 背景 CCSprite* downBg = CCSprite::create("bg_welcome.png") ; downBg->setAnchorPoint(ccp(0.5, 0)) ; downBg->setPosition(ccp(winSize.width/2, 0)) ; this->addChild(downBg, 0) ; // 加载logo CCSprite* logo = CCSprite::create("logo_01.png") ; logo->setAnchorPoint(ccp(0.5, 0.5)) ; logo->setPosition(ccp(winSize.width/2, winSize.height/2+35)) ; this->addChild(logo, 1) ; ///////////////////////////////// 输入框 //////////////////////////////////////// const float input_width = 213.0f ; const float input_height = 39.0f ; const float labelNode_padding = 8.0f ; const float labelNode_width = winSize.width/3 ; const float labelNode_height = 2*input_height+labelNode_padding ; CCNode* labelNode = CCNode::create() ; labelNode->setContentSize(CCSizeMake(labelNode_width, labelNode_height)) ; labelNode->setAnchorPoint(ccp(0.5, 0)) ; labelNode->setPosition(ccp(winSize.width/2-5, 85)) ; this->addChild(labelNode, 2) ; CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create("bg_textfield.png") ; // 用户名 CCSprite* txtUsernameBg = CCSprite::createWithTexture(batchNode->getTexture()) ; txtUsernameBg->setAnchorPoint(ccp(0, 0)) ; txtUsernameBg->setPosition(ccp(0, input_height+labelNode_padding)) ; labelNode->addChild(txtUsernameBg, 0) ; this->txtUsername = CCTextFieldTTF::textFieldWithPlaceHolder("Username", CCSizeMake(input_width, input_height), kCCTextAlignmentLeft, "font01.ttf", 26.0f) ; this->txtUsername->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; this->txtUsername->setAnchorPoint(ccp(0, 0.5)) ; this->txtUsername->setPosition(ccp((winSize.width-labelNode_width)/2+5, 85+labelNode_height*3/4)) ; this->addChild(this->txtUsername, 3) ; // 密码 CCSprite* txtPasswordBg = CCSprite::createWithTexture(batchNode->getTexture()) ; txtPasswordBg->setAnchorPoint(ccp(0, 0)) ; txtPasswordBg->setPosition(ccp(0, 0)) ; labelNode->addChild(txtPasswordBg, 0) ; this->txtPassword = CCTextFieldTTF::textFieldWithPlaceHolder("Password", CCSizeMake(input_width, input_height), kCCTextAlignmentLeft, "font01.ttf", 26.0f) ; this->txtPassword->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; this->txtPassword->setAnchorPoint(ccp(0, 0.5)) ; this->txtPassword->setPosition(ccp((winSize.width-labelNode_width)/2+5, 85+labelNode_height/4-2)) ; this->addChild(this->txtPassword,3) ; // 登录按钮 CCMenuItemImage* loginMenuItem = CCMenuItemImage::create("menu_login_n.png", "menu_login_s.png", this, menu_selector(LoginView::menuLoginCallback)) ; loginMenuItem->setAnchorPoint(ccp(0, 0)) ; loginMenuItem->setPosition(ccp(0, input_height+labelNode_padding)) ; // 注册按钮 CCMenuItemImage* registeMenuItem = CCMenuItemImage::create("menu_registe_n.png", "menu_registe_s.png", this, menu_selector(LoginView::menuRegisteCallback)) ; registeMenuItem->setAnchorPoint(ccp(0, 0)) ; registeMenuItem->setPosition(ccp(0, 0)) ; CCMenu* loginMenu = CCMenu::create(loginMenuItem, registeMenuItem, NULL) ; loginMenu->setAnchorPoint(ccp(0, 0)) ; loginMenu->setPosition(ccp(input_width+10, -5)) ; labelNode->addChild(loginMenu) ; // ////////////////////////////////////////////////////////////////////////////////////////////// const float loginNode_padding = 11.0f ; const float loginNode_margin_bottom = 32.0f ; const float menu_item_width = 101.0f ; CCNode* optionNode = CCNode::create() ; optionNode->setContentSize(CCSizeMake(winSize.width/3, 50)) ; optionNode->setAnchorPoint(ccp(0.5, 0)) ; optionNode->setPosition(ccp(winSize.width/2-5, loginNode_margin_bottom)) ; this->addChild(optionNode, 1) ; // 游客登录 CCMenuItemImage* guestLoginItem = CCMenuItemImage::create("menu_guest_login_n.png", "menu_guest_login_s.png", this, menu_selector(LoginView::menuGuestLoginCallback)) ; guestLoginItem->setAnchorPoint(ccp(0, 0)) ; guestLoginItem->setPosition(ccp(0, 0)) ; // 忘记密码 CCMenuItemImage* forgetPwdItem = CCMenuItemImage::create("menu_forget_pwd_n.png", "menu_forget_pwd_s.png", this, menu_selector(LoginView::menuForgetPwdCallback)) ; forgetPwdItem->setAnchorPoint(ccp(0, 0)) ; forgetPwdItem->setPosition(ccp(menu_item_width+loginNode_padding, 0)) ; // go CCMenuItemImage* goMenuItem = CCMenuItemImage::create("menu_go_n.png", "menu_go_s.png", this, menu_selector(LoginView::menuGoCallback)) ; goMenuItem->setAnchorPoint(ccp(0, 0)) ; goMenuItem->setPosition(ccp(2*(menu_item_width+loginNode_padding), 0)) ; CCMenu* goMenu = CCMenu::create(guestLoginItem, forgetPwdItem, goMenuItem, NULL) ; goMenu->setAnchorPoint(ccp(0, 0)) ; goMenu->setPosition(ccp(0, 0)) ; optionNode->addChild(goMenu) ; /* ///////////////////////////////////////////////////////////////////////////////////////////// CCLabelTTF* tipLabel = CCLabelTTF::create("小提示:在游戏中达到规定时间,可以获取神秘大奖哦!", CCSizeMake(winSize.width, 45), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "font01.ttf", 22.0f) ; tipLabel->setAnchorPoint(ccp(0.5, 0)) ; tipLabel->setPosition(ccp(winSize.width/2, 20)) ; this->addChild(tipLabel, 2) ; */ // 接收键盘点击事件 this->setKeypadEnabled(true) ; // 触摸可使用 this->setTouchEnabled(true); return true ; }
// 初始化顶部bar void ActivityView::initTopBar(CCSize winSize) { //////////////////////////////////////////////////////////////////////////////////////////////////// // topBarNode 背景 CCSprite* topBarBg = CCSprite::create("bg_nav_top.png") ; topBarBg->setAnchorPoint(ccp(0.5, 0)) ; topBarBg->setPosition(ccp(winSize.width/2, 0)) ; const float topBar_height = topBarBg->getContentSize().height ; // 顶部条信息 ////////////////////////////////////////////////////////////////////////////////////// this->topBarNode = CCNode::create() ; this->topBarNode->setContentSize(CCSizeMake(winSize.width, topBar_height)) ; this->topBarNode->setAnchorPoint(ccp(0, 0)) ; this->topBarNode->setPosition(ccp(0, winSize.height - topBar_height)) ; this->addChild(this->topBarNode, 0, 1) ; // 将topBarNode背景加入到topBarNode this->topBarNode->addChild(topBarBg, 0 ) ; ///////////////////////////// 左侧布局 ////////////////////////// CCNode* leftNode = CCNode::create() ; leftNode->setContentSize(CCSizeMake(300, topBar_height)) ; leftNode->setAnchorPoint(ccp(0, 0.5)) ; leftNode->setPosition(ccp(30, topBar_height/2)) ; this->topBarNode->addChild(leftNode, 1) ; // 头像 CCSprite* headPortraitSprite = CCSprite::create("user/head_default_f2.png") ; headPortraitSprite->setAnchorPoint(ccp(0, 0)) ; headPortraitSprite->setPosition(ccp(0, 10)) ; headPortraitSprite->setScale(0.8) ; leftNode->addChild(headPortraitSprite) ; // 昵称 CCLabelTTF* nikeNameLabel = CCLabelTTF::create("昵称:我是主角", "font01.ttf", 22.0f) ; // nikeNameLabel->setColor(ccc3(191, 173, 111)) ; nikeNameLabel->setAnchorPoint(ccp(0, 0)) ; nikeNameLabel->setPosition(ccp(70, topBar_height/2+2)) ; nikeNameLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; // 水平对齐方式 nikeNameLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式 leftNode->addChild(nikeNameLabel) ; // 金币 CCLabelTTF* goldCoinLabel = CCLabelTTF::create("金币:10000", "font01.ttf", 22.0f) ; goldCoinLabel->setAnchorPoint(ccp(0, 1)) ; goldCoinLabel->setPosition(ccp(70, topBar_height/2)) ; goldCoinLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; // 水平对齐方式 goldCoinLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式 leftNode->addChild(goldCoinLabel) ; // 信息 CCSprite* titleMsg = CCSprite::create("icon_title_activity.png") ; titleMsg->setAnchorPoint(ccp(0.5, 0.5)) ; titleMsg->setPosition(ccp(winSize.width/2, topBar_height/2)) ; this->topBarNode->addChild(titleMsg, 1) ; // 分割线 CCSprite* spliteLineLeft = CCSprite::create("icon_top_nav_splite.png") ; spliteLineLeft->setAnchorPoint(ccp(0, 1)) ; spliteLineLeft->setPosition(ccp(winSize.width/3+10, topBar_height)) ; this->topBarNode->addChild(spliteLineLeft, 1) ; // 分割线 CCSprite* spliteLineRight = CCSprite::create("icon_top_nav_splite.png") ; spliteLineRight->setAnchorPoint(ccp(0, 1)) ; spliteLineRight->setPosition(ccp(winSize.width*2/3-20, topBar_height)) ; this->topBarNode->addChild(spliteLineRight, 1) ; ///////////////////////////////////////////////////////////////////////////////////////////////// /****************************** 菜单选项 ********************************************************/ // 右侧menu const float right_width = 200 ; const float item_width = 55 ; // 礼物 CCMenuItemImage* menuGifts = CCMenuItemImage::create("menu_gifts_n.png", "menu_gifts_s.png", this, menu_selector(ActivityView::menuGiftsClickCallback)) ; // menuBack->setContentSize(CCSizeMake(67, 68)) ; menuGifts->setAnchorPoint(ccp(0, 0.5)) ; menuGifts->setPosition(ccp(0, topBar_height/2)) ; //menuGifts->setPosition(ccp(right_width-2*item_width, topBar_height/2)) ; //rightMenu->addChild(menuGifts) ; // 返回大厅 CCMenuItemImage* menuBack = CCMenuItemImage::create("menu_back_n.png", "menu_back_s.png", this, menu_selector(MessageView::menuBackClickCallback)) ; menuBack->setAnchorPoint(ccp(0, 0.5)) ; menuBack->setPosition(ccp(2*(item_width+10), topBar_height/2)) ; //menuBack->setPosition(ccp(right_width, topBar_height/2)) ; //rightMenu->addChild(menuBack) ; // 设置 CCMenuItemImage* menuSetting = CCMenuItemImage::create("menu_setting_n.png", "menu_setting_s.png", this, menu_selector(MessageView::menuSettingClickCallback)) ; // menuBack->setContentSize(CCSizeMake(67, 68)) ; menuSetting->setAnchorPoint(ccp(0, 0.5)) ; menuSetting->setPosition(ccp(item_width+10, topBar_height/2)) ; //menuSetting->setPosition(ccp(right_width-item_width, topBar_height/2)) ; //rightMenu->addChild(menuSetting) ; CCMenu* rightMenu = CCMenu::create(menuGifts, menuBack, menuSetting, NULL) ; rightMenu->setContentSize(CCSizeMake(winSize.width/4, topBar_height)) ; rightMenu->setAnchorPoint(ccp(0, 0)) ; rightMenu->setPosition(ccp(winSize.width*3/4-10, 0)) ; this->topBarNode->addChild(rightMenu, 1) ; }
//初始化UI bool LayerGoods::initUI() { CCPoint vo = CCDirector::sharedDirector()->getVisibleOrigin(); CCSize vs = CCDirector::sharedDirector()->getVisibleSize(); UserInfo *user_info = Topwo::getInstance()->getTopwoData()->getUserInfo(); //背景 CCScale9Sprite* sp_bg = CCScale9Sprite::create(RES_white_dialog); this->addChild(sp_bg); sp_bg->setContentSize(CCSizeMake(780.0f, 340.0f)); CCSize size_sp_bg = sp_bg->getContentSize(); sp_bg->setPosition(ccp(vs.width * 0.5f, vs.height * 0.5f)); //标题 CCSprite *sp_title = CCSprite::create(RES_LayerGoods_title); this->addChild(sp_title); CCSize size_sp_title = sp_title->getContentSize(); sp_title->setPosition(ccp(vs.width * 0.5f, (vs.height + size_sp_bg.height) * 0.5f - size_sp_title.height * 0.8f)); //关闭项 CCMenuItemSprite *item_close = CCMenuItemSprite::create( CCSprite::create(RES_btn_close_1_0), CCSprite::create(RES_btn_close_1_0), this, menu_selector(LayerGoods::menuCallbackClose) ); CCSize size_item_close = item_close->getContentSize(); CCNode *node = item_close->getNormalImage(); node->setAnchorPoint(ccp(0.5f, 0.5f)); node->setPosition(ccp(size_item_close.width * 0.5f, size_item_close.height * 0.5f)); node = item_close->getSelectedImage(); node->setAnchorPoint(ccp(0.5f, 0.5f)); node->setPosition(ccp(size_item_close.width * 0.5f, size_item_close.height * 0.5f)); node->setScale(1.2f); item_close->setPosition(ccp((vs.width + size_sp_bg.width - size_item_close.width) * 0.5f, (vs.height + size_sp_bg.height - size_item_close.height) * 0.5f)); //购买物品1 CCSprite* sp_goods_1 = CCSprite::create(RES_LayerGoods_tipo); this->addChild(sp_goods_1, 0 ,1); CCSize size_sp_goods_1 = sp_goods_1->getContentSize(); sp_goods_1->setPosition(ccp(vs.width * 0.5f - size_sp_goods_1.width * 2.04f, vs.height * 0.43f)); int goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelTiPo()); CCLabelAtlas* la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", goods_level)->getCString(), RES_number_style_5, 9, 12, '0'); sp_goods_1->addChild(la_value, 0, 0); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.45f, size_sp_goods_1.height * 0.56f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_1->addChild(la_value, 0, 1); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.68f, size_sp_goods_1.height * 0.48f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_1->addChild(la_value, 0, 2); la_value->setAnchorPoint(ccp(0, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.56f, size_sp_goods_1.height * 0.35f)); CCMenuItemSprite* item_buy_goods_1 = CCMenuItemSprite::create( CCSprite::create(RES_btn_buy_0), CCSprite::create(RES_btn_buy_1), this, menu_selector(LayerGoods::menuCallbackBuy) ); item_buy_goods_1->setPosition(ccp(vs.width * 0.5f - size_sp_goods_1.width * 2.04f, vs.height * 0.31f)); item_buy_goods_1->setTag(1); //购买物品2 CCSprite* sp_goods_2 = CCSprite::create(RES_LayerGoods_meili); this->addChild(sp_goods_2, 0, 2); sp_goods_2->setPosition(ccp(vs.width * 0.5f - size_sp_goods_1.width * 1.02f, vs.height * 0.43f)); goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelMeiLi()); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", goods_level)->getCString(), RES_number_style_5, 9, 12, '0'); sp_goods_2->addChild(la_value, 0, 0); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.45f, size_sp_goods_1.height * 0.56f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_2->addChild(la_value, 0, 1); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.68f, size_sp_goods_1.height * 0.48f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_2->addChild(la_value, 0, 2); la_value->setAnchorPoint(ccp(0, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.56f, size_sp_goods_1.height * 0.35f)); CCMenuItemSprite* item_buy_goods_2 = CCMenuItemSprite::create( CCSprite::create(RES_btn_buy_0), CCSprite::create(RES_btn_buy_1), this, menu_selector(LayerGoods::menuCallbackBuy) ); item_buy_goods_2->setPosition(ccp(vs.width * 0.5f - size_sp_goods_1.width * 1.02f, vs.height * 0.31f)); item_buy_goods_2->setTag(2); //购买物品3 CCSprite* sp_goods_3 = CCSprite::create(RES_LayerGoods_zhili); this->addChild(sp_goods_3, 0, 3); sp_goods_3->setPosition(ccp(vs.width * 0.5f, vs.height * 0.43f)); goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelZhiLi()); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", goods_level)->getCString(), RES_number_style_5, 9, 12, '0'); sp_goods_3->addChild(la_value, 0, 0); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.45f, size_sp_goods_1.height * 0.56f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_3->addChild(la_value, 0, 1); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.68f, size_sp_goods_1.height * 0.48f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_3->addChild(la_value, 0, 2); la_value->setAnchorPoint(ccp(0, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.56f, size_sp_goods_1.height * 0.35f)); CCMenuItemSprite* item_buy_goods_3 = CCMenuItemSprite::create( CCSprite::create(RES_btn_buy_0), CCSprite::create(RES_btn_buy_1), this, menu_selector(LayerGoods::menuCallbackBuy) ); item_buy_goods_3->setPosition(ccp(vs.width * 0.5f, vs.height * 0.31f)); item_buy_goods_3->setTag(3); //购买物品4 CCSprite* sp_goods_4 = CCSprite::create(RES_LayerGoods_eq); this->addChild(sp_goods_4, 0, 4); sp_goods_4->setPosition(ccp(vs.width * 0.5f + size_sp_goods_1.width * 1.02f, vs.height * 0.43f)); goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelEQ()); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", goods_level)->getCString(), RES_number_style_5, 9, 12, '0'); sp_goods_4->addChild(la_value, 0, 0); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.45f, size_sp_goods_1.height * 0.56f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_4->addChild(la_value, 0, 1); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.68f, size_sp_goods_1.height * 0.48f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_4->addChild(la_value, 0, 2); la_value->setAnchorPoint(ccp(0, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.56f, size_sp_goods_1.height * 0.35f)); CCMenuItemSprite* item_buy_goods_4 = CCMenuItemSprite::create( CCSprite::create(RES_btn_buy_0), CCSprite::create(RES_btn_buy_1), this, menu_selector(LayerGoods::menuCallbackBuy) ); item_buy_goods_4->setPosition(ccp(vs.width * 0.5f + size_sp_goods_1.width * 1.02f, vs.height * 0.31f)); item_buy_goods_4->setTag(4); //购买物品5 CCSprite *sp_goods_5 = CCSprite::create(RES_LayerGoods_ganxing); this->addChild(sp_goods_5, 0, 5); sp_goods_5->setPosition(ccp(vs.width * 0.5f + size_sp_goods_1.width * 2.04f, vs.height * 0.43f)); goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelGanXing()); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", goods_level)->getCString(), RES_number_style_5, 9, 12, '0'); sp_goods_5->addChild(la_value, 0, 0); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.45f, size_sp_goods_1.height * 0.56f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_5->addChild(la_value, 0, 1); la_value->setAnchorPoint(ccp(0.5f, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.68f, size_sp_goods_1.height * 0.48f)); la_value = CCLabelAtlas::create(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString(), RES_number_style_2, 9, 15, '+'); sp_goods_5->addChild(la_value, 0, 2); la_value->setAnchorPoint(ccp(0, 0.5f)); la_value->setPosition(ccp(size_sp_goods_1.width * 0.56f, size_sp_goods_1.height * 0.35f)); CCMenuItemSprite *item_buy_goods_5 = CCMenuItemSprite::create( CCSprite::create(RES_btn_buy_0), CCSprite::create(RES_btn_buy_1), this, menu_selector(LayerGoods::menuCallbackBuy) ); item_buy_goods_5->setPosition(ccp(vs.width * 0.5f + size_sp_goods_1.width * 2.04f, vs.height * 0.31f)); item_buy_goods_5->setTag(5); CCMenu *menu = CCMenu::create(item_close, item_buy_goods_1, item_buy_goods_2, item_buy_goods_3, item_buy_goods_4, item_buy_goods_5, NULL); this->addChild(menu, 0, 0); menu->setPosition(CCPointZero); updateMe(); return true; }
void CCINode::loadImages(){ int tagIndex = 0; while (true) { CCIMovieTag * tag = NULL; if (tagIndex<tags.size()) { tag = tags[tagIndex++]; }else{ tagIndex = 0; break; } if (tag->getTagType()==TagTypeDefineBitsLossless2 || tag->getTagType()==TagTypeDefineBitsJPEG3||tag->getTagType()==TagTypeDefineBitsJPEG2||tag->getTagType()==TagTypeDefineBits) { CCIImageTag* imageTag = (CCIImageTag*)tag; CCTexture2D * text = imageTag->getTexture(); if (text) { this->textures->setObject(text, imageTag->getCharacterID()); } }else if(tag->getTagType()==TagTypeDefineShape||tag->getTagType()==TagTypeDefineShape2||tag->getTagType()==TagTypeDefineShape3){ //shape是可以放上去的精灵 CCIDefineShape * defineShapeTag = (CCIDefineShape *)tag; CCIRect *bounds = defineShapeTag->getBounds(); CCNode * shape = CCNode::create(); //CCNode * shape = CCLayerColor::create(ccc4(200,0,0,100)); shape->ignoreAnchorPointForPosition(false); shape->setContentSize(bounds->getSize()); shape->setAnchorPoint(bounds->getAnchorPoint()); //shape->ignoreAnchorPointForPosition(true); shape->setUserObject(CCInteger::create(NodeTypeNode)); CCIShapeWithStyle * style = defineShapeTag->getShapes(); CCIFillStyleArray * fileStyles = style->FillStyles; this->fillNodeWithStyle(fileStyles, shape,bounds); for (int i=0; i<style->ShapeRecords.size(); i++) { CCIShapeRecord * record = style->ShapeRecords[i]; if (record->ShapeType==ShapeTypeStyle){ CCIStyleChangeRecord * styleRecord = (CCIStyleChangeRecord *)record; if (styleRecord->StateNewStyles) { fileStyles = styleRecord->FillStyles; this->fillNodeWithStyle(fileStyles, shape,bounds); } } } this->nodes->setObject(shape, defineShapeTag->getShapeId()); }else if(tag->getTagType()==TagTypeDefineSprite){ CCIDefineSprite * sprite = (CCIDefineSprite *)tag; CCINode * node = CCINode::createWithTags(sprite->getControlTags(), this->swfMovie,this->nodes); node->setUserObject(CCInteger::create(NodeTypeCCINode)); this->nodes->setObject(node, sprite->getSpriteId()); } } }
void CListView::updateNodesPosition() { m_pContainer->removeAllChildrenWithCleanup(true); if( m_vNodeList.size() == 0 ) return; m_fLayoutIndexSize = 0.0f; switch( m_eDirection ) { case eScrollViewDirectionHorizontal: { unsigned int i = 0; unsigned int end = m_vNodeList.size(); CCNode* pNode = NULL; for(; i < end; ++i ) { pNode = m_vNodeList[i]; pNode->setAnchorPoint(ListViewHorizontalNodeAnchorPoint); pNode->setPosition(CCPoint(m_fLayoutIndexSize, 0)); m_fLayoutIndexSize += pNode->getContentSize().width; } setContainerSize(CCSize(m_fLayoutIndexSize, m_obContentSize.height)); } break; case eScrollViewDirectionVertical: { float fAllNodesSize = 0.0f; unsigned int i = 0; unsigned int end = m_vNodeList.size(); CCNode* pNode = NULL; for(; i < end; ++i ) { pNode = m_vNodeList[i]; fAllNodesSize += pNode->getContentSize().height; } m_fLayoutIndexSize = fAllNodesSize; fAllNodesSize = MAX(m_obContentSize.height, fAllNodesSize); setContainerSize(CCSize(m_obContentSize.width, fAllNodesSize)); i = 0; end = m_vNodeList.size(); for(; i < end; ++i ) { pNode = m_vNodeList[i]; fAllNodesSize = fAllNodesSize - pNode->getContentSize().height; pNode->setAnchorPoint(ListViewVerticalNodeAnchorPoint); pNode->setPosition(CCPoint(0, fAllNodesSize)); m_pContainer->addChild(pNode); } } break; default: break; } }
void RichText::formarRenderers() { if (_ignoreSize) { float newContentSizeWidth = 0.0f; float newContentSizeHeight = 0.0f; CCArray* row = (CCArray*)(_elementRenders[0]); float nextPosX = 0.0f; for (unsigned int j=0; j<row->count(); j++) { CCNode* l = (CCNode*)(row->objectAtIndex(j)); l->setAnchorPoint(CCPointZero); l->setPosition(ccp(nextPosX, 0.0f)); _elementRenderersContainer->addChild(l, 1, j); CCSize iSize = l->getContentSize(); newContentSizeWidth += iSize.width; newContentSizeHeight = MAX(newContentSizeHeight, iSize.height); nextPosX += iSize.width; } _elementRenderersContainer->setContentSize(CCSizeMake(newContentSizeWidth, newContentSizeHeight)); } else { float newContentSizeHeight = 0.0f; float *maxHeights = new float[_elementRenders.size()]; for (unsigned int i=0; i<_elementRenders.size(); i++) { CCArray* row = (CCArray*)(_elementRenders[i]); float maxHeight = 0.0f; for (unsigned int j=0; j<row->count(); j++) { CCNode* l = (CCNode*)(row->objectAtIndex(j)); maxHeight = MAX(l->getContentSize().height, maxHeight); } maxHeights[i] = maxHeight; newContentSizeHeight += maxHeights[i]; } float nextPosY = _customSize.height; for (unsigned int i=0; i<_elementRenders.size(); i++) { CCArray* row = (CCArray*)(_elementRenders[i]); float nextPosX = 0.0f; nextPosY -= (maxHeights[i] + _verticalSpace); for (unsigned int j=0; j<row->count(); j++) { CCNode* l = (CCNode*)(row->objectAtIndex(j)); l->setAnchorPoint(CCPointZero); l->setPosition(ccp(nextPosX, nextPosY)); _elementRenderersContainer->addChild(l, 1, i*10 + j); nextPosX += l->getContentSize().width; } } _elementRenderersContainer->setContentSize(_size); delete [] maxHeights; } _elementRenders.clear(); if (_ignoreSize) { CCSize s = getContentSize(); _size = s; } else { _size = _customSize; } }
CCNode *HRootLayer::readNodeGraphFromFile(const char* pCCBFileName, bool originalSize) { CCNodeLoaderLibrary *library = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary(); CCBReader reader(library); // HFileUtils::resetInUI(true); PHSCREENDATA pData = NULL; std::string filename = getUILayout(pCCBFileName, &pData); CCNode *node = reader.readNodeGraphFromFile(filename.c_str(), this, AppDelegate::getInstance()->getGameManager()->getScreenSize()); // HFileUtils::resetInUI(false); setCCBAnimationManager(reader.getAnimationManager()); m_fScaleX = 1.0f; m_fScaleY = 1.0f; if (node != NULL) { if (originalSize) { node->setAnchorPoint(CCPointZero); node->setPosition(CCPointZero); setContentSize(node->getContentSize()); // updateAndAdjust(node, 1, 1); addChild(node); } else { node->setAnchorPoint(CCPointMake(0.5f, 0.5f)); node->setPosition(CCPointMake((getContentSize().width - node->getContentSize().width) / 2, (getContentSize().height - node->getContentSize().height) / 2)); if (pData) { if (m_sbRatioOfEquality) { // float scale = (pData->scaleX < pData->scaleY) ? pData->scaleX : pData->scaleY; // m_fScaleX = m_fScaleY = scale; // node->setScale(scale); // updateAndAdjust(node, scale, scale); } else if (m_sbAdjustForDifferentScreent) { node->setAnchorPoint(CCPointZero); node->setPosition(CCPointZero); // float scale = (pData->scaleX < pData->scaleY) ? pData->scaleX : pData->scaleY; // m_fScaleX = m_fScaleY = scale; // node->setScale(scale); // updateAndAdjust(node, scale, scale); } else { // m_fScaleX = pData->scaleX; // m_fScaleY = pData->scaleY; // node->setScaleX(pData->scaleX); // node->setScaleY(pData->scaleY); // updateAndAdjust(node, pData->scaleX, pData->scaleY); } } else { // updateAndAdjust(node, 1, 1); } addChild(node); } node->setScaleX(m_fScaleX); node->setScaleY(m_fScaleY); updateAndAdjust(node); } if (m_pViewPage) { m_pViewPage->create(); } if (m_pTutorialNode) { m_pTutorialNode->updatePriority(m_pTutorialNode); // HTouchEnabledLayerColor *layer = dynamic_cast<HTouchEnabledLayerColor *>(m_pTutorialNode); // if (layer) layer->updatePriority(layer); } m_pCCbNode = node; CC_SAFE_RETAIN(m_pCCbNode); onShowEditbox(false); return node; }
void TaoZhuangInfoUI::onEnter() { CCLayer::onEnter(); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,-2014,true); CCSize size = CCDirector::sharedDirector()->getWinSize(); //m_lNodeList.push_back(spr); ccColor4B color = {0,0,0,100}; CCLayerColor *colorLayer1 = CCLayerColor::create(color); colorLayer1->setPosition(CCPointZero); colorLayer1->setContentSize(size); addChild(colorLayer1); UILayer* uiLayer = UILayer::create(); ///auto myLayout = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("testUI.ExportJson")); //alpha0中使用 Widget* myLayout = GUIReader::shareReader()->widgetFromJsonFile("NewFriendAddUI_2.ExportJson"); //alpha1中使用 uiLayer->addWidget(myLayout); this->addChild(uiLayer); //CCSize size = CCDirector::sharedDirector()->getWinSize(); myLayout->ignoreAnchorPointForPosition(false); myLayout->setAnchorPoint(ccp(0.5,0.5)); myLayout->setPosition(ccp(size.width / 2,size.height / 2)); //BaseSprite* getFullPhotoOfActor() unsigned int curGroupId = getZhuangbeiGroupID(m_sProfessionid); OneSuitInfo suitInfo; if(SuitPool::getPool()->getSuitInforByZBGroupId(curGroupId, suitInfo)) { //ImageManager::getManager()-> Label *name = dynamic_cast<Label*>(myLayout->getChildByName("Name")); if (name) { name->setText(suitInfo.suit_name.c_str()); } int index = 0; for (vector<SuitPart>::iterator iter = suitInfo.parts_of_suit.begin() ; iter != suitInfo.parts_of_suit.end() ; iter++) { index ++; Label *name1 = dynamic_cast<Label*>(myLayout->getChildByName(CCString::createWithFormat("Name%d",index)->getCString())); string nameTitle = iter->zhuangbei_name.c_str(); if (iter->zhuanbei_type == ZhuangbeiType_DanshouJian || iter->zhuanbei_type == ZhuangbeiType_ShuangshouBishou || iter->zhuanbei_type == ZhuangbeiType_ShuangshouFu || iter->zhuanbei_type == ZhuangbeiType_DanshouFazhang || iter->zhuanbei_type == ZhuangbeiType_Gong || iter->zhuanbei_type == ZhuangbeiType_ShuangshouFazhang) { nameTitle += LFStrings::getValue("ZhuangBeiWuQi"); } else if (iter->zhuanbei_type == ZhuangbeiType_Faqi || iter->zhuanbei_type == ZhuangbeiType_Dunpai) { nameTitle += LFStrings::getValue("ZhuangBeiFuShou"); } else if (iter->zhuanbei_type == ZhuangbeiType_Hushenfu) { nameTitle += LFStrings::getValue("ZhuangBeiHuShenFu"); } else if (iter->zhuanbei_type == ZhuangbeiType_KuijiaZhong || iter->zhuanbei_type == ZhuangbeiType_KuijiaQin) { nameTitle += LFStrings::getValue("ZhuangBeiXiongJia"); } else { nameTitle += LFStrings::getValue("ZhuangBeiJieZhi"); } name1->setText(nameTitle.c_str()); name1->setFontName(fontStr_kaiti); } for (int i = index + 1; i <= 6; i++) { Label *name1 = dynamic_cast<Label*>(myLayout->getChildByName(CCString::createWithFormat("Name%d",i)->getCString())); name1->setVisible(false); } for (int i = 0 ; i < 5 ; i ++) { Label *name2 = dynamic_cast<Label*>(myLayout->getChildByName(CCString::createWithFormat("Label%d",i + 1)->getCString())); name2->setFontName(fontStr_kaiti); Label *name1 = dynamic_cast<Label*>(myLayout->getChildByName(CCString::createWithFormat("ZB%dNumber",i + 1)->getCString())); if (suitInfo.suit_attr[i][0].attr_type == 0) { name2->setVisible(false); name1->setVisible(false); continue; } name1->setText(GetMoFaShuXing_ByZBAttr(suitInfo.suit_attr[i][0])); name1->setFontName(fontStr_kaiti); //string nameTitle = iter->zhuangbei_name.c_str(); } } { Label *miaoShuText = dynamic_cast<Label*>(myLayout->getChildByName("Label_50")); if (miaoShuText) { miaoShuText->setFontName(fontStr_kaiti); miaoShuText->setText(getNpcMiaoShu(m_sProfessionid).c_str()); } } CCNode *node = ImageManager::getManager()->getFullPhotoOfAllShenBing(m_sProfessionid); { UIImageView *taoZhuang = dynamic_cast<UIImageView*>(myLayout->getChildByName("Image_49")); if (taoZhuang) { myLayout->addNode(node,2); node->ignoreAnchorPointForPosition(false); node->setAnchorPoint(taoZhuang->getAnchorPoint()); node->setPosition(ccp(taoZhuang->getPositionX(),taoZhuang->getPositionY() + node->getContentSize().height / 2 + 100)); taoZhuang->setVisible(false); taoZhuang->setEnabled(false); } } { Button *closeItem = dynamic_cast<Button*>(myLayout->getChildByName("CloseBtn")); if (closeItem) { //m_iCloseItem = closeItem; m_lButtonList.push_back(closeItem); closeItem->addTouchEventListener(this, toucheventselector(TaoZhuangInfoUI::clickOk)); } } }
//初始化UI bool LayerMission::initUI() { CCPoint vo = CCDirector::sharedDirector()->getVisibleOrigin(); CCSize vs = CCDirector::sharedDirector()->getVisibleSize(); //背景 CCSprite* mission_bg = CCSprite::create("images/LayerMission_bg.png"); this->addChild(mission_bg); CCSize size_mission_bg = mission_bg->getContentSize(); mission_bg->setPosition(ccp(vo.x + vs.width * 0.5f, vo.y + vs.height * 0.5f)); //体力值 CCSprite* sp_physical = CCSprite::create("images/LayerMission_physical.png"); mission_bg->addChild(sp_physical); CCSize size_sp_physical = sp_physical->getContentSize(); sp_physical->setPosition(ccp(size_mission_bg.width * 0.52f, size_mission_bg.height * 0.78f)); //消耗的体力值 CCLabelAtlas* atlas_need_physical = CCLabelAtlas::create("10", RES_number_style_1, 20, 20, '0'); sp_physical->addChild(atlas_need_physical); atlas_need_physical->setAnchorPoint(ccp(0.5f, 0.5f)); CCSize size_atlas_need_physical = atlas_need_physical->getContentSize(); atlas_need_physical->setPosition(ccp(size_sp_physical.width * 0.28f, size_sp_physical.height * 0.45f)); //当前拥有的体力值 __atlas_total_physical = CCLabelAtlas::create("", RES_number_style_1, 20, 20, '0'); sp_physical->addChild(__atlas_total_physical); __atlas_total_physical->setAnchorPoint(ccp(0, 0.5f)); CCSize size_atlas_total_physical = __atlas_total_physical->getContentSize(); __atlas_total_physical->setPosition(ccp(size_sp_physical.width * 0.95f, size_sp_physical.height * 0.45f)); //名字 __ttf_name = CCLabelTTF::create("", "fonts/ttfs/MicrosoftYaHei.ttf", 40.0f); mission_bg->addChild(__ttf_name); __ttf_name->setColor(ccc3(218, 69, 231)); CCSize size_ttf_name = __ttf_name->getContentSize(); __ttf_name->setPosition(ccp(size_mission_bg.width * 0.205f, size_mission_bg.height * 0.77f)); //标题 __ttf_title = CCLabelTTF::create("", "fonts/ttfs/MicrosoftYaHei.ttf", 36.0f); mission_bg->addChild(__ttf_title); __ttf_title->enableStroke(ccc3(0, 117, 146), 1.0f); CCSize size_ttf_title = __ttf_title->getContentSize(); __ttf_title->setPosition(ccp(size_mission_bg.width * 0.5f, size_mission_bg.height - 32.0f)); //内容 __ttf_content = CCLabelTTF::create("", "fonts/ttfs/MicrosoftYaHei.ttf", 24.0f, CCSizeMake(460.0f, 110.0f), kCCTextAlignmentLeft); mission_bg->addChild(__ttf_content); __ttf_content->setAnchorPoint(ccp(0.5f, 1.0f)); CCSize size_ttf_content = __ttf_content->getContentSize(); __ttf_content->setPosition(ccp(size_mission_bg.width * 0.53f, size_mission_bg.height * 0.68f)); //目标 __ttf_mission = CCLabelTTF::create("", "fonts/ttfs/MicrosoftYaHei.ttf", 24.0f, CCSizeZero, kCCTextAlignmentLeft); mission_bg->addChild(__ttf_mission); __ttf_mission->setAnchorPoint(ccp(0, 0.5f)); __ttf_mission->enableStroke(ccc3(255, 0, 0), 1.0f); CCSize size_ttf_target = __ttf_mission->getContentSize(); __ttf_mission->setPosition(ccp(size_mission_bg.width * 0.13f, size_mission_bg.height * 0.32f)); //奖励 __ttf_reward = CCLabelTTF::create("", "fonts/ttfs/MicrosoftYaHei.ttf", 24.0f, CCSizeZero, kCCTextAlignmentLeft); mission_bg->addChild(__ttf_reward); __ttf_reward->setAnchorPoint(ccp(0, 0.5f)); __ttf_reward->enableStroke(ccc3(255, 255, 0), 1.0f); CCSize size_ttf_reward = __ttf_reward->getContentSize(); __ttf_reward->setPosition(ccp(size_mission_bg.width * 0.13f, size_mission_bg.height * 0.24f)); //任务指引选项 __item_mission_guide = CCMenuItemImage::create( "images/btn_mission_guide_0.png", "images/btn_mission_guide_1.png", this, menu_selector(LayerMission::menuCallbackMissionGuide)); CCSize size_item_mission_guide = __item_mission_guide->getContentSize(); __item_mission_guide->setPosition(ccp(size_mission_bg.width * 0.5f, size_item_mission_guide.height * 0.5f)); //获取奖励选项 __item_get_reward = CCMenuItemImage::create( "images/btn_get_reward_0.png", "images/btn_get_reward_1.png", this, menu_selector(LayerMission::menuCallbackGetReward)); CCSize size_item_get_reward = __item_get_reward->getContentSize(); __item_get_reward->setPosition(ccp(size_mission_bg.width * 0.5f, size_item_mission_guide.height * 0.5f)); //关闭项 CCMenuItemSprite *item_close = CCMenuItemSprite::create( CCSprite::create(RES_btn_close_1_0), CCSprite::create(RES_btn_close_1_0), this, menu_selector(LayerMission::menuCallbackClose) ); CCSize size_item_close = item_close->getContentSize(); CCNode *node = item_close->getNormalImage(); node->setAnchorPoint(ccp(0.5f, 0.5f)); node->setPosition(ccp(size_item_close.width * 0.5f, size_item_close.height * 0.5f)); node = item_close->getSelectedImage(); node->setAnchorPoint(ccp(0.5f, 0.5f)); node->setPosition(ccp(size_item_close.width * 0.5f, size_item_close.height * 0.5f)); node->setScale(1.2f); item_close->setPosition(ccp(size_mission_bg.width - size_item_close.width * 0.5f, size_mission_bg.height - size_item_close.height * 0.5f)); CCMenu* pMenu = CCMenu::create(item_close, __item_mission_guide, __item_get_reward, NULL); mission_bg->addChild(pMenu, 1); pMenu->setPosition(CCPointZero); updataMissionContent(); return true; }