let _OPBasePs = new Pos2D(370 - 129 , 505 + 20); 
let _OPFpsSPs = new Pos2D(_OPBasePs._x + 384 , _OPBasePs._y + 46); 
let _OPLive2DPs = new Pos2D(_OPBasePs._x + 384 , _OPBasePs._y + 46 + 62); 
let _OPFpsSPs_CB = [
    [384,46,140,42],
    [384 + 148,46,140,42]
];
let _OPLive2DPs_CB = [
    [384,46 + 62,140,42],
    [384 + 148,46 + 62,140,42]
];
let _OPTitleFlg = false;
let NMenu_SaveVar = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () { 
    NMenu_SaveVar.call(this);
    this._Live2DLightFlg = false;   
};
Game_Interpreter.prototype.MenuOptionView = function (_SetFlg) {
    _SetFlg = typeof _SetFlg !== 'undefined' ? _SetFlg : false;
    ViewSpriteArr_Reset();
    let _SetOpi = 255;
    if (_SetFlg) {
        _SetOpi = 0;
    }
    let _MasVol = $gameVariables.value(MasterVolVarNo);
    let _BGMVol = ConfigManager['bgmVolume'];
    let _SEMVol = ConfigManager['seVolume'];
    let _VoiceVol = $gameVariables.value(VoiceVolVarNo);
    this.SetSprite(PNo_OBase, MenuUIPath + "Option/M_OBack", 249 + Save_ZureX, 224 + Save_ZureY, _SetOpi);
    this.SetSprite(PNo_OBarPic + 0, MenuUIPath + "Option/M_OBar1", 478 + Save_ZureX, 237 + Save_ZureY + (59 * 0), _SetOpi, Math.floor(_MasVol), 100);
    this.SetSprite(PNo_OBarPic + 1, MenuUIPath + "Option/M_OBar2", 478 + Save_ZureX, 237 + Save_ZureY + (59 * 1), _SetOpi, Math.floor(_BGMVol), 100);
    this.SetSprite(PNo_OBarPic + 2, MenuUIPath + "Option/M_OBar3", 478 + Save_ZureX, 237 + Save_ZureY + (59 * 2), _SetOpi, Math.floor(_SEMVol), 100);
    this.SetSprite(PNo_OBarPic + 3, MenuUIPath + "Option/M_OBar4", 478 + Save_ZureX, 237 + Save_ZureY + (59 * 3), _SetOpi, Math.floor(_VoiceVol), 100);
    this.SetSprite(PNo_OBarHit + 0, MenuUIPath + "Option/M_OBar1", 478 + Save_ZureX, 237 + Save_ZureY + (59 * 0) - 10, 1 , 100 , 200);
    this.SetSprite(PNo_OBarHit + 1, MenuUIPath + "Option/M_OBar2", 478 + Save_ZureX, 237 + Save_ZureY + (59 * 1) - 10, 1 , 100 , 200);
    this.SetSprite(PNo_OBarHit + 2, MenuUIPath + "Option/M_OBar3", 478 + Save_ZureX, 237 + Save_ZureY + (59 * 2) - 10, 1 , 100 , 200);
    this.SetSprite(PNo_OBarHit + 3, MenuUIPath + "Option/M_OBar4", 478 + Save_ZureX, 237 + Save_ZureY + (59 * 3) - 10, 1 , 100 , 200);
    let BarWidth = 414; 
    let SxPos = 0; 
    SxPos = Math.floor(BarWidth * (_MasVol / 100));
    this.SetSpriteC(PNo_OPosP + 0, MenuUIPath + "Option/M_OPoint", 478 + Save_ZureX + SxPos, 244 + Save_ZureY + (59 * 0), _SetOpi);
    SxPos = Math.floor(BarWidth * (_BGMVol / 100));
    this.SetSpriteC(PNo_OPosP + 1, MenuUIPath + "Option/M_OPoint", 478 + Save_ZureX + SxPos, 244 + Save_ZureY + (59 * 1), _SetOpi);
    SxPos = Math.floor(BarWidth * (_SEMVol / 100));
    this.SetSpriteC(PNo_OPosP + 2, MenuUIPath + "Option/M_OPoint", 478 + Save_ZureX + SxPos, 244 + Save_ZureY + (59 * 2), _SetOpi);
    SxPos = Math.floor(BarWidth * (_VoiceVol / 100));
    this.SetSpriteC(PNo_OPosP + 3, MenuUIPath + "Option/M_OPoint", 478 + Save_ZureX + SxPos, 244 + Save_ZureY + (59 * 3), _SetOpi);
    this.SetSprite(PNo_OBtn, MenuUIPath + "Option/M_OSyokiBtn", 464 + Save_ZureX, 520 + Save_ZureY - 59, _SetOpi); 
    this.SetSprite(PNo_OBase_Mute, MenuUIPath + "Option/PNo_OBase_Mute", 249 + Save_ZureX, 224 + Save_ZureY, _SetOpi); 
    this.SetSprite(PN_OPBase , MenuUIPath + "Option/PN_OPBase" , _OPBasePs._x + Save_ZureX , _OPBasePs._y + Save_ZureY, _SetOpi);
    this.MoveSprite(PN_OPBase, true, true, 10);
    if ($gameSwitches.value(DownFpsSwt)) {
        this.SetSprite(PN_OPFpsS, MenuUIPath + "Option/M_OfpsSelecter", _OPFpsSPs._x + Save_ZureX, _OPFpsSPs._y + Save_ZureY, _SetOpi);
    } else {
        this.SetSprite(PN_OPFpsS, MenuUIPath + "Option/M_OfpsSelecter", _OPFpsSPs._x + Save_ZureX + 148, _OPFpsSPs._y + Save_ZureY, _SetOpi);
    }
    this.MoveSprite(PN_OPFpsS, true, true, 10);
    // if ($gameSwitches.value(SW_Live2DLight)) {
    //     this.SetSprite(PN_OPLive2D, MenuUIPath + "Option/M_OfpsSelecter", _OPLive2DPs._x + Save_ZureX, _OPLive2DPs._y + Save_ZureY, _SetOpi);
    //     this.SetSprite(PN_OPLive2D, MenuUIPath + "Option/M_OfpsSelecter", _OPLive2DPs._x + Save_ZureX + 148, _OPLive2DPs._y + Save_ZureY, _SetOpi);
    // this.MoveSprite(PN_OPLive2D, true, true, 10);
    _OPTitleFlg = (Save_ZureY == -39);
    if (!_OPTitleFlg) { 
        this.SetSprite(PN_OPTtlOnlyImg, MenuUIPath + "Option/PN_OPTtlOnlyImg",
            _OPBasePs._x + Save_ZureX  + 380 ,_OPFpsSPs._y + Save_ZureY + 50);
    }
    for (let i = 0; i <= ViewSpriteArr.length - 1; i++) {
        switch (ViewSpriteArr[i]){
            case PNo_OBarHit + 0:
            case PNo_OBarHit + 1:
            case PNo_OBarHit + 2:
            case PNo_OBarHit + 3:
                this.MoveSprite(ViewSpriteArr[i], true, true, 10, 1, true, true);
                break;
            default:
                this.MoveSprite(ViewSpriteArr[i], true, true, 10, 255, true, true);
        }
    }
};
Game_Interpreter.prototype.MasterVolSet = function (_SetVar) {
    $gameVariables.setValue(MasterVolVarNo, _SetVar); 
    this.UTA_Save(); 
    AudioManager.masterVolume = Math.floor($gameVariables.value(MasterVolVarNo)) / 100;
}
Game_Interpreter.prototype.BGMVolSet = function (_SetVar) {
    ConfigManager['bgmVolume'] = _SetVar;
    ConfigManager['meVolume'] = _SetVar;
    ConfigManager.save(); 
}
Game_Interpreter.prototype.SEVolSet = function (_SetVar) {
    ConfigManager['seVolume'] = _SetVar;
    ConfigManager['bgsVolume'] = _SetVar;
    SoundManager.playOk();
    ConfigManager.save(); 
}
Game_Interpreter.prototype.VoiceVolSet = function (_SetVar) {
    $gameVariables.setValue(VoiceVolVarNo, _SetVar); 
    VoiceVol = $gameVariables.value(VoiceVolVarNo);
    this.UTA_Save(); 
}
Game_Interpreter.prototype.MenuOptionUpdate = function () {
    let _OverPicNoArr = [PNo_OBarHit + 0, PNo_OBarHit + 1,
        PNo_OBarHit + 2, PNo_OBarHit + 3, PNo_OBtn];
    let _OverPicNo = overPointerSpCkArr(_OverPicNoArr);
    if(_OverPicNo != -1) {
        if (TouchInput.isTriggered() || TouchInput.isRepeated()) { 
            let _BarPosX = TouchInput.mouseX - Save_ZureX - 478;
            let _SetVar = Math.floor((_BarPosX / 414) * 100);
            if(_SetVar < 2) _SetVar = 0;
            if(_SetVar > 98) _SetVar = 100;
            switch (_OverPicNo){
                case PNo_OBarHit + 0: 
                    this.MasterVolSet(_SetVar);
                    this.MenuOptionView();
                    break;
                case PNo_OBarHit + 1: 
                    this.BGMVolSet(_SetVar);
                    this.MenuOptionView();
                    break;
                case PNo_OBarHit + 2: 
                    this.SEVolSet(_SetVar);
                    this.PlaySe("zb_GetSup");
                    this.MenuOptionView();
                    break;
                case PNo_OBarHit + 3: 
                    this.VoiceVolSet(_SetVar);
                    let _RandNo = Math.floor(Math.random() * 5);
                    if (_RandNo == 0) this.PVoice("romasha","_p1_7_kansy");
                    if (_RandNo == 1) this.PVoice("romasha","_p1_10_yatta");
                    if (_RandNo == 2) this.PVoice("romasha","_p1_12_kora");
                    if (_RandNo == 3) this.PVoice("romasha","_p1_15_yann");
                    if (_RandNo == 4) this.PVoice("romasha","_p1_17_mou");
                    this.MenuOptionView();
                    break;
                case PNo_OBtn: 
                    SoundManager.playOk();
                    _SetVar = 30;
                    this.MasterVolSet(30);
                    this.BGMVolSet(_SetVar);
                    this.SEVolSet(_SetVar);
                    this.VoiceVolSet(_SetVar);
                    this.MenuOptionView();
                    break;
            }
        }
    }
    let _CkNo = overSpriteClickable( PN_OPBase , _OPFpsSPs_CB);
    if (_CkNo != -1) {
        if (TouchInput.isTriggered()){
            $gameSwitches.setValue(DownFpsSwt , _CkNo == 0);
            this.MoveSprite(PN_OPFpsS , _OPFpsSPs._x + Save_ZureX + (148 * _CkNo) , _OPFpsSPs._y + Save_ZureY , 3);
            this.UTA_Save();
        }
    }
    _CkNo = overSpriteClickable( PN_OPBase , _OPLive2DPs_CB);
    if(_CkNo != -1 && _OPTitleFlg) {
        if (TouchInput.isTriggered()){
            $gameSwitches.setValue(SW_Live2DLight , _CkNo == 0);
            this.MoveSprite(PN_OPLive2D , _OPLive2DPs._x + Save_ZureX + (148 * _CkNo) , _OPLive2DPs._y + Save_ZureY , 3);
            this.UTA_Save();
        }
    }
    this.SpriteCngColor(PNo_OPosP + 0); 
    this.SpriteCngColor(PNo_OPosP + 1); 
    this.SpriteCngColor(PNo_OPosP + 2); 
    this.SpriteCngColor(PNo_OPosP + 3); 
    this.SpriteCngColor(PNo_OBtn); 
    switch (_OverPicNo) {
        case PNo_OBarHit + 0:
            this.SpriteCngColor(PNo_OPosP + 0, [100, 100, 100, 0]);
            break;
        case PNo_OBarHit + 1:
            this.SpriteCngColor(PNo_OPosP + 1, [100, 100, 100, 0]);
            break;
        case PNo_OBarHit + 2:
            this.SpriteCngColor(PNo_OPosP + 2, [100, 100, 100, 0]);
            break;
        case PNo_OBarHit + 3:
            this.SpriteCngColor(PNo_OPosP + 3, [100, 100, 100, 0]);
            break;
        case PNo_OBtn:
            this.SpriteCngColor(PNo_OBtn, [100, 100, 100, 0]);
            break;
    }
    this.SpriteCngColor(PNo_OBase_Mute); 
    if (overPointerSpCkTm(PNo_OBase_Mute)) {
        this.SpriteCngColor(PNo_OBase_Mute, [100, 100, 100, 0]);
        if (TouchInput.isTriggered()){
            this.VoiceVolSet(0);
            this.MenuOptionView();
        }
    }
}
