123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- import WOneByone from "../game/fight/evnet/map1/WOneByone";
- import Home from "../game/home/Home";
- import FqLogin from "../login/FqLogin";
- const { ccclass, property } = cc._decorator;
- /**
- * 第一次进入游戏主页时候的引导
- */
- @ccclass
- export default class PlotHome extends cc.Component {
- @property({
- displayName: '对话对象',
- type: [cc.Node]
- })
- mNode: Array<cc.Node> = [];
- @property(cc.Prefab)
- mMapDialog: cc.Prefab = null;
- @property([cc.String])
- text: Array<string> = [];
- @property(cc.Node)
- private mBlockInputEvents: cc.Node = null;
- /**
- * 冒险按钮
- */
- @property(cc.Node)
- mBtMx: cc.Node = null;
- @property(sp.Skeleton)
- mBtSpine: sp.Skeleton = null;//冒险菜单动画
- /**
- * 点击任意位置的回调
- */
- private blockInputCallback: () => void;
- private home: Home;
- onLoad() {
- this.home = this.node.getComponent(Home)
- }
- /**
- * 执行对话
- */
- public exDialog() {
- this.dialog(0)
- this.mBtSpine.node.parent.active = false;
- }
- public openMenu() {
- this.mNode[1].children[0].active = false;
- cc.tween(this).sequence(
- cc.delayTime(0.1),
- cc.callFunc(() => {
- this.mBtSpine.setAnimation(0, 'idle', true);
- })
- ).start()
- }
- private dialog(index: number) {
- if (index >= this.text.length) {
- this.setBlockInputCallback(null);
- this.moveToMx(() => {
- this.mBlockInputEvents.active = false;
- this.guideMX()
- })
- return;
- }
- let texts = this.text[index].split('|')
- let mid = parseInt(texts.shift());
- let curNode = this.mNode[mid]
- this.mBlockInputEvents.active = true
- this.showDialog(texts, curNode, null, () => {
- index++;
- this.dialog(index);
- });
- }
- /**
- * 对象头顶显示对话
- */
- private showDialog(dialogs: Array<string>,//对话内容
- curNode: cc.Node,//显示在地图中的位置
- spine: sp.Skeleton,//当前动画精灵
- callback: () => void)//对话结束后的回调
- {
- let node = cc.instantiate(this.mMapDialog);
- node.zIndex = 9999;
- node.y += curNode.height
- node.parent = curNode;
- let obo = node.getComponent(WOneByone);
- obo.dialogs = dialogs;
- obo.spine = spine;
- obo.setCallback(() => {
- node.destroy();
- callback();
- });
- this.setBlockInputCallback(() => {
- obo.jump();
- });
- obo._start();
- }
- public setBlockInputCallback(blockInputCallback: () => void) {
- this.blockInputCallback = blockInputCallback
- }
- public onclickBlockInput() {
- if (this.blockInputCallback) {
- this.blockInputCallback()
- }
- }
- /**
- * 幽灵移动到冒险按钮
- */
- private moveToMx(callback: () => void) {
- //1.幽灵变身
- let spine = this.mNode[1].children[0].getComponent(sp.Skeleton)
- spine.setAnimation(0, 'escape', false);
- spine.setCompleteListener(() => {
- spine.setCompleteListener(null)
- spine.setAnimation(0, 'fly', true);
- let pos = this.mBtMx.convertToWorldSpaceAR(cc.v2(0, 0));
- let winSize = cc.winSize;
- pos.x -= winSize.width / 2;
- pos.y -= winSize.height / 2;
- cc.tween(this.mNode[1]).sequence(
- cc.moveTo(1, pos),
- cc.callFunc(() => {
- this.openMenu1()
- callback()
- })
- ).start()
- })
- }
- private openMenu1() {
- this.mBtSpine.node.parent.active = true;
- this.mBtSpine.setCompleteListener(()=>{
- this.mBtSpine.setAnimation(0, 'idle', false);
- })
- this.mBtSpine.setAnimation(0, 'open', false);
- }
- /**
- * 强制引导到冒险
- */
- private guideMX() {
- let main = this.home.main
- let guideMask = main.mGuideMask
- guideMask.setTargetNode(this.mBtMx)
- guideMask.show()
- this.home.setMxCallback(() => {
- guideMask.close()
- this.home.setMxCallback(null)
- FqLogin.commitEvent('jinruguanqia','','')
- })
- }
- }
|