|
|
@@ -0,0 +1,74 @@
|
|
|
+
|
|
|
+const { ccclass, property } = cc._decorator;
|
|
|
+/**
|
|
|
+ * @author 薛鸿潇
|
|
|
+ */
|
|
|
+@ccclass
|
|
|
+export default class GuideWeak extends cc.Component {
|
|
|
+
|
|
|
+ onLoad() {
|
|
|
+ gData.guideWeakData.guideStyle = this;
|
|
|
+ this.InitTouch();
|
|
|
+ mk.event.register('close-panel', this.onClosePanel, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ update(dt) {
|
|
|
+ if (!gData.guideWeakData.enable) return;
|
|
|
+ if (!gData.guideWeakData.data_config.triggerTime) return;
|
|
|
+ if (gData.guideWeakData.cur_guide_id) return;
|
|
|
+
|
|
|
+ gData.guideWeakData.silent_time += dt;
|
|
|
+ if (gData.guideWeakData.silent_time >= gData.guideWeakData.data_config.triggerTime) {
|
|
|
+ gData.guideWeakData.initGuideId();
|
|
|
+ gData.guideWeakData.openPanelByBtn();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 界面关闭
|
|
|
+ */
|
|
|
+ public onClosePanel(panel_name: string = '') {
|
|
|
+ cc.log(panel_name)
|
|
|
+ if (gData.guideWeakData.panel_name_config[panel_name] == gData.guideWeakData.cur_guide_id) {
|
|
|
+ gData.guideWeakData.cur_guide_id = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /** 玩家的屏幕触摸操作 */
|
|
|
+ private onClickCall(touch) {
|
|
|
+ cc.log('弱引导计时重置');
|
|
|
+ gData.guideWeakData.silent_time = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ ///////////////// 自定义触摸监听 /////////////////
|
|
|
+ private _eventManager = cc["internal"]["eventManager"];
|
|
|
+ private _touchListener: any;
|
|
|
+ private InitTouch() {
|
|
|
+ const EventListener = cc["EventListener"];
|
|
|
+ this._touchListener = EventListener.create({
|
|
|
+ event: EventListener.TOUCH_ONE_BY_ONE,
|
|
|
+ swallowTouches: false,//是否吞噬touch事件
|
|
|
+ owner: this.node,
|
|
|
+ mask: null,
|
|
|
+ onTouchBegan: this.onTouchStart.bind(this),
|
|
|
+ onTouchMoved: null,
|
|
|
+ onTouchEnded: this.onTouchEnded.bind(this),
|
|
|
+ onTouchCancelled: null,
|
|
|
+ });
|
|
|
+ this._eventManager.addListener(this._touchListener, this.node);
|
|
|
+ }
|
|
|
+
|
|
|
+ private onTouchStart(touch: cc.Touch, event: cc.Event.EventTouch): boolean {
|
|
|
+ // cc.log("touch start");
|
|
|
+ //此处必须返回true(表示接触到了节点),否则TOUCH_MOVE,TOUCH_END,TOUCH_CANCEL不触发。
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ private onTouchEnded(touch: cc.Touch, event: cc.Event.EventTouch): void {
|
|
|
+ // cc.log("touch end");
|
|
|
+ this.onClickCall(touch);
|
|
|
+ }
|
|
|
+ protected onDestroy(): void {
|
|
|
+ // super.onDestroy();
|
|
|
+ this._eventManager.removeListener(this._touchListener, this.node);
|
|
|
+ mk.event.remove('close-panel', this.onClosePanel, this);
|
|
|
+ }
|
|
|
+}
|