• <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)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            本文地址:http://www.shnenglu.com/zdhsoft/archive/2014/07/23/207760.html
            使用cocostudio可以裝載編輯好的UI,但是過于復(fù)雜。特別是在加截UI后,發(fā)現(xiàn)觸屏事件有些問題。如果直接使用程序?qū)懰兰虞dUI又過于麻煩?;c時間,增加了一個基于ini的UI配置類,目前只實現(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    ·#冒號開頭表示從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) 評論(0)  編輯 收藏 引用 所屬分類: 原創(chuàng) 、cocos2dx
            久久婷婷成人综合色综合| 久久精品午夜一区二区福利| 麻豆一区二区99久久久久| 无码日韩人妻精品久久蜜桃| 97精品久久天干天天天按摩| 狠狠色综合久久久久尤物| 久久久久女教师免费一区| 亚洲色欲久久久综合网东京热 | 午夜精品久久久久久久久| 新狼窝色AV性久久久久久| 免费观看久久精彩视频| 久久毛片一区二区| 久久91亚洲人成电影网站| 丁香色欲久久久久久综合网| 久久99国产精品久久99| 久久婷婷色综合一区二区| 久久精品女人天堂AV麻| 伊人久久无码中文字幕| 精品久久久久一区二区三区| 国产精品美女久久福利网站| 久久99精品免费一区二区| 中文字幕久久精品无码| 精品久久久久久久久久久久久久久| 97精品国产97久久久久久免费| 美女写真久久影院| 无码人妻久久一区二区三区| 久久人人爽人人爽人人片AV麻豆 | 99久久精品免费看国产一区二区三区| 7国产欧美日韩综合天堂中文久久久久 | 7国产欧美日韩综合天堂中文久久久久| 人人狠狠综合88综合久久| 久久国产香蕉一区精品| 精品综合久久久久久97超人| 无码久久精品国产亚洲Av影片 | 久久精品中文闷骚内射| 久久天天躁夜夜躁狠狠| 久久受www免费人成_看片中文| 久久久久久无码国产精品中文字幕 | 亚洲国产精品久久久天堂| 国产精品99久久久精品无码 | 久久97久久97精品免视看|