2012-09-09 22:34:32 +08:00
|
|
|
#include "TableViewTestScene.h"
|
|
|
|
#include "CustomTableViewCell.h"
|
|
|
|
#include "../ExtensionsTest.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
USING_NS_CC_EXT;
|
|
|
|
|
|
|
|
void runTableViewTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene *pScene = Scene::create();
|
2012-09-09 22:34:32 +08:00
|
|
|
TableViewTestLayer *pLayer = TableViewTestLayer::create();
|
|
|
|
pScene->addChild(pLayer);
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(pScene);
|
2012-09-09 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// on "init" you need to initialize your instance
|
|
|
|
bool TableViewTestLayer::init()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
if ( !Layer::init() )
|
2012-09-09 22:34:32 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2012-09-09 22:34:32 +08:00
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
TableView* tableView = TableView::create(this, Size(250, 60));
|
2013-06-20 14:17:10 +08:00
|
|
|
tableView->setDirection(kScrollViewDirectionHorizontal);
|
2013-07-12 14:11:55 +08:00
|
|
|
tableView->setPosition(Point(20,winSize.height/2-30));
|
2012-09-09 22:34:32 +08:00
|
|
|
tableView->setDelegate(this);
|
|
|
|
this->addChild(tableView);
|
|
|
|
tableView->reloadData();
|
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
tableView = TableView::create(this, Size(60, 250));
|
2013-06-20 14:17:10 +08:00
|
|
|
tableView->setDirection(kScrollViewDirectionVertical);
|
2013-07-12 14:11:55 +08:00
|
|
|
tableView->setPosition(Point(winSize.width-150,winSize.height/2-120));
|
2012-09-09 22:34:32 +08:00
|
|
|
tableView->setDelegate(this);
|
2013-06-20 14:17:10 +08:00
|
|
|
tableView->setVerticalFillOrder(kTableViewFillTopDown);
|
2012-09-09 22:34:32 +08:00
|
|
|
this->addChild(tableView);
|
|
|
|
tableView->reloadData();
|
|
|
|
|
|
|
|
// Back Menu
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(TableViewTestLayer::toExtensionsMainLayer, this));
|
2013-07-12 14:11:55 +08:00
|
|
|
itemBack->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menuBack = Menu::create(itemBack, NULL);
|
2013-07-12 14:47:36 +08:00
|
|
|
menuBack->setPosition(Point::ZERO);
|
2012-09-09 22:34:32 +08:00
|
|
|
addChild(menuBack);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TableViewTestLayer::toExtensionsMainLayer(cocos2d::Object *sender)
|
2012-09-09 22:34:32 +08:00
|
|
|
{
|
|
|
|
ExtensionsTestScene *pScene = new ExtensionsTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TableViewTestLayer::tableCellTouched(TableView* table, TableViewCell* cell)
|
2012-09-09 22:34:32 +08:00
|
|
|
{
|
|
|
|
CCLOG("cell touched at index: %i", cell->getIdx());
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size TableViewTestLayer::tableCellSizeForIndex(TableView *table, unsigned int idx)
|
2012-09-09 22:34:32 +08:00
|
|
|
{
|
2013-04-10 16:38:00 +08:00
|
|
|
if (idx == 2) {
|
2013-07-12 14:30:26 +08:00
|
|
|
return Size(100, 100);
|
2013-04-10 16:38:00 +08:00
|
|
|
}
|
2013-07-12 14:30:26 +08:00
|
|
|
return Size(60, 60);
|
2012-09-09 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
TableViewCell* TableViewTestLayer::tableCellAtIndex(TableView *table, unsigned int idx)
|
2012-09-09 22:34:32 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
String *string = String::createWithFormat("%d", idx);
|
|
|
|
TableViewCell *cell = table->dequeueCell();
|
2012-09-09 22:34:32 +08:00
|
|
|
if (!cell) {
|
|
|
|
cell = new CustomTableViewCell();
|
|
|
|
cell->autorelease();
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sprite = Sprite::create("Images/Icon.png");
|
2013-07-12 14:47:36 +08:00
|
|
|
sprite->setAnchorPoint(Point::ZERO);
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition(Point(0, 0));
|
2012-09-09 22:34:32 +08:00
|
|
|
cell->addChild(sprite);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *label = LabelTTF::create(string->getCString(), "Helvetica", 20.0);
|
2013-07-12 14:47:36 +08:00
|
|
|
label->setPosition(Point::ZERO);
|
|
|
|
label->setAnchorPoint(Point::ZERO);
|
2012-09-09 22:34:32 +08:00
|
|
|
label->setTag(123);
|
|
|
|
cell->addChild(label);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *label = (LabelTTF*)cell->getChildByTag(123);
|
2012-09-09 22:34:32 +08:00
|
|
|
label->setString(string->getCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
unsigned int TableViewTestLayer::numberOfCellsInTableView(TableView *table)
|
2012-09-09 22:34:32 +08:00
|
|
|
{
|
|
|
|
return 20;
|
|
|
|
}
|