| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- 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<foodIndexes.length&&i<this.blockGroups.length;i++){
- let blockGroup = this.blockGroups[i];
- let firstBlock = blockGroup.children[0];
- let foodIndex = foodIndexes[i];
- for (let j = 0; j <= foodIndex; j++) {
- let duplicatedBlock:cc.Node = cc.instantiate(firstBlock);
- duplicatedBlock.getChildByName('Question').active = false;
- duplicatedBlock.getChildByName('Value').getComponent(cc.Label).string = this.foodCalories[j].toString();
- duplicatedBlock.y = (j + 1) * 200;
- let spriteNode = new cc.Node();
- spriteNode.addComponent(cc.Sprite).spriteFrame = this.foodFrames[j];
- duplicatedBlock.addChild(spriteNode);
- blockGroup.addChild(duplicatedBlock);
- if(spriteNode.height > 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)
- ));
- }
- }
- }
|