SoundManager.playGetItem = function() {
    var se = {name: 'Item3', volume: 90, pitch: 100, pan: 0};;
    AudioManager.playSe(se);
};

Game_Temp.prototype.getItem = function() {
    return this._getItem;
};

Game_Temp.prototype.setGetItem = function(item) {
    this._getItem = item;
};

Game_Temp.prototype.clearGetItem = function() {
    this._getItem = null;
};

// Change Items
Game_Interpreter.prototype.command126 = function(params) {
    const value = this.operateValue(params[1], params[2], params[3]);
    $gameParty.gainItem($dataItems[params[0]], value);
    if(value > 0) $gameTemp.setGetItem($dataItems[params[0]]);//@add
    return true;
};

//居場所判定
Game_Character.prototype.isHere = function(x, y, direction) {
    return this.x === x && this.y === y && this.direction() === direction;
};

//入手順管理を追加
const _Game_Party_initAllItems    = Game_Party.prototype.initAllItems;
Game_Party.prototype.initAllItems = function() {
    _Game_Party_initAllItems.apply(this, arguments);
    this._getOrder = [];
};

const _Game_Party_gainItem    = Game_Party.prototype.gainItem;
Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
    _Game_Party_gainItem.apply(this, arguments);
    if(amount > 0){
        this._getOrder.push(item.id);
    }else{
        this._getOrder = this._getOrder.filter(id => id !== item.id);
    }
};

Game_Party.prototype.itemsGetOrder = function() {
    return this._getOrder.map(id => $dataItems[id]);
};

Game_Party.prototype.hasAnyItem = function() {
    return this._getOrder.some(id => !!id);
};

Game_Party.prototype.hasAnyKey = function() {
    return this._getOrder.some(id => $dataItems[id].name === '鍵');
};



//カウンターマウスクリック問題
Game_Player.prototype.triggerTouchAction = function() {
    if ($gameTemp.isDestinationValid()) {
        const direction = this.direction();
        const x1 = this.x;
        const y1 = this.y;
        const x2 = $gameMap.roundXWithDirection(x1, direction);
        const y2 = $gameMap.roundYWithDirection(y1, direction);
        const x3 = $gameMap.roundXWithDirection(x2, direction);
        const y3 = $gameMap.roundYWithDirection(y2, direction);
        const destX = $gameTemp.destinationX();
        const destY = $gameTemp.destinationY();
        const direction2 = this.directionToward(destX, destY);
        const direction3 = this.reverseDir(direction2);
        const x4 = $gameMap.roundXWithDirection(destX, direction3);
        const y4 = $gameMap.roundYWithDirection(destY, direction3);
        if (destX === x1 && destY === y1) {
            return this.triggerTouchActionD1(x1, y1);
        } else if (destX === x2 && destY === y2) {
            return this.triggerTouchActionD2(x2, y2);
        } else if (destX === x3 && destY === y3) {
            return this.triggerTouchActionD3(x2, y2);
        }/* else if ($gameMap.isCounter(x4, y4)){
            return this.triggerTouchActionD4(x4, y4);
        }*/
    }
    return false;
};

Game_CharacterBase.prototype.directionToward = function(x, y) {
    const sx = this.deltaXFrom(x);
    const sy = this.deltaYFrom(y);
    if (Math.abs(sx) > Math.abs(sy)) {
        return sx > 0 ? 4 : 6;
    } else if (sy !== 0) {
        return sy > 0 ? 8 : 2;
    }
};

Game_Player.prototype.moveByInput = function() {
    if (!this.isMoving() && this.canMove()) {
        let direction = this.getInputDirection();
        if (direction > 0) {
            $gameTemp.clearDestination();
        } else if ($gameTemp.isDestinationValid()) {
            const x = $gameTemp.destinationX();
            const y = $gameTemp.destinationY();
            const counter = this.isDestCounter(x, y);
            direction = this.findDirectionTo(x, y);
            if(counter > 0){
                direction = counter;
            }
        }
        if (direction > 0) {
            this.executeMove(direction);
        }
    }
};

Game_Player.prototype.isDestCounter = function(x, y) {
    const x1 = this.x;
    const y1 = this.y;
    const direction = this.directionToward(x, y);
    const x2 = $gameMap.roundXWithDirection(x1, direction);
    const y2 = $gameMap.roundYWithDirection(y1, direction);
    return $gameMap.isCounter(x2, y2) ? direction : 0;
};

/*
Game_Player.prototype.triggerTouchActionD4 = function(x, y) {
    if ($gameMap.isCounter(x, y)) {
        this.checkEventTriggerThere2([0, 1, 2]);
    }
    return $gameMap.setupStartingEvent();
};

Game_Player.prototype.checkEventTriggerThere2 = function(triggers) {
    if (this.canStartLocalEvents()) {
        const destX = $gameTemp.destinationX();
        const destY = $gameTemp.destinationY();
        const direction = this.directionToward(destX, destY);
        const x1 = this.x;
        const y1 = this.y;
        const x2 = $gameMap.roundXWithDirection(x1, direction);
        const y2 = $gameMap.roundYWithDirection(y1, direction);
        this.startMapEvent(x2, y2, triggers, true);
        if (!$gameMap.isAnyEventStarting() && $gameMap.isCounter(x2, y2)) {
            const x3 = $gameMap.roundXWithDirection(x2, direction);
            const y3 = $gameMap.roundYWithDirection(y2, direction);
            this.startMapEvent(x3, y3, triggers, true);
        }
    }
};*/

//-----------------------------------------------------------------------------
// Scene_Map
//-----------------------------------------------------------------------------

const _Scene_Map_createDisplayObjects    = Scene_Map.prototype.createDisplayObjects;
Scene_Map.prototype.createDisplayObjects = function() {
    _Scene_Map_createDisplayObjects.apply(this, arguments);
    this.createGaugeSprite();
    this.createShortcutWindow();
    this.createSystemButtons();
};

Scene_Map.prototype.createButtons = function() {
    /*
    if (ConfigManager.touchUI) {
        this.createMenuButton();
    }*/
};

const _Scene_Map_update    = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
    _Scene_Map_update.apply(this, arguments);
    this.updateGauge();
    this.visibleShortCut();
};

Scene_Map.prototype.createGaugeSprite = function() {
    var y = 422;// - 48;
    this._heartSprite = new Sprite();
    this._heartSprite.bitmap = ImageManager.loadSystem('Heart');
    this._heartSprite.y = y + 64;
    this._heartSprite.anchor.y = 0.5;
    this._heartSprite.visible = false;
    this.addChild(this._heartSprite);

    this._heartEffectSprite = new Sprite();
    this._heartEffectSprite.bitmap = ImageManager.loadSystem('HeartB');
    this._heartEffectSprite.blendMode = 1;
    this._heartEffectSprite.opacity = 0;
    this._heartEffectSprite.y = y + 64;
    this._heartEffectSprite.anchor.y = 0.5;
    this._heartEffectSprite.visible = false;
    this._heartEffectSprite.duration = 60;
    this._heartEffectSprite.switch = false;
    this._heartEffectSprite.phase = 0;
    this.addChild(this._heartEffectSprite);

    this._gaugeSprites = [];
    this._gaugeEffectSprites = [];
    y -= 24;
    for(var i = 0; i < 15; i++){
        var y2 = y - 28 * i;
        this._gaugeSprites[i] = new Sprite();
        this._gaugeSprites[i].bitmap = ImageManager.loadSystem('Gauge');
        this._gaugeSprites[i].y = y2;
        this._gaugeSprites[i].visible = false;
        this.addChild(this._gaugeSprites[i]);

        this._gaugeEffectSprites[i] = new Sprite();
        this._gaugeEffectSprites[i].bitmap = ImageManager.loadSystem('GaugeB');
        this._gaugeEffectSprites[i].blendMode = 1;
        this._gaugeEffectSprites[i].opacity = 0;
        this._gaugeEffectSprites[i].y = y2;
        this._gaugeEffectSprites[i].visible = false;
        this._gaugeEffectSprites[i].duration = 60;
        this.addChild(this._gaugeEffectSprites[i]);
    }
};

Scene_Map.prototype.updateGauge = function() {
    this.visibleGauge();
    this.updateHeartEffect();
    this.updateGaugeEffects();
    this.updateButtons();
};

Scene_Map.prototype.visibleGauge = function() {
    const visble = $gameVariables.value(5) > 0 && !$gameScreen.isStill() && !$gameSwitches.value(13);
    this._heartSprite.visible = visble;
    this._heartEffectSprite.visible = visble;
    for(var i = 0; i < this._gaugeSprites.length; i++){
        this._gaugeSprites[i].visible = visble;
        this._gaugeEffectSprites[i].visible = visble;
    }
};

Scene_Map.prototype.updateHeartEffect = function() {
    var d = this._heartEffectSprite.duration;
    var scaleY = 1.0;
    if(this._heartEffectSprite.switch){
        var opacity = easeIn(255, 128, d, 60);
    }else{
        var opacity = easeOut(128, 255, d, 60);
    }
    if(this._heartEffectSprite.phase === 2){
        scaleY = bounceIn(1.0, 1.1, d, 60);
    }
    this._heartEffectSprite.opacity = opacity;
    this._heartSprite.scale.y = scaleY;
    this._heartEffectSprite.scale.y = scaleY;
    this._heartEffectSprite.duration--;
    if(this._heartEffectSprite.duration === 0){
        this._heartEffectSprite.switch = !this._heartEffectSprite.switch;
        this._heartEffectSprite.duration = 60;
        this._heartEffectSprite.phase++;
    }
    if(this._heartEffectSprite.phase > 2) this._heartEffectSprite.phase = 0;
};

Scene_Map.prototype.updateGaugeEffects = function() {
    for(var i = 0; i < this._gaugeSprites.length; i++){
        var yuri = $gameVariables.value(7);
        if(yuri > i){
            //this._gaugeEffectSprites[i].visible = true;
            this.updateGaugeEffect(i);
        }
    }
};

Scene_Map.prototype.updateGaugeEffect = function(i) {
    if(this._gaugeEffectSprites[i].duration > 0){
        var d = this._gaugeEffectSprites[i].duration;
        var opacity = easeOut(0, 255, d, 60);
        var scaleY = easeOut(1.5, 1.0, d, 60);
        this._gaugeEffectSprites[i].opacity = opacity;
        this._gaugeEffectSprites[i].scale.y = scaleY;
        this._gaugeEffectSprites[i].duration--;
        if(this._gaugeEffectSprites[i].duration === 0){
            this._gaugeEffectSprites[i].scale.y = 1.0;
        }
    }
};

Scene_Map.prototype.createShortcutWindow = function() {
    this._shortcutWindow = new Window_ShortCuts();
    this._shortcutWindow.setHandler('ok', this.onShortcut.bind(this));
    this._shortcutWindow.setHandler('long', this.onLongShortcut.bind(this));
    this.addChild(this._shortcutWindow);
    //this.createSChangeButton();
};

Scene_Map.prototype.createSystemButtons = function() {
    const x = Graphics.boxWidth - 76;
    const y = Graphics.boxHeight - 72;
    this._buttons = [];
    this.createButton(0, x, y);
    this.createButton(1, x, y + 40);
};

Scene_Map.prototype.createButton = function(i, x, y) {
    const bitmap = ImageManager.loadSystem('SystemButtons');
    const buttonWidth = 72;
    const buttonHeight = 24;
    this._buttons[i] = new Sprite_ButtonEx(bitmap, x, y);
    this._buttons[i].setColdFrame(buttonWidth * i, 0, buttonWidth, buttonHeight);
    this._buttons[i].setHotFrame(buttonWidth * i, buttonHeight, buttonWidth, buttonHeight);
    this._buttons[i].setClickHandler(this.onButton.bind(this, i));
    this._buttons[i].visible = false;
    this.addChild(this._buttons[i]);
};

Scene_Map.prototype.updateButtons = function() {
    const visible = this.isMenuEnabled();
    for (const button of this._buttons) {
        button.visible = visible;
    }
};

Scene_Map.prototype.onShortcut = function(i) {
    var item = this._shortcutWindow.item();
    if(DataManager.isItem(item)){
        this.useItem(item);
    }
    this._shortcutWindow.refresh();
};

Scene_Map.prototype.useItem = function(item) {
    if($gameParty.numItems(item) <= 0) return
    if(!$gamePlayer.canMove()) return;
    var actor = $gameActors.actor(1);
    if(!actor.canUse(item)) return;
    if(item.consumable){
        $gameParty.loseItem(item, 1);
    }
    //var action = new Game_Action(actor);
    //action.setItemObject(item);
    item.effects.forEach(function(effect) {
        if (effect.code === Game_Action.EFFECT_COMMON_EVENT) {
            $gameTemp.reserveCommonEvent(effect.dataId);
        }
    }, this);
};

Scene_Map.prototype.onLongShortcut = function(i) {
    this._shortcutWindow.refresh();
};

Scene_Map.prototype.onButton = function(i) {
    if(!this.isMenuEnabled()) return;
    switch(i){
        case 0 :
            this.commandSave();
            break;
        case 1 :
            this.commandOptions();
            break;
    }
};

Scene_Map.prototype.commandSave = function() {
    SoundManager.playOk();
    SceneManager.push(Scene_Save);
    $gameTemp.clearDestination();
    this._waitCount = 2;
};

Scene_Map.prototype.commandOptions = function() {
    SoundManager.playOk();
    SceneManager.push(Scene_Options);
    $gameTemp.clearDestination();
    this._waitCount = 2;
};

Scene_Map.prototype.callMenu = function() {
    this.commandSave();
    /*
    SoundManager.playOk();
    SceneManager.push(Scene_Menu);
    Window_MenuCommand.initCommandPosition();
    SceneManager.push(Scene_Options);
    $gameTemp.clearDestination();
    this._mapNameWindow.hide();
    this._waitCount = 2;
    */
};

Scene_Map.prototype.visibleShortCut = function() {
    this._shortcutWindow.visible = $gameVariables.value(5) > 0 && !$gameMap.isEventRunning()
};

Scene_Map.prototype.isMapTouchOk = function() {
    return this.isActive() && $gamePlayer.canMove() && !this.isButtonsTouched() && !this.isWindowTouched();
};

Scene_Map.prototype.isButtonsTouched = function() {
    //return false;
    return this._buttons.some(function(button) {
        return button.visible && button.isBeingTouched();
   });
};

Scene_Map.prototype.isWindowTouched = function() {
    return this._shortcutWindow.isTouchedInsideFrame();
};

//-----------------------------------------------------------------------------
// Scene_Message
//-----------------------------------------------------------------------------
const _Scene_Message_createAllWindows    = Scene_Message.prototype.createAllWindows;
Scene_Message.prototype.createAllWindows = function() {
    _Scene_Message_createAllWindows.apply(this, arguments);
    this.createNoticeWindow();
};

const _Scene_Message_update    = Scene_Message.prototype.update;
Scene_Message.prototype.update = function() {
    _Scene_Message_update.apply(this, arguments);
    this.checkGetItem();
};

Scene_Message.prototype.createNoticeWindow = function() {
    this._noticeWindow = new Window_Notice();
    this.addWindow(this._noticeWindow);
};

Scene_Message.prototype.checkGetItem = function() {
    if($gameTemp.getItem()){
        this.displayGetItem();
        $gameTemp.clearGetItem()
    }
};

Scene_Message.prototype.displayGetItem = function() {
    SoundManager.playGetItem();
    this._noticeWindow.displayGetItem($gameTemp.getItem());
};

//-----------------------------------------------------------------------------
// Window_ShortCuts
//-----------------------------------------------------------------------------

function Window_ShortCuts() {
    this.initialize.apply(this, arguments);
}

Window_ShortCuts.prototype = Object.create(Window_Base.prototype);
Window_ShortCuts.prototype.constructor = Window_ShortCuts;

Window_ShortCuts.prototype.initialize = function() {
    const ww = this.windowWidth();
    const wh = this.windowHeight();
    const wx = Graphics.boxWidth - ww - 4;
    const wy = 24;
    const rect = new Rectangle(wx, wy, ww, wh);
    Window_Base.prototype.initialize.call(this, rect);
    this.opacity = 0;
    this.index = -1;
    this._handlers = {};
    this._pressing = [];
    this.createButtons();
    this.hide();
    this.refresh();
};

Window_ShortCuts.prototype.update = function() {
    Window_Base.prototype.update.call(this);
    this.checkNewItem();
};

Window_ShortCuts.prototype.windowWidth = function() {
    return 64 + 48;
};

Window_ShortCuts.prototype.windowHeight = function() {
    return this.fittingHeight(15);
};

Window_ShortCuts.prototype.createIcons = function() {
    this.icons = new Bitmap(this.contentsWidth(), this.contentsHeight());
};

Window_ShortCuts.prototype.createButtons = function() {
    const bitmap = ImageManager.loadSystem('SCFrame');
    const buttonWidth = 34;
    const buttonHeight = 34;
    const num = 10;
    const sx = 12 + 48;
    const sy = 12;
    this._buttons = [];
    for(var i = 0; i < num; i++){
        this._buttons[i] = new Sprite_ButtonEx(bitmap, this.buttonX(sx, i), this.buttonY(sy, i));
        this._buttons[i].setColdFrame(0, 0, buttonWidth, buttonHeight);
        this._buttons[i].setHotFrame(0, buttonHeight, buttonWidth, buttonHeight);
        this.addChildToBack(this._buttons[i]);
        this._buttons[i].setClickHandler(this.onButton.bind(this, i));
        //this._buttons[i].setLongHandler(this.onLongButton.bind(this, i));
    }
};

Window_ShortCuts.prototype.buttonX = function(sx, i) {
    return sx;
};

Window_ShortCuts.prototype.buttonY = function(sy, i) {
    return sy + 42 * i;
};

Window_ShortCuts.prototype.checkNewItem = function() {
    var result = false;
    const items = $gameParty.itemsGetOrder();
    const max = Math.max(items.length, this._data.length);
    for(var i = 0; i < max; i++){
        if(items[i] !== this._data[i]){
            result = true;
        }
    }
    if(result) this.refresh();
};

Window_ShortCuts.prototype.makeItemList = function() {
    this._data = $gameParty.itemsGetOrder();
};

Window_ShortCuts.prototype.refresh = function() {
    this.makeItemList();
    this.contents.clear();
    this.contents.fontSize = 14;
    const sx = 0 + 48;
    const sy = 0;
    //var sIndex = 0//$gameSystem.shortcutsPage() ? 8 : 0;
    for(var i = 0; i < this._buttons.length; i++){
        var x = this.buttonX(sx, i);
        var y = this.buttonY(sy, i);
        //var index = i + sIndex;
        var item = this._data[i];
        this.resetTextColor();
        this.changePaintOpacity(true);
        if(DataManager.isItem(item)){
            this.drawItem(item, x, y);
        }
        /*
        if(commands[index].isItem()){
            this.drawItem(item, x, y);
        }
        if(commands[index].isEquipItem()){
            this.drawEquipItem(item, x, y);
        }
        if(commands[index].isSkill()){
            this.drawSkill(item, x, y);
        }
        this.resetTextColor();
        if(item){
            this.drawSCName(item, x, y, i);
        }*/
    }
};

Window_ShortCuts.prototype.drawSCName = function(item, x, y, i) {
    var short = item.name.slice(0, 2);
    this.drawText(short, x - 32, y, 32);
};

Window_ShortCuts.prototype.drawItem = function(item, x, y) {
    var iconIndex = item ? item.iconIndex : 0;
    //var num = $gameParty.numItems(item);
    //var enable = num > 0 && ($gameActors.actor(1).canUse(item) || item.meta.canThrow);//num > 0// && $gamePlayer.canMove();
    //this.changePaintOpacity(enable);
    this.drawIcon(iconIndex, x + 1, y + 1);
    //this.drawNum(num, x, y);
};

Window_ShortCuts.prototype.drawEquipItem = function(item, x, y) {
    var iconIndex = item ? item.iconIndex : 0;
    var num = -1;
    var equip = $gameActors.actor(1).isEquipped(item);
    var enable = $gameParty.hasItem(item) || equip;
    //弓の場合
    if(item.wtypeId === 5){
        num = $gameParty.numArrows();
        enable = enable && num > 0;
    }
    this.changePaintOpacity(enable);
    this.drawIcon(iconIndex, x + 1, y + 1);
    this.changeTextColor(this.mpCostColor());
    if(equip) this.drawEquip(x,y)
    this.resetTextColor();
    this.drawNum(num, x, y);
};

Window_ShortCuts.prototype.drawSkill = function(item, x, y) {
    var iconIndex = item ? item.iconIndex : 0;
    if(item.tpCost){
        var num = Math.min($gameActors.actor(1).coolTime(item), item.tpCost);
        this.changeTextColor(this.ctColor());
    }else{
        var num = $gameActors.actor(1).skillMpCost(item);
        this.changeTextColor(this.mpCostColor());
    }
    var enable = $gameActors.actor(1).canUse(item);
    this.changePaintOpacity(enable);
    this.drawIcon(iconIndex, x + 1, y + 1);
    this.changePaintOpacity(true);
    if(num > 0){
        this.drawNum(num, x - 16, y - 12);
    }
    if(item.requiredWtypeId1 === 5){
        this.resetTextColor();
        num = $gameParty.numArrows();
        this.drawNum(num, x, y);
    }
};

Window_ShortCuts.prototype.drawNum = function(num,x,y) {
    if(num > -1){
        this.drawText(num, x, y + 6, 28, 'right');
    }
};

Window_ShortCuts.prototype.drawEquip = function(x,y) {
    this.drawText('E', x + 2, y + 6, 28);
};

Window_ShortCuts.prototype.onButton = function(index) {
    this.index = index;
    this.callHandler('ok');
    this.refresh();
};

Window_ShortCuts.prototype.onLongButton = function(index) {
    this.index = index;
    this.callHandler('long');
    this.refresh();
};

Window_ShortCuts.prototype.item = function() {
    return this._data[this.index];
};

Window_ShortCuts.prototype.isTouchedInsideFrame = function() {
    const touchPos = new Point(TouchInput.x, TouchInput.y);
    const localPos = this.worldTransform.applyInverse(touchPos);
    return this.innerRect.contains(localPos.x, localPos.y);
};

Window_ShortCuts.prototype.setHandler = function(symbol, method) {
    this._handlers[symbol] = method;
};

Window_ShortCuts.prototype.isHandled = function(symbol) {
    return !!this._handlers[symbol];
};

Window_ShortCuts.prototype.callHandler = function(symbol) {
    if (this.isHandled(symbol)) {
        this._handlers[symbol]();
    }
};

Window_ShortCuts.prototype.index = function() {
    return this.index;
};

//-----------------------------------------------------------------------------
// Window_Notice
//-----------------------------------------------------------------------------
function Window_Notice() {
    this.initialize.apply(this, arguments);
}

Window_Notice.prototype = Object.create(Window_Base.prototype);
Window_Notice.prototype.constructor = Window_Notice;

Window_Notice.prototype.initialize = function() {
    const ww = this.windowWidth();
    const wh = this.windowHeight();
    const wx = 96 - ww;
    const wy = 0;
    const rect = new Rectangle(wx, wy, ww, wh);
    this._isOpening = false;
    this._isWating = false;
    this._isClosing = false;
    this._duration = 0;
    this._waitTime = 120;
    this._item = "";
    this._defaultY = wy - 16;
    Window_Base.prototype.initialize.call(this, rect);
    this.opacity = 0;
    this.hide();
    //this.refresh();
};

Window_Notice.prototype.windowWidth = function() {
    return Graphics.boxWidth - 128;
};

Window_Notice.prototype.windowHeight = function() {
    return this.fittingHeight(1);
};

Window_Notice.prototype.update = function() {
    Window_Base.prototype.update.call(this);
    this.updateFade();
};

Window_Notice.prototype.updateFade = function() {
    const d = this._duration;
    if(this._isOpening){
        const x1 = Graphics.boxWidth;
        this.x = easeOut(x1, 80, d, 30);
        this.contents.paintOpacity = easeOut(0, 255, d, 30);
        this._duration--;
        if(this._duration == 0){
            this._isOpening = false;
            this._isWating = true;
            this._duration = this._waitTime;
        }
        this.refresh();
    }else if(this._isWating){
        this._duration--;
        if (this._duration == 0) {
            this._isWating = false;
            this._isClosing = true;
            this._duration = 30;
        }
    }else if(this._isClosing){
        const y1 = this._defaultY;
        this.y = easeIn(y1, y1 - 15, d, 30);
        this.contents.paintOpacity = easeIn(255, 0, d, 30);
        this._duration--;
        if (this._duration == 0) {
            this._isClosing = false;
            this.hide();
        }
        this.refresh();
    }
};

Window_Notice.prototype.drawTextEx = function(text, x, y, width) {
    //this.resetFontSettings();
    const textState = this.createTextState(text, x, y, width);
    this.processAllText(textState);
    return textState.outputWidth;
};

Window_Notice.prototype.refresh = function() {
    this.contents.clear();
    this.drawBackground(0,0,this.contents.width, this.contents.height);
    this.contents.fontSize = 24;
    this.drawTextEx(this._text, 16, 0, this.contents.width);
};

Window_Notice.prototype.drawBackground = function(x, y, width, height) {
    var color1 = ColorManager.dimColor1();
    var color2 = ColorManager.dimColor2();
    this.contents.gradientFillRect(x, y, width, height, color1, color2);
    //this.contents.fillRect(x, y, width, height,color1);
};

Window_Notice.prototype.startDisplay = function(text) {
    this._text = text;
    this.contents.paintOpacity = 0;
    this.x = -this.width;
    this.y = this._defaultY;
    this._duration = 30;
    this.show();
    this._isOpening = true;
};

Window_Notice.prototype.displayGetItem = function(item) {
    const iconIndex = item.iconIndex;
    // const name = item.name;
    const name = this.itemData(item).name;
    const language = $gameVariables.value(25);
    switch (language) {
      case 0:
        text = '\\I[' + iconIndex + ']\\C[2]' + name + '\\C[0]を入手！';
        break;
      case 1:
        text = '\\I[' + iconIndex + ']\\C[2]' + name + '\\C[0] obtained!';
        break;
      case 2:
        text = '\\I[' + iconIndex + ']\\C[2]' + name + '\\C[0]入手了！';
        break;
      case 3:
        text = '\\I[' + iconIndex + ']\\C[2]' + name + '\\C[0]入手了！';
        break;
      default:
        break;
    }
    // const japanese_mode = $gameSwitches.value(80);
    // if (japanese_mode) {
    //     text = '\\I[' + iconIndex + ']\\C[2]' + name + '\\C[0]を入手！';
    // } else {
    //     text = '\\C[0]I got' + '\\I[' + iconIndex + ']\\C[2]' + name;
    // }
    this. startDisplay(text);
};



Window_Notice.prototype.isBusy = function() {
    return this._isOpening || this._isWating;
};