import Userdata from "./Userdata";
|
import Global from "./Global";
|
import SoundManager from "./SoundManager";
|
import { Sdk } from "./Sdk/Sdk";
|
import RankTool from "./Sdk/RankTool";
|
import Game from "./Game";
|
import { SdkToutiao } from "./Sdk/SdkToutiao";
|
|
const { ccclass, property } = cc._decorator;
|
|
@ccclass
|
export default class ResultLayer extends cc.Component {
|
|
@property(cc.Label)
|
stageBgLabel: cc.Label = null;
|
|
@property(cc.Label)
|
gemLabel: cc.Label = null;
|
@property([sp.Skeleton])
|
resultStarSkeletons: sp.Skeleton[] = [];
|
|
@property(cc.Button)
|
nextButton: cc.Button = null;
|
|
@property(cc.Sprite)
|
scoreProgress: cc.Sprite = null;
|
|
@property(cc.Button)
|
shareRecordButton: cc.Button = null;
|
@property(cc.Label)
|
shareRecordLabel: cc.Label = null;
|
|
@property(cc.Node)
|
moregamesNode: cc.Node = null;
|
|
private from: number = 0;
|
private to: number = 0;
|
private star_anim_names: string[] = ['star', 'star', 'star'];
|
|
private currLevel = 0;
|
|
onLoad() {
|
this.node.on('updateInfo', () => {
|
this.updateGems();
|
});
|
}
|
|
onEnable() {
|
cc.director.getPhysicsManager().enabled = false;
|
this.gemLabel.string = Userdata.Gem.toString();
|
|
if (Sdk.isToutiao) {
|
|
SdkToutiao.showInterAd();
|
this.moregamesNode.active = SdkToutiao.isSupportMoreGames();
|
} else {
|
if (!Userdata.isPurchased()) {
|
Sdk.ins.showInterAd();
|
}
|
}
|
|
// cc.sys.garbageCollect();
|
}
|
|
show(isWin: boolean, isSkip: boolean = false) {
|
this.currLevel = Userdata.SelectLevel;
|
this.stageBgLabel.string = "关卡 " + Userdata.SelectLevel;
|
|
if (isWin) {
|
SoundManager.playWin();
|
let oldStars = Userdata.Stars;
|
|
//更新星级
|
let currLevelStar = isSkip ? 0 : Game.instance.Stars;
|
cc.log('stars = ' + currLevelStar);
|
for (let i = 1; i <= 3; i++) {
|
if (i <= currLevelStar) {
|
this.scheduleOnce(() => {
|
this.resultStarSkeletons[i - 1].node.active = true;
|
this.resultStarSkeletons[i - 1].setAnimation(0, this.star_anim_names[i - 1], false);
|
SoundManager.playStar(i);
|
}, i * 0.3);
|
} else {
|
this.resultStarSkeletons[i - 1].node.active = false;
|
}
|
}
|
|
let currStar = Userdata.GetLevelStar(Userdata.SelectLevel);
|
let addScore = 0;// Game.instance.currScore;
|
if (currStar <= 0) {//首次通关
|
if (currLevelStar == 0) {//跳过
|
addScore = 0;
|
} else if (currLevelStar == 1) {
|
addScore = 577;
|
} else if (currLevelStar == 2) {
|
addScore = 1177;
|
} else {
|
addScore = 1777;
|
}
|
} else {
|
addScore = 577;//反复打关卡
|
}
|
|
Userdata.UpdateLevelStar(Userdata.SelectLevel, currLevelStar);
|
|
//解锁下一关
|
if (Userdata.SelectLevel < Global.MAX_STAGE * Global.MAX_MORE_LEVELS) {//有下一关
|
Userdata.SelectLevel += 1;
|
Userdata.UnlockLevel(Userdata.SelectLevel);
|
}
|
|
|
this.showProgress(addScore);
|
this.scheduleOnce(function () {
|
Userdata.saveUserdata();
|
}.bind(this), 1);
|
|
} else {
|
SoundManager.playFailed();
|
this.showProgress(0);
|
}
|
|
this.nextButton.interactable = isWin;
|
|
if (Sdk.isToutiao){
|
this.shareRecordButton.node.active = !isSkip && SdkToutiao.lastRecordPath;
|
}else{
|
this.shareRecordButton.node.active = false;
|
}
|
|
this.updateStars();
|
}
|
|
onClickMoreGames(){
|
SoundManager.playButton();
|
if (Sdk.isToutiao){
|
SdkToutiao.showMoreGames();
|
}
|
}
|
|
onClickFollow(){
|
SoundManager.playButton();
|
if (Sdk.isToutiao){
|
SdkToutiao.showFollow();
|
}
|
}
|
|
onClickShortcut(){
|
SoundManager.playButton();
|
if (Sdk.isToutiao){
|
SdkToutiao.addShortcut();
|
}
|
}
|
|
updateStars() {
|
RankTool.uploadAsync(Userdata.Stars, Userdata.CurrSkin);
|
}
|
|
showProgress(addScore: number) {
|
this.from = Userdata.RewardScore / Global.REWARD_NEED_SCORE;
|
Userdata.RewardScore += addScore;
|
this.to = Userdata.RewardScore / Global.REWARD_NEED_SCORE;
|
|
this.scoreProgress.fillRange = this.from;
|
|
cc.log("from = " + this.from + " to = " + this.to);
|
|
if (this.to > 1) {//会满一次后,再从0开始
|
while (this.to > 1) {
|
this.to -= 1;
|
}
|
while (Userdata.RewardScore > Global.REWARD_NEED_SCORE) {
|
Userdata.RewardScore -= Global.REWARD_NEED_SCORE;
|
}
|
|
this.schedule(this.updateRewardFull, 0.03, cc.macro.REPEAT_FOREVER, 0);
|
} else {
|
this.schedule(this.updateRewardProgress, 0.03, cc.macro.REPEAT_FOREVER, 0.25);
|
}
|
}
|
|
updateRewardFull(dt: number) {
|
this.from += dt * 0.3;
|
if (this.from > 1) {
|
this.from = 1;
|
}
|
|
this.scoreProgress.fillRange = this.from;
|
|
if (this.from >= 1) {
|
this.from = 0
|
this.unschedule(this.updateRewardFull);
|
this.schedule(this.updateRewardProgress, 0.03, cc.macro.REPEAT_FOREVER, 0.25);
|
|
Global.showScoreRewardUI(this.node.parent, this.node);
|
|
//Userdata.addGem(Global.SCORE_REWARD_GEM);
|
//Userdata.saveUserdata();
|
//Global.showTip(this.node.parent, "获得10钻石!");
|
}
|
}
|
|
updateGems() {
|
if (this && this.gemLabel){
|
this.gemLabel.string = Userdata.Gem.toString();
|
}
|
}
|
|
updateRewardProgress(dt: number) {
|
this.from += dt * 0.3;
|
if (this.from > this.to) {
|
this.from = this.to;
|
}
|
|
//cc.log("from = " + this.from + " to = " + this.to);
|
|
this.scoreProgress.fillRange = this.from;
|
|
if (this.from >= this.to) {
|
this.unschedule(this.updateRewardProgress);
|
}
|
}
|
|
onClickNext() {
|
SoundManager.playButton();
|
if ((this.currLevel + 1) > Global.MAX_STAGE * Global.MAX_MORE_LEVELS) {//没有下一关
|
Global.showTip('你通关了, 牛逼格拉斯.');
|
return;
|
}
|
Userdata.SelectLevel = this.currLevel + 1;
|
|
this.hide();
|
|
Game.instance.reloadLevel();
|
}
|
|
onClickNextWithFriends() {
|
SoundManager.playButton();
|
if ((this.currLevel + 1) > Global.MAX_STAGE * Global.MAX_MORE_LEVELS) {//没有下一关
|
Global.showTip('你通关了, 牛逼 !!!');
|
return;
|
}
|
|
// this.hide();
|
|
if (Sdk.isToutiao) {
|
SdkToutiao.shareRecord(null, (res) => {
|
if (res) {
|
Global.showTip("获得奖励 50 钻石.");
|
Userdata.addGem(50);
|
Game.instance.updateGems();
|
this.updateGems();
|
Userdata.saveUserdata();
|
this.shareRecordButton.interactable = false;
|
this.shareRecordLabel.string = "已领取";
|
} else {
|
Global.showTip("分享失败");
|
}
|
});
|
} else {
|
// let screenShot = cc.find('ScreenShot');
|
// if (screenShot) {
|
// let ss1: any = screenShot.getComponent('ScreenShot');
|
// ss1.updateInfo(Userdata.Stars, true, (baseImg64) => {
|
// Sdk.ins.playWithFriend(baseImg64, 'Come and play this interesting game.', () => {
|
// Userdata.SelectLevel = this.currLevel + 1;
|
// Game.instance.reloadLevel();
|
// })
|
// });
|
// }
|
}
|
}
|
|
onClickShareScreenShot() {
|
SoundManager.playButton();
|
|
// let screenShot = cc.find('ScreenShot');
|
// if (screenShot) {
|
// cc.log('resultLayer share found screenshot');
|
// let ss1: any = screenShot.getComponent('ScreenShot');
|
// ss1.updateInfo(Userdata.Stars, true, (baseImg64) => {
|
// Sdk.ins.share(baseImg64, 'Come and play this interesting game.');
|
// });
|
// }
|
}
|
|
onClickRetry() {
|
SoundManager.playButton();
|
this.hide();
|
|
Userdata.SelectLevel = this.currLevel;
|
Game.instance.reloadLevel();
|
}
|
|
onClickClose() {
|
SoundManager.playButton();
|
this.hide();
|
|
let loading = cc.find('Canvas/Loading');
|
if (loading) {
|
loading.zIndex = 999;
|
loading.active = true;
|
}
|
cc.director.loadScene("main");
|
}
|
|
onClickWatchAds() {
|
SoundManager.playButton();
|
}
|
|
hide() {
|
this.node.active = false;
|
this.destroy();
|
}
|
}
|