EggMediator.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import ConfigManager from "../../../engines/configs/ConfigManager";
  2. import { GUIManager } from "../../../engines/gui/GUIManager";
  3. import GUIMediator from "../../../engines/gui/GUIMediator";
  4. import SceneManager from "../../../engines/scenes/SceneManager";
  5. import UI_Egg from "../../../ui/Egg/UI_Egg";
  6. import Main from "../../Main";
  7. import ConfigKeys from "../../models/ConfigKeys";
  8. import GameModel from "../../models/GameModel";
  9. import UIKeys from "../../UIKeys";
  10. export default class EggMediator extends GUIMediator{
  11. private downSpeed:number=0.35;
  12. private clickSpeed:number=0.15;
  13. private progress:number=0;
  14. private __state:number=0;
  15. private __startTime:number;
  16. constructor(){
  17. super();
  18. }
  19. protected OnShow():void{
  20. this.__state=0;
  21. this.progress=0;
  22. this.view.m_progressBar.min=0;
  23. this.view.m_progressBar.max=1;
  24. if(Main.TEST){
  25. this.__state=2;
  26. this.view.m_btnContinue.visible=true;
  27. this.view.m_btnDD.visible=false;
  28. }else{
  29. this.view.m_btnContinue.visible=false;
  30. this.view.m_btnDD.visible=true;
  31. }
  32. this.RandomCar();
  33. }
  34. /**
  35. * 随机一辆车
  36. */
  37. private RandomCar():void{
  38. let list:any[]=ConfigManager.single.GetConfigList(ConfigKeys.Car);
  39. let index:number=Math.floor(Math.random()*list.length);
  40. let config:any=list[index];
  41. GameModel.single.currentCarId=config.id;
  42. //车的名称
  43. this.view.m_txtName.text=config.name;
  44. let attr:string="行驶速度:"+config.speed+"m/s"+"\n";
  45. attr+="转向速度:"+config.turnSpeed+"m/s"+"\n";
  46. attr+="冲刺速度:"+config.sprintSpeed+"m/s"+"\n";
  47. this.view.m_txtAttribute.text=attr;
  48. //加载图标
  49. this.view.m_groupCar.url = config.icon;
  50. // cc.assetManager.loadBundle(config.packageName,(err,bundle:cc.AssetManager.Bundle)=>{
  51. // if(err){
  52. // cc.log("加载AssetBundle出错:"+config.packageName);
  53. // }
  54. // bundle.load(config.icon,(err,asset:cc.SpriteFrame)=>{
  55. // if(err){
  56. // cc.log("加载图标出错:"+config.icon);
  57. // }
  58. // this.view.m_groupCar.texture=asset;
  59. // })
  60. // });
  61. }
  62. protected OnHide():void{
  63. }
  64. protected AddEvents():void{
  65. this.view.m_btnDD.onClick(this.AddButtonClick,this);
  66. this.view.m_btnContinue.onClick(this.ContinueButtonClick,this);
  67. }
  68. protected RemoveEvents():void{
  69. this.view.m_btnDD.offClick(this.AddButtonClick,this);
  70. this.view.m_btnContinue.offClick(this.ContinueButtonClick,this);
  71. }
  72. private ContinueButtonClick():void{
  73. if(this.__state==2){
  74. this.GotoFighting();
  75. }
  76. }
  77. private AddButtonClick():void{
  78. if(this.__state==0){
  79. this.progress+=this.clickSpeed;
  80. }
  81. }
  82. Tick(dt:number):void{
  83. if(this.__state==0){
  84. this.progress-=dt*this.downSpeed;
  85. if(this.progress<0){
  86. this.progress=0;
  87. }
  88. if(this.progress>0.4&&this.progress<0.8){
  89. let r:number=Math.random()*1;
  90. if(r>0.5){
  91. this.CallBanner(true);
  92. this.__state=1;
  93. this.__startTime=cc.sys.now();
  94. }
  95. }
  96. this.view.m_progressBar.value=this.progress;
  97. }else if(this.__state==1){
  98. this.view.m_progressBar.value=1;
  99. let curTime:number=cc.sys.now();
  100. if(curTime-this.__startTime>1000){
  101. this.view.m_btnContinue.visible=true;
  102. this.view.m_btnDD.visible=false;
  103. this.__state=2;
  104. }
  105. }
  106. }
  107. private CallBanner(isShow:boolean):void{
  108. if(isShow){
  109. cc.log("显示Banner");
  110. }else{
  111. cc.log("隐藏Banner");
  112. }
  113. }
  114. private GotoFighting():void{
  115. SceneManager.single.Swicth("mainPackage","Fighting");
  116. GUIManager.single.Show(UIKeys.Fighting);
  117. this.HideSelf();
  118. }
  119. private get view():UI_Egg{
  120. return this._view as UI_Egg;
  121. }
  122. }