GameRule.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { _decorator, Component, Game, Label, Node, PageView } from 'cc';
  2. import { Player } from './Player';
  3. import { GameConstant } from './GameConstant';
  4. import { SoundManager } from './SoundManager';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('GameRule')
  7. export class GameRule extends Component {
  8. @property(PageView)
  9. pageView: PageView = null;
  10. @property(Node)
  11. iconPaytableLayout1: Node = null;
  12. @property(Node)
  13. iconPaytableLayout2: Node = null;
  14. @property(SoundManager)
  15. soundManager: SoundManager = null;
  16. public curPageIndex = 0;
  17. start() {
  18. // this.pageView.enabled = false;
  19. }
  20. show(curBetIndex) {
  21. this.node.active = true;
  22. for (let i = 0; i < this.iconPaytableLayout1.children.length; i++) {
  23. let paytable = this.iconPaytableLayout1.children[i].getChildByName("paytableLayout");
  24. for (let j = 0; j < paytable.children.length; j++) {
  25. let scoreNode = paytable.children[j].getChildByName("score").getComponent(Label);
  26. let score = Player.getInstance().betConfig[curBetIndex] * GameConstant.ICON_TYPE_TIMES[3 - j][i];
  27. scoreNode.string = GameConstant.formatNumber(score, {currency: Player.getInstance().currencyType});
  28. }
  29. }
  30. for (let i = 0; i < this.iconPaytableLayout2.children.length; i++) {
  31. let paytable = this.iconPaytableLayout2.children[i].getChildByName("paytableLayout");
  32. for (let j = 0; j < paytable.children.length; j++) {
  33. let scoreNode = paytable.children[j].getChildByName("score").getComponent(Label);
  34. let score = Player.getInstance().betConfig[curBetIndex] * GameConstant.ICON_TYPE_TIMES[3 - j][5 + i];
  35. scoreNode.string = GameConstant.formatNumber(score, {currency: Player.getInstance().currencyType});
  36. }
  37. }
  38. }
  39. onClickGameRuleLeft() {
  40. this.soundManager.playClick();
  41. this.curPageIndex = this.pageView.getCurrentPageIndex();
  42. this.curPageIndex--;
  43. if (this.curPageIndex < 0) {
  44. this.pageView.setCurrentPageIndex(this.pageView.content.children.length - 1);
  45. } else {
  46. this.pageView.scrollToPage(this.curPageIndex);
  47. }
  48. }
  49. onClickGameRuleClose() {
  50. this.soundManager.playClick();
  51. this.node.active = false;
  52. }
  53. onClickGameRuleRight() {
  54. this.soundManager.playClick();
  55. this.curPageIndex = this.pageView.getCurrentPageIndex();
  56. this.curPageIndex++;
  57. if (this.curPageIndex > this.pageView.content.children.length - 1) {
  58. this.pageView.setCurrentPageIndex(0);
  59. } else {
  60. this.pageView.scrollToPage(this.curPageIndex);
  61. }
  62. }
  63. }