Пример #1
0
bool RobotLooseLayer::init()
{
    CCSize mapSize = GameParams::getInstanse()->mapSize();
    
    if ( !initWithColor(ccc4(145,145,145,255 * 0.45f)) )
    {
        return false;
    }
    
    CCLabelTTF *label = CCLabelTTF::create(CCLocalizedString("RobotBroken", "NotLocalized"), "Marker Felt", 42);
    
    label->setAnchorPoint( CCPointZero );
    label->setPosition( CCPointZero );
    
    addChild(label, 20);
    
    setContentSize(CCSizeMake(label->getContentSize().width, label->getContentSize().height));
    setPosition(ccp(mapSize.width / 2 - getContentSize().width / 2, -getContentSize().height));
    
    return true;
}
Пример #2
0
	void UITextInputField::LoadBinary(NiStream &kStream)
	{
		UIControlBase::LoadBinary(kStream);    

		mutableDic* dic = kStream.GetStreamData();
        
		float contentScale = CCDirector::sharedDirector()->getContentScaleFactor();
		
		uint32_t bLocalizeString = 0;
		kStream.getIntAttributeValue(dic, "bLocalizeString", bLocalizeString);

		std::string strTemp = "";
		kStream.getStringattributeValue(dic, "placeholder", strTemp);
		const char* placeholder = strTemp.c_str();
		if (bLocalizeString > 0)
		{
			placeholder = CCLocalizedString(strTemp.c_str(), strTemp.c_str());
		}

		uint32_t lengthLimit = 0;
		kStream.getIntAttributeValue(dic, "lengthLimit", lengthLimit);

		uint32_t isPassword = 0;
		kStream.getIntAttributeValue(dic, "isPassword", isPassword);

		int priority = kCCMenuHandlerPriority;
		kStream.getSignedIntAttributeValue(dic,"priority",priority);

		uint32_t dimensionWidth = 0;
		uint32_t dimensionHeight = 0;
		kStream.getIntAttributeValue(dic, "dimensionWidth", dimensionWidth);
		kStream.getIntAttributeValue(dic, "dimensionHeight", dimensionHeight);
        
        dimensionWidth /= contentScale;
        dimensionHeight /= contentScale;

		uint32_t alignment = 1;
		kStream.getIntAttributeValue(dic, "alignment", alignment);

		mutableDic *colorDic = static_cast<mutableDic*>(dic->objectForKey("color"));
		uint32_t color[3] = {255, 255, 255};
		if(colorDic)
		{
			kStream.getIntAttributeValue(colorDic, "red", color[0]);
			kStream.getIntAttributeValue(colorDic, "green", color[1]);
			kStream.getIntAttributeValue(colorDic, "blue", color[2]);
		}

		string font = KJLinXin;
		kStream.getStringattributeValue(dic, "font", font);

        float largeFontSize = GameFontManager::largeFontSize();
		uint32_t fontSize = largeFontSize * contentScale;
		kStream.getIntAttributeValue(dic, "fontSize", fontSize);
		fontSize /= contentScale;

		CCSize dimension = CCSizeMake(dimensionWidth, dimensionHeight);
		if(dimensionWidth > 0 && dimensionHeight < fontSize)
		{
			dimension = CCSizeMake(dimensionWidth, fontSize);
		}
        
		CCSize touchSize = CCSizeZero;
		mutableDic *rectDic = static_cast<mutableDic*>(dic->objectForKey("rect"));
		if(rectDic)
		{
			uint32_t useASRect = 0;
			std::string ASRectName = "";
			std::string ASfile = KUI_BIN;
			uint32_t anchorPoint = 0;
			// if use Asprite Rect
			kStream.getIntAttributeValue(rectDic, "useASRect", useASRect);
			kStream.getIntAttributeValue(rectDic, "anchorPoint", anchorPoint);
			if(useASRect == 1)
			{
				kStream.getStringattributeValue(rectDic, "ASRectName", ASRectName);
				if(ASRectName != "")
				{
					mutableDic* dicAsMgr = static_cast<mutableDic*>(rectDic->objectForKey("AspriteManager"));
					// content attributes 
					if (dicAsMgr)
					{
						if (IsIpad())
						{
							kStream.getStringattributeValue(dicAsMgr, "ipad", ASfile); 
						}else
						{
							kStream.getStringattributeValue(dicAsMgr, "iphone", ASfile); 
						}
					}
					int ID = getResourceIDByName(ASRectName.c_str());
					// name not exists, use normal method
					if(ID != -1)
					{
						ASprite *as = AspriteManager::getInstance()->getAsprite(ASfile);
						CCRect asRect = as->getframeRect(ID);
						touchSize = asRect.size;
						switch(anchorPoint)
						{
						case 0:
							{
								CCRect rect = as->getframeRect(ID);
								m_ptWorldPosition = rect.origin;
							}
							break;

						case 1:
							m_ptWorldPosition = as->GetFramePointMiddle(ID);
							break;

						default:
							break;
						}

						CCPoint parentWorldPosition = CCPointZero;
						if(m_pParent != NULL)
						{
							parentWorldPosition = m_pParent->getWorldPosition();
						}

						m_ptLocalPosition.x = m_ptWorldPosition.x - parentWorldPosition.x;
						m_ptLocalPosition.y = m_ptWorldPosition.y - parentWorldPosition.y;
					}
				}
			}
		}

		m_pTextInputField = TextInputField::textFieldWithPlaceHolder(placeholder,
			dimension,
			(CCTextAlignment)alignment,
			font.c_str(),
			(float)fontSize
			);

		m_pTextInputField->setAnchorPoint(ccp(0.5, 0.5));
		m_pTextInputField->setPosition(m_ptLocalPosition);
		m_pTextInputField->setLengthLimit(lengthLimit);
		m_pTextInputField->setIsPassword(isPassword != 0);
		m_pTextInputField->setColor(ccc3(color[0], color[1], color[2]));
		m_pTextInputField->setInitPriority(priority);
		m_pTextInputField->setTouchInputSize(touchSize);
		// make background
		CreateWhiteBack();
		if(m_pWhiteBack != NULL)
		{
			m_pWhiteBack->setPosition(m_ptLocalPosition);
			m_pWhiteBack->setVisible(m_bIsVisible);
		}

		m_pControlNode = m_pTextInputField;
		m_pControlNode->setVisible(m_bIsVisible);
	}
Пример #3
0
bool UpStateLayer::init()
{
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
    if (!CCLayerColor::initWithColor(Color_Up_Down,origin.x+visibleSize.width,UpHeight)) {
        
        return false;
    }
    
    m_Level_bg = CCMenuItem::create(this, menu_selector(UpStateLayer::menuBePressed));
    m_Top_bg = CCMenuItem::create(this, menu_selector(UpStateLayer::menuBePressed));
    m_Score_bg = CCMenuItem::create(this, menu_selector(UpStateLayer::menuBePressed));
    

    m_Level_bg->ignoreAnchorPointForPosition(false);
    m_Top_bg->ignoreAnchorPointForPosition(false);
    m_Score_bg->ignoreAnchorPointForPosition(false);
    m_Level_bg->setAnchorPoint(ccp(0, 0.5));
    m_Top_bg->setAnchorPoint(ccp(0, 0.5));
    m_Score_bg->setAnchorPoint(ccp(0, 0.5));
    
    
    
    //menu
    CCMenu * menu = CCMenu::create(m_Level_bg,m_Top_bg,m_Score_bg,NULL);
    menu->setAnchorPoint(ccp(0, 0));
    menu->setPosition(ccp(0, 0));
    this->addChild(menu);
    
    if (SettingHelper::getGameType() == GAME_TYPE_CLASSIC || SettingHelper::getGameType() == GAME_TYPE_SPEED) {
        
        m_Score_bg->setContentSize(CCSizeMake(this->getContentSize().width/2, UpHeight));
        m_Top_bg->setContentSize(CCSizeMake(this->getContentSize().width/2, UpHeight));
        
        //最高分/得分
        m_Top_bg->setPosition(ccp(0,UpHeight/2));
        m_Score_bg->setPosition(ccp(this->getContentSize().width/2,UpHeight/2));
        
    }else{
        
        m_Level_bg->setContentSize(CCSizeMake(this->getContentSize().width/3, UpHeight));
        m_Score_bg->setContentSize(CCSizeMake(this->getContentSize().width/3, UpHeight));
        
        //等级/目标/得分
        m_Level_bg->setPosition(ccp(0,UpHeight/2));
        m_Score_bg->setPosition(ccp(this->getContentSize().width/2,UpHeight/2));
        
    }

    title_score = CCLabelTTF::create(CCLocalizedString("score", ""), "fonts/Josefin Sans.ttf", 12);
    title_level = CCLabelTTF::create(CCLocalizedString("level", ""), "fonts/Josefin Sans.ttf", 12);
    title_top = CCLabelTTF::create(CCLocalizedString("top", ""), "fonts/Josefin Sans.ttf", 12);
    title_goal = CCLabelTTF::create(CCLocalizedString("goal", ""), "fonts/Josefin Sans.ttf", 12);
    
    title_score->setAnchorPoint(ccp(0, 0.5));
    title_score->setColor(Color_Text);
    
    title_top->setAnchorPoint(ccp(0, 0.5));
    title_top->setColor(Color_Text);
    
    title_level->setAnchorPoint(ccp(0, 0.5));
    title_level->setColor(Color_Text);
    
    title_goal->setAnchorPoint(ccp(0, 0.5));
    title_goal->setColor(Color_Text);
    
    
    
    m_Level_bg->addChild(title_level);
    m_Level_bg->addChild(title_goal);
    m_Top_bg->addChild(title_top);
    m_Score_bg->addChild(title_score);
    
    

    
    
    //labels
    m_labelScore = CCLabelTTF::create("0", "fonts/Josefin Sans.ttf", 20);
    m_labelLevel = CCLabelTTF::create("0", "fonts/Josefin Sans.ttf", 20);
    m_labelGoal = CCLabelTTF::create("0", "fonts/Josefin Sans.ttf", 20);
    m_labelTop = CCLabelTTF::create("0", "fonts/Josefin Sans.ttf", 20);

    
    
    m_labelTop->setAnchorPoint(ccp(0, 0.5));
    m_labelTop->setColor(Color_Text);
    
    m_labelScore->setAnchorPoint(ccp(0, 0.5));
    m_labelScore->setColor(Color_Text);
    
    m_labelLevel->setAnchorPoint(ccp(0, 0.5));
    m_labelLevel->setColor(Color_Text);
    
    m_labelGoal->setAnchorPoint(ccp(0, 0.5));
    m_labelGoal->setColor(Color_Text);
    
    m_Level_bg->addChild(m_labelLevel);
    m_Level_bg->addChild(m_labelGoal);
    m_Top_bg->addChild(m_labelTop);
    m_Score_bg->addChild(m_labelScore);
    
    
    
    //设置位置
    resetItemPosition();
    
    
    //progress
    CCSprite *psSprite1 = CCSprite::create("progress_bar.png");
    
    //利用精灵创建进度条,并设置一些属性
    progresstime1 = CCProgressTimer::create(psSprite1);    //初始化CCProgressTimer
    progresstime1->setPercentage(100.0f);    //设置初始百分比的值
    //    Setup for a bar starting from the left since the midpoint is 0 for the x
    progresstime1->setMidpoint(ccp(0,0));
    //    Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change
    progresstime1->setBarChangeRate(ccp(1, 0));
    progresstime1->setType(kCCProgressTimerTypeBar);    //设置进度条为水平
    progresstime1->setAnchorPoint(ccp(0, 0));
    progresstime1->setPosition(ccp(0, 0));    //放置进度条位置
    
    
    this->addChild(progresstime1, 100);    //加入Layer中
    
    
    
    this->scheduleUpdate();
    
    
    this->setVisible(false);
    
    return true;
}
Пример #4
0
bool SelectMenuLayer::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    m_bKeypadEnabled=true;
    m_bTouchEnabled = true;
    
    CCSize screenSize = GameParams::getInstanse()->screenSize;
    
    setPosition( ccp (0,0) );
    
    CCSprite *backGround  = CCSprite::create(PICT_PATH "Background/background1.png" );
    backGround->setPosition( ccp(screenSize.width/2, screenSize.height/2) );
    resizeSprite(backGround, screenSize.width, screenSize.height);
    addChild(backGround, -1);
    
    CCMenu *navigationMenu = CCMenu::create(NULL);
    worldSelectMenu = CCMenu::create();
    
    
    

    worldSelectMenu->setPosition( ccp(0, 50 * GetGameParams->worlds.size() / 2) );
    for (int i = 0; i < GetGameParams->worlds.size(); ++i) {
        CCMenuItemFont * world_ = CCMenuItemFont::create(
                                                         CCString::createWithFormat(CCLocalizedString("WorldPattern", "NotLocalized"), i+1)->m_sString.c_str(), this, menu_selector(SelectMenuLayer::setWorld)
                                                         );
        world_->setPosition( ccp(screenSize.width / 2, screenSize.height / 2 - i*50) );
        worldSelectMenu->addChild(world_);
    }

    
    
#ifdef MAP_EDITOR
    plusButton = CCMenuItemFont::create("+", this, menu_selector(SelectMenuLayer::addWorld));
    plusButton->setPosition( ccp(screenSize.width / 2, screenSize.height / 2 - GetGameParams->worlds.size()*50) );
    worldSelectMenu->addChild(plusButton,1);
#endif
    
    addChild(worldSelectMenu);
    
#ifdef MAP_EDITOR
    CCMenuItemFont *uploadToServer = CCMenuItemFont::create("Загрузить на сервер", this, menu_selector(SelectMenuLayer::uploadMapsToServer));
    uploadToServer->setPosition( ccp (170, screenSize.height - 75) );
    uploadToServer->setColor(ccc3(20, 200, 20));
    navigationMenu->addChild(uploadToServer);
#endif
    
    CCMenuItemFont *goToMain = CCMenuItemFont::create(CCLocalizedString("BackToMainMenu", "NotLocalized"), this, menu_selector(SelectMenuLayer::mainMenu));
    goToMain->setPosition( ccp (170, screenSize.height - 25) );
    
    navigationMenu->addChild(goToMain);
    navigationMenu->setPosition( CCPointZero );
    addChild(navigationMenu, 1);
    
    
    return true;
}