const PN_OsBack_Black = 145;
const PN_OsBack = 331;
const PN_OsRBtn_SelH = PN_OsBack + 3;
const PN_OsRBtn = PN_OsRBtn_SelH + 1;
const PN_OsLBtn_SelH = PN_OsRBtn + 7;
const PN_OsLBtn = PN_OsLBtn_SelH + 1;
const PN_OsEndBtn = PN_OsLBtn + 7;
const PN_VolBar = PN_OsEndBtn + 1;
const PN_VolTumami = PN_VolBar + 3;
const PN_VolTxt = PN_VolTumami + 3;
const CN_Osioki = 101;
const CN_Osioki_End = 108;
const SW_Osioki_Inran_Use = 84;
let _OsiokiModeFlg = false;
let Osioki_BtnArr = [];
let Osioki_BtnArr_0 = [];
let Osioki_BtnArr_1 = [];
let Osioki_BtnArr_2 = [];
let Osioki_BtnArr_Sw = [];
let Osioki_BtnPic = [];
let _Osioki_Sel屈服 = 0;
let _Osioki_Sel動き = 0;
let BefOsioki_終了Flg = false;
let Osioki_終了Flg = false;
let _Osioki_VNVar = VN_奴隷_屈服度;
const OsiokiBarPosY = 560;
const OsiokiPic = "pictures/Adv_Dorei/Osioki/";
Game_Interpreter.prototype.Adv_Osioki_View = function () {
    _Osioki終了Select = false;
    this.SetPictFIn(PN_OsBack_Black, "Black", 0, 0, 0, 0, 15);
    if ($gameSwitches.value(SW_Osioki_Inran_Use)) {
        this.SetPictFIn(PN_OsBack, OsiokiPic + "PN_OsBack_2", 0, 0, 0, 0, 15);
        _Osioki_VNVar = VN_淫乱度;
    } else {
        this.SetPictFIn(PN_OsBack, OsiokiPic + "PN_OsBack", 0, 0, 0, 0, 15);
        _Osioki_VNlet = VN_奴隷_屈服度;
    }
    _Osioki_Sel屈服 = 0;
    _Osioki_Sel動き = 0;
    if ($gameVariables.value(_Osioki_VNVar) >= 50) _Osioki_Sel屈服 = 1;
    if ($gameVariables.value(_Osioki_VNVar) >= 100) _Osioki_Sel屈服 = 2;
    for (let i = 0; i <= 3 - 1; i++) {
        let _opi = 150;
        if (_Osioki_Sel屈服 == i) {
            switch (i) {
                case 0:
                    Osioki_BtnArr = Osioki_BtnArr_0.slice();
                    break;
                case 1:
                    Osioki_BtnArr = Osioki_BtnArr_1.slice();
                    break;
                case 2:
                    Osioki_BtnArr = Osioki_BtnArr_2.slice();
                    break;
            }
            _opi = 255;
            this.SetPictFInC(PN_OsRBtn_SelH, OsiokiPic + "PN_OsRBtn_SelH", 1350, 185 + (103 * i), 0, 0, 15, _opi);
        }
        this.SetPictFInC(PN_OsRBtn + i, OsiokiPic + "PN_OsRBtn_" + i, 1350, 185 + (103 * i), 0, 0, 15, _opi);
    }
    Osioki_BtnPic = [];
    for (let i = 0; i <= Osioki_BtnArr.length - 1; i++) {
        if (i == _Osioki_Sel動き) {
            this.SetPictFIn(PN_OsLBtn_SelH, OsiokiPic + "PN_OsLBtn_SelH", 0, 148 + (76 * i) - 17, 0, 0, 15);
        }
        this.SetPictFIn(PN_OsLBtn + i, OsiokiPic + Osioki_BtnArr[i], 0, 148 + (76 * i), 0, 0, 15);
        Osioki_BtnPic.push(PN_OsLBtn + i);
    }
    BefOsioki_終了Flg = false;
    Osioki_終了Flg = false;
    this.SetPictFInC(PN_OsEndBtn, OsiokiPic + "PN_OsEndBtn", 90, 757, 0, 0, 15, 150);
    for (let i = 0; i <= 3 - 1; i++) {
        let _VarPar = 0;
        switch (i) {
            case 0:
                _VarPar = ConfigManager['bgmVolume'];
                break;
            case 1:
                _VarPar = ConfigManager['seVolume'];
                break;
            case 2:
                _VarPar = $gameVariables.value(VoiceVolVarNo);
                break;
        }
        this.SetPictFIn(PN_VolBar + i, OsiokiPic + "PN_VolBar", 1276, OsiokiBarPosY + 60 * i, 0, 0, 15, 255, _VarPar);
        this.SetPictFIn(PN_VolTumami + i, OsiokiPic + "PN_VolTumami", 1274 + (150 * (_VarPar / 100)), OsiokiBarPosY - 3 + (60 * i), 0, 0, 15);
        this.SetPicStrC(PN_VolTxt + i, _VarPar, 20, 1357, OsiokiBarPosY - 21 + (60 * i), 0);
        this.MovePict(PN_VolTxt + i, 1357, OsiokiBarPosY - 21 + (60 * i), 15);
    }
}
let _OsiokiVolArr = [
    [1275, 628 - 69 + 60 * 0, 150, 16],
    [1275, 628 - 69 + 60 * 1, 150, 16],
    [1275, 628 - 69 + 60 * 2, 150, 16]
]
let _Osioki終了Select = false;
Game_Interpreter.prototype.Adv_Osioki = function () {
    this.PicCngColorArr(Osioki_BtnPic);
    let _CNo = overPointerCkArr(Osioki_BtnPic);
    if (_CNo != -1) {
        this.PicCngColor(_CNo, [100, 100, 100, 0]);
        _Osioki_Sel動き = _CNo - PN_OsLBtn;
        if (TouchInput.isTriggered()) {
            this.SetPictFIn(PN_OsLBtn_SelH, OsiokiPic + "PN_OsLBtn_SelH", 0, 148 + (76 * _Osioki_Sel動き) - 17, 0, 0, 15);
            this.SetCmnEvent(CN_Osioki + _Osioki_Sel動き);
        }
    }
    if (Osioki_終了Flg) {
        if (!BefOsioki_終了Flg) {
            BefOsioki_終了Flg = true;
            this.MovePict(PN_OsEndBtn, true, true, 10);
        }
    }
    this.PicCngColor(PN_OsEndBtn);
    if (overPointerCk(PN_OsEndBtn) && Osioki_終了Flg) {
        this.PicCngColor(PN_OsEndBtn, [100, 100, 100, 0]);
        if (TouchInput.isTriggered()) {
            this.SetCmnEvent(CN_Osioki_End);
            this.DelPictSpan(PN_VolBar, PN_VolTxt + 2);
            return false; 
        }
    }
    let befSelect = _Osioki_Sel動き;
    let mvFlg = false;
    if (Input.isTriggered('down')) { 
        _Osioki_Sel動き++;
        mvFlg = true;
    }
    if (Input.isTriggered('up')) {
        _Osioki_Sel動き--;
        if (_Osioki終了Select) _Osioki_Sel動き = Osioki_BtnPic.length - 1;
        mvFlg = true;
    }
    if (mvFlg) {
        if (_Osioki_Sel動き < 0) _Osioki_Sel動き = 0;
        if (_Osioki_Sel動き < Osioki_BtnPic.length) {
            _Osioki終了Select = false;
            if (befSelect != _Osioki_Sel動き) {
                this.SetCmnEvent(CN_Osioki + _Osioki_Sel動き);
                this.SetPictFIn(PN_OsLBtn_SelH, OsiokiPic + "PN_OsLBtn_SelH", 0, 148 + (76 * _Osioki_Sel動き) - 17, 0, 0, 15);
                this.PicCngColor(PN_OsEndBtn);
            }
        } else {
            _Osioki終了Select = true;
        }
    }
    if (_Osioki終了Select) {
        this.PicCngColor(PN_OsEndBtn, [100, 100, 100, 0]);
        if (Input.isTriggered('ok') ) {
            this.SetCmnEvent(CN_Osioki_End);
            this.DelPictSpan(PN_VolBar, PN_VolTxt + 2);
            return false; 
        }
    }
    _CNo = overPicClickable(PN_OsBack, _OsiokiVolArr);
    if (_CNo != -1) {
        if (TouchInput.isPressed()) {
            let _VolPar = Math.floor(((PL_MouseX - 1275) / 150) * 100);
            switch (_CNo) {
                case 0:
                    ConfigManager['bgmVolume'] = _VolPar;
                    break;
                case 1:
                    ConfigManager['seVolume'] = _VolPar;
                    break;
                case 2:
                    $gameVariables.setValue(VoiceVolVarNo, _VolPar);
                    VoiceVol = $gameVariables.value(VoiceVolVarNo); 
                    break;
            }
            this.SetPict(PN_VolBar + _CNo, OsiokiPic + "PN_VolBar", 1276, OsiokiBarPosY + 60 * _CNo, 255, _VolPar);
            this.SetPict(PN_VolTumami + _CNo, OsiokiPic + "PN_VolTumami", 1274 + (150 * (_VolPar / 100)), OsiokiBarPosY - 3 + (60 * _CNo), 255);
            this.SetPicStrC(PN_VolTxt + _CNo, _VolPar, 20, 1357, OsiokiBarPosY - 21 + (60 * _CNo));
            this.UTA_Save();        
            ConfigManager.save();   
        }
    }
    return true; 
}
Game_Interpreter.prototype.Adv_Osioki_UIBtnClose = function () {
    for (let i = PN_OsRBtn_SelH; i <= PN_OsEndBtn; i++) {
        this.MovePict(i, true, true, 10, 0);
    }
}
Game_Interpreter.prototype.Adv_Osioki_AllClose = function () {
    this.MovePict(PN_OsBack_Black, true, true, 10, 0);
    this.MovePict(PN_OsBack, true, true, 10, 0);
    this.Adv_Osioki_UIBtnClose();
    _dorei_Selecter = 0;
}
