• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            專職C++

            不能停止的腳步

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(28)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            本文地址:http://www.shnenglu.com/zdhsoft/archive/2014/07/23/207760.html
            使用cocostudio可以裝載編輯好的UI,但是過于復(fù)雜。特別是在加截UI后,發(fā)現(xiàn)觸屏事件有些問題。如果直接使用程序?qū)懰兰虞dUI又過于麻煩。花點(diǎn)時(shí)間,增加了一個(gè)基于ini的UI配置類,目前只實(shí)現(xiàn)了CCSprite和plist的加載。其它的可以后面慢慢加
            頭文件
            #ifndef _X_UI_H_
            #define _X_UI_H_
            #include <cocos2d.h>
            namespace zdh
            {
                USING_NS_CC;
                void CreateByXUI(CCNode * paramParent, const char * paramFileName);
            }
            #endif
            源文件
            #include "xui.h"
            #include "xini.h"
            #include "xlog.h"

            namespace zdh
            {
                namespace xui
                {
                    //--------------------------------------------------------------------------------------
                    int GetIntValue(XIniText::TSection * paramSection, const char * paramKeyName)
                    {
                        auto pV = paramSection->getEntry(paramKeyName);
                        if (isNULL(pV)) return 0;
                        else return pV->getValue().getField().ToIntDef(0);
                    }
                    //--------------------------------------------------------------------------------------
                    int GetDoubleValue(XIniText::TSection * paramSection, const char * paramKeyName)
                    {
                        auto pV = paramSection->getEntry(paramKeyName);
                        if (isNULL(pV)) return 0;
                        else return pV->getValue().getField().ToIntDef(0);
                    }
                    //--------------------------------------------------------------------------------------
                    const XAnsiString & GetStringValue(XIniText::TSection * paramSection, const char * paramKeyName)
                    {
                        static const XAnsiString strEmpty;
                        auto pV = paramSection->getEntry(paramKeyName);
                        if (isNULL(pV)) return strEmpty;
                        else return pV->getValue().getField();
                    }
                };

                //--------------------------------------------------------------------------------------
                void CreateSpriteByXUI(CCNode * paramParent, XIniText::TSection * paramSpriteSection)
                {
                    XInt ix = xui::GetIntValue(paramSpriteSection, "x");
                    XInt iy = xui::GetIntValue(paramSpriteSection, "y");
                    XInt izOrder = xui::GetIntValue(paramSpriteSection, "zOrder");
                    const XAnsiString & pImageName = xui::GetStringValue(paramSpriteSection, "image");
                    XInt iTag = xui::GetIntValue(paramSpriteSection, "tag");
                    CCSprite * pSprite = NULL;
                    if (pImageName[0] == ':') //如果是從Cache中讀取
                    {
                        pSprite = CCSprite::createWithSpriteFrameName(pImageName.c_str()+1);
                    }
                    else
                    {
                        pSprite = CCSprite::create(pImageName.c_str());
                    }
                    pSprite->setPosition(ix, iy);
                    pSprite->setAnchorPoint(0, 0);
                    pSprite->setTag(iTag);
                    pSprite->setZOrder(izOrder);
                    paramParent->addChild(pSprite, izOrder);
                }
                
                void LoadSpriteFrameByPList(CCNode * /*paramParent*/, XIniText::TSection * paramSection)
                {
                    const XAnsiString & pPListName = xui::GetStringValue(paramSection, "filename");
                    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(pPListName.c_str());
                }

                //--------------------------------------------------------------------------------------
                void CreateByXUI(CCNode * paramParent, const char * paramFileName)
                {
                    std::string strFullFileName = CCFileUtils::sharedFileUtils()->fullPathForFilename(paramFileName);
                    unsigned long dwGetSize = 0;
                    const unsigned char * pData = CCFileUtils::sharedFileUtils()->getFileData(strFullFileName.c_str(), "rb", &dwGetSize);
                    ZDH_INFO("Load XUI:%s size=%u", paramFileName, dwGetSize);
                    if (dwGetSize == 0)
                    {
                        if (isNotNULL(pData)) delete[] pData;
                        return;
                    }

                    std::string strData((const char *)pData, dwGetSize);
                    std::stringstream ss(strData);
                    XIniText stIni;
                    if (!stIni.Load(ss))
                    {
                        ZDH_INFO("Load XUI Fail, %s", paramFileName);
                        return;
                    }
                    for (int s = 0; s < stIni.getSectionCount(); s++)
                    {
                        auto pSection = stIni.getSection(s);
                        auto pType = pSection->getEntry("type");
                        if (isNULL(pType))
                        {
                            ZDH_INFO("Section=[%s] not exist key:\"type\"", pSection->getSectionName().c_str());
                            continue;
                        }
                        const XAnsiString & paramTypeValue = pType->getValue().getField();
                        if (paramTypeValue == "CCSprite")
                        {
                            CreateSpriteByXUI(paramParent, pSection);
                        }
                        else if (paramTypeValue == "plist")
                        {
                            LoadSpriteFrameByPList(paramParent, pSection);
                        }
                    }
                }
            }
            配置文件
            #支持UTF-8格式
            [gk_label.png]
            type = CCSprite
            image = gk_label.png
            tag = 1
            x = 18
            y = 914
            zOrder = 1

            [mb_label.png]
            type = CCSprite
            image = :mb_label.png    ·#冒號(hào)開頭表示從CCSpriteFrameCache加載圖片
            tag = 1
            x = 348
            y = 916
            zOrder = 1

            [score_label.png]
            type = CCSprite
            image = score_label.png
            tag = 1
            x = 258
            y = 855
            zOrder = 1

            [game_star.plist]
            #批量裝載
            type = plist
            filename = game_star.plist
            相關(guān)用到的TTextIni和XAnsiString,參考我的開源代碼
            posted on 2014-07-23 20:04 冬瓜 閱讀(2107) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 原創(chuàng)cocos2dx
            精品久久久久久中文字幕| 亚洲综合熟女久久久30p| 91精品国产乱码久久久久久| 久久永久免费人妻精品下载| 91视频国产91久久久| 久久中文字幕无码专区| 影音先锋女人AV鲁色资源网久久| 日韩精品久久无码中文字幕| 国产精品久久久久久久午夜片 | 久久九九兔免费精品6| 久久亚洲AV成人出白浆无码国产 | 人妻久久久一区二区三区| 久久精品国产免费一区| 精品多毛少妇人妻AV免费久久| 国产一久久香蕉国产线看观看| 久久久久亚洲精品日久生情| 伊人久久大香线蕉精品| 久久久女人与动物群交毛片| 久久综合精品国产一区二区三区| 国内精品久久国产大陆| 午夜精品久久久久久中宇| 久久久久亚洲精品男人的天堂| 九九久久99综合一区二区| 伊人久久综合无码成人网| 亚洲国产香蕉人人爽成AV片久久| 99久久国产综合精品成人影院| 久久亚洲日韩精品一区二区三区| 漂亮人妻被中出中文字幕久久| 久久精品国产一区二区| 国产精品gz久久久| 99精品伊人久久久大香线蕉| 国产亚洲美女精品久久久久狼| 国产午夜免费高清久久影院 | 亚洲成人精品久久| 99久久免费国产特黄| 国产精品禁18久久久夂久| 无码人妻久久一区二区三区| 色狠狠久久AV五月综合| 久久久久久亚洲AV无码专区| 日韩精品久久无码中文字幕| 久久精品国产亚洲av水果派|