From 3aeba770d1dcba3f02be97c1fdadaa7754dbaa0d Mon Sep 17 00:00:00 2001 From: JCGit <1027718562@qq.com> Date: Sun, 18 Sep 2016 03:16:28 -0700 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86mvc?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/README | 6 +- client/src/app/MyApp.lua | 14 ++- client/src/app/scenes/MainScene.lua | 19 ---- client/src/config.lua | 2 +- client/src/framework/cc/mvc/AppBase.lua | 1 + client/src/framework/functions.lua | 7 +- client/src/packages/global.lua | 23 +---- client/src/packages/mvc/controlbase.lua | 8 +- client/src/packages/mvc/layoutbase.lua | 131 ++---------------------- client/src/packages/mvc/mvc.lua | 38 +++++-- client/src/packages/mvc/panelbase.lua | 101 ------------------ client/src/packages/mvc/scenebase.lua | 82 ++------------- client/src/packages/mvc/uibox.lua | 82 --------------- client/src/packages/network/session.lua | 14 +-- client/src/packages/ui/uihelper.lua | 102 ------------------ client/src/packages/upder/updView.lua | 22 ++-- client/src/packages/upder/upder.lua | 22 ++-- client/src/packages/utils/logger.lua | 14 --- client/src/packages/utils/utils.lua | 1 + 19 files changed, 111 insertions(+), 578 deletions(-) delete mode 100644 client/src/app/scenes/MainScene.lua delete mode 100644 client/src/packages/mvc/panelbase.lua delete mode 100644 client/src/packages/mvc/uibox.lua delete mode 100644 client/src/packages/ui/uihelper.lua diff --git a/client/src/README b/client/src/README index 51c72b3..2d1059c 100644 --- a/client/src/README +++ b/client/src/README @@ -20,10 +20,12 @@ packages.utils,及其子集lfs, logger等。 packages.mvc, 及其子集uibox, layoutbase等。 -2、引用外部库函数,采用"库名_函数名"形式。 +2、引用外部库函数,采用"库名_函数名"形式, +对packages的引用,采用"库名"形式 如: -引用 cc.Layer -> local cc_layer = cc.Layer +引用 cc.Layer -> local cc_layer = cc.Layer +引用 utils.logger -> local logger = g.logger 3、成员变量,采用"_驼峰"形式, 局部变量,采用驼峰形式。 diff --git a/client/src/app/MyApp.lua b/client/src/app/MyApp.lua index edb2126..e9d9ae4 100644 --- a/client/src/app/MyApp.lua +++ b/client/src/app/MyApp.lua @@ -12,7 +12,19 @@ end function MyApp:run() cc.FileUtils:getInstance():addSearchPath("res/") - self:enterScene("MainScene") + + -- self:enterScene("LoginScene") + + local loginScene = require("app.Login.LoginScene") + -- local loginScene = g.mvc.SceneBase + local scene = loginScene.new() + display.replaceScene(scene) + + -- local scenebase = g.mvc.SceneBase + + -- local scene = scenebase.new() + + end return MyApp diff --git a/client/src/app/scenes/MainScene.lua b/client/src/app/scenes/MainScene.lua deleted file mode 100644 index 1dc78af..0000000 --- a/client/src/app/scenes/MainScene.lua +++ /dev/null @@ -1,19 +0,0 @@ - -local MainScene = class("MainScene", function() - return display.newScene("MainScene") -end) - -function MainScene:ctor() - cc.ui.UILabel.new({ - UILabelType = 2, text = "Hello, World", size = 64}) - :align(display.CENTER, display.cx, display.cy) - :addTo(self) -end - -function MainScene:onEnter() -end - -function MainScene:onExit() -end - -return MainScene diff --git a/client/src/config.lua b/client/src/config.lua index 4c35980..92a2dfd 100644 --- a/client/src/config.lua +++ b/client/src/config.lua @@ -1,6 +1,6 @@ -- 0 - disable debug info, 1 - less debug info, 2 - verbose debug info -DEBUG = 1 +DEBUG = 2 -- display FPS stats on screen DEBUG_FPS = true diff --git a/client/src/framework/cc/mvc/AppBase.lua b/client/src/framework/cc/mvc/AppBase.lua index 64751de..a0852eb 100644 --- a/client/src/framework/cc/mvc/AppBase.lua +++ b/client/src/framework/cc/mvc/AppBase.lua @@ -39,6 +39,7 @@ function AppBase:enterScene(sceneName, args, transitionType, time, more) local sceneClass = require(scenePackageName) local scene = sceneClass.new(unpack(checktable(args))) display.replaceScene(scene, transitionType, time, more) + return scene end function AppBase:createView(viewName, ...) diff --git a/client/src/framework/functions.lua b/client/src/framework/functions.lua index c575d43..0c36dfc 100644 --- a/client/src/framework/functions.lua +++ b/client/src/framework/functions.lua @@ -282,9 +282,10 @@ end ]] function class(classname, super) + local superType = type(super) local cls - + -- print(superType) if superType ~= "function" and superType ~= "table" then superType = nil super = nil @@ -336,6 +337,10 @@ function class(classname, super) instance:ctor(...) return instance end + + function cls.create(...) + return cls.new(...) + end end return cls diff --git a/client/src/packages/global.lua b/client/src/packages/global.lua index e7ef416..fde5e79 100644 --- a/client/src/packages/global.lua +++ b/client/src/packages/global.lua @@ -1,13 +1,13 @@ --1、extand lua --- require('packages.extands.functions') --- require('packages.extands.string') +require('packages.extands.functions') +require('packages.extands.string') require('packages.extands.table') --2、extand cc --- require('packages.extands.ListenerEx') --- require('packages.extands.ListViewEx') +require('packages.extands.ListenerEx') +require('packages.extands.ListViewEx') -- require('packages.extands.TableViewEx') --3、global @@ -17,21 +17,8 @@ cc.exports.g = g table.merge(g, cc.load("utils")) ---[[ --- test logger -local t = {a=1, b=2} -g.logger.n("11") -g.logger.i("22") - -g.logger.f("%d", 33) -g.logger.w("44") --- g.logger.e("55") -]] - -g.eventcenter = cc.load("eventcenter") - g.mvc = cc.load("mvc") --- g.logger.d(g.mvc) +g.logger.d(g.mvc) diff --git a/client/src/packages/mvc/controlbase.lua b/client/src/packages/mvc/controlbase.lua index 1ad05d3..dd44eb6 100644 --- a/client/src/packages/mvc/controlbase.lua +++ b/client/src/packages/mvc/controlbase.lua @@ -1,11 +1,9 @@ local controlbase = class("controlbase") function controlbase:ctor( ) - - if self.onCreate then - self:onCreate() - self:load() - end + + if self.onCreate then self:onCreate() end + end function controlbase:load() diff --git a/client/src/packages/mvc/layoutbase.lua b/client/src/packages/mvc/layoutbase.lua index 1196c18..aad24ca 100644 --- a/client/src/packages/mvc/layoutbase.lua +++ b/client/src/packages/mvc/layoutbase.lua @@ -1,13 +1,6 @@ ---[[ -@author : jc -@log : -@todo : -1、LayoutBase的enableNodeEvents,resetWidgetText,onLocateClickCallback等方法,extend widget后重写。 - -]] -local ccui_layout = ccui.layout -local lang_text = nil--g.mgr.tablemgr.getTextByKey -local layoutbase = class("layoutbase", ccui.Layout) +local layoutbase = class("layoutbase", function () + return display.newLayer() +end) function layoutbase:ctor(...) if self.onCreate then self:onCreate(...) end @@ -29,13 +22,8 @@ function layoutbase:createCSBNode(filename) assert(self._csbNode, string.format("layoutbase:createCSBNode load resouce node from file \"%s\" failed", filename)) self:addChild(self._csbNode) - self:enableNodeEvents() - -- 重定向点击事件 self:registerLayoutHandlers() - - --重设控件的文本 - self:resetWidgetText() return self._csbNode end @@ -45,81 +33,6 @@ function layoutbase:createCSBNode(filename) end end -function layoutbase:enableNodeEvents() - if self.enableNodeEvent then - return self - end - - self:registerScriptHandler( function(state) - if state == "enter" and self.onEnter then - self:onEnter() - elseif state == "exit" then - if self.onExit then - self:onExit() - end - if self.onEnxitUnifiedCallBack then - self:onEnxitUnifiedCallBack() - end - elseif state == "enterTransitionFinish" then - if self.onEnterTransitionFinish then - self:onEnterTransitionFinish() - end - if self.onEnterFinishUnifiedCallBack then - self:onEnterFinishUnifiedCallBack() - end - elseif state == "exitTransitionStart" and self.onExitTransitionStart then - self:onExitTransitionStart() - elseif state == "cleanup" and self.onCleanup then - self:onCleanup() - end - end ) - self.enableNodeEvent = true - - return self -end - -function layoutbase:disableNodeEvents() - self:unregisterScriptHandler() - self.enableNodeEvent = false - return self -end - -function layoutbase:resetWidgetText() - - local widgetType = { - WIDGET_BUTTON = 1, - WIDGET_LABLE = 2, - WIDGET_TEXTFIELD = 3, - } - - local textReflect - textReflect = function(node) - - local children = node:getChildren() - for _, v in ipairs(children) do - if v.getCustomProperty then - local key = v:getCustomProperty() - if key ~= '' then - local langtext = lang_text(key) - - local Type = v:getWidgetType() - if widgetType.WIDGET_BUTTON == Type then - v:setTitleText(langtext) - elseif widgetType.WIDGET_LABLE == Type then - v:setString(langtext) - elseif widgetType.WIDGET_TEXTFIELD == Type then - v:setString(langtext) - end - end - end - - textReflect(v) - end - end - - textReflect(self._csbNode) -end - function layoutbase:registerLayoutHandlers() if not self.option then @@ -131,17 +44,13 @@ function layoutbase:registerLayoutHandlers() end local handlers = self.option.handlerMap - self.onDispatch = function(_func, _sender) + self.onDispatch = function(cb, _sender) - local callback = handlers[_func] - if not callback then - logf("layoutbase registerLayout find no handler,evtName:%s!", evtName) - else + local callback = handlers[cb] + if callback then local f =function() if self[callback] then - self[callback](self, _sender, _func) - else - logf("layoutbase registerLayout find no handler,callback:%s!", callback) + self[callback](self, _sender, cb) end end @@ -158,20 +67,13 @@ function layoutbase:registerLayoutHandlers() if v.getCallbackName then tolua.cast(v, "ccui.Widget") - local _func = v:getCallbackName() - if _func and _func ~= "" then - handlers[_func] = _func + local cb = v:getCallbackName() + if cb and cb ~= "" then + handlers[cb] = cb v:addClickEventListener(function (_sender) -- 分发触摸事件 - - --[[ if _func == "onBack" then - g.mgr.soundMgr:playEffectSound("commonBack") - else - g.mgr.soundMgr:playEffectSound("commonClick") - end - ]] -- - self.onDispatch(_func, _sender) + self.onDispatch(cb, _sender) end) end end @@ -189,13 +91,6 @@ function layoutbase:getCsbName() return self._csbName or "" end -function layoutbase:getLayoutTag() - local arr = string.split(self._csbName, '/') - local panel = string.split(arr[3], '.')[1] - local tag = string.format("app.%s.%s.%s", arr[1], arr[2], panel) - return tag -end - function layoutbase:getChildByName(name) return self._csbNode:getChildByName(name) end @@ -204,8 +99,4 @@ function layoutbase:getChildByTag(tag) return self._csbNode:getChildByTag(tag) end -function layoutbase:seekWidgetByName(name) - return uihelper.seekWidgetByName(self._csbNode, name) -end - return layoutbase \ No newline at end of file diff --git a/client/src/packages/mvc/mvc.lua b/client/src/packages/mvc/mvc.lua index 813029d..da6fccc 100644 --- a/client/src/packages/mvc/mvc.lua +++ b/client/src/packages/mvc/mvc.lua @@ -1,12 +1,32 @@ +local mvc = cc.mvc -local _M = {} +--TODO: 扩展viewBase +-- local ViewBase = import("") -_M.layoutbase = import(".layoutbase") -_M.panelbase = import(".panelbase") -_M.scenebase = import(".scenebase") -_M.proxybase = import(".proxybase") -_M.controlbase = import(".controlbase") --- _M.BaseTips = import(".BaseTips") --- _M.BaseCache = import(".BaseCache") +--TODO: 扩展ViewMgr +-- local ViewMgr = import("") -return _M \ No newline at end of file +--TODO: 扩展SceneBase +local SceneBase = import(".scenebase") + +--TODO: 扩展SceneMgr +-- local SceneMgr = import("") + +mvc.ViewBase = ViewBase +mvc.SceneBase = SceneBase + +return mvc, SceneMgr +--[[ + scenemgr + | \ + | \ + | \ + scene1 scene2 + | + | + | + viewmgr + | \ + | \ + view1 view2 +]] \ No newline at end of file diff --git a/client/src/packages/mvc/panelbase.lua b/client/src/packages/mvc/panelbase.lua deleted file mode 100644 index b88cfbe..0000000 --- a/client/src/packages/mvc/panelbase.lua +++ /dev/null @@ -1,101 +0,0 @@ -local layoutbase = import(".layoutbase") -local scenebase = import(".scenebase") -local panelbase = class("panelbase", layoutbase) - -function panelbase:onEnterTransitionFinish() - - self._curOpened = true - - self:setContentSize(display.size) -end - -function panelbase:onExit() - self._curOpened = false -end - -function panelbase:onEnterFinishUnifiedCallBack() - --print("onEnterFinishUnifiedCallBack",self.__cname) - g.eventcore:dispatch(g.mainEvent.onShowView , self.__cname) -end - -function panelbase:onEnxitUnifiedCallBack() - --print("onEnxitUnifiedCallBack",self.__cname) - g.eventcore:dispatch(g.mainEvent.onExitView , self.__cname) -end - - -function panelbase:open() - if self._curOpened then return end - local sceneManager = g.mgr.scenemgr - local scene = sceneManager:getCurScene() - - if scene:getViewByViewName(self.__cname) then - return - end - - local box = scene:getChildByTag(scenebase.eLayerID.ELAYER_BOX) - assert(box, "panelbase:open ui, no box-layer.") - - self:setTouchEnabled(true) - - scene:setView(self , true) - - box:add(self) -end - -function panelbase:close() - - if not self._curOpened then return end - local sceneManager = g.mgr.scenemgr - local scene = sceneManager:getCurScene() - - if not scene:getViewByViewName(self.__cname) then - --print("\n") - --logw(string.format("\n---------------------------------------------------------\nthe view is not exist %s\n---------------------------------------------------------\n",self.__cname )) - return - end - - local box = scene:getChildByTag(scenebase.eLayerID.ELAYER_BOX) - assert(box, "panelbase:close ui, no box-layer.") - - if self.clear then - self:clear() - end - - box:remove(self) -end - -function panelbase:remove() - local sceneManager = g.mgr.scenemgr - local scene = sceneManager:getCurScene() - scene:setView(self , false) - self:removeFromParent() -end - -function panelbase:refresh() - -- body -end - -function panelbase:cover() - -- body -end - -function panelbase:getIsOpen() - return self._curOpened or false -end - -function panelbase:enableCover(bClickClose, callBack) - self:setBackGroundColorType(LAYOUT_COLOR_SOLID) - self:setBackGroundColor(cc.c3b(0,0,0)) - self:setBackGroundColorOpacity(150) - - if bClickClose then - self:addClickEventListener(function(self) - if callBack then - callBack() - end - end) - end -end - -return panelbase diff --git a/client/src/packages/mvc/scenebase.lua b/client/src/packages/mvc/scenebase.lua index 453f510..45bf4ff 100644 --- a/client/src/packages/mvc/scenebase.lua +++ b/client/src/packages/mvc/scenebase.lua @@ -1,7 +1,8 @@ -local scenebase = class("scenebase", cc.Scene) -local uibox = import(".uibox") +local scenebase = class("scenebase", function() + return display.newScene("scenebase") +end) -scenebase.eLayerID ={ +local eLayerID ={ ELAYER_GAME = 0, -- 场景层,战斗地图或背景ui ELAYER_WIDGET = 1, -- 场景部件层 ELAYER_BOX = 2, -- ui管理层 @@ -12,53 +13,19 @@ scenebase.eLayerID ={ } function scenebase:ctor(...) - self:enableNodeEvents() - - self._viewSet = {} - - self._clickEventMap = {} - setmetatable(self._clickEventMap, {__mode = "k"}) - self._touchEventMap = {} - setmetatable(self._touchEventMap, {__mode = "k"}) - - self._listenerCount = 0 if self.onCreate then self:onCreate(...) end end -function scenebase:enableNodeEvents() - if self._enableNodeEvent then - return self - end - - self:registerScriptHandler( function(state) - if state == "enter" and self.onEnter then - self:onEnter() - elseif state == "exit" and self.onExit then - self:onExit() - elseif state == "enterTransitionFinish" and self.onEnterTransitionFinish then - self:onEnterTransitionFinish() - elseif state == "exitTransitionStart" and self.onExitTransitionStart then - self:onExitTransitionStart() - elseif state == "cleanup" and self.onCleanup then - self:onCleanup() - end - end ) - self._enableNodeEvent = true - - return self -end - function scenebase:createLayer(layerid) - local layer = nil + local layer + if layerid == self.eLayerID.ELAYER_BOX then - layer = uibox:create() elseif layerid == self.eLayerID.ELAYER_TIPS then - layer = uibox:create() - cc.Director:getInstance():setNotificationNode(layer) else layer = cc.Layer:create() end + return layer end @@ -83,46 +50,13 @@ function scenebase:addLayer(layerid) assert(layer, string.format("scenebase createLayer layer:%d error.", layerid)) local zorder = self:getLayerZOrder(layerid) - if self.eLayerID.ELAYER_TIPS == layerid then - layer:removeFromParent() - end self:addChild(layer, zorder, layerid) + return layer end return child end - -function scenebase:setView(view , isStore) - self._viewSet[view.__cname] = isStore and view or nil -end - -function scenebase:getViewByViewName(viewName) - assert(type(viewName) == "string" , " viewName type is wrong") - return self._viewSet[viewName] -end - -function scenebase:setStoreClickEvent(widget , event) - self._listenerCount = self._listenerCount + 1 - --print("setStoreClickEvent" , self._listenerCount , self.__cname) - self._clickEventMap[widget] = event -end - -function scenebase:getClickEvent(widget ) - return self._clickEventMap[widget] -end - -function scenebase:setStoreTouchEvent(widget ,event) - self._listenerCount = self._listenerCount + 1 - --print("setStoreTouchEvent" , self._listenerCount , self.__cname) - self._touchEventMap[widget] = event - -end - -function scenebase:getTouchEvent(widget) - return self._touchEventMap[widget] -end - function scenebase:getSceneID() return self.sceneID_ or 0 end diff --git a/client/src/packages/mvc/uibox.lua b/client/src/packages/mvc/uibox.lua deleted file mode 100644 index 2143871..0000000 --- a/client/src/packages/mvc/uibox.lua +++ /dev/null @@ -1,82 +0,0 @@ -local cc_layer = cc.Layer - -local uibox = class("uibox", cc_layer) - -function uibox:ctor() - - local director = cc.Director:getInstance() - local origin = director:getVisibleOrigin() - local size = director:getVisibleSize() - - local container = ccui.Layout:create() - container:setContentSize(size) - container:setPosition(origin) - container:setLocalZOrder(-1) - self:addChild(container) - - self._container = container - self._box = {} -end - -function uibox:add(layer) - if layer and not layer:getParent() then - local box = self._box - local idx = #box - - if box[idx] and box[idx].cover then - box[idx]:cover() - end - self._container:addChild(layer) - table.insert(box, layer) - end -end - - -function uibox:addSystem(bar) - self._container:addChild(bar) -end - - -function uibox:remove(layer) - if not layer or not layer:getParent() then - return - end - local box = self._box - local last = #box - for i,v in ipairs(box) do - if v == layer then - if i == last then - if box[i - 1] and box[i-1].refresh then - box[i - 1]:refresh() - end - end - table.remove(box, i) - layer:remove() - break - end - end -end - - -function uibox:clean() - for i,v in ipairs(self._box) do - if v.clear then - v:clear() - end - v:remove() - end - self._box = {} -end - - -function uibox:checkOnTop(layer) - local box = self._box - - if layer and layer:getParent() == self._container and #box > 0 then - return box[#box-1] == layer - end - return false -end - - -return uibox \ No newline at end of file diff --git a/client/src/packages/network/session.lua b/client/src/packages/network/session.lua index 0e63b49..0f57ace 100644 --- a/client/src/packages/network/session.lua +++ b/client/src/packages/network/session.lua @@ -112,7 +112,7 @@ function Session:close(noMsg) end if self.tickScheduler then scheduler:unscheduleScriptEntry(self.tickScheduler) end if not noMsg then - g.eventcore:dispatchEvent({name=netevent.EVT_CLOSE}) + g.eventcenter:dispatchEvent({name=netevent.EVT_CLOSE}) end end @@ -139,13 +139,13 @@ end function Session:_disconnect() self.isConnected = false self.tcp:shutdown() - g.eventcore:dispatchEvent({name=netevent.EVT_CLOSE}) + g.eventcenter:dispatchEvent({name=netevent.EVT_CLOSE}) end function Session:_onDisconnect() --printInfo("%s._onDisConnect", self.name); self.isConnected = false - g.eventcore:dispatchEvent({name=netevent.EVT_CLOSED}) + g.eventcenter:dispatchEvent({name=netevent.EVT_CLOSED}) -- self:_reconnect() end @@ -153,7 +153,7 @@ end function Session:_onConnected() --printInfo("%s._onConnectd", self.name) self.isConnected = true - g.eventcore:dispatchEvent({name=netevent.EVT_CONNECTED}) + g.eventcenter:dispatchEvent({name=netevent.EVT_CONNECTED}) if self.connectTimeTickScheduler then scheduler:unscheduleScriptEntry(self.connectTimeTickScheduler) @@ -173,7 +173,7 @@ function Session:_onConnected() end function Session:_connectFailure(status) - g.eventcore:dispatchEvent({name=netevent.EVT_CONNECT_FAIL}) + g.eventcenter:dispatchEvent({name=netevent.EVT_CONNECT_FAIL}) -- self:_reconnect() end @@ -249,7 +249,7 @@ function Session:recvMsg() --logi(string.format("now received:%d.", recved)) end - g.eventcore:dispatchEvent({name=netevent.EVT_MESSAGE, data=self.msg}) + g.eventcenter:dispatchEvent({name=netevent.EVT_MESSAGE, data=self.msg}) self.msg = "" end @@ -262,7 +262,7 @@ function Session:recvLine() local msg = self:validMsg(body, partial) if not msg then return end - g.eventcore:dispatchEvent({name=netevent.EVT_DATA, data=msg}) + g.eventcenter:dispatchEvent({name=netevent.EVT_DATA, data=msg}) end return Session diff --git a/client/src/packages/ui/uihelper.lua b/client/src/packages/ui/uihelper.lua deleted file mode 100644 index 985ae1e..0000000 --- a/client/src/packages/ui/uihelper.lua +++ /dev/null @@ -1,102 +0,0 @@ -local string_format = string.format - - -local uihelper = {} - -function uihelper.seekWidgetByName(root, name) - - local recurse - recurse = function (root_, name) - local nodename = root_:getName() - if nodename == name then return root_ end - - local children = root_:getChildren() - -- print(nodename, #children, name) - for k,v in pairs(children) do - local res = recurse(v, name) - if res then - return res - end - end - return nil - end - - if not root then return nil end - return recurse(root, name) -end - -function uihelper.loadTexture(target, uitype, icon, packtype) - assert(type(uitype) == 'string', 'uitype should be sprite/image/button.') - - local f = function () - local loadFunc - if uitype == 'sprite' then - target:setTexture(icon) - return - elseif uitype == 'image' then - loadFunc = target.loadTexture - elseif uitype == 'button' then - loadFunc = target.loadTextureNormal - end - - assert(loadFunc, 'error target setTexture function.') - loadFunc(target, icon, packtype) - end - - local ok, r = xpcall(f, __G__TRACKBACK__) - if not ok then - logw(string.format('texture icon:%s.', icon)) - print(r) - end -end - ---[[ - param = { - name - actionName - isLoop 0 not loop ; >0 loop ; <0 from the design - frameCall - endCall - timeScale - pos - parent - bPlay - } -]] -function uihelper.createArmature(param) - assert(type(param) == "table" , "param type is wrong") - assert(type(param.name) == "string" , "armature name type is wrong") - local isLoop = param.isLoop or -1 - local actionName = param.actionName or "play" - local armature = {} - cc.bind(armature, "animation") - - armature:createArmature(param.name) - - if param.bPlay == nil or param.bPlay == true then - armature:playAnimation(actionName , -1 , isLoop) - end - - local target = armature:getArmature() - - if param.pos then - target:setPosition(param.pos) - end - - if param.endCall then - target:getAnimation():setMovementEventCallFunc(param.endCall) - end - - if param.frameCall then - target:getAnimation():setFrameEventCallFunc(param.frameCall) - end - if param.timeScale then - target:getAnimation():setSpeedScale(param.timeScale) - end - if param.parent then - param.parent:addChild(target) - end - return target , armature -end - -return uihelper \ No newline at end of file diff --git a/client/src/packages/upder/updView.lua b/client/src/packages/upder/updView.lua index 168d857..8fbf8b2 100644 --- a/client/src/packages/upder/updView.lua +++ b/client/src/packages/upder/updView.lua @@ -24,19 +24,19 @@ function UpdView:onCreate() self.downingText = self:seekWidgetByName('Text_2') self.progress = self:seekWidgetByName('LoadingBar_1') - g.eventcore:addEventListener("ME_CHECK_VERLIST", handler(self, self.checkVerlist)) - g.eventcore:addEventListener("ME_DOWNLOAD_ZIPS", handler(self, self.downloadZips)) - g.eventcore:addEventListener("ME_DOWNLOAD_OVER", handler(self, self.downloadOver)) - g.eventcore:addEventListener("ME_DOWNLOAD_SO_OVER", handler(self, self.downloadSoOver)) - g.eventcore:addEventListener("ME_DOWNLOAD_APK", handler(self, self.downloadApkTip)) + g.eventcenter:addEventListener("ME_CHECK_VERLIST", handler(self, self.checkVerlist)) + g.eventcenter:addEventListener("ME_DOWNLOAD_ZIPS", handler(self, self.downloadZips)) + g.eventcenter:addEventListener("ME_DOWNLOAD_OVER", handler(self, self.downloadOver)) + g.eventcenter:addEventListener("ME_DOWNLOAD_SO_OVER", handler(self, self.downloadSoOver)) + g.eventcenter:addEventListener("ME_DOWNLOAD_APK", handler(self, self.downloadApkTip)) end function UpdView:clear() - g.eventcore:removeEventListenersByEvent("ME_CHECK_VERLIST") - g.eventcore:removeEventListenersByEvent("ME_DOWNLOAD_ZIPS") - g.eventcore:removeEventListenersByEvent("ME_DOWNLOAD_OVER") - g.eventcore:removeEventListenersByEvent("ME_DOWNLOAD_SO_OVER") - g.eventcore:removeEventListenersByEvent("ME_DOWNLOAD_APK") + g.eventcenter:removeEventListenersByEvent("ME_CHECK_VERLIST") + g.eventcenter:removeEventListenersByEvent("ME_DOWNLOAD_ZIPS") + g.eventcenter:removeEventListenersByEvent("ME_DOWNLOAD_OVER") + g.eventcenter:removeEventListenersByEvent("ME_DOWNLOAD_SO_OVER") + g.eventcenter:removeEventListenersByEvent("ME_DOWNLOAD_APK") end function UpdView:checkVerlist(event) @@ -179,7 +179,7 @@ function UpdView:showCheckUpd(fileSize) self.checkBox:setVisible(false) self.downInfo:setVisible(true) - g.eventcore:dispatchEvent({name="ME_CONTINUE_UPDATE"}) + g.eventcenter:dispatchEvent({name="ME_CONTINUE_UPDATE"}) end end diff --git a/client/src/packages/upder/upder.lua b/client/src/packages/upder/upder.lua index 9a56a0b..6cf9990 100644 --- a/client/src/packages/upder/upder.lua +++ b/client/src/packages/upder/upder.lua @@ -18,7 +18,7 @@ local upder = class("upder") function upder:startUpdate() - g.eventcore:addEventListener("ME_CONTINUE_UPDATE", handler(self, self.doContinueUpdate)) + g.eventcenter:addEventListener("ME_CONTINUE_UPDATE", handler(self, self.doContinueUpdate)) self.view_ = UpdView:create() self.view_:retain() @@ -93,10 +93,10 @@ function upder:clear() self.view_:removeFromParent() end self.view_:release() - g.eventcore:removeEventListenersByEvent("ME_CONTINUE_UPDATE") + g.eventcenter:removeEventListenersByEvent("ME_CONTINUE_UPDATE") local LoginEvent = require("app.login.event.LoginEvent") - g.eventcore:dispatchEvent({name=LoginEvent.updateDone}) + g.eventcenter:dispatchEvent({name=LoginEvent.updateDone}) end function upder:checkVersion() @@ -186,11 +186,11 @@ function upder:checkVersion() end end - g.eventcore:dispatchEvent({name="ME_CHECK_VERLIST", info=stateinfo}) + g.eventcenter:dispatchEvent({name="ME_CHECK_VERLIST", info=stateinfo}) self.resumeUpdate() end - g.eventcore:dispatchEvent({name="ME_CHECK_VERLIST", info=stateinfo}) + g.eventcenter:dispatchEvent({name="ME_CHECK_VERLIST", info=stateinfo}) self.dlder.downloadFile(_option.URL_VER, _writePath, verlistCB) self.suspendUpdate() return ret @@ -213,7 +213,7 @@ function upder:downloadZip() received=params[2], expected=params[3] } - g.eventcore:dispatchEvent({name="ME_DOWNLOAD_ZIPS", info=stateinfo}) + g.eventcenter:dispatchEvent({name="ME_DOWNLOAD_ZIPS", info=stateinfo}) return elseif tag == 'fileError' then ret = false @@ -229,7 +229,7 @@ function upder:downloadZip() self:writeLocalVersion(ver, curTag) end - g.eventcore:dispatchEvent({name="ME_DOWNLOAD_ZIPS", info=stateinfo}) + g.eventcenter:dispatchEvent({name="ME_DOWNLOAD_ZIPS", info=stateinfo}) stateinfo.errcode = nil stateinfo.errstr = nil @@ -237,7 +237,7 @@ function upder:downloadZip() -- 更新完so后,用户自行重启游戏 if updType == "so" then - g.eventcore:dispatchEvent({name="ME_DOWNLOAD_SO_OVER"}) + g.eventcenter:dispatchEvent({name="ME_DOWNLOAD_SO_OVER"}) return end self.resumeUpdate() @@ -253,7 +253,7 @@ function upder:downloadZip() for k,v in pairs(ziplist) do if v.updType == "apk" or (v.updType == "so" and (CC_ENV_CONFIG == 1 or CC_ENV_CONFIG == 2)) then - g.eventcore:dispatchEvent({name="ME_DOWNLOAD_APK"}) + g.eventcenter:dispatchEvent({name="ME_DOWNLOAD_APK"}) self.suspendUpdate() break end @@ -281,7 +281,7 @@ function upder:downloadZip() end)() self.view_:open() - g.eventcore:dispatchEvent({name="ME_DOWNLOAD_ZIPS", info=stateinfo}) + g.eventcenter:dispatchEvent({name="ME_DOWNLOAD_ZIPS", info=stateinfo}) self.suspendUpdate() --小版本更新 @@ -298,7 +298,7 @@ function upder:downloadZip() end end - g.eventcore:dispatchEvent({name="ME_DOWNLOAD_OVER", info=stateinfo}) + g.eventcenter:dispatchEvent({name="ME_DOWNLOAD_OVER", info=stateinfo}) self.view_:close() return true end diff --git a/client/src/packages/utils/logger.lua b/client/src/packages/utils/logger.lua index 8f326d4..73ae202 100644 --- a/client/src/packages/utils/logger.lua +++ b/client/src/packages/utils/logger.lua @@ -22,20 +22,6 @@ _M.w = function(fmt, ...) print_log("WARN", fmt, ...) end ---[[ -_M.d = function(fmt, ...) - - if type(DEBUG) ~= "number" or DEBUG < 2 then return end - - local info = debug.getinfo(2) - print_info("----------------" .. info.name .. "------------------") - print_info("FilePosition :" .. info.source) - print_info("LineNum :" .. info.currentline) - print_log("DEBUG", fmt, ...) - print_info("------------------------------------------------------") -end -]] -- - _M.d = function(value, desciption, nesting) if type(nesting) ~= "number" then nesting = 4 end diff --git a/client/src/packages/utils/utils.lua b/client/src/packages/utils/utils.lua index 3c1a84c..6c61992 100644 --- a/client/src/packages/utils/utils.lua +++ b/client/src/packages/utils/utils.lua @@ -4,6 +4,7 @@ local _M = { logger = import(".logger"), simp2trad = import(".simp2trad"), timer = import(".timer"), + uihelper = import(".uihelper") } return _M