25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

357 satır
11 KiB

  1. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  2. local MJRoomPlayerView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomPlayerView")
  3. local yibinmajiangRoomPlayerView = class("yibinmajiangRoomPlayerView", MJRoomPlayerView)
  4. function yibinmajiangRoomPlayerView:ctor()
  5. yibinmajiangRoomPlayerView.super.ctor(self);
  6. end
  7. function yibinmajiangRoomPlayerView:loadUI()
  8. local ui = loadUI("mj_yibinmajiang/res/ui_fangjian/mj_yibinmajiang_playerView.ui");
  9. self.ui = ui;
  10. self:addChild(ui);
  11. end
  12. function yibinmajiangRoomPlayerView:onEnter()
  13. self:loadUI()
  14. self:init()
  15. end
  16. function yibinmajiangRoomPlayerView:init()
  17. local names =
  18. {
  19. player = "Layout_player_%d", -- 头像绿圈根节点
  20. head = "ImageView_head_%d", -- 头像
  21. -- headBoarder = "ImageView_head_border_%d", --头像边
  22. name = "Text_Name_%d", -- 名字
  23. score = "Text_Score_%d", -- 总分数
  24. banker = "ImageView_banker_%d", -- 庄家
  25. readyState = "ImageView_ready_%d", -- 准备
  26. headInfo = "Layout_PlayerInfo_%d", --个人信息点击触发框
  27. offLine = "ImageView_offLine_%d", --离线标志
  28. --其他节点
  29. arrow = "ImageView_arrow_%d", -- 指示器
  30. tip = "ImageView_tip_%d", --提示操作图
  31. huxi = "Text_huxi_%d", --胡息
  32. qihu = "ImageView_qihu_%d", --弃胡
  33. -- bao = "ImageView_bao_%d", --爆
  34. piao = "ImageView_piao_%d", --飘
  35. -- baoAnim = "Layout_baoAnim_%d", --爆牌特效
  36. hu = "ImageView_hu_%d", --胡牌
  37. viewOrder = "ImageView_ViewId_%d", -- 座位
  38. dingque = "ImageView_DingQue_%d", -- 定缺
  39. hutype = 'ImageView_huType_%d', -- 胡牌类型
  40. huindex = 'ImageView_huIndex_%d', -- 胡牌顺序
  41. }
  42. self.allNodes = {}
  43. self.headSize = {}
  44. for i = 1,4 do--LHQ_GAME_CONST.LHQ_GAME_CONST_PLAYER do
  45. local nodes = {}
  46. --玩家根节点
  47. local namePlayer = string.format(names.player,i)
  48. local nodePlayer = self.ui.Items[namePlayer]
  49. -- nodePlayer:setVisible(false)
  50. nodes.player = nodePlayer
  51. --头像
  52. local nameHead = string.format(names.head,i)
  53. local nodeHead = self.ui.Items[nameHead]
  54. nodes.head = nodeHead
  55. nodeHead:setTouchEnabled(true)
  56. nodeHead:registerClick(function()
  57. self:onClickHead(i)
  58. end)
  59. -- 需要记录头像的原始尺寸
  60. if not self.headSize.width then
  61. self.headSize.width = nodeHead:getContentSize().width
  62. self.headSize.height = nodeHead:getContentSize().height
  63. end
  64. --昵称
  65. local nickName = string.format(names.name,i)
  66. local nodeName = self.ui.Items[nickName]
  67. nodes.name = nodeName
  68. nodeName:setText("")
  69. --总分
  70. local nickScore = string.format(names.score,i)
  71. local nodeScore = self.ui.Items[nickScore]
  72. nodes.score = nodeScore
  73. --庄家
  74. local nameBanker = string.format(names.banker,i)
  75. local nodeBanker = self.ui.Items[nameBanker]
  76. nodeBanker:setVisible(false)
  77. nodes.banker = nodeBanker
  78. --准备
  79. local nameReadyState = string.format(names.readyState,i)
  80. local nodeReadyState = self.ui.Items[nameReadyState]
  81. nodes.readyState = nodeReadyState
  82. --头像信息
  83. local headInfo = string.format(names.headInfo,i)
  84. local nodeheadInfo = self.ui.Items[headInfo]
  85. nodes.headInfo = nodeheadInfo
  86. --离线信息
  87. local offLine = string.format(names.offLine,i)
  88. local nodeoffLine = self.ui.Items[offLine]
  89. nodes.offLine = nodeoffLine
  90. --指示器
  91. -- local nameArrow = string.format(names.arrow,i)
  92. -- local nodeArrow = self.ui.Items[nameArrow]
  93. -- nodes.arrow = nodeArrow
  94. --tip
  95. local nameTip = string.format(names.tip,i)
  96. local nodeTip = self.ui.Items[nameTip]
  97. nodes.tip = nodeTip
  98. --huxi
  99. local nameHuxi = string.format(names.huxi,i)
  100. local nodeHuxi = self.ui.Items[nameHuxi]
  101. nodes.huxi = nodeHuxi
  102. --弃胡
  103. local nameQiHu = string.format(names.qihu,i)
  104. local nodeQiHu = self.ui.Items[nameQiHu]
  105. nodeQiHu:setVisible(false)
  106. nodes.qihu = nodeQiHu
  107. --飘
  108. local namePiao = string.format(names.piao,i)
  109. local nodePiao = self.ui.Items[namePiao]
  110. nodePiao:setVisible(false)
  111. nodes.piao = nodePiao
  112. --爆
  113. -- local nameBao = string.format(names.bao,i)
  114. -- local nodeBao = self.ui.Items[nameBao]
  115. -- nodeBao:setVisible(false)
  116. -- nodes.bao = nodeBao
  117. --胡
  118. local nameHu = string.format(names.hu,i)
  119. local nodeHu = self.ui.Items[nameHu]
  120. nodeHu:setVisible(false)
  121. nodes.hu = nodeHu
  122. --座位
  123. local nameViewOrder = string.format(names.viewOrder, i);
  124. local nodeViewOrder = self.ui.Items[nameViewOrder]
  125. nodes.viewOrder = nodeViewOrder
  126. -- 定缺
  127. local nameDingQue = string.format(names.dingque, i);
  128. local nodeDingQue = self.ui.Items[nameDingQue]
  129. nodes.dingque = nodeDingQue
  130. -- 胡牌类型
  131. local nameHuType = string.format(names.hutype, i);
  132. local nodeHuType = self.ui.Items[nameHuType]
  133. nodes.hutype = nodeHuType
  134. -- 胡牌顺序
  135. local nameHuIndex = string.format(names.huindex, i);
  136. local nodeHuIndex = self.ui.Items[nameHuIndex]
  137. nodes.huindex = nodeHuIndex
  138. --报牌动画
  139. -- local nameBaoAnim = string.format(names.baoAnim, i);
  140. -- local nodeBaoAnim = self.ui.Items[nameBaoAnim];
  141. -- nodeBaoAnim:setVisible(false);
  142. -- nodeBaoAnim:setScale(0.9);
  143. -- nodes.baoAnim = nodeBaoAnim;
  144. self.allNodes[i] = nodes
  145. end
  146. self:initChatComponent()
  147. self.PropAniManager = import("luaScript.Tools.PropAniPlayer"):new(self.ui)
  148. --发送道具
  149. self:bindEvent(app.room,"showProp" , handler(self , self.showProp));
  150. self:bindEvent(app , MJDefine.MJEvent.ChangeChatEnable , handler(self , self.onChangeChatEnable))
  151. end
  152. function yibinmajiangRoomPlayerView:initChatComponent()
  153. yibinmajiangRoomPlayerView.super.initChatComponent(self);
  154. local voiceEnable = tonumber(loadUserInfo("voiceEnable")) or 1
  155. local propEnable = tonumber(loadUserInfo("propEnable")) or 1
  156. self.chatComponentView:setVoiceEnabled(voiceEnable==1)
  157. self.chatComponentView:setPropEnabled(propEnable==1)
  158. end
  159. function yibinmajiangRoomPlayerView:onChangeChatEnable()
  160. if not self.chatComponentView or tolua.isnull(self.chatComponentView) then
  161. return
  162. end
  163. local voiceEnable = tonumber(loadUserInfo("voiceEnable")) or 1
  164. local propEnable = tonumber(loadUserInfo("propEnable")) or 1
  165. self.chatComponentView:setVoiceEnabled(voiceEnable==1)
  166. self.chatComponentView:setPropEnabled(propEnable==1)
  167. end
  168. function yibinmajiangRoomPlayerView:updatePlayerInfo( index )
  169. yibinmajiangRoomPlayerView.super.updatePlayerInfo(self, index);
  170. local nodes = self.allNodes[index];
  171. local nUserId = app.room.seatShowList[index];
  172. local roomInfo = app.room.roomInfo;
  173. local memberInfo = app.room.roomInfo.memberList[nUserId];
  174. if not memberInfo then
  175. return ;
  176. end
  177. local seat = memberInfo.nSeatId;
  178. -- 更新座位
  179. if nodes.viewOrder then
  180. nodes.viewOrder:loadTexture(string.format("mj_yibinmajiang/res/zy_fangjian/player/yibinmajiang_seat_%d.png", (seat + 1)), 0);
  181. end
  182. end
  183. -- 显示飘标志
  184. function yibinmajiangRoomPlayerView:showPiao(viewId,bVisible)
  185. if self.allNodes[viewId] and self.allNodes[viewId].piao then
  186. self.allNodes[viewId].piao:setVisible(bVisible)
  187. else
  188. logE("yibinmajiangRoomPlayerView:showPiao ->viewId is not exit"..viewId)
  189. end
  190. end
  191. -- 清理所有飘标志
  192. function yibinmajiangRoomPlayerView:clearAllPiao()
  193. for i=1,4 do
  194. if self.allNodes[i] and self.allNodes[i].piao then
  195. self.allNodes[i].piao:setVisible(false)
  196. end
  197. end
  198. end
  199. function yibinmajiangRoomPlayerView:showHu( viewId, bVisible )
  200. if self.allNodes[viewId] and self.allNodes[viewId].hu then
  201. self.allNodes[viewId].hu:setVisible(bVisible);
  202. end
  203. if bVisible and self.allNodes[viewId] and self.allNodes[viewId].bao then
  204. self.allNodes[viewId].bao:setVisible(false);
  205. end
  206. end
  207. -- 显示桌面胡标记(1胡2胡3胡)
  208. function yibinmajiangRoomPlayerView:showHuFlag(viewId, bVisible)
  209. local userId = app.room:getUserIdByViewId(viewId)
  210. local memberInfo = app.room.roomInfo.memberList[userId]
  211. local huType = memberInfo.huType
  212. local huIndex = memberInfo.huIndex
  213. if huType > 0 and huIndex > 0 then
  214. -- 胡牌类型
  215. local huTypeTable = {
  216. [MJDefine.MJGameHuType.HU_ZIMO] = 'mj/res/ui/zy_fangjian/operate/mj_effect_zimo.png',
  217. [MJDefine.MJGameHuType.HU_DIANPAO] = 'mj/res/ui/zy_fangjian/operate/mj_effect_jiepao.png',
  218. [MJDefine.MJGameHuType.HU_QIANGGANG] = 'mj/res/ui/zy_fangjian/operate/mj_effect_hupai.png',
  219. }
  220. local huTypeImg = 'mj/res/ui/zy_fangjian/operate/mj_effect_hupai.png'
  221. huTypeImg = huTypeTable[huType] and huTypeTable[huType] or huTypeImg
  222. self.allNodes[viewId].hutype:loadTexture(huTypeImg)
  223. -- 胡牌顺序
  224. local huIndexTable = {
  225. [1] = 'mj/res/ui/zy_fangjian/operate/mj_effect_num1.png',
  226. [2] = 'mj/res/ui/zy_fangjian/operate/mj_effect_num2.png',
  227. [3] = 'mj/res/ui/zy_fangjian/operate/mj_effect_num3.png',
  228. }
  229. local huIndexImg = 'mj/res/ui/zy_fangjian/operate/mj_effect_num1.png'
  230. huIndexImg = huIndexTable[huIndex] and huIndexTable[huIndex] or huIndexImg
  231. self.allNodes[viewId].huindex:loadTexture(huIndexImg)
  232. -- index是type的子类,所以直接显示父类即可
  233. self.allNodes[viewId].hutype:setVisible(true)
  234. end
  235. end
  236. function yibinmajiangRoomPlayerView:clearHu( )
  237. for i=1,4 do
  238. if self.allNodes[i] and self.allNodes[i].hu then
  239. self.allNodes[i].hu:setVisible(false)
  240. self.allNodes[i].hutype:setVisible(false)
  241. end
  242. end
  243. end
  244. function yibinmajiangRoomPlayerView:refreshPlayerScore (scoreInfo)
  245. for k, v in ipairs(scoreInfo) do
  246. if self.allNodes[v.viewId] and self.allNodes[v.viewId].score then
  247. self.allNodes[v.viewId].score:setString(v.totalScore);
  248. end
  249. end
  250. end
  251. -- 获得定缺图的世界坐标
  252. function yibinmajiangRoomPlayerView:getDingQuePos()
  253. local temp = {}
  254. for i = 1, 4 do
  255. if self.allNodes[i] and self.allNodes[i].dingque then
  256. local pos = self.allNodes[i].dingque:getPosition()
  257. local worldPos = self.allNodes[i].dingque:getParent():convertToWorldSpace(self.allNodes[i].dingque:getPosition())
  258. temp[i] = worldPos
  259. end
  260. end
  261. return temp
  262. end
  263. -- 显示定缺
  264. function yibinmajiangRoomPlayerView:showDingQue(viewId, queValue)
  265. -- 4个一起显示
  266. -- for i = 1, 4 do
  267. -- if self.allNodes[i] and self.allNodes[i].dingque then
  268. -- self.allNodes[i].dingque:setVisible(true)
  269. -- end
  270. -- end
  271. -- 单独显示
  272. if self.allNodes[viewId] and self.allNodes[viewId].dingque then
  273. local temp = {
  274. [0] = 'wan',
  275. [1] = 'tong',
  276. [2] = 'tiao',
  277. }
  278. local texturePath = string.format('mj_yibinmajiang/res/zy_fangjian/player/yibinmajiang_dingque_%s.png', temp[queValue])
  279. self.allNodes[viewId].dingque:loadTexture(texturePath)
  280. self.allNodes[viewId].dingque:setVisible(true)
  281. end
  282. end
  283. -- 隐藏定缺
  284. function yibinmajiangRoomPlayerView:clearDingQue(viewId)
  285. if viewId then
  286. if self.allNodes[viewId] and self.allNodes[viewId].dingque then
  287. self.allNodes[viewId].dingque:setVisible(false)
  288. end
  289. return
  290. end
  291. for i = 1, 4 do
  292. if self.allNodes[i] and self.allNodes[i].dingque then
  293. self.allNodes[i].dingque:setVisible(false)
  294. end
  295. end
  296. end
  297. return yibinmajiangRoomPlayerView