Cocos2d-x 3.3Bate0 ExpandedListView
之前写的ExpandedListView版本号因为版本号升级这里提供Cocos2d-x 3.3Bate0 版本号
代码下载:http://download.csdn.net/detail/qqmcy/8033343
以下介绍下怎样使用。
先介绍下
DJDataObject存放数据模型的类
DayReportListAdapter 自己定义的adapter或是iOS中的cell
ListViewTest 演示样例类。
以下上代码啦
DJDataObject.h
//
// DJDataObject.h
// testthirdone
//
// Created by 杜甲 on 14-6-7.
//
// #ifndef __testthirdone__DJDataObject__
#define __testthirdone__DJDataObject__ #include "cocos2d.h" USING_NS_CC; class DJDataObject :public Ref
{ public: CREATE_FUNC(DJDataObject);
virtual bool init();
std::string name;
std::vector<DJDataObject*> children; void initWithNameAndChildren(std::string name,std::vector<DJDataObject*> data_vec); }; #endif /* defined(__testthirdone__DJDataObject__) */
DJDataObject.cpp
//
// DJDataObject.cpp
// testthirdone
//
// Created by 杜甲 on 14-6-7.
//
// #include "DJDataObject.h" bool DJDataObject::init()
{
bool bRet = false;
do { bRet = true;
} while (0); return bRet;
} void DJDataObject::initWithNameAndChildren(std::string name,std::vector<DJDataObject*> data_vec)
{
this->name = name;
this->children = data_vec; }
DayReportListAdapter.h
//
// DayReportListAdapter.h
//
//
// Created by 杜甲 on 14-6-4.
//
// #ifndef __ht_mobile_cpp__DayReportListAdapter__
#define __ht_mobile_cpp__DayReportListAdapter__ #include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "DJTreeNodeInfo.h" USING_NS_CC; class DayReportListAdapter :public ui::Layout
{ public:
CREATE_FUNC(DayReportListAdapter);
virtual bool init();
ui::Text* organName; ui::Text* prem_day; ui::Text* prem_month; ui::ImageView* in_Image; void setBackGround(int treeDepthLevel);
Vec2 preVec2;
float preOffsetX; typedef std::function<void(Ref*, Vec2 offset_vec2)> ccAdapterCallback;
void addEventListener(const ccAdapterCallback& callback);
ccAdapterCallback _eventCallback; bool isMoving_HORIZONTAL;
Size winSize; }; #endif /* defined(__ht_mobile_cpp__DayReportListAdapter__) */
DayReportListAdapter.cpp
//
// DayReportListAdapter.cpp
//
//
// Created by 杜甲 on 14-6-4.
//
// #include "DayReportListAdapter.h" #include "VisibleRect.h" bool DayReportListAdapter::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!ui::Layout::init());
setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);
setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
winSize = Director::getInstance()->getWinSize(); setTouchEnabled(true);
float topLength = 30; in_Image = ui::ImageView::create("CloseNormal.png");
in_Image->setScale(VisibleRect::getImageScale());
in_Image->setTouchEnabled(true);
addChild(in_Image); auto rp_image = ui::RelativeLayoutParameter::create();
rp_image->setRelativeName("rp_image"); float offset = -in_Image->getContentSize().width * 2/3 *(1- VisibleRect::getImageScale()); rp_image->setMargin(ui::Margin(-in_Image->getContentSize().width * 2/3 *(1- VisibleRect::getImageScale()),0,0,0));
rp_image->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL);
in_Image->setLayoutParameter(rp_image); organName = ui::Text::create();
organName->setFontSize(38 * VisibleRect::getImageScale());
organName->setColor(Color3B::BLACK);
addChild(organName); auto rp_organName = ui::RelativeLayoutParameter::create();
rp_organName->setRelativeName("rp_organName");
rp_organName->setRelativeToWidgetName("rp_image");
rp_organName->setMargin(ui::Margin(1 * VisibleRect::getImageScale() + offset,topLength,0,0));
rp_organName->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER);
organName->setLayoutParameter(rp_organName); prem_month = ui::Text::create();
prem_month->setFontSize(38 * VisibleRect::getImageScale());
prem_month->setTextHorizontalAlignment(cocos2d::TextHAlignment::LEFT);
prem_month->setColor(Color3B::BLACK);
addChild(prem_month); auto rp_prem_month = ui::RelativeLayoutParameter::create();
rp_prem_month->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT);
rp_prem_month->setRelativeName("rp_prem_month");
rp_prem_month->setMargin(ui::Margin(0,topLength,50*VisibleRect::getImageScale(),0)); prem_month->setLayoutParameter(rp_prem_month); auto center = ui::Layout::create();
center->setSize(Size(1, 1));
addChild(center); auto rp_center = ui::RelativeLayoutParameter::create();
rp_center->setRelativeName("rp_center");
rp_center->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);
center->setLayoutParameter(rp_center); prem_day = ui::Text::create();
prem_day->setTextHorizontalAlignment(cocos2d::TextHAlignment::LEFT); prem_day->setFontSize(38 * VisibleRect::getImageScale());
prem_day->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
prem_day->setSize(Size(100, 50));
prem_day->setColor(Color3B::BLACK);
addChild(prem_day); auto rp_prem_day = ui::RelativeLayoutParameter::create();
rp_prem_day->setRelativeToWidgetName("rp_center");
rp_prem_day->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL); // rp_prem_day->setRelativeToWidgetName("rp_prem_month");
rp_prem_day->setMargin(ui::Margin(30,topLength,0,0));
prem_day->setLayoutParameter(rp_prem_day); auto bottom_color = ui::Layout::create();
bottom_color->setSize(Size(winSize.width, 1));
bottom_color->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
bottom_color->setBackGroundColor(Color3B::BLACK);
addChild(bottom_color); auto rp_bottom_color = ui::RelativeLayoutParameter::create();
rp_bottom_color->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL);
rp_bottom_color->setMargin(ui::Margin(0,0,0,1));
bottom_color->setLayoutParameter(rp_bottom_color); bRet = true;
} while (0);
return bRet; } void DayReportListAdapter::setBackGround(int treeDepthLevel)
{
log("treeDepthLevel = %d",treeDepthLevel);
switch (treeDepthLevel) {
case 0: setBackGroundColor(Color3B(209, 238, 252)); break;
case 1:
setBackGroundColor(Color3B(224, 248, 216)); break;
case 2:
break; default:
break;
}
} void DayReportListAdapter::addEventListener(const ccAdapterCallback &callback)
{
_eventCallback = callback; }
ListViewTest.h
//
// ListViewTest.h
// testthirdone
//
// Created by 杜甲 on 14-6-9.
//
// /*
* 演示样例Demo
*/ #ifndef __testthirdone__ListViewTest__
#define __testthirdone__ListViewTest__ #include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "DJDataObject.h"
#include "DJListView.h" USING_NS_CC;
using namespace ui; class ListViewTest : public ui::Layout , public DJListViewDataSource , public DJListViewDelegate
{
public: CREATE_FUNC(ListViewTest);
virtual bool init(); private:
std::vector<DJDataObject*> data_vec; virtual ssize_t treeViewNumberOfChildrenOfItem(DJListView *treeView , void *item) ;
virtual ui::Layout *treeViewAndCellForItemAndTreeNodeInfo(DJListView *treeView , void *item , DJTreeNodeInfo *treeNodeInfo);
virtual void* treeViewAndChildOfItem(DJListView *treeView , int index , void *item); Size winSize;
virtual void treeViewWillDisplayCellForItemTreeNodeInfo(DJListView *treeView , ui::Layout *adapter , void *item , DJTreeNodeInfo *treeNodeInfo) ; }; #endif /* defined(__testthirdone__ListViewTest__) */
ListViewTest.cpp
//
// ListViewTest.cpp
// testthirdone
//
// Created by 杜甲 on 14-6-9.
//
// #include "ListViewTest.h"
#include "DJTreeNode.h"
#include "DJTreeNodeInfo.h"
#include "DayReportListAdapter.h" bool ListViewTest::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!ui::Layout::init());
winSize = Director::getInstance()->getWinSize(); setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
setBackGroundColor(Color3B(18, 23, 222)); std::vector<DJDataObject*>temp1;
std::vector<DJDataObject*>temp2;
std::vector<DJDataObject*>temp3;
std::vector<DJDataObject*>temp4; DJDataObject* data7 = DJDataObject::create();
data7->retain();
//initWithNameAndChildren 參数1:当前数据内容, 參数2 :子集
data7->initWithNameAndChildren("数据1-1-1", temp4);
temp1.push_back(data7); DJDataObject* data3 = DJDataObject::create();
data3->retain();
data3->initWithNameAndChildren("数据1-1", temp1); DJDataObject* data4 = DJDataObject::create();
data4->retain();
data4->initWithNameAndChildren("数据1-2", temp4); for (int i = 0; i < 7; i++)
{
DJDataObject* data6 = DJDataObject::create();
data6->retain();
data6->initWithNameAndChildren("数据h", temp3);
temp2.push_back(data6);
} DJDataObject* data1 = DJDataObject::create();
data1->retain();
data1->initWithNameAndChildren("数据r", temp2); DJDataObject* data = DJDataObject::create();
data->retain();
std::vector<DJDataObject*>temp;
temp.push_back(data3);
temp.push_back(data4); data->initWithNameAndChildren("数据12", temp); data_vec.push_back(data);
data_vec.push_back(data1); auto winSize = Director::getInstance()->getWinSize(); auto listView1 = DJListView::create();
listView1->setDJListViewDataSource(this);
listView1->setDJListViewDelegate(this);
listView1->setSize(winSize);
listView1->addExpandedListView(data_vec);
addChild(listView1); bRet = true;
} while (0); return bRet;
} void ListViewTest::treeViewWillDisplayCellForItemTreeNodeInfo(DJListView *treeView, ui::Layout *adapter, void *item, DJTreeNodeInfo *treeNodeInfo)
{
if (treeNodeInfo->treeDepthLevel == 0) {
adapter->setBackGroundColor(Color3B(150, 100, 200));
}else if (treeNodeInfo->treeDepthLevel == 1)
{
adapter->setBackGroundColor(Color3B(100, 100, 100));
}else if (treeNodeInfo->treeDepthLevel == 2)
{
adapter->setBackGroundColor(Color3B(100, 150, 150));
} } ssize_t ListViewTest::treeViewNumberOfChildrenOfItem(DJListView *treeView , void *item)
{
if (item == nullptr) { return data_vec.size();
} DJDataObject* data = static_cast<DJDataObject*>(item);
return data->children.size();
} ui::Layout* ListViewTest::treeViewAndCellForItemAndTreeNodeInfo(DJListView *treeView , void *item , DJTreeNodeInfo *treeNodeInfo)
{
DJDataObject* dobject = static_cast<DJDataObject*>(item) ; auto tableLayout1 = DayReportListAdapter::create();
tableLayout1->setSize(Size(winSize.width, 100));
tableLayout1->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
// tableLayout1->setBackGround(treeNodeInfo->treeDepthLevel);
// tableLayout1->setBackGroundColor(Color3B(189, 203, 222));
// listView->pushBackCustomItem(tableLayout1);
tableLayout1->organName->setString(dobject->name);
tableLayout1->prem_day->setString(StringUtils::format("%d",333));
tableLayout1->prem_month->setString("fffff"); return tableLayout1;
}
void* ListViewTest::treeViewAndChildOfItem(DJListView *treeView , int index , void *item)
{
DJDataObject* data = static_cast<DJDataObject*>(item);
if (item == nullptr) {
return data_vec.at( index );
}
return data->children.at( index );
}
效果:
Cocos2d-x 3.3Bate0 ExpandedListView的更多相关文章
- 小尝试一下 cocos2d
好奇 cocos2d 到底是怎样一个框架,正好有个项目需要一个游戏框架,所以稍微了解了一下.小结一下了解到的情况. 基本概念 首先呢,因为 cocos2d 是基于 pyglet 做的,你完全可以直接用 ...
- 采用cocos2d-x lua 制作数字滚动效果样例
require "Cocos2d"require "Cocos2dConstants"local testscene = class("testsce ...
- Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板
很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...
- iPhone开发与cocos2d 经验谈
转CSDN jilongliang : 首先,对于一个完全没有mac开发经验,甚至从没摸过苹果系统的开发人员来说,首先就是要熟悉apple的那一套开发框架(含开发环境IDE.开发框架uikit,还有开 ...
- cocos2d学习记录
视频 - http://www.manew.com/forum-105-3.html一个论坛帖 - http://www.zhihu.com/question/21114802官网 - http:// ...
- Android下Cocos2d创建HelloWorld工程
最近在搭建Cocos2d的环境,结果各种问题,两人弄了一天才能搞好一个环境-! -_-!! 避免大家也可能会遇到我这种情况,所以写一个随笔,让大家也了解下如何搭建吧- 1.环境安装准备 下载 tadp ...
- 学生信息管理系统(cocos2d引擎)——数据结构课程设计
老师手把手教了两天半,看了一下模式,加了几个功能就大功告成了!!! 给我的感想就是全都是指针! 添加图片精灵: CCSprite* spBG = CCSprite::create("&qu ...
- cocos2d触碰例子代码
// // TestLayer.h // MiniTD // // Created by OnePiece on 12-7-30. // Copyright 2012年 __MyCompanyName ...
- 如何优化cocos2d程序的内存使用和程序大小
在我完成第一个游戏项目的时候,我深切地意识到"使用cocos2d来制作游戏的开发者们,他们大多会被cocos2d的内存问题所困扰".而我刚开始接触cocos2d的时候,社区里面的人 ...
随机推荐
- 【Linux】替换文本中的字符
替换单个文本中的字符,有两种方法,如下详解 VIM替换 打开文件 vim test.txt 替换 :%s/原字符串/替换字符串/gg 直接替换 sed -i 's/原字符串/替换字符串/g' `ls ...
- MySQL数据库的查询缓冲机制
MySQL数据库的查询缓冲机制 2011-08-10 11:07 佚名 火魔网 字号:T | T 使用查询缓冲机制,可以极大地提高MySQL数据库查询的效率,节省查询所用的时间.那么查询缓冲机制是怎样 ...
- Bootstrap-学习系列
前言 首先在此多谢博友们在前几篇博文当中给与的支持和鼓励,以及在回复中提出的问题.意见和看法. 在此先声明一下,之前在下小菜所有的随笔文章中,只有前两篇关于Bootstrap的文章发表在了博客园的首页 ...
- 深入理解linux系统的目录结构
对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要,下面 ...
- Linux-Vim常用操作
vim wangyunpeng.txt 创建一个wangyunpeng.txt文件 输入"i"进入插入模式 显示行号,需要在命令模式下输入":se nu" cp ...
- angularJS 状态样式绑定
angularJS提供输入框不同状态下的样式绑定 输入框有4种状态 ng-model 指令可以为应用数据提供状态值(invalid, dirty, touched, error): <!DOCT ...
- iperf使用
1. sourceforge搜索iperf下载 2. ./configure make make install 3. server:iperf -s -p 12345 -i 1 -M: client ...
- wx小程序的学习
传送门: # 微信小程序案例大全 https://www.cnblogs.com/icyhoo/p/6282574.html # 微信小程序开发工具 https://mp.weixin.qq.com/ ...
- 分布式协调服务ZooKeeper工作原理
分布式协调服务ZooKeeper工作原理 原创 2016-02-19 杜亦舒 性能与架构 性能与架构 性能与架构 微信号 yogoup 功能介绍 网站性能提升与架构设计 大数据处理框架Hadoop.R ...
- Atitit.执行cmd 命令行 php
Atitit.执行cmd 命令行 php 1. 执行cmd 命令行,调用系统命令的基础 1 1.1. 实际执行模式 1 1.2. 空格的问题 1 1.3. 中文路径的问题,程序文件读取编码设置 1 1 ...