Browse Source

收益加速界面

greg 4 years ago
parent
commit
3f1f87227f

+ 6 - 0
assets/resources/ui/SpeedUpUI.prefab

@@ -4704,6 +4704,12 @@
       "__id__": 1
     },
     "_enabled": true,
+    "progressBar": {
+      "__id__": 93
+    },
+    "timeLabel": {
+      "__id__": 89
+    },
     "_id": ""
   },
   {

+ 5 - 1
assets/scripts/engines/buffers/BaseBuffer.ts

@@ -34,7 +34,7 @@ export default class BaseBuffer implements IBuffer
                 //排除自身
                 if(element!=this){
                     otherEndTime=element.GetEndTime();
-                    if(otherEndTime<currentTime){
+                    if(currentTime<otherEndTime){
                         otherTime+=otherEndTime-currentTime;
                     }
                 }
@@ -73,6 +73,10 @@ export default class BaseBuffer implements IBuffer
         return this.endTime;
     }
 
+    GetTime(): number {
+        return this.time;
+    }
+
     
     Tick(dt: number): void {
         

+ 5 - 0
assets/scripts/engines/buffers/IBuffer.ts

@@ -33,4 +33,9 @@ export default interface IBuffer
      * 剩余时间
      */
     GetTimeRemaining():number;
+
+    /**
+     * 时长
+     */
+    GetTime():number;
 }

+ 41 - 11
assets/scripts/engines/utils/StringUtils.ts

@@ -135,33 +135,63 @@ export default class StringUtils
      * @param secondsSeparator 
      */
     public static TimeFormatting(time:number,daySeparator:string="d",hoursSeparator:string="h",minutesSeparator:string="m",secondsSeparator:string="s"):string{
-        let ts:Date=new Date();
-        let timeStr:string="{0}{1}{2}{3}";
-        let day:number=0;
+        let timeStr:string="";
+        let index:number=0;
+        //天
+        let Day:number=0;
         while (time>this.DayTime) {
             time-=this.DayTime;
-            day++;
+            Day++;
         }
-        let hours:number=0;
+        if(Day>0){
+            if(Day<10){
+                timeStr+="0"+Day+daySeparator;
+            }else{
+                timeStr+=Day+daySeparator;
+            }
+            index++;
+        }
+        //时
+        let Hours:number=0;
         while (time>this.HoursTime) {
             time-=this.HoursTime;
-            hours++;
+            Hours++;
+        }
+        if(Hours>0){
+            if(Hours<10){
+                timeStr+="0"+Hours+hoursSeparator;
+            }else{
+                timeStr+=Hours+hoursSeparator;
+            }
+            index++;
         }
+        //分
         let Minute:number=0;
         while (time>this.MinutesTime) {
             time-=this.MinutesTime;
             Minute++;
         }
+        if(Minute>0){
+            if(Minute<10){
+                timeStr+="0"+Minute+minutesSeparator;
+            }else{
+                timeStr+=Minute+minutesSeparator;
+            }
+            index++;
+        }
+        //秒
         let Seconds:number=0;
         while (time>this.SecondsTime) {
             time-=this.SecondsTime;
             Seconds++;
         }
-        timeStr=this.substitute(timeStr,
-        day == 0 ? "" : day + daySeparator,
-        hours == 0 ? "" : hours + hoursSeparator,
-        Minute==0 ? "" : Minute + minutesSeparator,
-        Seconds == 0 ? "" : Seconds + secondsSeparator);
+        if(Seconds>0&&index<2){
+            if(Seconds<10){
+                timeStr+="0"+Seconds+secondsSeparator;
+            }else{
+                timeStr+=Seconds+secondsSeparator;
+            }
+        }
         return timeStr;
     }
 

+ 0 - 2
assets/scripts/games/buffers/AutoSyntheticBuffer.ts

@@ -1,7 +1,5 @@
 import { director } from "cc";
 import BaseBuffer from "../../engines/buffers/BaseBuffer";
-import BufferManager from "../../engines/buffers/BufferManager";
-import IBuffer from "../../engines/buffers/IBuffer";
 import { GameModel } from "../models/GameModel";
 
 

+ 1 - 1
assets/scripts/games/scenes/PreloadingScene.ts

@@ -82,7 +82,7 @@ export class PreloadingScene extends Component {
     
     private initLocalData():void{
         // //清除本地数据
-        // GameModel.single.ClearLocalData();
+        GameModel.single.ClearLocalData();
         GameModel.single.ReadByLocal();
         SceneManager.single.Swicth("PrepareScene");
     }

+ 42 - 1
assets/scripts/games/ui/accelerates/AccelerateMediator.ts

@@ -1,8 +1,10 @@
-import { _decorator, Component, Node } from 'cc';
+import { _decorator, Component, Node, ProgressBarComponent, LabelComponent } from 'cc';
 import BufferManager from '../../../engines/buffers/BufferManager';
+import IBuffer from '../../../engines/buffers/IBuffer';
 import { GUIManager } from '../../../engines/gui/GUIManager';
 import { GUIMediator } from '../../../engines/gui/GUIMediator';
 import { NoticeManager } from '../../../engines/notices/NoticeManager';
+import StringUtils from '../../../engines/utils/StringUtils';
 import { PlatformManager } from '../../../Platform/PlatformManager';
 import AccelerateBuffer from '../../buffers/AccelerateBuffer';
 import { GameModel } from '../../models/GameModel';
@@ -12,6 +14,21 @@ const { ccclass, property } = _decorator;
 @ccclass('AccelerateMediator')
 export class AccelerateMediator extends GUIMediator {
     
+    @property({
+        type:ProgressBarComponent
+    })
+    progressBar:ProgressBarComponent=null;
+
+    @property({
+        type:LabelComponent
+    })
+    timeLabel:LabelComponent=null;
+
+    /**
+     * 最大时间
+     */
+    private max:number=150*1000*10;
+
     OnShow(data?:any):void{
         super.OnShow(data);
     }
@@ -23,9 +40,14 @@ export class AccelerateMediator extends GUIMediator {
 
     DiamondButtonClickHandler():void{
         if(GameModel.single.diamond>20){
+            if(this.CurrentBufferTime>=this.max){
+                NoticeManager.ShowPrompt("加速时间已满!");
+                return;
+            }
             if(this.AddBuffer()){
                 //扣钱
                 GameModel.single.diamond-=20;
+                this.CloseButtonClickHandler();
             }
         }else{
             NoticeManager.ShowPrompt("钻石不足");
@@ -36,6 +58,10 @@ export class AccelerateMediator extends GUIMediator {
      * 视频按钮点击
      */
     VideoButtonClickHandler():void{
+        if(this.CurrentBufferTime>=this.max){
+            NoticeManager.ShowPrompt("加速时间已满!");
+            return;
+        }
         PlatformManager.showRewardedVideo(()=>{
             this.AddBuffer();
         },()=>{
@@ -56,4 +82,19 @@ export class AccelerateMediator extends GUIMediator {
         BufferManager.RunBuffer(buffer);
         return true;
     }
+
+
+    private get CurrentBufferTime():number{
+        let buffers:IBuffer[]=BufferManager.GetBufferGroup("Accelerate");
+        if(buffers==null||buffers.length==0){
+            return 0;
+        }
+        return buffers[0].GetTime();
+    }
+
+    update(dt:number):void{
+        this.progressBar.progress=this.CurrentBufferTime/this.max;
+        this.timeLabel.string=StringUtils.TimeFormatting(this.CurrentBufferTime,":",":",":","");
+        super.update(dt);
+    }
 }