// // CCTableViewLoader.cpp // redream_runtime_mac // // Created by zhuge on 2023/3/15. // #include "CCTableViewLoader.h" #define PROPERTY_CONTAINER "container" #define PROPERTY_VORDERING "vordering" #define PROPERTY_TABLEVIEW_REDFILE "tableviewRedFile" namespace redream { cocos2d::Size TableViewLoader::TableViewDataSource::tableCellSizeForIndex(cocos2d::extension::TableView *table, ssize_t idx) { auto cellSize = cellSizeForTable(table); return cellSize; } cocos2d::extension::TableViewCell* TableViewLoader::TableViewDataSource::TableViewDataSource::tableCellAtIndex(cocos2d::extension::TableView* table, ssize_t idx) { cocos2d::extension::TableViewCell* cell = table->dequeueCell(); if (nullptr == cell) { cell = new (std::nothrow) cocos2d::extension::TableViewCell(); cell->setIdx(idx); cell->autorelease(); if (idx < _subRedNodes.size()) { auto node = _subRedNodes.at(idx); cell->addChild(node); } } else { if (idx < _subRedNodes.size()) { auto node = _subRedNodes.at(idx); node->removeFromParentAndCleanup(false); cell->addChild(node); } } return cell; } cocos2d::Size TableViewLoader::TableViewDataSource::cellSizeForTable(cocos2d::extension::TableView* table) { return cocos2d::Size(50, 50); } ssize_t TableViewLoader::TableViewDataSource::numberOfCellsInTableView(cocos2d::extension::TableView* table) { return 3; } cocos2d::extension::TableView* TableViewLoader::createNode(cocos2d::Node * pParent, redream::REDReader * ccbReader) { auto dataSource = new TableViewDataSource(); auto tv = cocos2d::extension::TableView::create(dataSource, Size(200, 200)); tv->setDataSource(dataSource); return tv; } #pragma mark - table view loader void TableViewLoader::onHandlePropTypeREDFile(Node * pNode, Node * pParent, const char * pPropertyName, Node * pREDFileNode, REDReader * ccbReader) { if(strcmp(pPropertyName, PROPERTY_CONTAINER) == 0) { // do nothing, 添加节点交到TableViewRedFile属性 } else { NodeLoader::onHandlePropTypeREDFile(pNode, pParent, pPropertyName, pREDFileNode, ccbReader); } } void TableViewLoader::onHandlePropTypeTableviewRedFile(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, std::vector pREDFileNodes, REDReader * ccbReader) { if (strcmp(pPropertyName, PROPERTY_TABLEVIEW_REDFILE) == 0) { auto tableView = (cocos2d::extension::TableView*)pNode; auto dataSource = dynamic_cast(tableView->getDataSource()); if (dataSource != nullptr) { for (auto node: pREDFileNodes) { dataSource->addSubRedNode(node); } tableView->reloadData(); } } else { NodeLoader::onHandlePropTypeTableviewRedFile(pNode, pParent, pPropertyName, pREDFileNodes, ccbReader); } } void TableViewLoader::onHandlePropTypeIntegerLabeled(Node * pNode, Node * pParent, const char * pPropertyName, int pIntegerLabeled, REDReader * ccbReader) { if(strcmp(pPropertyName, PROPERTY_VORDERING) == 0) { ((cocos2d::extension::TableView *)pNode)->setVerticalFillOrder(cocos2d::extension::TableView::VerticalFillOrder(pIntegerLabeled)); } else { ScrollViewLoader::onHandlePropTypeIntegerLabeled(pNode, pParent, pPropertyName, pIntegerLabeled, ccbReader); } } } // namespace