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.

768 line
22 KiB

  1. -- 主界面
  2. -- 加载界面时,分别在五个玩家门前放置5张牌,但并不显示
  3. -- 更新玩家手牌列表时,按需显示
  4. local ZiPaiRoomMessageView = class("ZiPaiRoomMessageView", cc.UIView)
  5. function ZiPaiRoomMessageView:ctor(ui)
  6. ZiPaiRoomMessageView.super.ctor(self);
  7. -- 玩家节点
  8. self.nodes = {}
  9. self.recording = false; -- 是否正在录音
  10. --是否关闭点击信息
  11. self.m_isClose = true
  12. -- 记录每个玩家的最后一条语音
  13. self.playerVoice = {}
  14. --系统的音效状态
  15. self.soundState = app.systemSetting.info.sound
  16. --[[
  17. self.playerVoice =
  18. {
  19. [1] = {url = url, filePath = filePath, recordTime = recordTime},
  20. [2] = {url = url, filePath = filePath, recordTime = recordTime},
  21. [3] = {url = url, filePath = filePath, recordTime = recordTime},
  22. [4] = {url = url, filePath = filePath, recordTime = recordTime},
  23. [5] = {url = url, filePath = filePath, recordTime = recordTime},
  24. }
  25. --]]
  26. -- 最后一条音效
  27. self.lastSound = nil
  28. -- 正在说话的椅子号(同一时刻只允许一个玩家说话)
  29. self.lastSpeakingSeatId = false
  30. end
  31. function ZiPaiRoomMessageView:onEnter()
  32. ZiPaiRoomMessageView.super.onEnter(self)
  33. local ui = loadUI("zipai/res/ui/ui_fangjian/zipai_ui_shengyin.ui");
  34. self.ui = ui;
  35. self:addChild(ui);
  36. -- 语音按钮
  37. self.ui.Items.Button_Record:registerClick(handler(self , self.stopRecord), handler(self , self.beginRecord), handler(self , self.cancelRecord));
  38. -- 如果没有语音插件,则不显示语音按钮
  39. if not app.plugin.pluginVoice then
  40. self.ui.Items.Button_Record:setVisible(false)
  41. end
  42. -- 表情按钮
  43. self.ui.Items.Button_Face:registerClick(handler(self , self.onClickFace))
  44. -- 录音中
  45. self.ui.Items.Layout_luyinzhong:setVisible(false)
  46. -- 初始化玩家的各种节点
  47. self:initNodes()
  48. -- 监听事件
  49. self:initEvents()
  50. end
  51. function ZiPaiRoomMessageView:initNodes()
  52. self.myViewId = ZiPai_GAME_CONST.GAME_CONST_ME_VIEW_ID
  53. for i = 1, ZiPai_GAME_CONST.ZiPai_GAME_CONST_PLAYER do
  54. self.nodes[i] = {}
  55. local nodes = self.nodes[i];
  56. -- 说话的语音
  57. local nameSpeak = string.format("Layout_speak_%d",i)
  58. local nodeSpeak = self.ui.Items[nameSpeak]
  59. nodeSpeak:setVisible(false)
  60. nodes.nodeSpeak = nodeSpeak;
  61. -- 玩家头像信息
  62. local nameHeadInfo = string.format("Layout_wanjiaxinxi_%d",i)
  63. local nodeHeadInfo = self.ui.Items[nameHeadInfo]
  64. nodeHeadInfo:setVisible(false)
  65. nodes.nodeHeadInfo = nodeHeadInfo;
  66. --表情
  67. local nameFaceBG = string.format("Layout_face_%d",i);
  68. local nodeFaceBG = self.ui.Items[nameFaceBG]
  69. nodeFaceBG:setVisible(false)
  70. nodes.nodeFaceBG = nodeFaceBG;
  71. --表情图片
  72. local nameFaceImage = string.format("ImageView_face_%d",i);
  73. local nodeFaceImage = self.ui.Items[nameFaceImage]
  74. nodeFaceImage:setVisible(false)
  75. nodes.nodeFaceImage = nodeFaceImage;
  76. --聊天文字
  77. local nameChatText = string.format("Text_Chat_%d",i);
  78. local nodeChatText = self.ui.Items[nameChatText]
  79. nodes.nodeChatText = nodeChatText;
  80. end
  81. end
  82. function ZiPaiRoomMessageView:initEvents()
  83. -- 玩家语音
  84. self:bindEvent(app.user , "onChatMessageResponse" , handler(self , self.onChatMessageResponse));
  85. -- 回调語音播放
  86. self:bindEvent(app , "recordCallback" , handler(self , self.recordCallback));
  87. end
  88. function ZiPaiRoomMessageView:onClickBG()
  89. -- 隐藏头像
  90. for i = 1, ZiPai_GAME_CONST.ZiPai_GAME_CONST_PLAYER do
  91. self.nodes[i].nodeHeadInfo:setVisible(false)
  92. self.nodes[i].nodeHeadInfo:removeAllChildren()
  93. end
  94. self.m_isClose = true
  95. end
  96. -- 显示屏幕中间滑动手指取消录音的提示
  97. function ZiPaiRoomMessageView:showSpeaking()
  98. self.ui.Items.Layout_luyinzhong:setVisible(true)
  99. self.ui.Items.Layout_luyinzhong:playClip("speaking")
  100. end
  101. -- 隐藏屏幕中间滑动手指取消录音的提示
  102. function ZiPaiRoomMessageView:hideSpeaking()
  103. self.ui.Items.Layout_luyinzhong:setVisible(false)
  104. self.ui.Items.Layout_luyinzhong:stopClip("speaking")
  105. end
  106. function ZiPaiRoomMessageView:beginRecord()
  107. if not app.user:canSendChatMessage(2) then
  108. showTooltip("您发送语音信息的间隔时间太短,请稍后再发!")
  109. return
  110. end
  111. -- 停止所有的表情声音
  112. if self.lastSound then
  113. stopVoice(self.lastSound)
  114. end
  115. --为了不影响录制的过程,还可以听到音效,关闭所有的音效
  116. app.systemSetting.info.sound = false
  117. --暂停音乐
  118. cc.AudioController:getInstance():pause();
  119. --暂停音效
  120. --cc.AudioController:getInstance():setPlaySound(false)
  121. -- 停止所有的玩家语音
  122. app.plugin:stopPlayRecord()
  123. -- 如果有玩家正在说话
  124. if self.lastSpeakingSeatId then
  125. self.nodes[self.lastSpeakingSeatId].nodeSpeak:setVisible(false)
  126. end
  127. self.recording = true;
  128. --showTooltip("开始录音")
  129. self:showSpeaking()
  130. app.plugin:startRecord()
  131. end
  132. function ZiPaiRoomMessageView:cancelRecord()
  133. if not self.recording then
  134. return
  135. end
  136. --继续音乐
  137. cc.AudioController:getInstance():resume();
  138. --恢复音效
  139. --cc.AudioController:getInstance():setPlaySound(app.systemSetting.info.sound)
  140. app.systemSetting.info.sound = self.soundState
  141. --showTooltip("取消录音")
  142. self.recording = false;
  143. self:hideSpeaking();
  144. app.plugin:cancelRecord()
  145. end
  146. function ZiPaiRoomMessageView:stopRecord()
  147. if not self.recording then
  148. return
  149. end
  150. --showTooltip("结束录音")
  151. self.recording = false;
  152. self:hideSpeaking();
  153. app.systemSetting.info.sound = self.soundState
  154. --继续音乐
  155. cc.AudioController:getInstance():resume();
  156. --恢复音效
  157. --cc.AudioController:getInstance():setPlaySound(app.systemSetting.info.sound)
  158. if cc.Application:getInstance():getTargetPlatform() == 0 then
  159. local jsonData =
  160. {
  161. recordUrl = "recordUrl",
  162. recordTime = 10,
  163. }
  164. local content = json.encode(jsonData)
  165. if app.user:sendChatMessage(2, content) then
  166. -- 记录我发送过的语音
  167. self.playerVoice[self.myViewId] = {}
  168. self.playerVoice[self.myViewId].filePath = ""
  169. self.playerVoice[self.myViewId].recordUrl = jsonData.recordUrl
  170. self.playerVoice[self.myViewId].recordTime = jsonData.recordTime;
  171. --播放录音时先停止背景音乐
  172. --cc.AudioController:getInstance():pause();
  173. -- 播放我的语音
  174. self:replayRecord(self.myViewId)
  175. -- 播放我的语音
  176. self:showSpeakClip(self.myViewId)
  177. self.ui.Items.Layout_1:runDelay(jsonData.recordTime, function()
  178. --播放背景音乐
  179. --cc.AudioController:getInstance():resume();
  180. end )
  181. end
  182. return
  183. end
  184. app.plugin:stopRecord()
  185. end
  186. -- 播放回调函数
  187. function ZiPaiRoomMessageView:recordCallback(event)
  188. --恢复音乐
  189. if app.systemSetting.info.music then
  190. cc.AudioController:getInstance():resume();
  191. end
  192. if not event then return end
  193. local filePath, recordUrl, recordTime = event.filePath, event.recordUrl, event.recordTime
  194. log("log_event", filePath, recordUrl, recordTime)
  195. if not filePath then return end
  196. if not recordUrl then return end
  197. if not recordTime then return end
  198. recordTime = math.ceil(recordTime / 1000);
  199. if recordTime <= 1 then
  200. showTooltip("录音时间过短!")
  201. return
  202. end
  203. local jsonData =
  204. {
  205. recordUrl = recordUrl,
  206. recordTime = recordTime,
  207. }
  208. local content = json.encode(jsonData);
  209. if app.user:sendChatMessage(2, content) then
  210. -- 记录我发送过的语音
  211. self.playerVoice[self.myViewId] = {}
  212. self.playerVoice[self.myViewId].filePath = filePath;
  213. self.playerVoice[self.myViewId].recordUrl = recordUrl;
  214. self.playerVoice[self.myViewId].recordTime = recordTime;
  215. --播放录音时先停止背景音乐
  216. --cc.AudioController:getInstance():pause();
  217. -- 播放我的语音
  218. self:replayRecord(self.myViewId)
  219. -- 播放我的语音
  220. self:showSpeakClip(self.myViewId)
  221. --[[self.ui.Items.Layout_1:runDelay(recordTime, function()
  222. --播放背景音乐
  223. cc.AudioController:getInstance():resume();
  224. end)--]]
  225. end
  226. end
  227. -- 重新播放某个玩家之前说的话
  228. function ZiPaiRoomMessageView:replayRecord(nSeatShowId)
  229. log("ZiPaiRoomMessageView:replayRecord() nSeatShowId = ", nSeatShowId);
  230. log("ZiPaiRoomMessageView:replayRecord() self.playerVoice = ", table.tostring(self.playerVoice));
  231. local data = self.playerVoice[nSeatShowId]
  232. if data and data.filePath then
  233. app.plugin:playRecord(data.filePath)
  234. local recordTime = data.recordTime
  235. self.lastSpeakingSeatId = nSeatShowId
  236. self.ui.Items.Layout_1:runDelay(recordTime, function()
  237. self.lastSpeakingSeatId = nil
  238. end )
  239. end
  240. end
  241. -- 创建一个用户头像
  242. function ZiPaiRoomMessageView:createHeadInfo(nSeatShowId)
  243. local nUserId = app.room:getUserIdByViewId(nSeatShowId);
  244. local memberInfo = app.room.roomInfo.memberList[nUserId]
  245. if not memberInfo then
  246. return
  247. end
  248. local userInfo = json.decode(memberInfo.userInfo)
  249. local ui = loadUI("res/ui/ui_fangjian/ui_fangjian_wanjiaxinxi.ui")
  250. --隐藏滑动条
  251. ui.Items.ScrollView:hideAllBar()
  252. --头像显示
  253. --先设置默认头像
  254. local nodeHead = ui.Items.ImageView_head
  255. self.headSize = {}
  256. self.headSize.width = nodeHead:getContentSize().width
  257. self.headSize.height = nodeHead:getContentSize().height
  258. if nSeatShowId == self.myViewId then
  259. ui.Items.ImageView_my:setVisible(true)
  260. ui.Items.ImageView_other:setVisible(false)
  261. else
  262. ui.Items.ImageView_my:setVisible(false)
  263. ui.Items.ImageView_other:setVisible(true)
  264. end
  265. setPlayerHeadImage(memberInfo.nUserId, userInfo.headimgurl, nodeHead)
  266. --男1女2
  267. local sexNum = userInfo.sex or 1
  268. if tonumber(sexNum) == 1 then
  269. ui.Items.ImageView:loadTexture("userInfo_boy.png",cc.TextureResType.plistType)
  270. else
  271. ui.Items.ImageView:loadTexture("userInfo_girl.png",cc.TextureResType.plistType)
  272. end
  273. --注册时间
  274. local registerTime = tonumber(loadUserInfo("userRegisterTime")) or 0
  275. local time = os.date("%Y/%m/%d",registerTime)
  276. ui.Items.Text_registerTime:setText(tostring(time))
  277. -- 如果显示宽度大于10个英文字符宽度,则展示8个英文字符加省略号
  278. local nickname = getSubStringNickname(userInfo.nickname,ui.Items.Text_mingzi)
  279. ui.Items.Text_mingzi:setText(nickname)
  280. local id = tonumber(nUserId) or 0
  281. ui.Items.Text_id:setText(string.format("%06d", id))
  282. ui.Items.Text_2:setVisible(false)
  283. if self.playerVoice[nSeatShowId] then
  284. local recordTime = self.playerVoice[nSeatShowId].recordTime or 0
  285. ui.Items.Text_2:setText(tostring(recordTime).."''")
  286. -- 点击播放语音
  287. ui.Items.ImageView_5:setTouchEnabled(true)
  288. ui.Items.ImageView_5:registerClick(function()
  289. --停止播放背景音乐
  290. cc.AudioController:getInstance():pause();
  291. app.systemSetting.info.sound = false
  292. --停止播放音效
  293. --cc.AudioController:getInstance():setPlaySound(false)
  294. -- 播放语音
  295. self:replayRecord(nSeatShowId)
  296. --必须用全局的
  297. local seq = cc.Sequence:create(cc.DelayTime:create(recordTime),cc.CallFunc:create(function ()
  298. app.systemSetting.info.sound = self.soundState
  299. cc.AudioController:getInstance():resume();
  300. --恢复音效
  301. --cc.AudioController:getInstance():setPlaySound(app.systemSetting.info.sound)
  302. end))
  303. cc.Director:getInstance():getRunningScene():runAction(seq)
  304. --播放动画
  305. ui.Items.Layout_2:playClip("say")
  306. ui.Items.Layout_2:runDelay(recordTime, function()
  307. ui.Items.Layout_2:stopClip("say")
  308. end )
  309. end )
  310. else
  311. ui.Items.ImageView_5:setTouchEnabled(true)
  312. ui.Items.ImageView_5:registerClick(function()
  313. if nSeatShowId == self.myViewId then
  314. showTooltip("请先录音哦")
  315. else
  316. showTooltip("该玩家还没说过话呢")
  317. end
  318. end )
  319. end
  320. --道具ID, 消息类型
  321. local function SendPropMessage(uidStarId,uidEndId,propId,mType,isQunFa)
  322. self:onClickBG()
  323. if not app.user:canSendChatMessage(1) then
  324. showTooltip("您发送聊天信息的间隔时间太短,请稍后再发!")
  325. return
  326. end
  327. local sexId = 0
  328. local memberInfo = app.room.roomInfo.memberList[app.user.loginInfo.uid]
  329. if memberInfo then
  330. local userInfo = json.decode(memberInfo.userInfo)
  331. if not userInfo then
  332. return
  333. end
  334. --男1女2,默认是男生
  335. sexId = tonumber(userInfo.sex) or 1
  336. end
  337. local tt = json.decode(app.user.userInfo)
  338. local data =
  339. {
  340. uidStarId = uidStarId,
  341. uidEndId = uidEndId,
  342. propId = propId,
  343. isQunFa = isQunFa,
  344. areano = tt.areano,
  345. }
  346. -- 发送消息到服务器
  347. --1: 表情 2: 语音 3:聊天
  348. local str = json.encode(data)
  349. local isSendSuccess = app.user:sendChatMessage(mType, str);
  350. --[[if isSendSuccess == true then
  351. if mType == 4 then
  352. self:showProp(uidStarId, uidEndId,propId,isQunFa)
  353. end
  354. end--]]
  355. end
  356. self.lastPropTouchTime = tonumber(loadUserInfo("lastPropTouchTime")) or 0
  357. saveUserInfo("lastPropTouchTime",self.lastPropTouchTime)
  358. ui.Items.Button_5:setVisible(false)
  359. ui.Items.Button_7:setVisible(false)
  360. ui.Items.ScrollView:requestDoLayout()
  361. ui.Items.ScrollView:doLayout()
  362. --道具实现
  363. for i = 1 ,10 do
  364. local name = string.format("Button_%d",i - 1)
  365. ui.Items[name]:registerClick(function ()
  366. playBtnEffect()
  367. if app.room.isOnLooker then
  368. showTooltip("旁观不允许发送道具")
  369. return
  370. end
  371. if table.nums(app.room.roomInfo.memberList) == 1 then
  372. showTooltip("桌子上没有其他人可以发哦")
  373. return
  374. end
  375. local curTime = os.time()
  376. local distance = curTime - self.lastPropTouchTime
  377. local disbandTime = 12
  378. if distance <= disbandTime then
  379. showTooltip(string.format("您操作太快,请%d秒后再试!",disbandTime - distance + 1))
  380. return
  381. end
  382. self.lastPropTouchTime = curTime
  383. saveUserInfo("lastPropTouchTime",self.lastPropTouchTime)
  384. if nSeatShowId == self.myViewId then
  385. --群发道具
  386. --根据在线人数发送道具
  387. local propID = i
  388. local targetUid = app.room:getUserIdByViewId(nSeatShowId)
  389. SendPropMessage(app.user.loginInfo.uid,targetUid,propID,4,1)
  390. else
  391. local propID = i
  392. local targetUid = app.room:getUserIdByViewId(nSeatShowId)
  393. if not targetUid then
  394. showTooltip("道具:目标ID不存在")
  395. return
  396. end
  397. SendPropMessage(app.user.loginInfo.uid,targetUid,propID,4,0)
  398. end
  399. end)
  400. end
  401. return ui
  402. end
  403. -- 显示玩家的头像信息
  404. function ZiPaiRoomMessageView:showHeadInfo(nSeatShowId)
  405. if not self.nodes[nSeatShowId] or not self.nodes[nSeatShowId].nodeHeadInfo then
  406. return
  407. end
  408. self:onClickBG()
  409. local layoutHeadInfo = self.nodes[nSeatShowId].nodeHeadInfo
  410. layoutHeadInfo:removeAllChildren()
  411. self.m_isClose = nil
  412. local ui = self:createHeadInfo(nSeatShowId)
  413. if not ui then
  414. return
  415. end
  416. layoutHeadInfo:addChild(ui);
  417. layoutHeadInfo:setVisible(true)
  418. end
  419. -- 播放某个玩家说话的动画
  420. function ZiPaiRoomMessageView:showSpeakClip(nSeatShowId)
  421. if not self.playerVoice[nSeatShowId] then
  422. return
  423. end
  424. local recordTime = self.playerVoice[nSeatShowId].recordTime or 1
  425. local uiFile = ""
  426. if nSeatShowId == 1 or nSeatShowId == 2 then
  427. uiFile = "res/ui/ui_fangjian/ui_fangjian_speak_4.ui"
  428. else
  429. uiFile = "res/ui/ui_fangjian/ui_fangjian_speak_2.ui"
  430. end
  431. local ui = loadUI(uiFile)
  432. ui.Items.Text:setText(tostring(recordTime).."''");
  433. ui.Items.ImageView:playClip("speak");
  434. local nodeSpeak = self.nodes[nSeatShowId].nodeSpeak;
  435. nodeSpeak:removeAllChildren()
  436. nodeSpeak:addChild(ui);
  437. nodeSpeak:setVisible(true)
  438. --播放录音时先停止背景音乐
  439. cc.AudioController:getInstance():pause();
  440. app.systemSetting.info.sound = false
  441. nodeSpeak:runDelay(recordTime, function()
  442. nodeSpeak:setVisible(false)
  443. nodeSpeak:removeAllChildren()
  444. --播放背景音乐
  445. cc.AudioController:getInstance():resume();
  446. app.systemSetting.info.sound = self.soundState
  447. end )
  448. -- 记录语音正在播放中
  449. self.lastSpeakingSeatId = nSeatShowId
  450. self.ui:runDelay(recordTime, function()
  451. self.lastSpeakingSeatId = nil
  452. end )
  453. end
  454. --点击表情按钮显示表情界面
  455. function ZiPaiRoomMessageView:onClickFace()
  456. local function SendChatMessage(chatId,mType)
  457. if not app.user:canSendChatMessage(1) then
  458. showTooltip("您发送聊天信息的间隔时间太短,请稍后再发!")
  459. return
  460. end
  461. local sexId = 0
  462. local memberInfo = app.room.roomInfo.memberList[app.user.loginInfo.uid]
  463. if memberInfo then
  464. local userInfo = json.decode(memberInfo.userInfo)
  465. if not userInfo then
  466. return
  467. end
  468. --男1女2,默认是男生
  469. sexId = tonumber(userInfo.sex) or 1
  470. end
  471. local data =
  472. {
  473. Id = chatId,
  474. sexId = sexId,
  475. }
  476. -- 发送消息到服务器
  477. --1: 表情 2: 语音 3:聊天
  478. local str = json.encode(data)
  479. local isSendSuccess = app.user:sendChatMessage(mType, str);
  480. if isSendSuccess == true then
  481. -- 本地播放表情和音效
  482. if mType == 1 then
  483. --self:showFace(self.myViewId, chatId);
  484. elseif mType == 3 then
  485. --self:showChat(self.myViewId, chatId,sexId);
  486. end
  487. end
  488. end
  489. playBtnEffect()
  490. local function mesCallBack(idx)
  491. playBtnEffect()
  492. SendChatMessage(idx,3)
  493. end
  494. local function faceCallBack(idx)
  495. playBtnEffect()
  496. SendChatMessage(idx,1)
  497. end
  498. local faceUI = import("Views.Room.ChatFaceView"):new(ZiPai_GAME_CHAT_TXT,mesCallBack,faceCallBack)
  499. self.ui:addChild(faceUI);
  500. end
  501. --显示快捷语
  502. function ZiPaiRoomMessageView:showChat(nSeatShowId, Id,sexId)
  503. local voiceFile = ""
  504. if sexId == 1 then
  505. voiceFile = string.format("zipai/res/sound/chat/ZiPai_%s_%d.ogg","male",Id)
  506. else
  507. voiceFile = string.format("zipai/res/sound/chat/ZiPai_%s_%d.ogg","female",Id)
  508. end
  509. --播放音效
  510. self:playFaceVoice(voiceFile);
  511. --展示话筒
  512. self.nodes[nSeatShowId].nodeChatText:setText(ZiPai_GAME_CHAT_TXT[Id])
  513. self.nodes[nSeatShowId].nodeFaceBG:setScale(0,0,0)
  514. self.nodes[nSeatShowId].nodeFaceBG:setOpacity(255)
  515. self.nodes[nSeatShowId].nodeFaceBG:setVisible(true)
  516. self.nodes[nSeatShowId].nodeFaceBG:stopAllActions()
  517. self.nodes[nSeatShowId].nodeFaceBG:runAction(cc.Sequence:create(cc.ScaleTo:create(0.2,1,1,1),
  518. cc.DelayTime:create(4.0),cc.FadeOut:create(0.3),cc.CallFunc:create(function ()
  519. self.nodes[nSeatShowId].nodeFaceBG:setVisible(false)
  520. self.nodes[nSeatShowId].nodeFaceBG:setOpacity(255)
  521. end)))
  522. end
  523. --显示表情
  524. function ZiPaiRoomMessageView:showFace(nSeatShowId, Id)
  525. --播放动画
  526. self:playFaceAnimation(nSeatShowId,Id)
  527. end
  528. function ZiPaiRoomMessageView:playFaceAnimation(nSeatShowId,Id)
  529. --判断纹理是否存在
  530. local name = string.format("face%d_%d.png",Id,1)
  531. local cache = cc.SpriteFrameCache:getInstance()
  532. local spriteFrame = cache:getSpriteFrameByName(name);
  533. if tolua.isnull(spriteFrame) then
  534. print("spriteFrame is not in cache")
  535. return
  536. end
  537. local nodeFaceImage = self.nodes[nSeatShowId].nodeFaceImage
  538. nodeFaceImage:setScale(0.6)
  539. local indexFace = 0; --[1-10]
  540. local maxList = {10,10,10,10,10,10,10,24,10,12,11,10}
  541. --每隔多少秒切换一张图片
  542. local everyFrame = 0.1
  543. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  544. indexFace = indexFace + 1
  545. if 0 < indexFace and indexFace <= maxList[Id] then
  546. local name = string.format("face%d_%d.png",Id,indexFace)
  547. if not tolua.isnull(nodeFaceImage) then
  548. nodeFaceImage:loadTexture(name, cc.TextureResType.plistType)
  549. end
  550. else
  551. self.nodes[nSeatShowId].nodeFaceImage:setVisible(false)
  552. end
  553. end))
  554. if not maxList[Id] then
  555. return
  556. end
  557. local act = cc.Repeat:create(seq,maxList[Id] + 2)
  558. nodeFaceImage:stopAllActions()
  559. nodeFaceImage:runAction(act)
  560. nodeFaceImage:setVisible(true)
  561. end
  562. --播放表情音效
  563. function ZiPaiRoomMessageView:playFaceVoice(musicFilePath)
  564. -- 如果正在播放语音,则不处理
  565. if self.lastSpeakingSeatId then
  566. return
  567. end
  568. -- 如果正在播放音效,则停止音效
  569. if self.lastSound then
  570. stopVoice(self.lastSound)
  571. self.lastSound = nil
  572. end
  573. -- 记录当前的音效
  574. self.lastSound = playVoice(musicFilePath)
  575. end
  576. -- //////////////////////// //////////////////////// --
  577. function ZiPaiRoomMessageView:onChatMessageResponse(event)
  578. if not event or not event.response then
  579. return
  580. end
  581. -- 用户ID
  582. local nUserId = event.response.nUserId
  583. local nSeatShowId = app.room:getViewIdByUserId(nUserId);
  584. if not nSeatShowId then
  585. print("ZiPaiRoomMessageView:onChatMessageResponse() nSeatShowId = ", nSeatShowId);
  586. return
  587. end
  588. -- //类型 1: 表情 2: 语音 3:聊天
  589. if event.response.type == 1 then
  590. -- 表情
  591. local data = json.decode(event.response.content)
  592. local Id = data.Id or 1
  593. self:showFace(nSeatShowId, Id);
  594. elseif event.response.type == 2 then
  595. -- 语音
  596. local jsonData = json.decode(event.response.content)
  597. local recordUrl = tostring(jsonData.recordUrl)
  598. local recordTime = tonumber(jsonData.recordTime)
  599. --[[if self.recording then
  600. return
  601. end--]]
  602. -- 下载玩家的语音文件并播放
  603. -- 下载完成后返回该文件在本地存储的路径
  604. app.plugin:downloadRecord(nUserId, recordUrl, function(recordTag, filePath)
  605. local userId = tonumber(recordTag)
  606. local seatShowId = app.room:getViewIdByUserId(userId)
  607. if not seatShowId then
  608. print("ZiPaiRoomMessageView:onChatMessageResponse() seatShowId = ", seatShowId);
  609. return
  610. end
  611. self.playerVoice[seatShowId].filePath = filePath
  612. end);
  613. -- 记录该玩家的语音文件,重播要用
  614. self.playerVoice[nSeatShowId] = {}
  615. self.playerVoice[nSeatShowId].recordUrl = recordUrl;
  616. self.playerVoice[nSeatShowId].recordTime = recordTime;
  617. -- 该玩家头像上播放说话的效果
  618. self:showSpeakClip(nSeatShowId)
  619. elseif event.response.type == 3 then
  620. -- 聊天
  621. local data = json.decode(event.response.content)
  622. local Id = data.Id
  623. local sexId = data.sexId
  624. self:showChat(nSeatShowId, Id,sexId);
  625. elseif event.response.type == 4 then
  626. -- 道具
  627. local data = json.decode(event.response.content)
  628. local uidStarId = data.uidStarId
  629. local uidEndId = data.uidEndId
  630. local propId = data.propId
  631. local isQunFa = data.isQunFa
  632. self:showProp(uidStarId, uidEndId,propId,isQunFa)
  633. else
  634. -- 未知的
  635. end
  636. end
  637. --发送道具
  638. function ZiPaiRoomMessageView:showProp(uidStarId, uidEndId,propId,isQunFa)
  639. response = {}
  640. response.uidStarId = uidStarId
  641. response.uidEndId = uidEndId
  642. response.propId = propId
  643. response.isQunFa = isQunFa
  644. app.room:dispatchEvent({name = "showProp",response = response});
  645. end
  646. return ZiPaiRoomMessageView;