// on "init" you need to initialize your instance
bool TableViewTestLayer::init()
{
    if ( !Layer::init() )
    {
        return false;
    }

	Size winSize = Director::sharedDirector()->getWinSize();

    TableView* tableView = TableView::create(this, CCSizeMake(250, 60));
    tableView->setDirection(kScrollViewDirectionHorizontal);
    tableView->setPosition(ccp(20,winSize.height/2-30));
    tableView->setDelegate(this);
    this->addChild(tableView);
    tableView->reloadData();

	tableView = TableView::create(this, CCSizeMake(60, 250));
	tableView->setDirection(kScrollViewDirectionVertical);
	tableView->setPosition(ccp(winSize.width-150,winSize.height/2-120));
	tableView->setDelegate(this);
	tableView->setVerticalFillOrder(kTableViewFillTopDown);
	this->addChild(tableView);
	tableView->reloadData();

	// Back Menu
	MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(TableViewTestLayer::toExtensionsMainLayer, this));
	itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
	Menu *menuBack = Menu::create(itemBack, NULL);
	menuBack->setPosition(PointZero);
	addChild(menuBack);

    return true;
}
// on "init" you need to initialize your instance
bool TableViewTest::init()
{
    if ( !TestCase::init() )
    {
        return false;
    }

	Size winSize = Director::getInstance()->getWinSize();

    TableView* tableView = TableView::create(this, Size(250, 60));
    tableView->setDirection(ScrollView::Direction::HORIZONTAL);
    tableView->setPosition(Vec2(20,winSize.height/2-30));
    tableView->setDelegate(this);
    this->addChild(tableView);
    tableView->reloadData();

	tableView = TableView::create(this, Size(60, 250));
	tableView->setDirection(ScrollView::Direction::VERTICAL);
	tableView->setPosition(Vec2(winSize.width-150,winSize.height/2-120));
	tableView->setDelegate(this);
	tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
	this->addChild(tableView);
	tableView->reloadData();

    return true;
}
// on "init" you need to initialize your instance
bool TableViewTestLayer::init()
{
    if ( !Layer::init() )
    {
        return false;
    }

	Size winSize = Director::getInstance()->getWinSize();

    TableView* tableView = TableView::create(this, Size(250, 60));
    tableView->setDirection(ScrollView::Direction::HORIZONTAL);
    tableView->setPosition(Point(20,winSize.height/2-30));
    tableView->setDelegate(this);
    this->addChild(tableView);
    tableView->reloadData();

	tableView = TableView::create(this, Size(60, 250));
	tableView->setDirection(ScrollView::Direction::VERTICAL);
	tableView->setPosition(Point(winSize.width-150,winSize.height/2-120));
	tableView->setDelegate(this);
	tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
	this->addChild(tableView);
	tableView->reloadData();

	// Back Menu
	MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(TableViewTestLayer::toExtensionsMainLayer, this));
	itemBack->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
	Menu *menuBack = Menu::create(itemBack, NULL);
	menuBack->setPosition(Point::ZERO);
	addChild(menuBack);

    return true;
}
Exemple #4
0
// on "init" you need to initialize your instance
bool Overview::init()
{
    //初期化
    if ( !Layer::init() ) return false;
    
    //userDefaultの読み込み
    userDefault = UserDefault::getInstance();
    
    //ストーリー
    storyManager = StoryManager::getInstance();
    
    //話数
    story_count = storyManager->getStoryCount();
    
    //リスト
    story_list = storyManager->gets();
    
    //画面サイズサイズを取得
    window_size = Director::getInstance()->getWinSize();
    
    TableView* tableView = TableView::create(this, Size(window_size.width / 100 * 80, window_size.height / 100 * 80));
    //展開方向
    tableView->setDirection(TableView::Direction::VERTICAL);
    //表示順序上からしたへ
    tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
    tableView->setPosition(Point((window_size.width - tableView->getContentSize().width) / 2, 20));
    tableView->setBounceable(false);
    //追加
    tableView->setDelegate(this);
    addChild(tableView);
    tableView->reloadData();
    return true;
}
// on "init" you need to initialize your instance
bool MainScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }

    initBackground();

    curEquipment = NULL;
	Size winSize = Director::getInstance()->getWinSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	TableView* tableView = TableView::create(this, Size(winSize.width, 200));
	tableView->setDirection(ScrollView::Direction::HORIZONTAL);
	tableView->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	tableView->setPosition(Point(winSize.width*0.2 + origin.x, winSize.height/2 + origin.y - 50));
	tableView->setDelegate(this);
	this->addChild(tableView);
	tableView->reloadData();

	auto listener = EventListenerKeyboard::create();
	listener->onKeyReleased = CC_CALLBACK_2(MainScene::onKeyReleased,this);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,this);

    return true;
}
Exemple #6
0
bool SceneRule::init()
{
    if (!Layer::init()) {
        return false;
    }
    
    auto bg = KUtil::addSprite(this, KUtil::getPath(F_BG, "bg_3.png"), Point(HALF_WIDTH, 0), ANCHOR_CENTER_DOWN, 0);
    bg->setScale(KUtil::getScale(FULL_WIDTH, FULL_HEIGHT, bg->getContentSize(), true));
    
    Size size = Size(FULL_WIDTH-20, FULL_HEIGHT-160-10);
    auto tbg = GameTool::addTextBg(this, size, Point(10, 160), ANCHOR_LEFT_DOWN, 10);
    
    detailLabel = KUtil::addLabelConfig(tbg, DETAIL_POINT_MATCH, KUtil::getPath(F_FONT, "luoliti.ttf"), 30, Point(10, 10), Color4B(0, 0, 0, 255), ANCHOR_LEFT_DOWN, 10, Size(size.width-20, size.height-20), TextHAlignment::LEFT, TextVAlignment::TOP);
    
    Vector<MenuItem *> itemArray;
    
    GameTool::addBtn2(&itemArray, "返回", 32, Point(FULL_WIDTH-5, FULL_HEIGHT-5), ANCHOR_RIGHT_UP, CC_CALLBACK_1(SceneRule::callbackBack, this));
    
    KUtil::addMenu(this, &itemArray, 30);
    
    listQAKind.pushBack(QAKind::create(QAKIND_POINT_MATCH, "普通赛规则"));
    listQAKind.pushBack(QAKind::create(QAKIND_HUNDRED_MATCH, "冲百赛规则"));
    listQAKind.pushBack(QAKind::create(QAKIND_BIGTWO_RULE, "锄大地规则"));
    
    cellHeight = 160;
    cellWidth = 250;
    TableView* tableView = TableView::create(this, Size(FULL_WIDTH, cellHeight));
    tableView->setDirection(ScrollView::Direction::HORIZONTAL);
    tableView->setPosition(Point(0, 0));
    tableView->setDelegate(this);
    this->addChild(tableView, 100);
    tableView->reloadData();
    
    return true;
}
static int lua_cocos2dx_TableView_setDelegate(lua_State* L)
{
    if (nullptr == L)
        return 0;

    int argc = 0;
    TableView* self = nullptr;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
    if (!tolua_isusertype(L,1,"cc.TableView",0,&tolua_err)) goto tolua_lerror;
#endif

    self = (TableView*)  tolua_tousertype(L,1,0);

#if COCOS2D_DEBUG >= 1
    if (nullptr == self)
    {
        tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TableView_setDelegate'\n", nullptr);
        return 0;
    }
#endif

    argc = lua_gettop(L) - 1;

    if (0 == argc)
    {
        LUA_TableViewDelegate* delegate = new (std::nothrow) LUA_TableViewDelegate();
        if (nullptr == delegate)
            return 0;

        __Dictionary* userDict = static_cast<__Dictionary*>(self->getUserObject());
        if (nullptr == userDict)
        {
            userDict = new __Dictionary();
            if (NULL == userDict)
                return 0;

            self->setUserObject(userDict);
            userDict->release();
        }

        userDict->setObject(delegate, KEY_TABLEVIEW_DELEGATE);
        self->setDelegate(delegate);
        delegate->release();

        return 0;
    }

    luaL_error(L, "'setDelegate' function of TableView wrong number of arguments: %d, was expecting %d\n", argc, 0);
    return 0;

#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(L,"#ferror in function 'setDelegate'.",&tolua_err);
    return 0;
#endif
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    TableView *tv = TableView::create(this,Size(300,300));
    
    tv->setAnchorPoint(Point(0,0));
    tv->setPosition(100, 100);
    tv->setDelegate(this);
    addChild(tv);
    
    return true;
}
Exemple #9
0
bool TaskListLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}

	Size size = Director::getInstance()->getVisibleSize();

	TableView* tableView = TableView::create(this, Size(600, 500));
	tableView->setDirection(cocos2d::extension::ScrollView::Direction::VERTICAL); //方向垂直
	tableView->setPosition(Point::ZERO);
	tableView->setDelegate(this);
	tableView->setTag(0);
	addChild(tableView);

	tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);  //填充次序从上到下
	tableView->reloadData();

	return true;
}
Exemple #10
0
// on "init" you need to initialize your instance
bool ArtScene::init()
{
	setTouchEnabled(false);
	CCLog("INIT!");
	//draw a giant box behind everything
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();
	_selectedIndex = 0;
	_selectedGallary = GameManager::getInstance()->getSelectedGallary();
	_selectedArt = ArtManager::getInstance()->getArt(_selectedGallary->artIds.at(_selectedIndex));

	auto background = LayerColor::create(Color4B::WHITE, visibleSize.width, visibleSize.height);
	background->setPosition(Point(0, 0));
	addChild(background);

	auto redBox = TopBar::create();
	addChild(redBox);

	auto blackBox = LayerColor::create(Color4B::BLACK, visibleSize.width, 40 * G_assetScale);
	blackBox->setPosition(Point(0, 0));
	addChild(blackBox);

	auto gradBox1 = LayerGradient::create(Color4B(120, 120, 120, 255), Color4B(243, 243, 243, 255), Point(1, 0));
	gradBox1->setContentSize(Size(visibleSize.width * 0.5f, 60 * G_assetScale));
	gradBox1->setPosition(Point(0, 40 * G_assetScale));
	addChild(gradBox1);

	auto gradBox2 = LayerGradient::create(Color4B(243, 243, 243, 255), Color4B(120, 120, 120, 255), Point(1, 0));
	gradBox2->setContentSize(Size(visibleSize.width * 0.5f, 60 * G_assetScale));
	gradBox2->setPosition(Point(visibleSize.width * 0.5f, 40 * G_assetScale));
	addChild(gradBox2);

	auto slimBar = LayerColor::create(Color4B(151, 151, 151, 255), visibleSize.width, 1);
	slimBar->setPosition(Point(0, 100 * G_assetScale));
	addChild(slimBar);

	auto slimBar2 = LayerColor::create(Color4B(51, 51, 51, 255), visibleSize.width, 1);
	slimBar2->setPosition(Point(0, visibleSize.height - redBox->getContentSize().height - 1));
	addChild(slimBar2);

	auto picBox = LayerColor::create(Color4B::BLACK, visibleSize.width - 50, 120 * G_assetScale);
	picBox->setPosition(Point(25, visibleSize.height - 240 * G_assetScale));
	addChild(picBox);

	auto artY = 180.0f * G_assetScale;
	_artImage = CCSprite::create();
	_artImage->setPosition(Point(visibleSize.width * 0.5f, visibleSize.height - artY));
	addChild(_artImage);

	float starBoxSize = 75 * G_assetScale;
	float starBoxPadding = 18 * G_assetScale;
	float starY = 128 * G_assetScale;
	float starX1 =(visibleSize.width - starBoxSize) * 0.5f;
	float starX2 = starX1 - (starBoxPadding + starBoxSize);
	float starX3 = starX1 + starBoxPadding + starBoxSize;
	
	_starBox1 = (DifficultyButton*)DifficultyButton::create();
	_starBox1->setPosition(starX2, starY);
	addChild(_starBox1);
	
	_starBox2 = (DifficultyButton*)DifficultyButton::create();
	_starBox2->setPosition(starX1, starY);
	addChild(_starBox2);

	_starBox3 = (DifficultyButton*)DifficultyButton::create();
	_starBox3->setPosition(starX3, starY);
	addChild(_starBox3);
	
	{
		FontDefinition fontDef;
		fontDef._fontName = Utils::getExtraBoldFont();
		fontDef._fontSize = round(12 * G_assetScale) * 4;

		auto label = LabelTTF::createWithFontDefinition("GALLARY " + _selectedGallary->romanNumber, fontDef);
		label->setPosition(visibleSize.width * 0.5f, visibleSize.height - 60 * G_assetScale);
		label->setColor(Color3B::BLACK);
		label->setScale(0.25f);
		addChild(label);
	}
	{
		FontDefinition fontDef;
		fontDef._fontName = Utils::getBoldItalicFont();
		fontDef._fontSize = round(24 * G_assetScale) * 4;
		
		auto label = LabelTTF::createWithFontDefinition(_selectedGallary->name, fontDef);
		label->setPosition(visibleSize.width * 0.5f, visibleSize.height - 79 * G_assetScale);
		label->setColor(Color3B::BLACK);
		label->setScale(0.25f);
		addChild(label);
	}
	{
		FontDefinition fontDef;
		fontDef._fontName = Utils::getBoldItalicFont();
		fontDef._fontSize = round(16 * G_assetScale) * 4;

		_artLabel = LabelTTF::createWithFontDefinition("", fontDef);
		_artLabel->setPosition(visibleSize.width * 0.5f, visibleSize.height - 265 * G_assetScale);
		_artLabel->setColor(Color3B::BLACK);
		_artLabel->setScale(0.25f);
		addChild(_artLabel);
	}
	{
		FontDefinition fontDef;
		fontDef._fontName = Utils::getBoldItalicFont();
		fontDef._fontSize = round(12 * G_assetScale) * 4;
		_artistLabel = LabelTTF::createWithFontDefinition("", fontDef);
		_artistLabel->setPosition(visibleSize.width * 0.5f, visibleSize.height - 285 * G_assetScale);
		_artistLabel->setColor(Color3B::BLACK);
		_artistLabel->setScale(0.25f);
		addChild(_artistLabel);
	}
	
	TableView* tableView = TableView::create(this, Size(Size(visibleSize.width, 60 * G_assetScale)));
	tableView->setDirection(ScrollView::Direction::HORIZONTAL);
	tableView->setPosition(Point(0, 40 * G_assetScale));
	tableView->setDelegate(this);
	this->addChild(tableView);
	tableView->reloadData();

	drawSelected();

    return true;
}
Exemple #11
0
// 初始化
bool RankScene::init()
{
	if (!Layer::init())
	{
		return false;
	}

	selected = 3001;
	opt = "easy";
	scheduleUpdate();

	Size mysize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	//背景图片
	Sprite *pbg = Sprite::create("rank_bg.png");
	pbg->setPosition(Vec2(origin.x + mysize.width / 2, origin.y + mysize.height / 2));
	this->addChild(pbg, -1);

	//返回按钮
	Scale9Sprite *spback = Scale9Sprite::create("close.png");
	ControlButton *pbtbk = ControlButton::create(spback);
	pbtbk->setPosition(Vec2(origin.x + mysize.width - 20, origin.y + mysize.height - 25));
	pbtbk->setPreferredSize(Size(36, 36));
	pbtbk->addTargetWithActionForControlEvents(
		this,
		cccontrol_selector(RankScene::backToMenu),
		Control::EventType::TOUCH_UP_INSIDE);
	this->addChild(pbtbk);

	//rank_easy , tag = 3001
	Scale9Sprite *speasy = Scale9Sprite::create("easy.png");
	ControlButton *rkeasy = ControlButton::create(speasy);
	rkeasy->setPosition(Vec2(origin.x + 40, origin.y + mysize.height / 2 + 50));
	rkeasy->setPreferredSize(Size(75, 50));
	rkeasy->addTargetWithActionForControlEvents(
		this,
		cccontrol_selector(RankScene::showRank),
		Control::EventType::TOUCH_UP_INSIDE);
	this->addChild(rkeasy, 1, 3001);

	//rank_normal , tag = 3002
	Scale9Sprite *spnormal = Scale9Sprite::create("normal.png");
	ControlButton *rknormal = ControlButton::create(spnormal);
	rknormal->setPosition(Vec2(origin.x + 40, origin.y + mysize.height / 2 - 20));
	rknormal->setPreferredSize(Size(75, 50));
	rknormal->addTargetWithActionForControlEvents(
		this,
		cccontrol_selector(RankScene::showRank),
		Control::EventType::TOUCH_UP_INSIDE);
	this->addChild(rknormal, 1, 3002);

	//rank_hard tag = 3003
	Scale9Sprite *sphard = Scale9Sprite::create("hard.png");
	ControlButton *rkhard = ControlButton::create(sphard);
	rkhard->setPosition(Vec2(origin.x + 40, origin.y + mysize.height / 2 - 90));
	rkhard->setPreferredSize(Size(75, 50));
	rkhard->addTargetWithActionForControlEvents(
		this,
		cccontrol_selector(RankScene::showRank),
		Control::EventType::TOUCH_UP_INSIDE);
	this->addChild(rkhard, 1, 3003);

	TableView * tbeasy = TableView::create(this, Size(360, 200));
	tbeasy->setDirection(ScrollView::Direction::VERTICAL);
	tbeasy->setPosition(Vec2(origin.x + 90, origin.y + 15));
	tbeasy->setDelegate(this);
	tbeasy->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
	this->addChild(tbeasy, 1, 3005);

	return true;
}