const PN_mDBase = 144;
const PN_mDBtn = 157
const PN_mDCntBack = PN_mDBtn + 5;
const PN_mDCount = PN_mDCntBack + 1;
const PN_mDkpkTxt = PN_mDCount + 3;
const PN_mDKpkSetu = PN_mDkpkTxt + 2;
const PN_mDStWin = 180;
const PN_mDStKuti = PN_mDStWin + 4;
const PN_mDStTiti = PN_mDStKuti + 6;
const PN_mDStTitu = PN_mDStTiti + 3;
const PN_mDStSiri = PN_mDStTitu + 6;
const PN_mDSell = 300; 
const D_Menu_PicPath = "pictures/Adv_Dorei/Menu/";
let _dMenuflame = 0;
let _dMenu_SelX = 0;
let _dMenu_SelY = 0;
let DMenuFlg = false;
Game_Interpreter.prototype.Dorei_Menu_Open = function () {
    DMenuFlg = true;
    Adv_Stop = MenuOpen = true; 
    MenuLayer = MenuFlame = 0;
    menu_l0_flame = 0;
    _dMenu_SelX = 0;
    _dMenu_SelY = 0;
    this.D_Menu_L0_View(true);
    L2dAllFadeOut();
}
Game_Interpreter.prototype.D_Sell_View = function () {
}
Game_Interpreter.prototype.D_Menu_Update = function () {
    switch (MenuLayer) {
        case 0:
            this.D_Menu_L0_Update();
            break;
        case 1:
            this.D_Menu_L1_Update();
            break;
    }
    MenuFlame++;
}
let Dorei_説明Arr = ["" , "" , "" , ""];
const CN_Dorei_MenuOn = 495;
const CN_Dorei_MenuOff = 496;
Game_Interpreter.prototype.D_Menu_L0_View = function () {
    this.SetPictFInC( PN_mAdvSell , DPicPath + "PN_mAdvSell" ,
        26 + 20 + _dMenu_SelX * 235 , 24 + 40 + _dMenu_SelY * 84 , 0 , 0 , 5);
    this.SetPictFIn(PN_mDBase , D_Menu_PicPath + "PN_mDBase" , 0 , 0 , 0 , 0 , 5);
    this.SetCmnEventSc(CN_Dorei_MenuOn);
    this.SetSpriteFIn( PN_mDBtn + 0 , D_Menu_PicPath + "PN_mDBtn_Save" , 26 , 24 , 0 , 0 , 5);
    this.SetSpriteFIn( PN_mDBtn + 1 , D_Menu_PicPath + "PN_mDBtn_Load" , 26 + 235 , 24 , 0 , 0 , 5);
    this.SetSpriteFIn( PN_mDBtn + 2 , D_Menu_PicPath + "PN_mDBtn_Option" , 26 , 24 + 84 , 0 , 0 , 5);
    this.SetSpriteFIn( PN_mDBtn + 3 , D_Menu_PicPath + "PN_mDBtn_Title" , 26 + 235 , 24 + 84 , 0 , 0 , 5);
    this.SetSpriteFIn( PN_mDBtn + 4 , D_Menu_PicPath + "PN_mDBtn_Rate" , 26 , 24 + 84 * 2 , 0 , 0 , 5);
    this.SetSpriteFIn( PN_mDCntBack , D_Menu_PicPath + "PN_mDCntBack" , 0 , 0 , 0 , 0 , 5);
    this.SpriteStr(PN_mDCount + 0 , $gameVariables.value(VN_経験人数) , 35 , 332 , 286 + (60 * 0) , 0);
    this.MoveSprite(PN_mDCount + 0 , true , true , 5);
    this.SpriteStr(PN_mDCount + 1 , $gameVariables.value(VN_絶頂人数) , 35 , 332 , 286 + (60 * 1) , 0);
    this.MoveSprite(PN_mDCount + 1 , true , true , 5);
    this.SpriteStr(PN_mDCount + 2 , $gameVariables.value(VN_射精人数) , 35 , 332 , 286 + (60 * 2) , 0);
    this.MoveSprite(PN_mDCount + 2 , true , true , 5);
    this.SpriteStrC(PN_mDkpkTxt + 0 , " " + $gameVariables.value(VN_奴隷_屈服度) + "% " , 44 , 117 , 538 , 0);
    this.MoveSprite(PN_mDkpkTxt + 0 , true , true , 5);
    this.SpriteStrC(PN_mDkpkTxt + 1 , this._屈服度StrGet() , 18 , 117 , 570 , 0);
    this.MoveSprite(PN_mDkpkTxt + 1 , true , true , 5);
    for (let i = 0; i <= 4 - 1; i++) {
        this.SpriteStr(PN_mDKpkSetu + i , Dorei_説明Arr[i] , 20 , 79 , 616 + (i * 40) , 0);
        this.MoveSprite(PN_mDKpkSetu + i , true , true , 5);
    }
    _NSprite_AncNo = 0;
    let _口Ps = new Pos2D(973 , 180);
    this.SetSpriteFIn( PN_mDStWin + 0 , D_Menu_PicPath + "PN_mDStWin_Kuti" , _口Ps._x , _口Ps._y , 0 , 0 , 5);
    let _乳Ps = new Pos2D(614 , 377);
    this.SetSpriteFIn( PN_mDStWin + 1 , D_Menu_PicPath + "PN_mDStWin_Titi" , _乳Ps._x , _乳Ps._y , 0 , 0 , 5);
    let _膣Ps = new Pos2D(1012 , 500);
    this.SetSpriteFIn( PN_mDStWin + 2 , D_Menu_PicPath + "PN_mDStWin_Titu" , _膣Ps._x , _膣Ps._y , 0 , 0 , 5);
    let _尻Ps = new Pos2D(725 , 584);
    this.SetSpriteFIn( PN_mDStWin + 3 , D_Menu_PicPath + "PN_mDStWin_Siri" , _尻Ps._x , _尻Ps._y , 0 , 0 , 5);
    let _口cnt = _胸cnt = _膣cnt = _尻cnt = 0;
    for (let i = 0; i <= 6 - 1; i++) {
        if($dataSystem.variables[VN_口経験 + i] != '') {
            this.SpriteStr(PN_mDStKuti + i , 
                $dataSystem.variables[VN_口経験 + i] + "：" +
                $gameVariables.value(VN_口経験 + i) + " " , 18 , _口Ps._x + 112 , _口Ps._y + 16 + (21 * _口cnt) , 0);
            this.MoveSprite(PN_mDStKuti + i , true , true , 5);
            _口cnt++;
        }
        if($dataSystem.variables[VN_胸経験 + i] != '') {
            this.SpriteStr(PN_mDStTiti + i  , 
                $dataSystem.variables[VN_胸経験 + i] + "：" + 
                $gameVariables.value(VN_胸経験 + i) + " " , 18 , _乳Ps._x + 18 , _乳Ps._y + 16 + (21 * _胸cnt) , 0);
            this.MoveSprite(PN_mDStTiti + i , true , true , 5);
            _胸cnt++;
        }
        if($dataSystem.variables[VN_膣経験 + i] != '') {
            this.SpriteStr(PN_mDStTitu + i ,
                $dataSystem.variables[VN_膣経験 + i] + "：" +
                $gameVariables.value(VN_膣経験 + i) + " " , 18 , _膣Ps._x + 115 , _膣Ps._y + 20 + (21 * _膣cnt) , 0);
            this.MoveSprite(PN_mDStTitu + i , true , true , 5);
            _膣cnt++;
        }
        if($dataSystem.variables[VN_尻経験 + i] != '') {
            this.SpriteStr(PN_mDStSiri + i , 
                $dataSystem.variables[VN_尻経験 + i] + "：" + 
                $gameVariables.value(VN_尻経験 + i) + " " , 18 , _尻Ps._x + 18 , _尻Ps._y + 13 + (21 * _尻cnt) , 0);
            this.MoveSprite(PN_mDStSiri + i , true , true , 5);
            _尻cnt++;
        }
    }
}
Game_Interpreter.prototype._屈服度StrGet = function () {
    if($gameVariables.value(VN_奴隷_屈服度) < 50){
        return " Defiant ";
    } else if($gameVariables.value(VN_奴隷_屈服度) < 100){
        return " Suppressed ";
    } else {
        return " Subservient ";
    }
}
Game_Interpreter.prototype._開発度StrGet = function () {
    return "  ";
}
Game_Interpreter.prototype.Adv_DoreiL0_Back = function () {
    this.DelPictSpan(PN_mL2Base , PN_MSvWin_Sel);
    MenuLayer = MenuFlame = 0;
    menu_l0_flame = 0;
    this.MovePict(PN_mAdvSell , 26 + 20 + _dMenu_SelX * 235 , 24 + 40 + _dMenu_SelY * 84 , 5);
    this.D_Menu_L0_View();
}
Game_Interpreter.prototype.D_Menu_L0_Update = function () {
    let _mvFlg = false; let _okFlg = false;
    menu_l0_flame++;
    if(menu_l0_flame < 5) return;
    if (Input.isTriggered('up')) {
        _mvFlg = true; _dMenu_SelY--;
    }
    if (Input.isTriggered('down')) {
        _mvFlg = true;
        _dMenu_SelY++;
    }
    if (Input.isTriggered('left')) {
        _mvFlg = true; _dMenu_SelX--;
    }
    if (Input.isTriggered('right')) {
        _mvFlg = true; _dMenu_SelX++;
    }
    if (Input.isTriggered('ok')) {
        _okFlg = true;
    }
    if(_dMenu_SelY < 0) {
        _dMenu_SelY = 1;
        if (_dMenu_SelX == 0) _dMenu_SelX = 2;
    }
    if(_dMenu_SelY > 1) {
        if (_dMenu_SelX == 0) {
            if (_dMenu_SelY > 2) _dMenu_SelY = 0;
        }
        else _dMenu_SelY = 0;
    }
    if(_dMenu_SelX < 0) _dMenu_SelX = 1;
    if(_dMenu_SelX > 1) _dMenu_SelX = 0;
    let _CBNo = overPointerSpCkArr([PN_mDBtn + 0 ,PN_mDBtn + 1 ,PN_mDBtn + 2 ,PN_mDBtn + 3,PN_mDBtn + 4]);
    let _CngX = _dMenu_SelX;
    let _CngY = _dMenu_SelY;
    switch(_CBNo){
        case PN_mDBtn + 0: 
            _dMenu_SelX = 0; _dMenu_SelY = 0;
            break;
        case PN_mDBtn + 1: 
            _dMenu_SelX = 1; _dMenu_SelY = 0;
            break;
        case PN_mDBtn + 2: 
            _dMenu_SelX = 0; _dMenu_SelY = 1;
            break;
        case PN_mDBtn + 3: 
            _dMenu_SelX = 1; _dMenu_SelY = 1;
            break;
        case PN_mDBtn + 4: 
            _dMenu_SelX = 0; _dMenu_SelY = 2;
            break;
    }
    if(_CngX != _dMenu_SelX || _CngY != _dMenu_SelY){
        _mvFlg = true;
    }
    if(_CBNo != -1 && TouchInput.isTriggered()) _okFlg = true;
    if(_mvFlg){
        SoundManager.playCursor();
        this.MovePict(PN_mAdvSell , 26 + 20 + _dMenu_SelX * 235 , 24 + 40 + _dMenu_SelY * 84 , 5);
    }
    if(_okFlg){
        SoundManager.playOk();
        menu_l1_flame = 0;
        if(_dMenu_SelX == 0 && _dMenu_SelY == 0) {
            this.D_Menu_SaveView();
        }
        if(_dMenu_SelX == 1 && _dMenu_SelY == 0) {
            this.D_Menu_LoadView();
        }
        if(_dMenu_SelX == 0 && _dMenu_SelY == 1) {
            this.D_Menu_OptionView();
        }
        if(_dMenu_SelX == 1 && _dMenu_SelY == 1) {
            this.D_Menu_TitleView();
        }
        if(_dMenu_SelX == 0 && _dMenu_SelY == 2) {
            this.D_Menu_RateView();
        }
    }
    if (Input.isTriggered('escape') || TouchInput.isCancelled()) { 
        this.D_Menu_Close(); 
        this.Adv_ReDoreiEvent();
    }
}
Game_Interpreter.prototype.D_Menu_SaveView = function () {
    MenuLayer = 1;
    _DML1Mode = DML1Mode._Save;
    this.Menu_L1Save_Cng();
}
Game_Interpreter.prototype.D_Menu_LoadView = function () {
    MenuLayer = 1;
    _DML1Mode = DML1Mode._Load;
    this.Menu_L1Load_Cng();
}
Game_Interpreter.prototype.D_Menu_OptionView = function () {
    MenuLayer = 1;
    _DML1Mode = DML1Mode._Option;
    Opt_Zure = new Pos2D(-120,0);
    this.Menu_L1Option_Cng();
}
Game_Interpreter.prototype.D_Menu_TitleView = function () {
    MenuLayer = 1;
    _DML1Mode = DML1Mode._Title;
    this.Menu_L1Title_Cng();
}
let _DML1Mode = 0;
let DML1Mode = {
    _Save:1,
    _Load:2,
    _Option:3,
    _Title:4,
    _Rate:5
};
Game_Interpreter.prototype.D_Menu_L1_Update = function () {
    switch(_DML1Mode){
        case DML1Mode._Save:
            this.Menu_L1Save_Update();
            break;
        case DML1Mode._Load:
            this.Menu_L1Save_Update();
            break;
        case DML1Mode._Option:
            this.Menu_L1Option_Update();
            break;
        case DML1Mode._Title:
            this.Menu_L1Title_Update();
            break;
        case DML1Mode._Rate:
            this.Menu_L1Rate_Update();
            break;
    }
    menu_l1_flame++;
}
const D_Menu_Rate_PicPath = D_Menu_PicPath + "Rate/";
const VN_屈服度上昇率 = 187;
const VN_開発度上昇率 = 188;
let _RateCbMap = [
    [593, 203 + 211 * 0, 542, 33],
    [593, 203 + 211 * 1, 542, 33]
];
let Menu_L1Rate_Update_PushFrame = 0;
let Menu_L1Rate_Update_SelectNo = 0;
let Menu_L1Rate_Update_SelectNoMax = 1;
Game_Interpreter.prototype.D_Menu_RateView = function () {
    MenuLayer = 1;
    Menu_L1Rate_Update_PushFrame = 0;
    Menu_L1Rate_Update_SelectNo = 0;
    _DML1Mode = DML1Mode._Rate;
    this.SetPict(PN_mOpBase , D_Menu_Rate_PicPath + "PN_mOpBase")
    this.MovePict(PN_mDSell, 546, 214 + 211 * Menu_L1Rate_Update_SelectNo, 5, 255);
}
Game_Interpreter.prototype.Menu_L1Rate_Update = function () {
    Menu_L1Rate_Update_PushFrame++;
    var f屈服度率 = $gameVariables.value(VN_屈服度上昇率);
    var f開発度率 = $gameVariables.value(VN_開発度上昇率);
    this.SetPict(PN_mOpBar + 0 , D_Menu_Rate_PicPath + "PN_mOpBar" , 593 , 203 , 255 , f屈服度率 / 5);
    this.SetPict(PN_mOpBar + 1 , D_Menu_Rate_PicPath + "PN_mOpBar" , 593 , 203 + 211 , 255 , f開発度率 / 5);
    D_Text_Cng_font = "Makinas"; 
    this.SetPicStr(PN_mOpTxt + 0, f屈服度率 + "%", 40, 1155, 193, 255);
    this.SetPicStr(PN_mOpTxt + 1, f開発度率 + "%", 40, 1155, 193 + 211, 255);
    D_Text_Cng_font = "";
    let _mvFlg = false;
    let _CNo = overPicClickable(PN_mOpBase, _RateCbMap);
    if (_CNo != -1) {
        if (Menu_L1Rate_Update_SelectNo != _CNo) {
            Menu_L1Rate_Update_SelectNo = _CNo;
            _mvFlg = true;
        }
        if (TouchInput.isPressed()) {
            let _ParX = PL_MouseX - 593;
            let _setValue = Math.floor((_ParX / 542) * 500);
            if (_setValue < 0) _setValue = 0;
            if (_setValue > 500) _setValue = 500;
            switch (Menu_L1Rate_Update_SelectNo) {
                case 0:
                    $gameVariables.setValue(VN_屈服度上昇率 ,_setValue);
                    break;
                case 1:
                    $gameVariables.setValue(VN_開発度上昇率 ,_setValue);
                    break;
            }
        }
    }
    if (Input.isTriggered('up')) {
        Menu_L1Rate_Update_SelectNo--;
        _mvFlg = true;
    }
    if (Input.isTriggered('down')) {
        Menu_L1Rate_Update_SelectNo++;
        _mvFlg = true;
    }
    let pushFrame = 7;
    let rightOnFlg = Input.isTriggered('right');
    if (Input.isPressed('right') && Menu_L1Rate_Update_PushFrame % pushFrame == pushFrame - 1) rightOnFlg = true;
    let leftOnFlg = Input.isTriggered('left');
    if (Input.isPressed('left') && Menu_L1Rate_Update_PushFrame % pushFrame == pushFrame - 1) leftOnFlg = true;
    if (rightOnFlg || leftOnFlg) Menu_L1Rate_Update_PushFrame = 0;
    if (rightOnFlg) {
        switch (Menu_L1Rate_Update_SelectNo) {
            case 0:
                f屈服度率 += 20;
                if (f屈服度率 > 500) f屈服度率 = 500;
                $gameVariables.setValue(VN_屈服度上昇率 ,f屈服度率);
                break;
            case 1:
                f開発度率 += 20;
                if (f開発度率 > 500) f開発度率 = 500;
                $gameVariables.setValue(VN_開発度上昇率 ,f開発度率);
                break;
        }
    }
    if (leftOnFlg) {
        switch (Menu_L1Rate_Update_SelectNo) {
            case 0:
                f屈服度率 -= 20;
                if (f屈服度率 < 0) f屈服度率 = 0;
                $gameVariables.setValue(VN_屈服度上昇率 ,f屈服度率);
                break;
            case 1:
                f開発度率 -= 20;
                if (f開発度率 < 0) f開発度率 = 0;
                $gameVariables.setValue(VN_開発度上昇率 ,f開発度率);
                break;
        }
    }
    if (Menu_L1Rate_Update_SelectNo > Menu_L1Rate_Update_SelectNoMax) Menu_L1Rate_Update_SelectNo = 0
    if (Menu_L1Rate_Update_SelectNo < 0) Menu_L1Rate_Update_SelectNo = Menu_L1Rate_Update_SelectNoMax;
    if (_mvFlg) {
        this.MovePict(PN_mDSell, 546, 214 + 211 * Menu_L1Rate_Update_SelectNo, 5, 255);
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled()) {
        this.DelPictSpan(PN_mOpBase , PN_mOpTxt + 3);
        MenuLayer = 0;
        this.MovePict(PN_mAdvSell , 26 + 20 + _dMenu_SelX * 235 , 24 + 40 + _dMenu_SelY * 84 , 5);
    }
}
Game_Interpreter.prototype.D_Menu_Close = function () {
    MenuOpen = Adv_Stop = false;
    DMenuFlg = false;
    this.SetCmnEventSc(CN_Dorei_MenuOff);
    this.DelPict(PN_mDBase);
    this.DelSprite(151); 
    this.DelPictSpan(PN_mDBtn, PN_mAdvSell);
    this.DelSpriteSpan(PN_mDBtn, PN_mAdvSell);
    L2dFadeMdl("Ta_Leona" , "rightout" , 15 , "2neutral_idle" , 1 , null , 80 , null);
    this.SetPictC(PN_AdvSell, AdvPic + "PN_AdvSell", L0BtnPos._x - 15, L0BtnPos._y - (_AdvSellSa * L0_Selecter) + 35, 0);
    this.MovePict(PN_AdvSell, true, true, 5, 255);
    this.DelPict(PN_AdvSell);
}
