const CN_MenuStpCmn = 998;  
const CN_Menu強制終了 = 904;    
const SW_MenuHStOff = 20;    
const SW_MenuSaveOff = 1067; 
let MenuStopFlg = false; 
let Menu_Main_Selecter = 0; 
let MenuCngOkFlg = true; 
let LockNo = []; 
const VN_MenuCloseFlame = 146;
const SW_MenuDeckOff = 26; 
let menuAutoCloseFlame = 0;
Game_Interpreter.prototype.NupuLoadPicDel = function () {
    for (let i = PNo_MBase; i <= 300; i++) {
        this.DelSprite(i);
        this.DelPict(i);
    }
    _CmnSaveEndFlg = true;
};
const MN_Title = 8; 
let MenuKnsOffCk = function () {
    if (MenuModeStr != _MMode.Map) return true; 
    if (battleflg) return true; 
    if ($gameMap._mapId == MN_Title) return true; 
    return false;
}
Game_Interpreter.prototype.NupuMenuStart = function () {
    _Reset_AnalogMove(); 
    RentalDeckSetting();
    Menu着替え実行Flg = false;
    menuAutoCloseFlame = $gameVariables.value(VN_MenuCloseFlame);
    this.SetCmnEventSc(CN_BefMenu); 
    let args = new Array("on");
    this.pluginCommand("waitBlur", args);
    MenuKeyFlame = 0;
    MenuCngOkFlg = true;
    SelectMenuNoL1 = 1; 
    ClickMenuNo = 1;    
    Menu_EditLayer = 1; 
    Menu_Main_Selecter = 0;
    menuSyogoDataFlg = Menu_RclickStopFlg = false;
    if (SaveSelPage > 3) SaveSelPage = 0;
    SaveSelectNo
    GetCard_Setting(); 
}
function GetCard_CardSet(cardNo) {
    if ($gameSystem.GetCard.indexOf(cardNo) == -1) {
        $gameSystem.GetCard.push(cardNo);
    }
}
function GetCard_Setting() {
    for (let i = 1; i <= $dataWeapons.length - 1; i++) {
        if ($gameParty.hasItem($dataWeapons[i], true)) {
            GetCard_CardSet(i);
        }
    }
    $gameSystem.MasterDeck.forEach(cardNo => {
        GetCard_CardSet(cardNo);
    });
    $gameSystem.DeckArr.forEach(deckArr => {
        deckArr.forEach(cardNo => {
            GetCard_CardSet(cardNo);
        });
    });
}
const CN_着替え後 = 366;
Game_Interpreter.prototype.MenuEnd = function () {
    MenuFlame = 0;
    MenuAddresMode = 0;
    Menu_EditLayer = 1;
    this.Layer1_DelPicture();
    this.MenuPicDel();
    this.DelSpriteSpan(PN_SetuWaku, PN_T_Setu + 22); 
    this.DelSpriteSpan(PNo_MBase , PN_MnReric);
    this.SetSprite(PNo_Map, MapPicPath + "UI_Map_CharaBack", 979, 0);
    let args = new Array("off");
    this.pluginCommand("waitBlur", args);
    this.SetCmnEventSc(CN_着替え後);
}
Game_Interpreter.prototype.NupuMenuEnd_Cmn = function () {
    MenuCngOkFlg = true;
    MenuFlgSwich = false;
    this.MenuEnd();
    Menu_RclickStopFlg = false;
    MeneExitOkFlg = false; 
    Tutorial_Flg = _アルバムFlg = Item_BtlSelect_Flg = false;
    this.DelSpriteSpan(PN_MsBack, PN_MsSetVirs + 3);
}
Game_Interpreter.prototype.MenuPicDel = function () {
    let _DelPicAr = [PNo_MBase,
        PNo_MTBtn + 0, PNo_MTBtn + 1, PNo_MTBtn + 2,
        PNo_MBtn + 0, PNo_MBtn + 1, PNo_MBtn + 2, PNo_MBtn + 3, PNo_MBtn + 4, PNo_MBtn + 5,
        PNo_MBtn + 6, PNo_MBtn + 7,
        PNo_RockKey + 0, PNo_RockKey + 1, PNo_RockKey + 2,
        PNo_RockKey + 3, PNo_RockKey + 4, PNo_RockKey + 5];
    this.DelSpriteArr(_DelPicAr);
    this.DelPictArr(_DelPicAr); 
}
Game_Interpreter.prototype.MenuPicDelAll = function () {
    this.Layer1_DelPicture();
    this.MenuPicDel();
}
let Menu_DoCloseFlg = false; 
let MeneExitOkFlg = false; 
let MenuFlame = 0;
let SelectMenuNoL1 = 1; 
let ClickMenuNo = 1; 
let menu_ZureA = -993; 
let MenuOpenNo = 0; 
Game_Interpreter.prototype.MenuBaseUpdate = function () {
    if (MenuModeStr == _MMode.TalkMode) return; 
    if (MenuStopFlg) return; 
    this.SetSprite(PNo_Map, MenuUIPath + "UI_Map_CharaBack", 979, 0);
    if (Memory_EndFlg) Menu_Main_Selecter = 2;
    switch (Menu_Main_Selecter) {
        case 0: 
            this.MenuMainUpdate();
            break;
        case 1: 
            this.Menu_DE_Update();
            break;
        case 2: 
            this.Menu_H_BaseUpdate();
            break;
    }
    MenuFlame++;
    if (menuAutoCloseFlame > 0) {
        menuAutoCloseFlame--;
        if (menuAutoCloseFlame == 0) {
            switch (Menu_Main_Selecter) {
                case 0: 
                    break;
                case 1: 
                    this.Dc_CloseBtn();
                    break;
                case 2: 
                    L2dFadeMdl("romasha_talk", "rightin", 20, "talk"); 
                    break;
            }
            this.NupuMenuEnd_Cmn(); 
            this.SetCmnEventSc(CN_Menu強制終了);
            menuSyogoDataFlg = false;
            Equip_ExitFlg = false;
            this.Menu_Data_RentDeckMode_Exit();
            return;
        }
    }
}
Game_Interpreter.prototype.MenuMainUpdate = function () {
    if (Menu_Data_RentDeckMode) {
        this.Menu_Data_RentDeckMode_Update();
        return;
    }
    if (MenuFlame == 0) {   
        if (Menu_DoCloseFlg) {
            Menu_DoCloseFlg = false;
            MenuFlgSwich = false;
            this.MenuEnd(); 
            return;
        }
        MeneExitOkFlg = false; 
        if (!_Menu_FstDeckFlg && !_Menu_FstHstFlg) {
            this.MenuSetup(); 
        }
    }
    if (MenuFlame > 11) { 
        MeneExitOkFlg = true;   
        this.BtnPictUpdate();   
        this.MenuKeyWaitUpdate(); 
    }
}
Game_Interpreter.prototype.MenuMainReset = function () {
    MenuFlame = -1;
    Menu_Main_Selecter = 0;
    this.Layer1_DelPicture(); 
    if (_Menu_FstHstFlg || _Menu_FstDeckFlg) {
        _Menu_FstHstFlg = false;
        _Menu_FstDeckFlg = false;
        Menu_DoCloseFlg = true;
    }
}
const SW_ゴブリンパート = 750;
const _M_BtnX = -15; 
const _M_BtnY = 170; 
Game_Interpreter.prototype.MenuSetup = function () {
    this.SetSprite(PNo_MTBtn + 0, MenuUIPath + "MTBtn1b", 342 + (242 * 0), 110 , 0);
    this.SetSprite(PNo_MTBtn + 1, MenuUIPath + "MTBtn2", 342 + (242 * 1), 110 , 0);
    this.SetSprite(PNo_MTBtn + 2, MenuUIPath + "MTBtn3", 342 + (242 * 2), 110 , 0);
    if (!$gameSwitches.value(SW_MenuDeckOff) || $gameSwitches.value(SW_ゴブリンパート)) {
        this.SetSprite(PNo_MTBtn + 1, MenuUIPath + "MTBtn2_d", 342 + (242 * 1), 110 , 0);
    }
    if ($gameSwitches.value(SW_MenuHStOff)) {
        this.SetSprite(PNo_MTBtn + 2, MenuUIPath + "MTBtn3_d", 342 + (242 * 2), 110 , 0);
    }
    this.SetSprite(PNo_MBase, MenuUIPath + "PNo_MBase", menu_ZureA, 75);
    this.MoveSprite(PNo_MBase, 0, 75, 5);
    this.MoveSprite(PNo_MTBtn + 0, 342 + (242 * 0), 110, 5);
    this.MoveSprite(PNo_MTBtn + 1, 342 + (242 * 1), 110, 5);
    this.MoveSprite(PNo_MTBtn + 2, 342 + (242 * 2), 110, 5);
    for (let i = 0; i <= 6; i++) {
        let _zY = 0;
        if (i == 6) _zY = 30 + 67;
        this.SetSprite(PNo_MBtn + i, MenuUIPath + "PNo_MBtn" + (i + 1) + "a", menu_ZureA, _M_BtnY + (67 * i) + _zY);
        if ($gameSwitches.value(SW_MenuSaveOff) && (i + 1) == 4) {
            this.SetSprite(PNo_MBtn + i, MenuUIPath + "PNo_MBtn4d", menu_ZureA, _M_BtnY + (67 * i) + _zY);
        }
        this.MoveSprite(PNo_MBtn + i, _M_BtnX, _M_BtnY + (67 * i) + _zY, 5);
    }
    if ($gameSwitches.value(SW_エンディング見た)) {
        this.SetSprite(PN_MSkipBtn, MenuUIPath + "PN_MSkipBtn", 0, 590);
    }
    if ($gameSwitches.value(SW_ルーザーズ敗北)) {
        this.DelSprite(PNo_MBtn + 1);
    }
    let _CngPicStr = MenuUIPath + "PNo_MBtn" + ClickMenuNo + "b";
    let _CkNo = ClickMenuNo - 1;
    this.CngSprite(PNo_MBtn + _CkNo, _CngPicStr);
    _zY = 0;
    if (_CkNo == 6) _zY = 30 + 67;
    this.MoveSprite(PNo_MBtn + _CkNo, 0, _M_BtnY + (67 * _CkNo) + _zY, 5);
    if (MenuOpenNo == 0) {
        this.MenuDataView(true); 
    } else {
        this.MenuMouseUpdate();
        switch (MenuOpenNo) { 
            case 1: 
                this.MenuDataView(true);
                break;
            case 2: 
                ItemMode = 0;
                this.MenuItemView(true);
                break;
            case 3: 
                this.MenuEquipView(true);
                break;
            case 4: 
                if (NowLoadNo > 36) {
                    NowLoadNo = $gameVariables.value(VN_BefSaveNo); 
                }
                if (NowLoadNo != -1) {
                    if (NowLoadNo > 12) {
                        SaveSelectNo = (NowLoadNo - 1) % 12;
                        SaveSelPage = Math.floor((NowLoadNo - 1) / 12);
                    } else {
                        SaveSelectNo = NowLoadNo - 1;
                    }
                }
                _File_CngFlg = true;
                this.MenuSaveView(true);
                break;
            case 5: 
                this.MenuAddresView(true);
                break;
            case 6: 
                this.MenuOptionView(true);
                break;
            case 7: 
                this.MenuShutDownView(true);
                break;
        }
        ClickMenuNo = MenuOpenNo;
        this.MenuMainBtnDraw();
        MenuOpenNo = 0;
    }
}
let _SaveWaitTimer = -1; 
let _SaveFileNo = 0; 
Game_Interpreter.prototype.BtnPictUpdate = function () {
    this.Layer1_Update(); 
    if (_SaveWaitTimer >= 0) {
        MeneExitOkFlg = false; 
        if (_SaveWaitTimer == 0) {
            MeneExitOkFlg = true; 
            this.GameFileSave(_SaveFileNo);
            if (SaveCompAction != null) {
                SaveCompAction(this);
                SaveCompAction = null;
            }
        }
        _SaveWaitTimer--;
    }
}
let MenuKeyFlame = 0;
let MenuKeyWait = 0; 
Game_Interpreter.prototype.MenuKeyWaitUpdate = function () {
    MenuKeyFlame++;
    if (MenuKeyWait > 0) { 
        MenuKeyWait--;
        return;
    }
    this.MenuMouseUpdate(); 
}
let _Bef_ClickNo = -1;
Game_Interpreter.prototype.MenuMouseUpdate = function () {
    if (SaveClickOffFlame > 0) { 
        SaveClickOffFlame--;
        return;
    }
    let _ckBtnPicArr = [
        PNo_MBtn + 0, PNo_MBtn + 1, PNo_MBtn + 2,
        PNo_MBtn + 3, PNo_MBtn + 4, PNo_MBtn + 5,
        PNo_MBtn + 6 , PN_MSkipBtn, PNo_MailIcon];
    if ($gameSwitches.value(SW_MenuSaveOff)) {
        _ckBtnPicArr = _ckBtnPicArr.filter(item => item !== PNo_MBtn + 3); 
    }
    this.SpriteCngColor(PN_MSkipBtn);
    let _CkOverNoL1 = overPointerSpCkArr(_ckBtnPicArr);
    if (_CkOverNoL1 == PN_MSkipBtn) this.SpriteCngColor( PN_MSkipBtn , [100,100,100,0]);
    if (MenuOpenNo != 0) _CkOverNoL1 = PNo_MBtn + (MenuOpenNo - 1); 
    if (_CkOverNoL1 != -1 && MenuCngOkFlg && !Item_BtlSelect_Flg) { 
        MenuKeyFlame = 0;
        SelectMenuNoL1 = _CkOverNoL1 - PNo_MBtn + 1;
        if (TouchInput.isTriggered() && LockNo.indexOf(SelectMenuNoL1) == -1) { //クリック処理(それぞれ左項目)
            if (ClickMenuNo != _CkOverNoL1 - PNo_MBtn + 1) { 
                Menu_Data_VirusMode = false;
                Menu_EditLayer = 1; 
                _Bef_ClickNo = ClickMenuNo;
                ClickMenuNo = _CkOverNoL1 - PNo_MBtn + 1; 
                if (_CkOverNoL1 == PNo_MailIcon) ClickMenuNo = 5;
                this.MenuMainBtnDraw();
                if (ClickMenuNo != 7) {
                    this.Layer1_DelPicture(); 
                }
                switch (ClickMenuNo) { 
                    case 1: 
                        this.MenuDataView(true);
                        break;
                    case 2: 
                        if ($gameSwitches.value(SW_ルーザーズ敗北)) break;
                        ItemMode = 0;
                        this.MenuItemView(true);
                        break;
                    case 3: 
                        this.MenuEquipView(true);
                        break;
                    case 4: 
                        if (NowLoadNo > 36) {
                            NowLoadNo = $gameVariables.value(VN_BefSaveNo); 
                        }
                        if (NowLoadNo != -1) {
                            if (NowLoadNo > 12) {
                                SaveSelectNo = (NowLoadNo - 1) % 12;
                                SaveSelPage = Math.floor((NowLoadNo - 1) / 12);
                            } else {
                                SaveSelectNo = NowLoadNo - 1;
                            }
                        }
                        _File_CngFlg = true;
                        this.MenuSaveView(true);
                        break;
                    case 5: 
                        this.MenuAddresView(true);
                        break;
                    case 6: 
                        this.MenuOptionView(true);
                        break;
                    case 7: 
                        this.MenuShutDownView(true);
                        break;
                    case 9: 
                        this.NupuMenuEnd_Cmn(); 
                        this.SetCmnEventSc(1789);
                        menuSyogoDataFlg = false;
                        Equip_ExitFlg = false;
                        this.Menu_Data_RentDeckMode_Exit();
                        SoundManager.playOk(); 
                        return;
                }
            }
            SoundManager.playOk(); 
        }
    }
    switch (ClickMenuNo) { 
        case 1: 
            this.MenuDataUpdate();
            break;
        case 2: 
            this.MenuItemUpdate();
            break;
        case 3: 
            this.MenuEquipUpdate();
            break;
        case 4: 
            this.MenuSaveUpdate();
            break;
        case 5: 
            this.MenuAddressUpdate();
            break;
        case 6: 
            this.MenuOptionUpdate();
            break;
        case 7: 
            this.MenuShutDownUpdate();
            break;
    }
    this.MenuMainTopBtnUpdate(); 
}
Game_Interpreter.prototype.MenuMainBtnDraw = function () {
    for (let i = 0; i <= 6; i++) {
        let zureY = 0;
        if (i == 6) zureY = 30 + 67;
        this.SetSprite(PNo_MBtn + i, MenuUIPath + "PNo_MBtn" + (i + 1) + "a",
            _M_BtnX, _M_BtnY + (67 * i) + zureY);
    }
    let cngPicStr = MenuUIPath + "PNo_MBtn" + ClickMenuNo + "b";
    let ckNo = ClickMenuNo - 1;
    this.CngSprite(PNo_MBtn + ckNo, cngPicStr);
    _zY = 0;
    if (ckNo == 6) _zY = 30 + 67;
    this.MoveSprite(PNo_MBtn + ckNo, 0, _M_BtnY + (67 * ckNo) + _zY, 10);
    if ($gameSwitches.value(SW_ルーザーズ敗北)) {
        this.DelSprite(PNo_MBtn + 1);
    }
}
Game_Interpreter.prototype.MenuMainTopBtnDraw = function () {
    this.SetSprite(PNo_MTBtn + 0, MenuUIPath + "MTBtn1", 342 + (242 * 0), 110);
    this.SetSprite(PNo_MTBtn + 1, MenuUIPath + "MTBtn2", 342 + (242 * 1), 110);
    this.SetSprite(PNo_MTBtn + 2, MenuUIPath + "MTBtn3", 342 + (242 * 2), 110);
    if (!$gameSwitches.value(SW_MenuDeckOff) || $gameSwitches.value(SW_ゴブリンパート)) {
        this.SetSprite(PNo_MTBtn + 1, MenuUIPath + "MTBtn2_d", 342 + (242 * 1), 110);
    }
    if ($gameSwitches.value(SW_MenuHStOff)) {
        this.SetSprite(PNo_MTBtn + 2, MenuUIPath + "MTBtn3_d", 342 + (242 * 2), 110);
    }
    switch (Menu_Main_Selecter) {
        case 0: 
            this.SetSprite(PNo_MTBtn + 0, MenuUIPath + "MTBtn1b", 342 + (242 * 0), 110);
            break;
        case 1: 
            break;
        case 2: 
            this.SetSprite(PNo_MTBtn + 2, MenuUIPath + "MTBtn3b", 342 + (242 * 2), 110);
            break;
    }
}
let _Menu_FstDeckFlg = false; 
let _Menu_FstHstFlg = false; 
let HMenuBtn_ViewFlg = true;
let TopBtnUpdate_SkipFlame = 0;
Game_Interpreter.prototype.MenuMainTopBtnUpdate = function () {
    if (_SaveWaitTimer > 0) return; 
    if (Input.isTriggered('menu') || TouchInput.isCancelled()) return; 
    if (TopBtnUpdate_SkipFlame > 0) {
        TopBtnUpdate_SkipFlame--;
        return;
    }
    if (Menu_Data_VirusMode) return;
    if (Menu_Data_RentDeckMode) return;
    this.ShutDownCk(); 
    let topBtnPicArr = [PNo_MTBtn + 0, PNo_MTBtn + 1, PNo_MTBtn + 2, PN_HStBtn, PNo_TelIcon];
    let overPicNo = overPointerSpCkArr(topBtnPicArr);
    this.SpriteCngColorArr(topBtnPicArr);
    if (_Menu_FstDeckFlg) {
        overPicNo = PNo_MTBtn + 1;
    }
    if (_Menu_FstHstFlg) {
        overPicNo = PNo_MTBtn + 2;
    }
    if (overPicNo != -1 && MenuCngOkFlg && !Item_BtlSelect_Flg) {
        if (!$gameSwitches.value(SW_MenuDeckOff) && overPicNo == PNo_MTBtn + 1) return;
        if ($gameSwitches.value(SW_MenuHStOff) && overPicNo == PNo_MTBtn + 2) return;
        this.SpriteCngColor(overPicNo, [100, 100, 100, 0]);
        if (TouchInput.isTriggered() || _Menu_FstDeckFlg || _Menu_FstHstFlg) { 
            SoundManager.playOk(); 
            switch (overPicNo) { 
                case PNo_MTBtn + 0:
                case PNo_MTBtn + 1:
                case PNo_MTBtn + 2:
                    MenuKeyFlame = 0;
                    SelectMenuNoL1 = -1; 
                    Menu_EditLayer = 1; 
            }
            switch (overPicNo) {
                case PNo_MTBtn + 0: 
                    if (Menu_Main_Selecter == 0) break; 
                    Menu_Main_Selecter = 0; 
                    ClickMenuNo = 1;        
                    SelectMenuNoL1 = 1;     
                    this.MenuDataView(true);    
                    break;
                case PNo_MTBtn + 1:         
                case PNo_TelIcon:
                    if ($gameSwitches.value(SW_ゴブリンパート)) return;
                    if (!$gameSwitches.value(SW_MenuDeckOff)) break;
                    if (Menu_Main_Selecter == 1) break; 
                    Menu_Main_Selecter = 1;
                    this.N_DE_Start();      
                    break;
                case PNo_MTBtn + 2:         
                case PN_HStBtn:
                    if (Input.isTriggered('menu') || TouchInput.isCancelled()) break; 
                    this.Layer1_DelPicture();
                    if (Menu_Main_Selecter == 2) break; 
                    Menu_Main_Selecter = 2; 
                    this.Menu_H_StartUp();  
                    ClickMenuNo = 0;        
                    SoundManager.playOk();  
                    break;
            }
            switch (overPicNo) { 
                case PNo_MTBtn + 0:
                case PNo_MTBtn + 1:
                case PNo_MTBtn + 2:
                    this.MenuMainTopBtnDraw();
            }
        }
    }
}
let Menu_Hint_Mode = 0;
Game_Interpreter.prototype.HintView = function (_SetFlg) {
    _SetFlg = typeof _SetFlg !== 'undefined' ? _SetFlg : false;
    let _SetOpi = 255;
    if (_SetFlg) {
        _SetOpi = 0;
    }
    ViewSpriteArr_Reset();
}
Game_Interpreter.prototype.HintUpdate = function () {
}
let _SDownTimer = 0;
let _SDownCancel = false;
let _SDownDelPic = [PN_SDBack, PN_SDYes, PN_SDNo, PN_SDWaku, PN_SDGage];
Game_Interpreter.prototype.MenuShutDownView = function (_SetFlg) {
    MenuCngOkFlg = false; 
    this.Layer1_DelTop(); 
    this.SetSprite(PN_SDBack, MenuUIPath + "ShutDown/TitleBack", 0, 0, 1);
    this.SetSpriteC(PN_SDYes, MenuUIPath + "ShutDown/TitleBack_Yesa", 506, 446, 1);
    this.SetSpriteC(PN_SDNo, MenuUIPath + "ShutDown/TitleBack_Noa", 804, 446, 1);
    _SDownTimer = 0;
    _SDownCancel = false;
    for (let i = 0; i <= ViewSpriteArr.length - 1; i++) {
        this.MoveSprite(ViewSpriteArr[i], true, true, 10, 255, true, true);
    }
}
Game_Interpreter.prototype.MenuShutDownUpdate = function () {
    let overPicNo = overPointerSpCkArr([PN_SDYes, PN_SDNo]);
    switch (overPicNo) {
        case PN_SDYes:
            this.SetSpriteC(PN_SDYes, MenuUIPath + "ShutDown/TitleBack_Yesb", 506, 446);
            this.SetSpriteC(PN_SDNo, MenuUIPath + "ShutDown/TitleBack_Noa", 804, 446);
            break;
        case PN_SDNo:
            this.SetSpriteC(PN_SDYes, MenuUIPath + "ShutDown/TitleBack_Yesa", 506, 446);
            this.SetSpriteC(PN_SDNo, MenuUIPath + "ShutDown/TitleBack_Nob", 804, 446);
            break;
    }
    if (TouchInput.isTriggered() || TouchInput.isRepeated()) { 
        switch (overPicNo) {
            case PN_SDYes:
                _SDownTimer = 1;
                break;
            case PN_SDNo:
                ClickMenuNo = _Bef_ClickNo;
                this.MenuMainBtnDraw();
                _SDownCancel = true;
                _SDownTimer = 0;
                MenuCngOkFlg = true; 
                break;
        }
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled()) {
        MenuCngOkFlg = true; 
    }
    if (_SDownTimer > 0) {
        MenuCngOkFlg = true; 
        this.SetSprite(PN_SDWaku, MenuUIPath + "ShutDown/Pic_SDWaku", 454, 483);
        this.SetSprite(PN_SDGage, MenuUIPath + "ShutDown/Pic_SDGage", 457, 485, 255, _SDownTimer);
        _SDownTimer++;
        if (_SDownTimer == 100) {
            GameResetFlame = 1;
        }
    }
}
Game_Interpreter.prototype.ShutDownCk = function () {
    if (_SDownCancel) {
        MenuKeyFlame = 0;
        this.DelSpriteArr(_SDownDelPic); 
        this.MenuMainTopBtnDraw(); 
        _SDownCancel = false;
    }
}
let Menu_EditLayer = 1; 
Game_Interpreter.prototype.Layer1_DelBtm = function (_No) { 
    _No = typeof _No !== 'undefined' ? _No : 36;
    for (let i = _No; i <= 120; i++) this.DelPict(i); 
    for (let i = _No; i <= 120; i++) this.DelSprite(i); 
}
Game_Interpreter.prototype.Layer1_DelTop = function (_No) { 
    _No = typeof _No !== 'undefined' ? _No : 135;
    for (let i = _No; i <= 180; i++) {
        this.DelPict(i);
        this.DelSprite(i); 
    }
}
Game_Interpreter.prototype.Layer1_DelPicture = function (_BtmNo , _TopNo) { 
    this.Layer1_DelBtm(_BtmNo);
    this.Layer1_DelTop(_TopNo);
    this.MoveSprite(PN_HBase);
}
Game_Interpreter.prototype.Layer1_Update = function () {
    if (MenuKeyFlame == 0) { 
        this.MenuMainTopBtnDraw();
        let _CkOverArr = [];
        for (let i = 0; i <= 7; i++) {
            if ($gameSwitches.value(SW_MenuSaveOff) && i == 3) continue;
            this.SpriteCngColor(PNo_MBtn + i);
            _CkOverArr.push(PNo_MBtn + i);
        }
        let _OverNo = overPointerSpCkArr(_CkOverArr);
        if (_OverNo != -1) { 
            this.SpriteCngColor(_OverNo, [100, 100, 100, 0])
        }
    }
}
Game_Interpreter.prototype.Layer1_MoveKey = function () {
    let KeyFlg = false;
    if (Input.isTriggered('up')) {
        MenuKeyFlame = 0;
        SelectMenuNoL1--;
    } else if (Input.isTriggered('left')) {
        MenuKeyFlame = 0;
        SelectMenuNoL1--;
    } else if (Input.isTriggered('right')) {
        MenuKeyFlame = 0;
        SelectMenuNoL1++;
    } else if (Input.isTriggered('down')) {
        MenuKeyFlame = 0;
        SelectMenuNoL1++;
    }
    if (SelectMenuNoL1 < 1) {
        SelectMenuNoL1 = 8;
    } 
    if (SelectMenuNoL1 > 8) {
        SelectMenuNoL1 = 1;
    } 
}
Game_Interpreter.prototype.Layer1_okkey = function () {
    switch (SelectMenuNoL1) {
    }
}
let N_LoadSuccessFlg = false; 
let _Live2DLoadFlame = 0;
let romatalk_LoadFlg = false;
let romatalk_IdlMtn = "";
Game_Interpreter.prototype.N_Start_Live2DSet = function () {
    romatalk_LoadFlg = true;
}
N_LoadingCanMove = Game_Player.prototype.canMove;
Game_Player.prototype.canMove = function() {
    if (_Live2DLoadFlame > 0) return false;
    return N_LoadingCanMove.call(this);
};
let b初期キャラ更新スキップFlg = false;
const CN_スピナモードロード時処理 = 1448;
const SW_スピナ操作モード = 19;
let LoadingFrame = 0; 
const LoadingIconRollFrame = 120; 
let Loop200Flg = false;
let CN_5章_着替えメニュー開き = 366;
let FirstMdlLoadViewFlg = false;
let Nupu_MenuUpdate = Game_Interpreter.prototype.NUpdate;
Game_Interpreter.prototype.NUpdate = function () {
    function getRandomElementFromArray(array) {
        const randomIndex = Math.floor(Math.random() * array.length);
        return array[randomIndex];
    }
    if (N_LoadSuccessFlg) { 
        this.NupuLoadPicDel();
        this.SetCmnEventSc(CN_着替え後);
        N_LoadSuccessFlg = false;
        b初期キャラ更新スキップFlg = true;
        SSkipLoadCmp_Func();
        _Live2DLoadFlame = 5;
        romatalk_LoadFlg = false;
        for (let i = 0; i <= $gameSystem.Live2D_ViewSave.length - 1; i++) {
            if ($gameSystem.Live2D_ViewSave[i]._MdlName == "romasha_talk") {
                romatalk_LoadFlg = true;
                romatalk_IdlMtn = $gameSystem.Live2D_ViewSave[i]._IdlMtn;
            }
        }
        this.SetSprite(PN_LoadSucTop , "PN_LoadSucTop" , 0 , 0 );
        this.SetSprite(PN_LoadSucGage , "PN_LoadSucGage" , 640 , 427 , 255 , 0 );
        //this.MoveSprite(PN_LoadSucGage , true , true , _Live2DLoadFlame - 30 , true , 90);
        if (!NotRomaLoading) {
            this.PlaySpriteAnime(PN_RomaLoading , "PN_RomaLoading" , 20 , 5, 1290 , 672);
        }
        AbmNoArr_Get(); 
        let ckData = getRandomElementFromArray(dataWeapons_AbmNo);
        while (ckData.id > 660 || ckData.id < 500) {
            ckData = getRandomElementFromArray(dataWeapons_AbmNo)
        }
        this.SpriteStrC(PN_LoadMiniGame , " \\I[" + ckData.iconIndex + "] " ,
            24 , 727 , 344 , 255 , 0 , 200);
        EasingStr = "easeInOutQuad";
        this.MoveSprite(PN_LoadMiniGame , true , true , LoadingIconRollFrame , 255 , 200 , 200);
        EasingStr = "";
        Loop200Flg = true;
    }
    if (_Live2DLoadFlame > 0) {
        LoadingFrame++;
        if (LoadingFrame % LoadingIconRollFrame == 0) {
            let mxSize = 200;
            if (Loop200Flg) {
                mxSize = 0;
                EasingStr = "easeInQuad";
            }
            else {
                EasingStr = "easeInOutQuad";
                let ckData = getRandomElementFromArray(dataWeapons_AbmNo);
                while (ckData.id > 660 || ckData.id < 500) {
                    ckData = getRandomElementFromArray(dataWeapons_AbmNo)
                }
                this.SpriteStrC(PN_LoadMiniGame , " \\I[" + ckData.iconIndex + "] " ,
                    24 , 727 , 344 , 255 , 0 , 200);
            }
            Loop200Flg = !Loop200Flg;
            this.MoveSprite(PN_LoadMiniGame , true , true , LoadingIconRollFrame , 255 , mxSize , 200);
            EasingStr = "";
        }
        if (Live2DSubCounter < subLoadMdlSetting.length) _Live2DLoadFlame++;
        if (_Live2DLoadFlame == 4) {
            Live2D_Load(); 
        }
        this.SetSprite(PN_LoadSucGage , "PN_LoadSucGage" , 640 , 427 , 255 ,
            Live2DSubCounter/ subLoadMdlSetting.length * 100);
        D_Text_Cng_font = "Makinas";
        let viewPar = Math.round(Live2DSubCounter/ subLoadMdlSetting.length * 100) ;
        this.SpriteStrC( PN_RomaLoadText , "Live2Dロード中（" + viewPar + "％）" ,
            17 , 734 , 452);
        D_Text_Cng_font = "";
        if ($gameSwitches.value(SW_スピナ操作モード)) {
            romatalk_LoadFlg = false;
            L2dAutoFadeOut("romasha_talk", 1);
        }
        if (romatalk_LoadFlg) {
            let _ckdata = Game_Live2D.live2dData()[Game_Live2D.fullName("romasha_talk")];
            if (!_ckdata) return;
            if (_Live2DLoadFlame == 3) {
                L2dAutoFadeOut("romasha_talk", 0);
                this.SetCmnEventSc(CN_romasha_talk);
            }
            if (_Live2DLoadFlame == 2) {
                L2dFadeMdl("romasha_talk", "rightin", 0, "");
            }
            if (_Live2DLoadFlame == 1 && romatalk_IdlMtn != "") {
                if (L2D_MotionIndexGet("romasha_talk" , romatalk_IdlMtn) != -1) {
                    L2dIdleStart("romasha_talk", romatalk_IdlMtn)
                    this.SetCmnEventSc(CN_5章_着替えメニュー開き);
                } else {
                    _Live2DLoadFlame++;
                }
            }
        } else {
            let _ckdata = Game_Live2D.live2dData()[Game_Live2D.fullName("romasha_talk")];
            if (!_ckdata) return;
            if (!FirstMdlLoadViewFlg) {
                this.SetCmnEventSc(CN_スピナモードロード時処理);
                FirstMdlLoadViewFlg = true;
            }
        }
        if (_Live2DLoadFlame == 1) {
            this.MoveSprite(PN_LoadSucTop , true,true,10 , 0);
            this.MoveSprite(PN_LoadSucGage , true,true,10 , 0);
            this.MoveSprite(PN_RomaLoading , true,true,10 , 0);
            this.MoveSprite(PN_RomaLoadText , true,true,10 , 0);
            this.MoveSprite(PN_LoadMiniGame , true,true,10 , 0);
        }
        _Live2DLoadFlame--;
    }
    Nupu_MenuUpdate.call(this);
    if (CGet_ViewFlg()) {
    } else {
        if (MenuFlgSwich) {
            if (MenuFlame == 0) {
                this.NupuMenuStart(); 
            }
            this.MenuBaseUpdate(); 
        } else {
            if (MeneExitOkFlg) { 
                MenuFlgSwich = false;
                this.MenuEnd();
                MeneExitOkFlg = false; 
            }
        }
    }
};
let Menu禁止Flg = false;  
let Menu禁止Flame = 0;    
let MenuFlgSwich = false; 
let Menu_RclickStopFlg = false; 
let Menu_RclickStopFlame = 0;
let Menu強制OpenFlg = false;
let Menu着替え実行Flg = false;
(function () {
    Scene_Map.prototype.isMenuCalled = function () {
        if (Menu_RclickStopFlame > 0) {
            Menu_RclickStopFlame--;
            return;
        }
        if ($gamePlayer.isMoveRouteForcing()) return; 
        if (_SaveWaitTimer > 0) return;
        if (Tutorial_Flg) return;
        if (_アルバムFlg) return;
        if (Equip_ExitFlg) return;
        if (battleflg || RD_Flg || fuzokuFlg) return false; 
        if (Menu禁止Flg) return false;
        if (Menu禁止Flame > 0) {
            Menu禁止Flame--;
            return false;
        }
        if (_Live2DLoadFlame > 0) return false; 
        if (Item_BtlSelect_Flg) return false;
        if (MenuKnsOffCk()) return false; 
        let _MenuOpenScFlg = false;
        if (!MenuFlgSwich) {
            if (overPointerSpCk(PNo_MailIcon) && TouchInput.isTriggered()) {
                menuDataFlame = 0;
                MenuOpenNo = ClickMenuNo = 5;
                _MenuOpenScFlg = true;
            }
            if (overPointerSpCk(PNo_TelIcon) && TouchInput.isTriggered()) {
                menuDataFlame = 0;
                _Menu_FstDeckFlg = true;
                _MenuOpenScFlg = true;
            }
            if (overPointerSpCk(PN_HStBtn) && TouchInput.isTriggered()) {
                menuDataFlame = 0;
                _Menu_FstHstFlg = true;
                _MenuOpenScFlg = true;
            }
        }
        if (Input.isTriggered('menu') || TouchInput.isCancelled() || _MenuOpenScFlg || Menu強制OpenFlg) {
            _Reset_AnalogMove(); 
            Menu強制OpenFlg = false;
            if (MenuStopFlg) return; 
            if (CGet_ViewFlg()) return false; 
            if ($gameSystem.isMenuEnabled()) { 
                if (Menu_Main_Selecter != 1 && !Menu_RclickStopFlg) {
                    SoundManager.playCancel(); 
                }
                if (MenuFlame == 0) {
                    MenuFlgSwich = true;
                    L2dSetMotion("romasha_talk", "device");
                    $gameTemp.reserveCommonEvent(CN_L2DIdlSet);
                }
            } else {
                $gameTemp.reserveCommonEvent(CN_MenuStpCmn);
            }
            if (MeneExitOkFlg && !Menu_RclickStopFlg) { 
                if (Menu_EditLayer <= 1) {
                    if (ClickMenuNo != 8) {
                        MenuFlgSwich = false;
                        Menu_Main_Selecter = 0; 
                    } else {
                        _SDownCancel = true;
                        _SDownTimer = 0;
                        ClickMenuNo = _Bef_ClickNo;
                    }
                } else {
                    Menu_EditLayer--;
                }
            }
        }
        return false; 
    };
    Scene_Base.prototype.checkGameover = function () {
        if ($gameParty.isAllDead()) {
            //SceneManager.goto(Scene_Gameover);
            //$gameScreen.startFadeOut(30); //フェードアウトするぜ
            //$gameSwitches.setValue(switchId, true); //全滅したぜ
            //$gameParty.reviveBattleMembers(); //みんな生き返るぜ
        }
    };
})();
let Nupu_Game_Player_triggerAction = Game_Player.prototype.triggerAction;
Game_Player.prototype.triggerAction = function () {
    if (!MenuFlgSwich) { 
        Nupu_Game_Player_triggerAction.call(this);
    }
    return false;
};
let Nupu_MapPLUpdate = PlayerMover.prototype.update;
PlayerMover.prototype.update = function () {
    Nupu_MapPLUpdate.call(this);
    if (MenuFlgSwich) {
        this.clearTargetPosition(); 
        $gameTemp.clearDestination();
    }
}
let ClickCkFlg = false; 
let ClickCk_BtnArr = [];
let _ClickCk_flame = 0;
Game_Interpreter.prototype.ClickCk_WinView = function (_DrawTxtArr, _WinNo) {
    _WinNo = typeof _WinNo !== 'undefined' ? _WinNo : 0;
    _ClickCk_flame = 0;
    ClickCk_BtnArr = [];
    this.SetPictFIn(PN_ClickCk_Back, "Black", 0, 0, 0, 0, 15, 150);
    let _SetImg = MenuUIPath + "PN_ClickCk";
    if (_WinNo != 0) {
        _SetImg += "_" + _WinNo;
    }
    switch (_WinNo) {
        case 0:
            this.SetPictFIn(PN_ClickCk_Yes, MenuUIPath + "PN_ClickCk_Yesa", 432, 420, 0, 0, 15);
            this.SetPictFIn(PN_ClickCk_No, MenuUIPath + "PN_ClickCk_Noa", 432 + 310, 420, 0, 0, 15);
            ClickCk_BtnArr = [PN_ClickCk_Yes, PN_ClickCk_No];
            break;
        case 1:
            break;
    }
    this.SetPictFInC(PN_ClickCk, _SetImg, 720, 405, 0, 0, 15);
    if (_DrawTxtArr.length == 1) {
        this.SetPicStrC(PN_ClickCk_Txt, _DrawTxtArr[0], 38, 672, 338, 0);
        this.MovePict(PN_ClickCk_Txt, true, true, 10);
    }
    if (_DrawTxtArr.length == 2) {
        this.SetPicStrC(PN_ClickCk_Txt + 0, _DrawTxtArr[0], 38, 672, 314, 0);
        this.SetPicStrC(PN_ClickCk_Txt + 1, _DrawTxtArr[1], 38, 672, 314 + 60, 0);
        this.MovePict(PN_ClickCk_Txt + 0, true, true, 10);
        this.MovePict(PN_ClickCk_Txt + 1, true, true, 10);
    }
    ClickCkFlg = true;
}
Game_Interpreter.prototype.ClickCk_Update = function () {
    _ClickCk_flame++;
    if (_ClickCk_flame < 16) return -1;
    this.CngPict(PN_ClickCk_Yes, MenuUIPath + "PN_ClickCk_Yesa");
    this.CngPict(PN_ClickCk_No, MenuUIPath + "PN_ClickCk_Noa");
    let _CNo = overPointerCkArr(ClickCk_BtnArr);
    if (_CNo != -1) {
        switch (_CNo) {
            case PN_ClickCk_Yes:
                this.CngPict(PN_ClickCk_Yes, MenuUIPath + "PN_ClickCk_Yesb");
                if (TouchInput.isTriggered()) {
                    SoundManager.playOk();
                    return PN_ClickCk_Yes;
                }
                break;
            case PN_ClickCk_No:
                this.CngPict(PN_ClickCk_No, MenuUIPath + "PN_ClickCk_Nob");
                if (TouchInput.isTriggered()) {
                    SoundManager.playOk();
                    return PN_ClickCk_No;
                }
                break;
        }
    }
    return -1; 
}
Game_Interpreter.prototype.ClickCk_WinDel = function () {
    this.DelPictSpan(PN_ClickCk_Back, PN_ClickCk_No);
    ClickCkFlg = false;
}
