Exemple #1
0
void Bag::initEquips()
{
	UIPanel* equipPanel = dynamic_cast<UIPanel*>(uiLayer->getWidgetByName("equippanel"));
	CCArray* equips = equipPanel->getChildren();
	CCObject* object = NULL;

	int bagGridCount = 1;

	int equipType = EQUIP_TYPE_HELMET;		//the first type of equip

	CCARRAY_FOREACH(equips,object)
	{
		UIPanel* equipChildPanel = (UIPanel*)object;
		CCArray* equips = equipChildPanel->getChildren();

		int equipStartNum = 1;

		CCARRAY_FOREACH_REVERSE(equips, object)
		{
			UIWidget* equip = dynamic_cast<UIWidget*>(object);
			equip->addTouchEventListener(this,toucheventselector(Bag::touchEvent));
			initEquipID(equip,equipType,equipStartNum);
			
			UIWidget* bagGrid = getBagGrid(bagGridCount++);
			changeParent(bagGrid,equip);

			equipStartNum++;
		}
static int lua_cocos2dx_UIWidget_addTouchEventListener(lua_State* L)
{
    if (nullptr == L)
        return 0;
    
    int argc = 0;
    UIWidget* self = nullptr;
    
#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
	if (!tolua_isusertype(L,1,"UIWidget",0,&tolua_err)) goto tolua_lerror;
#endif
    
    self = static_cast<UIWidget*>(tolua_tousertype(L,1,0));
    
#if COCOS2D_DEBUG >= 1
	if (nullptr == self) {
		tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_UIWidget_addTouchEventListener'\n", NULL);
		return 0;
	}
#endif
    
    argc = lua_gettop(L) - 1;
    
    if (1 == argc)
    {
#if COCOS2D_DEBUG >= 1
        if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err))
        {
            goto tolua_lerror;
        }
#endif
        LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create();
        if (nullptr == listener)
        {
            tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL);
            return 0;
        }
        
        LUA_FUNCTION handler = (  toluafix_ref_function(L,2,0));
        
        ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::EVENT_LISTENER);
        
        self->setUserObject(listener);
        self->addTouchEventListener(listener, toucheventselector(LuaCocoStudioEventListener::eventCallbackFunc));
                
        return 0;
    }
    
    CCLOG("'addTouchEventListener' function of UIWidget has wrong number of arguments: %d, was expecting %d\n", argc, 1);
    return 0;
    
#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(L,"#ferror in function 'addTouchEventListener'.",&tolua_err);
    return 0;
#endif
}
void SelectMenuView::noticeView(SelectMenuModel* model)
{
#pragma region RESET_SCROLL_RECT
	char tmp[32];
	UIPageView* scrollView = static_cast<UIPageView*>(this->getWidgetByName("scrollView"));
	for( int i = 0; i < MAX_BEAUTY_NUM; i++ )
	{
		UIWidget* widget = scrollView->getChildByTag( i + CARD_TAG );
		widget->addTouchEventListener(this , toucheventselector(SelectMenuView::onTouchBeautyCard));
		//UIImageView* card_bg = static_cast<UIImageView*>(widget->getChildByName("card_bg"));
		//card_bg->setTouchEnabled(true);
		//card_bg->addTouchEventListener(this , toucheventselector(SelectMenuView::touchBeautyCard));

		UILabelBMFont* nameTxt = static_cast<UILabelBMFont*>(widget->getChildByName("txt_name"));
		UILabelBMFont* timeTxt = static_cast<UILabelBMFont*>(widget->getChildByName("txt_time"));
		UIImageView* beautyHead = static_cast<UIImageView*>(widget->getChildByName("head"));
		UIImageView* beContinue = static_cast<UIImageView*>(widget->getChildByName("moreLevel"));
		UIImageView* passRibbon = static_cast<UIImageView*>(widget->getChildByName("lock"));
		UIImageView* hearts[MAX_HEART];
		UIImageView* stars[MAX_STAR];
		for( int n = 0; n < MAX_HEART; n++ )
		{
			sprintf( tmp, "heart%d",n+1 );
			hearts[n] = static_cast<UIImageView*>(widget->getChildByName(tmp));
			hearts[n]->setVisible(false);
			sprintf( tmp, "star%d",n+1 );
			stars[n] = static_cast<UIImageView*>(widget->getChildByName(tmp));
			stars[n]->setVisible(false);
		}

		if( i < REAL_BEAUTY_NUM )
		{
			BeautyData data = model->getBeautyData(i);
			// --------------------------- Setting ---------------------------
			//if( i < REAL_BEAUTY_NUM )
			//{
				sprintf( tmp , "head_%d.png" , i);
				beautyHead->loadTexture(tmp ,UI_TEX_TYPE_PLIST);
			//}
			nameTxt->setText( data.name );
			if(data.time>9) sprintf( tmp,"%d:00", data.time );
			else sprintf( tmp,"0%d:00", data.time );
			timeTxt->setVisible(true);
			timeTxt->setText(tmp);
			for ( int n = 0; n < MAX_STAR; n++ )
			{
				if( n < data.difficult ) stars[n]->setVisible(true);
				else stars[n]->setVisible(false);
			}
			int heartNum = model->getUserGainHeartNum(i);
			for ( int n = 0; n < MAX_HEART; n++ )
			{
				if( n < heartNum ) hearts[n]->setVisible(true);
				else hearts[n]->setVisible(false);
			}
			beContinue->setVisible(false);
			if(heartNum < 0)
			{// not pass && close
				passRibbon->setVisible(true);
			}
			else
			{// pass || open
				passRibbon->setVisible(false);
			}
		}
		/////////////
		else
		{
			if(i == MAX_BEAUTY_NUM - 1 )
			{
				beContinue->setVisible(true);
				beautyHead->loadTexture("head_9.png" ,UI_TEX_TYPE_PLIST);
			}
			else
			{
				sprintf( tmp , "head_%d.png" , i);
				beautyHead->loadTexture(tmp ,UI_TEX_TYPE_PLIST);
			}
			nameTxt->setText( "???????????" );
			timeTxt->setText("--:--");
			passRibbon->setVisible(false);
		}
	}
#pragma endregion
}