const VN_Menuモラル = 91;
const VN_Menu性的 = 92;
const H_MaxRank経験値 = 700;
let VN_HステRank_NUpdateSc = Game_Interpreter.prototype.NUpdateSc;
Game_Interpreter.prototype.NUpdateSc = function () {
    VN_HステRank_NUpdateSc.call(this);
    for (let i = 0; i < 4; i++) {
        let ckValue = $gameVariables.value(VN_Kaihatu + i);
        let _開発Rank = 1; 
        if (ckValue >= $Nupu_PSData.hStData.cRankValue) _開発Rank++; 
        if (ckValue >= $Nupu_PSData.hStData.bRankValue) _開発Rank++; 
        if (ckValue >= $Nupu_PSData.hStData.aRankValue) _開発Rank++; 
        if (ckValue >= H_MaxRank経験値) _開発Rank++; 
        $gameVariables.setValue(VN_HステRank + i , _開発Rank);
    }
}
let Menu_H_Data_Mode = 0; 
let DW2_Pos; 
let kaihatuRankSaveArr = []; 
Game_Interpreter.prototype.Menu_H_DataView = function (fadeInFlg) {
    fadeInFlg = typeof fadeInFlg !== 'undefined' ? fadeInFlg : false;
    useHStData = GetHStData();
    ViewSpriteArr_Reset(); 
    let fstOpacity = 255;
    if (fadeInFlg) {
        Menu_H_Data_Mode = 0;
        fstOpacity = 0;
        kaihatuRankSaveArr = []; 
    }
    if ($gameVariables.value(VN_Menuモラル) == 0) $gameVariables.setValue(VN_Menuモラル ,"正義");
    if ($gameVariables.value(VN_Menu性的) == 0) $gameVariables.setValue(VN_Menu性的 ,"嫌悪");
    D_Text_Cng_font = "Makinas"; 
    let DW1_Pos = new Pos2D(413, 163);
    this.SetSpriteC(PN_H_DWin0, Menu_H_UIPath + "Data/s_DataWin0", DW1_Pos._x, DW1_Pos._y, fstOpacity);
    this.SpriteStrC(PN_H_DWin0 + 1, $gameVariables.value(VN_Menuモラル) , 28, DW1_Pos._x - 91, DW1_Pos._y + 34, fstOpacity);
    this.SpriteStrC(PN_H_DWin0 + 2, $gameVariables.value(VN_Menu性的) , 28, DW1_Pos._x + 91, DW1_Pos._y + 34, fstOpacity);
    DW2_Pos = new Pos2D(1159, 270); 
    this.Menu_H_DataWinDraw(1, fstOpacity);
    DW2_Pos = new Pos2D(410, 405);  
    this.Menu_H_DataWinDraw(2, fstOpacity);
    DW2_Pos = new Pos2D(1159, 547); 
    this.Menu_H_DataWinDraw(3, fstOpacity);
    DW2_Pos = new Pos2D(410, 680);  
    this.Menu_H_DataWinDraw(4, fstOpacity);
    D_Text_Cng_font = ""; 
    for (let i = 0; i <= ViewSpriteArr.length - 1; i++) {
        this.MoveSprite(ViewSpriteArr[i], true, true, 10, 255, true, true);
    }
    L2dFadeMdl("romasha_talk", "centerin", 10, "", null, null, -80, 0);
    this.SetCmnEventSc(CN_RomashaMotion); 
}
Game_Interpreter.prototype.Menu_H_DataWinDraw = function (setMode, setOpacity) {
    let E_Mode = setMode - 1;
    let barValue = 0;
    let kaihatuRank = 1; 
    barValue = $gameVariables.value(VN_Kaihatu + E_Mode) / 100; 
    if ($gameVariables.value(VN_Kaihatu + E_Mode) >= 100) {
        kaihatuRank++;
        let _WariVar = $gameVariables.value(VN_Kaihatu + E_Mode) - 100;
        barValue = _WariVar / 150;
    }
    if ($gameVariables.value(VN_Kaihatu + E_Mode) >= 250) {
        kaihatuRank++;
        let _WariVar = $gameVariables.value(VN_Kaihatu + E_Mode) - 250;
        barValue = _WariVar / 200;
    }
    if ($gameVariables.value(VN_Kaihatu + E_Mode) >= 450) {
        kaihatuRank++;
        let _WariVar = $gameVariables.value(VN_Kaihatu + E_Mode) - 450;
        barValue = _WariVar / 250;
    }
    if ($gameVariables.value(VN_Kaihatu + E_Mode) >= H_MaxRank経験値) {
        kaihatuRank++;
        barValue = 1; 
    }
    kaihatuRankSaveArr.push([setMode, kaihatuRank]);
    this.SetSpriteC(PN_H_DWin + 0 + (E_Mode * 6), Menu_H_UIPath + "Data/s_DataWin" + setMode, DW2_Pos._x, DW2_Pos._y, setOpacity);
    this.SetSpriteC(PN_H_DWin + 1 + (E_Mode * 6), Menu_H_UIPath + "Data/Win" + setMode + "_Mode" + kaihatuRank,
        DW2_Pos._x - 103, DW2_Pos._y + 29, setOpacity);
    this.SetSprite(PN_H_DWin + 2 + (E_Mode * 6), Menu_H_UIPath + "Data/StBar",
        DW2_Pos._x + -45, DW2_Pos._y - 1, setOpacity, barValue * 100);
    this.SetSpriteC(PN_H_DWin + 3 + (E_Mode * 6), Menu_H_UIPath + "Data/Rank_" + kaihatuRank,
        DW2_Pos._x + 137, DW2_Pos._y - 64, setOpacity);
    for (let i = 0; i <= useHStData.View_Rank.length - 1; i++) {
        if (useHStData.View_Rank[i].No == setMode && useHStData.View_Rank[i].rank == kaihatuRank) {
            this.SpriteStr(PN_H_DWin + 4 + (E_Mode * 6), useHStData.View_Rank[i].rankText1, 17,
                DW2_Pos._x - 40, DW2_Pos._y + 24, setOpacity);
            this.SpriteStr(PN_H_DWin + 5 + (E_Mode * 6), useHStData.View_Rank[i].rankText2, 17,
                DW2_Pos._x - 40, DW2_Pos._y + 50, setOpacity);
            break;
        }
    }
}
Game_Interpreter.prototype.Menu_H_DataUpdate = function () {
    switch (Menu_H_Data_Mode) {
        case 0:
            this.Menu_H_Data_SelectUpdate();
            break;
        case 1:
            this.Menu_H_Data_開発DetaiUpdate();
            break;
    }
}
Game_Interpreter.prototype.Menu_H_Data_SelectUpdate = function () {
    let _overArr = [];
    _overArr.push(PN_H_DWin + (0 * 6));
    _overArr.push(PN_H_DWin + (1 * 6));
    _overArr.push(PN_H_DWin + (2 * 6));
    _overArr.push(PN_H_DWin + (3 * 6));
    let _overNo = overPointerSpCkArr(_overArr);
    if (_overNo != -1) {
        if (GetSpriteData(_overNo) != undefined) {
            let _posX = GetSpriteData(_overNo)._x;
            let _posY = GetSpriteData(_overNo)._y;
            this.SetSpriteC(PN_H_DSelH, Menu_H_UIPath + "Data/dSelectH", _posX, _posY);
        }
        if (TouchInput.isTriggered()) {
            SoundManager.playOk(); 
            let _ckNo = Math.floor((_overNo - PN_H_DWin) / 6);
            this.Menu_H_Data_開発DetailView(_ckNo);
            Menu_EditLayer++;
            Menu_H_Data_Mode = 1;
        }
    } else {
        this.DelSprite(PN_H_DSelH);
    }
}
let H_DataWinSelNo = -1;
Game_Interpreter.prototype.Menu_H_Data_開発DetailView = function (ckModeNo) {
    H_DataWinSelNo = ckModeNo; 
    ViewSpriteArr_Reset(); 
    let rankNo = 1;
    for (let i = 0; i <= kaihatuRankSaveArr.length - 1; i++) {
        if (kaihatuRankSaveArr[i][0] == ckModeNo + 1) {
            rankNo = kaihatuRankSaveArr[i][1];
        }
    }
    let titleText = "";
    if (ckModeNo == 0) titleText = "口淫熟練度";
    if (ckModeNo == 1) titleText = "乳開発度";
    if (ckModeNo == 2) titleText = "尻開発度";
    if (ckModeNo == 3) titleText = "膣開発度";
    let setX = 355;
    let setY = 134;
    this.SetSprite(PN_DSBase, Menu_H_UIPath + "Data/ddBase", setX, setY, 0);
    this.SetSprite(PN_DSChara, Menu_H_UIPath + "Data/ddBody" + (ckModeNo + 1) + "_" + rankNo, setX, setY, 0);
    this.SetSprite(PN_DSTop, Menu_H_UIPath + "Data/ddBTop", setX, setY, 0);
    let _Keiken = $gameVariables.value(VN_Kaihatu + ckModeNo); 
    let _BarWari = 1 - (_Keiken / H_MaxRank経験値);
    if (_BarWari < 0) _BarWari = 0;
    this.SetSprite(PN_DSKakusi, Menu_H_UIPath + "Data/ddKakusi",
        setX + 810, setY + 135, 255, -100 * _BarWari);
    let _owSet = "\\ow[0]"
    D_Text_Cng_font = "Makinas"; 
    this.SpriteStr(PN_DSTtTxt, titleText, 40, setX + 305, setY + 58, 0);
    //this.SpriteStr(PN_DSKknTxt, _owSet + _Keiken, 25, setX + 758, setY + 100, 0);
    let _開発Rank = 1; 
    if (_Keiken >= $Nupu_PSData.hStData.cRankValue) _開発Rank++; 
    if (_Keiken >= $Nupu_PSData.hStData.bRankValue) _開発Rank++; 
    if (_Keiken >= $Nupu_PSData.hStData.aRankValue) _開発Rank++; 
    if (_Keiken >= H_MaxRank経験値) _開発Rank++; 
    this.SetSprite(PN_DSTop + 1, Menu_H_UIPath + "Data/Rank_" + _開発Rank, setX + 751, setY + 76, 0);
    let _SelVNo = -1;
    for (let i = 0; i <= useHStData.View_Rank.length - 1; i++) {
        if (useHStData.View_Rank[i].No == ckModeNo + 1 &&
            useHStData.View_Rank[i].rank == _開発Rank) {
            _SelVNo = i;
            break;
        }
    }
    if (_SelVNo != -1) {
        this.DelSpriteSpan(PN_DSStTxt + 0 , PN_DSStTxt + 2);
        let ckArr = useHStData.View_Rank[_SelVNo].rankSetu.split('\r\n');
        for (let i = 0; i <= ckArr.length - 1; i++) {
            this.SpriteStr(PN_DSStTxt + i, ckArr[i], 22
                , setX + 305, setY + 226 + i * 30, 0);
        }
    }
    let _実績SetX = setX + 390;
    let _実績SetY = setY + 411;
    let _実績Count = 0;
    for (let i = 0; i <= 6 - 1; i++) {
        if ($gameSwitches.value(SW_HJisseki + 1 + i + (6 * ckModeNo))) {
            let _実績ZureX = 0;
            let _実績ZureY = Math.floor(_実績Count / 2) * 30;
            if (_実績Count % 2 == 1) _実績ZureX = 193;
            this.SpriteStr(PN_DSJskTxt + i, "・" + $dataSystem.switches[SW_HJisseki + 1 + i + (6 * ckModeNo)],
                25, _実績SetX + _実績ZureX, _実績SetY + _実績ZureY, 0);
            _実績Count++;
        }
    }
    for (let i = 0; i <= ViewSpriteArr.length - 1; i++) {
        this.MoveSprite(ViewSpriteArr[i], true, true, 10, 255, true, true);
    }
    D_Text_Cng_font = ""; 
}
Game_Interpreter.prototype.Menu_H_Data_開発DetaiUpdate = function () {
    if (TouchInput.isCancelled() || Input.isTriggered('menu')) {
        this.Layer1_DelTopTop(PN_DSBase);
        Menu_H_Data_Mode = 0;
        L2dFadeMdl("romasha_talk", "centerin", 10, "", null, null, -80, 0);
    }
}
