• CCardSlip


    该类已经把tableview封装好,可以把它当做一个精灵来用,这样做的好处是,当一个界面同时需要多个tableview的时候就可以很好的解决这个问题,而且模块也更清晰。

    //-----------------------------------------------------------------
    //@file        gameui/Card/CardSlip.h
    //@date        2014-01-03
    //@desc        我的卡组滑动界面
    //@action    我的卡组系统 
    //-----------------------------------------------------------------
    
    #ifndef __GAMEUI_CARD_CARDSLIP_H__
    #define __GAMEUI_CARD_CARDSLIP_H__
    
    #include <vector>
    #include "include/ILayer.h"
    #include "kernel/BaseDefine.h"
    #include "cocos-ext.h"
    
    USING_NS_CC_EXT;
    
    class CCardSlip : public CBaseLayer, public CCTableViewDataSource, public CCTableViewDelegate
    {
    private:
        CCTableView* m_pTableView;
        CCTableViewCell* m_pClickCell;
        CCSprite* m_pSelect;
        int m_nSelectIndex;
        CCPoint m_ccSelectPoint;
    
    private:
        bool CreateCell(CCTableViewCell* pCell, UINT unIdx);
        bool ReCreateCell(CCTableViewCell* pCell, UINT unIdx);
        void ClickContent(UINT unIdx);
    
    public:
        virtual bool Create();
        virtual void OnTick() {}
        virtual void onEnter();
        virtual void onEnterTransitionDidFinish();
        virtual void onExit();
    
        virtual void             tableCellTouched(CCTableView* table, CCTableViewCell* cell);
        virtual CCSize             cellSizeForTable(CCTableView *table);
        virtual CCTableViewCell* tableCellAtIndex(CCTableView *table, unsigned int idx);
        virtual unsigned int     numberOfCellsInTableView(CCTableView *table);
    
        virtual void             scrollViewDidScroll(CCScrollView* view);
        virtual void             scrollViewDidZoom(CCScrollView* view);
    
    };
    
    #endif // __GAMEUI_CARD_CARDSLIP_H__
    #include "CardSlip.h"
    
    #include "kernel/Common.h"
    #include "kernel/GlobalMgr.h"
    #include "kernel/CommonData/CommonData.h"
    
    bool CCardSlip::Create()
    {
        if (!CBaseLayer::Create())
            return false;
        setTouchEnabled(true);
    }
    
    void CCardSlip::onEnter()
    {
        CBaseLayer::onEnter();
    }
    
    void CCardSlip::onEnterTransitionDidFinish()
    {
        CBaseLayer::onEnterTransitionDidFinish();
    
        m_pTableView = CCTableView::create(this, CCSizeMake(277, 465));
        CC_ERROR(m_pTableView, "【CCardSlip::onEnterTransitionDidFinish】m_pTableView create failed")
    
        m_pTableView->setAnchorPoint(CCPointZero);
        m_pTableView->setDirection(kCCScrollViewDirectionVertical);
        m_pTableView->setPosition(CCPointZero);
        m_pTableView->setDelegate(this);
        m_pTableView->setVerticalFillOrder(kCCTableViewFillTopDown);
        this->addChild(m_pTableView);
        m_pTableView->reloadData();
    }
    
    void CCardSlip::onExit()
    {
        CBaseLayer::onExit();
    }
    
    bool CCardSlip::CreateCell(CCTableViewCell* pCell, UINT unIdx)
    {
        std::string g_ImgPath(CGlobalMgr::GetInstance()->GetResourcesEx());
        std::string strPath;
    
        strPath = g_ImgPath + "29.png";
        CCSprite* pImgSlot = CCSprite::create(strPath.c_str());
        CC_ERROR_R(pImgSlot, "【CCardSlip::CreateCell】pImgSlot 为空")
        pImgSlot->setPosition(CCPointZero);
        pImgSlot->setAnchorPoint(CCPointZero);
        pCell->addChild(pImgSlot);
        return true;
    }
    
    bool CCardSlip::ReCreateCell(CCTableViewCell* pCell, UINT unIdx)
    {
        std::string g_ImgPath(CGlobalMgr::GetInstance()->GetResourcesEx());
        std::string strPath;
    
        strPath = g_ImgPath + "29.png";
        CCSprite* pImgSlot = CCSprite::create(strPath.c_str());
        CC_ERROR_R(pImgSlot, "【CCardSlip::ReCreateCell】pImgSlot 为空")
        pImgSlot->setPosition(CCPointZero);
        pImgSlot->setAnchorPoint(CCPointZero);
        pCell->addChild(pImgSlot);
        return true;
    }
    
    void CCardSlip::ClickContent(UINT unIdx)
    {
    
    }
    
    void CCardSlip::tableCellTouched(CCTableView* table, CCTableViewCell* cell)
    {
        if(!table || !cell)
            return;
    
        m_pClickCell = cell;
    }
    
    CCSize CCardSlip::cellSizeForTable(CCTableView *table)
    {
        return CCSizeMake(280, 62);
    }
    
    CCTableViewCell* CCardSlip::tableCellAtIndex(CCTableView *table, unsigned int idx)
    {
        CCTableViewCell* pCell = table->dequeueCell();
        if (!pCell)
        {
            pCell = new CCTableViewCell();
            pCell->autorelease();
            this->CreateCell(pCell, idx);
        }
        else
        {
            pCell->removeAllChildren();
            this->ReCreateCell(pCell, idx);
        }
        return pCell;
    }
    
    unsigned int CCardSlip::numberOfCellsInTableView(CCTableView *table)
    {
        return 10;
    }
    
    void CCardSlip::scrollViewDidScroll(CCScrollView* view)
    {
    
    }
    
    void CCardSlip::scrollViewDidZoom(CCScrollView* view)
    {
    
    }
  • 相关阅读:
    Compiling and Installing Yate on Windows
    Windows系统下的TCP参数优化
    TCP参数参数调优
    在浏览器测试JavaScript的方法
    万物智能互联时代
    shopify主题Grid模板修改
    Invalid argument supplied for foreach() in wpinclude/scriptloader.php如何解决
    shopify主题模板startup修改
    shopify主题Pacific模板配置修改
    qperf 简要总结 延迟与带宽信息
  • 原文地址:https://www.cnblogs.com/newlist/p/3504657.html
Copyright © 2020-2023  润新知