You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.0 KiB

  1. -- 上传日志界面
  2. local ScreenView = class("ScreenView", cc.UIView)
  3. function ScreenView:ctor(fileName)
  4. ScreenView.super.ctor(self);
  5. self.fileName = fileName;
  6. self.newFilePath = ""
  7. local ui = loadUI("res/ui/ui_fangjian/ui_fangjian_screenshot.ui");
  8. self.ui = ui;
  9. self:addChild(ui);
  10. end
  11. function ScreenView:onEnter()
  12. ScreenView.super.onEnter(self)
  13. -- 取消
  14. self.ui.Items.Button_Exit:registerClick(handler(self , self.onClickClose))
  15. -- 分享
  16. self.ui.Items.Button_Share:registerClick(handler(self , self.onClickShare))
  17. -- 玩家头像
  18. setPlayerHeadImage(app.user.loginInfo.uid, app.user.headimgurl, self.ui.Items.ImageView_Head)
  19. -- 玩家昵称
  20. local shortname = getShortName(app.user.nickname)
  21. self.ui.Items.Text_Name:setText(shortname)
  22. -- 截屏图片
  23. local texture = loadTextureFromFile(self.fileName)
  24. if texture then
  25. self.ui.Items.ImageView_Screen:setTexture2(texture);
  26. end
  27. local function callback(texture)
  28. self.ui.Items.ImageView_Code:setTexture(texture)
  29. self:runDelay(0.3, handler(self, self.ScreenShot))
  30. end
  31. dd.IGameCommon.getShareCRCodeTexture(callback)
  32. end
  33. function ScreenView:ScreenShot()
  34. -- 删除旧的文件
  35. local oldFilePath = cc.FileUtils:getInstance():getWritablePath() .. self.fileName
  36. os.remove(oldFilePath);
  37. -- 产生新的截屏文件并保存到相册
  38. ScreenShot(function(fullPath, fileName)
  39. self.ui.Items.Button_Exit:setVisible(true)
  40. self.ui.Items.Button_Share:setVisible(true)
  41. self.newFilePath = fullPath
  42. --[[
  43. if fullPath and fileName then
  44. local delayClose = false
  45. -- 如果支持拷贝到相册,则拷贝到相册然后自动关闭界面
  46. if isSupportCopyToDcim() then
  47. delayClose = true
  48. local dateNow = os.date("*t", os.time())
  49. local timeString = string.format("%04d-%02d-%02d-%02d%-02d-%02d", dateNow.year, dateNow.month, dateNow.day, dateNow.hour, dateNow.min, dateNow.sec);
  50. local dcimPath = getSystemPath("DCIM")
  51. local dcimFilePath = string.format("%s/%s/screen_%s.jpg", dcimPath, "Camera", timeString)
  52. copyFile(self.newFilePath, dcimFilePath)
  53. showTooltip("截屏已保存到本地相册");
  54. self:runDelay(1, handler(self, self.onClickClose))
  55. end
  56. end
  57. --]]
  58. end)
  59. end
  60. -- 取消
  61. function ScreenView:onClickClose()
  62. if self.newFilePath and self.newFilePath ~= "" then
  63. --os.remove(self.newFilePath);
  64. end
  65. self:removeFromParent()
  66. end
  67. -- 分享
  68. function ScreenView:onClickShare()
  69. function doShare()
  70. local info = {}
  71. info.scene = "talk"
  72. info.contentType = "image"
  73. info.image = self.newFilePath
  74. info.imageWidth = 1000
  75. info.thumbWidth = 100
  76. app.plugin:shareGame(info)
  77. end
  78. -- 如果已经截屏成功了,则直接分享
  79. -- 否则再次截屏
  80. if self.newFilePath then
  81. doShare()
  82. self:onClickClose()
  83. else
  84. ScreenShot(function(fullpath, filename)
  85. if fullpath and filename then
  86. self.newFilePath = fullpath
  87. doShare()
  88. self:onClickClose()
  89. else
  90. showTooltip("截屏失败")
  91. end
  92. end)
  93. end
  94. end
  95. return ScreenView;