├── .gitignore ├── LICENSE ├── README.md ├── lib ├── cocos │ ├── cocos2d │ │ ├── Cocos2d.lua │ │ ├── Cocos2dConstants.lua │ │ ├── DeprecatedCocos2dClass.lua │ │ ├── DeprecatedCocos2dEnum.lua │ │ ├── DeprecatedCocos2dFunc.lua │ │ ├── DeprecatedOpenglEnum.lua │ │ ├── DrawPrimitives.lua │ │ ├── Opengl.lua │ │ ├── OpenglConstants.lua │ │ ├── bitExtend.lua │ │ ├── deprecated.lua │ │ ├── functions.lua │ │ ├── json.lua │ │ ├── luaj.lua │ │ └── luaoc.lua │ ├── cocosbuilder │ │ ├── CCBReaderLoad.lua │ │ └── DeprecatedCocosBuilderClass.lua │ ├── cocosdenshion │ │ ├── AudioEngine.lua │ │ ├── DeprecatedCocosDenshionClass.lua │ │ └── DeprecatedCocosDenshionFunc.lua │ ├── cocostudio │ │ ├── CocoStudio.lua │ │ ├── DeprecatedCocoStudioClass.lua │ │ ├── DeprecatedCocoStudioFunc.lua │ │ └── StudioConstants.lua │ ├── controller │ │ └── ControllerConstants.lua │ ├── extension │ │ ├── DeprecatedExtensionClass.lua │ │ ├── DeprecatedExtensionEnum.lua │ │ ├── DeprecatedExtensionFunc.lua │ │ └── ExtensionConstants.lua │ ├── framework │ │ ├── audio.lua │ │ ├── components │ │ │ └── event.lua │ │ ├── device.lua │ │ ├── display.lua │ │ ├── extends │ │ │ ├── LayerEx.lua │ │ │ ├── MenuEx.lua │ │ │ ├── NodeEx.lua │ │ │ ├── SpriteEx.lua │ │ │ ├── UICheckBox.lua │ │ │ ├── UIEditBox.lua │ │ │ ├── UIListView.lua │ │ │ ├── UIPageView.lua │ │ │ ├── UIScrollView.lua │ │ │ ├── UISlider.lua │ │ │ ├── UITextField.lua │ │ │ └── UIWidget.lua │ │ ├── init.lua │ │ ├── package_support.lua │ │ └── transition.lua │ ├── init.lua │ ├── network │ │ ├── DeprecatedNetworkClass.lua │ │ ├── DeprecatedNetworkEnum.lua │ │ ├── DeprecatedNetworkFunc.lua │ │ └── NetworkConstants.lua │ ├── spine │ │ └── SpineConstants.lua │ └── ui │ │ ├── DeprecatedUIEnum.lua │ │ ├── DeprecatedUIFunc.lua │ │ ├── GuiConstants.lua │ │ └── experimentalUIConstants.lua ├── quick │ ├── audio.lua │ ├── cc │ │ ├── EventProxy.lua │ │ ├── GameObject.lua │ │ ├── Registry.lua │ │ ├── components │ │ │ ├── Component.lua │ │ │ ├── behavior │ │ │ │ ├── EventProtocol.lua │ │ │ │ └── StateMachine.lua │ │ │ └── ui │ │ │ │ ├── BasicLayoutProtocol.lua │ │ │ │ ├── DraggableProtocol.lua │ │ │ │ └── LayoutProtocol.lua │ │ ├── init.lua │ │ ├── mvc │ │ │ ├── AppBase.lua │ │ │ ├── CtrlBase.lua │ │ │ ├── ModelBase.lua │ │ │ └── init.lua │ │ ├── net │ │ │ ├── SocketTCP.lua │ │ │ └── init.lua │ │ ├── ui │ │ │ ├── UIBoxLayout.lua │ │ │ ├── UIButton.lua │ │ │ ├── UICheckBoxButton.lua │ │ │ ├── UICheckBoxButtonGroup.lua │ │ │ ├── UIGroup.lua │ │ │ ├── UIImage.lua │ │ │ ├── UIInput.lua │ │ │ ├── UILabel.lua │ │ │ ├── UILayout.lua │ │ │ ├── UIListView.lua │ │ │ ├── UIListViewItem.lua │ │ │ ├── UILoadingBar.lua │ │ │ ├── UIPageView.lua │ │ │ ├── UIPageViewItem.lua │ │ │ ├── UIPushButton.lua │ │ │ ├── UIScrollView.lua │ │ │ ├── UISlider.lua │ │ │ ├── UIStretch.lua │ │ │ └── init.lua │ │ └── utils │ │ │ ├── GameState.lua │ │ │ ├── Localize.lua │ │ │ └── Timer.lua │ ├── cocos2dx.lua │ ├── cocos2dx │ │ ├── ActionEx.lua │ │ ├── DrawNodeEx.lua │ │ ├── Event.lua │ │ ├── NodeEx.lua │ │ ├── SceneEx.lua │ │ └── SpriteEx.lua │ ├── crypto.lua │ ├── debug.lua │ ├── device.lua │ ├── display.lua │ ├── filter.lua │ ├── functions.lua │ ├── init.lua │ ├── json.lua │ ├── network.lua │ ├── platform │ │ ├── android.lua │ │ ├── ios.lua │ │ └── mac.lua │ ├── scheduler.lua │ ├── shortcodes.lua │ ├── transition.lua │ └── zr │ │ ├── CaptureScreenUtil.lua │ │ ├── DBCCArmatureNodeEx.lua │ │ ├── FileUtil.lua │ │ ├── FilterSpriteEx.lua │ │ ├── ResourceCache.lua │ │ ├── ResourceManager.lua │ │ ├── SharedObject.lua │ │ ├── UIProgressBar.lua │ │ ├── UIProgressBarOld.lua │ │ ├── UIProgressDot.lua │ │ ├── WebView.lua │ │ ├── dragonbones.lua │ │ └── init.lua └── zrong │ ├── debug.lua │ ├── functions.lua │ ├── init.lua │ ├── luabit │ ├── bit.lua │ ├── hex.lua │ ├── noki.lua │ ├── readme.txt │ └── utf8.lua │ └── zr │ ├── init.lua │ ├── log │ ├── FileHandler.lua │ ├── LogHandler.lua │ ├── Logger.lua │ ├── PrintHandler.lua │ ├── SyslogHandler.lua │ ├── adapter │ │ ├── RestyAdapter.lua │ │ └── SocketAdapter.lua │ └── init.lua │ └── utils │ ├── BigNumber.lua │ ├── ByteArray.lua │ ├── ByteArrayVarint.lua │ ├── Gettext.lua │ ├── bit.lua │ └── init.lua ├── luabytearray.png ├── src ├── MainScene.lua ├── config.lua ├── game.lua └── main.lua └── test └── testlog.lua /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | *.log 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, Jacky Tsang 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /lib/cocos/cocos2d/bitExtend.lua: -------------------------------------------------------------------------------- 1 | -- bit operation 2 | 3 | bit = bit or {} 4 | bit.data32 = {} 5 | 6 | for i=1,32 do 7 | bit.data32[i]=2^(32-i) 8 | end 9 | 10 | function bit._b2d(arg) 11 | local nr=0 12 | for i=1,32 do 13 | if arg[i] ==1 then 14 | nr=nr+bit.data32[i] 15 | end 16 | end 17 | return nr 18 | end 19 | 20 | function bit._d2b(arg) 21 | arg = arg >= 0 and arg or (0xFFFFFFFF + arg + 1) 22 | local tr={} 23 | for i=1,32 do 24 | if arg >= bit.data32[i] then 25 | tr[i]=1 26 | arg=arg-bit.data32[i] 27 | else 28 | tr[i]=0 29 | end 30 | end 31 | return tr 32 | end 33 | 34 | function bit._and(a,b) 35 | local op1=bit._d2b(a) 36 | local op2=bit._d2b(b) 37 | local r={} 38 | 39 | for i=1,32 do 40 | if op1[i]==1 and op2[i]==1 then 41 | r[i]=1 42 | else 43 | r[i]=0 44 | end 45 | end 46 | return bit._b2d(r) 47 | 48 | end 49 | 50 | function bit._rshift(a,n) 51 | local op1=bit._d2b(a) 52 | n = n <= 32 and n or 32 53 | n = n >= 0 and n or 0 54 | 55 | for i=32, n+1, -1 do 56 | op1[i] = op1[i-n] 57 | end 58 | for i=1, n do 59 | op1[i] = 0 60 | end 61 | 62 | return bit._b2d(op1) 63 | end 64 | 65 | function bit._not(a) 66 | local op1=bit._d2b(a) 67 | local r={} 68 | 69 | for i=1,32 do 70 | if op1[i]==1 then 71 | r[i]=0 72 | else 73 | r[i]=1 74 | end 75 | end 76 | return bit._b2d(r) 77 | end 78 | 79 | function bit._or(a,b) 80 | local op1=bit._d2b(a) 81 | local op2=bit._d2b(b) 82 | local r={} 83 | 84 | for i=1,32 do 85 | if op1[i]==1 or op2[i]==1 then 86 | r[i]=1 87 | else 88 | r[i]=0 89 | end 90 | end 91 | return bit._b2d(r) 92 | end 93 | 94 | bit.band = bit.band or bit._and 95 | bit.rshift = bit.rshift or bit._rshift 96 | bit.bnot = bit.bnot or bit._not 97 | -------------------------------------------------------------------------------- /lib/cocos/cocos2d/deprecated.lua: -------------------------------------------------------------------------------- 1 | 2 | function schedule(node, callback, delay) 3 | local delay = cc.DelayTime:create(delay) 4 | local sequence = cc.Sequence:create(delay, cc.CallFunc:create(callback)) 5 | local action = cc.RepeatForever:create(sequence) 6 | node:runAction(action) 7 | return action 8 | end 9 | 10 | function performWithDelay(node, callback, delay) 11 | local delay = cc.DelayTime:create(delay) 12 | local sequence = cc.Sequence:create(delay, cc.CallFunc:create(callback)) 13 | node:runAction(sequence) 14 | return sequence 15 | end 16 | -------------------------------------------------------------------------------- /lib/cocos/cocos2d/luaj.lua: -------------------------------------------------------------------------------- 1 | 2 | local luaj = {} 3 | 4 | local callJavaStaticMethod = LuaJavaBridge.callStaticMethod 5 | 6 | local function checkArguments(args, sig) 7 | if type(args) ~= "table" then args = {} end 8 | if sig then return args, sig end 9 | 10 | sig = {"("} 11 | for i, v in ipairs(args) do 12 | local t = type(v) 13 | if t == "number" then 14 | sig[#sig + 1] = "F" 15 | elseif t == "boolean" then 16 | sig[#sig + 1] = "Z" 17 | elseif t == "function" then 18 | sig[#sig + 1] = "I" 19 | else 20 | sig[#sig + 1] = "Ljava/lang/String;" 21 | end 22 | end 23 | sig[#sig + 1] = ")V" 24 | 25 | return args, table.concat(sig) 26 | end 27 | 28 | function luaj.callStaticMethod(className, methodName, args, sig) 29 | local args, sig = checkArguments(args, sig) 30 | --echoInfo("luaj.callStaticMethod(\"%s\",\n\t\"%s\",\n\targs,\n\t\"%s\"", className, methodName, sig) 31 | return callJavaStaticMethod(className, methodName, args, sig) 32 | end 33 | 34 | return luaj 35 | -------------------------------------------------------------------------------- /lib/cocos/cocos2d/luaoc.lua: -------------------------------------------------------------------------------- 1 | 2 | local luaoc = {} 3 | 4 | local callStaticMethod = LuaObjcBridge.callStaticMethod 5 | 6 | function luaoc.callStaticMethod(className, methodName, args) 7 | local ok, ret = callStaticMethod(className, methodName, args) 8 | if not ok then 9 | local msg = string.format("luaoc.callStaticMethod(\"%s\", \"%s\", \"%s\") - error: [%s] ", 10 | className, methodName, tostring(args), tostring(ret)) 11 | if ret == -1 then 12 | print(msg .. "INVALID PARAMETERS") 13 | elseif ret == -2 then 14 | print(msg .. "CLASS NOT FOUND") 15 | elseif ret == -3 then 16 | print(msg .. "METHOD NOT FOUND") 17 | elseif ret == -4 then 18 | print(msg .. "EXCEPTION OCCURRED") 19 | elseif ret == -5 then 20 | print(msg .. "INVALID METHOD SIGNATURE") 21 | else 22 | print(msg .. "UNKNOWN") 23 | end 24 | end 25 | return ok, ret 26 | end 27 | 28 | return luaoc 29 | -------------------------------------------------------------------------------- /lib/cocos/cocosbuilder/DeprecatedCocosBuilderClass.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.CCBProxy then 2 | return 3 | end 4 | -- This is the DeprecatedCocosBuilderClass 5 | 6 | DeprecatedCocosBuilderClass = {} or DeprecatedCocosBuilderClass 7 | 8 | --tip 9 | local function deprecatedTip(old_name,new_name) 10 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 11 | end 12 | 13 | --CCBReader class will be Deprecated,begin 14 | function DeprecatedCocosBuilderClass.CCBReader() 15 | deprecatedTip("CCBReader","cc.BReader") 16 | return cc.BReader 17 | end 18 | _G["CCBReader"] = DeprecatedCocosBuilderClass.CCBReader() 19 | --CCBReader class will be Deprecated,end 20 | 21 | --CCBAnimationManager class will be Deprecated,begin 22 | function DeprecatedCocosBuilderClass.CCBAnimationManager() 23 | deprecatedTip("CCBAnimationManager","cc.BAnimationManager") 24 | return cc.BAnimationManager 25 | end 26 | _G["CCBAnimationManager"] = DeprecatedCocosBuilderClass.CCBAnimationManager() 27 | --CCBAnimationManager class will be Deprecated,end 28 | 29 | --CCBProxy class will be Deprecated,begin 30 | function DeprecatedCocosBuilderClass.CCBProxy() 31 | deprecatedTip("CCBProxy","cc.CCBProxy") 32 | return cc.CCBProxy 33 | end 34 | _G["CCBProxy"] = DeprecatedCocosBuilderClass.CCBProxy() 35 | --CCBProxy class will be Deprecated,end 36 | -------------------------------------------------------------------------------- /lib/cocos/cocosdenshion/AudioEngine.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.SimpleAudioEngine then 2 | return 3 | end 4 | --Encapsulate SimpleAudioEngine to AudioEngine,Play music and sound effects. 5 | local M = {} 6 | 7 | function M.stopAllEffects() 8 | cc.SimpleAudioEngine:getInstance():stopAllEffects() 9 | end 10 | 11 | function M.getMusicVolume() 12 | return cc.SimpleAudioEngine:getInstance():getMusicVolume() 13 | end 14 | 15 | function M.isMusicPlaying() 16 | return cc.SimpleAudioEngine:getInstance():isMusicPlaying() 17 | end 18 | 19 | function M.getEffectsVolume() 20 | return cc.SimpleAudioEngine:getInstance():getEffectsVolume() 21 | end 22 | 23 | function M.setMusicVolume(volume) 24 | cc.SimpleAudioEngine:getInstance():setMusicVolume(volume) 25 | end 26 | 27 | function M.stopEffect(handle) 28 | cc.SimpleAudioEngine:getInstance():stopEffect(handle) 29 | end 30 | 31 | function M.stopMusic(isReleaseData) 32 | local releaseDataValue = false 33 | if nil ~= isReleaseData then 34 | releaseDataValue = isReleaseData 35 | end 36 | cc.SimpleAudioEngine:getInstance():stopMusic(releaseDataValue) 37 | end 38 | 39 | function M.playMusic(filename, isLoop) 40 | local loopValue = false 41 | if nil ~= isLoop then 42 | loopValue = isLoop 43 | end 44 | cc.SimpleAudioEngine:getInstance():playMusic(filename, loopValue) 45 | end 46 | 47 | function M.pauseAllEffects() 48 | cc.SimpleAudioEngine:getInstance():pauseAllEffects() 49 | end 50 | 51 | function M.preloadMusic(filename) 52 | cc.SimpleAudioEngine:getInstance():preloadMusic(filename) 53 | end 54 | 55 | function M.resumeMusic() 56 | cc.SimpleAudioEngine:getInstance():resumeMusic() 57 | end 58 | 59 | function M.playEffect(filename, isLoop) 60 | local loopValue = false 61 | if nil ~= isLoop then 62 | loopValue = isLoop 63 | end 64 | return cc.SimpleAudioEngine:getInstance():playEffect(filename, loopValue) 65 | end 66 | 67 | function M.rewindMusic() 68 | cc.SimpleAudioEngine:getInstance():rewindMusic() 69 | end 70 | 71 | function M.willPlayMusic() 72 | return cc.SimpleAudioEngine:getInstance():willPlayMusic() 73 | end 74 | 75 | function M.unloadEffect(filename) 76 | cc.SimpleAudioEngine:getInstance():unloadEffect(filename) 77 | end 78 | 79 | function M.preloadEffect(filename) 80 | cc.SimpleAudioEngine:getInstance():preloadEffect(filename) 81 | end 82 | 83 | function M.setEffectsVolume(volume) 84 | cc.SimpleAudioEngine:getInstance():setEffectsVolume(volume) 85 | end 86 | 87 | function M.pauseEffect(handle) 88 | cc.SimpleAudioEngine:getInstance():pauseEffect(handle) 89 | end 90 | 91 | function M.resumeAllEffects(handle) 92 | cc.SimpleAudioEngine:getInstance():resumeAllEffects() 93 | end 94 | 95 | function M.pauseMusic() 96 | cc.SimpleAudioEngine:getInstance():pauseMusic() 97 | end 98 | 99 | function M.resumeEffect(handle) 100 | cc.SimpleAudioEngine:getInstance():resumeEffect(handle) 101 | end 102 | 103 | function M.getInstance() 104 | return cc.SimpleAudioEngine:getInstance() 105 | end 106 | 107 | function M.destroyInstance() 108 | return cc.SimpleAudioEngine:destroyInstance() 109 | end 110 | 111 | AudioEngine = M 112 | -------------------------------------------------------------------------------- /lib/cocos/cocosdenshion/DeprecatedCocosDenshionClass.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.SimpleAudioEngine then 2 | return 3 | end 4 | -- This is the DeprecatedCocosDenshionClass 5 | 6 | DeprecatedCocosDenshionClass = {} or DeprecatedCocosDenshionClass 7 | 8 | --tip 9 | local function deprecatedTip(old_name,new_name) 10 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 11 | end 12 | 13 | --SimpleAudioEngine class will be Deprecated,begin 14 | function DeprecatedCocosDenshionClass.SimpleAudioEngine() 15 | deprecatedTip("SimpleAudioEngine","cc.SimpleAudioEngine") 16 | return cc.SimpleAudioEngine 17 | end 18 | _G["SimpleAudioEngine"] = DeprecatedCocosDenshionClass.SimpleAudioEngine() 19 | --SimpleAudioEngine class will be Deprecated,end 20 | -------------------------------------------------------------------------------- /lib/cocos/cocosdenshion/DeprecatedCocosDenshionFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.SimpleAudioEngine then 2 | return 3 | end 4 | --tip 5 | local function deprecatedTip(old_name,new_name) 6 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 7 | end 8 | 9 | --functions of SimpleAudioEngine will be deprecated begin 10 | local SimpleAudioEngineDeprecated = { } 11 | function SimpleAudioEngineDeprecated.sharedEngine() 12 | deprecatedTip("SimpleAudioEngine:sharedEngine","SimpleAudioEngine:getInstance") 13 | return cc.SimpleAudioEngine:getInstance() 14 | end 15 | SimpleAudioEngine.sharedEngine = SimpleAudioEngineDeprecated.sharedEngine 16 | 17 | function SimpleAudioEngineDeprecated.playBackgroundMusic(self,...) 18 | deprecatedTip("SimpleAudioEngine:playBackgroundMusic","SimpleAudioEngine:playMusic") 19 | return self:playMusic(...) 20 | end 21 | SimpleAudioEngine.playBackgroundMusic = SimpleAudioEngineDeprecated.playBackgroundMusic 22 | --functions of SimpleAudioEngine will be deprecated end 23 | -------------------------------------------------------------------------------- /lib/cocos/cocostudio/DeprecatedCocoStudioFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == ccs then 2 | return 3 | end 4 | 5 | --tip 6 | local function deprecatedTip(old_name,new_name) 7 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 8 | end 9 | 10 | --functions of GUIReader will be deprecated begin 11 | local GUIReaderDeprecated = { } 12 | function GUIReaderDeprecated.shareReader() 13 | deprecatedTip("GUIReader:shareReader","ccs.GUIReader:getInstance") 14 | return ccs.GUIReader:getInstance() 15 | end 16 | GUIReader.shareReader = GUIReaderDeprecated.shareReader 17 | 18 | function GUIReaderDeprecated.purgeGUIReader() 19 | deprecatedTip("GUIReader:purgeGUIReader","ccs.GUIReader:destroyInstance") 20 | return ccs.GUIReader:destroyInstance() 21 | end 22 | GUIReader.purgeGUIReader = GUIReaderDeprecated.purgeGUIReader 23 | --functions of GUIReader will be deprecated end 24 | 25 | --functions of SceneReader will be deprecated begin 26 | local SceneReaderDeprecated = { } 27 | function SceneReaderDeprecated.sharedSceneReader() 28 | deprecatedTip("SceneReader:sharedSceneReader","ccs.SceneReader:getInstance") 29 | return ccs.SceneReader:getInstance() 30 | end 31 | SceneReader.sharedSceneReader = SceneReaderDeprecated.sharedSceneReader 32 | 33 | function SceneReaderDeprecated.purgeSceneReader(self) 34 | deprecatedTip("SceneReader:purgeSceneReader","ccs.SceneReader:destroyInstance") 35 | return self:destroyInstance() 36 | end 37 | SceneReader.purgeSceneReader = SceneReaderDeprecated.purgeSceneReader 38 | --functions of SceneReader will be deprecated end 39 | 40 | 41 | --functions of ccs.GUIReader will be deprecated begin 42 | local CCSGUIReaderDeprecated = { } 43 | function CCSGUIReaderDeprecated.purgeGUIReader() 44 | deprecatedTip("ccs.GUIReader:purgeGUIReader","ccs.GUIReader:destroyInstance") 45 | return ccs.GUIReader:destroyInstance() 46 | end 47 | ccs.GUIReader.purgeGUIReader = CCSGUIReaderDeprecated.purgeGUIReader 48 | --functions of ccs.GUIReader will be deprecated end 49 | 50 | --functions of ccs.ActionManagerEx will be deprecated begin 51 | local CCSActionManagerExDeprecated = { } 52 | function CCSActionManagerExDeprecated.destroyActionManager() 53 | deprecatedTip("ccs.ActionManagerEx:destroyActionManager","ccs.ActionManagerEx:destroyInstance") 54 | return ccs.ActionManagerEx:destroyInstance() 55 | end 56 | ccs.ActionManagerEx.destroyActionManager = CCSActionManagerExDeprecated.destroyActionManager 57 | --functions of ccs.ActionManagerEx will be deprecated end 58 | 59 | --functions of ccs.SceneReader will be deprecated begin 60 | local CCSSceneReaderDeprecated = { } 61 | function CCSSceneReaderDeprecated.destroySceneReader(self) 62 | deprecatedTip("ccs.SceneReader:destroySceneReader","ccs.SceneReader:destroyInstance") 63 | return self:destroyInstance() 64 | end 65 | ccs.SceneReader.destroySceneReader = CCSSceneReaderDeprecated.destroySceneReader 66 | --functions of ccs.SceneReader will be deprecated end 67 | 68 | --functions of CCArmatureDataManager will be deprecated begin 69 | local CCArmatureDataManagerDeprecated = { } 70 | function CCArmatureDataManagerDeprecated.sharedArmatureDataManager() 71 | deprecatedTip("CCArmatureDataManager:sharedArmatureDataManager","ccs.ArmatureDataManager:getInstance") 72 | return ccs.ArmatureDataManager:getInstance() 73 | end 74 | CCArmatureDataManager.sharedArmatureDataManager = CCArmatureDataManagerDeprecated.sharedArmatureDataManager 75 | 76 | function CCArmatureDataManagerDeprecated.purge() 77 | deprecatedTip("CCArmatureDataManager:purge","ccs.ArmatureDataManager:destoryInstance") 78 | return ccs.ArmatureDataManager:destoryInstance() 79 | end 80 | CCArmatureDataManager.purge = CCArmatureDataManagerDeprecated.purge 81 | --functions of CCArmatureDataManager will be deprecated end 82 | -------------------------------------------------------------------------------- /lib/cocos/cocostudio/StudioConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == ccs then 2 | return 3 | end 4 | 5 | ccs.MovementEventType = { 6 | start = 0, 7 | complete = 1, 8 | loopComplete = 2, 9 | } 10 | 11 | ccs.InnerActionType = { 12 | LoopAction = 0, 13 | NoLoopAction = 1, 14 | SingleFrame = 2, 15 | } 16 | -------------------------------------------------------------------------------- /lib/cocos/controller/ControllerConstants.lua: -------------------------------------------------------------------------------- 1 | 2 | cc = cc or {} 3 | 4 | cc.ControllerKey = 5 | { 6 | JOYSTICK_LEFT_X = 1000, 7 | JOYSTICK_LEFT_Y = 1001, 8 | JOYSTICK_RIGHT_X = 1002, 9 | JOYSTICK_RIGHT_Y = 1003, 10 | 11 | BUTTON_A = 1004, 12 | BUTTON_B = 1005, 13 | BUTTON_C = 1006, 14 | BUTTON_X = 1007, 15 | BUTTON_Y = 1008, 16 | BUTTON_Z = 1009, 17 | 18 | BUTTON_DPAD_UP = 1010, 19 | BUTTON_DPAD_DOWN = 1011, 20 | BUTTON_DPAD_LEFT = 1012, 21 | BUTTON_DPAD_RIGHT = 1013, 22 | BUTTON_DPAD_CENTER = 1014, 23 | 24 | BUTTON_LEFT_SHOULDER = 1015, 25 | BUTTON_RIGHT_SHOULDER = 1016, 26 | 27 | AXIS_LEFT_TRIGGER = 1017, 28 | AXIS_RIGHT_TRIGGER = 1018, 29 | 30 | BUTTON_LEFT_THUMBSTICK = 1019, 31 | BUTTON_RIGHT_THUMBSTICK = 1020, 32 | 33 | BUTTON_START = 1021, 34 | BUTTON_SELECT = 1022, 35 | 36 | BUTTON_PAUSE = 1023, 37 | KEY_MAX = 1024, 38 | } 39 | -------------------------------------------------------------------------------- /lib/cocos/extension/DeprecatedExtensionEnum.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Control then 2 | return 3 | end 4 | 5 | _G.kCCControlStepperPartMinus = cc.CONTROL_STEPPER_PART_MINUS 6 | _G.kCCControlStepperPartPlus = cc.CONTROL_STEPPER_PART_PLUS 7 | _G.kCCControlStepperPartNone = cc.CONTROL_STEPPER_PART_NONE 8 | 9 | _G.CCControlEventTouchDown = cc.CONTROL_EVENTTYPE_TOUCH_DOWN 10 | _G.CCControlEventTouchDragInside = cc.CONTROL_EVENTTYPE_DRAG_INSIDE 11 | _G.CCControlEventTouchDragOutside = cc.CONTROL_EVENTTYPE_DRAG_OUTSIDE 12 | _G.CCControlEventTouchDragEnter = cc.CONTROL_EVENTTYPE_DRAG_ENTER 13 | _G.CCControlEventTouchDragExit = cc.CONTROL_EVENTTYPE_DRAG_EXIT 14 | _G.CCControlEventTouchUpInside = cc.CONTROL_EVENTTYPE_TOUCH_UP_INSIDE 15 | _G.CCControlEventTouchUpOutside = cc.CONTROL_EVENTTYPE_TOUCH_UP_OUTSIDE 16 | _G.CCControlEventTouchCancel = cc.CONTROL_EVENTTYPE_TOUCH_CANCEL 17 | _G.CCControlEventValueChanged = cc.CONTROL_EVENTTYPE_VALUE_CHANGED 18 | _G.CCControlStateNormal = cc.CONTROL_STATE_NORMAL 19 | _G.CCControlStateHighlighted = cc.CONTROL_STATE_HIGH_LIGHTED 20 | _G.CCControlStateDisabled = cc.CONTROL_STATE_DISABLED 21 | _G.CCControlStateSelected = cc.CONTROL_STATE_SELECTED 22 | 23 | _G.kCCScrollViewDirectionHorizontal = cc.SCROLLVIEW_DIRECTION_HORIZONTAL 24 | _G.kCCScrollViewDirectionVertical = cc.SCROLLVIEW_DIRECTION_VERTICAL 25 | _G.kCCTableViewFillTopDown = cc.TABLEVIEW_FILL_TOPDOWN 26 | _G.kCCTableViewFillBottomUp = cc.TABLEVIEW_FILL_BOTTOMUP 27 | -------------------------------------------------------------------------------- /lib/cocos/extension/DeprecatedExtensionFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Control then 2 | return 3 | end 4 | 5 | --tip 6 | local function deprecatedTip(old_name,new_name) 7 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 8 | end 9 | 10 | --functions of CCControl will be deprecated end 11 | local CCControlDeprecated = { } 12 | function CCControlDeprecated.addHandleOfControlEvent(self,func,controlEvent) 13 | deprecatedTip("addHandleOfControlEvent","registerControlEventHandler") 14 | print("come in addHandleOfControlEvent") 15 | self:registerControlEventHandler(func,controlEvent) 16 | end 17 | CCControl.addHandleOfControlEvent = CCControlDeprecated.addHandleOfControlEvent 18 | --functions of CCControl will be deprecated end 19 | 20 | --Enums of CCTableView will be deprecated begin 21 | CCTableView.kTableViewScroll = cc.SCROLLVIEW_SCRIPT_SCROLL 22 | CCTableView.kTableViewZoom = cc.SCROLLVIEW_SCRIPT_ZOOM 23 | CCTableView.kTableCellTouched = cc.TABLECELL_TOUCHED 24 | CCTableView.kTableCellSizeForIndex = cc.TABLECELL_SIZE_FOR_INDEX 25 | CCTableView.kTableCellSizeAtIndex = cc.TABLECELL_SIZE_AT_INDEX 26 | CCTableView.kNumberOfCellsInTableView = cc.NUMBER_OF_CELLS_IN_TABLEVIEW 27 | --Enums of CCTableView will be deprecated end 28 | 29 | --Enums of CCScrollView will be deprecated begin 30 | CCScrollView.kScrollViewScroll = cc.SCROLLVIEW_SCRIPT_SCROLL 31 | CCScrollView.kScrollViewZoom = cc.SCROLLVIEW_SCRIPT_ZOOM 32 | --Enums of CCScrollView will be deprecated end 33 | -------------------------------------------------------------------------------- /lib/cocos/extension/ExtensionConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Control then 2 | return 3 | end 4 | 5 | cc.CONTROL_STATE_NORMAL = 1 6 | cc.CONTROL_STATE_HIGH_LIGHTED = 2 7 | cc.CONTROL_STATE_DISABLED = 4 8 | cc.CONTROL_STATE_SELECTED = 8 9 | 10 | cc.CONTROL_STEPPER_PART_MINUS = 0 11 | cc.CONTROL_STEPPER_PART_PLUS = 1 12 | cc.CONTROL_STEPPER_PART_NONE = 2 13 | 14 | cc.TABLEVIEW_FILL_TOPDOWN = 0 15 | cc.TABLEVIEW_FILL_BOTTOMUP = 1 16 | 17 | cc.SCROLLVIEW_SCRIPT_SCROLL = 0 18 | cc.SCROLLVIEW_SCRIPT_ZOOM = 1 19 | cc.TABLECELL_TOUCHED = 2 20 | cc.TABLECELL_HIGH_LIGHT = 3 21 | cc.TABLECELL_UNHIGH_LIGHT = 4 22 | cc.TABLECELL_WILL_RECYCLE = 5 23 | cc.TABLECELL_SIZE_FOR_INDEX = 6 24 | cc.TABLECELL_SIZE_AT_INDEX = 7 25 | cc.NUMBER_OF_CELLS_IN_TABLEVIEW = 8 26 | 27 | cc.SCROLLVIEW_DIRECTION_NONE = -1 28 | cc.SCROLLVIEW_DIRECTION_HORIZONTAL = 0 29 | cc.SCROLLVIEW_DIRECTION_VERTICAL = 1 30 | cc.SCROLLVIEW_DIRECTION_BOTH = 2 31 | 32 | cc.CONTROL_EVENTTYPE_TOUCH_DOWN = 1 33 | cc.CONTROL_EVENTTYPE_DRAG_INSIDE = 2 34 | cc.CONTROL_EVENTTYPE_DRAG_OUTSIDE = 4 35 | cc.CONTROL_EVENTTYPE_DRAG_ENTER = 8 36 | cc.CONTROL_EVENTTYPE_DRAG_EXIT = 16 37 | cc.CONTROL_EVENTTYPE_TOUCH_UP_INSIDE = 32 38 | cc.CONTROL_EVENTTYPE_TOUCH_UP_OUTSIDE = 64 39 | cc.CONTROL_EVENTTYPE_TOUCH_CANCEL = 128 40 | cc.CONTROL_EVENTTYPE_VALUE_CHANGED = 256 41 | 42 | cc.EDITBOX_INPUT_MODE_ANY = 0 43 | cc.EDITBOX_INPUT_MODE_EMAILADDR = 1 44 | cc.EDITBOX_INPUT_MODE_NUMERIC = 2 45 | cc.EDITBOX_INPUT_MODE_PHONENUMBER = 3 46 | cc.EDITBOX_INPUT_MODE_URL = 4 47 | cc.EDITBOX_INPUT_MODE_DECIMAL = 5 48 | cc.EDITBOX_INPUT_MODE_SINGLELINE = 6 49 | 50 | cc.EDITBOX_INPUT_FLAG_PASSWORD = 0 51 | cc.EDITBOX_INPUT_FLAG_SENSITIVE = 1 52 | cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_WORD = 2 53 | cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_SENTENCE = 3 54 | cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_ALL_CHARACTERS = 4 55 | 56 | cc.KEYBOARD_RETURNTYPE_DEFAULT = 0 57 | cc.KEYBOARD_RETURNTYPE_DONE = 1 58 | cc.KEYBOARD_RETURNTYPE_SEND = 2 59 | cc.KEYBOARD_RETURNTYPE_SEARCH = 3 60 | cc.KEYBOARD_RETURNTYPE_GO = 4 61 | 62 | cc.ASSETSMANAGER_CREATE_FILE = 0 63 | cc.ASSETSMANAGER_NETWORK = 1 64 | cc.ASSETSMANAGER_NO_NEW_VERSION = 2 65 | cc.ASSETSMANAGER_UNCOMPRESS = 3 66 | 67 | cc.ASSETSMANAGER_PROTOCOL_PROGRESS = 0 68 | cc.ASSETSMANAGER_PROTOCOL_SUCCESS = 1 69 | cc.ASSETSMANAGER_PROTOCOL_ERROR = 2 70 | 71 | -------------------------------------------------------------------------------- /lib/cocos/framework/device.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local device = {} 26 | 27 | device.platform = "unknown" 28 | device.model = "unknown" 29 | 30 | local app = cc.Application:getInstance() 31 | local target = app:getTargetPlatform() 32 | if target == cc.PLATFORM_OS_WINDOWS then 33 | device.platform = "windows" 34 | elseif target == cc.PLATFORM_OS_MAC then 35 | device.platform = "mac" 36 | elseif target == cc.PLATFORM_OS_ANDROID then 37 | device.platform = "android" 38 | elseif target == cc.PLATFORM_OS_IPHONE or target == cc.PLATFORM_OS_IPAD then 39 | device.platform = "ios" 40 | local director = cc.Director:getInstance() 41 | local view = director:getOpenGLView() 42 | local framesize = view:getFrameSize() 43 | local w, h = framesize.width, framesize.height 44 | if w == 640 and h == 960 then 45 | device.model = "iphone 4" 46 | elseif w == 640 and h == 1136 then 47 | device.model = "iphone 5" 48 | elseif w == 750 and h == 1334 then 49 | device.model = "iphone 6" 50 | elseif w == 1242 and h == 2208 then 51 | device.model = "iphone 6 plus" 52 | elseif w == 768 and h == 1024 then 53 | device.model = "ipad" 54 | elseif w == 1536 and h == 2048 then 55 | device.model = "ipad retina" 56 | end 57 | elseif target == cc.PLATFORM_OS_WINRT then 58 | device.platform = "winrt" 59 | elseif target == cc.PLATFORM_OS_WP8 then 60 | device.platform = "wp8" 61 | end 62 | 63 | local language_ = app:getCurrentLanguage() 64 | if language_ == cc.LANGUAGE_CHINESE then 65 | language_ = "cn" 66 | elseif language_ == cc.LANGUAGE_FRENCH then 67 | language_ = "fr" 68 | elseif language_ == cc.LANGUAGE_ITALIAN then 69 | language_ = "it" 70 | elseif language_ == cc.LANGUAGE_GERMAN then 71 | language_ = "gr" 72 | elseif language_ == cc.LANGUAGE_SPANISH then 73 | language_ = "sp" 74 | elseif language_ == cc.LANGUAGE_RUSSIAN then 75 | language_ = "ru" 76 | elseif language_ == cc.LANGUAGE_KOREAN then 77 | language_ = "kr" 78 | elseif language_ == cc.LANGUAGE_JAPANESE then 79 | language_ = "jp" 80 | elseif language_ == cc.LANGUAGE_HUNGARIAN then 81 | language_ = "hu" 82 | elseif language_ == cc.LANGUAGE_PORTUGUESE then 83 | language_ = "pt" 84 | elseif language_ == cc.LANGUAGE_ARABIC then 85 | language_ = "ar" 86 | else 87 | language_ = "en" 88 | end 89 | 90 | device.language = language_ 91 | device.writablePath = cc.FileUtils:getInstance():getWritablePath() 92 | device.directorySeparator = "/" 93 | device.pathSeparator = ":" 94 | if device.platform == "windows" then 95 | device.directorySeparator = "\\" 96 | device.pathSeparator = ";" 97 | end 98 | 99 | printInfo("# device.platform = " .. device.platform) 100 | printInfo("# device.model = " .. device.model) 101 | printInfo("# device.language = " .. device.language) 102 | printInfo("# device.writablePath = " .. device.writablePath) 103 | printInfo("# device.directorySeparator = " .. device.directorySeparator) 104 | printInfo("# device.pathSeparator = " .. device.pathSeparator) 105 | printInfo("#") 106 | 107 | return device 108 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/LayerEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Layer = cc.Layer 26 | 27 | function Layer:onTouch(callback, isMultiTouches, swallowTouches) 28 | if type(isMultiTouches) ~= "boolean" then isMultiTouches = false end 29 | if type(swallowTouches) ~= "boolean" then swallowTouches = false end 30 | 31 | self:registerScriptTouchHandler(function(state, ...) 32 | local args = {...} 33 | local event = {name = state} 34 | if isMultiTouches then 35 | args = args[1] 36 | local points = {} 37 | for i = 1, #args, 3 do 38 | local x, y, id = args[i], args[i + 1], args[i + 2] 39 | points[id] = {x = x, y = y, id = id} 40 | end 41 | event.points = points 42 | else 43 | event.x = args[1] 44 | event.y = args[2] 45 | end 46 | callback(event) 47 | end, isMultiTouches, 0, swallowTouches) 48 | self:setTouchEnabled(true) 49 | return self 50 | end 51 | 52 | function Layer:removeTouch() 53 | self:unregisterScriptTouchHandler() 54 | self:setTouchEnabled(false) 55 | return self 56 | end 57 | 58 | function Layer:onKeypad(callback) 59 | self:registerScriptKeypadHandler(callback) 60 | self:setKeyboardEnabled(true) 61 | return self 62 | end 63 | 64 | function Layer:removeKeypad() 65 | self:unregisterScriptKeypadHandler() 66 | self:setKeyboardEnabled(false) 67 | return self 68 | end 69 | 70 | function Layer:onAccelerate(callback) 71 | self:registerScriptAccelerateHandler(callback) 72 | self:setAccelerometerEnabled(true) 73 | return self 74 | end 75 | 76 | function Layer:removeAccelerate() 77 | self:unregisterScriptAccelerateHandler() 78 | self:setAccelerometerEnabled(false) 79 | return self 80 | end 81 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/MenuEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Menu = cc.Menu 26 | local MenuItem = cc.MenuItem 27 | 28 | function MenuItem:onClicked(callback) 29 | self:registerScriptTapHandler(callback) 30 | return self 31 | end 32 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/SpriteEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Sprite = cc.Sprite 26 | 27 | function Sprite:playAnimationOnce(animation, args) 28 | local actions = {} 29 | 30 | local showDelay = args.showDelay or 0 31 | if showDelay then 32 | self:setVisible(false) 33 | actions[#actions + 1] = cc.DelayTime:create(showDelay) 34 | actions[#actions + 1] = cc.Show:create() 35 | end 36 | 37 | local delay = args.delay or 0 38 | if delay > 0 then 39 | actions[#actions + 1] = cc.DelayTime:create(delay) 40 | end 41 | 42 | actions[#actions + 1] = cc.Animate:create(animation) 43 | 44 | if args.removeSelf then 45 | actions[#actions + 1] = cc.RemoveSelf:create() 46 | end 47 | 48 | if args.onComplete then 49 | actions[#actions + 1] = cc.CallFunc:create(args.onComplete) 50 | end 51 | 52 | local action 53 | if #actions > 1 then 54 | action = cc.Sequence:create(actions) 55 | else 56 | action = actions[1] 57 | end 58 | self:runAction(action) 59 | return action 60 | end 61 | 62 | function Sprite:playAnimationForever(animation) 63 | local animate = cc.Animate:create(animation) 64 | local action = cc.RepeatForever:create(animate) 65 | self:runAction(action) 66 | return action 67 | end 68 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/UICheckBox.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local CheckBox = ccui.CheckBox 27 | 28 | function CheckBox:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "selected" 33 | else 34 | event.name = "unselected" 35 | end 36 | event.target = sender 37 | callback(event) 38 | end) 39 | return self 40 | end 41 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/UIEditBox.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local EditBox = ccui.EditBox 27 | 28 | function EditBox:onEditHandler(callback) 29 | self:registerScriptEditBoxHandler(function(name, sender) 30 | local event = {} 31 | event.name = name 32 | event.target = sender 33 | callback(event) 34 | end) 35 | return self 36 | end 37 | 38 | function EditBox:removeEditHandler() 39 | self:unregisterScriptEditBoxHandler() 40 | return self 41 | end 42 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/UIListView.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local ListView = ccui.ListView 27 | 28 | function ListView:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "ON_SELECTED_ITEM_START" 33 | else 34 | event.name = "ON_SELECTED_ITEM_END" 35 | end 36 | event.target = sender 37 | callback(event) 38 | end) 39 | return self 40 | end 41 | 42 | function ListView:onScroll(callback) 43 | self:addScrollViewEventListener(function(sender, eventType) 44 | local event = {} 45 | if eventType == 0 then 46 | event.name = "SCROLL_TO_TOP" 47 | elseif eventType == 1 then 48 | event.name = "SCROLL_TO_BOTTOM" 49 | elseif eventType == 2 then 50 | event.name = "SCROLL_TO_LEFT" 51 | elseif eventType == 3 then 52 | event.name = "SCROLL_TO_RIGHT" 53 | elseif eventType == 4 then 54 | event.name = "SCROLLING" 55 | elseif eventType == 5 then 56 | event.name = "BOUNCE_TOP" 57 | elseif eventType == 6 then 58 | event.name = "BOUNCE_BOTTOM" 59 | elseif eventType == 7 then 60 | event.name = "BOUNCE_LEFT" 61 | elseif eventType == 8 then 62 | event.name = "BOUNCE_RIGHT" 63 | end 64 | event.target = sender 65 | callback(event) 66 | end) 67 | return self 68 | end 69 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/UIPageView.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local PageView = ccui.PageView 27 | 28 | function PageView:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "TURNING" 33 | end 34 | event.target = sender 35 | callback(event) 36 | end) 37 | return self 38 | end 39 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/UIScrollView.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local ScrollView = ccui.ScrollView 27 | 28 | function ScrollView:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "SCROLL_TO_TOP" 33 | elseif eventType == 1 then 34 | event.name = "SCROLL_TO_BOTTOM" 35 | elseif eventType == 2 then 36 | event.name = "SCROLL_TO_LEFT" 37 | elseif eventType == 3 then 38 | event.name = "SCROLL_TO_RIGHT" 39 | elseif eventType == 4 then 40 | event.name = "SCROLLING" 41 | elseif eventType == 5 then 42 | event.name = "BOUNCE_TOP" 43 | elseif eventType == 6 then 44 | event.name = "BOUNCE_BOTTOM" 45 | elseif eventType == 7 then 46 | event.name = "BOUNCE_LEFT" 47 | elseif eventType == 8 then 48 | event.name = "BOUNCE_RIGHT" 49 | end 50 | event.target = sender 51 | callback(event) 52 | end) 53 | return self 54 | end 55 | 56 | ScrollView.onScroll = ScrollView.onEvent 57 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/UISlider.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local Slider = ccui.Slider 27 | 28 | function Slider:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "ON_PERCENTAGE_CHANGED" 33 | end 34 | event.target = sender 35 | callback(event) 36 | end) 37 | return self 38 | end 39 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/UITextField.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local TextField = ccui.TextField 27 | 28 | function TextField:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "ATTACH_WITH_IME" 33 | elseif eventType == 1 then 34 | event.name = "DETACH_WITH_IME" 35 | elseif eventType == 2 then 36 | event.name = "INSERT_TEXT" 37 | elseif eventType == 3 then 38 | event.name = "DELETE_BACKWARD" 39 | end 40 | event.target = sender 41 | callback(event) 42 | end) 43 | return self 44 | end 45 | -------------------------------------------------------------------------------- /lib/cocos/framework/extends/UIWidget.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Widget = ccui.Widget 26 | 27 | function Widget:onTouch(callback) 28 | self:addTouchEventListener(function(sender, state) 29 | local event = {x = 0, y = 0} 30 | if state == 0 then 31 | event.name = "began" 32 | elseif state == 1 then 33 | event.name = "moved" 34 | elseif state == 2 then 35 | event.name = "ended" 36 | else 37 | event.name = "cancelled" 38 | end 39 | event.target = sender 40 | callback(event) 41 | end) 42 | return self 43 | end 44 | -------------------------------------------------------------------------------- /lib/cocos/framework/init.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2015 chukong-incc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | __G__TRACKBACK__ = function(msg) 26 | print("****************************************") 27 | print("------------ LUA ERROR -----------------") 28 | local msg = debug.traceback(msg, 3) 29 | print(msg) 30 | print("------------ LUA ERROR END -------------") 31 | print("****************************************") 32 | return msg 33 | end 34 | 35 | if type(DEBUG) ~= "number" then DEBUG = 0 end 36 | 37 | -- load framework 38 | printInfo("") 39 | printInfo("# DEBUG = " .. DEBUG) 40 | printInfo("#") 41 | 42 | device = require("cocos.framework.device") 43 | display = require("cocos.framework.display") 44 | audio = require("cocos.framework.audio") 45 | transition = require("cocos.framework.transition") 46 | 47 | require("cocos.framework.extends.NodeEx") 48 | require("cocos.framework.extends.SpriteEx") 49 | require("cocos.framework.extends.LayerEx") 50 | require("cocos.framework.extends.MenuEx") 51 | 52 | if ccui then 53 | require("cocos.framework.extends.UIWidget") 54 | require("cocos.framework.extends.UICheckBox") 55 | require("cocos.framework.extends.UIEditBox") 56 | require("cocos.framework.extends.UIListView") 57 | require("cocos.framework.extends.UIPageView") 58 | require("cocos.framework.extends.UIScrollView") 59 | require("cocos.framework.extends.UISlider") 60 | require("cocos.framework.extends.UITextField") 61 | end 62 | 63 | require("cocos.framework.package_support") 64 | 65 | -- register the build-in packages 66 | cc.register("event", require("cocos.framework.components.event")) 67 | 68 | -- export global variable 69 | local __g = _G 70 | cc.exports = {} 71 | setmetatable(cc.exports, { 72 | __newindex = function(_, name, value) 73 | rawset(__g, name, value) 74 | end, 75 | 76 | __index = function(_, name) 77 | return rawget(__g, name) 78 | end 79 | }) 80 | 81 | -- disable create unexpected global variable 82 | function cc.disable_global() 83 | setmetatable(__g, { 84 | __newindex = function(_, name, value) 85 | error(string.format("USE \" cc.exports.%s = value \" INSTEAD OF SET GLOBAL VARIABLE", name), 0) 86 | end 87 | }) 88 | end 89 | 90 | if CC_DISABLE_GLOBAL then 91 | cc.disable_global() 92 | end 93 | -------------------------------------------------------------------------------- /lib/cocos/framework/package_support.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2015 chukong-incc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | -- Cocos2d-Lua core functions 26 | cc.loaded_packages = {} 27 | local loaded_packages = cc.loaded_packages 28 | 29 | function cc.register(name, package) 30 | cc.loaded_packages[name] = package 31 | end 32 | 33 | function cc.load(...) 34 | local names = {...} 35 | assert(#names > 0, "cc.load() - invalid package names") 36 | 37 | local packages = {} 38 | for _, name in ipairs(names) do 39 | assert(type(name) == "string", string.format("cc.load() - invalid package name \"%s\"", tostring(name))) 40 | if not loaded_packages[name] then 41 | local packageName = string.format("packages.%s.init", name) 42 | local cls = require(packageName) 43 | assert(cls, string.format("cc.load() - package class \"%s\" load failed", packageName)) 44 | loaded_packages[name] = cls 45 | 46 | if DEBUG > 1 then 47 | printInfo("cc.load() - load module \"packages.%s.init\"", name) 48 | end 49 | end 50 | packages[#packages + 1] = loaded_packages[name] 51 | end 52 | return unpack(packages) 53 | end 54 | 55 | local load_ = cc.load 56 | local bind_ 57 | bind_ = function(target, ...) 58 | local t = type(target) 59 | assert(t == "table" or t == "userdata", string.format("cc.bind() - invalid target, expected is object, actual is %s", t)) 60 | local names = {...} 61 | assert(#names > 0, "cc.bind() - package names expected") 62 | 63 | load_(...) 64 | if not target.components_ then target.components_ = {} end 65 | for _, name in ipairs(names) do 66 | assert(type(name) == "string" and name ~= "", string.format("cc.bind() - invalid package name \"%s\"", name)) 67 | if not target.components_[name] then 68 | local cls = loaded_packages[name] 69 | for __, depend in ipairs(cls.depends or {}) do 70 | if not target.components_[depend] then 71 | bind_(target, depend) 72 | end 73 | end 74 | local component = cls:create() 75 | target.components_[name] = component 76 | component:bind(target) 77 | end 78 | end 79 | 80 | return target 81 | end 82 | cc.bind = bind_ 83 | 84 | function cc.unbind(target, ...) 85 | if not target.components_ then return end 86 | 87 | local names = {...} 88 | assert(#names > 0, "cc.unbind() - invalid package names") 89 | 90 | for _, name in ipairs(names) do 91 | assert(type(name) == "string" and name ~= "", string.format("cc.unbind() - invalid package name \"%s\"", name)) 92 | local component = target.components_[name] 93 | assert(component, string.format("cc.unbind() - component \"%s\" not found", tostring(name))) 94 | component:unbind(target) 95 | target.components_[name] = nil 96 | end 97 | return target 98 | end 99 | 100 | function cc.setmethods(target, component, methods) 101 | for _, name in ipairs(methods) do 102 | local method = component[name] 103 | target[name] = function(__, ...) 104 | return method(component, ...) 105 | end 106 | end 107 | end 108 | 109 | function cc.unsetmethods(target, methods) 110 | for _, name in ipairs(methods) do 111 | target[name] = nil 112 | end 113 | end 114 | -------------------------------------------------------------------------------- /lib/cocos/init.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2015 chukong-incc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | require "cocos.cocos2d.Cocos2d" 26 | require "cocos.cocos2d.Cocos2dConstants" 27 | require "cocos.cocos2d.functions" 28 | 29 | -- zrong 2015-03-06 vome Opengl and AudioEngine to global 30 | -- opengl 31 | require "cocos.cocos2d.Opengl" 32 | require "cocos.cocos2d.OpenglConstants" 33 | -- audio 34 | require "cocos.cocosdenshion.AudioEngine" 35 | -- extensions 36 | require "cocos.extension.ExtensionConstants" 37 | -- network 38 | require "cocos.network.NetworkConstants" 39 | 40 | 41 | if CC_USE_FRAMEWORK == nil then 42 | -- zrong 2015-03-06 43 | -- cocos.framewrok.init has been in the quick framework 44 | -- and others libraries is unnecessary. 45 | elseif CC_USE_FRAMEWORK then 46 | require "cocos.framework.init" 47 | else 48 | -- cocosstudio 49 | if nil ~= ccs then 50 | require "cocos.cocostudio.CocoStudio" 51 | end 52 | -- ui 53 | if nil ~= ccui then 54 | require "cocos.ui.GuiConstants" 55 | require "cocos.ui.experimentalUIConstants" 56 | end 57 | 58 | -- Spine 59 | if nil ~= sp then 60 | require "cocos.spine.SpineConstants" 61 | end 62 | 63 | require "cocos.cocos2d.deprecated" 64 | require "cocos.cocos2d.DrawPrimitives" 65 | 66 | -- Lua extensions 67 | require "cocos.cocos2d.bitExtend" 68 | 69 | -- CCLuaEngine 70 | require "cocos.cocos2d.DeprecatedCocos2dClass" 71 | require "cocos.cocos2d.DeprecatedCocos2dEnum" 72 | require "cocos.cocos2d.DeprecatedCocos2dFunc" 73 | require "cocos.cocos2d.DeprecatedOpenglEnum" 74 | 75 | -- register_cocostudio_module 76 | if nil ~= ccs then 77 | require "cocos.cocostudio.DeprecatedCocoStudioClass" 78 | require "cocos.cocostudio.DeprecatedCocoStudioFunc" 79 | end 80 | 81 | 82 | -- register_cocosbuilder_module 83 | require "cocos.cocosbuilder.DeprecatedCocosBuilderClass" 84 | 85 | -- register_cocosdenshion_module 86 | require "cocos.cocosdenshion.DeprecatedCocosDenshionClass" 87 | require "cocos.cocosdenshion.DeprecatedCocosDenshionFunc" 88 | 89 | -- register_extension_module 90 | require "cocos.extension.DeprecatedExtensionClass" 91 | require "cocos.extension.DeprecatedExtensionEnum" 92 | require "cocos.extension.DeprecatedExtensionFunc" 93 | 94 | -- register_network_module 95 | require "cocos.network.DeprecatedNetworkClass" 96 | require "cocos.network.DeprecatedNetworkEnum" 97 | require "cocos.network.DeprecatedNetworkFunc" 98 | 99 | -- register_ui_moudle 100 | if nil ~= ccui then 101 | require "cocos.ui.DeprecatedUIEnum" 102 | require "cocos.ui.DeprecatedUIFunc" 103 | end 104 | 105 | -- cocosbuilder 106 | require "cocos.cocosbuilder.CCBReaderLoad" 107 | end 108 | -------------------------------------------------------------------------------- /lib/cocos/network/DeprecatedNetworkClass.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.XMLHttpRequest then 2 | return 3 | end 4 | -- This is the DeprecatedNetworkClass 5 | 6 | DeprecatedNetworkClass = {} or DeprecatedNetworkClass 7 | 8 | --tip 9 | local function deprecatedTip(old_name,new_name) 10 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 11 | end 12 | 13 | --WebSocket class will be Deprecated,begin 14 | function DeprecatedNetworkClass.WebSocket() 15 | deprecatedTip("WebSocket","cc.WebSocket") 16 | return cc.WebSocket 17 | end 18 | _G["WebSocket"] = DeprecatedNetworkClass.WebSocket() 19 | --WebSocket class will be Deprecated,end 20 | -------------------------------------------------------------------------------- /lib/cocos/network/DeprecatedNetworkEnum.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.XMLHttpRequest then 2 | return 3 | end 4 | 5 | _G.kWebSocketScriptHandlerOpen = cc.WEBSOCKET_OPEN 6 | _G.kWebSocketScriptHandlerMessage = cc.WEBSOCKET_MESSAGE 7 | _G.kWebSocketScriptHandlerClose = cc.WEBSOCKET_CLOSE 8 | _G.kWebSocketScriptHandlerError = cc.WEBSOCKET_ERROR 9 | 10 | _G.kStateConnecting = cc.WEBSOCKET_STATE_CONNECTING 11 | _G.kStateOpen = cc.WEBSOCKET_STATE_OPEN 12 | _G.kStateClosing = cc.WEBSOCKET_STATE_CLOSING 13 | _G.kStateClosed = cc.WEBSOCKET_STATE_CLOSED 14 | -------------------------------------------------------------------------------- /lib/cocos/network/DeprecatedNetworkFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.XMLHttpRequest then 2 | return 3 | end 4 | 5 | --tip 6 | local function deprecatedTip(old_name,new_name) 7 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 8 | end 9 | 10 | --functions of WebSocket will be deprecated begin 11 | local targetPlatform = CCApplication:getInstance():getTargetPlatform() 12 | if (kTargetIphone == targetPlatform) or (kTargetIpad == targetPlatform) or (kTargetAndroid == targetPlatform) or (kTargetWindows == targetPlatform) then 13 | local WebSocketDeprecated = { } 14 | function WebSocketDeprecated.sendTextMsg(self, string) 15 | deprecatedTip("WebSocket:sendTextMsg","WebSocket:sendString") 16 | return self:sendString(string) 17 | end 18 | WebSocket.sendTextMsg = WebSocketDeprecated.sendTextMsg 19 | 20 | function WebSocketDeprecated.sendBinaryMsg(self, table,tablesize) 21 | deprecatedTip("WebSocket:sendBinaryMsg","WebSocket:sendString") 22 | string.char(unpack(table)) 23 | return self:sendString(string.char(unpack(table))) 24 | end 25 | WebSocket.sendBinaryMsg = WebSocketDeprecated.sendBinaryMsg 26 | end 27 | --functions of WebSocket will be deprecated end 28 | -------------------------------------------------------------------------------- /lib/cocos/network/NetworkConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.XMLHttpRequest then 2 | return 3 | end 4 | 5 | cc.WEBSOCKET_OPEN = 0 6 | cc.WEBSOCKET_MESSAGE = 1 7 | cc.WEBSOCKET_CLOSE = 2 8 | cc.WEBSOCKET_ERROR = 3 9 | 10 | cc.WEBSOCKET_STATE_CONNECTING = 0 11 | cc.WEBSOCKET_STATE_OPEN = 1 12 | cc.WEBSOCKET_STATE_CLOSING = 2 13 | cc.WEBSOCKET_STATE_CLOSED = 3 14 | 15 | cc.XMLHTTPREQUEST_RESPONSE_STRING = 0 16 | cc.XMLHTTPREQUEST_RESPONSE_ARRAY_BUFFER = 1 17 | cc.XMLHTTPREQUEST_RESPONSE_BLOB = 2 18 | cc.XMLHTTPREQUEST_RESPONSE_DOCUMENT = 3 19 | cc.XMLHTTPREQUEST_RESPONSE_JSON = 4 20 | -------------------------------------------------------------------------------- /lib/cocos/spine/SpineConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == sp then 2 | return 3 | end 4 | 5 | sp.EventType = 6 | { 7 | ANIMATION_START = 0, 8 | ANIMATION_END = 1, 9 | ANIMATION_COMPLETE = 2, 10 | ANIMATION_EVENT = 3, 11 | } 12 | -------------------------------------------------------------------------------- /lib/cocos/ui/DeprecatedUIEnum.lua: -------------------------------------------------------------------------------- 1 | if nil == ccui then 2 | return 3 | end 4 | 5 | LAYOUT_COLOR_NONE = ccui.LayoutBackGroundColorType.none 6 | LAYOUT_COLOR_SOLID = ccui.LayoutBackGroundColorType.solid 7 | LAYOUT_COLOR_GRADIENT = ccui.LayoutBackGroundColorType.gradient 8 | 9 | LAYOUT_ABSOLUTE = ccui.LayoutType.ABSOLUTE 10 | LAYOUT_LINEAR_VERTICAL = ccui.LayoutType.VERTICAL 11 | LAYOUT_LINEAR_HORIZONTAL = ccui.LayoutType.HORIZONTAL 12 | LAYOUT_RELATIVE = ccui.LayoutType.RELATIVE 13 | 14 | BRIGHT_NONE = ccui.BrightStyle.none 15 | BRIGHT_NORMAL = ccui.BrightStyle.normal 16 | BRIGHT_HIGHLIGHT = ccui.BrightStyle.highlight 17 | 18 | UI_TEX_TYPE_LOCAL = ccui.TextureResType.localType 19 | UI_TEX_TYPE_PLIST = ccui.TextureResType.plistType 20 | 21 | TOUCH_EVENT_BEGAN = ccui.TouchEventType.began 22 | TOUCH_EVENT_MOVED = ccui.TouchEventType.moved 23 | TOUCH_EVENT_ENDED = ccui.TouchEventType.ended 24 | TOUCH_EVENT_CANCELED = ccui.TouchEventType.canceled 25 | 26 | SIZE_ABSOLUTE = ccui.SizeType.absolute 27 | SIZE_PERCENT = ccui.SizeType.percent 28 | 29 | POSITION_ABSOLUTE = ccui.PositionType.absolute 30 | POSITION_PERCENT = ccui.PositionType.percent 31 | 32 | CHECKBOX_STATE_EVENT_SELECTED = ccui.CheckBoxEventType.selected 33 | CHECKBOX_STATE_EVENT_UNSELECTED = ccui.CheckBoxEventType.unselected 34 | 35 | CHECKBOX_STATE_EVENT_SELECTED = ccui.CheckBoxEventType.selected 36 | CHECKBOX_STATE_EVENT_UNSELECTED = ccui.CheckBoxEventType.unselected 37 | 38 | LoadingBarTypeLeft = ccui.LoadingBarDirection.LEFT 39 | LoadingBarTypeRight = ccui.LoadingBarDirection.RIGHT 40 | 41 | LoadingBarTypeRight = ccui.SliderEventType.percent_changed 42 | 43 | TEXTFIELD_EVENT_ATTACH_WITH_IME = ccui.TextFiledEventType.attach_with_ime 44 | TEXTFIELD_EVENT_DETACH_WITH_IME = ccui.TextFiledEventType.detach_with_ime 45 | TEXTFIELD_EVENT_INSERT_TEXT = ccui.TextFiledEventType.insert_text 46 | TEXTFIELD_EVENT_DELETE_BACKWARD = ccui.TextFiledEventType.delete_backward 47 | 48 | SCROLLVIEW_EVENT_SCROLL_TO_TOP = ccui.ScrollViewDir.none 49 | SCROLLVIEW_DIR_VERTICAL = ccui.ScrollViewDir.vertical 50 | SCROLLVIEW_DIR_HORIZONTAL = ccui.ScrollViewDir.horizontal 51 | SCROLLVIEW_DIR_BOTH = ccui.ScrollViewDir.both 52 | 53 | SCROLLVIEW_EVENT_SCROLL_TO_TOP = ccui.ScrollviewEventType.scrollToTop 54 | SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM = ccui.ScrollviewEventType.scrollToBottom 55 | SCROLLVIEW_EVENT_SCROLL_TO_LEFT = ccui.ScrollviewEventType.scrollToLeft 56 | SCROLLVIEW_EVENT_SCROLL_TO_RIGHT = ccui.ScrollviewEventType.scrollToRight 57 | SCROLLVIEW_EVENT_SCROLLING = ccui.ScrollviewEventType.scrolling 58 | SCROLLVIEW_EVENT_BOUNCE_TOP = ccui.ScrollviewEventType.bounceTop 59 | SCROLLVIEW_EVENT_BOUNCE_BOTTOM = ccui.ScrollviewEventType.bounceBottom 60 | SCROLLVIEW_EVENT_BOUNCE_LEFT = ccui.ScrollviewEventType.bounceLeft 61 | SCROLLVIEW_EVENT_BOUNCE_RIGHT = ccui.ScrollviewEventType.bounceRight 62 | 63 | PAGEVIEW_EVENT_TURNING = ccui.PageViewEventType.turning 64 | 65 | PAGEVIEW_TOUCHLEFT = ccui.PVTouchDir.touch_left 66 | PAGEVIEW_TOUCHRIGHT = ccui.PVTouchDir.touch_right 67 | 68 | LISTVIEW_DIR_NONE = ccui.ListViewDirection.none 69 | LISTVIEW_DIR_VERTICAL = ccui.ListViewDirection.vertical 70 | LISTVIEW_DIR_HORIZONTAL = ccui.ListViewDirection.horizontal 71 | 72 | LISTVIEW_MOVE_DIR_NONE = ccui.ListViewMoveDirection.none 73 | LISTVIEW_MOVE_DIR_UP = ccui.ListViewMoveDirection.up 74 | LISTVIEW_MOVE_DIR_DOWN = ccui.ListViewMoveDirection.down 75 | LISTVIEW_MOVE_DIR_LEFT = ccui.ListViewMoveDirection.left 76 | LISTVIEW_MOVE_DIR_RIGHT = ccui.ListViewMoveDirection.right 77 | 78 | LISTVIEW_EVENT_INIT_CHILD = ccui.ListViewEventType.init_child 79 | LISTVIEW_EVENT_UPDATE_CHILD = ccui.ListViewEventType.update_child 80 | 81 | LAYOUT_PARAMETER_NONE = ccui.LayoutParameterType.none 82 | LAYOUT_PARAMETER_LINEAR = ccui.LayoutParameterType.linear 83 | LAYOUT_PARAMETER_RELATIVE = ccui.LayoutParameterType.relative 84 | 85 | ccui.LoadingBarType = ccui.LoadingBarDirection 86 | ccui.LoadingBarType.left = ccui.LoadingBarDirection.LEFT 87 | ccui.LoadingBarType.right = ccui.LoadingBarDirection.RIGHT 88 | 89 | ccui.LayoutType.absolute = ccui.LayoutType.ABSOLUTE 90 | ccui.LayoutType.linearVertical = ccui.LayoutType.VERTICAL 91 | ccui.LayoutType.linearHorizontal = ccui.LayoutType.HORIZONTAL 92 | ccui.LayoutType.relative = ccui.LayoutType.RELATIVE 93 | 94 | ccui.ListViewEventType.onsSelectedItem = ccui.ListViewEventType.ONSELECTEDITEM_START 95 | -------------------------------------------------------------------------------- /lib/cocos/ui/GuiConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == ccui then 2 | return 3 | end 4 | 5 | ccui.BrightStyle = 6 | { 7 | none = -1, 8 | normal = 0, 9 | highlight = 1, 10 | } 11 | 12 | ccui.TextureResType = 13 | { 14 | localType = 0, 15 | plistType = 1, 16 | } 17 | 18 | ccui.TouchEventType = 19 | { 20 | began = 0, 21 | moved = 1, 22 | ended = 2, 23 | canceled = 3, 24 | } 25 | 26 | ccui.SizeType = 27 | { 28 | absolute = 0, 29 | percent = 1, 30 | } 31 | 32 | ccui.PositionType = { 33 | absolute = 0, 34 | percent = 1, 35 | } 36 | 37 | ccui.CheckBoxEventType = 38 | { 39 | selected = 0, 40 | unselected = 1, 41 | } 42 | 43 | ccui.TextFiledEventType = 44 | { 45 | attach_with_ime = 0, 46 | detach_with_ime = 1, 47 | insert_text = 2, 48 | delete_backward = 3, 49 | } 50 | 51 | ccui.LayoutBackGroundColorType = 52 | { 53 | none = 0, 54 | solid = 1, 55 | gradient = 2, 56 | } 57 | 58 | ccui.LayoutType = 59 | { 60 | ABSOLUTE = 0, 61 | VERTICAL = 1, 62 | HORIZONTAL = 2, 63 | RELATIVE = 3, 64 | } 65 | 66 | ccui.LayoutParameterType = 67 | { 68 | none = 0, 69 | linear = 1, 70 | relative = 2, 71 | } 72 | 73 | ccui.LinearGravity = 74 | { 75 | none = 0, 76 | left = 1, 77 | top = 2, 78 | right = 3, 79 | bottom = 4, 80 | centerVertical = 5, 81 | centerHorizontal = 6, 82 | } 83 | 84 | ccui.RelativeAlign = 85 | { 86 | alignNone = 0, 87 | alignParentTopLeft = 1, 88 | alignParentTopCenterHorizontal = 2, 89 | alignParentTopRight = 3, 90 | alignParentLeftCenterVertical = 4, 91 | centerInParent = 5, 92 | alignParentRightCenterVertical = 6, 93 | alignParentLeftBottom = 7, 94 | alignParentBottomCenterHorizontal = 8, 95 | alignParentRightBottom = 9, 96 | locationAboveLeftAlign = 10, 97 | locationAboveCenter = 11, 98 | locationAboveRightAlign = 12, 99 | locationLeftOfTopAlign = 13, 100 | locationLeftOfCenter = 14, 101 | locationLeftOfBottomAlign = 15, 102 | locationRightOfTopAlign = 16, 103 | locationRightOfCenter = 17, 104 | locationRightOfBottomAlign = 18, 105 | locationBelowLeftAlign = 19, 106 | locationBelowCenter = 20, 107 | locationBelowRightAlign = 21, 108 | } 109 | 110 | ccui.SliderEventType = {percentChanged = 0} 111 | 112 | ccui.LoadingBarDirection = { LEFT = 0, RIGHT = 1} 113 | 114 | ccui.ScrollViewDir = { 115 | none = 0, 116 | vertical = 1, 117 | horizontal = 2, 118 | both = 3, 119 | } 120 | 121 | ccui.ScrollViewMoveDir = { 122 | none = 0, 123 | up = 1, 124 | down = 2, 125 | left = 3, 126 | right = 4, 127 | } 128 | 129 | ccui.ScrollviewEventType = { 130 | scrollToTop = 0, 131 | scrollToBottom = 1, 132 | scrollToLeft = 2, 133 | scrollToRight = 3, 134 | scrolling = 4, 135 | bounceTop = 5, 136 | bounceBottom = 6, 137 | bounceLeft = 7, 138 | bounceRight = 8, 139 | } 140 | 141 | ccui.ListViewDirection = { 142 | none = 0, 143 | vertical = 1, 144 | horizontal = 2, 145 | } 146 | 147 | ccui.ListViewMoveDirection = { 148 | none = 0, 149 | up = 1, 150 | down = 2, 151 | left = 3, 152 | right = 4, 153 | } 154 | 155 | ccui.ListViewEventType = { 156 | ONSELECTEDITEM_START = 0, 157 | ONSELECTEDITEM_END = 1, 158 | } 159 | 160 | ccui.PageViewEventType = { 161 | turning = 0, 162 | } 163 | 164 | ccui.PVTouchDir = { 165 | touchLeft = 0, 166 | touchRight = 1, 167 | } 168 | 169 | ccui.ListViewGravity = { 170 | left = 0, 171 | right = 1, 172 | centerHorizontal = 2, 173 | top = 3, 174 | bottom = 4 , 175 | centerVertical = 5, 176 | } 177 | 178 | ccui.TextType = { 179 | SYSTEM = 0, 180 | TTF = 1, 181 | } 182 | 183 | ccui.LayoutComponent.HorizontalEdge = { 184 | None = 0, 185 | Left = 1, 186 | Right = 2, 187 | Center = 3, 188 | } 189 | 190 | ccui.LayoutComponent.VerticalEdge = { 191 | None = 0, 192 | Bottom = 1, 193 | Top = 2, 194 | Center = 3, 195 | } 196 | -------------------------------------------------------------------------------- /lib/cocos/ui/experimentalUIConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == ccexp then 2 | return 3 | end 4 | 5 | ccexp.VideoPlayerEvent = { 6 | PLAYING = 0, 7 | PAUSED = 1, 8 | STOPPED= 2, 9 | COMPLETED =3, 10 | } 11 | -------------------------------------------------------------------------------- /lib/quick/cc/EventProxy.lua: -------------------------------------------------------------------------------- 1 | 2 | local EventProxy = class("EventProxy") 3 | 4 | function EventProxy:ctor(eventDispatcher, view) 5 | self.eventDispatcher_ = eventDispatcher 6 | self.handles_ = {} 7 | 8 | if view then 9 | cc(view):addNodeEventListener(cc.NODE_EVENT, function(event) 10 | if event.name == "exit" then 11 | self:removeAllEventListeners() 12 | end 13 | end) 14 | end 15 | end 16 | 17 | function EventProxy:addEventListener(eventName, listener, data) 18 | local handle = self.eventDispatcher_:addEventListener(eventName, listener, data) 19 | self.handles_[#self.handles_ + 1] = {eventName, handle} 20 | return self, handle 21 | end 22 | 23 | function EventProxy:removeEventListener(eventHandle) 24 | self.eventDispatcher_:removeEventListener(eventHandle) 25 | for index, handle in pairs(self.handles_) do 26 | if handle[2] == eventHandle then 27 | table.remove(self.handles_, index) 28 | break 29 | end 30 | end 31 | return self 32 | end 33 | 34 | function EventProxy:removeAllEventListenersForEvent(eventName) 35 | for key, handle in pairs(self.handles_) do 36 | if handle[1] == eventName then 37 | self.eventDispatcher_:removeEventListenersByEvent(eventName) 38 | self.handles_[key] = nil 39 | end 40 | end 41 | return self 42 | end 43 | 44 | function EventProxy:getEventHandle(eventName) 45 | for key, handle in pairs(self.handles_) do 46 | if handle[1] == eventName then 47 | return handle[2] 48 | end 49 | end 50 | end 51 | 52 | function EventProxy:removeAllEventListeners() 53 | for _, handle in pairs(self.handles_) do 54 | self.eventDispatcher_:removeEventListener(handle[2]) 55 | end 56 | self.handles_ = {} 57 | return self 58 | end 59 | 60 | return EventProxy 61 | -------------------------------------------------------------------------------- /lib/quick/cc/GameObject.lua: -------------------------------------------------------------------------------- 1 | 2 | local Registry = import(".Registry") 3 | 4 | local GameObject = {} 5 | 6 | function GameObject.extend(target) 7 | target.components_ = {} 8 | 9 | function target:checkComponent(name) 10 | return self.components_[name] ~= nil 11 | end 12 | 13 | function target:addComponent(name) 14 | local component = Registry.newObject(name) 15 | self.components_[name] = component 16 | component:bind_(self) 17 | return component 18 | end 19 | 20 | function target:removeComponent(name) 21 | local component = self.components_[name] 22 | if component then component:unbind_() end 23 | self.components_[name] = nil 24 | end 25 | 26 | function target:getComponent(name) 27 | return self.components_[name] 28 | end 29 | 30 | return target 31 | end 32 | 33 | return GameObject 34 | -------------------------------------------------------------------------------- /lib/quick/cc/Registry.lua: -------------------------------------------------------------------------------- 1 | 2 | local Registry = class("Registry") 3 | 4 | Registry.classes_ = {} 5 | Registry.objects_ = {} 6 | 7 | function Registry.add(cls, name) 8 | assert(type(cls) == "table" and cls.__cname ~= nil, "Registry.add() - invalid class") 9 | if not name then name = cls.__cname end 10 | assert(Registry.classes_[name] == nil, string.format("Registry.add() - class \"%s\" already exists", tostring(name))) 11 | Registry.classes_[name] = cls 12 | end 13 | 14 | function Registry.remove(name) 15 | assert(Registry.classes_[name] ~= nil, string.format("Registry.remove() - class \"%s\" not found", name)) 16 | Registry.classes_[name] = nil 17 | end 18 | 19 | function Registry.exists(name) 20 | return Registry.classes_[name] ~= nil 21 | end 22 | 23 | function Registry.newObject(name, ...) 24 | local cls = Registry.classes_[name] 25 | if not cls then 26 | -- auto load 27 | pcall(function() 28 | cls = require(name) 29 | Registry.add(cls, name) 30 | end) 31 | end 32 | assert(cls ~= nil, string.format("Registry.newObject() - invalid class \"%s\"", tostring(name))) 33 | return cls.new(...) 34 | end 35 | 36 | function Registry.setObject(object, name) 37 | assert(Registry.objects_[name] == nil, string.format("Registry.setObject() - object \"%s\" already exists", tostring(name))) 38 | assert(object ~= nil, "Registry.setObject() - object \"%s\" is nil", tostring(name)) 39 | Registry.objects_[name] = object 40 | end 41 | 42 | function Registry.getObject(name) 43 | assert(Registry.objects_[name] ~= nil, string.format("Registry.getObject() - object \"%s\" not exists", tostring(name))) 44 | return Registry.objects_[name] 45 | end 46 | 47 | function Registry.removeObject(name) 48 | assert(Registry.objects_[name] ~= nil, string.format("Registry.removeObject() - object \"%s\" not exists", tostring(name))) 49 | Registry.objects_[name] = nil 50 | end 51 | 52 | function Registry.isObjectExists(name) 53 | return Registry.objects_[name] ~= nil 54 | end 55 | 56 | return Registry 57 | -------------------------------------------------------------------------------- /lib/quick/cc/components/Component.lua: -------------------------------------------------------------------------------- 1 | 2 | local Component = class("Component") 3 | 4 | function Component:ctor(name, depends) 5 | self.name_ = name 6 | self.depends_ = checktable(depends) 7 | end 8 | 9 | function Component:getName() 10 | return self.name_ 11 | end 12 | 13 | function Component:getDepends() 14 | return self.depends_ 15 | end 16 | 17 | function Component:getTarget() 18 | return self.target_ 19 | end 20 | 21 | function Component:exportMethods_(methods) 22 | self.exportedMethods_ = methods 23 | local target = self.target_ 24 | local com = self 25 | for _, key in ipairs(methods) do 26 | if not target[key] then 27 | local m = com[key] 28 | target[key] = function(__, ...) 29 | return m(com, ...) 30 | end 31 | end 32 | end 33 | return self 34 | end 35 | 36 | function Component:bind_(target) 37 | self.target_ = target 38 | for _, name in ipairs(self.depends_) do 39 | if not target:checkComponent(name) then 40 | target:addComponent(name) 41 | end 42 | end 43 | self:onBind_(target) 44 | end 45 | 46 | function Component:unbind_() 47 | if self.exportedMethods_ then 48 | local target = self.target_ 49 | for _, key in ipairs(self.exportedMethods_) do 50 | target[key] = nil 51 | end 52 | end 53 | self:onUnbind_() 54 | end 55 | 56 | function Component:onBind_() 57 | end 58 | 59 | function Component:onUnbind_() 60 | end 61 | 62 | return Component 63 | -------------------------------------------------------------------------------- /lib/quick/cc/components/ui/BasicLayoutProtocol.lua: -------------------------------------------------------------------------------- 1 | 2 | local Component = cc.Component 3 | local BasicLayoutProtocol = class("BasicLayoutProtocol", Component) 4 | 5 | local MAX = 999999 6 | 7 | function BasicLayoutProtocol:ctor() 8 | BasicLayoutProtocol.super.ctor(self, "BasicLayoutProtocol") 9 | end 10 | 11 | function BasicLayoutProtocol:getLayoutSize() 12 | if self.layoutSize_ then 13 | return self.layoutSize_.width, self.layoutSize_.height 14 | else 15 | if self.target_.getCascadeBoundingBox then 16 | local size = self.target_:getCascadeBoundingBox().size 17 | return size.width, size.height 18 | else 19 | return 0, 0 20 | end 21 | end 22 | end 23 | 24 | function BasicLayoutProtocol:setLayoutSize(width, height) 25 | if width == 0 and height == 0 then 26 | self.layoutSize_ = nil 27 | else 28 | self.layoutSize_ = {width = checknumber(width), height = checknumber(height)} 29 | end 30 | return self.target_ 31 | end 32 | 33 | function BasicLayoutProtocol:getLayoutMinSize() 34 | return self.minSize_.width, self.minSize_.height 35 | end 36 | 37 | function BasicLayoutProtocol:setLayoutMinSize(width, height) 38 | self.minSize_.width = checknumber(width) 39 | self.minSize_.height = checknumber(height) 40 | return self.target_ 41 | end 42 | 43 | function BasicLayoutProtocol:getLayoutMaxSize() 44 | return self.maxSize_.width, self.maxSize_.height 45 | end 46 | 47 | function BasicLayoutProtocol:setLayoutMaxSize(width, height) 48 | self.maxSize_.width = checknumber(width) 49 | self.maxSize_.height = checknumber(height) 50 | return self.target_ 51 | end 52 | 53 | function BasicLayoutProtocol:getLayoutSizePolicy() 54 | return self.sizePolicy_.horizontal, self.sizePolicy_.vertical 55 | end 56 | 57 | local function checkSizePolicy(p) 58 | if p ~= display.AUTO_SIZE and p ~= display.FIXED_SIZE then 59 | printError("BasicLayoutProtocol - invalid size policy") 60 | return display.AUTO_SIZE 61 | else 62 | return p 63 | end 64 | end 65 | 66 | function BasicLayoutProtocol:setLayoutSizePolicy(horizontal, vertical) 67 | self.sizePolicy_.horizontal = checkSizePolicy(horizontal) 68 | self.sizePolicy_.vertical = checkSizePolicy(vertical) 69 | return self.target_ 70 | end 71 | 72 | function BasicLayoutProtocol:getLayoutPadding() 73 | return self.padding_.top, self.padding_.right, self.padding_.bottom, self.padding_.left 74 | end 75 | 76 | function BasicLayoutProtocol:setLayoutPadding(top, right, bottom, left) 77 | self.padding_.top = checknumber(top) 78 | self.padding_.right = checknumber(right) 79 | self.padding_.bottom = checknumber(bottom) 80 | self.padding_.left = checknumber(left) 81 | return self.target_ 82 | end 83 | 84 | function BasicLayoutProtocol:getLayoutMargin() 85 | return self.margin_.top, self.margin_.right, self.margin_.bottom, self.margin_.left 86 | end 87 | 88 | function BasicLayoutProtocol:setLayoutMargin(top, right, bottom, left) 89 | self.margin_.top = checknumber(top) 90 | self.margin_.right = checknumber(right) 91 | self.margin_.bottom = checknumber(bottom) 92 | self.margin_.left = checknumber(left) 93 | return self.target_ 94 | end 95 | 96 | function BasicLayoutProtocol:exportMethods() 97 | self:exportMethods_({ 98 | "getLayoutSize", 99 | "setLayoutSize", 100 | "getLayoutMinSize", 101 | "setLayoutMinSize", 102 | "getLayoutMaxSize", 103 | "setLayoutMaxSize", 104 | "getLayoutSizePolicy", 105 | "setLayoutSizePolicy", 106 | "getLayoutPadding", 107 | "setLayoutPadding", 108 | "getLayoutMargin", 109 | "setLayoutMargin", 110 | }) 111 | return self.target_ 112 | end 113 | 114 | function BasicLayoutProtocol:onBind_() 115 | self.layoutSize_ = nil 116 | self.minSize_ = {width = 0, height = 0} 117 | self.maxSize_ = {width = MAX, height = MAX} 118 | self.sizePolicy_ = {h = display.PREFERRED_SIZE, v = display.PREFERRED_SIZE} 119 | self.padding_ = {top = 0, right = 0, bottom = 0, left = 0} 120 | self.margin_ = {top = 0, right = 0, bottom = 0, left = 0} 121 | end 122 | 123 | function BasicLayoutProtocol:onUnbind_() 124 | end 125 | 126 | return BasicLayoutProtocol 127 | -------------------------------------------------------------------------------- /lib/quick/cc/components/ui/DraggableProtocol.lua: -------------------------------------------------------------------------------- 1 | 2 | local Component = cc.Component 3 | local DraggableProtocol = class("DraggableProtocol", Component) 4 | 5 | function DraggableProtocol:ctor() 6 | DraggableProtocol.super.ctor(self, "DraggableProtocol") 7 | end 8 | 9 | function DraggableProtocol:setDraggableEnable(bEnable) 10 | if bEnable then 11 | self.target_:setTouchEnabled(true) 12 | self.target_:addNodeEventListener(cc.NODE_TOUCH_EVENT, function (event) 13 | return self:dragOnTouch_(event) 14 | end) 15 | else 16 | self.target_:setTouchEnabled(false) 17 | end 18 | 19 | return self.target_ 20 | end 21 | 22 | function DraggableProtocol:exportMethods() 23 | self:exportMethods_({ 24 | "setDraggableEnable", 25 | }) 26 | 27 | return self.target_ 28 | end 29 | 30 | function DraggableProtocol:dragOnTouch_(event) 31 | local boundingBox = self.target_:getCascadeBoundingBox() 32 | 33 | if "began" == event.name and not cc.rectContainsPoint(boundingBox, cc.p(event.x, event.y)) then 34 | printInfo("DraggableProtocol - touch didn't in viewRect") 35 | return false 36 | end 37 | 38 | if "began" == event.name then 39 | return true 40 | elseif "moved" == event.name then 41 | local posX, posY = self.target_:getPosition() 42 | self.target_:setPosition( 43 | posX + event.x - event.prevX, 44 | posY + event.y - event.prevY) 45 | elseif "ended" == event.name then 46 | end 47 | end 48 | 49 | return DraggableProtocol 50 | -------------------------------------------------------------------------------- /lib/quick/cc/components/ui/LayoutProtocol.lua: -------------------------------------------------------------------------------- 1 | 2 | local BasicLayoutProtocol = import(".BasicLayoutProtocol") 3 | local LayoutProtocol = class("LayoutProtocol", BasicLayoutProtocol) 4 | 5 | function LayoutProtocol:ctor() 6 | LayoutProtocol.super.ctor(self, "LayoutProtocol") 7 | end 8 | 9 | function LayoutProtocol:setLayoutSize(width, height) 10 | LayoutProtocol.super.setLayoutSize(self, width, height) 11 | self:setLayout(self.layout_) 12 | return self.target_ 13 | end 14 | 15 | function LayoutProtocol:setLayout(layout) 16 | self.layout_ = layout 17 | if layout then 18 | layout:apply(self.target_) 19 | end 20 | return self.target_ 21 | end 22 | 23 | function LayoutProtocol:getLayout() 24 | return self.layout_ 25 | end 26 | 27 | function LayoutProtocol:exportMethods() 28 | LayoutProtocol.super.exportMethods(self) 29 | self:exportMethods_({ 30 | "setLayout", 31 | "getLayout", 32 | }) 33 | return self.target_ 34 | end 35 | 36 | return LayoutProtocol 37 | -------------------------------------------------------------------------------- /lib/quick/cc/init.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | --[[-- 26 | 27 | 初始化 cc 扩展 28 | 29 | cc 扩展在 cocos2dx C++ API 和 quick 基本模块的基础上,提供了符合脚本风格的事件接口、组件架构等扩展。 30 | 31 | ]] 32 | 33 | local CURRENT_MODULE_NAME = ... 34 | 35 | -- init base classes 36 | cc.Registry = import(".Registry") 37 | cc.GameObject = import(".GameObject") 38 | cc.EventProxy = import(".EventProxy") 39 | cc.Component = import(".components.Component") 40 | 41 | -- init components 42 | local components = { 43 | "components.behavior.StateMachine", 44 | "components.behavior.EventProtocol", 45 | "components.ui.BasicLayoutProtocol", 46 | "components.ui.LayoutProtocol", 47 | "components.ui.DraggableProtocol", 48 | } 49 | for _, packageName in ipairs(components) do 50 | cc.Registry.add(import("." .. packageName, CURRENT_MODULE_NAME), packageName) 51 | end 52 | 53 | -- cc = cc.GameObject.extend() 54 | local GameObject = cc.GameObject 55 | local ccmt = {} 56 | ccmt.__call = function(self, target) 57 | if target then 58 | return GameObject.extend(target) 59 | end 60 | printError("cc() - invalid target") 61 | end 62 | setmetatable(cc, ccmt) 63 | 64 | -- load MVC 65 | cc.mvc = import(".mvc.init") 66 | 67 | -- load more library 68 | cc.ui = import(".ui.init") 69 | 70 | -- load net library 71 | cc.net = import(".net.init") 72 | -------------------------------------------------------------------------------- /lib/quick/cc/mvc/AppBase.lua: -------------------------------------------------------------------------------- 1 | 2 | local AppBase = class("AppBase") 3 | 4 | AppBase.APP_ENTER_BACKGROUND_EVENT = "APP_ENTER_BACKGROUND_EVENT" 5 | AppBase.APP_ENTER_FOREGROUND_EVENT = "APP_ENTER_FOREGROUND_EVENT" 6 | 7 | function AppBase:ctor(appName, packageRoot) 8 | cc(self):addComponent("components.behavior.EventProtocol"):exportMethods() 9 | 10 | self.name = appName 11 | self.packageRoot = packageRoot or appName 12 | 13 | --[[ 14 | -- remove to Main App 15 | local eventDispatcher = cc.Director:getInstance():getEventDispatcher() 16 | local customListenerBg = cc.EventListenerCustom:create(AppBase.APP_ENTER_BACKGROUND_EVENT, 17 | handler(self, self.onEnterBackground)) 18 | eventDispatcher:addEventListenerWithFixedPriority(customListenerBg, 1) 19 | local customListenerFg = cc.EventListenerCustom:create(AppBase.APP_ENTER_FOREGROUND_EVENT, 20 | handler(self, self.onEnterForeground)) 21 | eventDispatcher:addEventListenerWithFixedPriority(customListenerFg, 1) 22 | ]] 23 | 24 | self.snapshots_ = {} 25 | 26 | -- set global app 27 | _G[self.name] = self 28 | end 29 | 30 | function AppBase:run() 31 | end 32 | 33 | function AppBase:exit() 34 | cc.Director:getInstance():endToLua() 35 | if device.platform == "windows" or device.platform == "mac" then 36 | os.exit() 37 | end 38 | end 39 | 40 | function AppBase:enterScene(sceneName, args, transitionType, time, more) 41 | local scene = self:ci(sceneName, args) 42 | display.replaceScene(scene, transitionType, time, more) 43 | end 44 | 45 | -- Import a class form this package 46 | function AppBase:import(className) 47 | if not string.find(className, self.packageRoot .. '.') then 48 | className = self.packageRoot .. '.' .. className 49 | end 50 | return require(className) 51 | end 52 | 53 | --- Create Instance 54 | function AppBase:ci(className, ...) 55 | return self:import(className).new(...) 56 | end 57 | 58 | function AppBase:makeLuaVMSnapshot() 59 | self.snapshots_[#self.snapshots_ + 1] = LuaStackSnapshot() 60 | while #self.snapshots_ > 2 do 61 | table.remove(self.snapshots_, 1) 62 | end 63 | 64 | return self 65 | end 66 | 67 | function AppBase:checkLuaVMLeaks() 68 | assert(#self.snapshots_ >= 2, "AppBase:checkLuaVMLeaks() - need least 2 snapshots") 69 | local s1 = self.snapshots_[1] 70 | local s2 = self.snapshots_[2] 71 | for k, v in pairs(s2) do 72 | if s1[k] == nil then 73 | print(k, v) 74 | end 75 | end 76 | 77 | return self 78 | end 79 | 80 | --[[ 81 | function AppBase:onEnterBackground() 82 | self:dispatchEvent({name = AppBase.APP_ENTER_BACKGROUND_EVENT}) 83 | end 84 | 85 | function AppBase:onEnterForeground() 86 | self:dispatchEvent({name = AppBase.APP_ENTER_FOREGROUND_EVENT}) 87 | end 88 | ]] 89 | 90 | return AppBase 91 | -------------------------------------------------------------------------------- /lib/quick/cc/mvc/CtrlBase.lua: -------------------------------------------------------------------------------- 1 | --- CtrlBase is C in the MVC 2 | -- @author zrong 3 | -- Creation: 2014-11-25 4 | 5 | local CtrlBase = class("CtrlBase") 6 | 7 | function CtrlBase:ctor(view, name, parent) 8 | assert(view, "Provide a legal view please!") 9 | -- view 一般是一个可视对象的实例,例如:CCNode/CCLayer/CCScene 10 | -- 但 view 也可以是任何对象。例如可以对一个 service 或者一个 model 使用 ctrl 11 | self._view = view 12 | self._name = name or self.__cname 13 | self._parent = parent 14 | self:_addParent() 15 | self:_registerEvents() 16 | printInfo("CtrlBase ctor, classname:%s, instancename:%s", 17 | tostring(self.__cname), tostring(self._name)) 18 | printInfo("CtrlBase ctor, self._view:%s, self._parent:%s", 19 | tostring(self._view), tostring(self._parent)) 20 | end 21 | 22 | -- 所有注册的事件对象保存在 _eventProxy table 中。 23 | function CtrlBase:_registerEvents() 24 | if not self._eventsProxy then self._eventsProxy = {} end 25 | return self 26 | end 27 | 28 | --- 通过 cc.EventProxy 来增加事件,这样方便批量销毁事件。 29 | function CtrlBase:_addEvent(dispatcher, ename, asyncHandler, who) 30 | local proxy = self._eventsProxy[dispatcher] 31 | if not proxy then 32 | proxy = cc.EventProxy.new(dispatcher, 33 | -- 对于非 Node 对象,不将其传给 proxy 34 | ((who and who.addNodeEventListener) and who) or nil) 35 | self._eventsProxy[dispatcher] = proxy 36 | end 37 | local selfHandler = nil 38 | if who then 39 | selfHandler = handler(who, asyncHandler) 40 | else 41 | selfHandler = handler(self, asyncHandler) 42 | end 43 | proxy:addEventListener(ename, selfHandler) 44 | return self 45 | end 46 | 47 | function CtrlBase:_unregisterEvents() 48 | if self._eventsProxy then 49 | for key, proxy in pairs(self._eventsProxy) do 50 | printInfo("|CtrlBase %s _unregisterEvents", self._name) 51 | proxy:removeAllEventListeners() 52 | self._eventsProxy[key] = nil 53 | end 54 | self._eventsProxy = nil 55 | end 56 | return self 57 | end 58 | 59 | function CtrlBase:getView() 60 | return self._view 61 | end 62 | 63 | function CtrlBase:_addParent() 64 | return self 65 | end 66 | 67 | function CtrlBase:_removeParent() 68 | self._parent = nil 69 | return self 70 | end 71 | 72 | function CtrlBase:destroy() 73 | printInfo("|----CtrlBase %s destroy", self._name) 74 | printInfo("|_view:", self._view) 75 | if self._view and self._view.destroy then 76 | self._view:destroy() 77 | end 78 | self:_unregisterEvents() 79 | self:_removeParent() 80 | printInfo("|_view:", self._view) 81 | self._view = nil 82 | printInfo("|_view:", self._view) 83 | printInfo("|----CtrlBase %s destroy, done", self._name) 84 | end 85 | 86 | return CtrlBase 87 | -------------------------------------------------------------------------------- /lib/quick/cc/mvc/ModelBase.lua: -------------------------------------------------------------------------------- 1 | local ModelBase = class("ModelBase") 2 | ModelBase.idkey = "id" 3 | ModelBase.schema = { 4 | id = {"string"} 5 | } 6 | ModelBase.fields = {"id"} 7 | 8 | local function filterProperties(properties, filter) 9 | for i, field in ipairs(filter) do 10 | properties[field] = nil 11 | end 12 | end 13 | 14 | function ModelBase:ctor(properties) 15 | cc(self):addComponent("components.behavior.EventProtocol"):exportMethods() 16 | 17 | self.isModelBase_ = true 18 | if type(properties) ~= "table" then properties = {} end 19 | self:setProperties(properties) 20 | end 21 | 22 | function ModelBase:getId() 23 | local id = self[self.class.idkey .. "_"] 24 | assert(id ~= nil, string.format("%s:getId() - invalid id", self.class.__cname)) 25 | return id 26 | end 27 | 28 | function ModelBase:isValidId() 29 | local propname = self.class.idkey .. "_" 30 | local id = self[propname] 31 | return type(id) == "string" and id ~= "" 32 | end 33 | 34 | function ModelBase:setProperties(properties) 35 | assert(type(properties) == "table", string.format("%s:setProperties() - invalid properties", self.class.__cname)) 36 | 37 | for field, schema in pairs(self.class.schema) do 38 | local typ, def = schema[1], schema[2] 39 | local propname = field .. "_" 40 | 41 | local val = properties[field] 42 | if val ~= nil then 43 | if typ == "number" then val = tonumber(val) end 44 | assert(type(val) == typ, string.format("%s:setProperties() - type mismatch, %s expected %s, actual is %s", self.class.__cname, field, typ, type(val))) 45 | self[propname] = val 46 | elseif self[propname] == nil and def ~= nil then 47 | if type(def) == "table" then 48 | val = clone(def) 49 | elseif type(def) == "function" then 50 | val = def() 51 | else 52 | val = def 53 | end 54 | self[propname] = val 55 | end 56 | end 57 | 58 | return self 59 | end 60 | 61 | function ModelBase:getProperties(fields, filter) 62 | local schema = self.class.schema 63 | if type(fields) ~= "table" then fields = self.class.fields end 64 | 65 | local properties = {} 66 | for i, field in ipairs(fields) do 67 | local propname = field .. "_" 68 | local typ = schema[field][1] 69 | local val = self[propname] 70 | assert(type(val) == typ, string.format("%s:getProperties() - type mismatch, %s expected %s, actual is %s", self.class.__cname, field, typ, type(val))) 71 | properties[field] = val 72 | end 73 | 74 | if type(filter) == "table" then 75 | filterProperties(properties, filter) 76 | end 77 | 78 | return properties 79 | end 80 | 81 | return ModelBase 82 | -------------------------------------------------------------------------------- /lib/quick/cc/mvc/init.lua: -------------------------------------------------------------------------------- 1 | 2 | -- init MVC 3 | local mvc = {} 4 | 5 | mvc.AppBase = import(".AppBase") 6 | mvc.ModelBase = import(".ModelBase") 7 | mvc.CtrlBase = import(".CtrlBase") 8 | 9 | return mvc 10 | -------------------------------------------------------------------------------- /lib/quick/cc/net/init.lua: -------------------------------------------------------------------------------- 1 | --- init net package 2 | -- @author zrong(zengrong.net) 3 | -- Creation 2014-01-02 4 | local net = {} 5 | 6 | net.SocketTCP = import(".SocketTCP") 7 | 8 | return net 9 | -------------------------------------------------------------------------------- /lib/quick/cc/ui/UIGroup.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | -------------------------------- 27 | -- @module UIGroup 28 | 29 | --[[-- 30 | 31 | quick UIGroup控件 32 | 33 | ]] 34 | 35 | local UIBoxLayout = import(".UIBoxLayout") 36 | local UIImage = import(".UIImage") 37 | 38 | local UIGroup = class("UIGroup", function() 39 | return display.newNode() 40 | end) 41 | 42 | -- start -- 43 | 44 | -------------------------------- 45 | -- UIGroup构建函数 46 | -- @function [parent=#UIGroup] new 47 | 48 | -- end -- 49 | 50 | function UIGroup:ctor() 51 | makeUIControl_(self) 52 | self:setLayout(UIBoxLayout.new(display.LEFT_TO_RIGHT)) 53 | self:setLayoutSizePolicy(display.AUTO_SIZE, display.AUTO_SIZE) 54 | self:align(display.LEFT_BOTTOM) 55 | end 56 | 57 | -- start -- 58 | 59 | -------------------------------- 60 | -- 添加一个控件 61 | -- @function [parent=#UIGroup] addWidget 62 | -- @param node widget 控件 63 | -- @return UIGroup#UIGroup 64 | 65 | -- end -- 66 | 67 | function UIGroup:addWidget(widget) 68 | self:addChild(widget) 69 | self:getLayout():addWidget(widget) 70 | return self 71 | end 72 | 73 | -- start -- 74 | 75 | -------------------------------- 76 | -- 触摸监听函数 77 | -- @function [parent=#UIGroup] onTouch 78 | -- @param function listener 函数 79 | -- @return UIGroup#UIGroup 80 | 81 | -- end -- 82 | 83 | function UIGroup:onTouch(listener) 84 | if not listener then listener = function() return true end end 85 | if USE_DEPRECATED_EVENT_ARGUMENTS then 86 | self:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event) 87 | return listener(event.name, event.x, event.y, event.prevX, event.prevY) 88 | end) 89 | else 90 | self:addNodeEventListener(cc.NODE_TOUCH_EVENT, listener) 91 | end 92 | return self 93 | end 94 | 95 | -- start -- 96 | 97 | -------------------------------- 98 | -- 打开触摸功能 99 | -- @function [parent=#UIGroup] enableTouch 100 | -- @param boolean enabled 101 | -- @return UIGroup#UIGroup 102 | 103 | -- end -- 104 | 105 | function UIGroup:enableTouch(enabled) 106 | self:setTouchEnabled(enabled) 107 | return self 108 | end 109 | 110 | -- start -- 111 | 112 | -------------------------------- 113 | -- 设置大小 114 | -- @function [parent=#UIGroup] setLayoutSize 115 | -- @param number width 116 | -- @param number height 117 | -- @return UIGroup#UIGroup 118 | 119 | -- end -- 120 | 121 | function UIGroup:setLayoutSize(width, height) 122 | self:getComponent("components.ui.LayoutProtocol"):setLayoutSize(width, height) 123 | if self.backgroundSprite_ then 124 | self.backgroundSprite_:setLayoutSize(self:getLayoutSize()) 125 | end 126 | return self 127 | end 128 | 129 | -- start -- 130 | 131 | -------------------------------- 132 | -- 设置背景图片 133 | -- @function [parent=#UIGroup] setBackgroundImage 134 | -- @param string filename 图片名 135 | -- @param table args 图片控件的参数表 136 | -- @return UIGroup#UIGroup 137 | -- @see UIImage 138 | 139 | -- end -- 140 | 141 | function UIGroup:setBackgroundImage(filename, args) 142 | self.backgroundSprite_ = UIImage.new(filename, args):setLayoutSize(self:getLayoutSize()) 143 | self:addChild(self.backgroundSprite_) 144 | return self 145 | end 146 | 147 | function UIGroup:clone_() 148 | reAddUIComponent_(self) 149 | end 150 | 151 | return UIGroup 152 | -------------------------------------------------------------------------------- /lib/quick/cc/ui/UIImage.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | -------------------------------- 27 | -- @module UIImage 28 | 29 | --[[-- 30 | 31 | quick UIImage控件 32 | 33 | ]] 34 | 35 | local UIImage = class("UIImage", function(filename, options) 36 | if options and options.scale9 then 37 | return display.newScale9Sprite(filename, nil, nil, nil, options.capInsets) 38 | else 39 | return display.newSprite(filename) 40 | end 41 | end) 42 | 43 | -- start -- 44 | 45 | -------------------------------- 46 | -- UIImage构建函数 47 | -- @function [parent=#UIImage] new 48 | -- @param string filename 图片文件名 49 | -- @param table options 参数表 50 | 51 | -- end -- 52 | 53 | function UIImage:ctor(filename, options) 54 | makeUIControl_(self) 55 | self:align(display.LEFT_BOTTOM) 56 | local contentSize = self:getContentSize() 57 | self:getComponent("components.ui.LayoutProtocol"):setLayoutSize(contentSize.width, contentSize.height) 58 | self.isScale9_ = options and options.scale9 59 | if self.isScale9_ then 60 | self:setLayoutSizePolicy(display.AUTO_SIZE, display.AUTO_SIZE) 61 | end 62 | 63 | self.args_ = {filename, options} 64 | end 65 | 66 | -- start -- 67 | 68 | -------------------------------- 69 | -- UIImage设置控件大小 70 | -- @function [parent=#UIImage] setLayoutSize 71 | -- @param number width 宽度 72 | -- @param number height 高度 73 | -- @return UIImage#UIImage 自身 74 | 75 | -- end -- 76 | 77 | function UIImage:setLayoutSize(width, height) 78 | self:getComponent("components.ui.LayoutProtocol"):setLayoutSize(width, height) 79 | local width, height = self:getLayoutSize() 80 | local top, right, bottom, left = self:getLayoutPadding() 81 | width = width - left - right 82 | height = height - top - bottom 83 | 84 | if self.isScale9_ then 85 | self:setContentSize(cc.size(width, height)) 86 | else 87 | local boundingSize = self:getBoundingBox() 88 | local sx = width / (boundingSize.width / self:getScaleX()) 89 | local sy = height / (boundingSize.height / self:getScaleY()) 90 | if sx > 0 and sy > 0 then 91 | self:setScaleX(sx) 92 | self:setScaleY(sy) 93 | end 94 | end 95 | 96 | if self.layout_ then 97 | self:setLayout(self.layout_) 98 | end 99 | 100 | return self 101 | end 102 | 103 | function UIImage:createCloneInstance_() 104 | return UIImage.new(unpack(self.args_)) 105 | end 106 | 107 | function UIImage:copySpecialProperties_(node) 108 | self:setLayoutSize(node:getLayoutSize()) 109 | end 110 | 111 | return UIImage 112 | -------------------------------------------------------------------------------- /lib/quick/cc/ui/UILabel.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | -------------------------------- 27 | -- @module UILabel 28 | 29 | --[[-- 30 | 31 | quick UILabel控件 32 | 33 | ]] 34 | 35 | local UILabel 36 | UILabel = class("UILabel", function(options) 37 | if not options then 38 | return 39 | end 40 | 41 | if 1 == options.UILabelType then 42 | return UILabel.newBMFontLabel_(options) 43 | elseif not options.UILabelType or 2 == options.UILabelType then 44 | return UILabel.newTTFLabel_(options) 45 | else 46 | printInfo("UILabel unkonw UILabelType") 47 | end 48 | end) 49 | 50 | UILabel.LABEL_TYPE_BM = 1 51 | UILabel.LABEL_TYPE_TTF = 2 52 | 53 | 54 | -- start -- 55 | 56 | -------------------------------- 57 | -- UILabel构建函数 58 | -- @function [parent=#UILabel] new 59 | -- @param table options 参数表 60 | 61 | -- end -- 62 | 63 | function UILabel:ctor(options) 64 | makeUIControl_(self) 65 | self:setLayoutSizePolicy(display.FIXED_SIZE, display.FIXED_SIZE) 66 | 67 | self:align(display.LEFT_CENTER) 68 | 69 | self.args_ = {options} 70 | end 71 | 72 | -- start -- 73 | 74 | -------------------------------- 75 | -- UILabel设置控件大小 76 | -- @function [parent=#UILabel] setLayoutSize 77 | -- @param number width 宽度 78 | -- @param number height 高度 79 | -- @return UILabel#UILabel 自身 80 | 81 | -- end -- 82 | 83 | function UILabel:setLayoutSize(width, height) 84 | self:getComponent("components.ui.LayoutProtocol"):setLayoutSize(width, height) 85 | return self 86 | end 87 | 88 | function UILabel:createCloneInstance_() 89 | return UILabel.new(unpack(self.args_)) 90 | end 91 | 92 | function UILabel:copyClonedWidgetChildren_(node) 93 | 94 | end 95 | 96 | -- private 97 | 98 | --[[-- 99 | 100 | 用位图字体创建文本显示对象,并返回 LabelBMFont 对象。 101 | 102 | BMFont 通常用于显示英文内容,因为英文字母加数字和常用符号也不多,生成的 BMFont 文件较小。如果是中文,应该用 TTFLabel。 103 | 104 | 可用参数: 105 | 106 | - text: 要显示的文本 107 | - font: 字体文件名 108 | - align: 文字的水平对齐方式(可选) 109 | - x, y: 坐标(可选) 110 | 111 | ~~~ lua 112 | 113 | local label = UILabel:newBMFontLabel({ 114 | text = "Hello", 115 | font = "UIFont.fnt", 116 | }) 117 | 118 | ~~~ 119 | 120 | @param table params 参数表格对象 121 | 122 | @return LabelBMFont LabelBMFont对象 123 | 124 | ]] 125 | function UILabel.newBMFontLabel_(params) 126 | return display.newBMFontLabel(params) 127 | end 128 | 129 | --[[-- 130 | 131 | 使用 TTF 字体创建文字显示对象,并返回 Label 对象。 132 | 133 | 可用参数: 134 | 135 | - text: 要显示的文本 136 | - font: 字体名,如果是非系统自带的 TTF 字体,那么指定为字体文件名 137 | - size: 文字尺寸,因为是 TTF 字体,所以可以任意指定尺寸 138 | - color: 文字颜色(可选),用 cc.c3b() 指定,默认为白色 139 | - align: 文字的水平对齐方式(可选) 140 | - valign: 文字的垂直对齐方式(可选),仅在指定了 dimensions 参数时有效 141 | - dimensions: 文字显示对象的尺寸(可选),使用 cc.size() 指定 142 | - x, y: 坐标(可选) 143 | 144 | align 和 valign 参数可用的值: 145 | 146 | - cc.ui.TEXT_ALIGN_LEFT 左对齐 147 | - cc.ui.TEXT_ALIGN_CENTER 水平居中对齐 148 | - cc.ui.TEXT_ALIGN_RIGHT 右对齐 149 | - cc.ui.TEXT_VALIGN_TOP 垂直顶部对齐 150 | - cc.ui.TEXT_VALIGN_CENTER 垂直居中对齐 151 | - cc.ui.TEXT_VALIGN_BOTTOM 垂直底部对齐 152 | 153 | ~~~ lua 154 | 155 | -- 创建一个居中对齐的文字显示对象 156 | local label = UILabel:newTTFLabel({ 157 | text = "Hello, World", 158 | font = "Marker Felt", 159 | size = 64, 160 | align = cc.ui.TEXT_ALIGN_CENTER -- 文字内部居中对齐 161 | }) 162 | 163 | -- 左对齐,并且多行文字顶部对齐 164 | local label = UILabel:newTTFLabel({ 165 | text = "Hello, World\n您好,世界", 166 | font = "Arial", 167 | size = 64, 168 | color = cc.c3b(255, 0, 0), -- 使用纯红色 169 | align = cc.ui.TEXT_ALIGN_LEFT, 170 | valign = cc.ui.TEXT_VALIGN_TOP, 171 | dimensions = cc.size(400, 200) 172 | }) 173 | 174 | ~~~ 175 | 176 | @param table params 参数表格对象 177 | 178 | @return LabelTTF LabelTTF对象 179 | 180 | ]] 181 | function UILabel.newTTFLabel_(params) 182 | return display.newTTFLabel(params) 183 | end 184 | 185 | return UILabel 186 | -------------------------------------------------------------------------------- /lib/quick/cc/ui/UIPageViewItem.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | -------------------------------- 27 | -- @module UIPageViewItem 28 | 29 | --[[-- 30 | 31 | quick 页面控件项 32 | 33 | ]] 34 | 35 | local UIPageViewItem = class("UIPageViewItem", function() 36 | return display.newNode() 37 | end) 38 | 39 | function UIPageViewItem:ctor() 40 | end 41 | 42 | return UIPageViewItem 43 | -------------------------------------------------------------------------------- /lib/quick/cc/ui/UIPushButton.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | -------------------------------- 27 | -- @module UIPushButton 28 | 29 | --[[-- 30 | 31 | quick 按钮控件 32 | 33 | ]] 34 | 35 | local UIButton = import(".UIButton") 36 | local UIPushButton = class("UIPushButton", UIButton) 37 | 38 | UIPushButton.NORMAL = "normal" 39 | UIPushButton.PRESSED = "pressed" 40 | UIPushButton.DISABLED = "disabled" 41 | 42 | -- start -- 43 | 44 | -------------------------------- 45 | -- 按钮控件构建函数 46 | -- @function [parent=#UIPushButton] ctor 47 | -- @param table images 各种状态的图片 48 | -- @param table options 参数表 其中scale9为是否缩放 49 | 50 | --[[-- 51 | 52 | 按钮控件构建函数 53 | 54 | 状态值: 55 | - normal 正常状态 56 | - pressed 按下状态 57 | - disabled 无效状态 58 | 59 | ]] 60 | -- end -- 61 | 62 | function UIPushButton:ctor(images, options) 63 | UIPushButton.super.ctor(self, { 64 | {name = "disable", from = {"normal", "pressed"}, to = "disabled"}, 65 | {name = "enable", from = {"disabled"}, to = "normal"}, 66 | {name = "press", from = "normal", to = "pressed"}, 67 | {name = "release", from = "pressed", to = "normal"}, 68 | }, "normal", options) 69 | if type(images) ~= "table" then images = {normal = images} end 70 | self:setButtonImage(UIPushButton.NORMAL, images["normal"], true) 71 | self:setButtonImage(UIPushButton.PRESSED, images["pressed"], true) 72 | self:setButtonImage(UIPushButton.DISABLED, images["disabled"], true) 73 | 74 | self.args_ = {images, options} 75 | end 76 | 77 | function UIPushButton:setButtonImage(state, image, ignoreEmpty) 78 | assert(state == UIPushButton.NORMAL 79 | or state == UIPushButton.PRESSED 80 | or state == UIPushButton.DISABLED, 81 | string.format("UIPushButton:setButtonImage() - invalid state %s", tostring(state))) 82 | UIPushButton.super.setButtonImage(self, state, image, ignoreEmpty) 83 | 84 | if state == UIPushButton.NORMAL then 85 | if not self.images_[UIPushButton.PRESSED] then 86 | self.images_[UIPushButton.PRESSED] = image 87 | end 88 | if not self.images_[UIPushButton.DISABLED] then 89 | self.images_[UIPushButton.DISABLED] = image 90 | end 91 | end 92 | 93 | return self 94 | end 95 | 96 | function UIPushButton:onTouch_(event) 97 | local name, x, y = event.name, event.x, event.y 98 | if name == "began" then 99 | self.touchBeganX = x 100 | self.touchBeganY = y 101 | if not self:checkTouchInSprite_(x, y) then return false end 102 | self.fsm_:doEvent("press") 103 | self:dispatchEvent({name = UIButton.PRESSED_EVENT, x = x, y = y, touchInTarget = true}) 104 | return true 105 | end 106 | 107 | -- must the begin point and current point in Button Sprite 108 | local touchInTarget = self:checkTouchInSprite_(self.touchBeganX, self.touchBeganY) 109 | and self:checkTouchInSprite_(x, y) 110 | if name == "moved" then 111 | if touchInTarget and self.fsm_:canDoEvent("press") then 112 | self.fsm_:doEvent("press") 113 | self:dispatchEvent({name = UIButton.PRESSED_EVENT, x = x, y = y, touchInTarget = true}) 114 | elseif not touchInTarget and self.fsm_:canDoEvent("release") then 115 | self.fsm_:doEvent("release") 116 | self:dispatchEvent({name = UIButton.RELEASE_EVENT, x = x, y = y, touchInTarget = false}) 117 | end 118 | else 119 | if self.fsm_:canDoEvent("release") then 120 | self.fsm_:doEvent("release") 121 | self:dispatchEvent({name = UIButton.RELEASE_EVENT, x = x, y = y, touchInTarget = touchInTarget}) 122 | end 123 | if name == "ended" and touchInTarget then 124 | self:dispatchEvent({name = UIButton.CLICKED_EVENT, x = x, y = y, touchInTarget = true}) 125 | end 126 | end 127 | end 128 | 129 | function UIPushButton:createCloneInstance_() 130 | return UIPushButton.new(unpack(self.args_)) 131 | end 132 | 133 | return UIPushButton 134 | -------------------------------------------------------------------------------- /lib/quick/cc/ui/UIStretch.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | -------------------------------- 27 | -- @module UIStretch 28 | 29 | --[[-- 30 | 31 | quick 拉伸控件 32 | 33 | ]] 34 | 35 | local UIStretch = class("UIStretch") 36 | 37 | -- start -- 38 | 39 | -------------------------------- 40 | -- quick 拉伸控件 41 | -- @function [parent=#UIStretch] new 42 | 43 | -- end -- 44 | 45 | function UIStretch:ctor() 46 | cc(self):addComponent("components.ui.LayoutProtocol"):exportMethods() 47 | self:setLayoutSizePolicy(display.AUTO_SIZE, display.AUTO_SIZE) 48 | self.position_ = {x = 0, y = 0} 49 | self.anchorPoint_ = display.ANCHOR_POINTS[display.CENTER] 50 | end 51 | 52 | -- start -- 53 | 54 | -------------------------------- 55 | -- 得到位置信息 56 | -- @function [parent=#UIStretch] getPosition 57 | -- @return number#number x 58 | -- @return number#number y 59 | 60 | -- end -- 61 | 62 | function UIStretch:getPosition() 63 | return self.position_.x, self.position_.y 64 | end 65 | 66 | -- start -- 67 | 68 | -------------------------------- 69 | -- 得到x位置信息 70 | -- @function [parent=#UIStretch] getPositionX 71 | -- @return number#number x 72 | 73 | -- end -- 74 | 75 | function UIStretch:getPositionX() 76 | return self.position_.x 77 | end 78 | 79 | -- start -- 80 | 81 | -------------------------------- 82 | -- 得到y位置信息 83 | -- @function [parent=#UIStretch] getPositionY 84 | -- @return number#number y 85 | 86 | -- end -- 87 | 88 | function UIStretch:getPositionY() 89 | return self.position_.y 90 | end 91 | 92 | -- start -- 93 | 94 | -------------------------------- 95 | -- 设置位置信息 96 | -- @function [parent=#UIStretch] setPosition 97 | -- @param number x x的位置 98 | -- @param number y y的位置 99 | 100 | -- end -- 101 | 102 | function UIStretch:setPosition(x, y) 103 | self.position_.x, self.position_.y = x, y 104 | end 105 | 106 | -- start -- 107 | 108 | -------------------------------- 109 | -- 设置x位置信息 110 | -- @function [parent=#UIStretch] setPositionX 111 | -- @param number x x的位置 112 | 113 | -- end -- 114 | 115 | function UIStretch:setPositionX(x) 116 | self.position_.x = x 117 | end 118 | 119 | -- start -- 120 | 121 | -------------------------------- 122 | -- 设置y位置信息 123 | -- @function [parent=#UIStretch] setPositionY 124 | -- @param number y y的位置 125 | 126 | -- end -- 127 | 128 | function UIStretch:setPositionY(y) 129 | self.position_.y = y 130 | end 131 | 132 | -- start -- 133 | 134 | -------------------------------- 135 | -- 得到锚点位置信息 136 | -- @function [parent=#UIStretch] getAnchorPoint 137 | -- @return table#table 位置信息 138 | 139 | -- end -- 140 | 141 | function UIStretch:getAnchorPoint() 142 | return self.anchorPoint_ 143 | end 144 | 145 | -- start -- 146 | 147 | -------------------------------- 148 | -- 设置锚点位置 149 | -- @function [parent=#UIStretch] setAnchorPoint 150 | -- @param ap 锚点 151 | 152 | -- end -- 153 | 154 | function UIStretch:setAnchorPoint(ap) 155 | self.anchorPoint_ = ap 156 | end 157 | 158 | 159 | return UIStretch 160 | -------------------------------------------------------------------------------- /lib/quick/cc/ui/init.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2011-2014 chukong-inc.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | -------------------------------- 27 | -- @module ui 28 | -- @parent_module cc 29 | 30 | --[[-- 31 | 32 | 初始化 cc.ui 扩展 33 | 34 | cc.ui 提供了一套 quick 专属的纯 lua UI控件模块 35 | 36 | ]] 37 | 38 | local c = cc 39 | local ui = {} 40 | 41 | function makeUIControl_(control) 42 | cc(control) 43 | control:addComponent("components.ui.LayoutProtocol"):exportMethods() 44 | control:addComponent("components.behavior.EventProtocol"):exportMethods() 45 | 46 | control:setCascadeOpacityEnabled(true) 47 | control:setCascadeColorEnabled(true) 48 | control:addNodeEventListener(c.NODE_EVENT, function(event) 49 | if event.name == "cleanup" then 50 | control:removeAllEventListeners() 51 | end 52 | end) 53 | end 54 | 55 | function reAddUIComponent_(control) 56 | -- control:removeComponent("components.ui.LayoutProtocol") 57 | -- control:removeComponent("components.behavior.EventProtocol") 58 | print("lua remove all node listener") 59 | -- control:removeAllNodeEventListeners() 60 | 61 | control:addComponent("components.ui.LayoutProtocol"):exportMethods() 62 | control:addComponent("components.behavior.EventProtocol"):exportMethods() 63 | 64 | print("lua add node listener") 65 | control:addNodeEventListener(c.NODE_EVENT, function(event) 66 | if event.name == "cleanup" then 67 | control:removeAllEventListeners() 68 | end 69 | end) 70 | end 71 | 72 | ui.TEXT_ALIGN_LEFT = cc.TEXT_ALIGNMENT_LEFT 73 | ui.TEXT_ALIGN_CENTER = cc.TEXT_ALIGNMENT_CENTER 74 | ui.TEXT_ALIGN_RIGHT = cc.TEXT_ALIGNMENT_RIGHT 75 | ui.TEXT_VALIGN_TOP = cc.VERTICAL_TEXT_ALIGNMENT_TOP 76 | ui.TEXT_VALIGN_CENTER = cc.VERTICAL_TEXT_ALIGNMENT_CENTER 77 | ui.TEXT_VALIGN_BOTTOM = cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM 78 | 79 | ui.UIGroup = import(".UIGroup") 80 | ui.UIImage = import(".UIImage") 81 | ui.UIPushButton = import(".UIPushButton") 82 | ui.UICheckBoxButton = import(".UICheckBoxButton") 83 | ui.UICheckBoxButtonGroup = import(".UICheckBoxButtonGroup") 84 | ui.UIInput = import(".UIInput") 85 | ui.UILabel = import(".UILabel") 86 | ui.UISlider = import(".UISlider") 87 | ui.UIBoxLayout = import(".UIBoxLayout") 88 | ui.UIScrollView = import(".UIScrollView") 89 | ui.UIListView = import(".UIListView") 90 | ui.UIPageView = import(".UIPageView") 91 | ui.UILoadingBar = import(".UILoadingBar") 92 | 93 | return ui 94 | -------------------------------------------------------------------------------- /lib/quick/cc/utils/GameState.lua: -------------------------------------------------------------------------------- 1 | 2 | local GameState = {} 3 | 4 | GameState.ERROR_INVALID_FILE_CONTENTS = -1 5 | GameState.ERROR_HASH_MISS_MATCH = -2 6 | GameState.ERROR_STATE_FILE_NOT_FOUND = -3 7 | 8 | local crypto = require(cc.PACKAGE_NAME .. ".crypto") 9 | local json = require(cc.PACKAGE_NAME .. ".json") 10 | 11 | local encodeSign = "=QP=" 12 | local stateFilename = "state.txt" 13 | local eventListener = nil 14 | local secretKey = nil 15 | 16 | local function isEncodedContents_(contents) 17 | return string.sub(contents, 1, string.len(encodeSign)) == encodeSign 18 | end 19 | 20 | local function encode_(values) 21 | local s = json.encode(values) 22 | local hash = crypto.md5(s..secretKey) 23 | local contents = json.encode({h = hash, s = s}) 24 | return encodeSign..contents 25 | end 26 | 27 | local function decode_(fileContents) 28 | local contents = string.sub(fileContents, string.len(encodeSign) + 1) 29 | local j = json.decode(contents) 30 | 31 | if type(j) ~= "table" then 32 | printError("GameState.decode_() - invalid contents") 33 | return {errorCode = GameState.ERROR_INVALID_FILE_CONTENTS} 34 | end 35 | 36 | local hash,s = j.h, j.s 37 | local testHash = crypto.md5(s..secretKey) 38 | if testHash ~= hash then 39 | printError("GameState.decode_() - hash miss match") 40 | return {errorCode = GameState.ERROR_HASH_MISS_MATCH} 41 | end 42 | 43 | local values = json.decode(s) 44 | if type(values) ~= "table" then 45 | printError("GameState.decode_() - invalid state data") 46 | return {errorCode = GameState.ERROR_INVALID_FILE_CONTENTS} 47 | end 48 | 49 | return {values = values} 50 | end 51 | 52 | ---------------------------------------- 53 | 54 | function GameState.init(eventListener_, stateFilename_, secretKey_) 55 | if type(eventListener_) ~= "function" then 56 | printError("GameState.init() - invalid eventListener") 57 | return false 58 | end 59 | 60 | eventListener = eventListener_ 61 | 62 | if type(stateFilename_) == "string" then 63 | stateFilename = stateFilename_ 64 | end 65 | 66 | if type(secretKey_) == "string" then 67 | secretKey = secretKey_ 68 | end 69 | 70 | eventListener({ 71 | name = "init", 72 | filename = GameState.getGameStatePath(), 73 | encode = type(secretKey) == "string" 74 | }) 75 | 76 | return true 77 | end 78 | 79 | function GameState.load() 80 | local filename = GameState.getGameStatePath() 81 | 82 | if not io.exists(filename) then 83 | printInfo("GameState.load() - file \"%s\" not found", filename) 84 | return eventListener({name = "load", errorCode = GameState.ERROR_STATE_FILE_NOT_FOUND}) 85 | end 86 | 87 | local contents = io.readfile(filename) 88 | printInfo("GameState.load() - get values from \"%s\"", filename) 89 | 90 | local values 91 | local encode = false 92 | 93 | if secretKey and isEncodedContents_(contents) then 94 | local d = decode_(contents) 95 | if d.errorCode then 96 | return eventListener({name = "load", errorCode = d.errorCode}) 97 | end 98 | 99 | values = d.values 100 | encode = true 101 | else 102 | values = json.decode(contents) 103 | if type(values) ~= "table" then 104 | printError("GameState.load() - invalid data") 105 | return eventListener({name = "load", errorCode = GameState.ERROR_INVALID_FILE_CONTENTS}) 106 | end 107 | end 108 | 109 | return eventListener({ 110 | name = "load", 111 | values = values, 112 | encode = encode, 113 | time = os.time() 114 | }) 115 | end 116 | 117 | function GameState.save(newValues) 118 | local values = eventListener({ 119 | name = "save", 120 | values = newValues, 121 | encode = type(secretKey) == "string" 122 | }) 123 | if type(values) ~= "table" then 124 | printError("GameState.save() - listener return invalid data") 125 | return false 126 | end 127 | 128 | local filename = GameState.getGameStatePath() 129 | local ret = false 130 | if secretKey then 131 | ret = io.writefile(filename, encode_(values)) 132 | else 133 | local s = json.encode(values) 134 | if type(s) == "string" then 135 | ret = io.writefile(filename, s) 136 | end 137 | end 138 | 139 | printInfo("GameState.save() - update file \"%s\"", filename) 140 | return ret 141 | end 142 | 143 | function GameState.getGameStatePath() 144 | return string.gsub(device.writablePath, "[\\\\/]+$", "") .. device.directorySeparator .. stateFilename 145 | end 146 | 147 | cc = cc or {} 148 | cc.utils = cc.utils or {} 149 | cc.utils.State = GameState 150 | 151 | return GameState 152 | -------------------------------------------------------------------------------- /lib/quick/cc/utils/Localize.lua: -------------------------------------------------------------------------------- 1 | 2 | local Localize = {} 3 | 4 | Localize.strings = {} 5 | 6 | function Localize.loadStrings(strings) 7 | Localize.strings = strings 8 | end 9 | 10 | function Localize.query(key, default) 11 | if not default then default = key end 12 | local lang = device.language 13 | if not Localize.strings[lang] or not Localize.strings[lang][key] then return default end 14 | return Localize.strings[lang][key] 15 | end 16 | 17 | function Localize.filename(filenameOrigin) 18 | local fi = io.pathinfo(filenameOrigin) 19 | return fi.dirname .. fi.basename .. "_" .. device.language .. fi.extname 20 | end 21 | 22 | cc = cc or {} 23 | cc.utils = cc.utils or {} 24 | cc.utils.Localize = Localize 25 | 26 | return Localize 27 | -------------------------------------------------------------------------------- /lib/quick/cc/utils/Timer.lua: -------------------------------------------------------------------------------- 1 | 2 | local scheduler = require(cc.PACKAGE_NAME .. ".scheduler") 3 | 4 | --[[-- 5 | 6 | Timer 实现了一个计时器容器,用于跟踪应用中所有需要计时的事件。 7 | 8 | ]] 9 | local Timer = {} 10 | 11 | --[[-- 12 | 13 | 创建一个计时器。 14 | 15 | **Returns:** 16 | 17 | - Timer 对象 18 | 19 | ]] 20 | function Timer.new() 21 | local timer = {} 22 | cc(timer):addComponent("components.behavior.EventProtocol"):exportMethods() 23 | 24 | ---- 25 | 26 | local handle = nil 27 | local countdowns = {} 28 | local timecount = 0 29 | 30 | ---- 31 | 32 | --[[-- 33 | @ignore 34 | ]] 35 | local function onTimer(dt) 36 | timecount = timecount + dt 37 | for eventName, cd in pairs(countdowns) do 38 | cd.countdown = cd.countdown - dt 39 | cd.nextstep = cd.nextstep - dt 40 | 41 | if cd.countdown <= 0 then 42 | print(string.format("[finish] %s", eventName)) 43 | timer:dispatchEvent({name = eventName, countdown = 0}) 44 | timer:removeCountdown(eventName) 45 | elseif cd.nextstep <= 0 then 46 | print(string.format("[step] %s", eventName)) 47 | cd.nextstep = cd.nextstep + cd.interval 48 | timer:dispatchEvent({name = eventName, countdown = cd.countdown}) 49 | end 50 | end 51 | end 52 | 53 | ---- 54 | 55 | --[[-- 56 | 57 | 添加一个计时器。 58 | 59 | 在计时器倒计时完成前,会按照 **interval** 参数指定的时间间隔触发 **eventName** 参数指定的事件。 60 | 事件参数则是倒计时还剩余的时间。 61 | 62 | 在计时器倒计时完成后,同样会触发 **eventName** 参数指定的事件。此时事件的参数是 0,表示倒计时完成。 63 | 64 | 因此在事件处理函数中,可以通过事件参数判断倒计时是否已经结束: 65 | 66 | local Timer = require("framework.cc.utils.Timer") 67 | local appTimer = Timer.new() 68 | 69 | -- 响应 CITYHALL_UPGRADE_TIMER 事件 70 | local function onCityHallUpgradeTimer(event) 71 | if event.countdown > 0 then 72 | -- 倒计时还未结束,更新用户界面上显示的时间 73 | .... 74 | else 75 | -- 倒计时已经结束,更新用户界面显示升级后的城防大厅 76 | end 77 | end 78 | 79 | -- 注册事件 80 | appTimer:addEventListener("CITYHALL_UPGRADE_TIMER", onCityHallUpgradeTimer) 81 | -- 城防大厅升级需要 3600 秒,每 30 秒更新一次界面显示 82 | appTimer:addCountdown("CITYHALL_UPGRADE_TIMER", 3600, 30) 83 | 84 | 考虑移动设备的特殊性,计时器可能存在一定误差,所以 **interval** 参数的最小值是 2 秒。 85 | 在界面上需要显示倒计时的地方,应该以“分”为单位。例如显示为“2 小时 23 分”,这样可以避免误差带来的问题。 86 | 87 | ### 注意 88 | 89 | 计时器在倒计时结束并触发事件后,会自动删除。关联到这个计时器的所有事件处理函数也会被取消。 90 | 91 | 92 | **Parameters:** 93 | 94 | - eventName: 计时器事件的名称 95 | - countdown: 倒计时(秒) 96 | - interval(可选): 检查倒计时的时间间隔,最小为 2 秒,最长为 120 秒,如果未指定则默认为 30 秒 97 | 98 | ]] 99 | function timer:addCountdown(eventName, countdown, interval) 100 | eventName = tostring(eventName) 101 | assert(not countdowns[eventName], "eventName '" .. eventName .. "' exists") 102 | assert(type(countdown) == "number" and countdown >= 30, "invalid countdown") 103 | 104 | if type(interval) ~= "number" then 105 | interval = 30 106 | else 107 | interval = math.floor(interval) 108 | if interval < 2 then 109 | interval = 2 110 | elseif interval > 120 then 111 | interval = 120 112 | end 113 | end 114 | 115 | countdowns[eventName] = { 116 | countdown = countdown, 117 | interval = interval, 118 | nextstep = interval, 119 | } 120 | end 121 | 122 | --[[-- 123 | 124 | 删除指定事件名称对应的计时器,并取消这个计时器的所有事件处理函数。 125 | 126 | **Parameters:** 127 | 128 | - eventName: 计时器事件的名称 129 | 130 | ]] 131 | function timer:removeCountdown(eventName) 132 | eventName = tostring(eventName) 133 | countdowns[eventName] = nil 134 | self:removeEventListenersByEvent(eventName) 135 | end 136 | 137 | --[[-- 138 | 139 | 启动计时器容器。 140 | 141 | 在开始游戏时调用这个方法,确保所有的计时器事件都正确触发。 142 | 143 | ]] 144 | function timer:start() 145 | if not handle then 146 | handle = scheduler.scheduleGlobal(onTimer, 1.0, false) 147 | end 148 | end 149 | 150 | --[[-- 151 | 152 | 停止计时器容器。 153 | 154 | ]] 155 | function timer:stop() 156 | if handle then 157 | scheduler.unscheduleGlobal(handle) 158 | handle = nil 159 | end 160 | end 161 | 162 | return timer 163 | end 164 | 165 | cc = cc or {} 166 | cc.utils = cc.utils or {} 167 | cc.utils.Timer = Timer 168 | 169 | return Timer 170 | -------------------------------------------------------------------------------- /lib/quick/cocos2dx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | -------------------------------- 26 | -- @module cocos2dx 27 | 28 | --[[-- 29 | 30 | 针对 cocos2d-x 的一些封装和扩展 31 | 32 | 预定义的节点事件: 33 | 34 | - cc.NODE_EVENT - enter, exit 等事件 35 | - cc.NODE_ENTER_FRAME_EVENT - 帧事件 36 | - cc.NODE_TOUCH_EVENT - 触摸事件 37 | - cc.NODE_TOUCH_CAPTURE_EVENT - 捕获触摸事件 38 | 39 | 预定义的层事件: 40 | 41 | - cc.ACCELERATE_EVENT - 重力感应事件 42 | - cc.KEYPAD_EVENT - 硬件按键事件 43 | 44 | 预定义的触摸模式: 45 | 46 | - cc.TOUCH_MODE_ALL_AT_ONCE - 多点触摸 47 | - cc.TOUCH_MODE_ONE_BY_ONE - 单点触摸 48 | 49 | ]] 50 | 51 | local p = cc.PACKAGE_NAME .. ".cocos2dx." 52 | 53 | require(p .. "Event") 54 | require(p .. "ActionEx") 55 | require(p .. "NodeEx") 56 | require(p .. "SceneEx") 57 | require(p .. "SpriteEx") 58 | require(p .. "DrawNodeEx") 59 | -------------------------------------------------------------------------------- /lib/quick/cocos2dx/DrawNodeEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | --[[-- 26 | 27 | ]] 28 | 29 | local c = cc 30 | local DrawNode = c.DrawNode 31 | 32 | local drawPolygon = DrawNode.drawPolygon 33 | function DrawNode:drawPolygon(points, params) 34 | local segments = #points 35 | local fillColor = cc.c4f(1,1,1,1) 36 | local borderWidth = 0 37 | local borderColor = cc.c4f(0,0,0,1) 38 | if params then 39 | if params.fillColor then fillColor = params.fillColor end 40 | if params.borderWidth then borderWidth = params.borderWidth end 41 | if params.borderColor then borderColor = params.borderColor end 42 | end 43 | drawPolygon(self, points, #points, fillColor, borderWidth, borderColor) 44 | return self 45 | end 46 | 47 | local drawDot = DrawNode.drawDot 48 | function DrawNode:drawDot(point, radius, color) 49 | drawDot(self, point, radius, color) 50 | return self 51 | end 52 | 53 | local drawCircle = DrawNode.drawCircle 54 | function DrawNode:drawCircle(center, radius, angle, segments, drawLineToCenter, color) 55 | drawCircle(self, center, radius, angle, segments, drawLineToCenter, color) 56 | return self 57 | end 58 | 59 | local drawSolidCircle = DrawNode.drawSolidCircle 60 | function DrawNode:drawSolidCircle(center, radius, angle, segments, color) 61 | drawSolidCircle(self, center, radius, angle, segments, color) 62 | return self 63 | end 64 | 65 | -- 绘制一个矩形边框 66 | -- @param orig 左下角坐标 cc.p 67 | -- @param dest 右上角坐标 cc.p 68 | -- @param color cc.c4f 69 | local drawRect = DrawNode.drawRect 70 | function DrawNode:drawRect(orig, dest, color) 71 | drawRect(self, orig, dest, color) 72 | return self 73 | end 74 | 75 | -- 绘制一个矩形填充 76 | -- @param orig 左下角坐标 cc.p 77 | -- @param dest 右上角坐标 cc.p 78 | -- @param color cc.c4f 79 | local drawSolidRect = DrawNode.drawSolidRect 80 | function DrawNode:drawSolidRect(orig, dest, color) 81 | drawSolidRect(self, orig, dest, color) 82 | self:setContentSize(cc.size(dest.x-orig.x, dest.y-orig.y)) 83 | return self 84 | end 85 | 86 | -- 绘制一根线 87 | -- @param orig 起始点坐标 cc.p 88 | -- @param dest 结束点坐标 cc.p 89 | -- @param color cc.c4f 90 | local drawLine = DrawNode.drawLine 91 | function DrawNode:drawLine(orig, dest, color) 92 | drawLine(self, orig, dest, color) 93 | return self 94 | end 95 | 96 | -- 绘制一根可以设置粗细的线 97 | -- @param from 起始点坐标 cc.p 98 | -- @param to 结束点坐标 cc.p 99 | -- @param radius number 100 | -- @param color cc.c4f 101 | local drawSegment = DrawNode.drawSegment 102 | function DrawNode:drawSegment(from, to, radius, color) 103 | drawSegment(self, from, to, radius, color) 104 | return self 105 | end 106 | 107 | local clear = DrawNode.clear 108 | function DrawNode:clear() 109 | clear(self) 110 | return self 111 | end 112 | -------------------------------------------------------------------------------- /lib/quick/cocos2dx/Event.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | --[[-- 26 | 27 | 定义 cocos2dx 中的事件 28 | 29 | ]] 30 | 31 | local c = cc 32 | 33 | -- cocos2dx 引擎级事件 34 | c.NODE_EVENT = 0 35 | c.NODE_ENTER_FRAME_EVENT = 1 36 | c.NODE_TOUCH_EVENT = 2 37 | c.NODE_TOUCH_CAPTURE_EVENT = 3 38 | c.MENU_ITEM_CLICKED_EVENT = 4 39 | c.ACCELERATE_EVENT = 5 40 | c.KEYPAD_EVENT = 6 41 | 42 | c.NODE_TOUCH_CAPTURING_PHASE = 0 43 | c.NODE_TOUCH_TARGETING_PHASE = 1 44 | -------------------------------------------------------------------------------- /lib/quick/cocos2dx/SceneEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local c = cc 26 | local Scene = c.Scene 27 | 28 | function Scene:setAutoCleanupEnabled() 29 | self:addNodeEventListener(c.NODE_EVENT, function(event) 30 | if event.name == "exit" then 31 | if self.autoCleanupImages_ then 32 | for imageName, v in pairs(self.autoCleanupImages_) do 33 | display.removeSpriteFrameByImageName(imageName) 34 | end 35 | self.autoCleanupImages_ = nil 36 | end 37 | end 38 | end) 39 | end 40 | 41 | function Scene:markAutoCleanupImage(imageName) 42 | if not self.autoCleanupImages_ then self.autoCleanupImages_ = {} end 43 | self.autoCleanupImages_[imageName] = true 44 | return self 45 | end 46 | -------------------------------------------------------------------------------- /lib/quick/cocos2dx/SpriteEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local c = cc 26 | local Sprite = c.Sprite 27 | 28 | function Sprite:playAnimationOnce(animation, removeWhenFinished, onComplete, delay) 29 | return transition.playAnimationOnce(self, animation, removeWhenFinished, onComplete, delay) 30 | end 31 | 32 | function Sprite:playAnimationForever(animation, delay) 33 | return transition.playAnimationForever(self, animation, delay) 34 | end 35 | 36 | -------------------------------------------------------------------------------- /lib/quick/filter.lua: -------------------------------------------------------------------------------- 1 | --- create some filters to build a FilteredSprite 2 | -- @author zrong(zengrong.net) 3 | -- Creation 2014-03-31 4 | 5 | -------------------------------- 6 | -- @module filter 7 | 8 | --[[-- 9 | 10 | 滤镜功能 11 | 12 | ]] 13 | 14 | local filter = {} 15 | 16 | local FILTERS = { 17 | -- colors 18 | GRAY = {cc.GrayFilter}, -- {r 0.299, g 0.587, b 0.114, a 0.0} or no parameters 19 | RGB = {cc.RGBFilter, 3, {1, 1, 1}}, -- {0.0~1.0, 0.0~1.0, 0.0~1.0} 20 | HUE = {cc.HueFilter, 1, {0}}, -- {-180~ 180} see photoshop 21 | BRIGHTNESS = {cc.BrightnessFilter, 1, {0}}, -- {-1.0~1.0} 22 | SATURATION = {cc.SaturationFilter, 1, {1}}, -- {0.0~2.0} 23 | CONTRAST = {cc.ContrastFilter, 1, {1}}, -- {0.0~4.0} 24 | EXPOSURE = {cc.ExposureFilter, 1, {0}}, -- {-10.0, 10.0} 25 | GAMMA = {cc.GammaFilter, 1, {1}}, -- {0.0, 3.0} 26 | HAZE = {cc.HazeFilter, 2, {0, 0}}, -- {distance -0.5~0.5, slope -0.5~0.5} 27 | SEPIA = {cc.SepiaFilter}, -- {no parameters} 28 | -- blurs 29 | GAUSSIAN_VBLUR = {cc.GaussianVBlurFilter, 1, {0}}, -- {pixel} 30 | GAUSSIAN_HBLUR = {cc.GaussianHBlurFilter, 1, {0}}, -- {pixel} 31 | ZOOM_BLUR = {cc.ZoomBlurFilter, 3, {1, 0.5, 0.5}}, -- {size, centerX, centerY} 32 | MOTION_BLUR = {cc.MotionBlurFilter, 2, {1, 0}}, -- {size, angle} 33 | -- others 34 | SHARPEN = {cc.SharpenFilter, 2, {0, 0}}, -- {sharpness, amount} 35 | MASK = {cc.MaskFilter, 1}, -- {DO NOT USE IT} 36 | DROP_SHADOW = {cc.DropShadowFilter, 1}, -- {DO NOT USE IT} 37 | -- custom 38 | CUSTOM = {cc.CustomFilter, 1} 39 | } 40 | 41 | local MULTI_FILTERS = { 42 | GAUSSIAN_BLUR = {}, 43 | } 44 | 45 | -- start -- 46 | 47 | -------------------------------- 48 | -- 创建一个滤镜效果,并返回 Filter 场景对象。 49 | -- @function [parent=#filter] newFilter 50 | -- @param string filterName 滤镜名称 51 | -- @param table param 52 | -- @return FilteredSprite#FilteredSprite ret (return value: cc.FilteredSprite) Filter的子类 53 | 54 | -- end -- 55 | 56 | function filter.newFilter(filterName, param) 57 | local filterData = FILTERS[filterName] 58 | assert(filterData, "filter.newFilter() - filter "..filterName.." is not found.") 59 | local cls, count, default = unpack(filterData) 60 | 61 | if "CUSTOM" == filterName then 62 | return cls:create(param) 63 | end 64 | 65 | local paramCount = (param and #param) or 0 66 | -- print("filter.newFilter:", paramCount, filterName, count) 67 | -- print("filter.newFilter param:", param) 68 | -- If count is nil, it means the Filter does not need a parameter. 69 | if count == nil then 70 | if paramCount == 0 then 71 | return cls:create() 72 | end 73 | elseif count == 0 then 74 | return cls:create() 75 | else 76 | if paramCount == 0 then 77 | return cls:create(unpack(default)) 78 | end 79 | assert(paramCount == count, 80 | string.format("filter.newFilter() - the parameters have a wrong amount! Expect %d, get %d.", 81 | count, paramCount)) 82 | end 83 | return cls:create(unpack(param)) 84 | end 85 | 86 | -- start -- 87 | 88 | -------------------------------- 89 | -- 创建滤镜数组,并返回 Filter 的数组对象 90 | -- @function [parent=#filter] newFilters 91 | -- @param table __filterNames 滤镜名称数组 92 | -- @param table __params 对应参数数组 93 | -- @return table#table ret (return value: table) Filter数组 94 | 95 | -- end -- 96 | 97 | function filter.newFilters(__filterNames, __params) 98 | assert(#__filterNames == #__params, 99 | "filter.newFilters() - Please ensure the filters and the parameters have the same amount.") 100 | local __filters = {} -- cc.Array:create() 101 | for i in ipairs(__filterNames) do 102 | table.insert(__filters, filter.newFilter(__filterNames[i], __params[i])) 103 | --__filters:addObject(filter.newFilter(__filterNames[i], __params[i])) 104 | end 105 | return __filters 106 | end 107 | 108 | return filter 109 | -------------------------------------------------------------------------------- /lib/quick/json.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | -------------------------------- 26 | -- @module json 27 | 28 | --[[-- 29 | 30 | JSON 编码与解码 31 | 32 | ]] 33 | local json = {} 34 | 35 | local cjson 36 | local function safeLoad() 37 | cjson = require("cjson") 38 | end 39 | 40 | if not pcall(safeLoad) then 41 | cjson = nil 42 | end 43 | 44 | -- start -- 45 | 46 | -------------------------------- 47 | -- 将表格数据编码为 JSON 字符串 48 | -- @function [parent=#json] encode 49 | -- @param table 表格对象 50 | -- @return string#string ret (return value: string) json字符串 51 | 52 | --[[-- 53 | 54 | 将表格数据编码为 JSON 字符串 55 | 56 | ~~~ lua 57 | 58 | local str = json.encode({a=1,b="ss",c={c1=1,c2=2},d={10,11},100}) 59 | echo(str) -- {"a":1,"b":"ss","c":{"c1":1,"c2":2},"d":[10,11],"1":100} 60 | local str = json.encode({1,2,"3",{10,11}}) 61 | echo(str) -- [ 1,2,"3",[10,11] ] 62 | 63 | ~~~ 64 | 65 | 注意: table作为字典使用时,整型键值将被转换为字符串键值 66 | 67 | ~~~ lua 68 | 69 | local str = json.encode({a=1,[5]=3}) 70 | echo(str) -- {"a":1,"5":3} 71 | 72 | ~~~ 73 | 74 | 注意: table所有键值为整型时,会当作数组看待,空位将转化为null 75 | 76 | ~~~ lua 77 | 78 | local str = json.encode({[3]=2,[5]=3}) 79 | echo(str) -- [null,null,2,null,3] 80 | 81 | ~~~ 82 | 83 | ]] 84 | -- end -- 85 | 86 | function json.encode(var) 87 | local status, result = pcall(cjson.encode, var) 88 | if status then return result end 89 | if DEBUG > 1 then 90 | printError("json.encode() - encoding failed: %s", tostring(result)) 91 | end 92 | end 93 | 94 | -- start -- 95 | 96 | -------------------------------- 97 | -- 将 JSON 字符串解码为表格对象 98 | -- @function [parent=#json] decode 99 | -- @param string json字符串 100 | -- @return table#table ret (return value: table) 表格对象 101 | 102 | --[[-- 103 | 104 | 将 JSON 字符串解码为表格对象 105 | 106 | ~~~ lua 107 | 108 | local json = require("framework.json") 109 | local tb = json.decode('{"a":1,"b":"ss","c":{"c1":1,"c2":2},"d":[10,11],"1":100}') 110 | dump(tb) --[ [ 111 | - "" = { 112 | - "1" = 100 113 | - "a" = 1 114 | - "b" = "ss" 115 | - "c" = { 116 | - "c1" = 1 117 | - "c2" = 2 118 | - } 119 | - "d" = { 120 | - 1 = 10 121 | - 2 = 11 122 | - } 123 | - } 124 | ] ] 125 | local tb = json.decode('[1,2,"3",[10,11] ]') 126 | dump(tb) --[ [ 127 | - "" = { 128 | - 1 = 1 129 | - 2 = 2 130 | - 3 = "3" 131 | - 4 = { 132 | - 1 = 10 133 | - 2 = 11 134 | - } 135 | - } 136 | ] ] 137 | 138 | ~~~ 139 | 140 | ]] 141 | -- end -- 142 | 143 | function json.decode(text) 144 | local status, result = pcall(cjson.decode, text) 145 | if status then return result end 146 | if DEBUG > 1 then 147 | printError("json.decode() - decoding failed: %s", tostring(result)) 148 | end 149 | end 150 | 151 | if cjson then 152 | json.null = cjson.null 153 | else 154 | json = nil 155 | end 156 | 157 | return json 158 | -------------------------------------------------------------------------------- /lib/quick/platform/android.lua: -------------------------------------------------------------------------------- 1 | 2 | if cc.bPlugin_ then 3 | luaj = require("cocos.cocos2d.luaj") 4 | else 5 | luaj = require(cc.PACKAGE_NAME .. ".luaj") 6 | end 7 | 8 | function io.exists(path) 9 | return cc.FileUtils:getInstance():isFileExist(path) 10 | end 11 | 12 | function io.readfile(path) 13 | return cc.HelperFunc:getFileData(path) 14 | end 15 | 16 | function device.showAlertAndroid(title, message, buttonLabels, listener) 17 | end 18 | -------------------------------------------------------------------------------- /lib/quick/platform/ios.lua: -------------------------------------------------------------------------------- 1 | 2 | if cc.bPlugin_ then 3 | luaoc = require("cocos.cocos2d.luaoc") 4 | else 5 | luaoc = require(cc.PACKAGE_NAME .. ".luaoc") 6 | end 7 | 8 | function device.showAlertIOS(title, message, buttonLabels, listener) 9 | end 10 | -------------------------------------------------------------------------------- /lib/quick/platform/mac.lua: -------------------------------------------------------------------------------- 1 | 2 | if cc.bPlugin_ then 3 | luaoc = require("cocos.cocos2d.luaoc") 4 | else 5 | -- luaoc = require(cc.PACKAGE_NAME .. ".luaoc") 6 | end 7 | -------------------------------------------------------------------------------- /lib/quick/scheduler.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2011-2014 chukong-inc.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | -------------------------------- 26 | -- @module scheduler 27 | 28 | 29 | --[[-- 30 | 31 | 全局计时器、计划任务 32 | 33 | «该模块在框架初始化时不会自动载入» 34 | 35 | 加载方式: local scheduler = require(cc.PACKAGE_NAME .. ".scheduler") 36 | 37 | ]] 38 | local scheduler = {} 39 | 40 | local sharedScheduler = cc.Director:getInstance():getScheduler() 41 | 42 | -- start -- 43 | 44 | -------------------------------- 45 | -- 计划一个全局帧事件回调,并返回该计划的句柄。 46 | -- @function [parent=#scheduler] scheduleUpdateGlobal 47 | -- @param function 回调函数 48 | -- @return mixed#mixed ret (return value: mixed) schedule句柄 49 | 50 | --[[-- 51 | 52 | 计划一个全局帧事件回调,并返回该计划的句柄。 53 | 54 | 全局帧事件在任何场景中都会执行,因此可以在整个应用程序范围内实现较为精确的全局计时器。 55 | 56 | 该函数返回的句柄用作 scheduler.unscheduleGlobal() 的参数,可以取消指定的计划。 57 | 58 | ]] 59 | 60 | -- end -- 61 | 62 | function scheduler.scheduleUpdateGlobal(listener) 63 | return sharedScheduler:scheduleScriptFunc(listener, 0, false) 64 | end 65 | 66 | -- start -- 67 | 68 | -------------------------------- 69 | -- 计划一个以指定时间间隔执行的全局事件回调,并返回该计划的句柄。 70 | -- @function [parent=#scheduler] scheduleGlobal 71 | -- @param function listener 回调函数 72 | -- @param number interval 间隔时间 73 | -- @return mixed#mixed ret (return value: mixed) schedule句柄 74 | 75 | --[[-- 76 | 77 | 计划一个以指定时间间隔执行的全局事件回调,并返回该计划的句柄。 78 | 79 | ~~~ lua 80 | 81 | local function onInterval(dt) 82 | end 83 | 84 | -- 每 0.5 秒执行一次 onInterval() 85 | local handle = scheduler.scheduleGlobal(onInterval, 0.5) 86 | 87 | ~~~ 88 | 89 | ]] 90 | 91 | -- end -- 92 | 93 | function scheduler.scheduleGlobal(listener, interval) 94 | return sharedScheduler:scheduleScriptFunc(listener, interval, false) 95 | end 96 | 97 | -- start -- 98 | 99 | -------------------------------- 100 | -- 取消一个全局计划 101 | -- @function [parent=#scheduler] unscheduleGlobal 102 | -- @param mixed schedule句柄 103 | 104 | --[[-- 105 | 106 | 取消一个全局计划 107 | 108 | scheduler.unscheduleGlobal() 的参数就是 scheduler.scheduleUpdateGlobal() 和 scheduler.scheduleGlobal() 的返回值。 109 | 110 | ]] 111 | 112 | -- end -- 113 | 114 | function scheduler.unscheduleGlobal(handle) 115 | sharedScheduler:unscheduleScriptEntry(handle) 116 | end 117 | 118 | -- start -- 119 | 120 | -------------------------------- 121 | -- 计划一个全局延时回调,并返回该计划的句柄。 122 | -- @function [parent=#scheduler] performWithDelayGlobal 123 | -- @param function listener 回调函数 124 | -- @param number time 延迟时间 125 | -- @return mixed#mixed ret (return value: mixed) schedule句柄 126 | 127 | --[[-- 128 | 129 | 计划一个全局延时回调,并返回该计划的句柄。 130 | 131 | scheduler.performWithDelayGlobal() 会在等待指定时间后执行一次回调函数,然后自动取消该计划。 132 | 133 | ]] 134 | 135 | -- end -- 136 | 137 | function scheduler.performWithDelayGlobal(listener, time) 138 | local handle 139 | handle = sharedScheduler:scheduleScriptFunc(function() 140 | scheduler.unscheduleGlobal(handle) 141 | listener() 142 | end, time, false) 143 | return handle 144 | end 145 | 146 | return scheduler 147 | -------------------------------------------------------------------------------- /lib/quick/zr/CaptureScreenUtil.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------ 2 | -- CaptureScreenUtil.lua 3 | -- 负责管理截图 4 | -- @author zrong 5 | -- Creation 2015-02-05 6 | ------------------------------------------ 7 | 8 | local CSU = {} 9 | local _cache = {} 10 | 11 | local FU = import('.FileUtil') 12 | local RC = import('.ResourceCache') 13 | 14 | function _retain(filename, filepath, scenename, sp) 15 | log:info('CaptureScreenUtil._retain filename: %s, filepath: %s, scenename: %s, sp: %s', filename, filepath, scenename, sp) 16 | --_release(filename) 17 | 18 | -- 保持 Sprite 避免由于没有加到舞台中而被回收 19 | sp:retain() 20 | local c = {} 21 | c.sprite = sp 22 | c.scenename = scenename 23 | c.filepath = filepath 24 | c.filename = filename 25 | _cache[filename] = c 26 | end 27 | 28 | function _release(filename) 29 | local c = _cache[filename] 30 | if c and c.sprite and c.sprite.getReferenceCount then 31 | log:info('CaptureScreenUtil._release filename: %s, sprite: %s', 32 | filename, tolua.type(c.sprite)) 33 | log:info('before release getReferenceCount %d', c.sprite:getReferenceCount()) 34 | c.sprite:release() 35 | log:info('after release c.sprite %s', c.sprite) 36 | log:info('after release c.sprite.getReferenceCount %s', c.sprite.getReferenceCount) 37 | log:info('after release getReferenceCount %d', c.sprite:getReferenceCount()) 38 | end 39 | return c 40 | end 41 | 42 | -- 截取当前屏幕,保存到 filename 43 | -- @param asyncHandler 回调函数中包含两个参数 asyncHandler(filename, sprite) 44 | -- @param filename 保存的文件名称 45 | -- @param scenename 若提供场景名称,则会建立一个 Sprite 实例, 46 | -- 在 asyncHandler 回调的时候通过第二个参数返回, 47 | -- 且会对此 Sprite 实例进行 retain 操作, 48 | -- 对此截屏用完后必须执行 clear 否则会引起内存泄露。 49 | function CSU.capture(asyncHandler, filename, scenename, filter) 50 | display.captureScreen(function(succ, filepath) 51 | -- log:info('CSU.captureScreen handler', succ, filepath) 52 | if succ then 53 | if scenename then 54 | local sp = nil 55 | if filter then 56 | sp = RC.newFilteredSprite(scenename, 57 | filepath, filter.filters, filter.params) 58 | else 59 | sp = RC.newSprite(scenename, filepath) 60 | end 61 | _retain(filename, filepath, scenename, sp) 62 | asyncHandler(filepath, sp) 63 | else 64 | asyncHandler(filepath, nil) 65 | end 66 | else 67 | asyncHandler(nil, nil) 68 | log:error('CaptureScreenUtil.capture 截屏失败!') 69 | end 70 | end, filename) 71 | end 72 | 73 | function CSU.get(filename) 74 | local c = _cache[filename] 75 | if c then 76 | return c.sprite, c.filename, c.filepath, c.scenename 77 | end 78 | return nil, nil, nil, nil 79 | end 80 | 81 | function CSU.clear(filename) 82 | local c = _release(filename) 83 | RC.removePdir(c.scenename, c.filepath) 84 | _cache[filename] = nil 85 | end 86 | 87 | return CSU 88 | -------------------------------------------------------------------------------- /lib/quick/zr/DBCCArmatureNodeEx.lua: -------------------------------------------------------------------------------- 1 | local d = db 2 | local DBCCArmatureNode = d.DBCCArmatureNode 3 | 4 | -- 返回所有可用的动画名称的字符串列表。 5 | function DBCCArmatureNode:getAnimationList() 6 | return self:getAnimation():getAnimationList() 7 | end 8 | 9 | function DBCCArmatureNode:hasAnimation(animationName) 10 | return self:getAnimation():hasAnimation(animatioinName) 11 | end 12 | 13 | function DBCCArmatureNode:getIsPlaying() 14 | return self:getAnimation():getIsPlaying() 15 | end 16 | 17 | function DBCCArmatureNode:getIsComplete() 18 | return self:getAnimation():getIsComplete() 19 | end 20 | 21 | -- 返回指定名称的 AnimationState 对象。 22 | -- 注意只有当这个名称正在播放,才可能返回。否则返回 nil。 23 | function DBCCArmatureNode:getState(name, layer) 24 | local layer = layer or 0 25 | return self:getAnimation():getState(name, layer) 26 | end 27 | 28 | -- 返回最后播放的 AnimationState 对象。 29 | function DBCCArmatureNode:getLastAnimationState() 30 | return self:getAnimation():getLastAnimationState() 31 | end 32 | 33 | -- 开始播放某个动画,返回一个 AnimationState 对象。 34 | -- 参数很多,参见 C++ 源码。 35 | function DBCCArmatureNode:gotoAndPlay(...) 36 | return self:getAnimation():gotoAndPlay(...) 37 | end 38 | 39 | -- 停止播放某个动画,返回一个 AnimationState 对象。 40 | function DBCCArmatureNode:gotoAndStop(...) 41 | return self:getAnimation():gotoAndStop(...) 42 | end 43 | 44 | -- 开始播放当前动画。 45 | function DBCCArmatureNode:play() 46 | self:getAnimation():play() 47 | return self 48 | end 49 | 50 | -- 停止播放当前动画。 51 | function DBCCArmatureNode:stop() 52 | self:getAnimation():stop() 53 | return self 54 | end 55 | 56 | -- 2015-05-08 zrong 57 | -- getBoundingBox 已经导出,不必再处理 58 | -- 为了计算相对位置,应该使用 getInnerBoundingBox 59 | --[[ 获取包围盒,返回一个 Rect 对象。 60 | function DBCCArmatureNode:getBoundingBox() 61 | return tolua.getcfunction(self, 'getBoundingBox')(self) 62 | end 63 | ]] 64 | 65 | -- 获取一个动画的 scale 值,单位秒。 66 | function DBCCArmatureNode:getAnimationScale(name) 67 | local scale = tolua.getcfunction(self, 'getAnimationScale')(self, name) 68 | if scale < 0 then return nil end 69 | return scale 70 | end 71 | 72 | -- 获取一个动画的 duration 值,单位秒。 73 | function DBCCArmatureNode:getAnimationDuration(name) 74 | local dur = tolua.getcfunction(self, 'getAnimationDuration')(self, name) 75 | if dur < 0 then return nil end 76 | return dur*0.001 77 | end 78 | -------------------------------------------------------------------------------- /lib/quick/zr/FileUtil.lua: -------------------------------------------------------------------------------- 1 | -- FileUtil 2 | -- 对C++提供的 FileUtils 进行封装,项目中必须统一使用 lua 版本。 3 | -- @author zrong 4 | -- 创建日期:2014-11-14 5 | 6 | local FU = {} 7 | 8 | local fu = cc.FileUtils:getInstance() 9 | 10 | FU.WRITEABLE_PATH = fu:getWritablePath() 11 | 12 | function FU.isDir(filename) 13 | -- char 47 = '/' 14 | return string.byte(filename, -1) == 47 15 | end 16 | 17 | function FU.isAbsolutePath(filename) 18 | return fu:isAbsolutePath(filename) 19 | end 20 | 21 | function FU.getWritablePath(filename) 22 | if filename then 23 | return FU.WRITEABLE_PATH .. filename 24 | end 25 | return FU.WRITEABLE_PATH 26 | end 27 | 28 | -- 获取一个相对路径文件的绝对路径。 29 | -- 这个文件必须相对于 res 文件夹。 30 | -- 若不提供值,则返回 res 文件夹的绝对路径。 31 | function FU.getFullPath(filename) 32 | if filename then 33 | return fu:fullPathForFilename(filename) 34 | end 35 | local resinfo = 'resinfo.lua' 36 | filename = fu:fullPathForFilename(resinfo) 37 | return string.sub(filename, 1, #filename - #resinfo) 38 | end 39 | 40 | -- 读取文件内容 41 | function FU.readFile(filename) 42 | --fullpath = RM.getFullPath(filename) 43 | local data = cc.HelperFunc:getFileData(filename) 44 | return data 45 | end 46 | 47 | -- 写入文件内容 48 | function FU.writeFile(filename, content, mode) 49 | return io.writefile(filename, content, mode) 50 | end 51 | 52 | -- filaname 可以是相对或绝对路径,目录必须以 / 结尾。 53 | function FU.exists(filename) 54 | if FU.isDir(filename) then 55 | return fu:isDirectoryExist(filename) 56 | end 57 | return fu:isFileExist(filename) 58 | end 59 | 60 | -- dirname 必须是绝对路径。目录必须以 / 结尾。 61 | function FU.mkdir(dirname) 62 | return fu:createDirectory(dirname) 63 | end 64 | 65 | -- filename 必须是绝对路径。目录必须以 / 结尾。 66 | function FU.rm(filename) 67 | if FU.isDir(filename) then 68 | fu:removeDirectory(filename) 69 | end 70 | return fu:removeFile(filename) 71 | end 72 | 73 | -- parent 是父文件夹路径,必须是绝对路径。 74 | function FU.rename(parent, old, new) 75 | return fu:renameFile(parent, old, new) 76 | end 77 | 78 | function FU.getFileSize(filename) 79 | return fu:getFileSize(filename) 80 | end 81 | 82 | return FU 83 | -------------------------------------------------------------------------------- /lib/quick/zr/FilterSpriteEx.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------- 2 | -- quick/zr/FilterSpriteEx.lua 3 | -- 扩展滤镜 Node 4 | ---------------------------------------- 5 | local c = cc 6 | local One = c.FilteredSpriteWithOne 7 | local Multi = c.FilteredSpriteWithMulti 8 | 9 | -------------------------------------------------------------------------------- /lib/quick/zr/SharedObject.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------- 2 | -- SharedObject 3 | -- 提供对本地缓存的写入和读取功能 4 | -- 5 | -- @author zrong 6 | -- 创建日期:2015-01-23 7 | -- 最后修改:2015-03-11 8 | ---------------------------------------- 9 | local SO = {} 10 | 11 | local FU = import('.FileUtil') 12 | 13 | -- 从 SO 中获取一个表 14 | function SO.getSO(fname) 15 | if not SO.exists(fname) then 16 | local err = string.format('文件 %s 不存在!', fname or 'nil') 17 | log:error(err) 18 | return nil, err 19 | end 20 | 21 | local fun, err = loadfile(SO.getPath(fname)) 22 | 23 | if not fun then 24 | local err = string.format('文件 %s 的格式错误:%s 。', fname or 'nil', err) 25 | log:error(err) 26 | SO.setEmptySO(fname) 27 | return nil, err 28 | end 29 | return fun() 30 | end 31 | 32 | -- 向 SO 中保存一个表 33 | function SO.setSO(fname, atable) 34 | if not atable then 35 | SO.setEmptySO(fname) 36 | return 37 | end 38 | local at = dump(atable, 10, 'table') 39 | table.insert(at, 1, 'local data =' ) 40 | table.insert(at, 'return data') 41 | 42 | SO.setString(fname, table.concat(at, '\n')) 43 | end 44 | 45 | -- 向 SO 中保存一个空表 46 | function SO.setEmptySO(fname) 47 | SO.setString(fname, "local data = {}\nreturn data") 48 | end 49 | 50 | -- 获取 SO 信息(以字符串形式) 51 | function SO.getString(fname) 52 | return FU.readFile(SO.getPath(fname)) 53 | end 54 | 55 | -- 写入 SO 信息(以字符串形式) 56 | function SO.setString(fname, content) 57 | if not content then content = "" end 58 | return FU.writeFile(SO.getPath(fname), content) 59 | end 60 | 61 | -- 判断 SO 是否存在 62 | function SO.exists(fname) 63 | return FU.exists(SO.getPath(fname)) 64 | end 65 | 66 | -- 获取 SO 的完整路径 67 | function SO.getPath(fname) 68 | return FU.getWritablePath(fname) 69 | end 70 | 71 | return SO 72 | -------------------------------------------------------------------------------- /lib/quick/zr/UIProgressDot.lua: -------------------------------------------------------------------------------- 1 | --- a progress bar that use dot image to exhibit percentage. 2 | -- @author zrong(zengrong.net) 3 | -- Creation 2014-01-14 4 | 5 | local UIProgressDot = class("UIProgressBar", function() 6 | return display.newNode() 7 | end) 8 | 9 | UIProgressDot._ZORDER_DOT = 0 10 | UIProgressDot._ZORDER_DOT = 0 11 | 12 | function UIProgressDot:ctor(__options) 13 | makeUIControl_(self) 14 | self:setLayoutSizePolicy(display.FIXED_SIZE, display.FIXED_SIZE) 15 | 16 | self._bgFile = __options.bg 17 | self._fgFile = __options.fg 18 | self._padding = __options.padding or 0 19 | self._amount = __options.amount or 5 20 | 21 | self._maximum = __options.max or 100 22 | self._minimum = __options.min or 0 23 | self._value = __options.value or self._maximum 24 | self._percent = self._value/(self._maximum-self._minimum) 25 | self:addScriptEventListener(cc.Event.ENTER_SCENE, function() 26 | --print("ENTER_SCENE") 27 | self:_updateImages() 28 | end) 29 | end 30 | 31 | function UIProgressDot:getValue() 32 | return self._value, self._maximum, self._minimum 33 | end 34 | 35 | function UIProgressDot:setValue(__value, __max, __min) 36 | self._value = __value 37 | if __max then self._maximum = __max end 38 | if __min then self._minimum = __min end 39 | self:_updateImages() 40 | return self 41 | end 42 | 43 | function UIProgressDot:getMaximum() 44 | return self._maximum 45 | end 46 | 47 | function UIProgressDot:setMaximum(__value) 48 | self._maximum = __value 49 | self:_updateImages() 50 | return self 51 | end 52 | 53 | function UIProgressDot:getMinimum() 54 | return self._minimum 55 | end 56 | 57 | function UIProgressDot:setMinimum(__value) 58 | self._minimum = __value 59 | self:_updateImages() 60 | return self 61 | end 62 | 63 | function UIProgressDot:_updateImages() 64 | local __lw, __lh = self:getLayoutSize() 65 | if self._value <= self._minimum then 66 | self._percent = 0 67 | else 68 | self._percent = self._value/(self._maximum-self._minimum) 69 | end 70 | local __fgDotNum = math.ceil(self._amount * self._percent) 71 | local __bgDotNum = self._amount - __fgDotNum 72 | 73 | printf("fg dot num:%d", __fgDotNum) 74 | printf("bg dot num:%d", __bgDotNum) 75 | 76 | if self._dots then 77 | for __, __dot in pairs(self._dots) do 78 | self:removeChild(__dot) 79 | end 80 | end 81 | self._dots = {} 82 | 83 | if self._fgFile then 84 | for i=1,__fgDotNum do 85 | self._dots[#self._dots+1] = display.newSprite(self._fgFile) 86 | end 87 | end 88 | if self._bgFile then 89 | for i=__fgDotNum+1,self._amount do 90 | self._dots[#self._dots+1] = display.newSprite(self._bgFile) 91 | end 92 | end 93 | for i=1,self._amount do 94 | local __dot = self._dots[i] 95 | if __dot then 96 | __dot:pos((i-1)*(__dot:getContentSize().width+self._padding), 0) 97 | :addTo(self, self._ORDER_DOT) 98 | end 99 | end 100 | end 101 | 102 | function UIProgressDot:setLayoutSize(__w, __h) 103 | self:getComponent("components.ui.LayoutProtocol"):setLayoutSize(__w, __h) 104 | local width, height = self:getLayoutSize() 105 | local top, right, bottom, left = self:getLayoutPadding() 106 | width = width - left - right 107 | height = height - top - bottom 108 | self:setContentSize(CCSize(width, height)) 109 | self:_updateImages() 110 | return self 111 | end 112 | 113 | return UIProgressDot 114 | -------------------------------------------------------------------------------- /lib/quick/zr/WebView.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------- 2 | -- 对 ccexp.WebView 进行必要的封装 3 | -- quick/zr/WebView.lua 4 | -- 5 | -- 作者:zrong 6 | -- 创建日期:2015-04-01 7 | ---------------------------------------- 8 | 9 | local isWebView = nil 10 | if device.platform == 'android' or device.platform == 'ios' then 11 | if ccexp.WebView then 12 | isWebView = true 13 | end 14 | else 15 | isWebView = false 16 | end 17 | 18 | local loadURL, loadFile, loadHTMLString, reload 19 | if isWebView then 20 | loadURL = ccexp.WebView.loadURL 21 | loadFile = ccexp.WebView.loadFile 22 | loadHTMLString = ccexp.WebView.loadHTMLString 23 | reload = ccexp.WebView.reload 24 | end 25 | 26 | local WebView = class('WebView', function() 27 | if isWebView then 28 | return ccexp.WebView:create() 29 | end 30 | return display.newNode() 31 | end) 32 | 33 | function WebView:ctor() 34 | d('WebView:ctor(), isWebView:', tostring(isWebView)) 35 | if isWebView then 36 | self:setScalesPageToFit(true) 37 | end 38 | end 39 | 40 | -- 返回自己是否是 WebView 41 | function WebView:isWebView() 42 | return isWebView 43 | end 44 | 45 | function WebView:loadURL(url) 46 | if loadURL then 47 | loadURL(self, url) 48 | end 49 | return self 50 | end 51 | 52 | function WebView:loadFile(file) 53 | if loadFile then 54 | loadFile(self, file) 55 | end 56 | return self 57 | end 58 | 59 | function WebView:loadHTMLString(str) 60 | if loadHTMLString then 61 | loadHTMLString(self, str) 62 | end 63 | return self 64 | end 65 | 66 | function WebView:reload() 67 | if reload then 68 | reload(self) 69 | end 70 | return self 71 | end 72 | 73 | return WebView 74 | -------------------------------------------------------------------------------- /lib/quick/zr/dragonbones.lua: -------------------------------------------------------------------------------- 1 | --- DragonBones 2 | -- @author zrong(zengrong.net) 3 | -- Creation 2014-07-24 4 | -- Modification 2015-05-08 5 | 6 | local dragonbones = {} 7 | 8 | dragonbones.EventType = 9 | { 10 | Z_ORDER_UPDATED = 0, 11 | ANIMATION_FRAME_EVENT = 1, 12 | BONE_FRAME_EVENT = 2, 13 | SOUND = 3, 14 | FADE_IN = 4, 15 | FADE_OUT = 5, 16 | START = 6, 17 | COMPLETE = 7, 18 | LOOP_COMPLETE = 8, 19 | FADE_IN_COMPLETE = 9, 20 | FADE_OUT_COMPLETE = 10, 21 | _ERROR = 11, 22 | } 23 | 24 | local dbFactory = db.DBCCFactory:getInstance() 25 | 26 | --- 创建一个 DBCCArmatureNode 对象 27 | -- @author zrong(zengrong.net) 28 | -- Creation:2014-10-28 29 | -- @param params 30 | -- { 31 | -- skeleton="dragon/skeleton.xml", 32 | -- texture="dragon/texture.xml", 33 | -- armatureName="Dragon", 34 | -- animationName="walk", 35 | -- skeletonName="Dragon", 36 | -- skinName="" 37 | -- } 38 | -- 下面的参数将在 dragon 文件夹中搜索 skeleton.xml 和 texture.xml 39 | -- { 40 | -- path="dragon", 41 | -- armatureName="Dragon", 42 | -- animationName="", 43 | -- skeletonName="Dragon", 44 | -- } 45 | -- 下面的参数直接在缓存中查找必要的骨骼动画数据(数据必须已经载入) 46 | -- { 47 | -- armatureName="Dragon", 48 | -- animationName="walk", 49 | -- skeletonName="Dragon", 50 | -- skinName = "" 51 | -- } 52 | function dragonbones.new(params) 53 | print('dragonbones.new params') 54 | dump(params) 55 | args = dragonbones._initParam(params) 56 | print('dragonbones.new args') 57 | dump(args) 58 | dragonbones.loadData(args) 59 | return dbFactory:buildArmatureNode(args.armatureName, args.skinName, 60 | args.animationName, args.skeletonName, args.textureName) 61 | end 62 | 63 | function dragonbones.setFactory(factory) 64 | dbFactory = factory 65 | end 66 | 67 | function dragonbones._initParam(params) 68 | if not params.animationName then 69 | params.animationName = '' 70 | end 71 | if not params.skeletonName then 72 | params.skeletonName = params.armatureName 73 | end 74 | if not params.textureName then 75 | params.textureName = params.skeletonName 76 | end 77 | if not params.skinName then 78 | params.skinName = '' 79 | end 80 | assert(params.armatureName and params.skeletonName, 81 | "armatureName and skeletonName are necessary!") 82 | return params 83 | end 84 | 85 | function dragonbones.loadData(params, initParam) 86 | local args = params 87 | if initParam then 88 | args = dragonbones._initParam(params) 89 | end 90 | if args.path then 91 | dbFactory:loadDataByDir(args.path, args.skeletonName, args.textureName) 92 | elseif args.skeleton and args.texture then 93 | dbFactory:loadData(args.skeleton, args.texture, 94 | args.skeletonName, args.textureName) 95 | end 96 | end 97 | 98 | function dragonbones.unloadData(params, initParam) 99 | local args = params 100 | if initParam then 101 | args = dragonbones._initParam(params) 102 | end 103 | dbFactory:unloadData(args.skeletonName, args.textureName) 104 | end 105 | 106 | return dragonbones 107 | -------------------------------------------------------------------------------- /lib/quick/zr/init.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------- 2 | -- Common lua library by zrong. 3 | -- 4 | -- Creation 2015-02-09 5 | ---------------------------------------- 6 | 7 | -- As same as cc.ui.init.makeUIControl_ 8 | -- but remove EventProtocol:exportMethods 9 | function makeUIControlWithoutEvent(control) 10 | cc(control) 11 | control:addComponent("components.ui.LayoutProtocol"):exportMethods() 12 | 13 | control:setCascadeOpacityEnabled(true) 14 | control:setCascadeColorEnabled(true) 15 | end 16 | 17 | --- only export EventProtocol to view 18 | function makeEventDispatcher(view) 19 | cc(view) 20 | view:addComponent("components.behavior.EventProtocol"):exportMethods() 21 | if view.addNodeEventListener then 22 | view:addNodeEventListener(cc.NODE_EVENT, function(event) 23 | if event.name == "cleanup" then 24 | view:removeAllEventListeners() 25 | end 26 | end) 27 | end 28 | end 29 | 30 | local _zr = zr or {} 31 | 32 | _zr.FileUtil = import('.FileUtil') 33 | _zr.SharedObject = import('.SharedObject') 34 | _zr.ResourceManager = import('.ResourceManager') 35 | _zr.ResourceCache = import('.ResourceCache') 36 | _zr.CaptureScreenUtil = import('.CaptureScreenUtil') 37 | _zr.dragonbones = import('.dragonbones') 38 | _zr.UIProgressBar = import('.UIProgressBar') 39 | _zr.WebView = import('.WebView') 40 | 41 | import(".DBCCArmatureNodeEx") 42 | import(".FilterSpriteEx") 43 | 44 | return _zr 45 | -------------------------------------------------------------------------------- /lib/zrong/init.lua: -------------------------------------------------------------------------------- 1 | --[[-- 2 | @author zrong 3 | @creation 2014-12-25 4 | 5 | zrong framework initialization 6 | ]] 7 | 8 | print("===========================================================") 9 | print(" LOAD ZRONG FRAMEWORK") 10 | 11 | local CURRENT_MODULE_NAME = ... 12 | 13 | zr = zr or {} 14 | zr.PACKAGE_NAME = string.sub(CURRENT_MODULE_NAME, 1, -6) 15 | 16 | require(zr.PACKAGE_NAME .. ".debug") 17 | require(zr.PACKAGE_NAME .. ".functions") 18 | require(zr.PACKAGE_NAME .. ".zr.init") 19 | print(" DONE") 20 | print("===========================================================") 21 | -------------------------------------------------------------------------------- /lib/zrong/luabit/hex.lua: -------------------------------------------------------------------------------- 1 | --[[--------------- 2 | Hex v0.4 3 | ------------------- 4 | Hex conversion lib for lua. 5 | 6 | How to use: 7 | hex.to_hex(n) -- convert a number to a hex string 8 | hex.to_dec(hex) -- convert a hex string(prefix with '0x' or '0X') to number 9 | 10 | Part of LuaBit(http://luaforge.net/projects/bit/). 11 | 12 | Under the MIT license. 13 | 14 | copyright(c) 2006~2007 hanzhao (abrash_han@hotmail.com) 15 | --]]--------------- 16 | 17 | require 'bit' 18 | 19 | do 20 | 21 | local function to_hex(n) 22 | if(type(n) ~= "number") then 23 | error("non-number type passed in.") 24 | end 25 | 26 | -- checking not float 27 | if(n - math.floor(n) > 0) then 28 | error("trying to apply bitwise operation on non-integer!") 29 | end 30 | 31 | if(n < 0) then 32 | -- negative 33 | n = bit.tobits(bit.bnot(math.abs(n)) + 1) 34 | n = bit.tonumb(n) 35 | end 36 | 37 | hex_tbl = {'A', 'B', 'C', 'D', 'E', 'F'} 38 | hex_str = "" 39 | 40 | while(n ~= 0) do 41 | last = math.mod(n, 16) 42 | if(last < 10) then 43 | hex_str = tostring(last) .. hex_str 44 | else 45 | hex_str = hex_tbl[last-10+1] .. hex_str 46 | end 47 | n = math.floor(n/16) 48 | end 49 | if(hex_str == "") then 50 | hex_str = "0" 51 | end 52 | return "0x" .. hex_str 53 | end 54 | 55 | local function to_dec(hex) 56 | if(type(hex) ~= "string") then 57 | error("non-string type passed in.") 58 | end 59 | 60 | head = string.sub(hex, 1, 2) 61 | 62 | if( head ~= "0x" and head ~= "0X") then 63 | error("wrong hex format, should lead by 0x or 0X.") 64 | end 65 | 66 | v = tonumber(string.sub(hex, 3), 16) 67 | 68 | return v; 69 | end 70 | 71 | -------------------- 72 | -- hex lib interface 73 | hex = { 74 | to_dec = to_dec, 75 | to_hex = to_hex, 76 | } 77 | 78 | end 79 | 80 | --[[ 81 | -- test 82 | d = 4341688 83 | h = to_hex(d) 84 | print(h) 85 | print(to_dec(h)) 86 | 87 | 88 | for i = 1, 100000 do 89 | h = hex.to_hex(i) 90 | d = hex.to_dec(h) 91 | if(d ~= i) then 92 | error("failed " .. i .. ", " .. h) 93 | end 94 | end 95 | --]] -------------------------------------------------------------------------------- /lib/zrong/luabit/readme.txt: -------------------------------------------------------------------------------- 1 | LuaBit 2 | ------ 3 | LuaBit is a bitwise operation lib completely written in Lua. It's 4 | written in the belief that Lua is self-contained. 5 | 6 | The supported operations are: not, and, or, xor, right shift, logic 7 | right shift and left shift. 8 | 9 | Several utilities are designed to leverage the power of bit operation: 10 | 1. hex: a dec <-> hex number converter 11 | 2. utf8: convert utf8 string to ucs2 12 | 3. noki: convert nokia pc suite backuped SMS file to .txt 13 | 14 | Under the MIT license. 15 | 16 | Visit http://luaforge.net/projects/bit/ to get latest version. 17 | 18 | Status 19 | ------ 20 | Now LuaBit is in v0.4. 21 | Release date: Mar 18, 2007 22 | 23 | Content 24 | ------- 25 | 3 files are there for LuaBit: 26 | 1) bit.lua 27 | is the bitwise operation lib, all operations are implemented here. 28 | 29 | 2) hex.lua 30 | is a helper lib for ease of using hex numbers with bitwise 31 | operation. 32 | 33 | 3) noki.lua 34 | a utility(based on bit and hex) to convert Nokia PC Suite backuped 35 | SMS to a unicode .txt file, which is more accessible than the 36 | original .nfb or .nfc file. 37 | 38 | 4) utf8.lua 39 | convert utf8 string to ucs2 string 40 | 41 | How to use 42 | ---------- 43 | Bit 44 | --- 45 | Just require 'bit' in your project and the bit lib will be 46 | available: 47 | bit.bnot(n) -- bitwise not (~n) 48 | bit.band(m, n) -- bitwise and (m & n) 49 | bit.bor(m, n) -- bitwise or (m | n) 50 | bit.bxor(m, n) -- bitwise xor (m ^ n) 51 | bit.brshift(n, bits) -- right shift (n >> bits) 52 | bit.blshift(n, bits) -- left shift (n << bits) 53 | bit.blogic_rshift(n, bits) -- logic right shift(zero fill >>>) 54 | 55 | Please note that bit.brshift and bit.blshift only support number within 56 | 32 bits. 57 | 58 | 2 utility functions are provided too: 59 | bit.tobits(n) -- convert n into a bit table(which is a 1/0 sequence) 60 | -- high bits first 61 | bit.tonumb(bit_tbl) -- convert a bit table into a number 62 | 63 | Hex 64 | --- 65 | For ease of using hex numbers, a utility hex lib is also included in 66 | LuaBit. You can require 'hex' to use them: 67 | hex.to_hex(n) -- convert a number to a hex string 68 | hex.to_dec(hex) -- convert a hex string(prefix with '0x' or '0X') to number 69 | 70 | With hex, you can write code like: 71 | bit.band(258, hex.to_dec('0xFF')) 72 | to get the lower 8 bits of 258, that's 2. 73 | 74 | Noki 75 | ---- 76 | require 'noki', to save your sms to .txt file: 77 | noki.save_sms('nokia.nfb', 'sms.txt') 78 | and you can view the output sms.txt in notepad or other editor which 79 | support unicode. 80 | 81 | Utf8 82 | ---- 83 | require 'utf8', to convert a utf8 string: 84 | ucs2_string = utf8.utf_to_uni(utf8_string) 85 | 86 | History 87 | ------- 88 | v0.4 89 | * utf8 to ucs2 converter(utf8.lua). 90 | * clean up for compatible with Lua5.1 and 5.0. 91 | * add 'How to use' section for bit.lua and hex.lua. 92 | 93 | v0.3 94 | * noki added as an application of bit. 95 | * typo correction. 96 | 97 | v0.2 98 | * add logic right shift(>>>) support: bit.blogic_rshift. 99 | * add 2 utility functions: bit.tobits and bit.tonumb. 100 | * update hex.to_hex(in hex.lua) to support negative number. 101 | 102 | v0.1 103 | LuaBit is written when I do my own game project(Fio at http://fio.edithis.info). 104 | When loading resources, I have to do some bit operation. And I do not 105 | like the embedded way of bit operation. So I decide to implement those 106 | ops in lua. And that's LuaBit. It's not as fast as the embedded one, but 107 | it works. And Lua is self-contained :-) 108 | 109 | To-Do List 110 | --------- 111 | v0.1 112 | It'll be useful if LuaBit support those bitwise op like: 113 | bit.band(258, '0xFF') 114 | ease to type and use. This will be supported in next release. 115 | 116 | v0.2 117 | I decide to delay this feature to later version for it'll mess up the 118 | interface of LuaBit. 119 | 120 | v0.3 121 | May more utility functions add to Noki - phonebook might be a nice candidate. 122 | 123 | v0.4 124 | There's no UCS2 -> UTF8 convertion now, this feature may add in next release 125 | or when the project need. 126 | 127 | Noki'll be be exluded from LuaBit in next release; I decide to let Noki grow 128 | into a powerful tool to support more Nokia PC Suite backup format(.nfb, 129 | .nfc and .nbu). 130 | 131 | Trial Noki demo at http://nokisms.googlepages.com/(in Chinese) 132 | 133 | Known issues 134 | ------------ 135 | LuaBit doesn't play very well with negative number. The return value of the 136 | bitwise operations might change to positive when applied on negative numbers 137 | though the bit sequence is correct. So if you want do some arithmetic with 138 | the result of bit operation, be careful. 139 | 140 | Feedback 141 | -------- 142 | Please send your comments, bugs, patches or change request to 143 | hanzhao(abrash_han@hotmail.com). 144 | -------------------------------------------------------------------------------- /lib/zrong/luabit/utf8.lua: -------------------------------------------------------------------------------- 1 | --[[--------------- 2 | Utf8 v0.4 3 | ------------------- 4 | utf8 -> unicode ucs2 converter 5 | 6 | How to use: 7 | to convert: 8 | ucs2_string = utf8.utf_to_uni(utf8_string) 9 | 10 | to view a string in hex: 11 | utf8.print_hex(str) 12 | 13 | Under the MIT license. 14 | 15 | Utf8 is a part of LuaBit Project(http://luaforge.net/projects/bit/). 16 | 17 | copyright(c) 2007 hanzhao (abrash_han@hotmail.com) 18 | --]]--------------- 19 | 20 | require 'hex' 21 | require 'bit' 22 | 23 | do 24 | local BYTE_1_HEAD = hex.to_dec('0x00') -- 0### #### 25 | local BYTE_2_HEAD = hex.to_dec('0xC0') -- 110# #### 26 | local BYTE_3_HEAD = hex.to_dec('0xE0') -- 1110 #### 27 | 28 | -- mask to get the head 29 | local BYTE_1_MASK = hex.to_dec('0x80') -- 1### #### 30 | local BYTE_2_MASK = hex.to_dec('0xE0') -- 111# #### 31 | local BYTE_3_MASK = hex.to_dec('0xF0') -- 1111 #### 32 | 33 | -- tail byte mask 34 | local TAIL_MASK = hex.to_dec('0x3F') -- 10## #### 35 | 36 | local mask_tbl = { 37 | BYTE_3_MASK, 38 | BYTE_2_MASK, 39 | BYTE_1_MASK, 40 | } 41 | local head_tbl = { 42 | BYTE_3_HEAD, 43 | BYTE_2_HEAD, 44 | BYTE_1_HEAD, 45 | } 46 | 47 | local len_tbl = { 48 | [BYTE_1_HEAD] = 1, 49 | [BYTE_2_HEAD] = 2, 50 | [BYTE_3_HEAD] = 3, 51 | } 52 | 53 | local function utf_read_char(utf, start) 54 | local head_byte = string.byte(utf, start) 55 | --print('head byte ' .. hex.to_hex(head_byte)) 56 | for m = 1, table.getn(mask_tbl) do 57 | local mask = mask_tbl[m] 58 | -- head match 59 | local head = bit.band(head_byte, mask) 60 | --print('head ' .. hex.to_hex(head) .. ' ' .. hex.to_hex(mask)) 61 | if(head == head_tbl[m]) then 62 | local len = len_tbl[head_tbl[m]] 63 | --print('len ' .. len) 64 | local tail_idx = start + len - 1 65 | local char = 0 66 | -- tail 67 | for i = tail_idx, start + 1, -1 do 68 | local tail_byte = string.byte(utf, i) 69 | local byte = bit.band(tail_byte, TAIL_MASK) 70 | --print('byte ' .. hex.to_hex(byte).. ' = ' .. hex.to_hex(tail_byte) .. '&'..hex.to_hex(TAIL_MASK)) 71 | if(tail_idx - i > 0) then 72 | local sft = bit.blshift(byte, (tail_idx - i) * 6) 73 | --print('shift ' .. hex.to_hex(sft) .. ' ' .. hex.to_hex(byte) .. ' ' .. ((tail_idx - i) * 6)) 74 | char = bit.bor(char, sft) 75 | --print('char ' .. hex.to_hex(char)) 76 | else 77 | char = byte 78 | end 79 | end -- tails 80 | 81 | -- add head 82 | local head_val = bit.band(head_byte, bit.bnot(mask)) 83 | --print('head val ' .. hex.to_hex(head_val)) 84 | head_val = bit.blshift(head_val, (len-1) * 6) 85 | --print('head val ' .. hex.to_hex(head_val)) 86 | char = bit.bor(head_val, char) 87 | --print('char ' .. hex.to_hex(char)) 88 | 89 | return char, len 90 | end -- if head match 91 | end -- for mask 92 | error('not find proper head mask') 93 | end 94 | 95 | local function print_hex(str) 96 | local cat = '' 97 | for i=1, string.len(str) do 98 | cat = cat .. ' ' .. hex.to_hex(string.byte(str, i)) 99 | end 100 | print(cat) 101 | end 102 | 103 | local HI_MASK = hex.to_dec('0xF0') 104 | local LO_MASK = hex.to_dec('0xFF') 105 | 106 | local function char_to_str(char) 107 | local hi, lo = bit.brshift(char, 8), bit.band(char, LO_MASK) 108 | -- print(hex.to_hex(char)..' '..hex.to_hex(hi)..' ' .. hex.to_hex(lo)) 109 | if(hi == 0) then 110 | return string.format('%c\0', lo) 111 | elseif(lo == 0) then 112 | return string.format('\0%c', hi) 113 | else 114 | return string.format('%c%c', lo, hi) 115 | end 116 | end 117 | 118 | local function utf_to_uni(utf) 119 | local n = string.len(utf) 120 | local i = 1 121 | local uni = '' 122 | while(i <= n) do 123 | --print('---') 124 | char, len = utf_read_char(utf, i) 125 | i = i + len 126 | --print(string.len(char_to_str(char))) 127 | 128 | uni = uni..char_to_str(char) 129 | end 130 | --print_hex(uni) 131 | return uni 132 | end 133 | 134 | -- interface 135 | utf8 = { 136 | utf_to_uni = utf_to_uni, 137 | print_hex = print_hex, 138 | } 139 | 140 | end 141 | 142 | --[[ 143 | -- test 144 | byte_3 = string.format('%c%c%c', hex.to_dec('0xE7'), hex.to_dec('0x83'), hex.to_dec('0xad')) 145 | print(string.len(byte_3)) 146 | utf8.utf_to_uni(byte_3) 147 | --]] 148 | --[[ 149 | byte_2 = string.format('%c%c', hex.to_dec('0xC2'), hex.to_dec('0x9D')) 150 | utf8.utf_to_uni(byte_2) 151 | 152 | byte_1 = string.format('%c', hex.to_dec('0xB')) 153 | utf8.utf_to_uni(byte_1) 154 | --]] 155 | --[[ 156 | test_mul = string.format( 157 | '%c%c%c%c%c%c%c%c%c', 158 | hex.to_dec('0xE8'),hex.to_dec('0xAF'), hex.to_dec('0xBA'), 159 | hex.to_dec('0xE5'),hex.to_dec('0x9F'), hex.to_dec('0xBA'), 160 | hex.to_dec('0xE4'),hex.to_dec('0xBA'), hex.to_dec('0x9A')) 161 | 162 | utf8.print_hex(utf8.utf_to_uni(test_mul)) 163 | --]] -------------------------------------------------------------------------------- /lib/zrong/zr/init.lua: -------------------------------------------------------------------------------- 1 | local _zr = zr or {} 2 | 3 | -- load utils library 4 | _zr.utils = import(".utils.init") 5 | 6 | -- load log library 7 | _zr.log = import(".log.init") 8 | 9 | return _zr 10 | -------------------------------------------------------------------------------- /lib/zrong/zr/log/FileHandler.lua: -------------------------------------------------------------------------------- 1 | --- A LogHandler for save log to a file. 2 | -- @author zrong 3 | -- Creation: 2014-11-14 4 | 5 | local FileHandler = class('LogHandler', import(".LogHandler")) 6 | 7 | -- @file A file to write info or a opened file handler. It must be a absolute path. 8 | -- @mode A mode for opened file, it is only available when file is a file name. 9 | -- @autoflush Default value is false。 10 | -- @starttime A timestamp that start application. Default value is nil (Do not show time). 11 | -- @gettime A function, return current time. 12 | function FileHandler:ctor(file, mode, autoflush, starttime, gettime) 13 | FileHandler.super.ctor(self, starttime, gettime) 14 | mode = mode or 'w+b' 15 | if type(file) == 'string' then 16 | self.filename = filename 17 | self._file = io.open(file, mode) 18 | else 19 | self._file = file 20 | end 21 | self._autoflush = autoflush 22 | end 23 | 24 | function FileHandler:emit(level, fmt, args) 25 | str = self:getString(level, fmt, args) 26 | self._file:write(str..'\n') 27 | if self._autoflush then 28 | self:flush() 29 | end 30 | end 31 | 32 | function FileHandler:flush() 33 | self._file:flush() 34 | end 35 | 36 | return FileHandler 37 | -------------------------------------------------------------------------------- /lib/zrong/zr/log/LogHandler.lua: -------------------------------------------------------------------------------- 1 | --- A base class for log handler. 2 | -- @author zrong 3 | -- Creation: 2014-11-14 4 | 5 | local LogHandler = class('LogHandler') 6 | 7 | local function _isfmt(fmt) 8 | return type(fmt) == 'string' and string.find(fmt, "%%") 9 | end 10 | 11 | -- @starttime 12 | -- @gettime A function, return current time. 13 | function LogHandler:ctor(starttime, gettime) 14 | self._gettime = nil 15 | self._starttime = nil 16 | if starttime then 17 | self._gettime = gettime or os.time 18 | self._starttime = (starttime == 0 and self._gettime()) or starttime 19 | end 20 | end 21 | 22 | function LogHandler:emit(level, fmt, args) 23 | end 24 | 25 | function LogHandler:flush() 26 | end 27 | 28 | function LogHandler:getString(level, fmt, args) 29 | local strlist = {} 30 | if self._starttime then 31 | strlist[#strlist+1] = string.format('[%.4f]', self._gettime()-self._starttime) 32 | end 33 | local argsnum = #args 34 | if argsnum > 0 and _isfmt(fmt) then 35 | local fmtnum = select(2, string.gsub(fmt, '%%[%a%.]', '')) 36 | if fmtnum ~= argsnum then 37 | strlist[#strlist+1] = string.format('LogHandler WARNING -- [%s] Cannot get a nil value between arguments OR you give a bad amout of arguments.', fmt) 38 | else 39 | -- Avoid error in lua 5.2 40 | local succ, err = pcall(string.format, fmt, unpack(args)) 41 | if succ then 42 | strlist[#strlist+1] = string.format(fmt, unpack(args)) 43 | else 44 | strlist[#strlist+1] = string.format('LogHandler WARNING -- [%s] %s.', fmt, err) 45 | end 46 | end 47 | elseif _isfmt(fmt) then 48 | fmt = string.gsub(fmt, '%%%a', 'nil') 49 | strlist[#strlist+1] = fmt 50 | else 51 | strlist[#strlist+1] = tostring(fmt) 52 | for i=1, argsnum do 53 | strlist[#strlist+1] = tostring(args[i]) 54 | end 55 | end 56 | return table.concat(strlist, '\t') 57 | end 58 | 59 | return LogHandler 60 | -------------------------------------------------------------------------------- /lib/zrong/zr/log/Logger.lua: -------------------------------------------------------------------------------- 1 | --- A lua log implement. 2 | -- @author zrong(zengrong.net) 3 | -- Creation: 2014-10-31 4 | 5 | local Logger = class('Logger') 6 | 7 | Logger.CRITICAL = 50 8 | Logger.ERROR = 40 9 | Logger.WARNING = 30 10 | Logger.INFO = 20 11 | Logger.DEBUG = 10 12 | Logger.NOTSET = 0 13 | 14 | function Logger:ctor(level, ...) 15 | self:setLevel(level or Logger.NOTSET) 16 | self._handlers = {...} 17 | end 18 | 19 | function Logger:setLevel(level) 20 | self._level = level 21 | end 22 | 23 | function Logger:getLevel(level) 24 | return self._level 25 | end 26 | 27 | function Logger:addHandler(logHandler) 28 | self._handlers[#self._handlers+1] = logHandler 29 | end 30 | 31 | function Logger:clearHandler() 32 | self._handlers = {} 33 | end 34 | 35 | function Logger:flush() 36 | for __, logHandler in pairs(self._handlers) do 37 | logHandler:flush() 38 | end 39 | end 40 | 41 | function Logger:log(level, fmt, ...) 42 | if level < self._level then return end 43 | args = {...} 44 | for __, logHandler in pairs(self._handlers) do 45 | logHandler:emit(level, fmt, args) 46 | end 47 | end 48 | 49 | function Logger:debug(fmt, ...) 50 | self:log(Logger.DEBUG, fmt, ...) 51 | end 52 | 53 | function Logger:info(fmt, ...) 54 | self:log(Logger.INFO, fmt, ...) 55 | end 56 | 57 | function Logger:warning(fmt, ...) 58 | self:log(Logger.WARNING, fmt, ...) 59 | end 60 | 61 | function Logger:error(fmt, ...) 62 | self:log(Logger.ERROR, fmt, ...) 63 | end 64 | 65 | function Logger:critical(fmt, ...) 66 | self:log(Logger.CRITICAL, fmt, ...) 67 | end 68 | 69 | return Logger 70 | -------------------------------------------------------------------------------- /lib/zrong/zr/log/PrintHandler.lua: -------------------------------------------------------------------------------- 1 | --- A handler for print infomation. 2 | -- @author zrong 3 | -- Creation: 2014-10-31 4 | 5 | local PrintHandler = class('PrintHandler', import(".LogHandler")) 6 | 7 | function PrintHandler:ctor(printfun, starttime, gettime) 8 | PrintHandler.super.ctor(self, starttime, gettime) 9 | self._printfun = printfun or print 10 | end 11 | 12 | function PrintHandler:emit(level, fmt, args) 13 | str = self:getString(level, fmt, args) 14 | self._printfun(str) 15 | end 16 | 17 | PrintHandler.printHandler = PrintHandler.new() 18 | 19 | return PrintHandler 20 | -------------------------------------------------------------------------------- /lib/zrong/zr/log/adapter/RestyAdapter.lua: -------------------------------------------------------------------------------- 1 | local RestyAdapter = class('RestyAdapter', import('.SocketAdapter')) 2 | 3 | function RestyAdapter:ctor(conf) 4 | RestyAdapter.super.ctor(self) 5 | local logger = require "resty.logger.socket" 6 | 7 | if not logger.initted() then 8 | local ok, err = logger.init(conf) 9 | if not ok then 10 | error("failed to initialize the RestyAdapter: ".. err) 11 | return 12 | end 13 | end 14 | self._logger = logger 15 | end 16 | 17 | function RestyAdapter:log(msg) 18 | local bytes, err = self._logger.log(msg) 19 | if err then 20 | return false, err 21 | end 22 | return true 23 | end 24 | 25 | function RestyAdapter:flush() 26 | self._logger:flush() 27 | end 28 | 29 | return RestyAdapter 30 | -------------------------------------------------------------------------------- /lib/zrong/zr/log/adapter/SocketAdapter.lua: -------------------------------------------------------------------------------- 1 | local SocketAdapter = class('SocketAdapter') 2 | 3 | function SocketAdapter:ctor() 4 | 5 | end 6 | 7 | function SocketAdapter:log(msg) 8 | return true 9 | end 10 | 11 | function SocketAdapter:flush() 12 | end 13 | 14 | return SocketAdapter 15 | -------------------------------------------------------------------------------- /lib/zrong/zr/log/init.lua: -------------------------------------------------------------------------------- 1 | local log = {} 2 | 3 | log.Logger = import(".Logger") 4 | log.LogHandler = import(".LogHandler") 5 | log.PrintHandler = import(".PrintHandler") 6 | log.FileHandler = import(".FileHandler") 7 | 8 | return log 9 | -------------------------------------------------------------------------------- /lib/zrong/zr/utils/BigNumber.lua: -------------------------------------------------------------------------------- 1 | --- via http://stackoverflow.com/questions/3104722/does-lua-make-use-of-64-bit-integers 2 | require "bit" 3 | 4 | -- Lua unsigned 64bit emulated bitwises 5 | -- Slow. But it works. 6 | 7 | function i64(v) 8 | local o = {}; o.l = v; o.h = 0; return o; 9 | end -- constructor +assign 32-bit value 10 | 11 | function i64_ax(h,l) 12 | local o = {}; o.l = l; o.h = h; return o; 13 | end -- +assign 64-bit v.as 2 regs 14 | 15 | function i64u(x) 16 | return ( ( (bit.rshift(x,1) * 2) + bit.band(x,1) ) % (0xFFFFFFFF+1)); 17 | end -- keeps [1+0..0xFFFFFFFFF] 18 | 19 | function i64_clone(x) 20 | local o = {}; o.l = x.l; o.h = x.h; return o; 21 | end -- +assign regs 22 | 23 | -- Type conversions 24 | 25 | function i64_toInt(a) 26 | return (a.l + (a.h * (0xFFFFFFFF+1))); 27 | end -- value=2^53 or even less, so better use a.l value 28 | 29 | function i64_toString(a) 30 | local s1=string.format("%x",a.l); 31 | local s2=string.format("%x",a.h); 32 | local s3="0000000000000000"; 33 | s3=string.sub(s3,1,16-string.len(s1))..s1; 34 | s3=string.sub(s3,1,8-string.len(s2))..s2..string.sub(s3,9); 35 | return "0x"..string.upper(s3); 36 | end 37 | 38 | -- Bitwise operators (the main functionality) 39 | 40 | function i64_and(a,b) 41 | local o = {}; o.l = i64u( bit.band(a.l, b.l) ); o.h = i64u( bit.band(a.h, b.h) ); return o; 42 | end 43 | 44 | function i64_or(a,b) 45 | local o = {}; o.l = i64u( bit.bor(a.l, b.l) ); o.h = i64u( bit.bor(a.h, b.h) ); return o; 46 | end 47 | 48 | function i64_xor(a,b) 49 | local o = {}; o.l = i64u( bit.bxor(a.l, b.l) ); o.h = i64u( bit.bxor(a.h, b.h) ); return o; 50 | end 51 | 52 | function i64_not(a) 53 | local o = {}; o.l = i64u( bit.bnot(a.l) ); o.h = i64u( bit.bnot(a.h) ); return o; 54 | end 55 | 56 | function i64_neg(a) 57 | return i64_add( i64_not(a), i64(1) ); 58 | end -- negative is inverted and incremented by +1 59 | 60 | -- Simple Math-functions 61 | 62 | -- just to add, not rounded for overflows 63 | function i64_add(a,b) 64 | local o = {}; 65 | o.l = a.l + b.l; 66 | local r = o.l - 0xFFFFFFFF; 67 | o.h = a.h + b.h; 68 | if( r>0 ) then 69 | o.h = o.h + 1; 70 | o.l = r-1; 71 | end 72 | return o; 73 | end 74 | 75 | -- verify a>=b before usage 76 | function i64_sub(a,b) 77 | local o = {} 78 | o.l = a.l - b.l; 79 | o.h = a.h - b.h; 80 | if( o.l<0 ) then 81 | o.h = o.h - 1; 82 | o.l = o.l + 0xFFFFFFFF+1; 83 | end 84 | return o; 85 | end 86 | 87 | -- x n-times 88 | function i64_by(a,n) 89 | local o = {}; 90 | o.l = a.l; 91 | o.h = a.h; 92 | for i=2, n, 1 do 93 | o = i64_add(o,a); 94 | end 95 | return o; 96 | end 97 | -- no divisions 98 | 99 | -- Bit-shifting 100 | 101 | function i64_lshift(a,n) 102 | local o = {}; 103 | if(n==0) then 104 | o.l=a.l; o.h=a.h; 105 | else 106 | if(n<32) then 107 | o.l= i64u( bit.lshift( a.l, n) ); o.h=i64u( bit.lshift( a.h, n) )+ bit.rshift(a.l, (32-n)); 108 | else 109 | o.l=0; o.h=i64u( bit.lshift( a.l, (n-32))); 110 | end 111 | end 112 | return o; 113 | end 114 | 115 | function i64_rshift(a,n) 116 | local o = {}; 117 | if(n==0) then 118 | o.l=a.l; o.h=a.h; 119 | else 120 | if(n<32) then 121 | o.l= bit.rshift(a.l, n)+i64u( bit.lshift(a.h, (32-n))); o.h=bit.rshift(a.h, n); 122 | else 123 | o.l=bit.rshift(a.h, (n-32)); o.h=0; 124 | end 125 | end 126 | return o; 127 | end 128 | 129 | -- Comparisons 130 | 131 | function i64_eq(a,b) 132 | return ((a.h == b.h) and (a.l == b.l)); 133 | end 134 | 135 | function i64_ne(a,b) 136 | return ((a.h ~= b.h) or (a.l ~= b.l)); 137 | end 138 | 139 | function i64_gt(a,b) 140 | return ((a.h > b.h) or ((a.h == b.h) and (a.l > b.l))); 141 | end 142 | 143 | function i64_ge(a,b) 144 | return ((a.h > b.h) or ((a.h == b.h) and (a.l >= b.l))); 145 | end 146 | 147 | function i64_lt(a,b) 148 | return ((a.h < b.h) or ((a.h == b.h) and (a.l < b.l))); 149 | end 150 | 151 | function i64_le(a,b) 152 | return ((a.h < b.h) or ((a.h == b.h) and (a.l <= b.l))); 153 | end 154 | 155 | 156 | -- samples 157 | a = i64(1); -- 1 158 | b = i64_ax(0x1,0); -- 4294967296 = 2^32 159 | a = i64_lshift(a,32); -- now i64_eq(a,b)==true 160 | print( i64_toInt(b)+1 ); -- 4294967297 161 | 162 | X = i64_ax(0x00FFF0FF, 0xFFF0FFFF); 163 | Y = i64_ax(0x00000FF0, 0xFF0000FF); 164 | 165 | -- swap algorithm 166 | X = i64_xor(X,Y); 167 | Y = i64_xor(X,Y); 168 | X = i64_xor(X,Y); 169 | 170 | print( "X="..i64_toString(X) ); -- 0x00000FF0FF0000FF 171 | print( "Y="..i64_toString(Y) ); -- 0x00FFF0FFFFF0FFFF 172 | -------------------------------------------------------------------------------- /lib/zrong/zr/utils/ByteArrayVarint.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Serialzation bytes stream use varint encoding of google protocol buffer, I implemented it in ActionScript. 3 | It depends on BitOp. 4 | A description: https://github.com/zrong/lua#ByteArrayVarint 5 | 6 | @see https://developers.google.com/protocol-buffers/docs/encoding 7 | @see https://github.com/zrong/as3/blob/master/src/org/zengrong/utils/ByteArrayVariant.as 8 | @see http://bitop.luajit.org/index.html 9 | @author zrong(zengrong.net) 10 | Creation: 2013-11-14 11 | ]] 12 | local ByteArrayVarint = class("ByteArrayVaiant", import(".ByteArray")) 13 | 14 | import('.bit') 15 | 16 | function ByteArrayVarint:ctor(__endian) 17 | self._endian = __endian 18 | self._buf = {} 19 | self._pos = 1 20 | end 21 | 22 | function ByteArrayVarint:readVInt() 23 | local __v = self:_decodeVarint() 24 | return self:_zigZagDecode(__v) 25 | end 26 | 27 | function ByteArrayVarint:writeVInt(__vint) 28 | local __v = self:_zigZagEncode(__vint) 29 | self:_encodeVarint(__v) 30 | return self 31 | end 32 | 33 | function ByteArrayVarint:readUVInt() 34 | return self:_decodeVarint() 35 | end 36 | 37 | function ByteArrayVarint:writeUVInt(__uvint) 38 | self:_encodeVarint(__uvint) 39 | return self 40 | end 41 | 42 | function ByteArrayVarint:readStringUVInt() 43 | local __len = self:readUVInt() 44 | return self:readStringBytes(__len) 45 | end 46 | 47 | function ByteArrayVarint:writeStringUVInt(__str) 48 | self:writeUVInt(#__str) 49 | self:writeStringBytes(__str) 50 | return self 51 | end 52 | 53 | --- Convert signed int to unsigned int 54 | -- After converting, 1=2, -1=1, -2=3, 2=4 55 | function ByteArrayVarint:_zigZagEncode(__value) 56 | if __value >= 0 then return bit.lshift(__value, 1) end 57 | return bit.bxor(bit.lshift(__value, 1), bit.bnot(0)) 58 | end 59 | 60 | function ByteArrayVarint:_zigZagDecode(__value) 61 | if bit.band(__value, 0x1) == 0 then return bit.rshift(__value, 1) end 62 | return bit.bxor(bit.rshift(__value, 1), bit.bnot(0)) 63 | end 64 | 65 | function ByteArrayVarint:_encodeVarint(__value) 66 | assert(type(__value) == "number", "Value to encode must be a number!") 67 | --[[ 2013-11-19 zrong 68 | Our server need a number greater than 32bit, but BitOp only support 32bit signed nubmers. 69 | Client will get a negative number if server send a number greater than 21 4748 3648. 70 | But, when client send the number to server use writeUVInt, server will get a positive number. 71 | Yes, it can get the number sent to client. 72 | Thus, we discard the estimating for __value. 73 | ]] 74 | -- if __value < 0 then __value = 0 end 75 | local __bytes = bit.band(__value ,0x7f) 76 | __value = bit.rshift(__value, 7) 77 | while __value ~= 0 do 78 | self:writeByte(bit.bor(0x80, __bytes)) 79 | __bytes = bit.band(__value , 0x7f) 80 | __value = bit.rshift(__value, 7) 81 | -- print(__bytes, __value) 82 | end 83 | self:writeByte(__bytes) 84 | end 85 | 86 | function ByteArrayVarint:_decodeVarint() 87 | local __result = 0 88 | local __shift = 0 89 | local __byte = nil 90 | while self._pos <= #self._buf do 91 | __byte = self:readByte() 92 | __result = bit.bor(__result, bit.lshift(bit.band(__byte, 0x7f), __shift)) 93 | if bit.band(__byte, 0x80) == 0 then 94 | return __result 95 | end 96 | __shift = __shift + 7 97 | -- BitOp do not support bitwise greater than 32bit 98 | assert(__shift<32, "Varint decode error! 32bit bitwise is unavailable in BitOp!") 99 | end 100 | error("Read variant at EOF!") 101 | end 102 | 103 | return ByteArrayVarint 104 | -------------------------------------------------------------------------------- /lib/zrong/zr/utils/Gettext.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Load a mo file, retuan a lua function or table. 3 | A sample and description(in chinese): http://zengrong.net/post/1986.htm 4 | 5 | @see http://lua-users.org/lists/lua-l/2010-04/msg00005.html 6 | Modifier zrong(zengrong.net) 7 | Creation 2013-11-29 8 | Last Modification 2015-01-25 9 | 10 | usage: 11 | 12 | local Gettext = require("utils.Gettext") 13 | 14 | -- use lua io, cannot use in Android 15 | local fd,err=io.open("main.mo","rb") 16 | if not fd then return nil,err end 17 | local raw_data=fd:read("*all") 18 | fd:close() 19 | 20 | local mo_data=assert(Gettext.parseData(raw_data)) 21 | print(mo_data["hello"]) 22 | -- 你好 23 | print(mo_data["world"]) 24 | -- nil 25 | 26 | -- then you'll get a kind of gettext function: 27 | local gettext= Gettext.gettext(raw_data) 28 | print(gettext("hello")) 29 | -- 你好 30 | print(gettext("world")) 31 | -- world 32 | 33 | -- with a slight modification this will be ready-to-use for the xgettext tool: 34 | 35 | _ = Gettext.gettext(raw_data) 36 | print(_("hello")) 37 | print(_("world")) 38 | ]] 39 | 40 | -- Original description 41 | ----------------------------------------------------------- 42 | -- load an mo file and return a lua table 43 | -- @param mo_file name of the file to load 44 | -- @return table on success 45 | -- @return nil,string on failure 46 | -- @copyright J.J?rgen von Bargen 47 | -- @licence I provide this as public domain 48 | -- @see http://www.gnu.org/software/hello/manual/gettext/MO-Files.html 49 | ----------------------------------------------------------- 50 | 51 | local Gettext = {} 52 | 53 | function Gettext.gettext(mo_data) 54 | local hash = Gettext.parseData(mo_data) 55 | return function(text) 56 | return hash[text] or text 57 | end 58 | end 59 | 60 | function Gettext.parseData(mo_data) 61 | -------------------------------- 62 | -- precache some functions 63 | -------------------------------- 64 | local byte=string.byte 65 | local sub=string.sub 66 | 67 | -------------------------------- 68 | -- check format 69 | -------------------------------- 70 | local peek_long --localize 71 | local magic=sub(mo_data,1,4) 72 | -- intel magic 0xde120495 73 | if magic=="\222\018\004\149" then 74 | peek_long=function(offs) 75 | local a,b,c,d=byte(mo_data,offs+1,offs+4) 76 | return ((d*256+c)*256+b)*256+a 77 | end 78 | -- motorola magic = 0x950412de 79 | elseif magic=="\149\004\018\222" then 80 | peek_long=function(offs) 81 | local a,b,c,d=byte(mo_data,offs+1,offs+4) 82 | return ((a*256+b)*256+c)*256+d 83 | end 84 | else 85 | return nil,"no valid mo-file" 86 | end 87 | 88 | -------------------------------- 89 | -- version 90 | -------------------------------- 91 | local V=peek_long(4) 92 | if V~=0 then 93 | return nul,"unsupported version" 94 | end 95 | 96 | ------------------------------ 97 | -- get number of offsets of table 98 | ------------------------------ 99 | local N,O,T=peek_long(8),peek_long(12),peek_long(16) 100 | ------------------------------ 101 | -- traverse and get strings 102 | ------------------------------ 103 | local hash={} 104 | for nstr=1,N do 105 | local ol,oo=peek_long(O),peek_long(O+4) O=O+8 106 | local tl,to=peek_long(T),peek_long(T+4) T=T+8 107 | hash[sub(mo_data,oo+1,oo+ol)]=sub(mo_data,to+1,to+tl) 108 | end 109 | return hash -- return table 110 | end 111 | 112 | return Gettext 113 | -------------------------------------------------------------------------------- /lib/zrong/zr/utils/bit.lua: -------------------------------------------------------------------------------- 1 | local has_bitop, bit = pcall(require, 'bit') 2 | if not has_bitop then 3 | import('...luabit.bit') 4 | end 5 | -------------------------------------------------------------------------------- /lib/zrong/zr/utils/init.lua: -------------------------------------------------------------------------------- 1 | --- init utils package 2 | -- @author zrong(zengrong.net) 3 | -- Creation 2014-01-02 4 | local utils = {} 5 | 6 | utils.ByteArray = import(".ByteArray") 7 | utils.ByteArrayVarint = import(".ByteArrayVarint") 8 | utils.Gettext = import(".Gettext") 9 | 10 | return utils 11 | -------------------------------------------------------------------------------- /luabytearray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrong/lua/19ebded9809802f396aab57c589fa8797b332fcf/luabytearray.png -------------------------------------------------------------------------------- /src/MainScene.lua: -------------------------------------------------------------------------------- 1 | require("pack") 2 | require("bit") 3 | local SocketTCP = require("net.SocketTCP") 4 | local ByteArray = require("utils.ByteArray") 5 | local ByteArrayVarint = require("utils.ByteArrayVarint") 6 | 7 | local MainScene = class("MainScene", function() 8 | return display.newScene("MainScene") 9 | end) 10 | 11 | function MainScene:ctor() 12 | echoInfo("socket.getTime:%f", SocketTCP.getTime()) 13 | echoInfo("os.gettime:%f", os.time()) 14 | echoInfo("socket._VERSION: %s", SocketTCP._VERSION) 15 | 16 | local __luaSocketLabel = ui.newTTFLabelMenuItem({ 17 | text = "lua socket connect", 18 | size = 32, 19 | x = display.cx, 20 | y = display.top - 128, 21 | listener = handler(self, self.onLuaSocketConnectClicked), 22 | }) 23 | 24 | local __luaSocketSendLabel = ui.newTTFLabelMenuItem({ 25 | text = "lua socket send", 26 | size = 32, 27 | x = display.cx, 28 | y = display.top - 160, 29 | listener = handler(self, self.onLuaSocketSendClicked), 30 | }) 31 | 32 | self:addChild(ui.newMenu({__luaSocketLabel, __luaSocketSendLabel})) 33 | 34 | self:testByteArray() 35 | end 36 | 37 | function MainScene:testByteArray() 38 | local __pack = self:getDataByLpack() 39 | local __ba1 = ByteArray.new() 40 | :writeBuf(__pack) 41 | :setPos(1) 42 | print("ba1.len:", __ba1:getLen()) 43 | print("ba1.readByte:", __ba1:readByte()) 44 | print("ba1.readInt:", __ba1:readInt()) 45 | print("ba1.readShort:", __ba1:readShort()) 46 | print("ba1.readString:", __ba1:readStringUShort()) 47 | print("ba1.readString:", __ba1:readStringUShort()) 48 | print("ba1.available:", __ba1:getAvailable()) 49 | print("ba1.toString(16):", __ba1:toString(16)) 50 | print("ba1.toString(10):", __ba1:toString(10)) 51 | 52 | local __ba2 = self:getByteArray() 53 | print("ba2.toString(10):", __ba2:toString(10)) 54 | 55 | 56 | local __ba3 = ByteArray.new() 57 | local __str = "" 58 | for i=1,20 do 59 | __str = __str.."ABCDEFGHIJ" 60 | end 61 | __ba3:writeStringSizeT(__str) 62 | __ba3:setPos(1) 63 | print("__ba3:readUInt:", __ba3:readUInt()) 64 | --print("__ba3.readStringSizeT:", __ba3:readStringUInt()) 65 | end 66 | 67 | function MainScene:getDataByLpack() 68 | local __pack = string.pack("