Scene_Base.prototype.start = function () {
	this._started = true;
	this._active = true;
	ConfigManager["touchUI"] = false;
};

//全てのウィンドウでマウスカーソルがホバーした時音を鳴らす
Window_Selectable.prototype.processTouch = function () {
	if (this.isOpenAndActive()) {
		const lastIndex = this.index();
		if (this.isHoverEnabled() && TouchInput.isHovered()) {
			this.onTouchSelect(false);
		} else if (TouchInput.isTriggered()) {
			this.onTouchSelect(true);
		}
		if (TouchInput.isClicked()) {
			this.onTouchOk();
		} else if (TouchInput.isCancelled()) {
			this.onTouchCancel();
		}
		if (this.index() !== lastIndex) {
			this.playCursorSound();
		}
	}
};

//アウトラインないver
// Window_Base.prototype.CBRdrawText = function (text, x, y, maxWidth, align) {
// 	this.contents.CBRdrawText(text, x, y, maxWidth, this.lineHeight(), align);
// };

// Bitmap.prototype.CBRdrawText = function (text, x, y, maxWidth, lineHeight, align) {
// 	// [Note] Different browser makes different rendering with
// 	//   textBaseline == 'top'. So we use 'alphabetic' here.
// 	const context = this.context;
// 	const alpha = context.globalAlpha;
// 	maxWidth = maxWidth || 0xffffffff;
// 	let tx = x;
// 	let ty = Math.round(y + lineHeight / 2 + this.fontSize * 0.35);
// 	if (align === "center") {
// 		tx += maxWidth / 2;
// 	}
// 	if (align === "right") {
// 		tx += maxWidth;
// 	}
// 	context.save();
// 	context.font = this._makeFontNameText();
// 	context.textAlign = align;
// 	context.textBaseline = "alphabetic";
// 	context.globalAlpha = alpha;
// 	this._drawTextBody(text, tx, ty, maxWidth);
// 	context.restore();
// 	this._baseTexture.update();
// };

/*
//ウィンドウスキンの変更
Window_Base.prototype.loadWindowskin = function() {
    this.windowskin = ImageManager.loadSystem("Window");
    this.CBRwindowskin_1 = ImageManager.loadSystem("scalable_window_04_03");
};

//背景ウィンドウフレームを追加
Window_Base.prototype._createFrameSprite = function() {
    this._frameSprite_1 = new Sprite();
    for (let i = 0; i < 8; i++) {
        this._frameSprite_1.addChild(new Sprite());
    }
    this._container.addChild(this._frameSprite_1);
};
Window_Base.prototype._refreshFrame = function() {
    //ウィンドウフレームの範囲
    var drect = { x: 0, y: 0, width: this._width, height: this._height };
    //利用するウィンドウの切り取る範囲
    var srect = { x: 0, y: 0, width: 128, height: 128 };
    var m = 20;
    for (const child of this._frameSprite_1.children) {
        child.bitmap = this.CBRwindowskin_1;
    }
    this._setRectPartsGeometry(this._frameSprite_1, srect, drect, m);
    this._frameSprite_1.opacity = 200;
};

Window_Base.prototype._updateFrame = function() {
    //this._frameSprite_1.visible = this.frameVisible;
};
Window_Base.prototype.drawItemBackground = function(index) {
};
Window_Base.prototype._refreshBack = function() {
    const m = this._margin;
    const w = Math.max(0, this._width - m * 2);
    const h = Math.max(0, this._height - m * 2);
    const sprite = this._backSprite;
    const tilingSprite = sprite.children[0];
    // [Note] We use 95 instead of 96 here to avoid blurring edges.
    sprite.bitmap = this.CBRwindowskin_1;
    sprite.setFrame(20, 20, 50, 50);
    sprite.y = 20;
    sprite.x = 20;
    //sprite.move(m, m);
    sprite.scale.x = (w - 32) / 50;
    sprite.scale.y = (h - 32) / 50;
    tilingSprite.bitmap = this._windowskin;
    tilingSprite.setFrame(0, 96, 96, 96);
    tilingSprite.move(0, 0, w, h);
    tilingSprite.scale.x = 1 / sprite.scale.x;
    tilingSprite.scale.y = 1 / sprite.scale.y;
    sprite.setColorTone(this._colorTone);
};
Window_Base.prototype.updateBackOpacity = function() {
    this.backOpacity = 200;
};

//なんか4px下が狭い
Window_Selectable.prototype.initialize = function(rect) {
    Window_Scrollable.prototype.initialize.call(this, rect);
    this._index = -1;
    this._cursorFixed = false;
    this._cursorAll = false;
    this._helpWindow = null;
    this._handlers = {};
    this._doubleTouch = false;
    this._canRepeat = true;
    this.deactivate();
    this.height += 4;
};
*/
//背景の黒い奴失くす
// Window_Selectable.prototype.drawAllItems = function () {
// 	const topIndex = this.topIndex();
// 	for (let i = 0; i < this.maxVisibleItems(); i++) {
// 		const index = topIndex + i;
// 		if (index < this.maxItems()) {
// 			this.drawItemBackground(index);
// 			this.drawItem(index);
// 		}
// 	}
// };
// Window_Selectable.prototype.drawItemBackground = function (index) {};

// Window_Base.prototype.loadWindowskin = function () {
// 	if (this.redWindow) {
// 		this.windowskin = ImageManager.loadSystem("Window_red");
// 	} else {
// 		this.windowskin = ImageManager.loadSystem("Window");
// 	}
// };

//赤情報があったらウィンドウのスキンを赤に
// Window_Base.prototype.initialize = function (rect) {
// 	Window.prototype.initialize.call(this);
// 	var s = SceneManager._scene.constructor.name;

// 	//メニューとツリーでメニューがあったら赤
// 	if (s == "Scene_Menu") {
// 		this.redWindow = true;
// 		//つまりメニューからセーブ画面に飛んでた時は赤
// 	} else if (SceneManager._stack.length > 0) {
// 		var idx = SceneManager._stack.findIndex((element) => element.name == "Scene_Menu");
// 		if (idx > -1 && s != "Scene_Map") {
// 			this.redWindow = true;
// 		}
// 	}
// 	this.loadWindowskin();
// 	this.checkRectObject(rect);
// 	this.move(rect.x, rect.y, rect.width, rect.height);
// 	this.updatePadding();
// 	this.updateBackOpacity();
// 	this.updateTone();
// 	this.createContents();
// 	this._opening = false;
// 	this._closing = false;
// 	this._dimmerSprite = null;
// };

Scene_Boot.prototype.adjustBoxSize = function () {
	const uiAreaWidth = $dataSystem.advanced.uiAreaWidth;
	const uiAreaHeight = $dataSystem.advanced.uiAreaHeight;
	const boxMargin = 0;
	Graphics.boxWidth = uiAreaWidth - boxMargin * 2;
	Graphics.boxHeight = uiAreaHeight - boxMargin * 2;
};

//################### メッセージウィンドウ #####################
Scene_Message.prototype.messageWindowRect = function () {
	const ww = Graphics.width;
	const wh = 270;
	const wx = 0;
	const wy = Graphics.height - wh;
	return new Rectangle(wx, wy, ww, wh);
};

Window_Message.prototype.loadWindowskin = function () {
	this.windowskin = ImageManager.loadSystem("message");
};

Window_Message.prototype._refreshBack = function () {
	const sprite = this._backSprite;
	// [Note] We use 95 instead of 96 here to avoid blurring edges.
	sprite.bitmap = this._windowskin;
};

Window_Message.prototype._refreshFrame = function () {};
Window_Message.prototype.updateBackOpacity = function () {
	this.backOpacity = (255 * ConfigManager.msOpacityVolume) / 100;
};

Window_Message.prototype.startMessage = function () {
	const text = $gameMessage.allText();
	const textState = this.createTextState(text, 0, 0, 0);
	textState.x = this.newLineX(textState);
	textState.startX = textState.x + 300;
	this._textState = textState;
	this.newPage(this._textState);
	this.updatePlacement();
	this.updateBackground();
	this.open();
	this._nameBoxWindow.start();
};

Window_Message.prototype.newPage = function (textState) {
	this.contents.clear();
	this.resetFontSettings();
	this.clearFlags();
	this.updateSpeakerName();
	this.loadMessageFace();
	textState.x = textState.startX;
	textState.y = 120;
	textState.height = this.calcTextHeight(textState);
};
Window_Message.prototype._refreshAllParts = function () {
	this._padding = 0;
	this._refreshBack();
	this._refreshFrame();
	this._refreshCursor();
	this._refreshArrows();
	// this._refreshPauseSign();
};

// #################### 名前欄 ####################
Window_NameBox.prototype.initialize = function () {
	Window_Base.prototype.initialize.call(this, new Rectangle());
	this.openness = 0;
	this._name = "";

	// windowが重なっても透過させる
	this._isWindow = false;
};

Window_NameBox.prototype.updatePlacement = function () {
	this.width = this.windowWidth();
	this.height = this.windowHeight();
	const messageWindow = this._messageWindow;
	if ($gameMessage.isRTL()) {
		this.x = messageWindow.x + messageWindow.width - this.width;
	} else {
		this.x = messageWindow.x;
	}
	if (messageWindow.y > 0) {
		this.y = messageWindow.y - this.height;
	} else {
		this.y = messageWindow.y + messageWindow.height;
	}

	this.x += 280;
	this.y += 150;
};

Window_NameBox.prototype._refreshAllParts = function () {
	this._padding = 0;
	//this._refreshBack();
	//this._refreshFrame();
	this._refreshCursor();
	this._refreshArrows();
	this._refreshPauseSign();
};

Window_NameBox.prototype.windowWidth = function () {
	if (this._name) {
		const textWidth = this.textSizeEx(`【${this._name}】`).width;
		const padding = this.padding + this.itemPadding();
		const width = Math.ceil(textWidth) + padding * 2;
		return Math.min(width, Graphics.boxWidth);
	} else {
		return 0;
	}
};

Window_NameBox.prototype.refresh = function () {
	const rect = this.baseTextRect();
	this.contents.clear();
	this.drawTextEx(this._name ? `【${this._name}】` : "", rect.x, rect.y, rect.width);
};
// Window_Message.prototype.newPage = function (textState) {
// 	this.contents.clear();
// 	this.resetFontSettings();
// 	this.clearFlags();
// 	this.updateSpeakerName();
// 	this.loadMessageFace();
// 	textState.x = textState.startX;
// 	textState.y = 0 + 70;
// 	textState.height = this.calcTextHeight(textState);
// };

//##########　名前欄
// Window_NameBox.prototype.initialize = function () {
// 	Window_Base.prototype.initialize.call(this, new Rectangle());
// 	this.openness = 0;
// 	this._name = "";

// 	this._isWindow = false;
// };

// Window_NameBox.prototype.updatePlacement = function () {
// 	this.width = this.windowWidth();
// 	this.height = this.windowHeight();
// 	const messageWindow = this._messageWindow;
// 	if ($gameMessage.isRTL()) {
// 		this.x = messageWindow.x + messageWindow.width - this.width;
// 	} else {
// 		this.x = messageWindow.x;
// 	}
// 	if (messageWindow.y > 0) {
// 		this.y = messageWindow.y - this.height + 70;
// 	} else {
// 		this.y = messageWindow.y + messageWindow.height + 70;
// 	}
// };
// Window_NameBox.prototype.windowWidth = function () {
// 	return Graphics.width;
// };

// Window_NameBox.prototype.refresh = function () {
// 	const rect = this.baseTextRect();
// 	this.contents.clear();
// 	this.drawTextEx(this._name, 224, rect.y, rect.width);
// };
// Window_NameBox.prototype.loadWindowskin = function () {
// 	this.windowskin = ImageManager.loadSystem("name");
// };
// Window_NameBox.prototype._refreshBack = function () {
// 	const sprite = this._backSprite;
// 	sprite.x = (1280 - 793) / 2;
// 	sprite.y = 50;
// 	// [Note] We use 95 instead of 96 here to avoid blurring edges.
// 	sprite.bitmap = this._windowskin;
// };

// Window_NameBox.prototype._refreshFrame = function () {};
// Window_NameBox.prototype.updateBackOpacity = function () {
// 	this.backOpacity = 255;
// };
