EggMediator.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. cc.assetManager.loadBundle(config.packageName,(err,bundle:cc.AssetManager.Bundle)=>{
  50. if(err){
  51. cc.log("加载AssetBundle出错:"+config.packageName);
  52. }
  53. bundle.load(config.icon,(err,asset:cc.SpriteFrame)=>{
  54. if(err){
  55. cc.log("加载图标出错:"+config.icon);
  56. }
  57. this.view.m_groupCar.texture=asset;
  58. })
  59. });
  60. }
  61. protected OnHide():void{
  62. }
  63. protected AddEvents():void{
  64. this.view.m_btnDD.onClick(this.AddButtonClick,this);
  65. this.view.m_btnContinue.onClick(this.ContinueButtonClick,this);
  66. }
  67. protected RemoveEvents():void{
  68. this.view.m_btnDD.offClick(this.AddButtonClick,this);
  69. this.view.m_btnContinue.offClick(this.ContinueButtonClick,this);
  70. }
  71. private ContinueButtonClick():void{
  72. if(this.__state==2){
  73. this.GotoFighting();
  74. }
  75. }
  76. private AddButtonClick():void{
  77. if(this.__state==0){
  78. this.progress+=this.clickSpeed;
  79. }
  80. }
  81. Tick(dt:number):void{
  82. if(this.__state==0){
  83. this.progress-=dt*this.downSpeed;
  84. if(this.progress<0){
  85. this.progress=0;
  86. }
  87. if(this.progress>0.4&&this.progress<0.8){
  88. let r:number=Math.random()*1;
  89. if(r>0.5){
  90. this.CallBanner(true);
  91. this.__state=1;
  92. this.__startTime=cc.sys.now();
  93. }
  94. }
  95. this.view.m_progressBar.value=this.progress;
  96. }else if(this.__state==1){
  97. this.view.m_progressBar.value=1;
  98. let curTime:number=cc.sys.now();
  99. if(curTime-this.__startTime>1000){
  100. this.view.m_btnContinue.visible=true;
  101. this.view.m_btnDD.visible=false;
  102. this.__state=2;
  103. }
  104. }
  105. }
  106. private CallBanner(isShow:boolean):void{
  107. if(isShow){
  108. cc.log("显示Banner");
  109. }else{
  110. cc.log("隐藏Banner");
  111. }
  112. }
  113. private GotoFighting():void{
  114. SceneManager.single.Swicth("mainPackage","Fighting");
  115. GUIManager.single.Show(UIKeys.Fighting);
  116. this.HideSelf();
  117. }
  118. private get view():UI_Egg{
  119. return this._view as UI_Egg;
  120. }
  121. }