diff --git a/templates/lua-template-runtime/.settings/version.json b/templates/lua-template-runtime/.settings/version.json index 5f06abfbad..62ee19a364 100644 --- a/templates/lua-template-runtime/.settings/version.json +++ b/templates/lua-template-runtime/.settings/version.json @@ -1,4 +1,4 @@ { - "templateVersion":"1.2", - "runtimeVersion":"1.2" + "templateVersion":"1.3", + "runtimeVersion":"1.3" } \ No newline at end of file diff --git a/templates/lua-template-runtime/config.json b/templates/lua-template-runtime/config.json index 09215954df..c88d6cf401 100644 --- a/templates/lua-template-runtime/config.json +++ b/templates/lua-template-runtime/config.json @@ -4,7 +4,8 @@ "name": "HelloLua", "width": 960, "height": 640, - "entry": "src/main.lua" + "entry": "src/main.lua", + "consolePort": 6010 }, "simulator_screen_size": [ { diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp index 1b2efff673..515cfdc6b0 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp @@ -46,9 +46,7 @@ bool AppDelegate::applicationDidFinishLaunching() #endif } - // turn on display FPS - director->setDisplayStats(true); - + // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp index 9054ac4ca8..9e5381a07a 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp @@ -24,6 +24,7 @@ bool ConfigParser::isInit() void ConfigParser::readConfig() { _isInit = true; + _consolePort = 6010; string filecfg = "config.json"; string fileContent; @@ -69,6 +70,9 @@ void ConfigParser::readConfig() if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) { _entryfile = objectInitView["entry"].GetString(); } + if (objectInitView.HasMember("consolePort")){ + _consolePort = objectInitView["consolePort"].GetUint(); + } } } if (_docRootjson.HasMember("simulator_screen_size")) @@ -123,6 +127,10 @@ bool ConfigParser::isLanscape() return _isLandscape; } +int ConfigParser::getConsolePort() +{ + return _consolePort; +} int ConfigParser::getScreenSizeCount(void) { return (int)_screenSizeArray.size(); diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.h b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.h index 7b2f536bb6..adae188dd5 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.h +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.h @@ -36,6 +36,7 @@ public: string getEntryFile(); rapidjson::Document& getConfigJsonRoot(); const SimulatorScreenSize getScreenSize(int index); + int getConsolePort(); bool isLanscape(); bool isInit(); @@ -48,6 +49,7 @@ private: string _entryfile; bool _isLandscape; bool _isInit; + int _consolePort; rapidjson::Document _docRootjson; }; diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/protobuf-lite/google/protobuf/stubs/atomicops_internals_x86_gcc.cc b/templates/lua-template-runtime/frameworks/runtime-src/Classes/protobuf-lite/google/protobuf/stubs/atomicops_internals_x86_gcc.cc new file mode 100644 index 0000000000..07748723f6 --- /dev/null +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/protobuf-lite/google/protobuf/stubs/atomicops_internals_x86_gcc.cc @@ -0,0 +1,137 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2012 Google Inc. All rights reserved. +// http://code.google.com/p/protobuf/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// This module gets enough CPU information to optimize the +// atomicops module on x86. + +#include + +#include + +// This file only makes sense with atomicops_internals_x86_gcc.h -- it +// depends on structs that are defined in that file. If atomicops.h +// doesn't sub-include that file, then we aren't needed, and shouldn't +// try to do anything. +#ifdef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_GCC_H_ + +// Inline cpuid instruction. In PIC compilations, %ebx contains the address +// of the global offset table. To avoid breaking such executables, this code +// must preserve that register's value across cpuid instructions. +#if defined(__i386__) +#define cpuid(a, b, c, d, inp) \ + asm("mov %%ebx, %%edi\n" \ + "cpuid\n" \ + "xchg %%edi, %%ebx\n" \ + : "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp)) +#elif defined(__x86_64__) +#define cpuid(a, b, c, d, inp) \ + asm("mov %%rbx, %%rdi\n" \ + "cpuid\n" \ + "xchg %%rdi, %%rbx\n" \ + : "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp)) +#endif + +#if defined(cpuid) // initialize the struct only on x86 + +namespace google { +namespace protobuf { +namespace internal { + +// Set the flags so that code will run correctly and conservatively, so even +// if we haven't been initialized yet, we're probably single threaded, and our +// default values should hopefully be pretty safe. +struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures = { + false, // bug can't exist before process spawns multiple threads + false, // no SSE2 +}; + +namespace { + +// Initialize the AtomicOps_Internalx86CPUFeatures struct. +void AtomicOps_Internalx86CPUFeaturesInit() { + uint32_t eax; + uint32_t ebx; + uint32_t ecx; + uint32_t edx; + + // Get vendor string (issue CPUID with eax = 0) + cpuid(eax, ebx, ecx, edx, 0); + char vendor[13]; + memcpy(vendor, &ebx, 4); + memcpy(vendor + 4, &edx, 4); + memcpy(vendor + 8, &ecx, 4); + vendor[12] = 0; + + // get feature flags in ecx/edx, and family/model in eax + cpuid(eax, ebx, ecx, edx, 1); + + int family = (eax >> 8) & 0xf; // family and model fields + int model = (eax >> 4) & 0xf; + if (family == 0xf) { // use extended family and model fields + family += (eax >> 20) & 0xff; + model += ((eax >> 16) & 0xf) << 4; + } + + // Opteron Rev E has a bug in which on very rare occasions a locked + // instruction doesn't act as a read-acquire barrier if followed by a + // non-locked read-modify-write instruction. Rev F has this bug in + // pre-release versions, but not in versions released to customers, + // so we test only for Rev E, which is family 15, model 32..63 inclusive. + if (strcmp(vendor, "AuthenticAMD") == 0 && // AMD + family == 15 && + 32 <= model && model <= 63) { + AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true; + } else { + AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false; + } + + // edx bit 26 is SSE2 which we use to tell use whether we can use mfence + AtomicOps_Internalx86CPUFeatures.has_sse2 = ((edx >> 26) & 1); +} + +class AtomicOpsx86Initializer { + public: + AtomicOpsx86Initializer() { + AtomicOps_Internalx86CPUFeaturesInit(); + } +}; + +// A global to get use initialized on startup via static initialization :/ +AtomicOpsx86Initializer g_initer; + +} // namespace + +} // namespace internal +} // namespace protobuf +} // namespace google + +#endif // __i386__ + +#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_GCC_H_ diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp index 1dddcd2832..07bb6906bb 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp @@ -35,6 +35,7 @@ THE SOFTWARE. #include "ConfigParser.h" #include "Protos.pb.h" #include "zlib.h" +#include "lua.h" #ifdef _WIN32 #include @@ -49,7 +50,7 @@ using namespace std; using namespace cocos2d; std::string g_resourcePath; -extern string getIPAddress(); + //1M size #define MAXPROTOLENGTH 1048576 @@ -60,11 +61,81 @@ extern string getIPAddress(); #define usleep(t) usleep(t) #endif +extern string getIPAddress(); const char* getRuntimeVersion() { - return "1.2"; + return "1.3"; } +static string& replaceAll(string& str,const string& old_value,const string& new_value) +{ + while(true) + { + int pos=0; + if((pos=str.find(old_value,0))!=string::npos) + str.replace(pos,old_value.length(),new_value); + else break; + } + return str; +} +static bool resetLuaModule(string fileName) +{ + if (fileName.empty()) + { + CCLOG("fileName is null"); + return false; + } + auto engine = LuaEngine::getInstance(); + LuaStack* luaStack = engine->getLuaStack(); + lua_State* stack=luaStack->getLuaState(); + lua_getglobal(stack, "package"); /* L: package */ + lua_getfield(stack, -1, "loaded"); /* L: package loaded */ + lua_pushnil(stack); /* L: lotable ?-.. nil */ + while ( 0 != lua_next(stack, -2 ) ) /* L: lotable ?-.. key value */ + { + //CCLOG("%s - %s \n", tolua_tostring(stack, -2, ""), lua_typename(stack, lua_type(stack, -1))); + std::string key=tolua_tostring(stack, -2, ""); + std::string tableKey =key; + int found = tableKey.rfind(".lua"); + if (found!=std::string::npos) + tableKey = tableKey.substr(0,found); + tableKey=replaceAll(tableKey,".","/"); + tableKey=replaceAll(tableKey,"\\","/"); + tableKey.append(".lua"); + found = fileName.rfind(tableKey); + if (0 == found || ( found!=std::string::npos && fileName.at(found-1) == '/')) + { + lua_pushstring(stack, key.c_str()); + lua_pushnil(stack); + if (lua_istable(stack, -5)) + { + lua_settable(stack, -5); + } + } + lua_pop(stack, 1); + } + lua_pop(stack, 2); + return true; +} +bool reloadScript(string modulefile) +{ + auto director = Director::getInstance(); + FontFNT::purgeCachedData(); + if (director->getOpenGLView()) + { + SpriteFrameCache::getInstance()->removeSpriteFrames(); + director->getTextureCache()->removeAllTextures(); + } + FileUtils::getInstance()->purgeCachedEntries(); + if (!resetLuaModule(modulefile)) + { + modulefile = ConfigParser::getInstance()->getEntryFile().c_str(); + } + auto engine = LuaEngine::getInstance(); + LuaStack* luaStack = engine->getLuaStack(); + std::string require = "require \'" + modulefile + "\'"; + return luaStack->executeString(require.c_str()); +} void startScript(string strDebugArg) { // register lua engine @@ -77,28 +148,8 @@ void startScript(string strDebugArg) engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); } -bool reloadScript(const string& modulefile) -{ - string strfile = modulefile; - if (strfile.empty()) - { - strfile = ConfigParser::getInstance()->getEntryFile().c_str(); - } - auto director = Director::getInstance(); - FontFNT::purgeCachedData(); - if (director->getOpenGLView()) - { - SpriteFrameCache::getInstance()->removeSpriteFrames(); - director->getTextureCache()->removeAllTextures(); - } - FileUtils::getInstance()->purgeCachedEntries(); - - director->getScheduler()->unscheduleAll(); - director->getScheduler()->scheduleUpdate(director->getActionManager(), Scheduler::PRIORITY_SYSTEM, false); - - return (LuaEngine::getInstance()->reload(strfile.c_str())==0); -} + #if defined(_MSC_VER) || defined(__MINGW32__) #include @@ -231,7 +282,7 @@ void FileServer::readResFileFinfo() if (!pFile) return ; fwrite(str,sizeof(char),strlen(str),pFile); fclose(pFile); - },this, 10.0f, false, "fileinfo"); + },this, 5.0f, false, "fileinfo"); } void FileServer::addResFileInfo(const char* filename,uint64_t u64) @@ -337,19 +388,8 @@ void FileServer::stop() } } -string& replaceAll(string& str,const string& old_value,const string& new_value) -{ - while(true) - { - int pos=0; - if((pos=str.find(old_value,0))!=string::npos) - str.replace(pos,old_value.length(),new_value); - else break; - } - return str; -} -bool CreateDir(const char *sPathName) +static bool CreateDir(const char *sPathName) { char DirName[256]={0}; strcpy(DirName, sPathName); @@ -382,7 +422,7 @@ bool CreateDir(const char *sPathName) return true; } -void recvBuf(int fd,char *pbuf,int bufsize) +static void recvBuf(int fd,char *pbuf,int bufsize) { int startFlagLen = bufsize; while (startFlagLen != 0){ @@ -447,7 +487,14 @@ void FileServer::loopReceiveFile() } } int contentSize = recvDataBuf.fileProto.content_size(); - if (contentSize>0){ + if (contentSize == 0) + { + recvDataBuf.contentBuf=""; + _recvBufListMutex.lock(); + _recvBufList.push_back(recvDataBuf); + _recvBufListMutex.unlock(); + }else if(contentSize>0) + { //recv body data Bytef *contentbuf= new Bytef[contentSize+1]; memset(contentbuf,0,contentSize+1); @@ -513,7 +560,7 @@ void FileServer::loopWriteFile() _fileNameMutex.lock(); _strFileName = filename; _fileNameMutex.unlock(); - cocos2d::log("WriteFile:: fullfilename = %s",filename.c_str()); + //cocos2d::log("WriteFile:: fullfilename = %s",filename.c_str()); CreateDir(fullfilename.substr(0,fullfilename.find_last_of("/")).c_str()); FILE *fp= nullptr; @@ -531,7 +578,7 @@ void FileServer::loopWriteFile() continue; } if (fp){ - if (0 == fwrite(recvDataBuf.contentBuf.c_str(), sizeof(char), recvDataBuf.contentBuf.size(),fp)){ + if (recvDataBuf.contentBuf.size() > 0 && 0 == fwrite(recvDataBuf.contentBuf.c_str(), sizeof(char), recvDataBuf.contentBuf.size(),fp)){ addResponse(recvDataBuf.fd,filename,runtime::FileSendComplete::RESULTTYPE::FileSendComplete_RESULTTYPE_FWRITE_ERROR,errno); fclose(fp); continue; @@ -751,16 +798,23 @@ public: for (int i=0;i< sizeof(commands)/sizeof(Console::Command);i++) { _console->addCommand(commands[i]); } +#if(CC_PLATFORM_MAC == CC_TARGET_PLATFORM || CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM) + _console->listenOnTCP(ConfigParser::getInstance()->getConsolePort()); +#else _console->listenOnTCP(6010); - +#endif + _fileserver = nullptr; +#if(CC_PLATFORM_MAC != CC_TARGET_PLATFORM && CC_PLATFORM_WIN32 != CC_TARGET_PLATFORM) _fileserver= FileServer::getShareInstance(); _fileserver->listenOnTCP(6020); _fileserver->readResFileFinfo(); +#endif } ~ConsoleCustomCommand() { Director::getInstance()->getConsole()->stop(); + if(_fileserver) _fileserver->stop(); } @@ -810,9 +864,11 @@ public: dReplyParse.AddMember("code",0,dReplyParse.GetAllocator()); }else if(strcmp(strcmd.c_str(),"getfileinfo")==0){ rapidjson::Value bodyvalue(rapidjson::kObjectType); - rapidjson::Document* filecfgjson = _fileserver->getFileCfgJson(); - for (auto it=filecfgjson->MemberonBegin();it!=filecfgjson->MemberonEnd();++it){ - bodyvalue.AddMember(it->name.GetString(),it->value.GetString(),dReplyParse.GetAllocator()); + if(_fileserver){ + rapidjson::Document* filecfgjson = _fileserver->getFileCfgJson(); + for (auto it=filecfgjson->MemberonBegin();it!=filecfgjson->MemberonEnd();++it){ + bodyvalue.AddMember(it->name.GetString(),it->value.GetString(),dReplyParse.GetAllocator()); + } } dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator()); dReplyParse.AddMember("code",0,dReplyParse.GetAllocator()); @@ -1056,6 +1112,11 @@ bool initRuntime() searchPathArray.insert(searchPathArray.begin(),g_resourcePath); FileUtils::getInstance()->setSearchPaths(searchPathArray); + auto engine = LuaEngine::getInstance(); + ScriptEngineManager::getInstance()->setScriptEngine(engine); + LuaStack* stack = engine->getLuaStack(); + register_runtime_override_function(stack->getLuaState()); + luaopen_debugger(engine->getLuaStack()->getLuaState()); return true; } @@ -1075,16 +1136,13 @@ bool startRuntime() #endif #endif - static ConsoleCustomCommand s_customCommand; - s_customCommand.init(); - auto engine = LuaEngine::getInstance(); - ScriptEngineManager::getInstance()->setScriptEngine(engine); + // turn on display FPS + Director::getInstance()->setDisplayStats(true); - LuaStack* stack = engine->getLuaStack(); - register_runtime_override_function(stack->getLuaState()); - - luaopen_debugger(engine->getLuaStack()->getLuaState()); - + static ConsoleCustomCommand *g_customCommand; + g_customCommand = new ConsoleCustomCommand(); + g_customCommand->init(); + auto scene = Scene::create(); auto connectLayer = new ConnectWaitLayer(); connectLayer->autorelease(); diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.h b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.h index 284c34942f..34d662924b 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.h +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.h @@ -31,7 +31,7 @@ using namespace std; bool initRuntime(); bool startRuntime(); -bool reloadScript(const string& modulefile); +bool reloadScript(string modulefile); #endif // _RUNTIME__H_ diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Android.mk b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Android.mk index d4ea0d1d11..c86a999470 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Android.mk +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Android.mk @@ -13,6 +13,7 @@ LOCAL_SRC_FILES := \ ../../Classes/protobuf-lite/google/protobuf/generated_message_util.cc \ ../../Classes/protobuf-lite/google/protobuf/message_lite.cc \ ../../Classes/protobuf-lite/google/protobuf/stubs/once.cc \ +../../Classes/protobuf-lite/google/protobuf/stubs/atomicops_internals_x86_gcc.cc \ ../../Classes/protobuf-lite/google/protobuf/repeated_field.cc \ ../../Classes/protobuf-lite/google/protobuf/wire_format_lite.cc \ ../../Classes/protobuf-lite/google/protobuf/io/zero_copy_stream.cc \ diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java index d4dd55873a..512805a1aa 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java @@ -30,6 +30,7 @@ import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; +import java.util.ArrayList; import org.cocos2dx.lib.Cocos2dxActivity; @@ -48,6 +49,7 @@ import android.os.Environment; import android.provider.Settings; import android.text.format.Formatter; import android.util.Log; +import android.view.WindowManager; import android.widget.Toast; // The name of .so is specified in AndroidMenifest.xml. NativityActivity will load it automatically for you. @@ -72,7 +74,8 @@ public class AppActivity extends Cocos2dxActivity{ // Check the wifi is opened when the native is debug. if(nativeIsDebug()) { - if(!isWifiConnected()) + getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + if(!isNetworkConnected()) { AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setTitle("Warning"); @@ -92,11 +95,20 @@ public class AppActivity extends Cocos2dxActivity{ } hostIPAdress = getHostIpAddress(); } - private boolean isWifiConnected() { + private boolean isNetworkConnected() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo networkInfo = cm.getActiveNetworkInfo(); - if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { + ArrayList networkTypes = new ArrayList(); + networkTypes.add(ConnectivityManager.TYPE_WIFI); + try { + networkTypes.add(ConnectivityManager.class.getDeclaredField("TYPE_ETHERNET").getInt(null)); + } catch (NoSuchFieldException nsfe) { + } + catch (IllegalAccessException iae) { + throw new RuntimeException(iae); + } + if (networkInfo != null && networkTypes.contains(networkInfo.getType())) { return true; } } diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj index 7f79759d56..e3f1928ef5 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj @@ -44,6 +44,7 @@ 3EB5156D1952865D006966AA /* stringprintf.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EB515511952865D006966AA /* stringprintf.cc */; }; 3EB5156E1952865D006966AA /* wire_format_lite.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EB515551952865D006966AA /* wire_format_lite.cc */; }; 3EB5156F1952865D006966AA /* wire_format_lite.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EB515551952865D006966AA /* wire_format_lite.cc */; }; + 3EEEDB61197107C0006A9FF8 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EEEDB60197107C0006A9FF8 /* MediaPlayer.framework */; }; 5023811817EBBCAC00990C9B /* AppController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5023810817EBBCAC00990C9B /* AppController.mm */; }; 5023811917EBBCAC00990C9B /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 5023810917EBBCAC00990C9B /* Default-568h@2x.png */; }; 5023811A17EBBCAC00990C9B /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 5023810A17EBBCAC00990C9B /* Default.png */; }; @@ -161,9 +162,6 @@ C08D5D6718E567C6009071A4 /* tp.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5418E567C6009071A4 /* tp.lua */; }; C08D5D6818E567C6009071A4 /* url.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5518E567C6009071A4 /* url.lua */; }; C08D5D6918E567C6009071A4 /* url.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5518E567C6009071A4 /* url.lua */; }; - C09BA7E718BC929700A85A3E /* WorkSpaceDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = C09BA7E418BC929700A85A3E /* WorkSpaceDialog.xib */; }; - C09BA7E818BC929700A85A3E /* WorkSpaceDialogController.mm in Sources */ = {isa = PBXBuildFile; fileRef = C09BA7E618BC929700A85A3E /* WorkSpaceDialogController.mm */; }; - C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C09BA7ED18BCA49600A85A3E /* NSAppSheetAdditions.m */; }; D6B061351803AC000077942B /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D6B061341803AC000077942B /* CoreMotion.framework */; }; F293B3CD15EB7BE500256477 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F293B3CC15EB7BE500256477 /* QuartzCore.framework */; }; F293B3D115EB7BE500256477 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F293B3D015EB7BE500256477 /* OpenAL.framework */; }; @@ -390,6 +388,7 @@ 3EB515551952865D006966AA /* wire_format_lite.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wire_format_lite.cc; sourceTree = ""; }; 3EB515561952865D006966AA /* wire_format_lite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wire_format_lite.h; sourceTree = ""; }; 3EB515571952865D006966AA /* wire_format_lite_inl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wire_format_lite_inl.h; sourceTree = ""; }; + 3EEEDB60197107C0006A9FF8 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/System/Library/Frameworks/MediaPlayer.framework; sourceTree = DEVELOPER_DIR; }; 5023810717EBBCAC00990C9B /* AppController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppController.h; sourceTree = ""; }; 5023810817EBBCAC00990C9B /* AppController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AppController.mm; sourceTree = ""; }; 5023810917EBBCAC00990C9B /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; @@ -471,11 +470,6 @@ C08D5D5318E567C6009071A4 /* socket.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = socket.lua; path = "../../cocos2d-x/external/lua/luasocket/socket.lua"; sourceTree = ""; }; C08D5D5418E567C6009071A4 /* tp.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tp.lua; path = "../../cocos2d-x/external/lua/luasocket/tp.lua"; sourceTree = ""; }; C08D5D5518E567C6009071A4 /* url.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = url.lua; path = "../../cocos2d-x/external/lua/luasocket/url.lua"; sourceTree = ""; }; - C09BA7E418BC929700A85A3E /* WorkSpaceDialog.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WorkSpaceDialog.xib; sourceTree = ""; }; - C09BA7E518BC929700A85A3E /* WorkSpaceDialogController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkSpaceDialogController.h; sourceTree = ""; }; - C09BA7E618BC929700A85A3E /* WorkSpaceDialogController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WorkSpaceDialogController.mm; sourceTree = ""; }; - C09BA7EC18BCA49600A85A3E /* NSAppSheetAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSAppSheetAdditions.h; sourceTree = ""; }; - C09BA7ED18BCA49600A85A3E /* NSAppSheetAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSAppSheetAdditions.m; sourceTree = ""; }; D6B061341803AC000077942B /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/CoreMotion.framework; sourceTree = DEVELOPER_DIR; }; F293B3C815EB7BE500256477 /* HelloLua iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "HelloLua iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; F293B3CC15EB7BE500256477 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; @@ -518,6 +512,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 3EEEDB61197107C0006A9FF8 /* MediaPlayer.framework in Frameworks */, C03781F618BF65B100FE4F13 /* libluabindings iOS.a in Frameworks */, 15A8A4441834C43700142BE0 /* libchipmunk iOS.a in Frameworks */, 15A8A4451834C43700142BE0 /* libcocos2dx iOS.a in Frameworks */, @@ -689,11 +684,6 @@ 5023817117EBBE3400990C9B /* mac */ = { isa = PBXGroup; children = ( - C09BA7EC18BCA49600A85A3E /* NSAppSheetAdditions.h */, - C09BA7ED18BCA49600A85A3E /* NSAppSheetAdditions.m */, - C09BA7E418BC929700A85A3E /* WorkSpaceDialog.xib */, - C09BA7E518BC929700A85A3E /* WorkSpaceDialogController.h */, - C09BA7E618BC929700A85A3E /* WorkSpaceDialogController.mm */, 5023817217EBBE3400990C9B /* Icon.icns */, C07828F418B4D72E00BD2287 /* main.m */, C07828F518B4D72E00BD2287 /* MainMenu.xib */, @@ -780,6 +770,7 @@ F293B3CB15EB7BE500256477 /* Frameworks */ = { isa = PBXGroup; children = ( + 3EEEDB60197107C0006A9FF8 /* MediaPlayer.framework */, 3EB51526195187AF006966AA /* CFNetwork.framework */, 15A8A4871834C90E00142BE0 /* libcurl.dylib */, D6B061341803AC000077942B /* CoreMotion.framework */, @@ -1019,7 +1010,6 @@ C08D5D6118E567C6009071A4 /* mime.lua in Resources */, C03781D418BF656A00FE4F13 /* Cocos2d.lua in Resources */, C03781BA18BF655400FE4F13 /* res in Resources */, - C09BA7E718BC929700A85A3E /* WorkSpaceDialog.xib in Resources */, C03781BC18BF655400FE4F13 /* src in Resources */, C08D5D6918E567C6009071A4 /* url.lua in Resources */, C03781E218BF656A00FE4F13 /* DrawPrimitives.lua in Resources */, @@ -1148,12 +1138,10 @@ 3EB515691952865D006966AA /* common.cc in Sources */, 3EB515651952865D006966AA /* repeated_field.cc in Sources */, 3EB5156B1952865D006966AA /* once.cc in Sources */, - C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */, 3EB5155D1952865D006966AA /* coded_stream.cc in Sources */, C00FD4991938512100C6382D /* Portrait_png.cpp in Sources */, C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */, 3EB5156D1952865D006966AA /* stringprintf.cc in Sources */, - C09BA7E818BC929700A85A3E /* WorkSpaceDialogController.mm in Sources */, C07828F818B4D72E00BD2287 /* main.m in Sources */, 3EB515611952865D006966AA /* zero_copy_stream_impl_lite.cc in Sources */, 3EB5156F1952865D006966AA /* wire_format_lite.cc in Sources */, diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/MainMenu.xib b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/MainMenu.xib index 1d691c1d28..a803574695 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/MainMenu.xib +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/MainMenu.xib @@ -2,10 +2,10 @@ 1060 - 13C64 + 13D65 5056 - 1265.19 - 697.40 + 1265.20 + 698.00 com.apple.InterfaceBuilder.CocoaPlugin 5056 @@ -164,14 +164,6 @@ File - - - ChangeProject - - 2147483647 - - - Close @@ -299,6 +291,14 @@ + + + Keep Window Top + + 2147483647 + + + @@ -386,14 +386,6 @@ tSA-7z-LPk - - - onChangeProject: - - - - KV1-nK-nLn - onFileClose: @@ -458,6 +450,14 @@ XXg-eJ-YSn + + + onSetTop: + + + + jvv-x1-KeN + menu @@ -594,16 +594,10 @@ 81 - - - UUd-nT-0Tr - - - 611 @@ -687,6 +681,7 @@ + @@ -718,6 +713,11 @@ + + CXy-V7-NaY + + + @@ -761,6 +761,7 @@ com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -777,8 +778,6 @@ com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -801,7 +800,68 @@ - + + + + AppController + NSObject + + id + id + id + id + id + id + id + + + + onFileClose: + id + + + onRelaunch: + id + + + onScreenLandscape: + id + + + onScreenPortait: + id + + + onScreenZoomOut: + id + + + onSetTop: + id + + + onViewChangeFrameSize: + id + + + + menu + NSMenu + + + menu + + menu + NSMenu + + + + IBProjectSource + ./Classes/AppController.h + + + + 0 IBCocoaFramework YES @@ -811,7 +871,7 @@ com.apple.InterfaceBuilder.CocoaPlugin.macosx - + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/NSAppSheetAdditions.h b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/NSAppSheetAdditions.h deleted file mode 100644 index 0f7e43b3ce..0000000000 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/NSAppSheetAdditions.h +++ /dev/null @@ -1,8 +0,0 @@ - -#import - -@interface NSApplication (SheetAdditions) - -- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow didEndBlock:(void (^)(NSInteger returnCode))block; - -@end diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/NSAppSheetAdditions.m b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/NSAppSheetAdditions.m deleted file mode 100644 index b5845bd784..0000000000 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/NSAppSheetAdditions.m +++ /dev/null @@ -1,22 +0,0 @@ - -#import "NSAppSheetAdditions.h" - -@implementation NSApplication (SheetAdditions) - -- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow didEndBlock:(void (^)(NSInteger returnCode))block -{ - [self beginSheet:sheet - modalForWindow:docWindow - modalDelegate:self - didEndSelector:@selector(my_blockSheetDidEnd:returnCode:contextInfo:) - contextInfo:Block_copy(block)]; -} - -- (void)my_blockSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo -{ - void (^block)(NSInteger returnCode) = contextInfo; - block(returnCode); - Block_release(block); -} - -@end diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.h b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.h index 411a256e9f..d7815e3ef7 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.h +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.h @@ -41,7 +41,7 @@ void createSimulator(const char* viewName, float width, float height,bool isLand @property (nonatomic, assign) IBOutlet NSMenu* menu; -- (IBAction) onChangeProject:(id)sender; +- (IBAction) onSetTop:(id)sender; - (IBAction) onFileClose:(id)sender; - (IBAction) onScreenPortait:(id)sender; - (IBAction) onScreenLandscape:(id)sender; diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.mm b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.mm index 43cce5504e..b860aac9e9 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.mm +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.mm @@ -22,16 +22,13 @@ THE SOFTWARE. ****************************************************************************/ -#import "SimulatorApp.h" -#import "WorkSpaceDialogController.h" -#import "NSAppSheetAdditions.h" - #include #include #include #include #include +#import "SimulatorApp.h" #include "AppDelegate.h" #include "glfw3.h" #include "glfw3native.h" @@ -43,6 +40,7 @@ using namespace cocos2d; bool g_landscape = false; +bool g_windTop = true; cocos2d::Size g_screenSize; GLView* g_eglView = nullptr; @@ -104,7 +102,7 @@ std::string getCurAppPath(void) width = height; height = tmpvalue; } - + g_windTop = true; g_eglView = GLView::createWithRect([viewName cStringUsingEncoding:NSUTF8StringEncoding],cocos2d::Rect(0.0f,0.0f,width,height),frameZoomFactor); auto director = Director::getInstance(); director->setOpenGLView(g_eglView); @@ -115,7 +113,7 @@ std::string getCurAppPath(void) [self createViewMenu]; [self updateMenu]; [window center]; - + [window becomeFirstResponder]; [window makeKeyAndOrderFront:self]; } @@ -172,6 +170,18 @@ void createSimulator(const char* viewName, float width, float height,bool isLand [itemPortait setState:NSOnState]; [itemLandscape setState:NSOffState]; } + + NSMenu *menuControl = [[[window menu] itemWithTitle:@"Control"] submenu]; + NSMenuItem *itemTop = [menuControl itemWithTitle:@"Keep Window Top"]; + if (g_windTop) { + [window setLevel:NSFloatingWindowLevel]; + [itemTop setState:NSOnState]; + } + else + { + [window setLevel:NSNormalWindowLevel]; + [itemTop setState:NSOffState]; + } int scale = g_eglView->getFrameZoomFactor()*100; @@ -223,7 +233,6 @@ void createSimulator(const char* viewName, float width, float height,bool isLand } - //[window setTitle:[NSString stringWithFormat:@"quick-x-player (%0.0f%%)", projectConfig.getFrameScale() * 100]]; } @@ -261,17 +270,10 @@ void createSimulator(const char* viewName, float width, float height,bool isLand [[NSRunningApplication currentApplication] terminate]; } -- (IBAction) onChangeProject:(id)sender +- (IBAction) onSetTop:(id)sender { - - WorkSpaceDialogController *controller = [[WorkSpaceDialogController alloc] initWithWindowNibName:@"WorkSpaceDialog"]; - [NSApp beginSheet:controller.window modalForWindow:window didEndBlock:^(NSInteger returnCode) { - if (returnCode == NSRunStoppedResponse) - { - CCLOG("1111"); - } - [controller release]; - }]; + g_windTop = !g_windTop; + [self updateMenu]; } diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialog.xib b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialog.xib deleted file mode 100644 index 7ebed71aa1..0000000000 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialog.xib +++ /dev/null @@ -1,846 +0,0 @@ - - - - 1070 - 13C64 - 5056 - 1265.19 - 697.40 - - com.apple.InterfaceBuilder.CocoaPlugin - 5056 - - - IBNSLayoutConstraint - NSButton - NSButtonCell - NSCustomObject - NSTextField - NSTextFieldCell - NSView - NSWindowTemplate - - - com.apple.InterfaceBuilder.CocoaPlugin - - - PluginDependencyRecalculationVersion - - - - - WorkSpaceDialogController - - - FirstResponder - - - NSApplication - - - 3 - 2 - {{196, 240}, {650, 150}} - 544736256 - Change Project - NSWindow - - - - - 256 - - - - 268 - {{17, 113}, {626, 17}} - - - YES - - 68157504 - 272630784 - Choose Project Directory: - - .LucidaGrandeUI - 13 - 1044 - - - - 6 - System - controlColor - - 3 - MC42NjY2NjY2NjY3AA - - - - 6 - System - controlTextColor - - 3 - MAA - - - - NO - 1 - - - - 268 - {{20, 83}, {516, 22}} - - - YES - - -1804599231 - 272630848 - - - - YES - - 6 - System - textBackgroundColor - - 3 - MQA - - - - 6 - System - textColor - - - - NO - 1 - - - - 268 - {{538, 77}, {108, 32}} - - - {250, 750} - YES - - 67108864 - 134217728 - Select... - - - -2038284288 - 129 - - .LucidaGrandeUI - 13 - 16 - - - - 400 - 75 - - NO - - - - 268 - {{538, 22}, {109, 32}} - - - {250, 750} - YES - - 67108864 - 134217728 - Open Project - - - -2038284288 - 129 - - - - 400 - 75 - - NO - - - - 268 - {{13, 32}, {82, 32}} - - - {250, 750} - YES - - 67108864 - 134217728 - Cancel - - - -2038284288 - 129 - - - Gw - 400 - 75 - - NO - - - {650, 150} - - - - {{0, 0}, {1920, 1058}} - {10000000000000, 10000000000000} - NO - - - - NO - - - - textFieldProjectDirectory - - - - 307 - - - - window - - - - 308 - - - - browseProjectDirectory: - - - - 315 - - - - onOpenProject: - - - - OsS-1W-RIl - - - - onCancel: - - - - NeH-n8-xBM - - - - - - 0 - - - - - - -2 - - - File's Owner - - - -1 - - - First Responder - - - -3 - - - Application - - - 1 - - - - - - - - 2 - - - - - - - - - - 9 - 0 - - 9 - 1 - 1 - - 0.0 - - 1000 - - 6 - 24 - 2 - NO - - - - 4 - 0 - - 4 - 1 - 1 - - 29 - - 1000 - - 3 - 9 - 3 - NO - - - - 6 - 0 - - 6 - 1 - 1 - - 0.0 - - 1000 - - 6 - 24 - 2 - NO - - - - 3 - 0 - - 4 - 1 - 1 - - 8 - - 1000 - - 6 - 24 - 3 - NO - - - - 5 - 0 - - 5 - 1 - 1 - - 0.0 - - 1000 - - 6 - 24 - 2 - NO - - - - 5 - 0 - - 6 - 1 - 1 - - 8 - - 1000 - - 6 - 24 - 3 - NO - - - - 4 - 0 - - 4 - 1 - 1 - - 39 - - 1000 - - 3 - 9 - 3 - NO - - - - 5 - 0 - - 5 - 1 - 1 - - 20 - - 1000 - - 8 - 23 - 3 - NO - - - - 3 - 0 - - 4 - 1 - 1 - - 8 - - 1000 - - 6 - 24 - 3 - NO - - - - 5 - 0 - - 5 - 1 - 1 - - 0.0 - - 1000 - - 6 - 24 - 2 - NO - - - - 3 - 0 - - 3 - 1 - 1 - - 20 - - 1000 - - 8 - 23 - 3 - NO - - - - - - 3 - - - - - - 7 - 0 - - 0 - 1 - 1 - - 622 - - 1000 - - 3 - 9 - 1 - NO - - - - - - 4 - - - - - 9 - - - - - - 7 - 0 - - 0 - 1 - 1 - - 516 - - 1000 - - 3 - 9 - 1 - NO - - - - - - 10 - - - - - 15 - - - - - - 7 - 0 - - 0 - 1 - 1 - - 96 - - 1000 - - 3 - 9 - 1 - NO - - - - - - 16 - - - - - 290 - - - - - - - - 291 - - - - - h9P-cE-Nn4 - - - - - - - - IHP-6G-mVo - - - - - iMi-xo-eWy - - - - - YJ1-Hw-Y6d - - - - - PG0-hY-geV - - - - - i6K-RE-2fe - - - - - gk1-TV-YZn - - - - - pS2-KY-JwZ - - - - - H3W-Ag-EM4 - - - - - uNq-ax-eLX - - - - - G4a-SP-Ne5 - - - - - V9F-80-0WS - - - - - jJo-kq-191 - - - - - LdE-9Z-oWz - - - - - 88D-6W-iEt - - - - - DKd-WY-ZYy - - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - - - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - - - - - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - - - - - com.apple.InterfaceBuilder.CocoaPlugin - - - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - - com.apple.InterfaceBuilder.CocoaPlugin - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - - - - - WorkSpaceDialogController - NSWindowController - - id - id - id - - - - browseProjectDirectory: - id - - - onCancel: - id - - - onOpenProject: - id - - - - NSButton - NSTextField - NSTextField - - - - buttonOpenProject - NSButton - - - textFieldProjectDirectory - NSTextField - - - textFieldScriptFile - NSTextField - - - - IBProjectSource - ./Classes/WorkSpaceDialogController.h - - - - - 0 - IBCocoaFramework - YES - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 - - - YES - 3 - YES - - diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialogController.h b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialogController.h deleted file mode 100644 index 2b9cddbd15..0000000000 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialogController.h +++ /dev/null @@ -1,22 +0,0 @@ - -#import - -@interface WorkSpaceDialogController : NSWindowController -{ - - NSTextField *textFieldProjectDirectory; - NSTextField *textFieldScriptFile; - NSButton *buttonOpenProject; -} - -@property (nonatomic, assign) IBOutlet NSTextField *textFieldProjectDirectory; -@property (nonatomic, assign) IBOutlet NSTextField *textFieldScriptFile; - -@property (nonatomic, assign) IBOutlet NSButton *buttonOpenProject; - -- (IBAction) browseProjectDirectory:(id)sender; - -- (IBAction) onCancel:(id)sender; -- (IBAction) onOpenProject:(id)sender; - -@end diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialogController.mm b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialogController.mm deleted file mode 100644 index 223803e55e..0000000000 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/WorkSpaceDialogController.mm +++ /dev/null @@ -1,97 +0,0 @@ - -#import "WorkSpaceDialogController.h" - -#pragma mark - - -@implementation WorkSpaceDialogController - -@synthesize textFieldProjectDirectory; -@synthesize textFieldScriptFile; -@synthesize buttonOpenProject; - -NSString* projectPath=nil; -- (id)initWithWindow:(NSWindow *)window -{ - self = [super initWithWindow:window]; - if (self) { - // Initialization code here. - } - - return self; -} - -- (void)dealloc -{ - [super dealloc]; - NSLog(@"[WorkSpaceDialogController dealloc]"); -} - -- (void)windowDidLoad -{ - [super windowDidLoad]; - - // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. - [self.window makeFirstResponder:textFieldProjectDirectory]; - if (nil != projectPath && 0 != projectPath.length) - { - [textFieldProjectDirectory setStringValue:projectPath]; - } -} - -#pragma mark - -#pragma mark functions - -- (NSString*) browseFolder:(NSString*)title -{ - NSOpenPanel* openDlg = [NSOpenPanel openPanel]; - [openDlg setTitle:title]; - [openDlg setCanChooseDirectories:YES]; - [openDlg setCanChooseFiles:NO]; - [openDlg setCanHide:YES]; - [openDlg setCanCreateDirectories:NO]; - [openDlg setCanSelectHiddenExtension:NO]; - [openDlg setAllowsMultipleSelection:NO]; - - if ([openDlg runModal] == NSFileHandlingPanelOKButton) - { - NSURL *url = [openDlg.URLs objectAtIndex:0]; - return [url path]; - } - return nil; -} - -#pragma mark - -#pragma mark outlet - -- (IBAction) browseProjectDirectory:(id)sender -{ - NSString *path = [self browseFolder:@"Choose Project Directory"]; - if (path) - { - [textFieldProjectDirectory setStringValue:path]; - } -} - - -- (IBAction) onCancel:(id)sender -{ - [self close]; - [NSApp endSheet:self.window returnCode:NSRunAbortedResponse]; -} - -- (IBAction) onOpenProject:(id)sender -{ - if([[textFieldProjectDirectory stringValue] isEqualToString:@""]) - { - NSRunAlertPanel(@"Waring", - @"Project path empty!", - @"OK", NULL, NULL); - return; - } - projectPath = [textFieldProjectDirectory stringValue]; - [self close]; - [NSApp endSheet:self.window returnCode:NSRunAbortedResponse]; -} - - -@end diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.cpp b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.cpp index d4ed7258a9..8e64c3d2cb 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.cpp @@ -38,6 +38,7 @@ using namespace cocos2d; WNDPROC g_oldProc=NULL; bool g_landscape=false; +bool g_windTop = true; CCSize g_screenSize; GLView* g_eglView=NULL; INT_PTR CALLBACK AboutDialogCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); @@ -70,6 +71,7 @@ void updateMenu() { HMENU hSysMenu = GetSystemMenu(glfwGetWin32Window(g_eglView->getWindow()), FALSE); HMENU viewMenu = GetSubMenu(hSysMenu, 8); + HMENU viewControl = GetSubMenu(hSysMenu, 9); if (g_landscape) { @@ -82,6 +84,16 @@ void updateMenu() CheckMenuItem(viewMenu, ID_VIEW_LANDSCAPE, MF_BYCOMMAND | MF_UNCHECKED); } + if (g_windTop) + { + ::SetWindowPos(glfwGetWin32Window(g_eglView->getWindow()),HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); + CheckMenuItem(viewControl, ID_CONTROL_TOP, MF_BYCOMMAND | MF_CHECKED); + + }else + { + ::SetWindowPos(glfwGetWin32Window(g_eglView->getWindow()),HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); + CheckMenuItem(viewControl, ID_CONTROL_TOP, MF_BYCOMMAND | MF_UNCHECKED); + } int width = g_screenSize.width; int height = g_screenSize.height; if (height > width) @@ -244,6 +256,10 @@ LRESULT CALLBACK SNewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar switch (wmId) { + case ID_CONTROL_TOP: + g_windTop = !g_windTop; + updateView(); + break; case ID_FILE_EXIT: shutDownApp(); break; @@ -324,6 +340,7 @@ void createSimulator(const char* viewName, float width, float height, bool isLan width = height; height = tmpvalue; } + g_windTop = true; g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor); auto director = Director::getInstance(); diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/game.rc b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/game.rc index 556a26c626..46a66d6cf7 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/game.rc +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/game.rc @@ -66,6 +66,7 @@ BEGIN POPUP "&Control" BEGIN MENUITEM "Restart(F5)", ID_CONTROL_RELOAD + MENUITEM "Keep Window Top", ID_CONTROL_TOP END POPUP "&Help" BEGIN @@ -88,19 +89,6 @@ BEGIN LTEXT "Cocos2d-x-Simulator",IDC_STATIC,29,17,169,25 END -IDD_DIALOG_VIEWCUSTOM DIALOGEX 0, 0, 179, 98 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Custom" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "OK",IDOK,47,77,50,14 - PUSHBUTTON "Cancel",IDCANCEL,104,77,50,14 - LTEXT "Width£º",IDC_STATIC,15,14,30,8 - LTEXT "Height£º",IDC_STATIC,15,36,36,12 - EDITTEXT IDC_EDIT_WIDTH,60,15,89,14,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT_HEIGHT,62,36,87,14,ES_AUTOHSCROLL -END - ///////////////////////////////////////////////////////////////////////////// // @@ -117,14 +105,6 @@ BEGIN TOPMARGIN, 7 BOTTOMMARGIN, 87 END - - IDD_DIALOG_VIEWCUSTOM, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 172 - TOPMARGIN, 7 - BOTTOMMARGIN, 91 - END END #endif // APSTUDIO_INVOKED diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/resource.h b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/resource.h index 6f04655931..d3ddc2bd16 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/resource.h +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/resource.h @@ -7,10 +7,7 @@ #define IDR_MENU_COCOS 201 #define IDD_DIALOG1 202 #define IDD_DIALOG_ABOUT 202 -#define IDD_DIALOG_VIEWCUSTOM 203 -#define IDC_EDIT_WIDTH 1000 #define IDC_EDIT2 1001 -#define IDC_EDIT_HEIGHT 1001 #define ID_VIEW_SIZE 30001 #define ID_FILE_NEW_WINDOW 32771 #define ID_VIEW_PORTRAIT 32775 @@ -27,13 +24,14 @@ #define ID_VIEW_ZOOMOUT75 32786 #define ID_VIEW_ZOOMOUT50 32787 #define ID_VIEW_ZOOMOUT25 32788 +#define ID_CONTROL_TOP 32793 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 201 -#define _APS_NEXT_COMMAND_VALUE 32793 +#define _APS_NEXT_COMMAND_VALUE 32794 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/templates/lua-template-runtime/runtime/config.json b/templates/lua-template-runtime/runtime/config.json index 7d3a94ae77..cf2dec8791 100644 --- a/templates/lua-template-runtime/runtime/config.json +++ b/templates/lua-template-runtime/runtime/config.json @@ -1,6 +1,6 @@ { - "version":"v3-lua-runtime-1.2", - "zip_file_size":"24461574 ", + "version":"v3-lua-runtime-1.3", + "zip_file_size":"24663989", "repo_name":"cocos-runtime-bin", "repo_parent":"https://github.com/chukong/" } diff --git a/templates/lua-template-runtime/src/GameScene.lua b/templates/lua-template-runtime/src/GameScene.lua new file mode 100644 index 0000000000..cd817c5ba0 --- /dev/null +++ b/templates/lua-template-runtime/src/GameScene.lua @@ -0,0 +1,184 @@ +require "Cocos2d" +require "Cocos2dConstants" + +local GameScene = class("GameScene",function() + return cc.Scene:create() +end) + +function GameScene.create() + local scene = GameScene.new() + scene:addChild(scene:createLayerFarm()) + scene:addChild(scene:createLayerMenu()) + return scene +end + + +function GameScene:ctor() + self.visibleSize = cc.Director:getInstance():getVisibleSize() + self.origin = cc.Director:getInstance():getVisibleOrigin() + self.schedulerID = nil +end + +function GameScene:playBgMusic() + local bgMusicPath = cc.FileUtils:getInstance():fullPathForFilename("background.mp3") + cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath, true) + local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav") + cc.SimpleAudioEngine:getInstance():preloadEffect(effectPath) +end + +function GameScene:creatDog() + local frameWidth = 105 + local frameHeight = 95 + + -- create dog animate + local textureDog = cc.Director:getInstance():getTextureCache():addImage("dog.png") + local rect = cc.rect(0, 0, frameWidth, frameHeight) + local frame0 = cc.SpriteFrame:createWithTexture(textureDog, rect) + rect = cc.rect(frameWidth, 0, frameWidth, frameHeight) + local frame1 = cc.SpriteFrame:createWithTexture(textureDog, rect) + + local spriteDog = cc.Sprite:createWithSpriteFrame(frame0) + spriteDog:setPosition(self.origin.x, self.origin.y + self.visibleSize.height / 4 * 3) + spriteDog.isPaused = false + + local animation = cc.Animation:createWithSpriteFrames({frame0,frame1}, 0.5) + local animate = cc.Animate:create(animation); + spriteDog:runAction(cc.RepeatForever:create(animate)) + + -- moving dog at every frame + local function tick() + if spriteDog.isPaused then return end + local x, y = spriteDog:getPosition() + if x > self.origin.x + self.visibleSize.width then + x = self.origin.x + else + x = x + 1 + end + + spriteDog:setPositionX(x) + end + + self.schedulerID = cc.Director:getInstance():getScheduler():scheduleScriptFunc(tick, 0, false) + + return spriteDog +end + +-- create farm +function GameScene:createLayerFarm() + local layerFarm = cc.Layer:create() + -- add in farm background + local bg = cc.Sprite:create("farm.jpg") + bg:setPosition(self.origin.x + self.visibleSize.width / 2 + 80, self.origin.y + self.visibleSize.height / 2) + layerFarm:addChild(bg) + + -- add land sprite + for i = 0, 3 do + for j = 0, 1 do + local spriteLand = cc.Sprite:create("land.png") + spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2) + layerFarm:addChild(spriteLand) + end + end + + -- add crop + local frameCrop = cc.SpriteFrame:create("crop.png", cc.rect(0, 0, 105, 95)) + for i = 0, 3 do + for j = 0, 1 do + local spriteCrop = cc.Sprite:createWithSpriteFrame(frameCrop); + spriteCrop:setPosition(210 + j * 180 - i % 2 * 90, 40 + i * 95 / 2) + layerFarm:addChild(spriteCrop) + end + end + + -- add moving dog + local spriteDog = self:creatDog() + layerFarm:addChild(spriteDog) + + -- handing touch events + local touchBeginPoint = nil + local function onTouchBegan(touch, event) + local location = touch:getLocation() + --cclog("onTouchBegan: %0.2f, %0.2f", location.x, location.y) + touchBeginPoint = {x = location.x, y = location.y} + spriteDog.isPaused = true + -- CCTOUCHBEGAN event must return true + return true + end + + local function onTouchMoved(touch, event) + local location = touch:getLocation() + --cclog("onTouchMoved: %0.2f, %0.2f", location.x, location.y) + if touchBeginPoint then + local cx, cy = layerFarm:getPosition() + layerFarm:setPosition(cx + location.x - touchBeginPoint.x, + cy + location.y - touchBeginPoint.y) + touchBeginPoint = {x = location.x, y = location.y} + end + end + + local function onTouchEnded(touch, event) + local location = touch:getLocation() + --cclog("onTouchEnded: %0.2f, %0.2f", location.x, location.y) + touchBeginPoint = nil + spriteDog.isPaused = false + end + + local listener = cc.EventListenerTouchOneByOne:create() + listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) + listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED ) + listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED ) + local eventDispatcher = layerFarm:getEventDispatcher() + eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layerFarm) + + local function onNodeEvent(event) + if "exit" == event then + cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.schedulerID) + end + end + layerFarm:registerScriptHandler(onNodeEvent) + + return layerFarm +end + +-- create menu +function GameScene:createLayerMenu() + + local layerMenu = cc.Layer:create() + local menuPopup, menuTools, effectID + + local function menuCallbackClosePopup() + -- stop test sound effect + cc.SimpleAudioEngine:getInstance():stopEffect(effectID) + menuPopup:setVisible(false) + end + + local function menuCallbackOpenPopup() + -- loop test sound effect + local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav") + effectID = cc.SimpleAudioEngine:getInstance():playEffect(effectPath) + menuPopup:setVisible(true) + end + + -- add a popup menu + local menuPopupItem = cc.MenuItemImage:create("menu2.png", "menu2.png") + menuPopupItem:setPosition(0, 0) + menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) + menuPopup = cc.Menu:create(menuPopupItem) + menuPopup:setPosition(self.origin.x + self.visibleSize.width / 2, self.origin.y + self.visibleSize.height / 2) + menuPopup:setVisible(false) + layerMenu:addChild(menuPopup) + + -- add the left-bottom "tools" menu to invoke menuPopup + local menuToolsItem = cc.MenuItemImage:create("menu1.png", "menu1.png") + menuToolsItem:setPosition(0, 0) + menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup) + menuTools = cc.Menu:create(menuToolsItem) + local itemWidth = menuToolsItem:getContentSize().width + local itemHeight = menuToolsItem:getContentSize().height + menuTools:setPosition(self.origin.x + itemWidth/2, self.origin.y + itemHeight/2) + layerMenu:addChild(menuTools) + + return layerMenu +end + +return GameScene diff --git a/templates/lua-template-runtime/src/hello2.lua b/templates/lua-template-runtime/src/hello2.lua deleted file mode 100644 index 27158aa788..0000000000 --- a/templates/lua-template-runtime/src/hello2.lua +++ /dev/null @@ -1,3 +0,0 @@ -function myadd(x, y) - return x + y -end \ No newline at end of file diff --git a/templates/lua-template-runtime/src/main.lua b/templates/lua-template-runtime/src/main.lua index a270259bf4..32f49d9378 100644 --- a/templates/lua-template-runtime/src/main.lua +++ b/templates/lua-template-runtime/src/main.lua @@ -1,8 +1,8 @@ + require "Cocos2d" -require "Cocos2dConstants" -- cclog -cclog = function(...) +local cclog = function(...) print(string.format(...)) end @@ -20,209 +20,21 @@ local function main() -- avoid memory leak collectgarbage("setpause", 100) collectgarbage("setstepmul", 5000) + + cc.FileUtils:getInstance():addSearchPath("src") + cc.FileUtils:getInstance():addSearchPath("res") cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(480, 320, 0) - cc.FileUtils:getInstance():addSearchPath("src") - cc.FileUtils:getInstance():addSearchPath("res") - local schedulerID = 0 - --support debug - local targetPlatform = cc.Application:getInstance():getTargetPlatform() - if (cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform) or - (cc.PLATFORM_OS_ANDROID == targetPlatform) or (cc.PLATFORM_OS_WINDOWS == targetPlatform) or - (cc.PLATFORM_OS_MAC == targetPlatform) then - cclog("result is ") - --require('debugger')() - + + --create scene + local scene = require("GameScene") + local gameScene = scene.create() + gameScene:playBgMusic() + + if cc.Director:getInstance():getRunningScene() then + cc.Director:getInstance():replaceScene(gameScene) + else + cc.Director:getInstance():runWithScene(gameScene) end - require "hello2" - cclog("result is " .. myadd(1, 1)) - - --------------- - - local visibleSize = cc.Director:getInstance():getVisibleSize() - local origin = cc.Director:getInstance():getVisibleOrigin() - - -- add the moving dog - local function creatDog() - local frameWidth = 105 - local frameHeight = 95 - - -- create dog animate - local textureDog = cc.Director:getInstance():getTextureCache():addImage("dog.png") - local rect = cc.rect(0, 0, frameWidth, frameHeight) - local frame0 = cc.SpriteFrame:createWithTexture(textureDog, rect) - rect = cc.rect(frameWidth, 0, frameWidth, frameHeight) - local frame1 = cc.SpriteFrame:createWithTexture(textureDog, rect) - - local spriteDog = cc.Sprite:createWithSpriteFrame(frame0) - spriteDog.isPaused = false - spriteDog:setPosition(origin.x, origin.y + visibleSize.height / 4 * 3) ---[[ - local animFrames = CCArray:create() - - animFrames:addObject(frame0) - animFrames:addObject(frame1) -]]-- - - local animation = cc.Animation:createWithSpriteFrames({frame0,frame1}, 0.5) - local animate = cc.Animate:create(animation); - spriteDog:runAction(cc.RepeatForever:create(animate)) - - -- moving dog at every frame - local function tick() - if spriteDog.isPaused then return end - local x, y = spriteDog:getPosition() - if x > origin.x + visibleSize.width then - x = origin.x - else - x = x + 1 - end - - spriteDog:setPositionX(x) - end - - schedulerID = cc.Director:getInstance():getScheduler():scheduleScriptFunc(tick, 0, false) - - return spriteDog - end - - -- create farm - local function createLayerFarm() - local layerFarm = cc.Layer:create() - - -- add in farm background - local bg = cc.Sprite:create("farm.jpg") - bg:setPosition(origin.x + visibleSize.width / 2 + 80, origin.y + visibleSize.height / 2) - layerFarm:addChild(bg) - - -- add land sprite - for i = 0, 3 do - for j = 0, 1 do - local spriteLand = cc.Sprite:create("land.png") - spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2) - layerFarm:addChild(spriteLand) - end - end - - -- add crop - local frameCrop = cc.SpriteFrame:create("crop.png", cc.rect(0, 0, 105, 95)) - for i = 0, 3 do - for j = 0, 1 do - local spriteCrop = cc.Sprite:createWithSpriteFrame(frameCrop); - spriteCrop:setPosition(10 + 200 + j * 180 - i % 2 * 90, 30 + 10 + i * 95 / 2) - layerFarm:addChild(spriteCrop) - end - end - - -- add moving dog - local spriteDog = creatDog() - layerFarm:addChild(spriteDog) - - -- handing touch events - local touchBeginPoint = nil - local function onTouchBegan(touch, event) - local location = touch:getLocation() - --cclog("onTouchBegan: %0.2f, %0.2f", location.x, location.y) - touchBeginPoint = {x = location.x, y = location.y} - spriteDog.isPaused = true - -- CCTOUCHBEGAN event must return true - return true - end - - local function onTouchMoved(touch, event) - local location = touch:getLocation() - --cclog("onTouchMoved: %0.2f, %0.2f", location.x, location.y) - if touchBeginPoint then - local cx, cy = layerFarm:getPosition() - layerFarm:setPosition(cx + location.x - touchBeginPoint.x, - cy + location.y - touchBeginPoint.y) - touchBeginPoint = {x = location.x, y = location.y} - end - end - - local function onTouchEnded(touch, event) - local location = touch:getLocation() - --cclog("onTouchEnded: %0.2f, %0.2f", location.x, location.y) - touchBeginPoint = nil - spriteDog.isPaused = false - end - - local listener = cc.EventListenerTouchOneByOne:create() - listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) - listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED ) - listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED ) - local eventDispatcher = layerFarm:getEventDispatcher() - eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layerFarm) - - local function onNodeEvent(event) - if "exit" == event then - cc.Director:getInstance():getScheduler():unscheduleScriptEntry(schedulerID) - end - end - layerFarm:registerScriptHandler(onNodeEvent) - - return layerFarm - end - - - -- create menu - local function createLayerMenu() - local layerMenu = cc.Layer:create() - - local menuPopup, menuTools, effectID - - local function menuCallbackClosePopup() - -- stop test sound effect - cc.SimpleAudioEngine:getInstance():stopEffect(effectID) - menuPopup:setVisible(false) - end - - local function menuCallbackOpenPopup() - -- loop test sound effect - local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav") - effectID = cc.SimpleAudioEngine:getInstance():playEffect(effectPath) - menuPopup:setVisible(true) - end - - -- add a popup menu - local menuPopupItem = cc.MenuItemImage:create("menu2.png", "menu2.png") - menuPopupItem:setPosition(0, 0) - menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) - menuPopup = cc.Menu:create(menuPopupItem) - menuPopup:setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2) - menuPopup:setVisible(false) - layerMenu:addChild(menuPopup) - - -- add the left-bottom "tools" menu to invoke menuPopup - local menuToolsItem = cc.MenuItemImage:create("menu1.png", "menu1.png") - menuToolsItem:setPosition(0, 0) - menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup) - menuTools = cc.Menu:create(menuToolsItem) - local itemWidth = menuToolsItem:getContentSize().width - local itemHeight = menuToolsItem:getContentSize().height - menuTools:setPosition(origin.x + itemWidth/2, origin.y + itemHeight/2) - layerMenu:addChild(menuTools) - - return layerMenu - end - - -- play background music, preload effect - - -- uncomment below for the BlackBerry version - local bgMusicPath = cc.FileUtils:getInstance():fullPathForFilename("background.mp3") - cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath, true) - local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav") - cc.SimpleAudioEngine:getInstance():preloadEffect(effectPath) - - -- run - local sceneGame = cc.Scene:create() - sceneGame:addChild(createLayerFarm()) - sceneGame:addChild(createLayerMenu()) - - if cc.Director:getInstance():getRunningScene() then - cc.Director:getInstance():replaceScene(sceneGame) - else - cc.Director:getInstance():runWithScene(sceneGame) - end end