UIGameWinner.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { _decorator, Button, Color, Component, Label, Node } from 'cc';
  2. import { ModuleDef } from '../../scripts/ModuleDef';
  3. import { GameUILayers } from '../../scripts/GameUILayers';
  4. import { MsgGameOverPush } from '../../module_basic/shared/protocols/public/game/MsgGameOverPush';
  5. import { IGameData, IGamePlayer } from '../../module_basic/shared/protocols/public/game/GameTypeDef';
  6. import { TEAM_ID_MAP } from '../../module_basic/shared/types/TeamInfo';
  7. import { GameWinnerPlayerItem } from './GameWinnerPlayerItem';
  8. import { RoomMgr } from '../../module_basic/scripts/RoomMgr';
  9. import { UIGameOver } from '../ui_game_over/UIGameOver';
  10. import { IRoomData } from '../shared/types/RoomData';
  11. const { ccclass, property } = _decorator;
  12. const tempColor = new Color();
  13. /**
  14. * @en Layout component is used to mount on the root node of the UI corresponding to the Prefab, and declare a series of property references for tgxUIController to call.
  15. * @zh Layout 组件用于挂载到UI对应的Prefab根节点,并声明一系列 property 引用,供 tgxUIController 调用。
  16. */
  17. @ccclass('Layout_UIGameWinner')
  18. export class Layout_UIGameWinner extends Component {
  19. @property(Label) lblCongrats: Label;
  20. @property([GameWinnerPlayerItem]) players: GameWinnerPlayerItem[] = [];
  21. @property(Label) lblTapToContinue: Label;
  22. }
  23. @tgx_class(ModuleDef.BASIC)
  24. export class UIGameWinner extends tgx.UIController {
  25. constructor() {
  26. super('ui_game_winner/ui_game_winner', GameUILayers.POPUP, Layout_UIGameWinner);
  27. this._ingoreCloseAll = true;
  28. }
  29. public get layout(): Layout_UIGameWinner {
  30. return this._layout as Layout_UIGameWinner;
  31. }
  32. private _createdTime = 0;
  33. protected onCreated(args: { gameOver: MsgGameOverPush, gameData: IGameData, roomData: IRoomData }): void {
  34. this._createdTime = Date.now();
  35. this.onButtonEvent(this.node, () => {
  36. //1.5秒后,才可以关闭
  37. if (Date.now() - this._createdTime < 1500) {
  38. return;
  39. }
  40. this.node.getComponent(Button).interactable = false;
  41. tgx.UIMgr.inst.showUI(UIGameOver, () => {
  42. this.close();
  43. }, this, args);
  44. });
  45. let teamName = TEAM_ID_MAP[args.gameOver.winner].name;
  46. this.layout.lblCongrats.string = `恭喜[${teamName}]获得第1名!`;
  47. let teamPlayers = [];
  48. args.gameData.players.forEach(p => {
  49. if (p.teamId == args.gameOver.winner) {
  50. teamPlayers.push(p);
  51. }
  52. });
  53. teamPlayers.sort((a: IGamePlayer, b: IGamePlayer) => {
  54. return b.weight - a.weight;
  55. });
  56. for (let i = 0; i < this.layout.players.length; ++i) {
  57. let playerCom = this.layout.players[i];
  58. let teamPlayer = teamPlayers[i];
  59. if(teamPlayer){
  60. let user = args.roomData.userList.find(v=>v.uid == teamPlayer.uid);
  61. playerCom.setPlayer(teamPlayer,user);
  62. }
  63. else{
  64. playerCom.lblRoleName.node.active = false;
  65. playerCom.lblUserName.node.active = false;
  66. }
  67. }
  68. RoomMgr.inst.backToLobby(true);
  69. }
  70. protected onUpdate(dt: number): void {
  71. tempColor.set(this.layout.lblTapToContinue.color);
  72. let value = Math.sin(Date.now() / 50 / Math.PI);
  73. value = value * 0.5 + 0.5;
  74. tempColor.a = value * 255;
  75. this.layout.lblTapToContinue.color = tempColor;
  76. }
  77. }