123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import i18n from "../../../i18n/i18n";
- import ViewObject from "../../../main/ViewObject";
- import { __StageData } from "../../data/sdata/SManage";
- import FF from "../FF";
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class FExitBox extends ViewObject {
- @property(cc.Label)
- mAbout: cc.Label = null;
- @property(cc.Sprite)
- mGoodIcon1: cc.Sprite = null;
- @property(cc.Label)
- mGood1: cc.Label = null;
- @property(cc.Sprite)
- mGoodIcon2: cc.Sprite = null;
- @property(cc.Label)
- mGood2: cc.Label = null;
-
- @property(cc.Node)
- mStar: cc.Node = null;
- @property([cc.SpriteFrame])
- mStarx: Array<cc.SpriteFrame> = [];
- public endType = 0;
- public ff:FF
- public stageData:__StageData
- public callbackOK:()=>void;
- public callbackClose:()=>void;
-
- public setOKCallback(callbackOK:()=>void){
- this.callbackOK = callbackOK;
- }
- public setCloseCallback(callbackClose:()=>void){
- this.callbackClose = callbackClose;
- }
- public onclickOK(){
- this.__distroyAll();
- this.callbackOK();
- cc.director.getPhysicsManager().enabled = true;
- }
- public onclickCancel(){
- this.__distroyAll();
- if(this.callbackClose){
- this.callbackClose()
- }
- }
- public init(__stageData:__StageData){
- this.stageData = __stageData
- let sManage = this.main.sManage;
- let good1 = sManage.getGoodById1(this.stageData.goodId1);
- cc.resources.load('icon/good/'+good1.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
- if(err){
- cc.error(err);
- }else{
- this.mGoodIcon1.spriteFrame = spriteFrame;
- }
- } );
- let good2 = sManage.getGoodById1(this.stageData.goodId2);
- cc.resources.load('icon/good/'+good2.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
- if(err){
- cc.error(err);
- }else{
- this.mGoodIcon2.spriteFrame = spriteFrame;
- }
- } );
-
- this.flush();
- let starCount = this.getStarCount()
- let nodes = this.mStar.children;
- for (let i = 0; i < nodes.length; i++) {
- let node = nodes[i];
- let sprite = node.getComponent(cc.Sprite);
- if(i < starCount){
- sprite.spriteFrame = this.mStarx[1];
- }else{
- sprite.spriteFrame = this.mStarx[0];
- }
- }
- let starCount1 = 0
- let main = this.main;
- let stageData = main.player.stage;
- let stageAttr = stageData.data[this.stageData.id];
-
- if(stageAttr != null){
- let count1 = this.getCount(this.stageData.goodId1);
- if(count1 >= this.stageData.goodCount1){
- starCount1 ++
- }
- let count2 = this.getCount(this.stageData.goodId2);
- if(count2 >= this.stageData.goodCount2){
- starCount1 ++
- }
- }
- if(starCount1 >= 2){
- this.mAbout.string = i18n.t('关卡内任务已完成')
- }else{
- this.mAbout.string = i18n.t('关卡内还有未完成的任务,是否确定退出?')
- }
- }
-
- private getStarCount(){
- let main = this.main;
- let stageData = main.player.stage;
- let stageAttr = stageData.data[this.stageData.id];
- let starCount = 0;
- if(this.endType == 0){
- starCount ++
- }else{
- if(stageData.stageIndex > this.stageData.id){
- starCount ++
- }
- }
- if(stageAttr != null){
- let count1 = this.getCount(this.stageData.goodId1);
- if(count1 >= this.stageData.goodCount1){
- starCount ++
- }
- let count2 = this.getCount(this.stageData.goodId2);
- if(count2 >= this.stageData.goodCount2){
- starCount ++
- }
- }
- return starCount
- }
- public flush(){
- let count1 = this.getCount(this.stageData.goodId1);
- this.mGood1.string = count1+'/'+this.stageData.goodCount1;
- let count2 = this.getCount(this.stageData.goodId2);
- this.mGood2.string = count2+'/'+this.stageData.goodCount2;
- }
- public getCount(goodId){
- let player = this.main.player;
- let stage = player.stage;
- let curr = stage.data[this.stageData.id];
- if(curr && curr.good){
- let count = curr.good[''+goodId];
- if(count == undefined){
- return 0 ;
- }
- return count;
- }else{
- return 0;
- }
- }
- }
|