/*
 * @Author: YeeChan
 * @Date: 2020-11-06 16:58:35
 * @Description: 登录重试按钮
 */

import FMViewBase from "../../Base/FMViewBase";
import AppPlatform from "../../Util/AppPlatform";

const { ccclass, property } = cc._decorator;

@ccclass
export default class DialogLoading extends FMViewBase {
    @property({ tooltip: "背景图", type: cc.Node })
    private bgNode: cc.Node = null;
    @property({ tooltip: "错误文本", type: cc.Label })
    private labelInfo: cc.Label = null;
    @property({ tooltip: "第一种类型", type: cc.Node })
    private typeNode1: cc.Node = null;
    @property({ tooltip: "第二种类型", type: cc.Node })
    private typeNode2: cc.Node = null;
    @property({ tooltip: "类型1中重新登录", type: cc.Node })
    private butLoad1: cc.Node = null;
    @property({ tooltip: "类型1中游客模式", type: cc.Node })
    private butVisitor1: cc.Node = null;
    @property({ tooltip: "类型2中重新登录", type: cc.Node })
    private butLoad2: cc.Node = null;

    public EventEnumView_custom = {
        ClickVisitor: "ClickVisitor",//游客
        ClickLoad: "ClickLoad"//登录
    };

    protected initView_custom(): void {
        this.butLoad1.on("click", () => {
            this.closeView();
            this.emitListenerEvent_custom(this.EventEnumView_custom.ClickLoad)
        }, this)
        this.butVisitor1.on("click", () => {
            this.closeView();
            this.emitListenerEvent_custom(this.EventEnumView_custom.ClickVisitor)
        }, this)
        this.butLoad2.on("click", () => {
            this.closeView();
            this.emitListenerEvent_custom(this.EventEnumView_custom.ClickLoad)
        }, this)
        if (AppPlatform.is_Android_custom() || AppPlatform.is_Iphone_custom()) {//anndroid ios模式 用第二种
            this.typeNode1.active = false;
            this.typeNode2.active = true;
        } else {
            this.typeNode1.active = true;
            this.typeNode2.active = false;
        }
    }

    /**
     * 打开提示框
     * @param info 
     */
    public openView(info: string) {
        this._initView_custom();
        this.labelInfo.string = info;

        cc.Tween.stopAllByTarget(this.bgNode);
        this.bgNode.opacity = 0;
        this.bgNode.scale = 0.75;
        cc.tween(this.bgNode)
            .to(0.25, { opacity: 255, scale: 1 }, { easing: "backOut" })
            .call(() => {
            })
            .start();
        this.node.active = true;
    }

    /**
     * 关闭
     */
    public closeView() {
        this.node.active = false;
    }


    protected addEvent_custom(): void { }
    protected removeEvent_custom(): void { }

}