UIGameResult.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../base/BaseUI";
  3. import { ModuleDef } from "../../scripts/ModuleDef";
  4. import { GameUILayers } from "../../scripts/GameUILayers";
  5. import { SceneUtil } from "../../core_tgx/base/SceneUtils";
  6. import { SceneDef } from "../../scripts/SceneDef";
  7. import { UIGameResultPlayerItem } from "./UIGameResultPlayerItem";
  8. import { tween } from "cc";
  9. import { Vec3 } from "cc";
  10. import UIUtils from "../base/UIUtils";
  11. import { isValid } from "cc";
  12. const { ccclass, property } = _decorator;
  13. @ccclass("UIGameResult")
  14. export class UIGameResult extends BaseUI {
  15. static show() {
  16. tgx.UIMgr.inst.show(
  17. ModuleDef.BALL,
  18. "ui_game/ui_game_result",
  19. GameUILayers.POPUP
  20. );
  21. }
  22. protected onLoad(): void {
  23. super.onLoad();
  24. this.initResult();
  25. }
  26. private _rankMap = {};
  27. async initResult() {
  28. let list = [];
  29. list.push({
  30. name: "player_1",
  31. score: 9.9,
  32. rank: 1,
  33. isSelf: false,
  34. kill: 87,
  35. });
  36. list.push({
  37. name: "player_2",
  38. score: 8.2,
  39. rank: 2,
  40. isSelf: true,
  41. kill: 66,
  42. });
  43. list.push({
  44. name: "player_3",
  45. score: 6.7,
  46. rank: 3,
  47. isSelf: false,
  48. kill: 55,
  49. });
  50. list.push({
  51. name: "player_4",
  52. score: 4.1,
  53. rank: 4,
  54. isSelf: false,
  55. kill: 34,
  56. });
  57. for (let index = 5; index <= 9; index++) {
  58. list.push({
  59. name: "player_" + index,
  60. score: 2 - index / 10,
  61. rank: index,
  62. isSelf: false,
  63. kill: 9 - index,
  64. });
  65. }
  66. for (let i in list) {
  67. this._rankMap[list[i].rank] = list[i];
  68. }
  69. for (let index = 1; index <= 9; index++) {
  70. this.FindNode("no" + index).active = false;
  71. }
  72. for (let index = 0; index < list.length; index++) {
  73. const element = list[index];
  74. let node = this.FindNode("no" + element.rank);
  75. if (node) {
  76. if (node.getComponent(UIGameResultPlayerItem) == null) {
  77. node.addComponent(UIGameResultPlayerItem);
  78. }
  79. node.getComponent(UIGameResultPlayerItem).init(element);
  80. }
  81. }
  82. for (let index = 1; index <= 9; index++) {
  83. if (this._rankMap[index] == null) {
  84. break;
  85. }
  86. if (index <= 3) {
  87. this.playTopAnim(index);
  88. } else if (index <= 6) {
  89. this.playLeftAnim(index);
  90. } else {
  91. this.playRightAnim(index);
  92. }
  93. }
  94. let aaa = this.FindNode("circle_anim");
  95. aaa.setScale(3, 3, 3);
  96. UIUtils.AnimBezierMoveAndScale(aaa, new Vec3(0, 0, 0), 1, 1, () => {});
  97. }
  98. playTopAnim(index: number) {
  99. let self = this;
  100. setTimeout(() => {
  101. if (!isValid(self.node)) {
  102. return;
  103. }
  104. let animNode = self.FindNode("no" + index);
  105. let moveDis = 200;
  106. animNode.setPosition(animNode.position.x, animNode.position.y - moveDis);
  107. animNode.active = true;
  108. UIUtils.AnimBezierMoveAndScale(
  109. animNode,
  110. new Vec3(animNode.position.x, animNode.position.y + moveDis, 0),
  111. 1,
  112. 0.3
  113. );
  114. }, index * 200);
  115. }
  116. playLeftAnim(index: number) {
  117. let self = this;
  118. setTimeout(() => {
  119. if (!isValid(self.node)) {
  120. return;
  121. }
  122. self.FindNode("no" + index).active = true;
  123. let animNode = self.FindNode("no" + index);
  124. let moveDis = 200;
  125. animNode.setPosition(animNode.position.x - moveDis, animNode.position.y);
  126. animNode.active = true;
  127. tween(animNode)
  128. .to(0.5, {
  129. position: new Vec3(
  130. animNode.position.x + moveDis,
  131. animNode.position.y
  132. ),
  133. })
  134. .start();
  135. }, 700 + index * 100);
  136. }
  137. playRightAnim(index: number) {
  138. let self = this;
  139. setTimeout(() => {
  140. if (!isValid(self.node)) {
  141. return;
  142. }
  143. let animNode = self.FindNode("no" + index);
  144. let moveDis = 200;
  145. animNode.setPosition(animNode.position.x + moveDis, animNode.position.y);
  146. animNode.active = true;
  147. tween(animNode)
  148. .to(0.5, {
  149. position: new Vec3(
  150. animNode.position.x - moveDis,
  151. animNode.position.y
  152. ),
  153. })
  154. .start();
  155. }, 800 + index * 100);
  156. }
  157. protected simpleOnBtnClick(name: string): void {
  158. if (name == "btn_back") {
  159. this.closePage();
  160. tgx.UIMgr.inst.closeAll();
  161. SceneUtil.loadScene(SceneDef.LOBBY);
  162. }
  163. }
  164. }