| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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;
- if (!mk.guide.isGuideComplete()) return;
- if (gData.gameData.gameStyle.node.parent.childrenCount > 1) 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) {
- 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不触发。
- const point_world_pos = touch.getLocation();
- let localPoint = this.node.parent.convertToNodeSpaceAR(new cc.Vec2(point_world_pos.x, point_world_pos.y));
- let result = this.pointInPoly(localPoint, this.node);
- return result;
- }
- private onTouchEnded(touch: cc.Touch, event: cc.Event.EventTouch): void {
- // cc.log("touch end");
- this.onClickCall(touch);
- }
- /**
- * 点是否在节点宽高范围内
- * @param point 点击的点
- * @param node
- * @returns
- */
- private pointInPoly(point: cc.Vec2 | cc.Vec3, node: cc.Node) {
- const self_node_pos = node.getPosition();
- if (point.x >= (self_node_pos.x - (this.node.width / 2)) &&
- point.x <= (self_node_pos.x + (this.node.width / 2)) &&
- point.y >= (self_node_pos.y - (this.node.height / 2)) &&
- point.y <= (self_node_pos.y + (this.node.height / 2))) {
- return true;
- }
- return false;
- }
- protected onDestroy(): void {
- // super.onDestroy();
- this._eventManager.removeListener(this._touchListener, this.node);
- mk.event.remove('close-panel', this.onClosePanel, this);
- }
- }
|