const ItmMaxView = 9;   
let MenuItemMode = 0;       
let Menu_ItemMode = 0; 
let menuListSelectNo = -1;  
let menuItemSelectNo = -1;  
let menuItemCkPicArr = []; 
let menuItemList = [];      
let menuItemUseFlame = 0; 
Game_Interpreter.prototype.ItemUseFlameCk = function () { 
    if (Tutorial_ClickPN != -1) return false;
    if (this._list != null) { 
        Menu_RclickStopFlg = true; 
        return true;
    }
    if (menuItemUseFlame > 0) {
        menuItemUseFlame--;
        Menu_RclickStopFlg = true; 
        return true;
    } else {
        Menu_RclickStopFlg = false; 
        return false;
    }
}
let menuItemView_flame = 0;
Game_Interpreter.prototype.MenuItemView = function (fadeInFlg) {
    fadeInFlg = typeof fadeInFlg !== 'undefined' ? fadeInFlg : false;
    ViewSpriteArr_Reset();
    let setOpacity = 255;
    if (fadeInFlg) {
        menuItemView_flame = 0;
        Menu_ItemMode = 0;
        setOpacity = 0;
        menuListSelectNo = -1; 
    }
    D_Text_Cng_font = "Makinas"; 
    this.SetSprite(PNo_IBase, MenuUIPath + "Item/IBase", 222, 192, setOpacity);
    this.SetSprite(PNo_ItemBtn + 0, MenuUIPath + "Item/IBtn1a", 271, 206, setOpacity);
    this.SetSprite(PNo_ItemBtn + 1, MenuUIPath + "Item/IBtn2a", 451, 206, setOpacity);
    this.SetSprite(PNo_ItemBtn + 2, MenuUIPath + "Item/IBtn3a", 631, 206, setOpacity);
    let _BtnStr = "IBtn" + String(MenuItemMode + 1) + "b"; 
    this.SetSprite(PNo_ItemBtn + MenuItemMode, MenuUIPath + "Item/" + _BtnStr, 271 + (180 * MenuItemMode), 206, setOpacity);
    switch (MenuItemMode) { 
        case 0: 
            this.ItemListSet(1);
            break;
        case 1: 
            this.ItemListSet(3); 
            break;
        case 2: 
            this.ItemListSet(2);
            break;
    }
    for (let i = 0; i <= ItmMaxView - 1; i++) { 
        this.DelSprite(PNo_ItemTxt + i);
        this.DelSprite(PNo_ICountTxt + i);
    }
    menuItemCkPicArr = [];
    menuItemCkPicArr.push(PNo_ItemBtn + 0); 
    menuItemCkPicArr.push(PNo_ItemBtn + 1); 
    menuItemCkPicArr.push(PNo_ItemBtn + 2); 
    for (let i = 0; i <= menuItemList.length - 1; i++) {
        let setIconNo = $dataItems[menuItemList[i][0]].iconIndex;
        let itemName = $dataItems[menuItemList[i][0]].name;
        for (let _s = itemName.length; _s <= 10; _s++) itemName += "　"; 
        this.SpriteStr(PNo_ItemTxt + i, "\\I[" + setIconNo + "] " + itemName, 24, 266, 311 + (41 * i), setOpacity);
        menuItemCkPicArr.push(PNo_ItemTxt + i); 
        if (menuItemList[i][1] > 1) {
            this.SpriteStr(PNo_ICountTxt + i, "×" + menuItemList[i][1], 24, 569, 311 + (41 * i), setOpacity);
        }
        if (!$dataItems[menuItemList[i][0]].consumable) { 
            this.SpriteStr(PNo_ICountTxt + i, "", 24, 569, 311 + (41 * i), setOpacity);
        }
        if (i >= (ItmMaxView - 1)) break; 
    }
    for (let i = 0; i <= ViewSpriteArr.length - 1; i++) {
        this.MoveSprite(ViewSpriteArr[i], true, true, 10);
    }
    D_Text_Cng_font = ""; 
    this.ItemBtlSetting(setOpacity);
    if (Item重要DrawFlg || Item消費DrawFlg) {
        let DrawImage = MenuUIPath + "Item/PN_IIsyoWin";
        if (Item消費DrawFlg) DrawImage = MenuUIPath + "Item/PN_SozaiWin";
        this.SetSprite(PN_IIsyoWin, DrawImage, 0, 0);
        let isyoCnt = 0;
        let isyoZureY = 26;
        function GetIsyoY() {
            let rtnY = 530 + (isyoZureY * isyoCnt);
            isyoCnt++;
            return rtnY;
        }
        function GetSozaiY() {
            let rtnY = 530 + ((isyoZureY + 10) * isyoCnt);
            isyoCnt++;
            return rtnY;
        }
        if (Item重要DrawFlg) {
            if ($gameSwitches.value(SW_衣装水着所持))
                this.SpriteStr(PN_IIsyoTxt + isyoCnt, "・水着データ", 16, 754, GetIsyoY());
            if ($gameSwitches.value(SW_衣装寝間着所持))
                this.SpriteStr(PN_IIsyoTxt + isyoCnt, "・寝間着データ", 16, 754, GetIsyoY());
            if ($gameSwitches.value(SW_衣装民族衣装所持))
                this.SpriteStr(PN_IIsyoTxt + isyoCnt, "・民族衣装データ", 16, 754, GetIsyoY());
            if ($gameSwitches.value(SW_衣装バニー所持))
                this.SpriteStr(PN_IIsyoTxt + isyoCnt, "・バニーデータ", 16, 754, GetIsyoY());
        }
        if (Item消費DrawFlg) {
            this.DelSpriteSpan(PN_IIsyoTxt + 0 , PN_IIsyoTxt + 3);
            for (let i = 0; i < 4; i++) {
                let ckWeaponData = $dataWeapons[201 + i];
                if ($gameParty.numItems(ckWeaponData) > 0) {
                    let setIconNo = ckWeaponData.iconIndex;
                    this.SpriteStr(PN_IIsyoTxt + isyoCnt, "\\I[" + setIconNo + "]" + ckWeaponData.name + " × " +
                        $gameParty.numItems(ckWeaponData), 24, 754, GetSozaiY() , 255 , 75 , 75);
                }
            }
        }
    } else {
        this.DelSpriteSpan(PN_IIsyoWin , PN_IIsyoTxt + 4);
    }
}
Game_Interpreter.prototype.ItemBtlSetting = function (setOpacity) {
    if ($gameSystem.SetAdSys == undefined) $gameSystem.SetAdSys = [];
    for (let i = 0; i <= $gameSystem.SetAdSys.length - 1; i++) {
        if ($gameSystem.SetAdSys[i] == -1) {
            this.SetSprite(PN_IBtlAddImg + i, MenuUIPath + "Item/PN_IBtlAddImg_0",
                905, 277 + 54 * i, setOpacity);
            this.MoveSprite(PN_IBtlAddImg + i, true, true, 10);
            this.DelSprite(PN_IBtlIco + i);
        } else {
            let ckCount = $gameParty.numItems($dataItems[$gameSystem.SetAdSys[i]]);
            let iconId = $dataItems[$gameSystem.SetAdSys[i]].iconIndex;
            let setIconStr = "\\I[" + iconId + "]\n";
            DText_NRZureY = -80; 
            this.SpriteStr(PN_IBtlIco + i, setIconStr, 32, 915, 285 + (54 * i), setOpacity);
            DText_NRZureY = 0; 
            this.MoveSprite(PN_IBtlIco + i, true, true, 10);
            this.SetSprite(PN_IBtlAddImg + i, MenuUIPath + "Item/PN_IBtlAddImg_1",
                905, 277 + (54 * i), setOpacity);
            this.MoveSprite(PN_IBtlAddImg + i, true, true, 10);
        }
    }
}
let Item消費DrawFlg = false;
let Item重要DrawFlg = false;
Game_Interpreter.prototype.ItemListSet = function (itemType) {
    Item消費DrawFlg = itemType == 1;
    Item重要DrawFlg = itemType == 2;
    menuItemList = [];
    for (let i = 1; i <= $dataItems.length - 1; i++) {
        if (BtlItemCheck(i)) continue; 
        if ($dataItems[i].itypeId == itemType) { 
            let _ItemCount = $gameParty.numItems($dataItems[i]);
            if (_ItemCount > 0) {
                menuItemList.push([i, _ItemCount]);
            }
        }
    }
}
Game_Interpreter.prototype.MenuItemUpdate = function () {
    if (menuItemView_flame == 1) this.MenuItemView(); 
    switch (Menu_ItemMode) {
        case 0: 
            this.MenuItem_SelectUpdate();
            break;
        case 1: 
            this.MenuItem_UseCheckUpdate();
            break;
        case 10: 
            this.MenuItem_CubeUseUpdate();
            break;
    }
    menuItemView_flame++;
}
let overMenuItemNo = -1;
Game_Interpreter.prototype.MenuItem_SelectUpdate = function () {
    if (Item_BtlSelect_Flg) {
        this.MenuItem_BtlSelectUpdate();
        return;
    }
    if (this.ItemUseFlameCk()) return; 
    MenuCngOkFlg = true; 
    let overPicNo = overPointerSpCkArr(menuItemCkPicArr);
    let itemSpriteCngColor = [PNo_ItemBtn + 0, PNo_ItemBtn + 1, PNo_ItemBtn + 2];
    for (let i = 0; i <= itemSpriteCngColor.length - 1; i++) {
        this.SpriteCngColor(itemSpriteCngColor[i]);
    }
    let _setuDrawFlg = false;
    if (overPicNo != -1) {
        _setuDrawFlg = true;
        switch (overPicNo) {
            case PNo_ItemBtn + 0: 
            case PNo_ItemBtn + 1: 
            case PNo_ItemBtn + 2: 
                if (MenuItemMode == overPicNo - PNo_ItemBtn) break; 
                this.SpriteCngColor(overPicNo, [100, 100, 100, 0]);
                if (TouchInput.isTriggered()) { 
                    if (menuAutoCloseFlame > 0) {
                        menuAutoCloseFlame = 1;
                        return;
                    }
                    MenuItemMode = overPicNo - PNo_ItemBtn;
                    this.MenuItemView();
                    SoundManager.playOk(); 
                }
                break;
            default: 
                if (overMenuItemNo != overPicNo - PNo_ItemTxt) SoundManager.playCursor();
                overMenuItemNo = overPicNo - PNo_ItemTxt;
                menuListSelectNo = overMenuItemNo;
                this.MenuItem_SetuView(menuListSelectNo);
                if (TouchInput.isTriggered()) { 
                    if (menuAutoCloseFlame > 0) {
                        menuAutoCloseFlame = 1;
                        return;
                    }
                    SoundManager.playOk(); 
                    this.MenuItem_UseCheckStart();
                    Menu_ItemMode = 1;
                    Menu_EditLayer = 2; 
                }
        }
    } else {
        overMenuItemNo = -1;
        this.DelSpriteArr(Item_SetDelPicArr);
    }
    let btlItemClickMap = [
        [669, 92 + 54 * 0, 129, 42],
        [669, 92 + 54 * 1, 129, 42],
        [669, 92 + 54 * 2, 129, 42]
    ];
    let clickMapNo = overSpriteClickable(PNo_IBase, btlItemClickMap);
    if (clickMapNo != -1) {
        if ($gameSystem.SetAdSys[clickMapNo] == -1) {
            this.SetSprite(PN_IBtlSelect, MenuUIPath + "Item/PN_IBtlSelect_0",
                904, 276 + 54 * clickMapNo);
        } else {
            this.SetSprite(PN_IBtlSelect, MenuUIPath + "Item/PN_IBtlSelect_1",
                904, 276 + 54 * clickMapNo);
            _setuDrawFlg = true;
            this.MenuItem_SetuDraw($gameSystem.SetAdSys[clickMapNo], 324, 207 + (clickMapNo * 54));
        }
        if (TouchInput.isTriggered()) { 
            if (menuAutoCloseFlame > 0) {
                menuAutoCloseFlame = 1;
                return;
            }
            Item_Btl変更中No = clickMapNo;
            SoundManager.playCursor();
            this.MenuItem_SelectStart();
        }
    } else {
        this.DelSprite(PN_IBtlSelect);
    }
    if (!_setuDrawFlg) {
        let dellPicArr = [PNo_UseWin , PNo_UseTxt , PNo_USetuTxt + 0, PNo_USetuTxt + 1, PNo_USetuTxt + 2, PNo_USetuTxt + 3];
        this.DelSpriteArr(dellPicArr); 
    }
}
let Item_BtlSelect_Flg = false;
let Item_BtlSelect_Arr = [];
let Item_BtlGetArr = []; 
let Item_Btl変更中No = 0;
Game_Interpreter.prototype.MenuItem_SelectStart = function () {
    Item_BtlGetArr = [];
    Item_BtlSelect_Flg = true;
    SoundManager.playCursor();
    this.SetSprite(PN_IBtlBlack, MenuUIPath + "Item/PN_IBtlBlack", 0, 0, 0);
    this.MoveSprite(PN_IBtlBlack, true, true, 10);
    let ckCounter = 0;
    Item_BtlSelect_Arr = [];
    for (let i = 0; i <= btlItemDatas.length - 1; i++) {
        if (btlItemDatas[i]._No < 7) continue;
        if ($gameSystem.SetAdSys.indexOf(btlItemDatas[i]._No) != -1) continue;
        let itemCount = $gameParty.numItems($dataItems[btlItemDatas[i]._No]);
        if (itemCount > 0) {
            let iconId = $dataItems[btlItemDatas[i]._No].iconIndex;
            let setName = btlItemDatas[i]._name + "\n";
            setName += "　　　　　　　　　　    ";
            DText_NRZureY = -64;
            this.SpriteStr(PN_IBtlSelTxt + ckCounter,
                "\\I[" + iconId + "] " + setName,
                24, 490, 126 + 40 * ckCounter, 0);
            DText_NRZureY = 0;
            this.MoveSprite(PN_IBtlSelTxt + ckCounter, true, true, 10);
            Item_BtlSelect_Arr.push(PN_IBtlSelTxt + ckCounter);
            Item_BtlGetArr.push(btlItemDatas[i]._No);
            ckCounter++;
        }
    }
    if ($gameSystem.SetAdSys[Item_Btl変更中No] != -1) {
        this.SpriteStr(PN_IBtlSelTxt + ckCounter, "はずす",
            24, 490, 126 + 40 * ckCounter, 0);
        this.MoveSprite(PN_IBtlSelTxt + ckCounter, true, true, 10);
        Item_BtlSelect_Arr.push(PN_IBtlSelTxt + ckCounter);
        Item_BtlGetArr.push(-1);
    }
    D_Text_Cng_font = "";
}
Game_Interpreter.prototype.MenuItem_BtlSelectUpdate = function () {
    let btlItemClickMap = [];
    for (let i = 0; i <= 15 - 1; i++) {
        btlItemClickMap.push([485, 126 + (i * 40), 333, 32]);
    }
    this.SpriteCngColorArr(Item_BtlSelect_Arr);
    let clickMapNo = overSpriteClickable(PN_IBtlBlack, btlItemClickMap);
    if (clickMapNo != -1 && Item_BtlGetArr.length > clickMapNo) {
        this.SpriteCngColor(PN_IBtlSelTxt + clickMapNo, [150, 150, 150, 0]);
        this.MenuItem_SetuView(clickMapNo, true);
        if (TouchInput.isTriggered()) {
            if (menuAutoCloseFlame > 0) {
                menuAutoCloseFlame = 1;
                return;
            }
            $gameSystem.SetAdSys[Item_Btl変更中No] = Item_BtlGetArr[clickMapNo];
            SoundManager.playOk(); 
            Item_BtlSelect_Flg = false;
            TopBtnUpdate_SkipFlame = 3;
            Menu禁止Flame = 3;
            this.DelSpriteSpan(PN_IBtlBlack, PN_IBtlSelTxt + 14);
            this.ItemBtlSetting();
            this.DelSpriteSpan(PNo_UseWin , PN_ICancelBtn);
        }
    } else {
        this.MenuItem_SetuDell();
        this.DelSpriteArr(Item_SetDelPicArr);
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled()) {
        if (menuAutoCloseFlame > 0) {
            menuAutoCloseFlame = 1;
            return;
        }
        Item_BtlSelect_Flg = false;
        Menu禁止Flame = 3;
        this.DelSpriteSpan(PN_IBtlBlack, PN_IBtlSelTxt + 14);
    }
}
let menuMiniStateWinPostion = new Pos2D(405, 200); 
Game_Interpreter.prototype.MenuItem_UseCheckStart = function () {
    MenuCngOkFlg = false; 
    this.SetSprite(PN_IUBack, "Black", 0, 0, 0); 
    this.MoveSprite(PN_IUBack, 0, 0, 10, 150);
    let moveWinX = 401;
    let moveWinY = 297;
    EasingStr = "easeInQuad"; 
    this.MoveSprite(PNo_UseWin, moveWinX, moveWinY, 10);
    this.MoveSprite(PNo_UseTxt, moveWinX + 42, moveWinY + 16, 10);
    this.MoveSprite(PN_UCntTxt, moveWinX + 342, moveWinY + 16, 10);
    for (let i = 0; i <= 4 - 1; i++) {
        this.MoveSprite(PNo_USetuTxt + i, moveWinX + 30, moveWinY + 70 + (26 * i), 10);
    }
    this.SetSpriteC(PN_ICancelBtn, MenuUIPath + "Item/ICancelBtn", ItemSelectPos._x + 369, ItemSelectPos._y + 154, 0); 
    let occasion = $dataItems[SelectItemId].occasion;
    switch (occasion) {
        case 3: 
            this.MoveSprite(PN_ICancelBtn, moveWinX + 279, moveWinY + 151, 10); 
            break;
        default:
            this.SetSpriteC(PN_IUseBtn, MenuUIPath + "Item/IUseBtn", ItemSelectPos._x + 165, ItemSelectPos._y + 154, 0);       
            this.MoveSprite(PN_IUseBtn, moveWinX + 170, moveWinY + 151, 10); 
            this.MoveSprite(PN_ICancelBtn, moveWinX + 369, moveWinY + 151, 10); 
    }
    EasingStr = ""; 
    //アイテムがカードパック（隠しアイテムA)の場合はミニステータスを表示しない
    if ($dataItems[SelectItemId].itypeId == 3) {
        if ($gameParty.numItems($dataItems[SelectItemId]) >= 5) {
            this.SetSpriteC(PN_IUseBtn + 1, MenuUIPath + "Item/IUseBtn_Douji",
                ItemSelectPos._x + 165 + 102, ItemSelectPos._y + 154 + 45, 0);    
            this.MoveSprite(PN_IUseBtn + 1, moveWinX + 170 + 102, moveWinY + 151 + 55, 10); 
        }
        return;
    }
    EasingStr = "easeInQuad"; 
    ViewSpriteArr_Reset();
    D_Text_Cng_font = "Makinas";
    this.SetSprite(PN_IMiniSt, MenuUIPath + "Item/IMiniStateBase",
        menuMiniStateWinPostion._x, menuMiniStateWinPostion._y, 0);
    let hpBarPar = ($gameActors._data[1]._hp / $gameActors._data[1].mhp) * 100;
    this.SetSprite(PN_IMHpBar, MenuUIPath + "Item/IMiniLPBar",
        menuMiniStateWinPostion._x + 105, menuMiniStateWinPostion._y + 31, 0, hpBarPar);
    this.SpriteStrC(PN_IMHp, String($gameActors._data[1]._hp), 24,
        menuMiniStateWinPostion._x + 418, menuMiniStateWinPostion._y + 38);
    this.SpriteStrC(PN_IMMaxHp, String($gameActors._data[1].mhp), 24,
        menuMiniStateWinPostion._x + 486, menuMiniStateWinPostion._y + 38);
    let ijoText = GetIjoText();
    if (ijoText == "") {
        let _OLineUp = "\\oc[rgb(0,0,0)]\\ow[0] "; 
        ijoText = _OLineUp + "正常";
        this.SpriteStr(PN_IMIjoTxt, ijoText, 22,
            menuMiniStateWinPostion._x + 95, menuMiniStateWinPostion._y + 53, 0);
    } else {
        this.SpriteStr(PN_IMIjoTxt, ijoText, 25,
            menuMiniStateWinPostion._x + 103, menuMiniStateWinPostion._y + 52, 0);
    }
    for (let i = 0; i <= ViewSpriteArr.length - 1; i++) {
        this.MoveSprite(ViewSpriteArr[i], true, true, 10, 255, true, true);
    }
    EasingStr = ""; 
    D_Text_Cng_font = "";
}
Game_Interpreter.prototype.MenuItem_UseCheckView = function () { 
    D_Text_Cng_font = "Makinas"; 
    let useWinX = 401;
    let useWinY = 297;
    let itemCounter = $gameParty.numItems($dataItems[SelectItemId]); 
    if (!$dataItems[SelectItemId].consumable) { 
        this.SpriteStr(PN_UCntTxt, "", 24, useWinX + 342, useWinY + 16);
    } else {
        this.SpriteStr(PN_UCntTxt, "×" + itemCounter, 24, useWinX + 342, useWinY + 16);
    }
    this.SpriteCngColor(PN_IUseBtn);
    let occasion = $dataItems[SelectItemId].occasion;
    switch (occasion) {
        case 3: 
            break;
        default:
            if (itemCounter > 0) { 
                this.SetSpriteC(PN_IUseBtn, MenuUIPath + "Item/IUseBtn", useWinX + 170, useWinY + 151);       
            } else {
                this.SpriteCngColor(PN_IUseBtn, [-50, -50, -50]);
            }
    }
    this.SetSpriteC(PN_ICancelBtn, MenuUIPath + "Item/ICancelBtn", useWinX + 369, useWinY + 151); 
    //アイテムがカードパック（隠しアイテムA)の場合はミニステータスを表示しない
    if ($dataItems[SelectItemId].itypeId == 3) {
        if ($gameParty.numItems($dataItems[SelectItemId]) >= 5) {
            this.SetSpriteC(PN_IUseBtn + 1, MenuUIPath + "Item/IUseBtn_Douji",
                useWinX + 170 + 102, useWinY + 151 + 45);       
        } else {
            this.DelSprite(PN_IUseBtn + 1);
        }
        return;
    }
    let hpBarPar = ($gameActors._data[1]._hp / $gameActors._data[1].mhp) * 100;
    this.SetSprite(PN_IMHpBar, MenuUIPath + "Item/IMiniLPBar",
        menuMiniStateWinPostion._x + 105, menuMiniStateWinPostion._y + 31, 255, hpBarPar);
    this.SpriteStrC(PN_IMHp, String($gameActors._data[1]._hp), 24,
        menuMiniStateWinPostion._x + 418, menuMiniStateWinPostion._y + 38);
    this.SpriteStrC(PN_IMMaxHp, String($gameActors._data[1].mhp), 24,
        menuMiniStateWinPostion._x + 486, menuMiniStateWinPostion._y + 38);
    let ijoText = GetIjoText();
    if (ijoText == "") {
        let outLineStr = "\\oc[rgb(0,0,0)]\\ow[0] "; 
        ijoText = outLineStr + "正常";
        this.SpriteStr(PN_IMIjoTxt, ijoText, 22,
            menuMiniStateWinPostion._x + 95, menuMiniStateWinPostion._y + 53);
    } else {
        this.SpriteStr(PN_IMIjoTxt, ijoText, 25,
            menuMiniStateWinPostion._x + 103, menuMiniStateWinPostion._y + 52);
    }
    D_Text_Cng_font = ""; 
}
let GetIjoText = function () { 
    let setIjoText = "";
    for (let i = 0; i <= $gameActors._data[1]._states.length - 1; i++) { 
        let stateId = $gameActors._data[1]._states[i];
        if (MetaChecker($dataStates[stateId],"パッシブ") != ""){
            setIjoText += "\\I[" + String($dataStates[stateId].iconIndex) + "]";
        }
    }
    return setIjoText;
}
let MenuItemUseSelect = -1;
Game_Interpreter.prototype.MenuItem_UseCheckUpdate = function () {
    if (this.ItemUseFlameCk()) return; 
    let ckPicArr = [PN_ICancelBtn];
    let itemCount = $gameParty.numItems($dataItems[SelectItemId]); 
    if (itemCount > 0) {
        ckPicArr.push(PN_IUseBtn) 
        ckPicArr.push(PN_IUseBtn + 1); 
    }
    let overPicNo = overPointerSpCkArr(ckPicArr);
    for (let i = 0; i <= ckPicArr.length - 1; i++) this.SpriteCngColor(ckPicArr[i])
    let cancelBtnFlg = false;
    switch (overPicNo) {
        case PN_IUseBtn:
        case PN_IUseBtn + 1:
            if (PN_IUseBtn != MenuItemUseSelect) SoundManager.playCursor();
            MenuItemUseSelect = PN_IUseBtn;
            this.SpriteCngColor(overPicNo, [80, 80, 80, 0]);
            if (TouchInput.isTriggered()) {
                if (menuAutoCloseFlame > 0) {
                    menuAutoCloseFlame = 1;
                    return;
                }
                SoundManager.playOk(); 
                let item = $dataItems[SelectItemId];
                let actor = $gameParty.leader();
                actor.useItem(item); 
                if ($dataItems[SelectItemId].itypeId == 3) {
                    Pack5OpenFlg = false;
                    if (overPicNo == PN_IUseBtn + 1) {
                        actor.useItem(item);
                        actor.useItem(item);
                        actor.useItem(item);
                        actor.useItem(item);
                        Pack5OpenFlg = true;
                    }
                    this.CGet_Start(SelectItemId); 
                    Menu_ItemMode = 10; 
                    break;
                }
                this.ItemUsing(SelectItemId);
                this.PlayAnime(item.animationId,
                    menuMiniStateWinPostion._x + 270, menuMiniStateWinPostion._y + 50);
                let action = new Game_Action(actor);
                action.setItemObject(item);
                action.apply($gameActors.actor(1));
                action.applyGlobal(); 
                menuItemUseFlame = 20;
                this.MenuItem_UseCheckView(); 
                this.MenuItemView(); 
            }
            break;
        case PN_ICancelBtn:
            if (PN_ICancelBtn != MenuItemUseSelect) SoundManager.playCursor();
            MenuItemUseSelect = PN_ICancelBtn;
            this.SpriteCngColor(PN_ICancelBtn, [80, 80, 80, 0]);
            if (TouchInput.isTriggered()) {
                Menu_EditLayer--;
                if (menuAutoCloseFlame > 0) {
                    menuAutoCloseFlame = 1;
                    return;
                }
                SoundManager.playCancel(); 
                cancelBtnFlg = true;
            }
            break;
        default:
            if (Tutorial_ClickPN != -1) return; 
            MenuItemUseSelect = -1;
            break;
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled() || cancelBtnFlg) {
        if (menuAutoCloseFlame > 0) {
            menuAutoCloseFlame = 1;
            return;
        }
        if (Tutorial_ClickPN == PN_IUseBtn) return;
        this.Layer1_DelBtm(PN_IUBack); 
        this.Layer1_DelTop();
        MenuItemUseSelect = -1;
        Menu_ItemMode = 0;
    }
}
Game_Interpreter.prototype.ItemUsing = function (itemId) {
    let itemData = $dataItems[itemId];
    for (let i = 0; i <= itemData.effects.length - 1; i++) {
        if (itemData.effects[i].code == 11) { 
            $gameActors._data[1]._hp += itemData.effects[i].value2;
        }
    }
}
let Item_SetDelPicArr = []; 
let SelectItemId = 0; 
let ItemSelectPos = null;
Game_Interpreter.prototype.MenuItem_SetuDell = function () {
    this.DelSpriteSpan(PNo_UseWin, PN_ICancelBtn);
}
Game_Interpreter.prototype.MenuItem_SetuView = function (selectItemNo, btlItemFlg) {
    btlItemFlg = typeof btlItemFlg !== 'undefined' ? btlItemFlg : false;
    Item_SetDelPicArr = [PNo_SelectB, PNo_UseWin, PNo_UseTxt, PN_UCntTxt];
    this.SetSprite(PNo_SelectB, MenuUIPath + "Item/ISelecter",
        245, 296 + (41 * selectItemNo), 255); 
    let useWinX = 615;
    let useWinY = 228 + (41 * selectItemNo);
    let itemNo = 0;
    if (btlItemFlg) {
        this.DelSprite(PNo_SelectB);
        useWinX = 488 + 315;
        useWinY = 120 - 82 + (40 * selectItemNo);
        itemNo = Item_BtlGetArr[selectItemNo];
    } else {
        itemNo = menuItemList[selectItemNo][0];
    }
    if (itemNo == -1) {
        let dellPicArr = [PNo_USetuTxt + 0, PNo_USetuTxt + 1, PNo_USetuTxt + 2, PNo_USetuTxt + 3];
        this.DelSpriteArr(dellPicArr); 
        return;
    }
    this.MenuItem_SetuDraw(itemNo, useWinX, useWinY);
    let occasion = $dataItems[itemNo].occasion;
    switch (occasion) {
        case 3:  
            break
        default: 
    }
    SelectItemId = itemNo; 
}
Game_Interpreter.prototype.MenuItem_SetuDraw = function (itemNo, useWinX, useWinY) {
    if (itemNo == -1) return;
    if ($dataItems[itemNo] == undefined) return; 
    ItemSelectPos = new Pos2D(useWinX, useWinY);
    let itemCount = $gameParty.numItems($dataItems[itemNo]);
    this.SetSprite(PNo_UseWin, MenuUIPath + "Item/IUseWin", useWinX, useWinY, 255);
    let itemName = $dataItems[itemNo].name;
    let iconNo = $dataItems[itemNo].iconIndex;
    let setuStrArr = $dataItems[itemNo].description.split("\n");
    D_Text_Cng_font = "Makinas";
    this.SpriteStr(PNo_UseTxt, "\\I[" + iconNo + "] " + itemName, 24, useWinX + 42, useWinY + 16);
    this.SpriteStr(PN_UCntTxt, "×" + itemCount, 24, useWinX + 342, useWinY + 16);
    if (!$dataItems[itemNo].consumable) {
        this.SpriteStr(PN_UCntTxt, "", 24, useWinX + 342, useWinY + 16);
    }
    for (let i = setuStrArr.length; i < 4; i++) {
        setuStrArr.push(""); 
    }
    for (let i = 0; i <= setuStrArr.length - 1; i++) {
        this.SpriteStr(PNo_USetuTxt + i, setuStrArr[i], 21, useWinX + 30, useWinY + 70 + (26 * i));
        Item_SetDelPicArr.push(PNo_USetuTxt + i);
    }
    var ctVar = MetaChecker($dataItems[itemNo] , "CT" , false);
    if (ctVar != false) {
        this.SpriteStr(PNo_USetuTxt + 3, SCol.Yel + "クールタイム：" + ctVar + "ターン", 21, useWinX + 30, useWinY + 55 + (26 * 3));
        Item_SetDelPicArr.push(PNo_USetuTxt + 3);
    }
    D_Text_Cng_font = "";
}
Game_Interpreter.prototype.MenuItem_CubeUseUpdate = function () {
    if (!CGet_ViewFlg()) {
        Menu_ItemMode = 1;
        let item = $dataItems[SelectItemId];
        let actor = $gameParty.leader();
        let action = new Game_Action(actor);
        action.setItemObject(item);
        action.apply($gameActors.actor(1));
        action.applyGlobal(); 
        menuItemUseFlame = 20;
        this.MenuItem_UseCheckView(); 
        this.MenuItemView(); 
    }
}
