mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
138 lines
4.2 KiB
JavaScript
138 lines
4.2 KiB
JavaScript
/****************************************************************************
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
Copyright (c) 2011-2012 cocos2d-x.org
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
****************************************************************************/
|
|
|
|
var CustomTableViewCell = cc.TableViewCell.extend({
|
|
draw:function (ctx) {
|
|
this._super(ctx);
|
|
}
|
|
});
|
|
|
|
var TableViewTestLayer = cc.Layer.extend({
|
|
|
|
ctor:function () {
|
|
this._super();
|
|
this.init();
|
|
},
|
|
|
|
init:function () {
|
|
var winSize = cc.director.getWinSize();
|
|
|
|
var tableView = new cc.TableView(this, cc.size(600, 60));
|
|
tableView.setDirection(cc.SCROLLVIEW_DIRECTION_HORIZONTAL);
|
|
tableView.x = 20;
|
|
tableView.y = winSize.height / 2 - 150;
|
|
tableView.setDelegate(this);
|
|
this.addChild(tableView);
|
|
tableView.reloadData();
|
|
|
|
tableView = new cc.TableView(this, cc.size(60, 350));
|
|
tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
|
|
tableView.x = winSize.width - 150;
|
|
tableView.y = winSize.height / 2 - 150;
|
|
tableView.setDelegate(this);
|
|
tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
|
|
this.addChild(tableView);
|
|
tableView.reloadData();
|
|
|
|
// Back Menu
|
|
var itemBack = new cc.MenuItemFont("Back", this.toExtensionsMainLayer, this);
|
|
itemBack.x = winSize.width - 50;
|
|
itemBack.y = 25;
|
|
var menuBack = new cc.Menu(itemBack);
|
|
menuBack.x = 0;
|
|
menuBack.y = 0;
|
|
this.addChild(menuBack);
|
|
|
|
return true;
|
|
},
|
|
|
|
toExtensionsMainLayer:function (sender) {
|
|
var scene = new ExtensionsTestScene();
|
|
scene.runThisTest();
|
|
},
|
|
|
|
scrollViewDidScroll:function (view) {
|
|
},
|
|
scrollViewDidZoom:function (view) {
|
|
},
|
|
|
|
tableCellTouched:function (table, cell) {
|
|
cc.log("cell touched at index: " + cell.getIdx());
|
|
},
|
|
tableCellTouched2:function () {
|
|
cc.log("cell touched at index: ");
|
|
},
|
|
|
|
tableCellSizeForIndex:function (table, idx) {
|
|
if (idx == 2) {
|
|
return cc.size(100, 100);
|
|
}
|
|
return cc.size(60, 60);
|
|
},
|
|
|
|
tableCellAtIndex:function (table, idx) {
|
|
var strValue = idx.toFixed(0);
|
|
var cell = table.dequeueCell();
|
|
var label;
|
|
if (!cell) {
|
|
cell = new CustomTableViewCell();
|
|
|
|
|
|
|
|
var sprite = new _ccsg.Sprite(s_image_icon);
|
|
sprite.anchorX = 0;
|
|
sprite.anchorY = 0;
|
|
sprite.x = 0;
|
|
sprite.y = 0;
|
|
cell.addChild(sprite);
|
|
|
|
label = new cc.LabelTTF(strValue, "Helvetica", 20.0);
|
|
label.x = 0;
|
|
label.y = 0;
|
|
label.anchorX = 0;
|
|
label.anchorY = 0;
|
|
label.tag = 123;
|
|
cell.addChild(label);
|
|
} else {
|
|
label = cell.getChildByTag(123);
|
|
label.setString(strValue);
|
|
}
|
|
|
|
return cell;
|
|
},
|
|
|
|
numberOfCellsInTableView:function (table) {
|
|
return 25;
|
|
}
|
|
});
|
|
|
|
var runTableViewTest = function () {
|
|
var pScene = new _ccsg.Scene();
|
|
var pLayer = new TableViewTestLayer();
|
|
pScene.addChild(pLayer);
|
|
cc.director.runScene(pScene);
|
|
};
|