require("luaScript.test") -- 主界面 local MainReview = class("MainReview", cc.UIView) local targetPlatform = cc.Application:getInstance():getTargetPlatform() local IS_FIRST_LOGIN = true -- subGameId : 要打开的子游戏的界面 function MainReview:ctor(subGameId, club_room_id) MainReview.super.ctor(self) self.subGameId = subGameId self.club_room_id = club_room_id --是否正在显示通知界面标志 self.isShowTongZHiView = false self:loadUI() end function MainReview:loadUI() local ui = loadUI("res/ui/ui_dating/ui_dating_review.ui") self.ui = ui self:addChild(ui) end function MainReview:onEnter() MainReview.super.onEnter(self) self:initButton() -- 版本信息 self:initVersion() -- 玩家信息 self:initPlayerInfo() -- 滚动公告 startScrollTips(self.ui.Items.Text, 80, app.user.scroll, self.ui.Items.Layout_Text) -- 子游戏列表获取成功后更新列表 self:initSubGameList() self:initOpenClub() self:initReviewAndRuanZhu() self:initBindEvent() end --初始化是否打开俱乐部界面 function MainReview:initOpenClub() if self.subGameId then -- 是否打开茶馆大厅 if app.club_php.clubID and app.club_php.clubID > 0 then local view = import("luaScript.Views.Club.ClubMain"):new(); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end cc.UserDefault:getInstance():setBoolForKey("firstLogin",false) end end --初始化审核 软著相关 function MainReview:initReviewAndRuanZhu() -- 活动信息 -- 苹果审核模式 if not isIOSReviewVersion() then self:initActivity() end -- 软著模式 if isRuanZhu() then self:initWithRuanZhuVersion() end -- 苹果审核模式 if isIOSReviewVersion() then self:initWithIosReviewVersion() end end --初始化事件绑定 function MainReview:initBindEvent() --self:bindEvent(app.user, "onPhoneBindResponse", handler(self, self.onPhoneBindResponse)) -- 监听APP从后台回来的消息 logD("MainReview add onMainViewLoginSuccessed") self:bindEvent(app.user, "onMainViewLoginSuccessed" , handler(self, self.onLoginSuccessed)) self:bindEvent(app, "applicationWillEnterForeground" , handler(self, self.onLoginSuccessed)) --收到禁止同桌结果事件 self:bindEvent(app.club , "onClubNotSameDeskResponse" , handler(self , self.onClubNotSameDeskResponse)) --绑定消息通知回调 self:bindEvent(app.club_php , GAME_EVENT.CLUB_INVITE , handler(self , self.onClubIniteEvent)) end --初始按钮事件 function MainReview:initButton() -- 点击玩家头像 self.ui.Items.ImageView_Head:registerClick(handler(self, self.onClickPlayerHead)) -- 按钮 - 兑换金币 self.ui.Items.Button_AddGold:registerClick(handler(self, self.OnClickButtonAddGold)) -- 暂不提供兑换金币服务 self.ui.Items.Button_AddGold:setVisible(false) -- 按钮 - 充值房卡 self.ui.Items.Button_AddDiamand:registerClick(handler(self, self.OnClickButtonAddDiamand)) self.ui.Items.ImageView_Diamand:registerClick(handler(self, self.OnClickButtonAddDiamand)) -- 按钮 - 商城 self.ui.Items.Button_ShangCheng:registerClick(handler(self , self.onClickButtonShop)) local effect = createAnimationByPlist("res/ui/zy_dating/dating/shop_animation.plist","dt_shangcheng-animation3_%d.png",0,40,0.5) self.ui.Items.Button_ShangCheng:addChild(effect) local size = self.ui.Items.Button_ShangCheng:getContentSize() effect:setPosition(cc.p(size.width/2+20,size.height/2+10)) -- 按钮 - 活动 --self.ui.Items.Button_HuoDong:registerClick(handler(self , self.onClickButtonActive)) -- 按钮 - 战绩 self.ui.Items.Button_zhanji:registerClick(handler(self , self.onClickZhanji)) -- 按钮 - 玩法 self.ui.Items.Button_wanfa:registerClick(handler(self , self.onClickWanfa)) -- 按钮 - 邮箱 --self.ui.Items.Button_email:registerClick(handler(self , self.onClickButtonEmail)) -- 按钮 - 实名认证 self.ui.Items.Button_ShiMing:registerClick(handler(self , self.onClickButtonShiMing)) -- 按钮 - 快速开始 self.ui.Items.Button_Start:registerClick(handler(self , self.onClickButtonStart)) -- 按钮 - 向右滑动 self.ui.Items.Button_Right:registerClick(handler(self , self.onClickButtonRight)) self.ui.Items.Button_Right:setVisible(false) -- 按钮 - 邀请码 --self.ui.Items.Button_Yaoqing:registerClick(handler(self , self.onClickButtonInviteCode)) --self.ui.Items.Button_Yaoqing:setVisible(false) -- 按钮 - 绑定手机号码 --self.ui.Items.Button_PhoneNum:registerClick(handler(self , self.onClickButtonBindPhone)) --self:onPhoneBindResponse() -- 按钮 - 茶馆 self.ui.Items.Button_Club:registerClick(handler(self , self.onClickButtonClub)) -- 按钮 - 金币场 --self.ui.Items.Button_Gold:registerClick(handler(self , self.onClickButtonGold)) -- 按钮 - 招代理 --self.ui.Items.Button_daili:registerClick(handler(self , self.onClickButtonKeFu)) -- 按钮 - 测试 --self.ui.Items.Button_test:registerClick(handler(self , self.onClickTest)) --self.ui.Items.Button_test:setVisible(targetPlatform == 0) --更多 --self.ui.Items.Button_More:registerClick(handler(self , self.onClickMore)) --self.ui.Items.Layout_More:setVisible(false) --举报 self.ui.Items.Button_JuBao:registerClick(handler(self , self.onClickJuBao)) --领取现金 --self.ui.Items.Button_PrizeCash:registerClick(handler(self , self.onClickPrizeCash)) --创建房间 self.ui.Items.Button_Create:registerClick(handler(self , self.onClickMoreGame)) --分享 --self.ui.Items.Button_fenxiang:registerClick(handler(self , self.onClickShare)) -- 兑换金币 self.ui.Items.ImageView_Gold:setVisible(false) --隐藏专用房卡 self.ui.Items.Layout_Diamond:setVisible(false) self.ui.Items.Button_Diamond_Arrow:setVisible(false) local seq = cc.Sequence:create( cc.ScaleTo:create(0.16,0.95), cc.ScaleTo:create(0.16,1), cc.ScaleTo:create(0.16,0.95), cc.ScaleTo:create(0.16,1), cc.ScaleTo:create(0.16,0.95), cc.ScaleTo:create(0.16,1), cc.DelayTime:create(3.0) ) self.ui.Items.ImageView_More_Tip:runAction(cc.RepeatForever:create(seq)) end -- 软著模式 function MainReview:initWithRuanZhuVersion() -- 茶馆按钮 self.ui.Items.Button_Club:setTouchEnabled(false) -- 比赛按钮 --self.ui.Items.Button_Gold:setTouchEnabled(false) --修改图片 self.ui.Items.Button_Club:loadTextureNormal("dating_btn_club_ruanzhu.png",1) --self.ui.Items.Button_Gold:loadTextureNormal("dating_btn_bisai_ruanzhu.png",1) end -- 苹果审核模式 function MainReview:initWithIosReviewVersion() -- 兑换金币 self.ui.Items.ImageView_Gold:setVisible(false) -- 版本号 self.ui.Items.Layout_Version:setVisible(false) -- 比赛按钮 --self.ui.Items.Button_Gold:setTouchEnabled(false) --活动 --self.ui.Items.Layout_HuoDong:setVisible(false) --实名 --self.ui.Items.Layout_ShiMing:setVisible(false) -- 重新布局 self.ui.Items.Layout_menu:requestDoLayout() self.ui.Items.Layout_menu:doLayout() end -- 初始化游戏版本信息 function MainReview:initVersion() if isIOSReviewVersion() then self.ui.Items.Layout_Version:setVisible(false) return end self.ui.Items.Text_Type:setVisible(isDebug()) local appVersionNum = getAppVersionNum() local resVersion = loadVersion() self.ui.Items.Text_Version:setText("文明游戏,拒绝赌博 "..appVersionNum.."."..resVersion) end function MainReview:initPlayerInfo() -- 初始化头像大小 local nodeHeadImage = self.ui.Items.ImageView_Head; self.head = {} self.head.width = nodeHeadImage:getContentSize().width self.head.height = nodeHeadImage:getContentSize().height logD("self.head = ", table.tostring(self.head)); logD("MainReview:initPlayerInfo() userInfo = ", tostring(app.user.userInfo)) local userInfo = json.decode(app.user.userInfo); -- 昵称 local nickname = getSubStringNickname(userInfo.nickname) self.ui.Items.Text_Name:setText(nickname or tostring("未知昵称")) -- ID local id = tonumber(app.user.loginInfo.uid) or 0 self.ui.Items.Text_ID:setText(string.format("ID:%07d", id)) -- 房卡数量 self.ui.Items.Text_Diamand:bind(app.user.loginInfo, "curCardNum", function() self.ui.Items.Text_Diamand:setString(tostring(app.user.loginInfo.curCardNum)) end) --金币数量 self.ui.Items.Text_Gold:bind(app.user.loginInfo, "curJingbiNum", function() local num = tonumber(app.user.loginInfo.curJingbiNum) or 0 num = num + 2000 local str if num > 100000 then str = tostring(math.floor(num / 1000) / 10).."W" else str = tostring(num) end self.ui.Items.Text_Gold:setString(str) end) -- 头像 local nodeHead = self.ui.Items.ImageView_Head; setPlayerHeadImage(app.user.loginInfo.uid, userInfo.headimgurl, nodeHead) end -- 初始化活动信息 function MainReview:initActivity() --默认弹出活动界面 self:bindEvent(app, "onGetActivityInfoResponse", handler(self, self.showActivityOnEnter)); -- 分享成功后通知此层关闭分享界面 -- self:bindEvent(app , "shareSuccCallback" , handler(self , self.shareSuccCallback)); --关闭通知界面后弹出活动界面 -- self:bindEvent(app, "onCloseTongZhiSucc", handler(self, self.onCloseTongZhiSucc)); --关闭代理招募后弹出活动界面 -- self:bindEvent(app, "onCloseDaiLiZhaoMu", handler(self, self.onCloseDaiLiZhaoMu)); self:bindEvent(app, GAME_EVENT.ACTIVITY_CLOSE, handler(self, self.onActivityClose)); -- 请求活动数据 app.serverConfigs:requestMissionList() end -- 初始化游戏列表 function MainReview:initSubGameList() self:bindEvent(app.serverConfigs, "getSubGameListSuccessed", handler(self, self.updateSubGameList)) self:updateSubGameList() end function MainReview:updateSubGameList() local page = self.ui.Items.Layout_Page page:removeAllChildren() local gameList = app.serverConfigs:getGameList() -- dump(gameList,"------gameList-------") for i = 1, 10 do local game = gameList[i] if 10 == i then game = gameList[#gameList] end if game then if game.gameType=="sub" then local uiSubGame = import("luaScript.Views.Main.MainViewGameIcon"):new(game.gameId) page:addChild(uiSubGame.ui) end end end end function MainReview:createWebGameItem(webGame) local gameLayout = cc.Layout:create() gameLayout:setSize(cc.size(152,188)) local webGameIcon = cc.ImageView:create() webGameIcon:setAutoSize(false) webGameIcon:setSize(cc.size(134,156)) setImageFromUrl(webGameIcon,webGame.icon) webGameIcon:registerClick(function() playBtnEffect() if not app.serverConfigs:isOpenWebGame(webGame.gameId) then showTooltip("敬请期待!") return end webGameIcon:setTouchEnabled(false) app.serverConfigs:requestWebGameUrl(webGame.gameId,function (url) if webGameIcon and not tolua.isnull(webGameIcon) then webGameIcon:setTouchEnabled(true) if not url or url =="" then showTooltip("敬请期待!") return end local view = import("luaScript.Views.Main.WebViews.WebGameView"):new(webGame.gameId,url) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view,nil,true) end end) end) if app.serverConfigs:isNewWebGame(webGame.gameId) then local newIcon = cc.ImageView:create() newIcon:loadTexture("res/ui/zy_dating/dating/img_newTag.png") webGameIcon:addChild(newIcon) newIcon:setPosition(cc.p(40,125)) end local size = gameLayout:getContentSize() webGameIcon:setPosition(cc.p(size.width/2,size.height/2)) gameLayout:addChild(webGameIcon) self.ui.Items.Layout_Page:addChild(gameLayout) end -- 进入子游戏 function MainReview:onClickSubGame(gameId) --[[if gameId == GAME_IDS.More or gameId == GAME_IDS.hejiangDaEr then--暂时屏蔽合江大贰 showTooltip("开发中...") return end--]] cc.UserDefault:getInstance():setBoolForKey("firstLogin",false) -- 打开对应的创建界面 local gameConfig = getSubGameConfig(gameId) if not gameConfig then showTooltip("开发中") return end app.gameId = gameId -- app.subGameManager:saveToFile(gameId) local gameData = {} gameData.gameId = gameId gameData.defaultPlayType = nil local createView = import("luaScript.Views.CreateRoom.CreateRoomBase"):new(gameData) createView:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(createView) -- self:updateSubGameList() end -- 兑换金币 function MainReview:OnClickButtonAddGold() playBtnEffect() local view = import("luaScript.Views.Main.ExchangeView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 充值房卡 function MainReview:OnClickButtonAddDiamand() playBtnEffect() local view = import("luaScript.Views.Main.RechargeView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 商城 function MainReview:onClickButtonShop() playBtnEffect() -- showTooltip("敬请期待!") -- do return end local view = import("luaScript.Views.Main.RechargeView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 活动 function MainReview:onClickButtonActive() --showTooltip("暂无活动") --do return end playBtnEffect() local missions = app.serverConfigs.missions; if #missions<1 then --or table.nums(activityData) < 1 -- showTooltip("暂无活动") return end self.isShowTongZHiView = true local view = import("luaScript.Views.Activity.ActivityMainView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end --活动分享成功 function MainReview:shareSuccCallback() if (not tolua.isnull(self.activityshareview)) then self.activityshareview:removeFromParent() self.activityshareview = nil end end -- 设置 function MainReview:onClickButtonEmail() playBtnEffect() showTooltip("开发中...") end -- 客服 function MainReview:onClickButtonKeFu() playBtnEffect() local view = import("luaScript.Views.Main.DaiLiView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 快速开始 function MainReview:onClickButtonStart() playBtnEffect() local view = import("luaScript.Views.Main.JoinRoomView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) --从大厅进入游戏时清空保存的茶馆id及桌子下标 app.club_php.clubID = 0; app.club_php.tableIdx = 0 end -- 向右滑动 function MainReview:onClickButtonRight() self.ui.Items.ScrollView:scrollBy(cc.p(-480,0),0.5,true) end -- 实名认证 function MainReview:onClickButtonShiMing() playBtnEffect() local view = import("luaScript.Views.Main.ShiMingView"):new(self.ShiMingRenZhengData,self) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 邀请码 function MainReview:onClickButtonInviteCode() playBtnEffect() local view = import("luaScript.Views.Main.InviteCodeView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 绑定手机号 function MainReview:onClickButtonBindPhone() playBtnEffect() local view = import("luaScript.Views.Main.PhoneBindView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 显示玩家信息的界面 function MainReview:onClickPlayerHead() playBtnEffect() local view = import("luaScript.Views.Main.MainSettingView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 茶馆 function MainReview:onClickButtonClub() playBtnEffect() local view = import("luaScript.Views.Club.ClubMain"):new(); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) --重新进入茶馆大厅时清空保存的茶馆id及桌子下标 app.club_php.clubID = 0; app.club_php.tableIdx = 0 cc.UserDefault:getInstance():setBoolForKey("firstLogin",false) end -- 金币场 function MainReview:onClickButtonGold() playBtnEffect() showTooltip("开发中...") end -- 战绩 function MainReview:onClickZhanji() playBtnEffect() local view = import("luaScript.Views.ZhanJi.ZhanJiViewBase"):new(-1); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end --玩法 function MainReview:onClickWanfa() playBtnEffect() local view = import("luaScript.Views.Main.HelpView"):new(-1) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end -- 启动游戏时弹出活动界面 function MainReview:showActivityOnEnter() --每次登陆弹出通知弹窗 -- local firstLogin = cc.UserDefault:getInstance():getBoolForKey("firstLogin") if IS_FIRST_LOGIN then -- if cc.Application:getInstance():getTargetPlatform() ~= 0 then local viewName = app.serverConfigs:popConfig() local viewName = app.serverConfigs:popConfig() if viewName then local view = import(viewName):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end IS_FIRST_LOGIN = false -- end end end function MainReview:onActivityClose() local viewName = app.serverConfigs:popConfig() if viewName then local view = import(viewName):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end --[[ function MainReview:onCloseDaiLiZhaoMu() local firstLogin = cc.UserDefault:getInstance():getBoolForKey("firstLogin") if firstLogin then local activityData = app.php.activityData; if not activityData or table.nums(activityData) < 1 then return end local view = import("luaScript.Views.Activity.ActivityMainView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end cc.UserDefault:getInstance():setBoolForKey("firstLogin",false) end function MainReview:onCloseLaXin() local firstLogin = cc.UserDefault:getInstance():getBoolForKey("firstLogin") if firstLogin then local view = import("luaScript.Views.Activity.ActivityMainView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end cc.UserDefault:getInstance():setBoolForKey("firstLogin",false) end function MainReview:onCloseTongZhiSucc() local activityData = app.php.activityData; if not activityData then return end self.attyData = app.php.activityData["7"]--type7分享活动 if not self.attyData then return end local isShared = (self.attyData.active == 3)--进度,1进行中,2等待领取 3已完成并领取奖励 local firstLogin = cc.UserDefault:getInstance():getBoolForKey("firstLogin") if firstLogin and (not isShared) then--每次登陆且没有领取过分享奖励就弹出分享奖励 --self:onClickButtonActive() self.activityshareview = import("luaScript.Views.Main.Activity.ActivityShareView"):new(7,true) self.activityshareview.ui.Items.Layout:setAnchorPoint(cc.p(0.5, 0.5)) local winSize = getWinSize() self.activityshareview.ui.Items.Layout:setContentSize(winSize) self.activityshareview.ui.Items.Layout_share:setPositionY(-30) app:showWaitDialog(self.activityshareview, 200, false) end cc.UserDefault:getInstance():setBoolForKey("firstLogin",false) end ]]-- function MainReview:onLoginSuccessed() logD("MainReview:onMainViewLoginSuccessed()") local roomId = nil local code = nil --"9024926188961793" --回放码 local str = copyStringFromClipboard() logD("MainReview:onMainViewLoginSuccessed() str = ", str) -- showTooltip(str) --如果第一个是~!开头则代表是浏览器传的参数 if string.find(str,"~!")==1 then local baseStr=string.sub(str,3,string.len(str)) baseStr=base64.decode(baseStr) local params=json.decode(decodeURI(baseStr)) dump(params,"MainReview:onMainViewLoginSuccessed params") if params then logD("do somthing!") if params.roomid then roomId = params.roomid end if params.code then code = params.code end end -- return else -- 检测玩家剪贴板里面是否有房间号, --如果有,查询这个房间号对应的游戏ID --如果没查到则不处理 --如果查到了,则判断游戏是否已安装 --未安装则提示安装,已安装则直接进入 roomId = getRoomIdFromCopyString(str) end -- local roomId = getRoomIdFromCopyString(str) logD("MainReview:onMainViewLoginSuccessed() roomId = ", roomId) if roomId then local function onQueryRoomResponse(gameId, roomId) logD("MainReview:onQueryRoomResponse() gameId = ", gameId) logD("MainReview:onQueryRoomResponse() roomId = ", roomId) if not gameId or tonumber(gameId) <= 0 then return end copyStringToClipboard("") -- 检查这个子游戏是否已安装 if app.subGameManager then local function requestJoinRoom() app.hall:requestJoinRoom(gameId, roomId) end if not app.subGameManager:isInstaller(gameId) then requestDownloadSubGame(gameId, requestJoinRoom, true) else requestJoinRoom(); end end end app.hall:queryRoomId(tonumber(roomId), onQueryRoomResponse); end if code then copyStringToClipboard("") local view = import("luaScript.Views.ZhanJi.ZhanJiViewBase"):new(-1,nil,code) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end --[[ function MainReview:onPhoneBindResponse(event) local phonenum = app.user.phonenum if phonenum and phonenum ~= "" then self.ui.Items.Button_PhoneNum:setVisible(false) end end ]] function MainReview:onClickTest() -- onTest(); local view = import("luaScript.Views.Main.GameManagerView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function MainReview:onClubNotSameDeskResponse(event) local playerInfo = json.decode(event.userInfo) setIsRoomGamedata(nil) local str = string.format("管理员已设置该牌桌 %s 玩家与您禁止同桌!",playerInfo.nickname) showConfirmDialog(str) end function MainReview:onClubIniteEvent(event) --房间邀请通知 local content = event.content local clubId = event.clubId local viewType = type(self.inviteView) if self.inviteView and viewType == "userdata" then --提示框已存在 return end local function closeCallback() --关闭提示框时清空数据,用于下次弹出 self.inviteView = nil end self.inviteView = import("luaScript.Views.Club.ClubInviteRoomNew"):new(clubId, content, closeCallback) self.inviteView:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(self.inviteView) end function MainReview:onClickMoreGame() playBtnEffect() --showTooltip("开发中...") local createView = import("luaScript.Views.CreateRoom.CreateRoomBase"):new() createView:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(createView) end --增加地区按钮 function MainReview:onClickDiqu() showTooltip("开发中...") end --更多 function MainReview:onClickMore() playBtnEffect() self.ui.Items.Layout_More:setVisible(not self.ui.Items.Layout_More:isVisible()) end --举报 function MainReview:onClickJuBao() playBtnEffect() -- showTooltip("开发中...") local url = string.format("http://cnapi.dingdingqipai.com/index-cn.php?action=report.show&uid=%s&app=%s",app.user.loginInfo.uid,getAppId()) logD(url) app.plugin:callUrl(url) end function MainReview:onClickPrizeCash() playBtnEffect() local view = import("luaScript.Views.Main.MainInviteNewFriend"):new(); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end return MainReview