Exemple #1
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);
	}
Exemple #2
0
	void UIScrollPage::LoadBinary(NiStream &kStream)
	{
		UIControlBase::LoadBinary(kStream);

		uint32_t contentWidth = 0;
		uint32_t contentHeight = 0;
		uint32_t direction = 0;
		int priority = kCCScrollTouchPriority;

		mutableDic *dic = kStream.GetStreamData();

		// get button click callback function
		kStream.getStringattributeValue(dic, "itemClickedCallback", m_strItemClickedFun);
		kStream.getStringattributeValue(dic, "itemDoubleClickedCallback", m_strItemDoubleClickedFun);
		kStream.getStringattributeValue(dic, "itemDragReleaseCallback", m_strItemDragReleaseFun);
		kStream.getStringattributeValue(dic, "tappedCallback", m_strTappedFun);
		kStream.getStringattributeValue(dic, "tapCancelCallback", m_strTapCancelFun);

		kStream.getIntAttributeValue(dic, "itemType", m_itemType);
		kStream.getIntAttributeValue(dic, "contentWidth", contentWidth);
		kStream.getIntAttributeValue(dic, "contentHeight", contentHeight);
		kStream.getIntAttributeValue(dic, "direction", direction);
		kStream.getSignedIntAttributeValue(dic, "indicatorOffsetX", m_indicatorOffsetX);
		kStream.getSignedIntAttributeValue(dic, "indicatorOffsetY", m_indicatorOffsetY);
        kStream.getSignedIntAttributeValue(dic,"priority",priority);

        contentWidth /= CC_CONTENT_SCALE_FACTOR();
        contentHeight /= CC_CONTENT_SCALE_FACTOR();
        m_indicatorOffsetX /= CC_CONTENT_SCALE_FACTOR();
        m_indicatorOffsetY /= CC_CONTENT_SCALE_FACTOR();
        
		setDirection((EScrollDirection)direction);

		// query frameRect property
		mutableDic* framedic = static_cast<mutableDic*>(dic->objectForKey("frameRect"));
		if( framedic )
		{
			string rectAsIndex = "";			
			kStream.getStringattributeValue(framedic, "rectAsIndex", rectAsIndex);	
			uint32_t  useAscontentRect = 0;
			kStream.getIntAttributeValue(framedic, "useAscontentRect", useAscontentRect);
			if (useAscontentRect)
			{
				CCPoint pt;
				string ASfile = KUI_BIN;
				kStream.getStringattributeValue(framedic, "binFile", ASfile); 
				ASprite *as = AspriteManager::getInstance()->getAsprite(ASfile);   

				int idx = getResourceIDByName(rectAsIndex.c_str());
				CCRect scrollRect = as->getframeRect(idx);
				CCPoint scrollCenter = as->GetFramePointMiddle(idx);

				// re-calculate the local position 
				CCPoint parentWorldPosition = CCPointZero;
				if(m_pParent != NULL)
				{
					parentWorldPosition = m_pParent->getWorldPosition();
				}

				m_ptLocalPosition.x = scrollCenter.x - parentWorldPosition.x;
				m_ptLocalPosition.y = scrollCenter.y - parentWorldPosition.y;

				setContentSize(scrollRect.size);
			}
		}
		else
		{
			setContentSize(CCSize(contentWidth, contentHeight));
		}

		m_pScrollLayer = UIScrollLayer::nodeWithNoLayer(m_contentSize, m_direction);
		m_pScrollLayer->setPosition(m_ptLocalPosition);
		m_pScrollLayer->setPagesIndicatorPosition(ccp(m_indicatorOffsetX, m_indicatorOffsetY));
		m_pScrollLayer->setPriority(priority);
		m_pScrollLayer->setVisible(m_bIsVisible);
		m_pControlNode = m_pScrollLayer->getBaseLayer();

		// add pages
		mutableDic* pageDic = static_cast<mutableDic*>(dic->objectForKey("page"));
		if( pageDic )
		{
			kStream.getIntAttributeValue(pageDic, "count", m_ipageCount); 
			kStream.getIntAttributeValue(pageDic, "column", m_icolumn); 
			kStream.getIntAttributeValue(pageDic, "row", m_irow); 
			kStream.getIntAttributeValue(pageDic, "cellOffsetX", m_celloffsetX); 
			kStream.getIntAttributeValue(pageDic, "cellOffsetY", m_celloffsetY);
            
            m_celloffsetX /= CC_CONTENT_SCALE_FACTOR();
            m_celloffsetY /= CC_CONTENT_SCALE_FACTOR();
            
			m_bIsConfiged = true;
		}

		m_cellAsfile = "";
		kStream.getStringattributeValue(dic, "cellAsIndex", m_cellAsfile);
		m_cellSelectedAsfile = "";
		kStream.getStringattributeValue(dic, "cellSelectedAsIndex", m_cellSelectedAsfile);
		if (m_cellAsfile.empty() == false)
		{
			CCPoint pt;
			m_cellBinFile = KUI_BIN;
			kStream.getStringattributeValue(dic, "binFile", m_cellBinFile); 
			ASprite *as = AspriteManager::getInstance()->getAsprite(m_cellBinFile);   
			int idx = getResourceIDByName(m_cellAsfile.c_str());
			m_cellRect = as->getframeRect(idx);
		}

		for(int i = 0 ; i < (int) m_ipageCount ; i ++)
		{
			addOneEmptyPage(i);
		}
	}