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.

505 lines
13 KiB

  1. local Functions = require("pk_erdoudizhu.luaScript.Functions_ERDouDiZhu")
  2. -- 房间设置界面
  3. local RoomPlayerView_ERDouDiZhu = class("RoomPlayerView_ERDouDiZhu", cc.UIView)
  4. function RoomPlayerView_ERDouDiZhu:ctor()
  5. RoomPlayerView_ERDouDiZhu.super.ctor(self)
  6. end
  7. function RoomPlayerView_ERDouDiZhu:onEnter()
  8. RoomPlayerView_ERDouDiZhu.super.onEnter(self)
  9. local ui = loadUI("pk_erdoudizhu/res/ui/ui_fangjian/doudizhu_ui_PlayerView.ui")
  10. self:addChild(ui)
  11. self.ui = ui
  12. --默认隐藏玩家头像
  13. for i = 1, 4 do
  14. local player = self.ui.Items["Layout_Player_" .. i]
  15. if player then
  16. player:setVisible(false)
  17. end
  18. end
  19. end
  20. function RoomPlayerView_ERDouDiZhu:getPlayerData(type, viewId)
  21. local player = self.ui.Items["Layout_Player_" .. viewId]
  22. if player then
  23. if type == "sex" then
  24. return player.userInfo.sex
  25. end
  26. end
  27. return nil
  28. end
  29. --刷新玩家
  30. function RoomPlayerView_ERDouDiZhu:updatePlayer(playerInfo, viewId)
  31. if playerInfo then
  32. self:initPlayer(playerInfo, viewId)
  33. else
  34. for _,v in pairs(app.room.roomInfo.memberList) do
  35. self:initPlayer(v, app.room:getViewIdByUserId(v.nUserId))
  36. end
  37. end
  38. end
  39. --更新玩家信息
  40. function RoomPlayerView_ERDouDiZhu:initPlayer(playerInfo, viewId)
  41. logE("RoomPlayerView_ERDouDiZhu initPlayer viewId : " .. viewId)
  42. logE("RoomPlayerView_ERDouDiZhu initPlayer playerInfo : " .. table.tostring(playerInfo))
  43. local player = self.ui.Items["Layout_Player_" .. viewId]
  44. if player then
  45. player:setVisible(true)
  46. local userInfo = json.decode(playerInfo.userInfo)
  47. player.playerInfo = playerInfo
  48. player.userInfo = userInfo
  49. --头像
  50. local head = self.ui.Items["Image_Head_" .. viewId]
  51. setDefaultHeadImg(userInfo.sex, playerInfo.nUserId, head, head:getContentSize().width)
  52. setPlayerHeadImage(playerInfo.nUserId, userInfo.headimgurl, head)
  53. --名字
  54. local nickname = userInfo.nickname or "error"
  55. self.ui.Items["Text_Name_" .. viewId]:setText(nickname)
  56. --分数
  57. local nTotalScore = playerInfo.nTotalScore or 0
  58. self.ui.Items["Text_Score_" .. viewId]:setText(nTotalScore)
  59. --庄家
  60. local nBankerId = app.room.roomInfo.nBankerId or 0
  61. self.ui.Items["Image_Banker_" .. viewId]:setVisible(nBankerId == playerInfo.nUserId)
  62. --离线 (0:离线、1:在线)
  63. local nOnlineStatus = playerInfo.nOnlineStatus or 1
  64. self.ui.Items["Image_OffLine_" .. viewId]:setVisible(nOnlineStatus == 0)
  65. --头像变灰
  66. self:setHeadGreyEnabled(nOnlineStatus == 0, viewId)
  67. --准备 (0:未准备、1:已准备)
  68. local nPlayerFlag = playerInfo.nPlayerFlag or 0
  69. self.ui.Items["Image_Ready_" .. viewId]:setVisible(nPlayerFlag == 1)
  70. --加倍
  71. local askBei = playerInfo.askBei or 0
  72. self.ui.Items["Image_AskBei_" .. viewId]:setVisible(askBei == 1)
  73. --闹钟
  74. self.ui.Items["Image_Clock_" .. viewId]:setVisible(false)
  75. --请让我再想想
  76. self.ui.Items["Image_Pop_" .. viewId]:setVisible(false)
  77. -- 头像框
  78. self.ui.Items["Image_HeadMask_" .. viewId]:setVisible(false)
  79. -- 托管
  80. self.ui.Items['ImageView_tuoguan_' .. viewId]:setVisible(false)
  81. --剩余牌
  82. local leftNumText = self.ui.Items["Text_LeftNum_" .. viewId]
  83. local leftNumImage = self.ui.Items["Image_LeftNum_" .. viewId]
  84. if leftNumText then
  85. leftNumText:setVisible(false)
  86. end
  87. if leftNumImage then
  88. leftNumImage:setVisible(false)
  89. end
  90. end
  91. end
  92. --隐藏玩家
  93. function RoomPlayerView_ERDouDiZhu:hidePlayer(viewId)
  94. local player = self.ui.Items["Layout_Player_" .. viewId]
  95. logE("RoomPlayerView_ERDouDiZhu hidePlayer viewId : " .. viewId)
  96. if player then
  97. player:setVisible(false)
  98. end
  99. end
  100. --刷新分数
  101. function RoomPlayerView_ERDouDiZhu:updateScore(viewId, totalScore)
  102. local score = self.ui.Items["Text_Score_" .. viewId]
  103. logE("RoomPlayerView_ERDouDiZhu updateScore viewId : " .. viewId)
  104. if score then
  105. score:setText("" .. totalScore)
  106. end
  107. end
  108. --显隐剩余牌
  109. function RoomPlayerView_ERDouDiZhu:setLeftNumVisible(bVisible, viewId, num)
  110. --房间规则
  111. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  112. --是否是回放
  113. if app.room.roomInfo.isRecord then
  114. return
  115. end
  116. -- 剩余牌
  117. local isNotShowLeftNumCard = false
  118. logE("RoomPlayerView_ERDouDiZhu setReadyVisible bVisible : " .. (bVisible and 1 or 0))
  119. logE("RoomPlayerView_ERDouDiZhu setReadyVisible viewId : " .. (viewId and viewId or -1))
  120. logE("RoomPlayerView_ERDouDiZhu setReadyVisible num : " .. (num and num or -1))
  121. if not isNotShowLeftNumCard then
  122. -- 显示剩余牌
  123. if viewId == -1 then
  124. for i = 1, 4 do
  125. local leftNumText = self.ui.Items["Text_LeftNum_" .. i]
  126. local leftNumImage = self.ui.Items["Image_LeftNum_" .. i]
  127. if leftNumText then
  128. leftNumText:setVisible(bVisible)
  129. if bVisible then
  130. leftNumText:setText("" .. num)
  131. end
  132. end
  133. if leftNumImage then
  134. leftNumImage:setVisible(bVisible)
  135. end
  136. end
  137. else
  138. local leftNumText = self.ui.Items["Text_LeftNum_" .. viewId]
  139. local leftNumImage = self.ui.Items["Image_LeftNum_" .. viewId]
  140. if leftNumText then
  141. leftNumText:setVisible(bVisible)
  142. if bVisible then
  143. leftNumText:setText("" .. num)
  144. end
  145. end
  146. if leftNumImage then
  147. leftNumImage:setVisible(bVisible)
  148. end
  149. end
  150. end
  151. -- 显示闹钟
  152. if viewId == -1 then
  153. self:cleanAllBaoJing()
  154. else
  155. if num == 1 or num == 2 then
  156. self:showBaoJingAni(viewId)
  157. Functions.playLastNumVoice(num, self:getPlayerData('sex', viewId))
  158. else
  159. self:showBaoJingAni(viewId, true)
  160. end
  161. end
  162. end
  163. --显隐准备
  164. function RoomPlayerView_ERDouDiZhu:setReadyVisible(bVisible, viewId)
  165. local ready = self.ui.Items["Image_Ready_" .. viewId]
  166. logE("RoomPlayerView_ERDouDiZhu showReady viewId : " .. viewId)
  167. if ready then
  168. ready:setVisible(bVisible)
  169. end
  170. end
  171. function RoomPlayerView_ERDouDiZhu:getChatViewPos()
  172. local headInfos = {}
  173. for i = 1, 4 do
  174. local head = self.ui.Items["Image_Head_" .. i]
  175. local player = self.ui.Items["Layout_Player_" .. i]
  176. if head and player then
  177. table.insert(headInfos, {headPos = cc.pAdd(cc.pAdd(player:getPosition(), head:getPosition()), cc.p(0, 0))})
  178. end
  179. end
  180. return headInfos
  181. end
  182. function RoomPlayerView_ERDouDiZhu:setOffLineVisible(bVisible, viewId)
  183. local offLine = self.ui.Items["Image_OffLine_" .. viewId]
  184. if offLine then
  185. offLine:setVisible(bVisible)
  186. --头像变灰
  187. self:setHeadGreyEnabled(bVisible, viewId)
  188. end
  189. end
  190. function RoomPlayerView_ERDouDiZhu:setHeadGreyEnabled(bVisible, viewId)
  191. local head = self.ui.Items["Image_Head_" .. viewId]
  192. local headMask = self.ui.Items["Image_HeadMask_" .. viewId]
  193. if head and headMask then
  194. head:setGreyEnabled(bVisible)
  195. headMask:setGreyEnabled(bVisible)
  196. end
  197. end
  198. function RoomPlayerView_ERDouDiZhu:bankerAni(viewId)
  199. local banker = self.ui.Items["Image_Banker_" .. viewId]
  200. if banker then
  201. banker:stopAllActions()
  202. banker:runAction(
  203. cc.Sequence:create(
  204. cc.ScaleTo(0, 2)
  205. )
  206. )
  207. end
  208. end
  209. function RoomPlayerView_ERDouDiZhu:setBankerVisible(bVisible, viewId)
  210. local banker = self.ui.Items["Image_Banker_" .. viewId]
  211. if banker then
  212. banker:setVisible(bVisible)
  213. end
  214. end
  215. function RoomPlayerView_ERDouDiZhu:setClockVisibel(bVisible, viewId, times, endFunc)
  216. local clock = self.ui.Items["Image_Clock_" .. viewId]
  217. if clock then
  218. clock:setVisible(bVisible)
  219. local imagePop = self.ui.Items["Image_Pop_" .. viewId]
  220. if imagePop then
  221. imagePop:setVisible(false)
  222. end
  223. local time = self.ui.Items["Text_Clock_" .. viewId]
  224. time:stopAllActions()
  225. if bVisible then
  226. local timesEx = times
  227. time:runAction(
  228. cc.RepeatForever:create(
  229. cc.Sequence:create(
  230. cc.CallFunc:create(function()
  231. time:setText("" .. timesEx)
  232. timesEx = timesEx - 1
  233. if timesEx < 5 then
  234. -- imagePop:setVisible(true)
  235. if timesEx < 0 then
  236. time:stopAllActions()
  237. if endFunc then
  238. endFunc(viewId)
  239. end
  240. end
  241. end
  242. end),
  243. cc.DelayTime:create(1.0)
  244. )
  245. )
  246. )
  247. end
  248. end
  249. end
  250. function RoomPlayerView_ERDouDiZhu:setTipsVisible(tipsType, bVisible, viewId, data)
  251. --显示锚点设置
  252. local anchorPont = {
  253. [1] = cc.p(1, 0.5),
  254. [2] = cc.p(0.5, 0.5),
  255. [3] = cc.p(0, 0.5),
  256. [4] = cc.p(0.5, 0.5),
  257. }
  258. local tipsFunc = {}
  259. --叫分
  260. tipsFunc["tips_jiaofen"] = function(nodeParent)
  261. local tips = nodeParent["tips_jiaofen"]
  262. if tips then
  263. tips:removeFromParent()
  264. nodeParent["tips_jiaofen"] = nil
  265. end
  266. if bVisible then
  267. local tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_fen%d.png", data.askLoard))
  268. if tipsEx then
  269. tipsEx:setAnchorPoint(anchorPont[viewId])
  270. nodeParent["tips_jiaofen"] = tipsEx
  271. nodeParent:addChild(tipsEx)
  272. end
  273. end
  274. end
  275. -- 叫地主
  276. tipsFunc["tips_jiaodizhu"] = function(nodeParent)
  277. local tips = nodeParent["tips_jiaodizhu"]
  278. if tips then
  279. tips:removeFromParent()
  280. nodeParent["tips_jiaodizhu"] = nil
  281. end
  282. if bVisible then
  283. local tipsEx = nil
  284. if data.askLoard ~= 0 then
  285. tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_jiao.png"))
  286. else
  287. tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_fen0.png"))
  288. end
  289. if tipsEx then
  290. tipsEx:setAnchorPoint(anchorPont[viewId])
  291. nodeParent["tips_jiaodizhu"] = tipsEx
  292. nodeParent:addChild(tipsEx)
  293. end
  294. end
  295. end
  296. -- 抢地主
  297. tipsFunc["tips_qiangdizhu"] = function(nodeParent)
  298. local tips = nodeParent["tips_qiangdizhu"]
  299. if tips then
  300. tips:removeFromParent()
  301. nodeParent["tips_qiangdizhu"] = nil
  302. end
  303. if bVisible then
  304. local tipsEx = nil
  305. if data.opType ~= 0 then
  306. tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_qiang.png"))
  307. end
  308. if tipsEx then
  309. tipsEx:setAnchorPoint(anchorPont[viewId])
  310. nodeParent["tips_qiangdizhu"] = tipsEx
  311. nodeParent:addChild(tipsEx)
  312. end
  313. end
  314. end
  315. --加倍
  316. tipsFunc["tips_jiabei"] = function(nodeParent)
  317. local tips = nodeParent["tips_jiabei"]
  318. if tips then
  319. tips:removeFromParent()
  320. nodeParent["tips_jiabei"] = nil
  321. end
  322. if bVisible then
  323. local tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_bei%d.png", data.askBei))
  324. if tipsEx then
  325. tipsEx:setAnchorPoint(anchorPont[viewId])
  326. nodeParent["tips_jiabei"] = tipsEx
  327. nodeParent:addChild(tipsEx)
  328. end
  329. self:setAskBeiVisible(data.askBei == 1, viewId)
  330. end
  331. end
  332. --要不起,不出
  333. tipsFunc["tips_yaobuqi"] = function(nodeParent)
  334. local tips = nodeParent["tips_yaobuqi"]
  335. if tips then
  336. tips:removeFromParent()
  337. nodeParent["tips_yaobuqi"] = nil
  338. end
  339. if bVisible then
  340. local tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_yaobuqi.png"))
  341. if tipsEx then
  342. tipsEx:setAnchorPoint(anchorPont[viewId])
  343. nodeParent["tips_yaobuqi"] = tipsEx
  344. nodeParent:addChild(tipsEx)
  345. end
  346. end
  347. end
  348. --显隐对应的提示
  349. local tipsNode = self.ui.Items["Layout_Tips_" .. viewId]
  350. if tipsNode then
  351. local tipsFuncEx = tipsFunc["" .. tipsType]
  352. if tipsFuncEx then
  353. tipsFuncEx(tipsNode)
  354. end
  355. end
  356. end
  357. -- 隐藏非传的内容文本
  358. function RoomPlayerView_ERDouDiZhu:setTipsVisibleExcept(tab, viewId)
  359. if not tab then
  360. tab = {}
  361. end
  362. local temp = {
  363. tips_jiaofen = true,
  364. tips_jiaodizhu = true,
  365. tips_qiangdizhu = true,
  366. tips_jiabei = true,
  367. tips_yaobuqi = true,
  368. }
  369. for i, v in pairs(tab) do
  370. temp[v] = false
  371. end
  372. for i, v in pairs(temp) do
  373. if v then
  374. self:setTipsVisible(i, false, viewId)
  375. end
  376. end
  377. end
  378. function RoomPlayerView_ERDouDiZhu:setAskBeiVisible(bVisible, viewId)
  379. local askBei = self.ui.Items["Image_AskBei_" .. viewId]
  380. if askBei then
  381. askBei:setVisible(bVisible)
  382. end
  383. end
  384. function RoomPlayerView_ERDouDiZhu:showBaoJingAni(viewId, clean)
  385. local nodeLayout = self.ui.Items['Layout_baojing_'..viewId]
  386. nodeLayout:removeAllChildren()
  387. if clean then
  388. return
  389. end
  390. --不需要报警器
  391. do
  392. return
  393. end
  394. --ani
  395. local img = cc.ImageView:createNode()
  396. img:loadTextureFromPlist("ddz_baojing_bg.png")
  397. nodeLayout:addChild(img)
  398. img:setPosition(cc.p(nodeLayout:getContentSize().width/2,nodeLayout:getContentSize().height/2))
  399. --light
  400. local light = cc.ImageView:createNode("ddz_baojing_bg.png")
  401. nodeLayout:addChild(light)
  402. light:setPosition(cc.p(nodeLayout:getContentSize().width/2,nodeLayout:getContentSize().height/2))
  403. local indexFace = 0;
  404. --每隔多少秒切换一张图片
  405. local everyFrame = 0.01
  406. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  407. indexFace = indexFace + 1
  408. if 0 < indexFace and indexFace <= 8 then
  409. local name = string.format("ddz_baojing_%d.png",indexFace)
  410. light:loadTextureFromPlist(name)
  411. else
  412. indexFace = 0
  413. end
  414. end))
  415. local act = cc.RepeatForever:create(seq)
  416. light:runAction(act)
  417. -- 经过几面后,移除警报动画
  418. local removeDelayTime = 1.5
  419. local function removeCallBack()
  420. nodeLayout:stopAllActions()
  421. nodeLayout:removeAllChildren()
  422. end
  423. schedule(nodeLayout, removeCallBack, removeDelayTime)
  424. end
  425. function RoomPlayerView_ERDouDiZhu:cleanAllBaoJing()
  426. for i = 1, 4 do
  427. local nodeLayout = self.ui.Items['Layout_baojing_'..i]
  428. nodeLayout:removeAllChildren()
  429. end
  430. end
  431. function RoomPlayerView_ERDouDiZhu:showTuoGuanByViewId(viewId, isShow)
  432. local nodeImg = self.ui.Items['ImageView_tuoguan_' .. viewId]
  433. if nodeImg then
  434. nodeImg:setVisible(isShow)
  435. end
  436. end
  437. return RoomPlayerView_ERDouDiZhu