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.

184 lines
5.3 KiB

  1. -- 大厅分享选择
  2. local HallShareView = class("HallShareView", cc.UIView)
  3. function HallShareView:ctor()
  4. HallShareView.super.ctor(self);
  5. local ui = loadUI("res/ui/ui_dating/ui_dating_sharechose.ui")
  6. self.ui = ui
  7. self:addChild(ui)
  8. self.lastClick = 0
  9. self.sharehy = false
  10. self.sharepyq = false
  11. end
  12. function HallShareView:onEnter()
  13. HallShareView.super.onEnter(self)
  14. self.ui.Items.Button_Close:registerClick(handler(self , self.onClickClose))
  15. self.ui.Items.Button_share_hy:registerClick(handler(self , self.onShareHy))--分享给好友
  16. self.ui.Items.Button_share_pyq:registerClick(handler(self , self.onSharePyq))--分享朋友圈
  17. -- 更新提示信息
  18. self:updateTips();
  19. self:bindEvent(app, "onGetShareRewardResponse", handler(self, self.onGetShareRewardResponse))
  20. self:updateView();
  21. end
  22. --- HallShareView:updateTips 更新提示信息
  23. function HallShareView:updateTips()
  24. local strTips = string.format("每日首次分享成功后,即可免费获得15%s%s", PLN.CURRENCY_UNIT, PLN.CURRENCY);
  25. self.ui.Items.Text_tips:setString(strTips);
  26. end
  27. function HallShareView:updateView()
  28. logD("HallShareView:updateView")
  29. local misstions,index = app.serverConfigs:getMissionListByType(2)
  30. for k,v in pairs(misstions) do
  31. if v.ext then
  32. local ext = json.decode(v.ext)
  33. if ext and ext.view == "ActivityShareView" then
  34. self.mission = v
  35. end
  36. end
  37. end
  38. logD("HallShareView:updateView", self.mission)
  39. if not self.mission then
  40. logD("HallShareView:updateView", "分享任务不存在");
  41. return
  42. end
  43. if not self.mission.ext then
  44. logD("HallShareView:updateView", "扩展配置错误", self.mission);
  45. return
  46. end
  47. local ext = json.decode(self.mission.ext)
  48. if not ext then
  49. logD("HallShareView:updateView", "ext解析为空", self.mission.ext);
  50. return
  51. end
  52. local urlfile2, time2 = convertIconUrl(ext.share_pic)
  53. self.fileName2 = getImageNameFromUrl(urlfile2)
  54. logD("HallShareView:updateView fileName2: ", self.fileName2)
  55. local fullPath = cc.FileUtils:getInstance():getWritablePath()..self.fileName2;
  56. app.waitDialogManager:showWaitNetworkDialog("获取分享内容")
  57. getImageFromUrlWithTime(ext.share_pic, self.fileName2, nil, function()
  58. app.waitDialogManager:closeWaitNetworkDialog()
  59. end)
  60. end
  61. -- 关闭
  62. function HallShareView:onClickClose()
  63. playBtnCloseEffect()
  64. self:removeFromParent()
  65. end
  66. -- 分享给好友
  67. function HallShareView:onShareHy()
  68. playBtnCloseEffect()
  69. local timeNow = os.time();
  70. if timeNow - self.lastClick <= 5 then
  71. showTooltip("点击太过频繁,请稍后再试")
  72. return
  73. end
  74. self.lastClick = timeNow;
  75. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then
  76. local imagePath = cc.FileUtils:getInstance():getWritablePath()..self.fileName2;
  77. --local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  78. local function requestGetReward()
  79. app.php:requestGetShareReward()
  80. end
  81. local info = {}
  82. info.scene = "talk"
  83. info.contentType = "image"
  84. info.image = imagePath
  85. info.imageWidth = 1000
  86. info.thumbWidth = 100
  87. app.plugin:shareGame(info,requestGetReward)
  88. else
  89. app.php:requestGetShareReward()
  90. end
  91. self.sharehy = true
  92. self.sharepyq = false
  93. end
  94. -- 分享朋友圈
  95. function HallShareView:onSharePyq()
  96. playBtnCloseEffect()
  97. local timeNow = os.time();
  98. if timeNow - self.lastClick <= 5 then
  99. showTooltip("点击太过频繁,请稍后再试")
  100. return
  101. end
  102. self.lastClick = timeNow;
  103. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then
  104. local imagePath = cc.FileUtils:getInstance():getWritablePath()..self.fileName2;
  105. --local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  106. local function requestGetReward()
  107. app.php:requestGetShareReward()
  108. end
  109. local info = {}
  110. info.scene = "friend"
  111. info.contentType = "image"
  112. info.image = imagePath
  113. info.imageWidth = 1000
  114. info.thumbWidth = 100
  115. app.plugin:shareGame(info,requestGetReward)
  116. else
  117. app.php:requestGetShareReward()
  118. end
  119. self.sharehy = false
  120. self.sharepyq = true
  121. end
  122. function HallShareView:onGetShareRewardResponse(result)
  123. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then
  124. if result.data.flag == -1 then
  125. showTooltip("今日已领取过奖励!")
  126. else
  127. local addNum = result.data.add
  128. self:showRewardAnimation(addNum);
  129. end
  130. else
  131. local imagePath = cc.FileUtils:getInstance():getWritablePath()..self.fileName2;
  132. --local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  133. local function requestGetReward()
  134. --app.php:requestGetShareReward()
  135. end
  136. local info = {}
  137. info.scene = "friend"
  138. if self.sharehy then
  139. info.scene = "talk"
  140. end
  141. info.contentType = "image"
  142. info.image = imagePath
  143. info.imageWidth = 1000
  144. info.thumbWidth = 100
  145. app.plugin:shareGame(info,requestGetReward)
  146. if result.data.flag == -1 then
  147. showTooltip("今日已领取过奖励!")
  148. else
  149. self:runAction(cc.Sequence:create(cc.DelayTime:create(1.2),cc.CallFunc:create(function ()
  150. local addNum = result.data.add
  151. self:showRewardAnimation(addNum);
  152. end)))
  153. end
  154. end
  155. end
  156. --- HallShareView:showRewardAnimation 显示获得房卡动画
  157. function HallShareView:showRewardAnimation(addNum)
  158. local view = import("luaScript.Views.Main.JiangLi"):new(addNum)
  159. view:setAnchorPoint(cc.p(0.5, 0.5))
  160. app:showWaitDialog(view, 200, true)
  161. end
  162. return HallShareView;