VerbView.ts
8.38 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import { DummyLabel, DummyNode, DummyRichText, DummySpriteFrame, DummyWidget } from "../../common/CCDummyObjects";
import Typewriter from "../../common/components/Typewriter";
import { AudioManager } from "simba-cc-audio-manager";
import { CompositeDisposable } from "simba-eventkit";
import { GameModelManager } from "../model/GameModelManager";
import { DeepReadonlyObject } from "simba-utils";
import { IItemTbl } from "../../config/ItemTbl";
import { UIManager } from "../../common/gameplay/managers/UIManager";
const { ccclass, property } = cc._decorator;
@ccclass
export default class VerbView extends cc.Component {
@property(cc.RichText)
title: cc.RichText = DummyRichText;
@property(cc.RichText)
desc: cc.RichText = DummyRichText;
@property(cc.Widget)
loadingWidget: cc.Widget = DummyWidget;
@property(cc.Node)
loadingNode: cc.Node = DummyNode;
@property(Typewriter)
typewriter: Typewriter = undefined as unknown as Typewriter;
@property(cc.Node)
guideNode: cc.Node = DummyNode;
@property({ type: cc.Node, displayName: "物品掉落节点" })
shopNode: cc.Node = DummyNode;
private _title: string;
private _desc: string;
private _callback: Function | undefined;
private _intervalPixel = 0;
/**是否正在执行渐显动画 */
private _isShowAction: boolean = false;
private _loadingNodeX: number;
private _loadingNodeY: number;
private _disposable: CompositeDisposable = new CompositeDisposable();
/**标志数据是否已经准备就绪 */
private _forceClickDataReady: boolean = false;
private _itemSpriteFrame: cc.SpriteFrame = DummySpriteFrame;
private _showItemCfg: DeepReadonlyObject<IItemTbl> | undefined = undefined;
itemDropSprFrame: cc.SpriteFrame;
cfg: DeepReadonlyObject<IItemTbl>;
onLoad() {
this.loadingNode.x = this.node.getContentSize().width / 2 + 10;
this._loadingNodeX = this.node.getContentSize().width / 2 + 10;
this.loadingNode.y = this.node.getContentSize().height / 2 - 36 - this.loadingNode.height / 2;
this._loadingNodeY = this.node.getContentSize().height / 2 - 36 - this.loadingNode.height / 2;
this.guideNode.active = false;
if (CC_DEV) {
globalThis['VerbView'] = this;
}
}
onEnable() {
this._disposable.add(GameModelManager.ForceClickDataReady.on(this.forceClickDataReady));
}
onDisable() {
this.node.off(cc.Node.EventType.TOUCH_END, this.touchEndCallback, this);
}
testCallback() {
this.toDating(() => { }, { title: '', desc: '来电了!!!' });
}
/**到聊天 */
toChat(info: { title: string, desc: string }) {
console.log('=====报幕到聊天====');
AudioManager.stopMusic();
this.restartNode();
this._title = info.title;
this._desc = info.desc;
this.verbAction();
}
/**到约会 */
toDating(callback: Function, info: { title: string, desc: string }) {
console.log('=====报幕到约会====');
AudioManager.stopMusic();
this.restartNode();
this._title = info.title;
this._desc = info.desc;
this._callback = callback;
this.verbAction();
}
/**报幕执行动画 */
verbAction() {
this._isShowAction = true;
let sequence = cc.sequence(
cc.fadeIn(1),
cc.callFunc(() => {
if (this._title) {
//打字机效果
this.title.node.active = true;
this.typewriter.showRichTextTyper(this.title, this._title, () => {
if (this._desc) {
this.desc.node.active = true;
this.typewriter.showRichTextTyper(this.desc, this._desc);
}
});
} else {
this.title.node.active = false;
if (this._desc) {
this.desc.node.active = true;
this.typewriter.showRichTextTyper(this.desc, this._desc);
}
}
//加载提示进入
this.loadingNode.runAction(cc.moveTo(0.3, cc.v2(this._loadingNodeX - this.loadingNode.getContentSize().width - this._intervalPixel, this._loadingNodeY)));
}),
cc.delayTime(1),
cc.callFunc(() => {
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndCallback, this);
this._isShowAction = false;
this.guideNode.active = true;
if (this._callback) {
this._callback();
}
})
)
this.node.runAction(sequence);
}
/**重置node */
restartNode() {
this.node.stopAllActions();
this.node.active = true;
let wid = this.node.getComponent(cc.Widget);
wid.updateAlignment();
this.node.opacity = 0;
this._callback = undefined;
this.guideNode.active = false;
this.loadingNode.x = this.node.getContentSize().width / 2 + 10;
this.loadingNode.y = this._loadingNodeY;
this._forceClickDataReady = false;
this._isShowAction = false;
}
/**
* 点击回调
*/
touchEndCallback = () => {
//如果有物品掉落信息就清空
if (this._itemSpriteFrame || this._showItemCfg) {
this._itemSpriteFrame = DummySpriteFrame;
this._showItemCfg = undefined;
}
/**没有显示动画并且数据没有准备完毕 */
if (!this._isShowAction && this._forceClickDataReady) {
let sequence = cc.sequence(
cc.delayTime(0.5),
cc.spawn(
cc.fadeOut(1),
cc.callFunc(() => {
this.title.node.active = false;
this.desc.node.active = false;
this.guideNode.active = false;
//加载提示退出
this.loadingNode.runAction(cc.moveTo(0.3, cc.v2(this._loadingNodeX + this.loadingNode.getContentSize().width + this._intervalPixel, this._loadingNodeY)))
})
),
cc.callFunc(() => {
this.node.active = false;
// AudioManager.resumeMusic();
})
)
this.node.runAction(sequence);
}
}
forceClickDataReady = () => {
this._forceClickDataReady = true;
console.log('this._forceClickDataReady', this._forceClickDataReady);
}
setItemDropData(spriteFrame: cc.SpriteFrame, cfg: DeepReadonlyObject<IItemTbl>) {
this.itemDropSprFrame = spriteFrame;
this.cfg = cfg;
this.showItemDrop(spriteFrame, cfg.scaletime, cfg.scale, cfg.delaytime, cfg.collecttime);
}
showItemDrop(itemSpr: cc.SpriteFrame, dropTime: number, startScale: number, delayTime: number, collectTime: number) {
this.shopNode.active = true;
let itemNode = this.shopNode.getChildByName("item");
let shopSprNode = this.shopNode.getChildByName("shopSpr");
let itemSprNode = this.shopNode.getChildByName("item").getChildByName("itemSpr");
let itemBaiSpineNode = this.shopNode.getChildByName("item").getChildByName("itemSpine");
itemNode.rotation = -90;
itemSprNode.getComponent(cc.Sprite).spriteFrame = itemSpr;
cc.tween(itemNode)
.to(0, { scale: startScale })
.to(dropTime, { scale: 1, angle: 0 })
.call(() => {
itemBaiSpineNode.active = true;
cc.tween(itemNode)
.to(delayTime, {})
.call(() => {
itemBaiSpineNode.active = false;
shopSprNode.active = true;
cc.tween(itemNode)
.to(collectTime, { scale: 0, angle: -360, x: shopSprNode.x, y: shopSprNode.y })
.call(() => {
itemNode.x = 0;
itemNode.y = 0;
this.shopNode.active = false;
shopSprNode.active = false;
UIManager.showSceneToast("记得去卧室查看它的故事呦~~");
}).start();
}).start();
}).start();
}
}