Example #1
0
void GameHallLayer::initRoomItemCallback(Widget* widget, MyRoomList room)
{
    ImageView* img = static_cast<ImageView*>(UIHelper::seekWidgetByName(widget, "Image_back"));
    ImageView* enter = static_cast<ImageView*>(img->getChildByName("Image_enter"));
    Label*  lblWord = static_cast<Label*>(enter->getChildByName("Label_word"));
    Widget* panelFree = UIHelper::seekWidgetByName(widget, "Image_free_back");
    
    string room_back;
    string word;
    int level = DataManager::sharedDataManager()->currLevel;
    unsigned long long gold = DataManager::sharedDataManager()->currGold;
    
    if (level >= room.roomLevelLimt && gold >= room.roomGoldLimt)
    {
        word = "进入";
        room_back = CCString::createWithFormat("room%d.png",room.roomid)->getCString();
        
        //显示免费转动次数
        if (1 == room.roomid && DataManager::sharedDataManager()->currFreeNum > 0)
        {
            ImageView* freeIcon = static_cast<ImageView*>(UIHelper::seekWidgetByName(panelFree, "Image_free"));
            Label* freeNum = static_cast<Label*>(UIHelper::seekWidgetByName(panelFree, "Label_freeNum"));
            
            panelFree->setVisible(true);
            freeIcon->loadTexture(CCString::createWithFormat("free%d.png",room.roomid)->getCString(),UI_TEX_TYPE_PLIST);
            freeNum->setText(CCString::createWithFormat("x%d",DataManager::sharedDataManager()->currFreeNum)->getCString());
        }
    }
    else
    {
        if (level < room.roomLevelLimt)
            word = CCString::createWithFormat("%d级" , room.roomLevelLimt)->getCString();
        else
            word = CCString::createWithFormat("%lld万", room.roomGoldLimt / 10000)->getCString();
        
        room_back = CCString::createWithFormat("room%d_grey.png",room.roomid)->getCString();
    }
    
    string room_btn = CCString::createWithFormat("button_room%d.png",room.roomid)->getCString();
    enter->loadTexture(room_btn.c_str(),UI_TEX_TYPE_PLIST);
    img->loadTexture(room_back.c_str(),UI_TEX_TYPE_PLIST);
    lblWord->setText(word);
}