let NupuMenuAddressIni = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () { 
    NupuMenuAddressIni.call(this);
    this.AllMailList = []; //メール保存用：new Mails();
    this.AddressList = []; 
};
class MailData { 
    constructor(No, iconImg, faceImg, charaName, mailTitle, naiyo, _添付ItemArr,
                closeCmnEvNo, fstCloseCmnEvNo, openSetVNNo, openSetVNValue, picDatas, itemOpenCmnNo , Important) {
        this.No = No; 
        this.IconImt = iconImg; 
        this.FaceImg = faceImg; 
        this.ChrStr = charaName; 
        this.MTitle = mailTitle; 
        this.MNaiyo = naiyo; 
        this.openFlg = false; 
        this.TmpOpenFlg = false; 
        this.TmpItemArr = _添付ItemArr; 
        this.ClsCmn = closeCmnEvNo; 
        this.FstClsCmnFlg = fstCloseCmnEvNo; 
        this.OpnVarNo = openSetVNNo;   
        this.OpnSetVar = openSetVNValue;     
        this.PicData = picDatas;    
        this.ItemOpenCmn = itemOpenCmnNo;
        this.Important = Important; 
        this.ToolNo = -1;   
    }
}
class MailPicData {
    constructor(picName, picDesc) {
        this.PicName = picName; 
        this.PicDesc = picDesc; 
    }
}
Game_Interpreter.prototype.AddMaill = function (iconImg, faceImg, charaName, mailTitle, naiyo, _添付ItemArr,
                                                closeCmnEvNo, fstCloseCmnEvNo, openSetVNNo, openSetVNValue, picDatas, itemOpenCmnNo) {
    closeCmnEvNo = typeof closeCmnEvNo !== 'undefined' ? closeCmnEvNo : -1; 
    fstCloseCmnEvNo = typeof fstCloseCmnEvNo !== 'undefined' ? fstCloseCmnEvNo : false; 
    openSetVNNo = typeof openSetVNNo !== 'undefined' ? openSetVNNo : -1; 
    openSetVNValue = typeof openSetVNValue !== 'undefined' ? openSetVNValue : -1;
    picDatas = typeof picDatas !== 'undefined' ? picDatas : [];
    itemOpenCmnNo = typeof itemOpenCmnNo !== 'undefined' ? itemOpenCmnNo : -1;
    var setPicDatas = []
    picDatas.forEach(picData => {
        setPicDatas.push(new MailPicData(picData[0], picData[1]));
    });
    let addMailData = new MailData($gameSystem.AllMailList.length, iconImg, faceImg, charaName, mailTitle, naiyo, _添付ItemArr,
        closeCmnEvNo, fstCloseCmnEvNo, openSetVNNo, openSetVNValue, setPicDatas, itemOpenCmnNo , false);
    AddMainData(addMailData);
};
let AddMainData = function (addMailData) {
    $gameSystem.AllMailList.unshift(addMailData);
    if ($gameSystem.AllMailList.length > 50) {
        for (let i = $gameSystem.AllMailList.length - 1; i >= 0 ; i--) {
            if (!$gameSystem.AllMailList[i].Important) {
                $gameSystem.AllMailList.splice(i , 1);
                return;
            } else {
                if (!$gameSystem.AllMailList[i].openFlg) continue;
                if ($gameSystem.AllMailList[i].TmpItemArr.length == 0) {
                    $gameSystem.AllMailList.splice(i , 1);
                    return;
                } else {
                    if (!$gameSystem.AllMailList[i].TmpOpenFlg) continue;
                    $gameSystem.AllMailList.splice(i , 1);
                    return;
                }
            }
        }
    }
}
let AddMail_Initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () { 
    AddMail_Initialize.call(this);
    this.GetMailNos = []; 
};
Game_Interpreter.prototype.CheckGetMailNo = function (No) {
    if ($gameSystem.GetMailNos == undefined) $gameSystem.GetMailNos = [];
    return $gameSystem.GetMailNos.indexOf(No) == -1;
}
let CheckGetMailNo = function (No) {
    if ($gameSystem.GetMailNos == undefined) $gameSystem.GetMailNos = [];
    return $gameSystem.GetMailNos.indexOf(No) != -1;
}
Game_Interpreter.prototype.AddMail設定ツールNo = function (No) {
    if ($gameSystem.GetMailNos == undefined) $gameSystem.GetMailNos = [];
    $gameSystem.GetMailNos.push(No);
    for (let i = 0; i < $Nupu_PSData.MailDatas.length; i++) {
        var mailData = $Nupu_PSData.MailDatas[i];
        if (mailData.No == No) {
            if (mailData.OpenVNo == 0) mailData.OpenVNo = -1;
            if (mailData.OpenSetVNoValue == 0) mailData.OpenSetVNoValue = -1;
            var setPicDatas = []
            mailData.PicDatas.forEach(picData => {
                setPicDatas.push(new MailPicData(picData.PicName, picData.PicDesc));
            });
            if (mailData.ItemOpenCmnId == undefined) mailData.ItemOpenCmnId = -1;
            var addMailData = new MailData($gameSystem.AllMailList.length, mailData.Icon, mailData.Face, mailData.Name, mailData.Title, mailData.MailText, mailData.SetItemIds,
                mailData.CmnId, mailData.OpenCmnFlg, mailData.OpenVNo, mailData.OpenSetVNoValue, setPicDatas, mailData.ItemOpenCmnId
                , mailData.Important);
            addMailData.ToolNo = No;
            AddMainData(addMailData);
        }
    }
}
let NewMailCounter = function () {
    let notOpenMailCounter = 0;
    for (let i = 0; i <= $gameSystem.AllMailList.length - 1; i++) {
        if (!$gameSystem.AllMailList[i].openFlg) {
            notOpenMailCounter++;
        }
    }
    return notOpenMailCounter;
};
const MailBlinkFlame = 10;
let MailGetFlame = -1;
let MailGet_NUpdate = Game_Interpreter.prototype.NUpdate;
Game_Interpreter.prototype.NUpdate = function () {
    MailGet_NUpdate.call(this);
    if (MailGetFlame != -1) {
        if (MailGetFlame % (MailBlinkFlame * 2) == 0) {
            this.MoveSprite(PNo_MailIcon, 180, 20, MailBlinkFlame, 0);
        }
        if ((MailGetFlame + MailBlinkFlame) % (MailBlinkFlame * 2) == 0) {
            this.MoveSprite(PNo_MailIcon, 180, 20, MailBlinkFlame, 255);
        }
        MailGetFlame++;
        if (MailGetFlame == MailBlinkFlame * 17) {
            this.MoveSprite(PNo_MailIcon, 180, 20, MailBlinkFlame, 255);
            MailGetFlame = -1;
        }
    }
}
let _Mail_点滅開始 = function () {
    MailGetFlame = 0;
}
class AddressData { 
    constructor(_ViewNo, _Name, _PicName, _Tag) {
        this._ViewNo = _ViewNo; 
        this._Name = _Name; 
        this._PicName = _PicName; 
        this._PicNo = 0; 
        this._Tag = _Tag; 
        this._newFlg = true;
    }
}
let AddAddress = function (viewNo, name, picName, tag) {
    tag = typeof tag !== 'undefined' ? tag : [];
    for (let i = 0; i <= $gameSystem.AddressList.length - 1; i++) {
        if ($gameSystem.AddressList[i]._Name == name) return; 
    }
    $gameSystem.AddressList.push(
        new AddressData(viewNo, name, picName, tag)
    );
};
let CngNoAddress = function (name, picNo) {
    for (let i = 0; i <= $gameSystem.AddressList.length - 1; i++) {
        if ($gameSystem.AddressList[i]._Name == name) {
            $gameSystem.AddressList[i]._PicNo = picNo;
        }
    }
}
let ViewAddressList = []; 
let ViewAddressListSetting_Tag = function (tag) {
    tag = typeof tag !== 'undefined' ? tag : [];
    ViewAddressList = []; 
    for (let i = 0; i <= $gameSystem.AddressList.length - 1; i++) {
        let tagSkipFlg = false;
        for (let j = 0; j <= tag.length - 1; j++) {
            if ($gameSystem.AddressList[i]._Tag.indexOf(tag[j]) == -1) tagSkipFlg = true;
        }
        if (tagSkipFlg) continue; 
        let addressAddFlg = false;
        for (let j = 0; j <= ViewAddressList.length - 1; j++) {
            if ($gameSystem.AddressList[i]._newFlg) {
                ViewAddressList.unshift($gameSystem.AddressList[i]);
                addressAddFlg = true;
                break;
            }
            if (ViewAddressList[j]._ViewNo >= $gameSystem.AddressList[i]._ViewNo) {
                ViewAddressList.splice(j, 0, $gameSystem.AddressList[i]); 
                addressAddFlg = true;
                break;
            }
        }
        if (!addressAddFlg) { 
            ViewAddressList.push($gameSystem.AddressList[i]);
        }
    }
};
const TmpIconNo = 192; 
const TmpIconCo = 176; 
let AddressScroll = new N_Scroll(MenuUIPath + "Adress/M_Bar", 289, PNo_AScroll, 186 + 500, 145 + 80);
AddressScroll.ViewCount = 7;
let ViewMailList = [];
let AddressSelectNo = 0; 
let MailSelectNo = -1; 
let MailBasePostion = new Pos2D(233, 177); 
let MenuAddresMode = 0; 
Game_Interpreter.prototype.MenuAddresView = function (fadeInFlg) {
    fadeInFlg = typeof fadeInFlg !== 'undefined' ? fadeInFlg : false;
    ViewSpriteArr_Reset();
    if (fadeInFlg) { 
        ViewMailList = $gameSystem.AllMailList.slice(); 
        AddressSelectNo = 0;
        AddressScroll.ZureNo = 0;
        MailSelectNo = -1; 
    }
    D_Text_Cng_font = "Makinas";
    this.SetSprite(PNo_ABase, MenuUIPath + "Adress/M_Base", MailBasePostion._x, MailBasePostion._y);
    let newMailCounter = NewMailCounter();
    this.SpriteStrC(PNo_ListTxt, String(newMailCounter), 20, MailBasePostion._x + 318, MailBasePostion._y + 42); 
    if (ViewMailList.length > 0) {
        this.SetSprite(PNo_MSelect, MenuUIPath + "Adress/M_Selecter",
            MailBasePostion._x + 22, MailBasePostion._y + 67 + (66 * AddressSelectNo)); 
    }
    let mailSpaceY = 66; 
    for (let i = 0; i <= ViewMailList.length - 1; i++) {
        if (i >= 7) break;
        let viewMailData = ViewMailList[i + AddressScroll.ZureNo];
        this.SetSprite(PNo_MailBase + (7 * i), MenuUIPath + "Adress/M_MailBase",
            MailBasePostion._x + 30, MailBasePostion._y + 75 + (mailSpaceY * i));
        let drawIconImt = viewMailData.IconImt;
        if (viewMailData.Important) {
            if (viewMailData.openFlg) {
                if (viewMailData.TmpItemArr.length > 0 && !viewMailData.TmpOpenFlg) {
                    drawIconImt = "M_IcoMail_Ex";
                }
            } else {
                drawIconImt = "M_IcoMail_Ex";
            }
        }
        if (drawIconImt == "") drawIconImt = "M_IcoMail_Ex";
        this.SetSprite(PNo_MIcon + (7 * i), MenuUIPath + "Adress/Icon/" + drawIconImt,
            MailBasePostion._x + 30, MailBasePostion._y + 80 + (mailSpaceY * i)); 
        if (!viewMailData.openFlg) {
            this.SetSprite(PNo_NewIcon + (7 * i), MenuUIPath + "Adress/M_New",
                MailBasePostion._x + 30, MailBasePostion._y + 75 + (mailSpaceY * i));
        } else {
            this.DelSprite(PNo_NewIcon + (7 * i));
        }
        let outLineStr = "\\oc[rgb(0,0,0)]\\ow[1] "; 
        this.SpriteStr(PNo_From + (7 * i), outLineStr + viewMailData.MTitle, 20,
            MailBasePostion._x + 135, MailBasePostion._y + 80 + (mailSpaceY * i));
        this.SpriteStr(PNo_SubTxt + (7 * i), outLineStr + viewMailData.ChrStr, 14,
            MailBasePostion._x + 135, MailBasePostion._y + 111 + (mailSpaceY * i));
        if (viewMailData.TmpItemArr.length > 0) {
            this.SpriteStrC(PNo_TmpIcon + (7 * i), "\\I[" + TmpIconNo + "]", 22,
                MailBasePostion._x + 563, MailBasePostion._y + 113 + (mailSpaceY * i));
            let tmpItemCount = TmpIconCo + viewMailData.TmpItemArr.length - 1;
            this.SpriteStrC(PNo_TmpSu + (7 * i), "\\I[" + tmpItemCount + "]", 22,
                MailBasePostion._x + 563 + 5, MailBasePostion._y + 113 + (mailSpaceY * i));
        } else {
            this.DelSprite(PNo_TmpIcon + (7 * i));
            this.DelSprite(PNo_TmpSu + (7 * i));
        }
    }
    this.SetSprite(PNo_Top, MenuUIPath + "Adress/M_Top", MailBasePostion._x + 643, MailBasePostion._y + 68);
    this.SetSprite(PNo_Down, MenuUIPath + "Adress/M_Down", MailBasePostion._x + 643, MailBasePostion._y + 480);
    for (let i = 0; i <= ViewSpriteArr.length - 1; i++) {
        this.MoveSprite(ViewSpriteArr[i], true, true, 10);
    }
    AddressScroll.posX = MailBasePostion._x + 644;
    AddressScroll.posY = MailBasePostion._y + 100;
    AddressScroll.ItemCount = ViewMailList.length;
    this.ScrollView(AddressScroll, 255);
    this.SetSpriteC(PN_AdListBtn, MenuUIPath + "Adress/M_IAdrBtn", MailBasePostion._x + 522, MailBasePostion._y + 42);
    D_Text_Cng_font = "";
};
Game_Interpreter.prototype.CloseMail = function () {
    try {
        let setCmnEvNo = ViewMailList[MailSelectNo].ClsCmn;
        if (ViewMailList[MailSelectNo].FstClsCmnFlg) {
            if (MMailFstOpen) {
                if (setCmnEvNo != -1) this.SetCmnEventSc(setCmnEvNo); 
            }
        } else {
            if (setCmnEvNo != -1) this.SetCmnEventSc(setCmnEvNo); 
        }
    } catch (ex) {
    }
    MailSelectNo = -1;
    MenuAddresMode = 0;
    DelSpriteSpan(PN_MailBlackT , PN_M_ClipTxt + 2);
    DelPictSpan(PN_MailBlackT , PN_M_ClipTxt + 2);
    ViewSpriteArr_Reset();
    this.MenuAddresView();
};
let TstCC = 0;
Game_Interpreter.prototype.MenuAddressUpdate = function () {
    if (MenuModeStr == _MMode.TalkMode) return; 
    if (Tutorial_SetuNo > 7 && IsTutorial) return; 
    switch (MenuAddresMode) {
        case 0: 
            this.MenuAddress_SelectUpdate();
            break;
        case 1: 
            this.MenuAddress_MailUpdate();
            break;
        case 12: 
            this.MenuAddress_MailOpenUpdate();
            break;
        case 2: 
            this.Addres_Mode2_Update();
            break;
    }
};
let MenuAddress_SelectUpdateSkipFrame = 0;
Game_Interpreter.prototype.MenuAddress_SelectUpdate = function () {
    if (MenuAddress_SelectUpdateSkipFrame > 0) {
        MenuAddress_SelectUpdateSkipFrame--;
        return;
    }
    MenuCngOkFlg = true; 
    let overPicArr = [
        PNo_MailBase, PNo_Top, PNo_Down, PNo_MailCBtn, PN_AdListBtn];
    for (let i = 0; i <= overPicArr.length - 1; i++) {
        this.SpriteCngColor(overPicArr[i]);
    }
    for (let i = 1; i <= 6; i++) {
        overPicArr.push(PNo_MailBase + (7 * i)); 
    }
    let overPicNo = overPointerSpCkArr(overPicArr);
    switch (overPicNo) {
        case PNo_MailBase + (7 * 0):
        case PNo_MailBase + (7 * 1):
        case PNo_MailBase + (7 * 2):
        case PNo_MailBase + (7 * 3):
        case PNo_MailBase + (7 * 4):
        case PNo_MailBase + (7 * 5):
        case PNo_MailBase + (7 * 6):
            let ckPicNo = overPicNo - PNo_MailBase;
            let selectNo = Math.round(ckPicNo / 7);
            if (AddressSelectNo != selectNo) { 
                AddressSelectNo = selectNo;
                this.MenuAddresView();
            }
            if (TouchInput.isTriggered()) {
                if (menuAutoCloseFlame > 0) {
                    menuAutoCloseFlame = 1;
                    return;
                }
                SoundManager.playOk(); 
                MailSelectNo = AddressSelectNo + AddressScroll.ZureNo; 
                Menu_EditLayer = 2; 
                SoundManager.playOk();
                MenuAddresMode = 1;
                this.Addres_Mode1_View(); 
            }
            break;
        case PN_AdListBtn: 
            this.SpriteCngColor(PN_AdListBtn, [100, 100, 100, 0]);
            if (TouchInput.isTriggered()) {
                if (menuAutoCloseFlame > 0) {
                    menuAutoCloseFlame = 1;
                    return;
                }
                SoundManager.playOk(); 
                this.SpriteCngColor(PN_AdListBtn);
                Menu_EditLayer = 2; 
                MenuAddresMode = 2;
                ViewAddressNo = -1; 
                this.Addres_Mode2_View(); 
            }
            break;
    }
    if (TouchInput.wheelY > 0) {
        AddressScroll.ZureAdd(+1);
        this.MenuAddresView();
        SoundManager.playCursor();
    } else if (TouchInput.wheelY < 0) {
        AddressScroll.ZureAdd(-1);
        this.MenuAddresView();
        SoundManager.playCursor();
    }
}
let OpenMailToolNo = -1;
let MMailFstOpen = false; 
Game_Interpreter.prototype.Addres_Mode1_View = function () {
    D_Text_Cng_font = "Makinas";
    MMailFstOpen = false;
    if (MailSelectNo != -1) {
        if ($gameSystem.AllMailList[MailSelectNo].openFlg == false) {
            MMailFstOpen = true;
        }
        $gameSystem.AllMailList[MailSelectNo].openFlg = true;
        ViewMailList[MailSelectNo].openFlg = true;
        if ($gameSystem.AllMailList[MailSelectNo].ToolNo == undefined) $gameSystem.AllMailList[MailSelectNo].ToolNo = -1;
        OpenMailToolNo = $gameSystem.AllMailList[MailSelectNo].ToolNo;
    }
    let _SetVNNo = ViewMailList[MailSelectNo].OpnVarNo;
    let _SetVNVar = ViewMailList[MailSelectNo].OpnSetVar;
    if (ViewMailList[MailSelectNo].FstClsCmnFlg) {
        if (MMailFstOpen) {
            if (_SetVNNo != -1) $gameVariables.setValue(_SetVNNo, _SetVNVar);
        }
    } else {
        if (_SetVNNo != -1) $gameVariables.setValue(_SetVNNo, _SetVNVar);
    }
    this.SetSprite(PN_MailBlackT, "Black", 0, 0, 150);
    let _MNPos = new Pos2D(MailBasePostion._x + 50, MailBasePostion._y - 25); 
    this.SetSprite(PNo_MailBack, MenuUIPath + "Adress/M_NBase", _MNPos._x, _MNPos._y);
    this.SetSprite(PNo_MailFace, MenuUIPath + "Adress/Face/" + ViewMailList[MailSelectNo].FaceImg
        , _MNPos._x + 36, _MNPos._y + 31);
    this.SpriteStr(PNo_MailFrom, ViewMailList[MailSelectNo].MTitle, 22
        , _MNPos._x + 137, _MNPos._y + 49);
    this.SpriteStr(PNo_MailTitle, ViewMailList[MailSelectNo].ChrStr, 17
        , _MNPos._x + 161, _MNPos._y + 84);
    if (!ViewMailList[MailSelectNo].TmpOpenFlg) {
        if (ViewMailList[MailSelectNo].TmpItemArr.length > 0) {
            this.SetSprite(PNo_MailTmp, MenuUIPath + "Adress/M_NTenpu"
                , _MNPos._x + 421, _MNPos._y + 20);
            this.SpriteStrC(PNo_MailTmpC
                , " " + SCol.Blk0 + String(ViewMailList[MailSelectNo].TmpItemArr.length) + " ", 22,
                _MNPos._x + 519, _MNPos._y + 49);
        }
    }
    let _MailStrArr = ViewMailList[MailSelectNo].MNaiyo.split("\n");
    try { 
        this.SpriteStr(PNo_MailStr, ViewMailList[MailSelectNo].MNaiyo, 19, _MNPos._x + 40, _MNPos._y + 150);
    } catch (e) {
        console.log(e);
    }
    var picCnt = 0;
    for (let i = 0; i < ViewMailList[MailSelectNo].PicData.length; i++) {
        var picData = ViewMailList[MailSelectNo].PicData[i];
        var posX = 347 + picCnt * 160;
        var picScale = 148 / 675 * 100;
        this.SetSprite(PN_MPic + picCnt, MenuUIPath + "Adress/Picture/" + picData.PicName, posX, 534,
            255, picScale, picScale);
        this.SetSprite(PN_M_Clip + picCnt, MenuUIPath + "Adress/PN_M_Clip", posX - 5, 534 - 16);
        this.SpriteStr(PN_M_ClipTxt + picCnt, picData.PicDesc, 18, posX + 19, 534 - 21);
        picCnt++;
    }
    this.SetSprite(PNo_MailCBtn, MenuUIPath + "Adress/M_CloseBtn", _MNPos._x + 225, _MNPos._y + 500);
    D_Text_Cng_font = "";
}
let MailPictureViewMode = false;
let MailPictureVeiwMode_Flame = 0;
let MenuAddress_MailUpdateSkipFrame = 0;
Game_Interpreter.prototype.MenuAddress_MailUpdate = function () {
    if (MailPictureViewMode) {
        MailPictureVeiwMode_Flame++
        if (MailPictureVeiwMode_Flame > 10) {
            let exitFlg = false;
            if (TouchInput.isTriggered()) {
                Menu_EditLayer--;
                exitFlg = true;
            }
            if (Input.isTriggered('menu') || TouchInput.isCancelled() || exitFlg) {
                this.DelSpriteSpan(PN_MPicBase, PN_MPicView);
                MailPictureViewMode = false;
            }
        }
        return;
    }
    MenuCngOkFlg = false; 
    let _cancelBtnFlg = false;
    let _OverPicNoArr = [PNo_MailCBtn, PNo_MailTmp];
    for (let k = 0; k <= _OverPicNoArr.length - 1; k++) {
        this.SpriteCngColor(_OverPicNoArr[k]);
    }
    _OverPicNo = overPointerSpCkArr(_OverPicNoArr);
    switch (_OverPicNo) {
        case PNo_MailTmp: 
            this.SpriteCngColor(PNo_MailTmp, [0, 150, 0, 0]);
            if (TouchInput.isTriggered()) {
                if (menuAutoCloseFlame > 0) {
                    menuAutoCloseFlame = 1;
                    return;
                }
                SoundManager.playOk(); 
                Menu_EditLayer = 2;
                MenuAddresMode = 12; 
                this.Addres_Mode12_View();
            }
            break;
        case PNo_MailCBtn: 
            this.SpriteCngColor(PNo_MailCBtn, [100, 100, 100, 0]);
            if (TouchInput.isTriggered()) {
                MenuAddress_SelectUpdateSkipFrame = 2;
                if (menuAutoCloseFlame > 0) {
                    menuAutoCloseFlame = 1;
                    return;
                }
                SoundManager.playOk(); 
                Menu_EditLayer = 1; 
                SoundManager.playCancel();
                _cancelBtnFlg = true; 
            }
            break;
    }
    let _CkMPArr = [PN_MPic, PN_MPic + 1, PN_MPic + 2];
    this.SpriteCngColorArr(_CkMPArr);
    _CNo = overPointerSpCkArr(_CkMPArr);
    if (_CNo != -1) {
        this.SpriteCngColor(_CNo, [100, 100, 100, 0]);
        var picNo = _CNo - PN_MPic;
        if (TouchInput.isTriggered()) {
            var picData = ViewMailList[MailSelectNo].PicData[picNo];
            MailPictureViewMode = true;
            MailPictureVeiwMode_Flame = 0;
            this.SetSpriteFIn(PN_MPicBase, MenuUIPath + "Adress/PN_MPicBase", 0, 0, 0, 0, 10);
            this.SetSpriteFIn(PN_MPicView, MenuUIPath + "Adress/Picture/" + picData.PicName, 254, 199, 0, 0, 10);
            this.SpriteStr(PN_MPicTxt, picData.PicDesc, 22, 254 + 34, 199 - 32);
            Menu_RclickStopFlame = 15;
            Menu_EditLayer++;
        }
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled() || _cancelBtnFlg) {
        if (menuAutoCloseFlame > 0) {
            menuAutoCloseFlame = 1;
            return;
        }
        if (Tutorial_ClickPN != -1) return false; 
        this.CloseMail();
    }
};
let Addres_Opnflame = 0;
let Addres_Mode12_flame = 0;
Game_Interpreter.prototype.Addres_Mode12_View = function () {
    Addres_Mode12_flame = 0;
    this.SetSpriteFIn(PN_MOpenWin, MenuUIPath + "Adress/PN_MOpenWin", 0, 0, 0, 0, 10);
    this.SetSpriteFIn(PN_MOpenBtn, MenuUIPath + "Adress/PN_MOpenBtn", 488, 448, 0, 0, 10);
    this.SetSpriteFIn(PN_MNotBtn, MenuUIPath + "Adress/PN_MNotBtn", 488 + 173, 448, 0, 0, 10);
    this.SpriteStrC(PN_MCntTxt
        , " " + SCol.Blk0 + String(ViewMailList[MailSelectNo].TmpItemArr.length) + " ", 22,
        679, 297);
    Addres_Opnflame = 0;
}
Game_Interpreter.prototype.MenuAddress_MailOpenUpdate = function () {
    if (Addres_Opnflame > 0) {
        if (Addres_Opnflame == 5) {
            D_Text_Cng_font = "Makinas";
            let _bsX = 502;
            let _bsY = 243;
            for (let i = 0; i <= ViewMailList[MailSelectNo].TmpItemArr.length - 1; i++) {
                let _GetItmId = ViewMailList[MailSelectNo].TmpItemArr[i];
                let _GetItmData = $dataItems[_GetItmId];
                let _ViewTxt = " \\I[" + _GetItmData.iconIndex + "] " + _GetItmData.name;
                $gameParty.gainItem($dataItems[_GetItmId], 1);
                this.SpriteStr(PN_MImtGetTxt + i, _ViewTxt, 25, _bsX, _bsY + i * 40, 255);
            }
            D_Text_Cng_font = "";
        }
        if (Addres_Opnflame > 10) {
            if (TouchInput.isTriggered()) { 
                Menu_RclickStopFlg = false;
                if (menuAutoCloseFlame > 0) {
                    menuAutoCloseFlame = 1;
                    return;
                }
                MenuAddresMode = 1;
                this.DelSpriteSpan(PN_MOpenWin, PN_MImtGetTxt + 5);
                for (let i = 0; i <= $gameSystem.AllMailList.length - 1; i++) {
                    if ($gameSystem.AllMailList[i].No == ViewMailList[MailSelectNo].No) {
                        $gameSystem.AllMailList[i].TmpItemArr = [];
                        if ($gameSystem.AllMailList[i].ItemOpenCmn > 0) {
                            this.SetCmnEventSc($gameSystem.AllMailList[i].ItemOpenCmn);
                        }
                    }
                }
                this.DelSprite(PNo_MailTmp);
                this.DelSprite(PNo_MailTmpC);
            }
        }
        Addres_Opnflame++;
        return;
    }
    let _CkMPArr = [PN_MOpenBtn, PN_MNotBtn];
    if (Addres_Mode12_flame > 10) {
        this.SpriteCngColorArr(_CkMPArr);
        let _CNo = overPointerSpCkArr(_CkMPArr);
        if (_CNo != -1) {
            this.SpriteCngColor(_CNo, [100, 100, 100, 0]);
            if (TouchInput.isTriggered()) {
                if (menuAutoCloseFlame > 0) {
                    menuAutoCloseFlame = 1;
                    return;
                }
                if (_CNo == PN_MOpenBtn) {
                    Addres_Opnflame = 1;
                    Menu_RclickStopFlg = true;
                    this.SetSpriteFIn(PN_MItmGetWin, MenuUIPath + "Adress/PN_MItmGetWin", 0, 0, 0, 0, 10);
                    this.PlayPtcPic("CCRea1", 646, 321);
                    this.PlaySe("itemgetbgm");
                }
                if (_CNo == PN_MNotBtn) {
                    MenuAddresMode = 1;
                    MenuCngOkFlg = true;
                    this.DelSpriteSpan(PN_MOpenWin, PN_MNotBtn);
                }
            }
        }
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled()) {
        if (menuAutoCloseFlame > 0) {
            menuAutoCloseFlame = 1;
            return;
        }
        if (Tutorial_ClickPN != -1) return false;
        MenuAddresMode = 1;
        MenuCngOkFlg = true;
        this.DelSpriteSpan(PN_MOpenWin, PN_MNotBtn);
    }
    Addres_Mode12_flame++;
}
let AddressTagClickMapArr = [
    [84, 68, 65, 25],
    [188, 68, 65, 25],
    [287, 68, 65, 25]
];
let AddressPos = new Pos2D(208, 80);
let AddressTagStr = ""; 
let AddressOverPicArr = [];
let AddressTagNo = -1; 
Game_Interpreter.prototype.Addres_Mode2_View = function (_Tag, _TSPos) {
    _Tag = typeof _Tag !== 'undefined' ? _Tag : [];
    _TSPos = typeof _TSPos !== 'undefined' ? _TSPos : -1;
    D_Text_Cng_font = "Makinas";
    this.SetSprite(PN_MailBlackB, "Black", 0, 0, 150);
    this.SetSprite(PN_AdBase, MenuUIPath + "Adress/Ad_Base", AddressPos._x, AddressPos._y);
    if (_TSPos == -1) { 
        this.SetSpriteC(PN_AdTagSel, MenuUIPath + "Adress/Ad_TagSelect",
            AddressPos._x + 115 + (103 * 0), AddressPos._y + 80);
    } else {
        this.MoveSprite(PN_AdTagSel, AddressPos._x + 115 + (103 * _TSPos),
            AddressPos._y + 80, 5);
    }
    AddressOverPicArr = [];
    ViewAddressListSetting_Tag(_Tag); 
    for (let i = 0; i <= ViewAddressList.length - 1; i++) {
        let _SetName = ViewAddressList[i]._Name;
        for (let j = ViewAddressList[i]._Name.length; j <= 16; j++) {
            _SetName += "　";
        }
        this.SpriteStr(PN_AdStr + i, _SetName, 24, AddressPos._x + 62, AddressPos._y + 110 + (32 * i));
        if (ViewAddressList[i]._newFlg) {
            this.SetSprite(PN_AdTag + i, MenuUIPath + "Adress/M_New",
                AddressPos._x + 16, AddressPos._y + 106 + (32 * i));
        }
        AddressOverPicArr.push(PN_AdStr + i); 
        if (i == 14) break;
    }
    this.SetSpriteC(PN_AdClsBtn, MenuUIPath + "Adress/M_CloseBtn", AddressPos._x + 803, AddressPos._y + 41);
    AddressOverPicArr.push(PN_AdClsBtn); 
    D_Text_Cng_font = "";
}
let ViewAddressNo = -1; 
Game_Interpreter.prototype.Addres_Mode2_Update = function () {
    MenuCngOkFlg = false; 
    let cancelBtnFlg = false;
    this.DelSprite(PN_AdSelecter); 
    this.SpriteCngColor(PN_AdClsBtn);
    let overPicNo = overPointerSpCkArr(AddressOverPicArr);
    if (overPicNo != -1) {
        switch (overPicNo) {
            case PN_AdClsBtn: 
                this.SpriteCngColor(PN_AdClsBtn, [100, 100, 100, 0]);
                if (TouchInput.isTriggered()) {
                    if (menuAutoCloseFlame > 0) {
                        menuAutoCloseFlame = 1;
                        return;
                    }
                    SoundManager.playOk(); 
                    cancelBtnFlg = true;
                }
                break;
            default:
                let selectNo = overPicNo - PN_AdStr;
                this.SetSprite(PN_AdSelecter, MenuUIPath + "Adress/Ad_Selecter",
                    AddressPos._x + 50, AddressPos._y + 102 + (32 * selectNo));
                if (TouchInput.isTriggered()) { 
                    if (menuAutoCloseFlame > 0) {
                        menuAutoCloseFlame = 1;
                        return;
                    }
                    SoundManager.playOk(); 
                    for (let i = 0; i <= $gameSystem.AddressList.length - 1; i++) {
                        if (ViewAddressList[selectNo]._Name == $gameSystem.AddressList[i]._Name) {
                            $gameSystem.AddressList[i]._newFlg = false; 
                        }
                    }
                    this.DelSprite(PN_AdTag + selectNo);
                    let vierPicName = ViewAddressList[selectNo]._PicName + ViewAddressList[selectNo]._PicNo;
                    this.SetSprite(PN_AdChrDate, MenuUIPath + "Adress/ListChara/" + vierPicName,
                        AddressPos._x + 414, AddressPos._y + 92, 0);
                    this.MoveSprite(PN_AdChrDate, AddressPos._x + 414, AddressPos._y + 82, 10)
                    this.SetSprite(PN_AdViewP, MenuUIPath + "Adress/M_AdViewPoint",
                        AddressPos._x + 50, AddressPos._y + 100 + (32 * selectNo));
                }
                break;
        }
    }
    let overClickMapNo = overSpriteClickable(PN_AdBase, AddressTagClickMapArr);
    if (overClickMapNo != -1) {
        if (TouchInput.isTriggered()) { 
            if (menuAutoCloseFlame > 0) {
                menuAutoCloseFlame = 1;
                return;
            }
            SoundManager.playOk(); 
            switch (overClickMapNo) {
                case 0: 
                    this.Layer1_DelTop(PN_AdSelecter);
                    this.Addres_Mode2_View([], 0);
                    break;
                case 1: 
                    this.Layer1_DelTop(PN_AdSelecter);
                    this.Addres_Mode2_View(["male"], 1);
                    break;
                case 2: 
                    this.Layer1_DelTop(PN_AdSelecter);
                    this.Addres_Mode2_View(["female"], 2);
                    break;
            }
        }
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled() || cancelBtnFlg) {
        this.Layer1_DelTop();
        this.CloseMail();
    }
}
