GuideManager.ts
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { UIManager } from "../ui/UIManager";
export class GuideManager {
private static _ins: GuideManager = null;
static get ins(): GuideManager {
if (this._ins == null) {
this._ins = new GuideManager();
}
return this._ins;
}
private _talkNode: cc.Node;
private _handNode: cc.Node;
init(node: cc.Node) {
this._talkNode = node.getChildByName('talk');
this._handNode = node.getChildByName('hand');
this._talkNode.removeFromParent();
this._handNode.removeFromParent();
this._talkNode.active = false;
this._handNode.active = false;
UIManager.ins.widgetLayer.addChild(this._talkNode);
UIManager.ins.widgetLayer.addChild(this._handNode);
}
showTalk(wpos: cc.Vec2, txt: string) {
this._talkNode.parent.convertToNodeSpaceAR(wpos, wpos);
this._talkNode.setPosition(wpos);
let label = this._talkNode.getComponentInChildren(cc.Label);
label.string = txt;
this._talkNode.active = true;
this._talkNode.height = label.node.height + 30;
let arrow = this._talkNode.getChildByName('arrow');
arrow.y = -this._talkNode.height / 2;
this._talkNode.y += this._talkNode.height / 2;
cc.Tween.stopAllByTarget(this._talkNode);
this._talkNode.scale = 0;
cc.tween(this._talkNode).to(0.2, { scale: 1 }, { easing: 'backOut' }).start();
}
hideTalk() {
cc.Tween.stopAllByTarget(this._talkNode);
this._talkNode.active = false;
}
showHand(wpos: cc.Vec2, down: boolean = true) {
this._handNode.parent.convertToNodeSpaceAR(wpos, wpos);
this._handNode.setPosition(wpos);
this._handNode.active = true;
let img = this._handNode.getChildByName('btn');
img.angle = down ? 90 : 270;
this._handNode.y += (this._handNode.height / 2 * (down ? 1 : -1));
}
hideHand() {
this._handNode.active = false;
}
}