//CBR_evRecos = null;

//DataManager._databaseFiles.push({ name: "CBR_evRecos", src: "CBR_eventList.json" });
function Scene_eroStatus() {
	this.initialize(...arguments);
}

(function () {
	Scene_eroStatus.prototype = Object.create(Scene_MenuBase.prototype);
	Scene_eroStatus.prototype.constructor = Scene_eroStatus;

	Scene_eroStatus.prototype.initialize = function () {
		Scene_MenuBase.prototype.initialize.call(this);

		this.CBR_live2D_list = [10, 11, 12, 13, 14, 15];
	};

	const Scene_eroStatus_terminate = Scene_eroStatus.prototype.terminate;
	Scene_eroStatus.prototype.terminate = function () {
		for (var i = 1; i <= $gameLive2d.MAXNUMBER; i++) {
			//this.live2dSprite[i].clear();
		}
		Scene_eroStatus_terminate.call(this);
	};

	const Scene_eroStatus_start = Scene_eroStatus.prototype.start;
	Scene_eroStatus.prototype.start = function () {
		Scene_eroStatus_start.call(this);
		this.createlive2d();
	};

	const Scene_eroStatus_update = Scene_eroStatus.prototype.update;
	Scene_eroStatus.prototype.update = function () {
		Scene_eroStatus_update.call(this);
		this.updatelive2d();
	};

	// ウィンドウのmarginを消去する
	Scene_eroStatus.prototype.createWindowLayer = function () {
		this._windowLayer = new WindowLayer();
		this._windowLayer.x = 0;
		this._windowLayer.y = 0;
		this.addChild(this._windowLayer);
	};

	Scene_eroStatus.prototype.createBackground = function () {
		this._backgroundSprite = new Sprite();
		this._backgroundSprite.bitmap = ImageManager.loadSystem("option_back");
		this.addChild(this._backgroundSprite);

		//背景の追加
		this._backgroundSprite_rireki = { sira: [0, 1], yozu: [0, 1] };
		this._backgroundSprite_rireki.sira[0] = new Sprite();
		this._backgroundSprite_rireki.sira[0].bitmap = ImageManager.loadSystem("erost_rireki_sira");
		this._backgroundSprite_rireki.sira[0].visible = false;
		this.addChild(this._backgroundSprite_rireki.sira[0]);

		this._backgroundSprite_rireki.yozu[0] = new Sprite();
		this._backgroundSprite_rireki.yozu[0].bitmap = ImageManager.loadSystem("erost_rireki_yozu");
		this._backgroundSprite_rireki.yozu[0].visible = false;
		this.addChild(this._backgroundSprite_rireki.yozu[0]);

		this._backgroundSprite_kaihatu = new Sprite();
		this._backgroundSprite_kaihatu.bitmap = ImageManager.loadSystem("erost_kaihatu_frame");
		this._backgroundSprite_kaihatu.visible = false;
		this.addChild(this._backgroundSprite_kaihatu);

		this._backgroundTextSprite = new Sprite(new Bitmap(Graphics.width, Graphics.height));
		var b = this._backgroundTextSprite.bitmap;
		b.fontFace = "serif";
		b.fontSize = 32;
		b.textColor = "#000000";
		b.drawTextM("Ｈステータス", 22, 20, 200, 22, "center");
		this.addChild(this._backgroundTextSprite);
	};

	Scene_eroStatus.prototype.create = function () {
		//Scene_MenuBase.prototype.create.call(this);

		Scene_Base.prototype.create.call(this);
		this.createBackground();

		this.updateActor();
		this.createWindowLayer();
		this.createButtons();

		DataManager.loadAllSavefileImages();
		this.createProfWindow();
		this.createKaihatuWindows();
		this.createRirekiWindows();
		this.createRireki_syuWindows();
		this.createSyougouWindow();

		this.createKirokuWindow();
		this.createCategoryWindow();

		//live2d用
		this._spriteset = new Spriteset_Base();
		this._spriteset._blackScreen.opacity = 0;
		this.addChild(this._spriteset);

		const commonEvent = $dataCommonEvents[1122];
		if (commonEvent) {
			const interpreter = new Game_Interpreter();
			interpreter.setup(commonEvent.list);
			interpreter.update();
		}
	};

	Scene_eroStatus.prototype.profWindowRect = function () {
		const wx = 0;
		const wy = 65;
		const ww = Graphics.width;
		const wh = 680;
		return new Rectangle(wx, wy, ww, wh);
	};
	Scene_eroStatus.prototype.createProfWindow = function () {
		const rect = this.profWindowRect();
		this._profWindow = new Window_EroStatus_prof(rect);
		this.addWindow(this._profWindow);
	};

	Scene_eroStatus.prototype.kaihatu_viewWindowRect = function () {
		const wx = 380;
		const wy = 0;
		const ww = Graphics.width - wx;
		const wh = 720;
		return new Rectangle(wx, wy, ww, wh);
	};
	Scene_eroStatus.prototype.kaihatu_selectWindowRect = function () {
		const wx = 0;
		const wy = 67;
		const ww = 390;
		const wh = 650;
		return new Rectangle(wx, wy, ww, wh);
	};

	Scene_eroStatus.prototype.createKaihatuWindows = function () {
		const rectV = this.kaihatu_viewWindowRect();
		this._kaihatuViewWindow = new Window_EroStatus_kaihatu_view(rectV);
		this._kaihatuViewWindow.hide();
		this.addWindow(this._kaihatuViewWindow);

		const rectS = this.kaihatu_selectWindowRect();
		this._kaihatuWindow = new Window_EroStatus_kaihatu_select(rectS);
		this._kaihatuWindow.setViewWindow(this._kaihatuViewWindow);
		this._kaihatuWindow.setHandler("ok", this.onKaihatuOk.bind(this));

		this._kaihatuWindow.callUpdateHelp();
		this._kaihatuWindow.hide();
		this.addWindow(this._kaihatuWindow);
	};

	// processOkも実行されるから注意ね
	Scene_eroStatus.prototype.onKaihatuOk = function () {
		this._kaihatuWindow.do_ok();
	};

	Scene_eroStatus.prototype.rireki_viewWindowRect = function () {
		const wx = 0;
		const wy = 520;
		const ww = Graphics.width - wx;
		const wh = 200;
		return new Rectangle(wx, wy, ww, wh);
	};

	Scene_eroStatus.prototype.rireki_selectWindowRect = function () {
		const wx = 270;
		const wy = 80;
		const ww = Graphics.width - wx - 140;
		const wh = 466;
		return new Rectangle(wx, wy, ww, wh);
	};

	Scene_eroStatus.prototype.createRirekiWindows = function () {
		const rectV = this.rireki_viewWindowRect();
		this._rirekiViewWindow = new Window_EroStatus_rireki_view(rectV);
		this._rirekiViewWindow.hide();
		this.addWindow(this._rirekiViewWindow);

		const rectS = this.rireki_selectWindowRect();
		this._rirekiWindow = new Window_EroStatus_rireki_select(rectS);
		this._rirekiWindow.setViewWindow(this._rirekiViewWindow);
		this._rirekiWindow.callUpdateHelp();
		this._rirekiWindow.hide();
		this.addWindow(this._rirekiWindow);
	};

	Scene_eroStatus.prototype.createRireki_syuWindows = function () {
		const rectV = this.rireki_viewWindowRect();
		this._rireki_syuViewWindow = new Window_EroStatus_rireki_syu_view(rectV);
		this._rireki_syuViewWindow.hide();
		this.addWindow(this._rireki_syuViewWindow);

		const rectS = this.rireki_selectWindowRect();
		this._rireki_syuWindow = new Window_EroStatus_rireki_syu_select(rectS);
		this._rireki_syuWindow.setViewWindow(this._rireki_syuViewWindow);
		this._rireki_syuWindow.callUpdateHelp();
		this._rireki_syuWindow.hide();
		this.addWindow(this._rireki_syuWindow);
	};

	Scene_eroStatus.prototype.syougouWindowRect = function () {
		const wx = 160;
		const wy = 80;
		const ww = Graphics.width - wx * 2;
		const wh = Graphics.height - wy - 14;
		return new Rectangle(wx, wy, ww, wh);
	};
	Scene_eroStatus.prototype.createSyougouWindow = function () {
		const rect = this.syougouWindowRect();
		this._syougouWindow = new Window_EroStatus_syougou(rect);
		this._syougouWindow.hide();
		this.addWindow(this._syougouWindow);
	};

	Scene_eroStatus.prototype.kirokuWindowRect = function () {
		const wx = 0;
		const wy = 65;
		const ww = Graphics.width;
		const wh = Graphics.height - wy;
		return new Rectangle(wx, wy, ww, wh);
	};
	Scene_eroStatus.prototype.createKirokuWindow = function () {
		const rect = this.kirokuWindowRect();
		this._kirokuWindow = new Window_EroStatus_kiroku(rect);
		this._kirokuWindow.hide();
		this.addWindow(this._kirokuWindow);
	};

	Scene_eroStatus.prototype.createCategoryWindow = function () {
		const rect = this.categoryWindowRect();
		this._categoryWindow = new Window_EroCategory(rect);

		this._categoryWindow.setProfWindow(this._profWindow);
		this._categoryWindow.setHandler("cancel", this.popScene.bind(this));
		this._categoryWindow.setKaihatuWindows(this._kaihatuWindow, this._kaihatuViewWindow);
		this._categoryWindow.setRirekiWindows(this._rirekiWindow, this._rirekiViewWindow);
		this._categoryWindow.setRireki_syuWindows(this._rireki_syuWindow, this._rireki_syuViewWindow);
		this._categoryWindow.setSyougouWindow(this._syougouWindow);
		this._categoryWindow.setKirokuWindow(this._kirokuWindow);

		this._categoryWindow.setHandler("ok", this.onCategoryOk.bind(this));

		this.addWindow(this._categoryWindow);
	};

	Scene_eroStatus.prototype.onCategoryOk = function () {
		if (this._categoryWindow.change_category) {
			var id = $gameParty._menuActorId == 1 ? 2 : 1;
			var actor = $gameActors.actor(id);
			$gameParty.setMenuActor(actor);
			SoundManager.playOk();

			var chara_show = actor.name() == "Shirayuki" ? "sira" : "yozu";
			var chara_hide = actor.name() == "Shirayuki" ? "yozu" : "sira";

			if (this._categoryWindow._category == "prof") {
				this._profWindow.refresh();
			}

			if (this._categoryWindow._category == "kiroku") {
				this._kirokuWindow.refresh();
				this._backgroundSprite_rireki[chara_show][0].visible = true;
				this._backgroundSprite_rireki[chara_hide][0].visible = false;
			}

			if (this._categoryWindow._category == "syougou") {
				this._syougouWindow.refresh();
				this._backgroundSprite_rireki[chara_show][0].visible = true;
				this._backgroundSprite_rireki[chara_hide][0].visible = false;
			}

			if (this._categoryWindow._category == "rireki_syu") {
				this._rireki_syuWindow.makeList();
				this._rireki_syuWindow.refresh();
				this._rireki_syuWindow.forceSelect(0);
				this._rireki_syuViewWindow.refresh();
				this._backgroundSprite_rireki[chara_show][0].visible = true;
				this._backgroundSprite_rireki[chara_hide][0].visible = false;
			}

			if (this._categoryWindow._category == "rireki") {
				this._rirekiWindow.makeList();
				this._rirekiWindow.refresh();
				this._rirekiWindow.forceSelect(0);
				this._backgroundSprite_rireki[chara_show][0].visible = true;
				this._backgroundSprite_rireki[chara_hide][0].visible = false;
			}

			if (this._categoryWindow._category == "kaihatu") {
				this._kaihatuWindow.refresh();
				this._kaihatuViewWindow.refresh();
				this._backgroundSprite_rireki[chara_hide][0].visible = false;

				if (chara_hide == "sira") {
					CBR_forceHide("shirayuki_uniform_expression");
					CBR_forceHide("shirayuki_naked_expression");
					CBR_forceHide("shirayuki_holdnaked_expression");
				} else {
					CBR_forceHide("yozuru_uniform_expression");
					CBR_forceHide("yozuru_naked_expression");
					CBR_forceHide("yozuru_holdnaked_expression");
				}
				this._categoryWindow._category = null;
				this._categoryWindow.setCategory("kaihatu");
			}
		}
	};

	Scene_eroStatus.prototype.popScene = function () {
		CBR_forceHide("shirayuki_uniform_expression");
		CBR_forceHide("shirayuki_naked_expression");
		CBR_forceHide("shirayuki_holdnaked_expression");
		CBR_forceHide("yozuru_uniform_expression");
		CBR_forceHide("yozuru_naked_expression");
		CBR_forceHide("yozuru_holdnaked_expression");
		SceneManager.pop();
	};

	// ####################################################
	// ################# カテゴリー ####################
	// ####################################################
	// カテゴリーウィンドウ
	function Window_EroCategory() {
		this.initialize(...arguments);
	}

	Window_EroCategory.prototype = Object.create(Window_HorzCommand.prototype);
	Window_EroCategory.prototype.constructor = Window_EroCategory;

	Scene_eroStatus.prototype.categoryWindowRect = function () {
		const wx = 270;
		const wy = -6;
		const ww = Graphics.width - wx;
		const wh = 58 + 8;
		return new Rectangle(wx, wy, ww, wh);
	};

	Window_EroCategory.prototype.processOk = function () {
		if (this.isCurrentItemEnabled()) {
			this.playOkSound();
			this.updateInputData();
			//this.deactivate();
			this.callOkHandler();
		} else {
			this.playBuzzerSound();
		}
	};

	Window_EroCategory.prototype.initialize = function (rect) {
		Window_HorzCommand.prototype.initialize.call(this, rect);
		this._padding = 0;
		this.setCategory("prof");
	};

	Window_EroCategory.prototype.maxCols = function () {
		return 7;
	};

	//カテゴリーはアイテムと大事な物だけにする
	Window_EroCategory.prototype.makeCommandList = function () {
		this.addCommand("プロフィール", "prof");
		this.addCommand("Ｈ開発度", "kaihatu");
		this.addCommand("Ｈ履歴", "rireki");
		this.addCommand("出産履歴", "rireki_syu");
		this.addCommand("Ｈ称号", "syougou");
		this.addCommand("Ｈ記録", "kiroku");
		if (1 < $gameParty.allMembers().length) {
			this.addCommand("チェンジ", "change");
		}
	};
	Window_EroCategory.prototype.setProfWindow = function (profWindow) {
		this._profWindow = profWindow;
	};

	Window_EroCategory.prototype.setKaihatuWindows = function (kaihatuWindow, kaihatuViewWindow) {
		this._kaihatuWindow = kaihatuWindow;
		this._kaihatuViewWindow = kaihatuViewWindow;
		//this.callUpdateHelp();
	};
	Window_EroCategory.prototype.setRirekiWindows = function (rirekiWindow, rirekiViewWindow) {
		this._rirekiWindow = rirekiWindow;
		this._rirekiViewWindow = rirekiViewWindow;
	};
	Window_EroCategory.prototype.setRireki_syuWindows = function (rireki_syuWindow, rireki_syuViewWindow) {
		this._rireki_syuWindow = rireki_syuWindow;
		this._rireki_syuViewWindow = rireki_syuViewWindow;
	};
	Window_EroCategory.prototype.setSyougouWindow = function (syougouWindow) {
		this._syougouWindow = syougouWindow;
	};
	Window_EroCategory.prototype.setKirokuWindow = function (kirokuWindow) {
		this._kirokuWindow = kirokuWindow;
	};

	// 変更があったらカテゴリーを更新する
	Window_EroCategory.prototype.update = function () {
		Window_HorzCommand.prototype.update.call(this);
		this.setCategory(this.currentSymbol());

		if (this.currentSymbol() == "kaihatu") {
			if (this.re_kaihatu) {
				this.re_kaihatu = false;
				this.show_kaihatu();
			}

			// 表示された後妊娠描写をする
			const model_sp = SceneManager._scene.live2dSprite[SceneManager._scene.nin_flag];
			if (SceneManager._scene.nin_flag && model_sp._model && model_sp._model.internalModel) {
				var actor = $gameParty.menuActor();
				var chara = actor.name() == "Shirayuki" ? "sira" : "yozu";
				if (chara == "sira") {
					model_sp._model.internalModel.coreModel._parameterValues[43] = 1;
					model_sp._model.internalModel.coreModel._parameterValues[44] = 1;
				} else {
					model_sp._model.internalModel.coreModel._parameterValues[34] = 1;
				}

				SceneManager._scene.nin_flag = false;
			}
		}
	};

	Window_EroCategory.prototype.show_kaihatu = function () {
		var actor = $gameParty.menuActor();
		var chara = actor.name() == "Shirayuki" ? "sira" : "yozu";
		//loadModelのロードが終わった後に実行されないとバグる

		// live2d処理
		// var ary = [
		// 	{ model: "uniform", sira: 10, yozu: 13 },
		// 	{ model: "naked", sira: 11, yozu: 14 },
		// 	{ model: "uniform", sira: 10, yozu: 13 },
		// 	{ model: "naked", sira: 11, yozu: 14 }
		// ];
		var ary = ["exp0", "exp1", "exp2", "exp3"];
		if (chara == "sira") {
			if ($gameVariables.value(204) == 0) {
				var key = 10;
				var text = "shirayuki_uniform_expression";
			} else {
				if ($gameVariables.value(204) == 1) {
					if ($gameSwitches.value(267)) {
						var key = 11;
						var text = "shirayuki_naked_expression";
					} else {
						key = 12;
						var text = "shirayuki_holdnaked_expression";
					}
				} else if ($gameVariables.value(204) == 2) {
					var key = 10;
					var text = "shirayuki_uniform_expression";
				} else if ($gameVariables.value(204) == 3) {
					var key = 11;
					var text = "shirayuki_naked_expression";
				}
			}

			if (!SceneManager._scene.live2dSprite[key]._model) {
				this.re_kaihatu = true;
			} else {
				SceneManager._scene.resetLive2d(key, ary[$gameVariables.value(245)]);
				CBR_forceShow(text);

				// 表示された後妊娠描写をする
				if ($gameVariables.value(204) == 2 || $gameVariables.value(204) == 3) {
					SceneManager._scene.nin_flag = key;
				}
			}
		} else {
			if ($gameVariables.value(205) == 0) {
				var key = 13;
				var text = "yozuru_uniform_expression";
			} else {
				if ($gameVariables.value(205) == 1) {
					if ($gameSwitches.value(313)) {
						var key = 14;
						var text = "yozuru_naked_expression";
					} else {
						var key = 15;
						var text = "yozuru_holdnaked_expression";
					}
				} else if ($gameVariables.value(205) == 2) {
					var key = 13;
					var text = "yozuru_uniform_expression";
				} else if ($gameVariables.value(205) == 3) {
					var key = 14;
					var text = "yozuru_naked_expression";
				}
			}
			if (!SceneManager._scene.live2dSprite[key]._model) {
				this.re_kaihatu = true;
			} else {
				SceneManager._scene.resetLive2d(key, ary[$gameVariables.value(325)]);
				CBR_forceShow(text);

				// 表示された後妊娠描写をする
				if ($gameVariables.value(205) == 2 || $gameVariables.value(205) == 3) {
					SceneManager._scene.nin_flag = key;
				}
			}
			// if (!$gameSwitches.value(313)) {
			// 	SceneManager._scene.resetLive2d(15);
			// 	CBR_forceShow("yozuru_holdnaked_expression");
			// } else {
			// 	var key = $gameVariables.value(205);
			// 	SceneManager._scene.resetLive2d(ary[key][chara]);
			// 	CBR_forceShow(`yozuru_${ary[key].model}_expression`);
			// }
		}
		this.parent.parent._backgroundSprite_kaihatu.visible = true;
		this._kaihatuWindow.refresh();
		this._kaihatuWindow.show();
		this._kaihatuViewWindow.refresh();
		this._kaihatuViewWindow.show();
	};

	Window_EroCategory.prototype.setCategory = function (category) {
		this.change_category = false;

		if (category == "change") {
			this.change_category = true;
		} else if (this._category !== category) {
			this._category = category;

			var actor = $gameParty.menuActor();
			var chara = actor.name() == "Shirayuki" ? "sira" : "yozu";

			if (this.parent) {
				this.parent.parent._backgroundSprite_rireki[chara][0].visible = false;
			}

			if (this._profWindow) {
				if (category == "prof") {
					this._profWindow.refresh();
					this._profWindow.show();
				} else {
					this._profWindow.hide();
				}
			}

			if (this._kaihatuWindow) {
				if (category == "kaihatu") {
					this.show_kaihatu();
				} else {
					if (chara == "sira") {
						CBR_forceHide("shirayuki_uniform_expression");
						CBR_forceHide("shirayuki_naked_expression");
						CBR_forceHide("shirayuki_holdnaked_expression");
					} else {
						CBR_forceHide("yozuru_uniform_expression");
						CBR_forceHide("yozuru_naked_expression");
						CBR_forceHide("yozuru_holdnaked_expression");
					}
					this.parent.parent._backgroundSprite_kaihatu.visible = false;
					this._kaihatuWindow.hide();
					this._kaihatuViewWindow.hide();
				}
			}

			if (this._rirekiWindow && this._rirekiViewWindow) {
				if (category == "rireki") {
					this._rirekiWindow.refresh();
					this._rirekiWindow.show();
					this._rirekiViewWindow.show();
					this._rirekiWindow.makeList();
					this.parent.parent._backgroundSprite_rireki[chara][0].visible = true;
				} else {
					this._rirekiWindow.hide();
					this._rirekiViewWindow.hide();
				}
			}

			if (this._rireki_syuWindow && this._rireki_syuViewWindow) {
				if (category == "rireki_syu") {
					this._rireki_syuWindow.refresh();
					this._rireki_syuWindow.show();
					this._rireki_syuViewWindow.show();
					this._rireki_syuWindow.makeList();
					this.parent.parent._backgroundSprite_rireki[chara][0].visible = true;
				} else {
					this._rireki_syuWindow.hide();
					this._rireki_syuViewWindow.hide();
				}
			}

			if (this._syougouWindow) {
				if (category == "syougou") {
					this._syougouWindow.show();
					this._syougouWindow.refresh();
					this.parent.parent._backgroundSprite_rireki[chara][0].visible = true;
				} else {
					this._syougouWindow.hide();
				}
			}

			if (this._kirokuWindow) {
				if (category == "kiroku") {
					this._kirokuWindow.show();
					this._kirokuWindow.refresh();
					this.parent.parent._backgroundSprite_rireki[chara][0].visible = true;
				} else {
					this._kirokuWindow.hide();
				}
			}
			// // 毎回一番上に戻す
			// this.select(0);
			// this.scrollTo(0, 0);
		}
	};

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

	//カーソルの変更
	Window_EroCategory.prototype.loadWindowskin = function () {
		this.windowskin = ImageManager.loadSystem("Window");
		this.menu_item_skin = ImageManager.loadSystem("menu_item_categoly_select");
		this.menu_cursor_skin = ImageManager.loadSystem("menu_item_categoly_cursor");

		if (!this.menu_item_skin.isReady()) {
			this.menu_item_skin.addLoadListener(() => {
				this.refresh(); // 画像がロードされたら再描画
			});
			return;
		}
	};

	Window_EroCategory.prototype.lineHeight = function () {
		return 58;
	};

	Window_EroCategory.prototype._refreshCursor = function () {
		const drect = this._cursorRect.clone();
		const srect = { x: 0, y: 0, width: 126, height: 58 };
		const m = 0;
		for (const child of this._cursorSprite.children) {
			child.bitmap = this.menu_cursor_skin;
		}
		this._setRectPartsGeometry(this._cursorSprite, srect, drect, m);
	};
	//カーソルを微調整、あとカーソルを常に不透明に
	Window_EroCategory.prototype._updateCursor = function () {
		this._cursorSprite.alpha = 255;
		this._cursorSprite.visible = this.isOpen() && this.cursorVisible;
		this._cursorSprite.x = this._cursorRect.x;
		this._cursorSprite.y = this._cursorRect.y - 4;
	};
	//未選択コマンドの背景を画像に
	Window_EroCategory.prototype.drawItemBackground = function (index) {
		const rect = this.itemRect(index);
		if (this.menu_item_skin.isReady()) {
			const bitmap = this.menu_item_skin;
			const dx = rect.x;
			const dy = rect.y;
			const dw = rect.width;
			const dh = rect.height;
			this.contentsBack.blt(bitmap, 0, 0, 126, 58, dx, dy - 4, dw, dh);
		}
	};

	//カーソルが来た時、アイテムの文字名の色を変更する
	Window_EroCategory.prototype.drawItem = function (index) {
		const rect = this.itemLineRect(index);
		const align = this.itemTextAlign();
		this.resetTextColor();
		if (index == this._index) {
			this.changeTextColor("#000000");
		}
		this.changePaintOpacity(this.isCommandEnabled(index));
		//文字をちょっと下にする
		this.drawTextS(this.commandName(index), rect.x, rect.y + 8, rect.width, align);
	};

	//セレクトするたびに背景をリフレッシュ
	Window_EroCategory.prototype.select = function (index) {
		this._index = index;

		this.contents.clear();
		this.contentsBack.clear();
		this.drawAllItems();

		this.refreshCursor();
		this.callUpdateHelp();
	};
	//↑のセレクトでの不具合を出ないようにする
	Window_EroCategory.prototype.drawAllItems = function () {
		this.contents.fontFace = "serif";
		const topIndex = this.topIndex();
		for (let i = 0; i < this.maxVisibleItems(); i++) {
			const index = topIndex + i;

			if (this._list && index < this.maxItems()) {
				//選択ちゅうだけ背景なくす
				if (i != this._index) {
					this.drawItemBackground(index);
				}
				this.drawItem(index);
			}
		}
	};

	Window_EroCategory.prototype.playOkSound = function () {
		// SoundManager.playOk();
	};

	// ###########################################################
	// ##################### プロフィール #####################
	// ###########################################################
	function Window_EroStatus_prof() {
		this.initialize(...arguments);
	}
	Window_EroStatus_prof.prototype = Object.create(Window_Base.prototype);
	Window_EroStatus_prof.prototype.constructor = Window_EroStatus_prof;

	// padding0を適用させる
	Object.defineProperty(Window_EroStatus_prof.prototype, "padding", {
		get: function () {
			return 0;
		},
		set: function (value) {
			this._padding = 0;
			this._refreshAllParts();
		},
		configurable: true
	});

	Window_EroStatus_prof.prototype.initialize = function (rect) {
		Window_Base.prototype.initialize.call(this, rect);
		this._padding = 0;
		this._margin = 0;
		this.refresh();
	};

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

	Window_EroStatus_prof.prototype.refresh = function () {
		const rect = this.baseTextRect();
		this.contents.clear();
		this.contents.fontFace = "serif";

		var bitmap = ImageManager.loadSystem("erost_prof_back");
		this.contents.blt(bitmap, 0, 0, 1280, 720, 0, 0);
		if (!bitmap.isReady()) {
			bitmap.addLoadListener(() => {
				this.refresh(); // 画像がロードされたら再描画
			});
			return;
		}

		var bitmap = ImageManager.loadSystem("erost_prof_frame");
		this.contents.blt(bitmap, 0, 0, 1280, 720, 0, 0);
		if (!bitmap.isReady()) {
			bitmap.addLoadListener(() => {
				this.refresh(); // 画像がロードされたら再描画
			});
			return;
		}

		var actor = $gameParty.menuActor();
		var chara = "sira";
		//一応画像のチラ付き抑える為にロードだけはやる
		if (actor.name() == "Shirayuki") {
			var bitmap = ImageManager.loadSystem("erost_prof_sira");
			ImageManager.loadSystem("erost_prof_yozu");
		} else {
			ImageManager.loadSystem("erost_prof_sira");
			var bitmap = ImageManager.loadSystem("erost_prof_yozu");
			chara = "yozu";
		}
		this.contents.blt(bitmap, 0, 0, 1280, 720, 580, -65);
		if (!bitmap.isReady()) {
			bitmap.addLoadListener(() => {
				this.refresh(); // 画像がロードされたら再描画
			});
			return;
		}

		var data = {
			sira: {
				name: "白雪・Lindblum",
				tall: "１５４",
				size3: [
					//0が通常 1は妊婦
					{ b: "１００", w: "５８　", h: "８８　" },
					{ b: "１１９", w: "９０", h: "９０" }
				]
			},
			yozu: {
				name: "黒羽夜鶴",
				tall: "１５６",
				size3: [
					{ b: "９４", w: "５６", h: "９１" },
					{ b: "１０８", w: "８８", h: "９６" }
				]
			}
		};

		//左上のコンテンツ
		this.contents.fontSize = 18;
		var sY = 129;
		var lineY = 34;
		var sX = 84;
		var lineX = 98;
		this.changeTextColor("#000000");
		this.drawTextM("名前", sX, sY, 400);
		this.drawTextM("身長", sX, sY + lineY, 400);
		this.drawTextM("３サイズ", sX, sY + lineY * 2, 400);
		this.drawTextM("バスト", sX + lineX, sY + lineY * 2, 400);
		this.drawTextM("ウエスト", sX + lineX, sY + lineY * 3, 400);
		this.drawTextM("ヒップ", sX + lineX, sY + lineY * 4, 400);

		this.resetTextColor();
		this.contents.fontSize = 18;

		this.drawTextS(data[chara].name, sX + lineX, sY, 400);
		this.drawTextS(`${data[chara].tall}ｃｍ`, sX + lineX, sY + lineY, 400);
		//3サイズ
		this.drawTextS(`${data[chara].size3[0].b}ｃｍ`, sX + lineX * 2, sY + lineY * 2, 400);
		this.drawTextS(`${data[chara].size3[0].w}ｃｍ`, sX + lineX * 2, sY + lineY * 3, 400);
		this.drawTextS(`${data[chara].size3[0].h}ｃｍ`, sX + lineX * 2, sY + lineY * 4, 400);

		//右上のコンテンツ
		var sY = 301;
		var lineY = 30;
		var sX = 84;
		var lineX = 75;
		this.changeTextColor("#000000");
		this.drawTextM("最近のＨ経験報告", sX, sY, 400);
		this.drawTextM("相手", sX, sY + lineY, 400);
		this.drawTextM("種族", sX, sY + lineY * 2, 400);
		this.drawTextM("場所", sX, sY + lineY * 3, 400);

		this.resetTextColor();
		this.contents.fontSize = 17;

		var ary = $gameVariables.value(143) || [];
		var ary2 = ary.filter((e) => CBR_eroRireki[e.id].actor == actor.name()) || [];
		this.contents.fontFace = "serif";

		if (ary2[0]) {
			var d = CBR_eroRireki[ary2[0].id];
			this.drawTextS(d.target, sX + lineX, sY + lineY, 400);
			this.drawTextS(d.job, sX + lineX, sY + lineY * 2, 400);
			this.drawTextS(d.place, sX + lineX, sY + lineY * 3, 400);
			this.drawTextExS(d.text, sX - 5, sY + lineY * 4 + 4, 400);
		}
	};
})();
