MoreGameNode.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import MoreGameData from "../datas/MoreGameData";
  2. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  3. import UiM, { PANEL_NAME } from "../manager/UiM";
  4. import MoreGamePicItem from "../prefabs/MoreGamePicItem";
  5. import MoreNormalGameItem from "../prefabs/MoreNormalGameItem";
  6. import PointItem from "../prefabs/PointItem";
  7. import CashRecordNode from "./CashRecordNode";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class MoreGameNode extends cc.Component {
  11. @property(cc.ScrollView)
  12. normalSv: cc.ScrollView = null;
  13. @property(cc.Prefab)
  14. moreGameNormalNode: cc.Prefab = null
  15. @property(cc.Node)
  16. dragArea: cc.Node = null
  17. @property(cc.Node)
  18. item1: cc.Node = null
  19. @property(cc.Node)
  20. item2: cc.Node = null
  21. @property(cc.Prefab)
  22. pointPrefab: cc.Prefab = null
  23. @property(cc.Node)
  24. pointLy: cc.Node = null
  25. @property(cc.Node)
  26. centerNode: cc.Node = null
  27. @property(cc.Node)
  28. btnLeft: cc.Node = null
  29. @property(cc.Node)
  30. btnRight: cc.Node = null
  31. private startX = 0
  32. private coolTime = false
  33. private curSelDownItem = null
  34. private preDownItem = null
  35. private curIndex = 0
  36. private normalDatas = null
  37. private bannerDatas = null
  38. public hasClick = false
  39. private curSelPoint = null
  40. start() {
  41. this.node.setContentSize(cc.winSize)
  42. this.normalSv.content.destroyAllChildren()
  43. if (MoreGameData.Instance.moreGameList == null || MoreGameData.Instance.moreGameList == undefined) {
  44. MoreGameData.Instance.sendRecommendList()
  45. } else {
  46. this.initView()
  47. }
  48. let addY = (cc.winSize.height - 1334)
  49. this.normalSv.node.height += addY
  50. this.normalSv.node.getChildByName('view').height += addY
  51. this.dragArea.on(cc.Node.EventType.TOUCH_START, this.onDragStart, this)
  52. this.dragArea.on(cc.Node.EventType.TOUCH_END, this.onDragEnd, this)
  53. }
  54. onDisable() {
  55. this.dragArea.off(cc.Node.EventType.TOUCH_START, this.onDragStart, this)
  56. this.dragArea.off(cc.Node.EventType.TOUCH_END, this.onDragEnd, this)
  57. }
  58. clickBack() {
  59. GameM.audioM.playEffect(AUDIO_TYPE.button)
  60. UiM.Instance.offPanel(PANEL_NAME.moreGameNode)
  61. }
  62. initView() {
  63. this.centerNode.parent = this.node
  64. this.normalSv.content.destroyAllChildren()
  65. if (MoreGameData.Instance.moreGameList == null || MoreGameData.Instance.moreGameList == undefined) {
  66. return
  67. }
  68. this.setBannerInfo()
  69. this.setNormalInfo()
  70. }
  71. setBannerInfo() {
  72. this.bannerDatas = MoreGameData.Instance.moreGameList.banner
  73. if (this.bannerDatas && this.bannerDatas.length > 0) {
  74. for (var i = 0; i < this.bannerDatas.length; i++) {
  75. let point = cc.instantiate(this.pointPrefab)
  76. point.name = i.toString()
  77. this.pointLy.addChild(point)
  78. }
  79. }
  80. }
  81. setNormalInfo() {
  82. this.normalDatas = MoreGameData.Instance.moreGameList.normal
  83. if (this.normalDatas && this.normalDatas.length > 0) {
  84. for (var i = 0; i < this.normalDatas.length; i++) {
  85. let node = cc.instantiate(this.moreGameNormalNode)
  86. node.name = i.toString()
  87. node.getComponent(MoreNormalGameItem).setInfo(this.normalDatas[i])
  88. node.parent = this.normalSv.content
  89. if (i == 1) {
  90. if (this.bannerDatas && this.bannerDatas.length > 0) {
  91. this.centerNode.parent = this.normalSv.content
  92. this.centerNode.x = 25
  93. this.onOpenBigPicNode(0)
  94. }
  95. }
  96. }
  97. }
  98. }
  99. clickCashRecord() {
  100. UiM.Instance.offPanel(PANEL_NAME.moreGameNode)
  101. UiM.Instance.onPanel(PANEL_NAME.CashRecordNode, true, () => {
  102. if (cc.isValid(UiM.Instance.cashRecordNode)) {
  103. UiM.Instance.cashRecordNode.getComponent(CashRecordNode).initType()
  104. }
  105. })
  106. }
  107. clickGotoCash() {
  108. GameM.audioM.playEffect(AUDIO_TYPE.button)
  109. UiM.Instance.offPanel(PANEL_NAME.moreGameNode)
  110. UiM.Instance.onPanel(PANEL_NAME.CashNode)
  111. }
  112. /** ---------------- bigpicNode */
  113. onOpenBigPicNode(index) {
  114. this.curIndex = index
  115. let data = this.bannerDatas[this.curIndex]
  116. this.curSelDownItem = this.item1
  117. this.curSelDownItem.getComponent(MoreGamePicItem).init(data)
  118. this.curSelDownItem.x = 0
  119. this.curSelDownItem.active = true
  120. this.item2.x = 750
  121. this.curSelPoint = this.pointLy.getChildByName(this.curIndex.toString())
  122. this.curSelPoint.getComponent(PointItem).setSel(true)
  123. this.hasClick = false
  124. if (this.bannerDatas.length > 1) {
  125. this.schedule(() => {
  126. if (!this.hasClick) {
  127. this.onSelDown(1)
  128. }
  129. }, 3, cc.macro.REPEAT_FOREVER, 7)
  130. }
  131. else {
  132. this.btnLeft.active = false
  133. this.btnRight.active = false
  134. }
  135. }
  136. onLeft() {
  137. GameM.audioM.playEffect(AUDIO_TYPE.button)
  138. this.hasClick = true
  139. this.onSelDown(2)
  140. }
  141. onRight() {
  142. GameM.audioM.playEffect(AUDIO_TYPE.button)
  143. this.hasClick = true
  144. this.onSelDown(1)
  145. }
  146. /**
  147. * 滑动选择
  148. * @param state 1 向左 2 向右
  149. */
  150. onSelDown(state) {
  151. if (this.coolTime) {
  152. return
  153. }
  154. let preTo = -750
  155. let data
  156. if (state == 1) {
  157. if (this.curIndex + 1 > this.bannerDatas.length - 1) {
  158. this.curIndex = 0
  159. }
  160. else {
  161. this.curIndex++
  162. }
  163. data = this.bannerDatas[this.curIndex]
  164. if (this.curSelDownItem == this.item1) {
  165. this.curSelDownItem = this.item2
  166. this.preDownItem = this.item1
  167. }
  168. else {
  169. this.curSelDownItem = this.item1
  170. this.preDownItem = this.item2
  171. }
  172. this.curSelDownItem.getComponent(MoreGamePicItem).init(data)
  173. this.curSelDownItem.x = 750
  174. preTo = -750
  175. }
  176. else if (state == 2) {
  177. if (this.curIndex - 1 < 0) {
  178. this.curIndex = this.bannerDatas.length - 1
  179. }
  180. else {
  181. this.curIndex--
  182. }
  183. data = this.bannerDatas[this.curIndex]
  184. if (this.curSelDownItem == this.item1) {
  185. this.curSelDownItem = this.item2
  186. this.preDownItem = this.item1
  187. }
  188. else {
  189. this.curSelDownItem = this.item1
  190. this.preDownItem = this.item2
  191. }
  192. this.curSelDownItem.getComponent(MoreGamePicItem).init(data)
  193. this.curSelDownItem.x = -750
  194. preTo = 750
  195. }
  196. this.coolTime = true
  197. cc.tween(this.preDownItem).to(0.4, { x: preTo }, cc.easeInOut(1)).start()
  198. cc.tween(this.curSelDownItem).to(0.4, { x: 0 }, cc.easeInOut(1)).call(() => {
  199. this.onSelPoint()
  200. this.coolTime = false
  201. }).start()
  202. }
  203. onDragStart(evt) {
  204. this.hasClick = true
  205. this.startX = evt.touch._point.x
  206. }
  207. onDragEnd(evt) {
  208. let end = evt.touch._point.x - this.startX
  209. if (Math.abs(end) > 20) {
  210. if (end > 0) {
  211. this.onSelDown(2)
  212. }
  213. else {
  214. this.onSelDown(1)
  215. }
  216. }
  217. }
  218. onSelPoint() {
  219. if (this.curSelPoint) {
  220. this.curSelPoint.getComponent(PointItem).setSel(false)
  221. }
  222. this.curSelPoint = this.pointLy.getChildByName(this.curIndex.toString())
  223. this.curSelPoint.getComponent(PointItem).setSel(true)
  224. }
  225. // clickCloseBigPicNode() {
  226. // GameM.audioM.playEffect(AUDIO_TYPE.button)
  227. // this.curSelPoint.getComponent(PointItem).setSel(false)
  228. // this.unscheduleAllCallbacks()
  229. // }
  230. }