let VN_Hatu = 62; 
let VN_Hyoka = VN_Hatu + 1; 
let VN_ZtTotal = 64; 
let VN_ZtTitu = VN_ZtTotal + 1; 
let VN_ZtKou = VN_ZtTitu + 1;   
let VN_ZtTkb = VN_ZtKou + 1;    
let VN_SexTotal = 68;           
let VN_Fera = VN_SexTotal + 1;  
let VN_SexCnt = VN_Fera + 1;    
let VN_ASexCnt = VN_SexCnt + 1; 
let VN_ZmTotal = 72;    
let VN_ZmTitu = VN_ZmTotal + 1; 
let VN_ZmAnl = VN_ZmTitu + 1;   
let VN_ZmKao = VN_ZmAnl + 1;   
let VN_ZmBody = VN_ZmKao + 1;   
let VN_OnaCnt = 78;  
let VN_OpenCnt = VN_OnaCnt + 1; 
let VN_TstCnt = VN_OpenCnt + 1; 
let VN_Sekuhara = 81;   
const VN_風俗人気度 = 180;
let Menu_H_Record_Mode = 0; 
let RBPos = new Pos2D(246, 227);
let _sexRanking = []; 
Game_Interpreter.prototype.Menu_H_RecordView = function (fadeInFlg) {
    fadeInFlg = typeof fadeInFlg !== 'undefined' ? fadeInFlg : false;
    ViewSpriteArr_Reset(); 
    let setOpacity = 255;
    if (fadeInFlg) {
        setOpacity = 0;
    }
    this.SetSpriteC(PN_RBase, Menu_H_UIPath + "Record/Record", 389, 135, setOpacity);
    this.SetSprite(PN_Record, Menu_H_UIPath + "Record/R_Base", RBPos._x, RBPos._y, setOpacity);
    this.SetSpriteC(PN_RnkBtn, Menu_H_UIPath + "Record/R_RnkBtn", 786, 628, setOpacity);
    let outLineStr = "\\ow[0]"
    D_Text_Cng_font = "Makinas"; 
    let setFontSize = 35;
    let _hatuStr = $gameVariables.value(VN_Hatu);
    if (_hatuStr == "N[108]") _hatuStr = "\\N[108]";
    var match = _hatuStr.match(/\\N\[(\d+)\]/);
    if (match) {
        let actorId = Number(match[1]);
        _hatuStr = $gameActors._data[actorId]._name;
    }
    if (_hatuStr.length > 7) setFontSize = 25;
    this.SpriteStr(PN_RTopTxt + 0, outLineStr + "初体験：" + _hatuStr, setFontSize, 249, 184, setOpacity);
    setFontSize = 35;
    let _fstStr = $gameVariables.value(VN_Hatu);
    if (_fstStr.length > 7) setFontSize = 25;
    this.SpriteStr(PN_RTopTxt + 1, outLineStr + "ﾌｧｰｽﾄｷｽ：" + $gameVariables.value(VN_Hyoka), setFontSize, 650, 184, setOpacity);
    let zureX = 207;
    let zureY = 17;
    this.SpriteStr(PN_RZtTxt + 0, outLineStr + $gameVariables.value(VN_ZtTotal) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 0), setOpacity);
    this.SpriteStr(PN_RZtTxt + 1, outLineStr + $gameVariables.value(VN_ZtTitu) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 1), setOpacity);
    this.SpriteStr(PN_RZtTxt + 2, outLineStr + $gameVariables.value(VN_ZtKou) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 2), setOpacity);
    this.SpriteStr(PN_RZtTxt + 3, outLineStr + $gameVariables.value(VN_ZtTkb) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 3), setOpacity);
    zureY = 133;
    this.SpriteStr(PN_RSexTxt + 0, outLineStr + $gameVariables.value(VN_SexTotal) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 0), setOpacity);
    this.SpriteStr(PN_RSexTxt + 1, outLineStr + $gameVariables.value(VN_Fera) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 1), setOpacity);
    this.SpriteStr(PN_RSexTxt + 2, outLineStr + $gameVariables.value(VN_SexCnt) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 2), setOpacity);
    this.SpriteStr(PN_RSexTxt + 3, outLineStr + $gameVariables.value(VN_ASexCnt) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 3), setOpacity);
    zureY = 251;
    this.SpriteStr(PN_RZmnTxt + 0, outLineStr + $gameVariables.value(VN_ZmTotal) + " ml", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 0), setOpacity);
    this.SpriteStr(PN_RZmnTxt + 1, outLineStr + $gameVariables.value(VN_ZmTitu) + " ml", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 1), setOpacity);
    this.SpriteStr(PN_RZmnTxt + 2, outLineStr + $gameVariables.value(VN_ZmAnl) + " ml", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 2), setOpacity);
    this.SpriteStr(PN_RZmnTxt + 3, outLineStr + $gameVariables.value(VN_ZmKao) + " ml", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 3), setOpacity);
    this.SpriteStr(PN_RZmnTxt + 4, outLineStr + $gameVariables.value(VN_ZmBody) + " ml", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 4), setOpacity);
    zureY = 416;
    this.SpriteStr(PN_RSntTxt + 0, outLineStr + $gameVariables.value(VN_OnaCnt) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 0), setOpacity);
    this.SpriteStr(PN_RSntTxt + 1, outLineStr + $gameVariables.value(VN_OpenCnt) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 1), setOpacity);
    this.SpriteStr(PN_RSntTxt + 2, outLineStr + $gameVariables.value(VN_TstCnt) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 2), setOpacity);
    zureX = 256;
    zureY = 505;
    this.SpriteStr(PN_RSntTxt + 3, outLineStr + $gameVariables.value(VN_OkzCount) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 0) - 2, setOpacity);
    this.SpriteStr(PN_RSntTxt + 4, outLineStr + $gameVariables.value(VN_Sekuhara) + " 回", 25,
        RBPos._x + zureX, RBPos._y + zureY + (25 * 1), setOpacity);
    _sexRanking = []; 
    let checkVnArr = [];
    for (let i = 0; i <= (498 - 442) - 1; i++) checkVnArr.push(VN_SexRkg + i);
    for (let i = 0; i <= 40 - 1; i++) checkVnArr.push(VN_SexRkg2 + i);
    checkVnArr = checkVnArr.filter(function (x, i, self) {
        return self.indexOf(x) === i;
    });
    for (let i = 0; i <= checkVnArr.length - 1; i++) {
        if ($dataSystem.variables[checkVnArr[i]] != "") {
            if ($gameVariables.value(checkVnArr[i]) != 0) {
                if (_sexRanking.length == 0) { 
                    _sexRanking.push(checkVnArr[i]);
                    continue;
                }
                let addId = -1;
                for (let j = 0; j <= _sexRanking.length - 1; j++) {
                    if ($gameVariables.value(_sexRanking[j]) < $gameVariables.value(checkVnArr[i])) {
                        addId = j;
                        break;
                    }
                }
                if (addId == -1) {
                    _sexRanking.push(checkVnArr[i]);
                    continue;
                }
                _sexRanking.splice(addId, 0, checkVnArr[i]);
            }
        }
    }
    zureX = 436;
    zureY = 73;
    for (let i = 0; i <= _sexRanking.length - 1; i++) {
        this.SpriteStr(PN_RRnkTxt + i,
            outLineStr + $gameVariables.value(_sexRanking[i]) + " 回" + "：" +
            $dataSystem.variables[_sexRanking[i]], 23,
            RBPos._x + zureX, RBPos._y + zureY + (25 * i), setOpacity);
        if (i == 9) break;
    }
    if ($gameVariables.value(VN_風俗人気度) > 0) {
        this.SetSprite(PN_FuzokuSyasin, Menu_H_UIPath + "Record/" + "PN_FuzokuSyasin", 0, 0, setOpacity);
        this.SpriteStrC(PN_NinkiTxt, SCol.Ppr + $gameVariables.value(VN_風俗人気度), 50, 740 - 24, 147, setOpacity);
    }
    D_Text_Cng_font = ""; 
    for (let i = 0; i <= ViewSpriteArr.length - 1; i++) {
        this.MoveSprite(ViewSpriteArr[i], true, true, 10, 255, true, true);
    }
}
Game_Interpreter.prototype.Menu_H_RecordUpdate = function () {
    switch (Menu_H_Record_Mode) {
        case 0:
            MenuCngOkFlg = true;
            this.Menu_H_Record_BaseUpdate();
            break;
        case 1:
            MenuCngOkFlg = false;
            this.Menu_H_Record_RankingUpdate();
            break;
    }
}
Game_Interpreter.prototype.Menu_H_Record_BaseUpdate = function () {
    let overPicArr = [PN_RnkBtn];
    this.SpriteCngColorArr(overPicArr);
    let overPicNo = overPointerSpCkArr(overPicArr);
    if (overPicNo != -1) {
        this.SpriteCngColor(overPicNo, [100, 100, 100, 0]);
        if (TouchInput.isTriggered()) {
            if (menuAutoCloseFlame > 0) { menuAutoCloseFlame = 1; return; }
            SoundManager.playOk(); 
            switch (overPicNo) {
                case PN_RnkBtn:
                    this.Menu_H_Record_RankingView();
                    Menu_EditLayer++;
                    Menu_H_Record_Mode = 1;
                    break;
            }
        }
    }
}
let menuHRankingScroll; 
let menuHRankingPos = new Pos2D(335, 163); 
let menuHRankingScrollZure = 0; 
Game_Interpreter.prototype.Menu_H_Record_RankingView = function (fadeInFlg) {
    fadeInFlg = typeof fadeInFlg !== 'undefined' ? fadeInFlg : false;
    ViewSpriteArr_Reset(); 
    let setOpacity = 255;
    if (fadeInFlg) {
        menuHRankingScrollZure = 0;
        setOpacity = 0;
    }
    this.SetSpriteFIn(PN_RWBack, "Black", 0, 0, 0, 0, 15, 150);
    this.SetSprite(PN_RWBase, Menu_H_UIPath + "Record/R_RnkWin",
        menuHRankingPos._x, menuHRankingPos._y, setOpacity);
    menuHRankingScroll = new N_Scroll(Menu_H_UIPath + "Record/R_ScBar", 469, PN_RWScBar
        , menuHRankingPos._x + 681, menuHRankingPos._y + 96);
    menuHRankingScroll.ViewCount = 18;    
    menuHRankingScroll.ItemCount = _sexRanking.length; 
    menuHRankingScroll.ZureNo = menuHRankingScrollZure; 
    this.ScrollView(menuHRankingScroll);
    let outLineStr = "\\ow[0]"
    D_Text_Cng_font = "Makinas"; 
    let _hrVCnt = 18;
    for (let i = 0; i <= _hrVCnt - 1; i++) {
        this.DelPict(PN_RWTxt + i);
        this.DelSprite(PN_RWTxt + i);
    }
    for (let i = 0; i <= _sexRanking.length - 1; i++) {
        let ck_i = i + menuHRankingScrollZure;
        this.SpriteStr(PN_RWTxt + i,
            outLineStr + $gameVariables.value(_sexRanking[ck_i]) + " 回" + "：" +
            $dataSystem.variables[_sexRanking[ck_i]], 23
            , menuHRankingPos._x + 80, menuHRankingPos._y + 100 + (25 * i));
        if (i == _hrVCnt - 1) break;
    }
    D_Text_Cng_font = ""; 
}
Game_Interpreter.prototype.Menu_H_Record_RankingUpdate = function () {
    if (TouchInput.wheelY < 0) { 
        if (menuHRankingScrollZure > 0) menuHRankingScrollZure--;
        this.Menu_H_Record_RankingView();
    }
    if (TouchInput.wheelY > 0) { 
        if (_sexRanking.length > 18 + menuHRankingScrollZure) menuHRankingScrollZure++;
        this.Menu_H_Record_RankingView();
    }
    if (TouchInput.isCancelled()) {
        this.Layer1_DelTopTop(PN_RWBack);
        Menu_H_Record_Mode = 0;
    }
}
Game_Interpreter.prototype.Menu_H_RecordView_Draw = function () {
    this.SetSprite(PN_HBase, Menu_H_UIPath + "s_back", 0, 0);
    this.MoveSprite(PN_HBase, true, true, 5, 255, true, true);
    this.Menu_H_RecordView(true);
}
Game_Interpreter.prototype.Menu_H_RecordView_Del = function () {
    this.DelSpriteSpan(PN_HBase , PN_RWTxt + 18);
}
