Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

214 Zeilen
5.2 KiB

  1. ---
  2. -- ================================================================
  3. -- 文件名: MJRuleViewVertical.lua
  4. -- 描述: 麻将玩法弹框组件 - 向下滑出
  5. -- 版权: Copyright © 2016-2019 公司名称 版权所有
  6. -- 作者: Administrator
  7. -- 创建日期: 2020-02-04
  8. -- 更新日期: 2020-02-04
  9. -- 备注:
  10. -- ================================================================
  11. --
  12. local MJRuleViewVertical = class("MJRuleViewVertical", cc.UIView);
  13. MJRuleViewVertical.state = {
  14. NORMAL = 1, -- 正常状态,未弹出
  15. POPUP = 2, -- 弹出状态
  16. }
  17. ---
  18. -- 构造函数
  19. -- @return
  20. --
  21. function MJRuleViewVertical:ctor()
  22. MJRuleViewVertical.super.ctor(self);
  23. end
  24. ---
  25. -- 进入场景
  26. -- @return
  27. --
  28. function MJRuleViewVertical:onEnter()
  29. self._state = self.state.POPUP;
  30. self:loadUI();
  31. self:initViews();
  32. end
  33. ---
  34. -- 加载UI布局
  35. -- @return
  36. --
  37. function MJRuleViewVertical:loadUI ()
  38. local ui = loadUI("mj/res/ui/ui_fangjian/mj_ui_ruleview_vertical.ui");
  39. self:addChild(ui);
  40. self.ui = ui;
  41. end
  42. ---
  43. -- 初始化界面
  44. -- @return
  45. --
  46. function MJRuleViewVertical:initViews ()
  47. self.layoutMask = self.ui.Items.Layout_Mask;
  48. self.btnRule = self.ui.Items.Button_Rule;
  49. self.btnRuleMask = self.ui.Items.Button_Rule_Mask;
  50. self.layoutRule = self.ui.Items.Layout_Rule;
  51. self.layoutRuleSize = self.layoutRule:getSize();
  52. self.listviewRule = self.ui.Items.ListView;
  53. -- self.listviewRule:setAutoSize(true)
  54. self.listviewRule:hideAllBar();
  55. self.listviewItemTemplate = self.ui.Items.Text_Rule;
  56. self.listviewItemTemplate:setVisible(false);
  57. self.btnRule:setVisible(false);
  58. self.btnRule:registerClick(handler(self, self.onBtnRuleClicked));
  59. self.btnRuleMask:registerClick(handler(self, self.onBtnRuleClicked));
  60. self.layoutMask:registerClick(handler(self, self.onLayoutMaskTouched));
  61. self:runDelay(1.5, function ()
  62. if self._state == self.state.NORMAL then
  63. return;
  64. end
  65. self:toggleRuleView();
  66. end)
  67. end
  68. ---
  69. -- 规则按钮点击事件
  70. -- @return
  71. --
  72. function MJRuleViewVertical:onBtnRuleClicked ()
  73. playBtnEffect();
  74. self:toggleRuleView();
  75. end
  76. ---
  77. -- 开关弹框
  78. -- @return
  79. --
  80. function MJRuleViewVertical:toggleRuleView ()
  81. if self._isPlaying then
  82. -- 正在播放动画
  83. return;
  84. end
  85. self._isPlaying = true;
  86. local state = self._state or self.state.NORMAL;
  87. local ac = nil;
  88. if state == self.state.NORMAL then
  89. ac = self:getMoveOutAction();
  90. else
  91. ac = self:getMoveInAction();
  92. end
  93. if not ac then
  94. logD("MJRuleViewVertical:onBtnRuleClicked", "action is nil.");
  95. self._isPlaying = false;
  96. return;
  97. end
  98. self.layoutRule:runAction(ac);
  99. end
  100. ---
  101. -- 获取弹出动作
  102. -- @return
  103. --
  104. function MJRuleViewVertical:getMoveOutAction ()
  105. self.layoutRule:setVisible(true)
  106. self.btnRule:setVisible(false);
  107. local offsetY = self.layoutRuleSize.height + 0;
  108. local acMoveDown = cc.MoveBy:create(0.3, cc.p(0, -offsetY));
  109. local acCallback = cc.CallFunc:create(function ()
  110. self._isPlaying = false;
  111. self._state = self.state.POPUP;
  112. self.layoutMask:setVisible(true);
  113. end)
  114. local acSeq = cc.Sequence:create(acMoveDown, acCallback);
  115. return acSeq;
  116. end
  117. ---
  118. -- 获取缩回动作
  119. -- @return
  120. --
  121. function MJRuleViewVertical:getMoveInAction ()
  122. self.layoutMask:setVisible(false);
  123. local offsetY = self.layoutRuleSize.height + 0;
  124. local acMoveUp = cc.MoveBy:create(0.3, cc.p(0, offsetY));
  125. local acCallback = cc.CallFunc:create(function ()
  126. self.layoutRule:setVisible(false)
  127. self.btnRule:setVisible(true);
  128. self._isPlaying = false;
  129. self._state = self.state.NORMAL;
  130. end)
  131. local acSeq = cc.Sequence:create(acMoveUp, acCallback);
  132. return acSeq;
  133. end
  134. ---
  135. -- 背景层触摸事件
  136. -- @return
  137. --
  138. function MJRuleViewVertical:onLayoutMaskTouched ()
  139. if self._state == self.state.NORMAL then
  140. return;
  141. end
  142. self:toggleRuleView();
  143. end
  144. ---
  145. -- 设置规则按钮的偏移量
  146. -- @param x
  147. -- @param y
  148. -- @return
  149. --
  150. function MJRuleViewVertical:setBtnRuleOffset (x, y)
  151. if x then
  152. local btnRuleX = self.btnRule:getPositionX();
  153. btnRuleX = btnRuleX + x;
  154. self.btnRule:setPositionX(btnRuleX);
  155. local layoutRuleX = self.layoutRule:getPositionX();
  156. layoutRuleX = layoutRuleX + x;
  157. self.layoutRule:setPositionX(layoutRuleX);
  158. end
  159. if y then
  160. local btnRuleY = self.btnRule:getPositionY();
  161. btnRuleY = btnRuleY + y;
  162. self.btnRule:setPositionY(btnRuleY);
  163. local layoutRuleY = self.layoutRule:getPositionY();
  164. layoutRuleY = layoutRuleY + y;
  165. self.layoutRule:setPositionY(layoutRuleY);
  166. end
  167. end
  168. ---
  169. -- 设置规则列表
  170. -- @param list
  171. -- @return
  172. --
  173. function MJRuleViewVertical:setRuleList (list)
  174. self.listviewRule:removeAllChildren();
  175. for k, v in pairs(list) do
  176. if v then
  177. local item = self.listviewItemTemplate:getCopied();
  178. item:setString(v);
  179. item:setVisible(true);
  180. self.listviewRule:addChild(item);
  181. end
  182. end
  183. end
  184. return MJRuleViewVertical;