MatchPanel.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const {ccclass, property} = cc._decorator;
  2. @ccclass
  3. export default class MatchPanel extends cc.Component {
  4. @property({type: cc.SpriteFrame})
  5. private frameBoy: cc.SpriteFrame = null;
  6. @property({type: cc.SpriteFrame})
  7. private frameGirl: cc.SpriteFrame = null;
  8. @property({type: cc.SpriteFrame})
  9. private genderBoy: cc.SpriteFrame = null;
  10. @property({type: cc.SpriteFrame})
  11. private genderGirl: cc.SpriteFrame = null;
  12. @property({type: cc.AudioClip})
  13. private matchSuccess: cc.AudioClip = null;
  14. @property({type: cc.Animation})
  15. private meteorLine: cc.Animation = null;
  16. @property({type: cc.Sprite})
  17. private frameSelf: cc.Sprite = null;
  18. @property({type: cc.Sprite})
  19. private avatarSelf: cc.Sprite = null;
  20. @property({type: cc.Sprite})
  21. private genderSelf: cc.Sprite = null;
  22. @property({type: cc.Label})
  23. private nameSelf: cc.Label = null;
  24. @property({type: cc.Sprite})
  25. private frameOther: cc.Sprite = null;
  26. @property({type: cc.Sprite})
  27. private avatarOther: cc.Sprite = null;
  28. @property({type: cc.Sprite})
  29. private genderOther: cc.Sprite = null;
  30. @property({type: cc.Label})
  31. private nameOther: cc.Label = null;
  32. @property({type: cc.Node})
  33. private backGround: cc.Node = null;
  34. @property({type: cc.Node})
  35. private content: cc.Node = null;
  36. @property({type: cc.Label})
  37. private labelMatching: cc.Label = null;
  38. @property({type: cc.Label})
  39. private labelTime: cc.Label = null;
  40. @property({type: cc.Label})
  41. private labelWaitingTime: cc.Label = null;
  42. @property({type: cc.Node})
  43. private points: cc.Node = null;
  44. private waitingTime: number = 0;
  45. private countingTime: boolean = true;
  46. public static EVENT_MATCH_SUCCESS = "EVENT_MATCH_SUCCESS";
  47. public onLoad() {
  48. window.matchPanel = this;
  49. this.backGround.setContentSize(cc.winSize);
  50. }
  51. public update(dt:number) {
  52. if (this.countingTime) {
  53. this.waitingTime += dt;
  54. this.labelTime.string = this.timeFormatMS(this.waitingTime*1000);
  55. }
  56. }
  57. private timeFormatMS(millis:number) {
  58. let minute = Math.floor(millis / 1000 / 60);
  59. let second = Math.floor(millis / 1000 % 60);
  60. return (minute < 10 ? '0' : '') + minute + ':' + (second < 10 ? '0' : '') + second;
  61. }
  62. public renderMyInfo(nickName:string, gender:number, avatar:cc.SpriteFrame) {
  63. //render self info
  64. this.nameSelf.string = nickName;
  65. this.avatarSelf.spriteFrame = avatar;
  66. this.avatarSelf.node.setContentSize(180,180);
  67. if (gender == 2) {
  68. this.frameSelf.spriteFrame = this.frameGirl;
  69. this.genderSelf.spriteFrame = this.genderGirl;
  70. } else {
  71. this.frameSelf.spriteFrame = this.frameBoy;
  72. this.genderSelf.spriteFrame = this.genderBoy;
  73. }
  74. //rendere other style according to self style
  75. if (gender == 2) {
  76. this.frameOther.spriteFrame = this.frameBoy;
  77. this.genderOther.spriteFrame = this.genderBoy;
  78. this.points.children.forEach((child:cc.Node) => {
  79. child.color = cc.color(30, 144, 255, 255);
  80. });
  81. } else {
  82. this.frameOther.spriteFrame = this.frameGirl;
  83. this.genderOther.spriteFrame = this.genderGirl;
  84. this.points.children.forEach((child:cc.Node) => {
  85. child.color = cc.color(255, 105, 180, 255);
  86. });
  87. }
  88. }
  89. public renderOtherInfo(nickName:string, gender:number, avatar:cc.SpriteFrame) {
  90. //render other info
  91. this.nameOther.string = nickName;
  92. this.avatarOther.spriteFrame = avatar;
  93. this.avatarOther.node.setContentSize(180,180);
  94. if (gender == 2) {
  95. this.frameOther.spriteFrame = this.frameGirl;
  96. this.genderOther.spriteFrame = this.genderGirl;
  97. } else {
  98. this.frameOther.spriteFrame = this.frameBoy;
  99. this.genderOther.spriteFrame = this.genderBoy;
  100. }
  101. this.countingTime = false;
  102. this.points.destroy();
  103. this.labelMatching.string = "匹配完成";
  104. this.meteorLine.play("MeteorLine");
  105. this.labelTime.node.destroy();
  106. this.labelWaitingTime.node.destroy();
  107. cc.audioEngine.playEffect(this.matchSuccess, false);
  108. this.content.runAction(cc.sequence(
  109. cc.delayTime(2),
  110. cc.fadeOut(1),
  111. cc.callFunc(() => {
  112. this.node.emit(MatchPanel.EVENT_MATCH_SUCCESS);
  113. this.backGround.runAction(cc.sequence(
  114. cc.fadeOut(0.5),
  115. cc.callFunc(()=>{
  116. this.node.destroy();
  117. })
  118. ));
  119. })
  120. ));
  121. }
  122. }