-- 上传日志界面 local ScreenView = class("ScreenView", cc.UIView) function ScreenView:ctor(fileName) ScreenView.super.ctor(self); self.fileName = fileName; self.newFilePath = "" local ui = loadUI("res/ui/ui_fangjian/ui_fangjian_screenshot.ui"); self.ui = ui; self:addChild(ui); end function ScreenView:onEnter() ScreenView.super.onEnter(self) -- 取消 self.ui.Items.Button_Exit:registerClick(handler(self , self.onClickClose)) -- 分享 self.ui.Items.Button_Share:registerClick(handler(self , self.onClickShare)) -- 玩家头像 setPlayerHeadImage(app.user.loginInfo.uid, app.user.headimgurl, self.ui.Items.ImageView_Head) -- 玩家昵称 local shortname = getShortName(app.user.nickname) self.ui.Items.Text_Name:setText(shortname) -- 截屏图片 local texture = loadTextureFromFile(self.fileName) if texture then self.ui.Items.ImageView_Screen:setTexture2(texture); end local function callback(texture) self.ui.Items.ImageView_Code:setTexture(texture) self:runDelay(0.3, handler(self, self.ScreenShot)) end dd.IGameCommon.getShareCRCodeTexture(callback) end function ScreenView:ScreenShot() -- 删除旧的文件 local oldFilePath = cc.FileUtils:getInstance():getWritablePath() .. self.fileName os.remove(oldFilePath); -- 产生新的截屏文件并保存到相册 ScreenShot(function(fullPath, fileName) self.ui.Items.Button_Exit:setVisible(true) self.ui.Items.Button_Share:setVisible(true) self.newFilePath = fullPath --[[ if fullPath and fileName then local delayClose = false -- 如果支持拷贝到相册,则拷贝到相册然后自动关闭界面 if isSupportCopyToDcim() then delayClose = true local dateNow = os.date("*t", os.time()) local timeString = string.format("%04d-%02d-%02d-%02d%-02d-%02d", dateNow.year, dateNow.month, dateNow.day, dateNow.hour, dateNow.min, dateNow.sec); local dcimPath = getSystemPath("DCIM") local dcimFilePath = string.format("%s/%s/screen_%s.jpg", dcimPath, "Camera", timeString) copyFile(self.newFilePath, dcimFilePath) showTooltip("截屏已保存到本地相册"); self:runDelay(1, handler(self, self.onClickClose)) end end --]] end) end -- 取消 function ScreenView:onClickClose() if self.newFilePath and self.newFilePath ~= "" then --os.remove(self.newFilePath); end self:removeFromParent() end -- 分享 function ScreenView:onClickShare() function doShare() local info = {} info.scene = "talk" info.contentType = "image" info.image = self.newFilePath info.imageWidth = 1000 info.thumbWidth = 100 app.plugin:shareGame(info) end -- 如果已经截屏成功了,则直接分享 -- 否则再次截屏 if self.newFilePath then doShare() self:onClickClose() else ScreenShot(function(fullpath, filename) if fullpath and filename then self.newFilePath = fullpath doShare() self:onClickClose() else showTooltip("截屏失败") end end) end end return ScreenView;