UIPrivacy.ts 3.58 KB
import { WindowName } from "../../Global";

import { UIBase } from "../UIBase";
import { UIManager } from "../UIManager";

const { ccclass, property } = cc._decorator;
@ccclass
export default class UI_Privacy extends UIBase {
    private type: number = 1;

    @property(cc.Node)
    imgBg: cc.Node = null;
    @property(cc.Node)
    Privacy: cc.Node = null;

    private curTextNum: number = 0;
    private privacyTextList: cc.Node[] = null;

    // start() {

    // }
    protected onEnable(): void {
        this.curTextNum = 0;
        this.privacyTextList = this.Privacy.getChildByName('content').children;
        this.showFirstText();
        let _param = this.enableParam as number;
        this.Action_FadeIn();

        this.type = _param;
        if (_param == 2) {
            this.onEvent_ShowPrivcayText();
        } else {
            this.onEvent_BTN_Back();
        }

        cc.log('privacy')
    }


    showPrivacyTextForNum(curNum: number) {
        for (let i = 0; i < this.privacyTextList.length; i++) {
            if (i == curNum) {
                this.privacyTextList[i].active = true;
            } else {
                this.privacyTextList[i].active = false;
            }
        }
    }

    showFirstText() {
        this.privacyTextList.forEach(element => {
            if (element.name == 'Label1') {
                element.active = true;
            } else {
                element.active = false;
            }
        });
    }

    CloseUI() {
        this.Action_FadeOut();
        // this.showFirstText();
    }

    onEvent_BTN_Agree() {
        this.CloseUI();
        localStorage.setItem("_PRIVACY", "true");
    }

    onEvent_BTN_Exit() {
    }

    onEvent_BTN_Next() {
        this.curTextNum++;
        if (this.curTextNum >= this.privacyTextList.length) {
            this.curTextNum = 0;
        }
        this.showPrivacyTextForNum(this.curTextNum)

        //test
        // this.privacyTextList.forEach(element => {
        //     console.log(element.active + ' <<<<<<<<< ' + element.name)
        // });
    }

    onEvent_ShowPrivcayText() {
        this.imgBg.active = false;
        this.Privacy.active = true;
    }

    onEvent_BTN_Back() {
        if (this.type == 2) {
            this.CloseUI();
        } else {
            this.imgBg.active = true;
            this.Privacy.active = false;
        }
    }

    Action_SetButton_Clickable(value) {
        this.node.getChildByName('touchBlocker').active = !value;
    }

    Action_FadeIn(_data?: any, _fadeTime: number = 0.5) {
        // 动态进入的效果
        this.node.getChildByName('blackFrame').opacity = 0;
        cc.tween(this.node.getChildByName('blackFrame')).to(_fadeTime * 0.4, { opacity: 200 }).start();
        this.node.getChildByName('panel').scale = 0
        this.Action_SetButton_Clickable(false);
        cc.tween(this.node.getChildByName('panel')).to(_fadeTime, { scale: 1 }, { easing: 'backOut' }).call(() => {
            this.OnEvent_TweenFinished_FadeIn(_data);
        }).start();
    }

    OnEvent_TweenFinished_FadeIn(_data: any) {
        this.Action_SetButton_Clickable(true);
    }

    Action_FadeOut(_fadeTime: number = 0.3) {
        this.Action_SetButton_Clickable(false);
        cc.tween(this.node.getChildByName('blackFrame')).to(_fadeTime, { opacity: 0 }).start();
        cc.tween(this.node.getChildByName('panel')).to(_fadeTime, { scale: 0 }, { easing: 'backIn' }).call(() => {
            this.OnEvent_TweenFinished_FadeOut();
        }).start();
    }

    OnEvent_TweenFinished_FadeOut() {
        // this.node.active = false;
        UIManager.ins.closeWindow(WindowName.PRIVACY);

    }
}