-- 创建商店类,继承了Behavior local UIShopController = class("UIShopController", Behavior); -- 包含并引用系统提示框 local SystemPrompt = require(__APP_PACKAGE_NAME__ .. ".scenes.common.SystemPrompt") -- 包含引用其他界面 local UIGoodsInfoController = require(__APP_PACKAGE_NAME__ .. ".scenes.mainScene.uiShop.UIGoodsInfoController"); -- 相当于构造函数 function UIShopController:ctor( ) -- 调用父类的构造函数 UIShopController.super.ctor(self); -- 定义一些成员变量 self.Name = "UIShopController" self.numPerLine = 3 self.gridXInterval = 165 self.gridYInterval = 180 self.scheduleId = nil self.initCDTime = 0 self.gFlag = 0 self.selectImageViewItem = nil self.lebRefreshTime = nil; self.tabMGray = {}; end function UIShopController:onAwake( ) -- 这里初始化部件 self:initWidget(); end function UIShopController:onEnter( ) SceneM.createNetLayer(); -- 注册事件消息 self.owner:registerGlobalEvent(MsgID.msgid_P_OPSHOP_ACK, function ( params ) SceneM.destroyNetLayer(); self:showData(); self.owner:unRegisterGlobalEvent(MsgID.msgid_P_OPSHOP_ACK, self.id); end, self.id); -- 这里向服务器发送消息,msgid_P_OPSHOP_REQ这是个宏定义,后缀REQ表示请求, -- 服务器返回回来的消息是ACK,msgid_P_OPSHOP_ACK,这里也通过这个ACK来注册事件消息 local msg = {Ext = 0}; NetController:sendMsg(MsgID.msgid_P_OPSHOP_REQ,CJson.encode(msg)); end -- 这里在退出界面的时候会调用,释放一些资源 function UIShopController:onExit( ) if self.selectMask ~= nil then self.selectMask:release() end -- 卸载事件 self.owner:unRegisterGlobalEvent("onBuy", self.id); if self.scheduleId ~= nil then -- 卸载定时器 CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry(self.scheduleId); end end