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.

148 lines
4.2 KiB

  1. local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine")
  2. local MJOtherPlayerInfoView = class("MJOtherPlayerInfoView", cc.UIView)
  3. function MJOtherPlayerInfoView:ctor(nUserId)
  4. MJOtherPlayerInfoView.super.ctor(self);
  5. self.nUserId=nUserId
  6. local ui = loadUI("mj/res/ui/ui_fangjian/mj_ui_other_player_info.ui")
  7. self.ui = ui
  8. self:addChild(ui)
  9. end
  10. function MJOtherPlayerInfoView:onEnter()
  11. MJOtherPlayerInfoView.super.onEnter(self)
  12. self.ui.Items.Layout_Player_Info:setTouchEnabled(true)
  13. --更新头像
  14. local userInfo = app.room:getUserInfo(self.nUserId)
  15. local nickname = ""
  16. if userInfo and userInfo.nickname then
  17. nickname = getSubStringNickname(userInfo.nickname)
  18. -- self:updateUserHead(self.ui,v.nUserId, userInfo.sex, userInfo.headimgurl);
  19. setPlayerHeadImage(self.nUserId,userInfo.headimgurl,self.ui.Items.ImageView_Head)
  20. -- self.ui.Items.Text_Ip:setText("IP:"..userInfo.ip)
  21. end
  22. self.ui.Items.Text_Name:setText(nickname)
  23. self.ui.Items.Text_Id:setText("ID:"..self.nUserId)
  24. self.ui.Items.Text_Ip:setText("")
  25. self.ui.Items.Button_Voice:registerClick(function ()
  26. playBtnEffect()
  27. app.room:dispatchEvent({name = MJDefine.MJEvent.ReplayPlayerVoice, nUserId = self.nUserId})
  28. end)
  29. self:initProps()
  30. end
  31. function MJOtherPlayerInfoView:initProps()
  32. -- local nSeatShowId=app.room:getViewIdByUserId(self.nUserId)
  33. self.lastPropTouchTime = tonumber(loadUserInfo("lastPropTouchTime")) or 0
  34. saveUserInfo("lastPropTouchTime",self.lastPropTouchTime)
  35. if self.nUserId~=app.user.loginInfo.uid then
  36. self.ui.Items.ImageView_All_Send:setVisible(false)
  37. end
  38. self.ui.Items.ListView:setItemModel(self.ui.Items.Layout_Prop_Item)
  39. self.ui.Items.ListView:removeAllItems()
  40. --道具实现
  41. local tabProp={10,9,4,2,3,5,1,7,6,8}
  42. for i = 1 ,10 do
  43. self.ui.Items.ListView:pushBackDefaultItem()
  44. local item=self.ui.Items.ListView:getItem(i-1)
  45. local btnProp = item:getChildByName("Button_Prop") --string.format("Button_Prop_%d",i)
  46. btnProp:loadTextureNormal("mj_prop"..tabProp[i]..".png", cc.TextureResType.plistType)
  47. btnProp:registerClick(function ()
  48. playBtnEffect()
  49. if app.room.isOnLooker then
  50. showTooltip("旁观不允许发送道具")
  51. return
  52. end
  53. if table.nums(app.room.roomInfo.memberList) == 1 then
  54. showTooltip("桌子上没有其他人可以发哦")
  55. return
  56. end
  57. local curTime = os.time()
  58. local distance = curTime - self.lastPropTouchTime
  59. local disbandTime = 12
  60. if distance <= disbandTime then
  61. showTooltip(string.format("您操作太快,请%d秒后再试!",disbandTime - distance + 1))
  62. return
  63. end
  64. self.lastPropTouchTime = curTime
  65. saveUserInfo("lastPropTouchTime",self.lastPropTouchTime)
  66. if self.nUserId == app.user.loginInfo.uid then
  67. --群发道具
  68. --根据在线人数发送道具
  69. local propID = tabProp[i]
  70. --local targetUid = app.room:getUserIdByViewId(nSeatShowId)
  71. self:SendPropMessage(app.user.loginInfo.uid,self.nUserId,propID,4,1)
  72. else
  73. local propID = tabProp[i]
  74. --local targetUid = app.room:getUserIdByViewId(nSeatShowId)
  75. if not self.nUserId then
  76. showTooltip("道具:目标ID不存在")
  77. return
  78. end
  79. self:SendPropMessage(app.user.loginInfo.uid,self.nUserId,propID,4,0)
  80. end
  81. end)
  82. end
  83. end
  84. function MJOtherPlayerInfoView:SendPropMessage(uidStarId,uidEndId,propId,mType,isQunFa)
  85. -- self:onClickBG()
  86. if not app.user:canSendChatMessage(1) then
  87. showTooltip("您发送聊天信息的间隔时间太短,请稍后再发!")
  88. return
  89. end
  90. local sexId = 0
  91. local memberInfo = app.room.roomInfo.memberList[app.user.loginInfo.uid]
  92. if memberInfo then
  93. local userInfo = json.decode(memberInfo.userInfo)
  94. if not userInfo then
  95. return
  96. end
  97. --男1女2,默认是男生
  98. sexId = tonumber(userInfo.sex) or 1
  99. end
  100. local tt = json.decode(app.user.userInfo)
  101. local data =
  102. {
  103. uidStarId = uidStarId,
  104. uidEndId = uidEndId,
  105. propId = propId,
  106. isQunFa = isQunFa,
  107. areano = tt.areano,
  108. }
  109. -- 发送消息到服务器
  110. --1: 表情 2: 语音 3:聊天
  111. local str = json.encode(data)
  112. local isSendSuccess = app.user:sendChatMessage(mType, str);
  113. --[[if isSendSuccess == true then
  114. if mType == 4 then
  115. self:showProp(uidStarId, uidEndId,propId,isQunFa)
  116. end
  117. end--]]
  118. end
  119. return MJOtherPlayerInfoView;