Rank.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // import Global from "../../Script/Global";
  2. import Global from "./Global";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class Rank extends cc.Component {
  6. // LIFE-CYCLE CALLBACKS:
  7. Ani = null;
  8. Anistate = null;
  9. onLoad () {
  10. let RemoteS = Global.instance.GetS();
  11. let phb = this.node.getChildByName("phb").children;
  12. let phbRank;
  13. let phbName;
  14. let phbFloor;
  15. let j=0;
  16. let i=RemoteS.length-1
  17. // let len;
  18. let x=0;
  19. let f=false;
  20. if(RemoteS.length>=8){
  21. x = RemoteS.length - 8;
  22. }
  23. for(;j<phb.length-x;){//length = 8
  24. for(;(i>=0&&j<RemoteS.length-x);i--){
  25. phbName = phb[j].getChildByName("id").getComponent(cc.Label);
  26. phbRank = phb[j].getChildByName("rank").getComponent(cc.Label);
  27. phbFloor = phb[j].getChildByName("floor").getComponent(cc.Label);
  28. if(phbName.string==RemoteS[i].userId){
  29. i++;
  30. }
  31. phbName.string = RemoteS[i].userId.slice(4);
  32. phbRank.string = RemoteS[i].rank;
  33. phbFloor.string = RemoteS[i].score;
  34. if(phbName.string == Global.instance.GetUSer().userId.slice(4)){
  35. this.node.getChildByName("phbd1").getChildByName("myrank").getComponent(cc.Label).string
  36. = phb[j].getChildByName("rank").getComponent(cc.Label).string;
  37. this.node.getChildByName("phbd1").getChildByName("myfloor").getComponent(cc.Label).string
  38. = phb[j].getChildByName("floor").getComponent(cc.Label).string;
  39. f = true;
  40. }
  41. switch(RemoteS[i].rank){
  42. case 1:{
  43. phb[j].getChildByName("model").active = true;
  44. break;
  45. }
  46. case 2:{
  47. phb[j].getChildByName("model").active = true;
  48. break;
  49. }
  50. case 3:{
  51. phb[j].getChildByName("model").active = true;
  52. break;
  53. }
  54. default:{
  55. break;
  56. }
  57. }
  58. j++
  59. }
  60. j++;
  61. }
  62. if(!f){
  63. this.node.getChildByName("phbd1").getChildByName("myfloor").getComponent(cc.Label).string
  64. = Global.instance.getLocalScore().BestScore.toString();
  65. this.node.getChildByName("phbd1").getChildByName("myrank").getComponent(cc.Label).string
  66. = Global.instance.GetR();
  67. }
  68. }
  69. start () {
  70. }
  71. update (dt) {
  72. }
  73. /**
  74. * close the rank Scene and load the start scene.
  75. */
  76. CloseRank(){
  77. console.log("this button is used to close this rank Scene");
  78. this.destroy();
  79. Global.instance.OverFlag = false;
  80. cc.director.loadScene("StartScene");
  81. }
  82. }
  83. /**
  84. * 这里也需要修改:player的分数不在8名之内,
  85. * 需要读取player的名次。
  86. */