123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- import EventMgr from "../game/EventMgr";
- import { GameEvent } from "../game/GameEvent";
- import { GameMode } from "../game/GameMode";
- import Main from "../game/Main";
- import { SDKIpt } from "../game/SDKIpt";
- import DateTime from "../help/DateTime";
- import valBar from "./valBar";
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class gameView extends cc.Component {
- /**开始游戏 */
- @property(cc.Button)
- private btnPause: cc.Button = null;
- @property(cc.Label)
- private lbKillMonsterNum: cc.Label = null;
- @property(cc.Label)
- private lbBest: cc.Label = null;
- @property(cc.Node)
- private deductionText: cc.Node = null;
-
- @property(cc.Node)
- private endlessNode: cc.Node = null;
- @property(cc.Label)
- private lbRound: cc.Label = null;
-
- @property(cc.RichText)
- private endlessTime: cc.RichText = null;
- @property(cc.Node)
- private endlessWolfTitle: cc.Node = null;
- //无尽模式这一波狼剩余数量
- @property(cc.Label)
- private endlessWolfCount: cc.Label = null;
- // @property(cc.Label)
- // private lbHp: cc.Label = null;
- @property(valBar)
- private hpBar: valBar = null;
- @property(valBar)
- private rageBar: valBar = null;
-
- // @property(cc.Node)
- // private spHpTmp: cc.Node = null;
- // @property(cc.Node)
- // private hpRoot: cc.Node = null;
- // @property(cc.Node)
- // private hpPanel: cc.Node = null;
- // @property([cc.SpriteFrame])
- // private sprites:cc.SpriteFrame[] = []
-
- /**无尽模式计时器 */
- private tiemrId_endless;
- @property([cc.Node])
- private spHeadStats: cc.Node[] = [];
-
- @property(cc.Node)
- private guildTitle: cc.Node = null;
- // private initHp:number = 20;
- // private hps:cc.Node[]=[];
- onLoad () {
- this.btnPause.node.on("click",this.onBtnPause,this);
- this.guildTitle.active = Main.Ins.IsGuide;
- EventMgr.Instance.add_event_listenner(GameEvent.GuideState,this,this.onGuideChange);
- }
- onGuideChange(GuideState: GameEvent, isOpen: boolean, onGuideChange: any) {
- this.guildTitle.active = Main.Ins.IsGuide;
- }
- // protected start(): void {
-
- // }
- ON_SDK_UI_IPT(SDK_UI_IPT: GameEvent, ipt: SDKIpt, ON_SDK_UI_IPT: any) {
- if (!this.node.active) { return; }
- // if (Ticker.isPause) { return; }
- if (Main.Ins.MainView.active) { return; }
- switch (ipt) {
- case SDKIpt.leftFoot:
- Main.Ins.PauseGameView();
- break;
- default:
- break;
- }
- }
- OnEndlessGameNewRound() {
- // console.error("OnEndlessGameNewRound-------");
- let me = this;
- if (Main.Ins.Mode ==GameMode.endless) {
- // console.log("第"+Main.Ins.Round+"波--"+DateTime.format_hh_mm_ss());
- me.lbRound.string ="第"+Main.Ins.Round+"波";
- let endlessTime = Main.Ins.EndlessTime;
- me.endlessTime.string =me.timeShow(endlessTime-2);
- me.endlessWolfCount.string = Main.Ins.EndlessEnemyCount.toString()+'只';
-
- Ticker.unregistCount(this.tiemrId_endless);
- me.tiemrId_endless = Ticker.registerCount(function (count) {
- if (count>=2) {
- me.endlessTime.string =me.timeShow(endlessTime - count);
- // me.endlessTime.string = (endlessTime- count).toString();
- }
- }, endlessTime);
- }
- }
- private timeShow(endlessTime) {
- // console.error(endlessTime);
-
- let richOutline = "<outline color={0} width={1}>{2}</outline>";// "<outline color=black width=2>x</outline>";
- let richBold = "<b>{0}</b>";//"<b>x</b>"
- let richColor = "<color={0}>{1}</c>";//<color=#FFE25D>20</c>
- let str;
- let count1;
- let count2 = endlessTime - (Main.Ins.initEndlessTime - 2);
- if (count2 > 0) {
- count1 = endlessTime - count2;
- // str = count1 + "+" + count2;
-
- // str = richOutline.format("black", "2", count1);
- // str = richBold.format(str);
- // str = richColor.format("#FFE25D",str);
- str = "<outline color=black width=2><b><color=#FFE25D>"+count1+"秒</c><color=#6DFF5D><size=36>+"+count2+"秒</size></color></b></outline>"
- } else {
- count1 = endlessTime;
- str = endlessTime;
- // str = richOutline.format("black", "2", count1);
- // str = richBold.format(str);
- // str = richColor.format("#FFE25D",str);
-
- str = "<outline color=black width=2><b><color=#FFE25D>"+count1+"秒</c></b></outline>"
- }
- // str = richOutline.format("black", "2", count1);
- // str = richBold.format(str)
- // <outline color=black width=2><b><color=#FFE25D>20</c><color=#6DFF5D>+1</color></b></outline>
- // if (endlessTime>Main.Ins.initEndlessTime-2) {
- // let allCount = endlessTime;
- // let count1 = Main.Ins.initEndlessTime-2;
- // let count2 = allCount - count1;
- // str = count1.toString();
- // if (count2>0) {
- // str +="+"+count2;
- // }
- // }else{
- // str =endlessTime;
- // }
- return str;
- }
- OnHeroSuperSkill() {
- this.rageBar.show(0);
- }
- OnUpdateBestKill() {
- this.lbBest.string = `最高记录:${Main.Ins.BestScore}分`;
- }
- private onBtnPause() {
- // Ticker.tooglePause();
- // if ( cc.director.getScheduler().getTimeScale()==1) {
- // //游戏开始
- // cc.director.getScheduler().setTimeScale(0);
- // } else {
- // //游戏暂停
- // cc.director.getScheduler().setTimeScale(1);
- // }
-
- // if (cc.director.isPaused()) {
- // //游戏开始
- // cc.director.resume();
- // } else {
- // //游戏暂停
- // cc.director.pause();
- // }
-
- EventMgr.Instance.dispatch_event(GameEvent.SDK_UI_IPT,SDKIpt.leftFoot);
- // Main.Ins.PauseGameView();
-
- }
-
- private tickId_pause_ipt;
- public Show(){
- let me= this;
- this.node.active = true;
-
- EventMgr.Instance.remove_event_listenner(GameEvent.SDK_UI_IPT,me,me.ON_SDK_UI_IPT);
- Ticker.unregisterDelay(this.tickId_pause_ipt);
- this.tickId_pause_ipt = Ticker.registerDelay(function(){
- EventMgr.Instance.add_event_listenner(GameEvent.SDK_UI_IPT,me,me.ON_SDK_UI_IPT);
- // console.error("监听暂停");
- },100);
- EventMgr.Instance.add_event_listenner(GameEvent.HeroHpChange,this,this.OnHeroHpChange);
- EventMgr.Instance.add_event_listenner(GameEvent.HeroRageChange,this,this.OnHeroRageChange);
- EventMgr.Instance.add_event_listenner(GameEvent.UpdateBestKill,this,this.OnUpdateBestKill);
- EventMgr.Instance.add_event_listenner(GameEvent.HeroSuperSkill,this,this.OnHeroSuperSkill);
- // console.error("gameview监听");
- EventMgr.Instance.add_event_listenner(GameEvent.EndlessGameNewRound,this,this.OnEndlessGameNewRound);
- EventMgr.Instance.add_event_listenner(GameEvent.update_endless_wolf_count,this,this.on_update_endless_wolf_count);
-
- }
- on_update_endless_wolf_count(update_endless_wolf_count: GameEvent, count: number, on_update_endless_wolf_count: any) {
- this.endlessWolfCount.string = count.toString()+'只';
- }
- private hasInit:boolean =false;
-
- public Hide(){
- this.node.active = false;
-
- Ticker.unregisterDelay(this.tiemrId_endless);
- EventMgr.Instance.remove_event_listenner(GameEvent.HeroHpChange,this,this.OnHeroHpChange);
- EventMgr.Instance.remove_event_listenner(GameEvent.HeroRageChange,this,this.OnHeroRageChange);
- EventMgr.Instance.remove_event_listenner(GameEvent.UpdateBestKill,this,this.OnUpdateBestKill);
- EventMgr.Instance.remove_event_listenner(GameEvent.HeroSuperSkill,this,this.OnHeroSuperSkill);
- EventMgr.Instance.remove_event_listenner(GameEvent.EndlessGameNewRound,this,this.OnEndlessGameNewRound);
- EventMgr.Instance.remove_event_listenner(GameEvent.update_endless_wolf_count,this,this.on_update_endless_wolf_count);
-
- EventMgr.Instance.remove_event_listenner(GameEvent.SDK_UI_IPT,this,this.ON_SDK_UI_IPT);
- Ticker.unregisterDelay(this.tiemrId_endless);
- }
- public Init(hp:number){
- // this.initHp = hp;
-
- Ticker.unregisterDelay(this.tiemrId_endless);
- this.hpBar.node.active = Main.Ins.Mode == GameMode.normal;
- if (Main.Ins.Mode == GameMode.normal) {
- this.rageBar.node.y = this.hpBar.node.y-44;
- }else{
- this.rageBar.node.y = this.hpBar.node.y;
- }
- // this.rageBar.node.active = Main.Ins.Mode == GameMode.normal;
- this.endlessNode.active = Main.Ins.Mode == GameMode.endless;
- this.lbRound.string = "";
- if (Main.Ins.Mode == GameMode.normal) {
- this.hpBar.show(hp);
- }
- this.rageBar.show(0);
- this.OnUpdateBestKill();
- this.lbKillMonsterNum.string = "0";
- this.showHeroHead(hp);
- }
- public OnMonsterDie(killNum:number){
- this.lbKillMonsterNum.string = killNum.toString();
- }
- public OnHeroHpChange(msg: string, nowHp: number) {
- if (Main.Ins.Mode == GameMode.normal) {
- this.hpBar.show(nowHp);
- this.showHeroHead(nowHp);
- }
- }
- public OnHeroRageChange(msg: string, now: number) {
- this.rageBar.show(now);
- }
- public showDeductionText(){
- const lbKillWidth = this.lbKillMonsterNum.node.width
- const lbKillRight = this.lbKillMonsterNum.node.x
- this.deductionText.x = Math.ceil(Math.abs(lbKillWidth)+ Math.abs(lbKillRight)+6)*-1
- cc.tween(this.deductionText)
- .stop()
- .to(.3, {opacity: 200})
- .delay(.2)
- .to(.3, {opacity: 0})
- .start();
- }
- private showHeroHead(nowHp: number) {
- if (Main.Ins.Mode == GameMode.normal) {
- this.spHeadStats[0].active = nowHp > 8;
- this.spHeadStats[1].active = nowHp > 6;
- this.spHeadStats[2].active = nowHp > 4;
- this.spHeadStats[3].active = nowHp > 2;
- this.spHeadStats[4].active = nowHp > 1;
- this.spHeadStats[5].active = true;
- }else{
- this.spHeadStats[0].active = true;
- }
- }
-
- protected onDestroy(): void {
- EventMgr.Instance.remove_event_listenner(GameEvent.HeroHpChange,this,this.OnHeroHpChange);
- EventMgr.Instance.remove_event_listenner(GameEvent.HeroRageChange,this,this.OnHeroRageChange);
- EventMgr.Instance.remove_event_listenner(GameEvent.UpdateBestKill,this,this.OnUpdateBestKill);
- EventMgr.Instance.remove_event_listenner(GameEvent.HeroSuperSkill,this,this.OnHeroSuperSkill);
- EventMgr.Instance.remove_event_listenner(GameEvent.EndlessGameNewRound,this,this.OnEndlessGameNewRound);
- EventMgr.Instance.remove_event_listenner(GameEvent.update_endless_wolf_count,this,this.on_update_endless_wolf_count);
-
- EventMgr.Instance.remove_event_listenner(GameEvent.SDK_UI_IPT,this,this.ON_SDK_UI_IPT);
- Ticker.unregisterDelay(this.tiemrId_endless);
- }
- }
|