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.

422 lines
13 KiB

  1. -- 房间内用于显示玩家信息的界面
  2. local ChatDef = require("luaScript.GameChatDefine")
  3. local RoomPlayerInfoView = class("RoomPlayerInfoView", cc.UIView)
  4. --[[
  5. 使用方法:
  6. local view = import("luaScript.Views.Room.RoomPlayerInfoView"):new(nUserId, userInfo, posHead)
  7. view:setAnchorPoint(cc.p(0.5, 0.5))
  8. app:showWaitDialog(view, 0, true)
  9. --]]
  10. -- uid : 玩家游戏ID
  11. -- userInfo : 玩家信息
  12. -- headPos : 玩家头像未知
  13. function RoomPlayerInfoView:ctor(uid, userInfo, headPos, szHead, recordTime, replayRecord,idVisible)
  14. RoomPlayerInfoView.super.ctor(self);
  15. self.uid = uid;
  16. self.headPos = headPos;
  17. self.szHead = szHead;
  18. self.idVisible = idVisible;
  19. self.recordTime = tonumber(recordTime) or 0
  20. self.replayRecord = replayRecord;
  21. local ttUserInfo = type(userInfo)=="string" and json.decode(userInfo) or userInfo
  22. self.sex = tonumber(ttUserInfo.sex) or 1
  23. self.imageUrl = ttUserInfo.headimgurl
  24. self.nickname = ttUserInfo.nickname
  25. local ui = loadUI("res/ui/ui_fangjian/ui_fangjian_wanjiaxinxi.ui")
  26. self.ui = ui;
  27. self:addChild(ui);
  28. end
  29. function RoomPlayerInfoView:onEnter()
  30. RoomPlayerInfoView.super.onEnter(self)
  31. -- 点击空白区域关闭界面
  32. self.ui.Items.Layout:registerClick(handler(self, self.onClose))
  33. -- 玩家ID
  34. self.ui.Items.Text_ID:setText(tostring(self.uid))
  35. --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
  36. -- begin
  37. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  38. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  39. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  40. if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
  41. local clubInfo = app.club_php.clubList[app.club_php.clubID]
  42. if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
  43. self.ui.Items.Layout_4:setVisible(true)
  44. else
  45. self.ui.Items.Layout_4:setVisible(false)
  46. end
  47. end
  48. end
  49. end
  50. if self.uid == tonumber(app.user.loginInfo.uid) then
  51. self.ui.Items.Layout_4:setVisible(true)
  52. end
  53. self.ui.Items.Layout_Info:requestDoLayout()
  54. self.ui.Items.Layout_Info:doLayout()
  55. -- end
  56. -- 玩家性别
  57. -- local sexImage
  58. -- if self.sex == 1 then
  59. -- sexImage = "userInfo_boy.png"
  60. -- else
  61. -- sexImage = "userInfo_girl.png"
  62. -- end
  63. -- self.ui.Items.ImageView_Sex:loadTexture(sexImage, cc.TextureResType.plistType)
  64. -- 玩家昵称
  65. local nickname = getShortName(self.nickname)
  66. self.ui.Items.Text_Name:setText(nickname)
  67. -- 玩家头像
  68. setPlayerHeadImage(self.uid, self.imageUrl, self.ui.Items.ImageView_head)
  69. -- 信用评级
  70. --self.ui.Items.Text_XingYong:setVisible(false)
  71. -- 注册时间
  72. -- local time = os.date("%Y.%m.%d",os.time())
  73. self.ui.Items.Text_4:setVisible(false)
  74. self.ui.Items.Text_RegTime:setVisible(false)--:setText(tostring(time))
  75. --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
  76. -- begin
  77. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  78. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  79. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  80. --隐私数据
  81. local clubInfo = app.club_php.clubList[app.club_php.clubID]
  82. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  83. if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
  84. if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
  85. self.idVisible = true
  86. else
  87. self.idVisible = false
  88. end
  89. end
  90. end
  91. end
  92. if self.uid == tonumber(app.user.loginInfo.uid) then
  93. self.idVisible = true
  94. end
  95. self:setIDVisible(self.idVisible)
  96. -- 语音按钮
  97. -- local strRecordTime = tostring(self.recordTime).."''"
  98. -- self.ui.Items.Text_Voice:setText(strRecordTime);
  99. self.ui.Items.Button_uplog:registerClick(handler(self, self.onClickUpLog))
  100. self.ui.Items.Button_voice:registerClick(handler(self, self.onClickVoice))
  101. -- self.ui.Items.Button_Close:registerClick(handler(self, self.onClose))
  102. -- 道具按钮
  103. local Item_Prop = self.ui.Items.Item_Prop
  104. Item_Prop:setVisible(false)
  105. local uiScorllView = self.ui.Items.ScrollView
  106. uiScorllView:removeAllChildren()
  107. uiScorllView:hideAllBar();
  108. uiScorllView:getInnerContainer():setAutoSize(true)
  109. --loadSpriteFromFile(Prop_Btn_File)
  110. -- loadSpriteFrameFile(Prop_Btn_File)
  111. for _, propId in ipairs(GamePropSort) do
  112. local config = GameProp[propId]
  113. if config then
  114. local item = Item_Prop:getCopied()
  115. local uiBtn = item:getChildByName("Button_Prop")
  116. local ImageView_Lock = item:getChildByName("ImageView_Lock")
  117. ImageView_Lock:setVisible(false)
  118. -- local progress = nil
  119. -- local percent = 0
  120. if config.icon then
  121. uiBtn:loadTextureNormal("res/ui/zy_tongyong/zy_prop/"..config.icon)
  122. uiBtn:loadTexturePressed("res/ui/zy_tongyong/zy_prop/"..config.icon)
  123. uiBtn:loadTextureDisabled("res/ui/zy_tongyong/zy_prop/"..config.icon)
  124. -- local sp = cc.Sprite:createWithSpriteFrameName("userInfo_prop_bgr.png")
  125. -- local progress = cc.ProgressTimer:create(sp)
  126. -- progress:setPosition(uiBtn:getPosition())
  127. -- progress:setTag(100)
  128. -- progress:setReverseDirection(true)
  129. -- progress:setColor(cc.c3b(255,0,0))
  130. -- item:addChild(progress)
  131. end
  132. uiBtn:registerClick(function() self:onClickProp(propId) end)
  133. uiScorllView:addChild(item)
  134. end
  135. end
  136. -- self.ui.Items.ImageView_me:setVisible(isMe)
  137. -- self.ui.Items.Text_tipOther:setVisible(isMe)
  138. -- self.ui.Items.Text_tipOther_1:setVisible(isMe)
  139. self:updateTips()
  140. self:startPropTimer()
  141. -- self:updatePosition()
  142. self:checkPropModuleStatus()
  143. end
  144. function RoomPlayerInfoView:updateTips()
  145. local isMe = self.uid == app.user.loginInfo.uid
  146. self.ui.Items.Button_uplog:setVisible(isMe)
  147. if app.user:canSendChatMessage(ChatDef.MessageType.Prop) then
  148. if isMe then
  149. self.ui.Items.Text_tip:setText("点击道具全桌群发")
  150. else
  151. self.ui.Items.Text_tip:setText("点击发送道具")
  152. end
  153. end
  154. end
  155. function RoomPlayerInfoView:startPropTimer()
  156. if app.user:canSendChatMessage(ChatDef.MessageType.Prop) then
  157. return
  158. end
  159. local propTime = ChatDef.TimeInterval[ChatDef.MessageType.Prop]
  160. local lastTime = app.user:getLastChatTime(ChatDef.MessageType.Prop)
  161. local tempTime = os.time() - lastTime -->= ChatDef.TimeInterval[ChatDef.MessageType.Prop]
  162. local startTime = propTime - tempTime
  163. if startTime<0 then
  164. startTime = propTime
  165. end
  166. local childs = self.ui.Items.ScrollView:getChildren()
  167. local allBtn = {}
  168. -- local allTime = {}
  169. local allLock = {}
  170. for k,item in pairs(childs) do
  171. local Button_Prop = item:getChildByName("Button_Prop")
  172. -- local Text_Time = item:getChildByName("Text_Time")
  173. local ImageView_Lock = item:getChildByName("ImageView_Lock")
  174. -- local progress = item:getChildByTag(100)
  175. -- progress:setPercentage(100)
  176. -- Text_Time:setLocalZOrder(1)
  177. --
  178. -- Button_Prop:setColor(cc.c3b(0,0,0))
  179. Button_Prop:setTouchEnabled(false)
  180. ImageView_Lock:setVisible(true)
  181. table.insert(allBtn,Button_Prop)
  182. -- table.insert(allTime,Text_Time)
  183. -- table.insert(allLock,progress)
  184. table.insert(allLock,ImageView_Lock)
  185. end
  186. -- local function setAllPercentage(value)
  187. -- -- logD("value:"..value)
  188. -- for k,lock in pairs(allLock) do
  189. -- -- lock:setVisible(false)
  190. -- lock:setPercentage(value)
  191. -- end
  192. -- end
  193. local function setAllLockFalse()
  194. -- logD("value:"..value)
  195. for k,lock in pairs(allLock) do
  196. lock:setVisible(false)
  197. -- lock:setPercentage(value)
  198. end
  199. end
  200. local function setAllBtn()
  201. for k,btn in pairs(allBtn) do
  202. -- btn:setColor(cc.c3b(255,255,255))
  203. btn:setTouchEnabled(true)
  204. end
  205. end
  206. local function setAllTime(t)
  207. self.ui.Items.Text_tip:setText(t.."秒后可发送道具")
  208. -- for k,time in pairs(allTime) do
  209. -- time:setText(t)
  210. -- end
  211. end
  212. setAllTime(startTime)
  213. self:stopAllActions()
  214. self:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.DelayTime:create(1),cc.CallFunc:create(function()
  215. startTime = startTime-1
  216. if startTime<=0 then
  217. startTime = 0
  218. self:stopAllActions()
  219. setAllBtn()
  220. -- setAllPercentage(0)
  221. setAllLockFalse()
  222. self:updateTips()
  223. -- setAllTime("")
  224. return
  225. -- startTime = ChatDef.TimeInterval[ChatDef.MessageType.Prop]
  226. end
  227. -- setAllPercentage(100-(propTime-startTime)/propTime*100)
  228. setAllTime(startTime)
  229. -- progress:setPercentage(startTime/ChatDef.TimeInterval[ChatDef.MessageType.Prop]*100)
  230. end))))
  231. end
  232. -- 根据玩家头像节点的位置,自动调整本界面的位置
  233. function RoomPlayerInfoView:updatePosition()
  234. -- 把屏幕划分为9个相等的区域,根据玩家头像所在的区域,决定本界面在玩家头像的什么位置
  235. local function getAnchorPoint(pos)
  236. local qu = 2
  237. --local winSize = cc.Director:getInstance():getOpenGLView():getFrameSize();
  238. local winSize = cc.Director:getInstance():getWinSize()
  239. local minWidth = winSize.width / qu;
  240. local minHeight = winSize.height / qu;
  241. local szHead = self.szHead;
  242. -- 左下
  243. if pos.x <= minWidth and pos.y <= minHeight then
  244. return cc.p(0,0), cc.p(szHead.width / 2, -szHead.height / 2); --
  245. -- 左
  246. elseif pos.x <= minWidth and pos.y >= minHeight and pos.y <= minHeight * (qu - 1) then
  247. return cc.p(0,0.5), cc.p(szHead.width / 2, 0);
  248. -- 左上
  249. elseif pos.x <= minWidth and pos.y >= minHeight * (qu - 1) then
  250. return cc.p(0,1), cc.p(szHead.width / 2, szHead.height / 2);--
  251. -- 上
  252. elseif pos.x >= minWidth and pos.x <= minWidth * (qu - 1) and pos.y >= minHeight * (qu - 1) then
  253. return cc.p(0.5,1), cc.p(0, 0);---szHead.height / 2
  254. -- 右上
  255. elseif pos.x >= minWidth * (qu - 1) and pos.y >= minHeight * (qu - 1) then
  256. return cc.p(1,1), cc.p(-szHead.width / 2, szHead.height / 2);---szHead.height / 2
  257. -- 右
  258. elseif pos.x >= minWidth * (qu - 1) and pos.y >= minHeight and pos.y <= minHeight * (qu - 1) then
  259. return cc.p(1,0.5), cc.p(-szHead.width / 2, 0);
  260. -- 右下
  261. elseif pos.x >= minWidth * (qu - 1) and pos.y <= minHeight then
  262. return cc.p(1,0), cc.p(-szHead.width / 2, -szHead.height / 2); --szHead.height / 2
  263. -- 下
  264. elseif pos.x >= minWidth and pos.x <= minWidth * (qu - 1) and pos.y <= minHeight then
  265. return cc.p(0.5,0), cc.p(0, -szHead.height / 2 ); --szHead.height / 2
  266. -- 中
  267. else
  268. return cc.p(0,0), cc.p(0,0);
  269. end
  270. return cc.p(0,0), cc.p(0,0);
  271. end
  272. local anPoint, point = getAnchorPoint(self.headPos)
  273. local pos = cc.p(self.headPos.x + point.x, self.headPos.y + point.y );--
  274. self.ui.Items.Layout_1:setAnchorPoint(anPoint);
  275. self.ui.Items.Layout_1:setPosition(pos);
  276. end
  277. -- 发送道具
  278. function RoomPlayerInfoView:onClickProp(propIdx)
  279. if not app.user:canSendChatMessage(ChatDef.MessageType.Prop) then
  280. showTooltip("操作太过频繁,请稍后再发!")
  281. return
  282. end
  283. local uidSender = app.user.loginInfo.uid
  284. local uidReceiver = self.uid
  285. local data =
  286. {
  287. propIdx = propIdx,
  288. uidSender = uidSender,
  289. uidReceiver = uidReceiver,
  290. --isQunFa = uidSender == uidReceiver and 1 or 0,
  291. }
  292. local content = json.encode(data)
  293. local ret = app.user:sendChatMessage(ChatDef.MessageType.Prop, content);
  294. if ret then
  295. self:onClose()
  296. end
  297. end
  298. -- 上传日志
  299. function RoomPlayerInfoView:onClickUpLog( sender )
  300. playBtnEffect()
  301. local view = import("luaScript.Views.Room.UplogView"):new()
  302. view:setAnchorPoint(cc.p(0.5, 0.5))
  303. app:showWaitDialog(view)
  304. end
  305. -- 播放语音
  306. function RoomPlayerInfoView:onClickVoice()
  307. playBtnEffect()
  308. if self.recordTime <= 0 then
  309. showTooltip("无历史消息")
  310. return
  311. end
  312. if self.replayRecord then
  313. self.replayRecord(self.uid)
  314. end
  315. -- local nodeClip = self.ui.Items.Layout_2;
  316. -- nodeClip:playClip("say");
  317. -- nodeClip:runDelay(self.recordTime, function()
  318. -- nodeClip:stopClip("say")
  319. -- end)
  320. end
  321. -- 关闭界面
  322. function RoomPlayerInfoView:onClose()
  323. playBtnEffect()
  324. self:removeFromParent()
  325. end
  326. -- 关闭界面
  327. function RoomPlayerInfoView:setIDVisible(bVisible)
  328. self.ui.Items.Layout_4:setVisible(bVisible)
  329. self.ui.Items.Layout_Info:requestDoLayout()
  330. self.ui.Items.Layout_Info:doLayout()
  331. end
  332. ---
  333. -- 检测互动道具是否可以使用
  334. -- 亲友圈配置
  335. -- @return
  336. --
  337. function RoomPlayerInfoView:checkPropModuleStatus ()
  338. if not app.room then
  339. return
  340. end
  341. local roomInfo = app.room.roomInfo or {}
  342. local strGameInfo = roomInfo.strGameInfo or roomInfo.nGameInfo or ""
  343. local info = json.decode(strGameInfo) or {}
  344. local isFobid = info.forbidProp == 1
  345. local childs = self.ui.Items.ScrollView:getChildren() or {}
  346. for k, item in pairs(childs) do
  347. item:getChildByName("Button_Prop"):setTouchEnabled(not isFobid)
  348. item:getChildByName("ImageView_Lock"):setVisible(isFobid)
  349. end
  350. if isFobid then
  351. self.ui.Items.Text_tip:setText("当前房间不可使用互动道具")
  352. end
  353. self.ui.Items.Button_voice:setVisible(not isFobid)
  354. end
  355. return RoomPlayerInfoView;