const PN_sBack = 140;
const PN_sChara = 150;
const PN_sLogo = 157;
const PN_sBtn = PN_sLogo + 1;
const PN_Jukon = PN_sBtn + 6;
const PN_BugfixBtn = PN_Jukon + 1;
const CN_Start = 2; 
const TitPic = "pictures/Title/";
let title_Selecter = 0; 
let title_SelecterRFlg = false; 
let _TitleTcPic = []; 
let titleLogoFlg = true;
let titleLogoFrame = 0;
Game_Interpreter.prototype.Title_LogoUpdate = function () {
    if (titleLogoFrame == 0) {
        this.SetPictFInC( PN_sBack , "logo" , 1440 / 2 , 810 / 2 , 0 , 0 , 15);
    }
    if (titleLogoFrame == 45) {
        this.MovePict(PN_sBack , true , true , 15 , 0);
    }
    if (titleLogoFrame == 60) {
        titleLogoFlg = false;
    }
    titleLogoFrame++;
}
Game_Interpreter.prototype.Title_Start = function () {
    $gameSystem.Voice重複禁止 = true; 
    TitleFlg = true;
    this.SetPictFIn(PN_sBack, TitPic + "PN_sBack", 0, 0, 0, 0, 5);
    $gameSystem.Voice重複禁止 = false;
}
Game_Interpreter.prototype.Title_PicDel = function () {
    this.DelPictSpan(PN_sBack + 0, PN_sBtn + 5);
}
let TitleGallaryModeOnFlg = true;
let TitleGallaryMode = false;
let TitleSlaveMode = false;
let TitleWaitFrame = 0;
let TitleGallarySlectViewFlg = false;
let TitleSlaveSlectViewFlg = false;
let TitleLogoCBM = [
    [60,120,34,30]
];
let title_flame = 0;
let start_flame = 0; 
let title_option_flg = false;
let TitleL2DSetFlg = false;
let TitleL2DLoadCmp = false;
let TitleEasterCnt = 0;
Game_Interpreter.prototype.Title_Update = function () {
    if (TitleWaitFrame > 0) {
        TitleWaitFrame--;
        return;;
    }
    if (TitleGallaryMode) {
        this.Gallary_Update();
        return;
    }
    if (TitleSlaveMode) {
        this.SlaveSelect_Update();
        return;
    }
    if (start_flame == 0){
        L2dIdleStart("Title","1yure");
    }
    if(!TitleL2DSetFlg) {
        L2dFadeMdl_FadeZureX = 500;
        EasingStr = "easeOutQuad";
        L2dFadeMdl("Title","in",180,"1yure" , 1, 1 ,100); 
        EasingStr = "";
        TitleL2DSetFlg = true;
    }
    if (title_flame == 0){
        this.SetPtcSc("Title",true,true,555);
        this.Title_Start();
    }
    if (title_flame == 60) {
        this.SetPictFIn(PN_sLogo, TitPic + "PN_sLogo", 0, 0, 20, 0, 60);
        _TitleTcPic = [];
    }
    if (title_flame == 120) {
        for (let i = 0; i <= 3 - 1; i++) {
            let _bX = 40 + (70 * i);
            let _by = 512 + (68 * i);
            this.SetPictFIn(PN_sBtn + i, TitPic + "PN_sBtn" + i, _bX, _by, 10, 0, 60 + (20 * i));
            _TitleTcPic.push(PN_sBtn + i);
            if (title_Selecter == i){
                this.PicCngColor(PN_sBtn + i, [150, 150, 150, 0] );
            }
        }
        if (this.IsGallaryMode()) {
            this.SetPictFIn(PN_sBtn + 3, TitPic + "PN_sBtn3" , 380, 512 + (68 * 0), 10, 0, 60 + (20 * 0));
            TitleGallarySlectViewFlg = true;
            _TitleTcPic.push(PN_sBtn + 3); 
        }
        if (this.IsSlaveMode()) {
            this.SetPictFIn(PN_sBtn + 4, TitPic + "PN_sBtn4" , 420 + 8, 512 + (68 * 1), 10, 0, 60 + (20 * 1));
            TitleSlaveSlectViewFlg = true;
            _TitleTcPic.push(PN_sBtn + 4); 
        }
        this.SetPictFIn(PN_sBtn + 5, TitPic + "PN_sBtn5" , 482, 512 + (68 * 2), 10, 0, 60 + (20 * 2));
        _TitleTcPic.push(PN_sBtn + 5); 
        this.SetPictFIn(PN_BugfixBtn, TitPic + "PN_BugfixBtn", 630, 741, 20, 0, 60);
    }
    if (title_flame > 120) {
        if (start_flame > 0){
            this.Start_Update();
            return; 
        }
        let _cmbNo = overPicClickable( PN_sLogo , TitleLogoCBM);
        if (_cmbNo != -1) {
            MouseStopFlame = 0;
            if (TouchInput.isTriggered() && TitleEasterCnt < 10) {
                TitleEasterCnt++;
                if (TitleEasterCnt == 10) {
                    this.GallaryMode全開放();
                    this.SlaveMode全開放();
                    this.PlaySe("spell_harness_magic_06");
                    this.SetPict(PN_FukiWin , "White");
                    this.MovePict(PN_FukiWin , true , true , 10 , 0);
                    this.SetPict(PN_sBtn + 3, TitPic + "PN_sBtn3" , 380 , 512);
                    TitleGallarySlectViewFlg = true;
                    if (_TitleTcPic.indexOf(PN_sBtn + 3) == -1) _TitleTcPic.push(PN_sBtn + 3); 
                    this.SetPict(PN_sBtn + 4, TitPic + "PN_sBtn4" , 420 + 8 , 512 + (68 * 1));
                    TitleSlaveSlectViewFlg = true;
                    if (_TitleTcPic.indexOf(PN_sBtn + 4) == -1) _TitleTcPic.push(PN_sBtn + 4); 
                    this.UTA_Save();
                }
                SoundManager.playOk(); 
            }
        }
        if (loadFlg) {
            this.Menu_L1Save_Update(); 
            menu_l1_flame++;
            return; 
        }
        if(title_option_flg) {
            this.Menu_L1Option_Update(); 
            menu_l1_flame++;
            return; 
        }
        let _mvFlg = false;
        if (Input.isTriggered('up')) {
            title_Selecter--;
            _mvFlg = true;
        }
        if (Input.isTriggered('down')) {
            title_Selecter++;
            _mvFlg = true;
        }
        if (Input.isTriggered('right')) {
            if (TitleGallaryModeOnFlg) {
                if (!title_SelecterRFlg) _mvFlg = true;
                title_SelecterRFlg = true;
            }
        }
        if (Input.isTriggered('left')) {
            if (TitleGallaryModeOnFlg) {
                if (title_SelecterRFlg) _mvFlg = true;
                title_SelecterRFlg = false;
            }
        }
        if (title_Selecter < 0) title_Selecter = 2;
        if (title_Selecter > 2) title_Selecter = 0;
        if (title_SelecterRFlg) {
            if (title_Selecter == 0 && !TitleGallarySlectViewFlg) title_Selecter = 2;
            if (title_Selecter == 1 && !TitleSlaveSlectViewFlg) title_Selecter = 2;
        }
        let _CNo = overPointerCkArr(_TitleTcPic);
        if (_CNo != -1) {
            var ckValue = _CNo - PN_sBtn;
            if (ckValue < 3) {
                if (title_Selecter != _CNo - PN_sBtn || title_SelecterRFlg) {
                    title_SelecterRFlg = false;
                    title_Selecter = _CNo - PN_sBtn;
                    _mvFlg = true;
                }
            } else {
                if (title_Selecter != _CNo - PN_sBtn - 3 || !title_SelecterRFlg) {
                    title_SelecterRFlg = true;
                    title_Selecter = _CNo - PN_sBtn - 3;
                    _mvFlg = true;
                }
            }
        }
        if (_mvFlg) {
            SoundManager.playCursor(); 
            var ckPicNo = title_Selecter;
            if (title_SelecterRFlg) ckPicNo += 3;
            for (let i = 0; i <= 6 - 1; i++) {
                this.PicCngColor(PN_sBtn + i);
                if (ckPicNo == i) this.PicCngColor(PN_sBtn + i, [150, 150, 150, 0]);
            }
        }
        if (Input.isTriggered('ok') || ((_CNo != -1) && TouchInput.isTriggered())) {
            title_Flg = false;
            switch (title_Selecter) {
                case 0:
                    if (!title_SelecterRFlg) {
                        this.DelPict(PN_BugfixBtn);
                        this.StopPtcSc(555);
                        start_flame = 1;
                        TitleFlg = false;
                    } else {
                        this.Gallary_Start();
                        TitleGallaryMode = true;
                    }
                    break;
                case 1:
                    if (!title_SelecterRFlg) {
                        loadFlg = true;
                        SoundManager.playOk(); 
                        this.Menu_L1Load_Cng(); 
                    } else {
                        this.SlaveSelect_Start();
                        TitleSlaveMode = true;
                    }
                    break;
                case 2:
                    if (!title_SelecterRFlg) {
                        OptSelNo = 0;
                        title_option_flg = true;
                        SoundManager.playOk(); 
                        this.SetPictFIn( PN_mL2Base - 1 , "Black" , 0 , 0 , 0 , 0 , 15 , 150);
                        this.Menu_L1Option_Cng();
                    } else {
                        window.close();
                    }
                    break;
            }
        }
        this.PicCngColor( PN_BugfixBtn);
        if(overPointerCk(PN_BugfixBtn)) {
            this.PicCngColor( PN_BugfixBtn , [75,75,75,0]);
            if(TouchInput.isTriggered()) {
                SoundManager.playOk(); 
                WebPageOpen("https://forms.gle/sQXpn5N22Jd8MS4T8");
            }
        }
    }
    title_flame++;
}
Game_Interpreter.prototype.Start_Update = function () {
    if (start_flame == 1){
        L2dSetMotion("Title","2shoot"); 
        $gameScreen.startFlash([255,255,255,255], 15);
        $gameScreen.startShake(5, 10, 15)
        this.PlaySe("Title_Gun");
        this.SetPict(PN_Jukon , TitPic + "PN_Jukon" , 0 , 0);
        this.PlayPtcPic("Title_Gun",267,594);
    }
    if (start_flame == 60) {
        L2dAutoFadeOut("Title",60);
        this.MovePict( PN_Jukon , true , true , 60 , 0);
        this.EnFadeIn("Black");
    }
    if (start_flame == 120) {
        this.SetCmnEventSc(CN_Start); 
    }
    start_flame++;
}
