import { CMS, Tool } from "./JCLibrary"; import WebView from "./WebView"; const {ccclass, property} = cc._decorator; @ccclass export default class SettlePanel extends cc.Component { @property({type:cc.AudioClip}) winAudio:cc.AudioClip = null; @property({type:cc.SpriteFrame}) failFrame:cc.SpriteFrame = null; @property({type:cc.SpriteFrame}) winFrame:cc.SpriteFrame = null; @property({type:cc.Node}) blockGroups:cc.Node[] = []; @property({type:cc.SpriteFrame}) foodFrames:cc.SpriteFrame[] = []; foodCalories:number[] = [10,50,100,150,200,250,300,350,400,450,500,550]; titleSprite:cc.Sprite; calorieLabel:cc.Label; timeLabel:cc.Label; onLoad(){ window.settlePanel = this; this.titleSprite = CMS.findChild(this.node,'PanelBG/Title',cc.Sprite); this.timeLabel = CMS.findChild(this.node,'PanelBG/Time',cc.Label); this.calorieLabel = CMS.findChild(this.node,'PanelBG/Tag/Calorie',cc.Label); CMS.findChild(this.node,'PanelBG/ButtonHome').on(cc.Node.EventType.TOUCH_END,()=>{ window.modeId = undefined; cc.director.loadScene('Game'); }); CMS.findChild(this.node,'PanelBG/ButtonRestart').on(cc.Node.EventType.TOUCH_END,()=>{ cc.director.loadScene('Game'); }); this.hide(); } hide(){ this.node.children.forEach((child)=>{ child.active = false; }); } show(winnerIndex:number){ this.node.children.forEach((child)=>{ child.active = true; }); this.node.zIndex = 10; this.node.getChildByName('BlackBG').setContentSize(cc.winSize); this.node.setPosition(window.cameraNode.position); if (cc.winSize.width < cc.view.getDesignResolutionSize().width) { this.node.getChildByName('PanelBG').setScale(cc.winSize.width / cc.view.getDesignResolutionSize().width); } if (window.total_score === undefined) { window.total_score = 0; } if(winnerIndex==window.myPlayerInfo.index){ window.total_score += 10; this.titleSprite.spriteFrame = this.winFrame; }else{ window.total_score -= 10; this.titleSprite.spriteFrame = this.failFrame; } cc.audioEngine.playEffect(this.winAudio,false); let calorie = Math.abs(window.appGame.caloriUnit * window.appGame.jumpCount); let timeMills = (window.topBar.time_init - parseInt(window.topBar.timeLabel.string)) * 1000; if (window.total_calorie === undefined) { window.total_calorie = calorie; } else { window.total_calorie += calorie; } if (window.total_time === undefined) { window.total_time = timeMills; } else { window.total_time += timeMills; } this.calorieLabel.string = Tool.decimal(window.total_calorie, 2).toString(); this.timeLabel.string = Tool.timeFormatHMS(window.total_time); // if (window.gm.appGame) { // WebView.getFruitInfo(window.totalCalorie); // } else { // this.renderFoods(this.getFoodIndexesByCalorie(window.totalCalorie)); // } this.renderFoods(this.getFoodIndexesByCalorie(window.total_calorie)); } getFoodIndexesByCalorie(calorie:number):number[]{ let indexes = []; while(true){ for(let i=this.foodCalories.length-1;i>=0;i--){ if(calorie>=this.foodCalories[i]){ indexes.push(i); calorie -= this.foodCalories[i]; break; }else{ if(i==0){ return indexes; } } } } } renderFoods(foodIndexes:number[]){ for(let i=0;i 70 || spriteNode.width > 63){ if(spriteNode.height - 70 > spriteNode.width - 63){ spriteNode.setScale(70 / spriteNode.height); }else{ spriteNode.setScale(63 / spriteNode.width); } } spriteNode.setPosition(0, 15); } blockGroup.runAction(cc.moveBy( 1,cc.v2(0,-(foodIndex+1)*200) )); } } }