//============================================================================= // IIISceneItem.js // ---------------------------------------------------------------------------- // (C) 2022 III // ---------------------------------------------------------------------------- /*:ja * @author III * @plugindesc 御前試合用のアイテムシーン * @target MZ * @help 御前試合用のアイテムシーンを提供します * ・アイテムのメモ欄に と記入すると、数値の大きい順にソートされます。 *  何も入力されていなければ数値0として扱います。 *  数値が同じ値の場合はMV標準のソート方法でソートされます(おそらくアイテムID昇順) *  この機能は4カラムレイアウトを有効にしていなくてもデフォルトで有効になります。 *  向こうにしたい場合はプラグインパラメータで制御できるようにするので相談してください。 * * ・4カラムレイアウトを有効にします。どのカテゴリのアイテムを4カラムとするか?はプラグインパラメータで指定してください。 *  (EnableCategoryXXXのパラメータ) * * ・4カラムレイアウトが有効な場合に、アイテムのメモ欄に と記入するとアイテムが所属するカラムを指定できます。 *  cateは0~3の範囲で指定してください。cate指定が無い場合、cate範囲が4以上の場合はcate=0として扱われます。 * * @param EnableCategoryItem * @desc アイテムカテゴリ「通常」を4カラムにする。 * @default true * @type boolean * * @param EnableCategoryWeapon * @desc アイテムカテゴリ「武器」を4カラムにする。 * @default false * @type boolean * * @param EnableCategoryArmor * @desc アイテムカテゴリ「防具」を4カラムにする。 * @default false * @type boolean * * @param EnableCategoryKeyItem * @desc アイテムカテゴリ「大事なもの」を4カラムにする。 * @default true * @type boolean * */ var Imported = Imported || {}; Imported["IIISceneItem"] = 1.0; (function () { "use strict"; var createPluginParameter = function (pluginName) { var params = JSON.parse( JSON.stringify(PluginManager.parameters(pluginName), function (k, v) { if (v === "null") { return v; } if (v[0] === '"' && v[v.length - 1] === '"') { return v; } try { return JSON.parse(v); } catch (e) { return v; } }) ); PluginManager.setParameters(pluginName, params); return params; }; var pluginParam = createPluginParameter("IIISceneItem"); //メタ情報に基づいたソート var _Window_ItemList_prototype_makeItemList = Window_ItemList.prototype.makeItemList; Window_ItemList.prototype.makeItemList = function () { _Window_ItemList_prototype_makeItemList.call(this); this._data.sort((a, b) => { var an = 0, bn = 0; an = a && a.meta && a.meta.up && !Number.isNaN(a.meta.up) ? parseInt(a.meta.up) : 0; bn = b && b.meta && b.meta.up && !Number.isNaN(b.meta.up) ? parseInt(b.meta.up) : 0; return bn - an; //降順 }); }; //アクター選択ウインドウの幅変更 const _Scene_ItemBase_prototype_actorWindowRect = Scene_ItemBase.prototype.actorWindowRect; Scene_Item.prototype.actorWindowRect = function () { //_Scene_ItemBase_prototype_actorWindowRect.call(this); const wx = 0; const wy = Math.min(this.mainAreaTop(), this.helpAreaTop()); const ww = Graphics.boxWidth - 240 * 3; const wh = this.mainAreaHeight() / 4 + this.helpAreaHeight(); return new Rectangle(wx, wy, ww, wh); }; //カテゴリが4カラムレイアウト対象かどうか Scene_Item.prototype.is4ColumnCategory = function (cate) { switch (cate) { case "item": return pluginParam.EnableCategoryItem; case "weapon": return pluginParam.EnableCategoryWeapon; case "armor": return pluginParam.EnableCategoryArmor; case "keyItem": return pluginParam.EnableCategoryKeyItem; } return false; }; //ウインドウ作成・拡張メンバの初期化もここでやっちゃう var _Scene_Item_prototype_createItemWindow = Scene_Item.prototype.createItemWindow; Scene_Item.prototype.createItemWindow = function () { _Scene_Item_prototype_createItemWindow.call(this); this._currentWindow = null; this._requestChangeWindow = null; this._oneColumnItemWindows = []; var wy = this._categoryWindow.y + this._categoryWindow.height; var wh = Graphics.boxHeight - (wy + this.helpAreaHeight()); for (var i = 0; i < 4; i++) { var ww = Graphics.boxWidth / 4; var wx = i * ww; //todo: windowがindexを持っていて良いのか? var win = new Window_OneColumnItemList(i, new Rectangle(wx, wy, ww, wh)); win.setHelpWindow(this._helpWindow); win.setHandler("ok", this.onItemOk.bind(this)); win.setHandler("cancel", this.onItemCancel.bind(this)); win.setOnTouchSelectedHandler(this.onItemListTouchSelected.bind(this)); win.setOnCursorLRHandler(this.onItemListCursorLR.bind(this)); this.addWindow(win); this._oneColumnItemWindows.push(win); } }; //アイテムカテゴリ決定した時 var _Scene_Item_prototype_onCategoryOk = Scene_Item.prototype.onCategoryOk; Scene_Item.prototype.onCategoryOk = function () { var cate = this._categoryWindow.currentSymbol(); if (this.is4ColumnCategory(cate)) { this._itemWindow.hide(); this._oneColumnItemWindows.forEach(function (win) { win.show(); win.activate(); win.deselect(); }); this.onItemListCursorLR(-1, 1); } else { this._itemWindow.show(); this._oneColumnItemWindows.forEach(function (win) { win.hide(); }); _Scene_Item_prototype_onCategoryOk.call(this); } }; //アイテム決定した時に呼ばれる var _Scene_Item_prototype_onItemOk = Scene_Item.prototype.onItemOk; Scene_Item.prototype.onItemOk = function () { _Scene_Item_prototype_onItemOk.call(this); var cate = this._categoryWindow.currentSymbol(); if (this.is4ColumnCategory(cate)) { //タッチ反応しないように this._oneColumnItemWindows.forEach(function (win) { win.deactivate(); }); } }; //アイテムキャンセルした時に呼ばれる var _Scene_Item_prototype_onItemCancel = Scene_Item.prototype.onItemCancel; Scene_Item.prototype.onItemCancel = function () { var cate = this._categoryWindow.currentSymbol(); if (this.is4ColumnCategory(cate)) { this._oneColumnItemWindows.forEach(function (win) { win.deselect(); win._enableWindow = false; }); this._currentWindow = null; this._requestChangeWindow = null; this._categoryWindow.activate(); } else { _Scene_Item_prototype_onItemCancel.call(this); } }; //アイテム決定した時に呼ばれる・itemどれを取得するか var _Scene_Item_prototype_item = Scene_Item.prototype.item; Scene_Item.prototype.item = function () { var cate = this._categoryWindow.currentSymbol(); if (this.is4ColumnCategory(cate)) { return this._currentWindow.item(); } return _Scene_Item_prototype_item.call(this); }; var _Scene_Item_prototype_useItem = Scene_Item.prototype.useItem; Scene_Item.prototype.useItem = function () { _Scene_Item_prototype_useItem.call(this); var cate = this._categoryWindow.currentSymbol(); if (this.is4ColumnCategory(cate)) { this._oneColumnItemWindows.forEach(function (win) { win.redrawCurrentItem(); }); } }; //ActorWin→cancelで戻ってくるときに呼ばれる var _Scene_Item_prototype_activateItemWindow = Scene_Item.prototype.activateItemWindow; Scene_Item.prototype.activateItemWindow = function () { var cate = this._categoryWindow.currentSymbol(); if (this.is4ColumnCategory(cate)) { //タッチ反応するように this._oneColumnItemWindows.forEach(function (win) { win.refresh(); win.activate(); }); } else { _Scene_Item_prototype_activateItemWindow.call(this); } }; //フレーム更新 var _Scene_Item_prototype_update = Scene_Item.prototype.update; Scene_Item.prototype.update = function () { _Scene_Item_prototype_update.call(this); var cate = this._categoryWindow.currentSymbol(); if (this.is4ColumnCategory(cate)) { this._itemWindow.hide(); this._oneColumnItemWindows.forEach(function (win) { win.show(); win.setCategory(cate); }); this.changeListWindowIfNeed(); } else { this._itemWindow.show(); this._oneColumnItemWindows.forEach(function (win) { win.hide(); }); } }; //タッチによる別リストウインドウの選択 Scene_Item.prototype.onItemListTouchSelected = function (win, triggerd) { if (win.maxItems() <= 0) { return; } this._requestChangeWindow = win; }; //キーボードによる別リストウインドウの選択 Scene_Item.prototype.onItemListCursorLR = function (winIdx, dir) { if (this._oneColumnItemWindows.length <= 1) { return; } //選択可能なウインドウ見つかるまで検索 var index = winIdx; var newWin = null; var searchCount = this._oneColumnItemWindows.length; do { searchCount--; index += dir > 0 ? 1 : -1; if (index < 0) { index = this._oneColumnItemWindows.length - 1; } else if (index >= this._oneColumnItemWindows.length) { index = 0; } if (this._oneColumnItemWindows[index].maxItems() <= 0) { continue; } newWin = this._oneColumnItemWindows[index]; if (newWin != null) { break; } } while (searchCount > 0); if (newWin != null) { AudioManager.playSe({ name: "Cursor1", volume: 100, pitch: 100, pan: 0 }); this.onItemListTouchSelected(newWin); } }; //変更要求あれば操作対象ウインドウを変更 Scene_Item.prototype.changeListWindowIfNeed = function () { var newWin = this._requestChangeWindow; var oldWin = this._currentWindow; if (!newWin || newWin == oldWin) { return; } if (oldWin) { oldWin._enableWindow = false; oldWin.deselect(); } this._currentWindow = newWin; this._currentWindow._enableWindow = true; if ( this._currentWindow.item() == null && this._currentWindow.maxItems() > 0 ) { this._currentWindow.select(0); } this._requestChangeWindow = null; }; var _Window_Base_prototype_drawItemName = Window_Base.prototype.drawItemName; Window_Base.prototype.drawItemName = function (item, x, y, width) { this.contents.fontSize = 20; // フォントサイズを設定 _Window_Base_prototype_drawItemName.call(this, item, x, y, width); this.resetFontSettings(); }; //----------------------------------------------------------------------------- // Window_OneColumnItemList // // 4カラムレイアウト用のウインドウ。強制的に1カラムになる。 function Window_OneColumnItemList() { this.initialize.apply(this, arguments); } Window_OneColumnItemList.prototype = Object.create(Window_ItemList.prototype); Window_OneColumnItemList.prototype.constructor = Window_OneColumnItemList; Window_OneColumnItemList.prototype.maxCols = function () { return 1; }; Window_OneColumnItemList.prototype.initialize = function (index, rect) { Window_ItemList.prototype.initialize.call(this, rect); this._enableWindow = false; this._winIndex = index; }; Window_OneColumnItemList.prototype.setOnTouchSelectedHandler = function ( handler ) { this._onTouchSelectedHandler = handler; }; Window_OneColumnItemList.prototype.setOnCursorLRHandler = function (handler) { this._onCursorLRHandler = handler; }; var _Window_OneColumnItemList_prototype_includes = Window_OneColumnItemList.prototype.includes; Window_OneColumnItemList.prototype.includes = function (item) { var ret = _Window_OneColumnItemList_prototype_includes.call(this, item); if (ret) { var cate = 0; if (item && item.meta && item.meta.cate) { cate = parseInt(item.meta.cate); } return cate == this._winIndex; } return ret; }; var _Window_OneColumnItemList_prototype_onTouchSelect = Window_OneColumnItemList.prototype.onTouchSelect; Window_OneColumnItemList.prototype.onTouchSelect = function (triggerd) { const hitIndex = this.hitIndex(); if (hitIndex >= 0) { _Window_OneColumnItemList_prototype_onTouchSelect.call(this, triggerd); if (!!this._onTouchSelectedHandler) { this._onTouchSelectedHandler(this, triggerd); } } }; var _Window_OneColumnItemList_prototype_cursorUp = Window_OneColumnItemList.prototype.cursorUp; Window_OneColumnItemList.prototype.cursorUp = function (wrap) { if (!this._enableWindow) return; _Window_OneColumnItemList_prototype_cursorUp.call(this, wrap); }; var _Window_OneColumnItemList_prototype_cursorDown = Window_OneColumnItemList.prototype.cursorDown; Window_OneColumnItemList.prototype.cursorDown = function (wrap) { if (!this._enableWindow) return; _Window_OneColumnItemList_prototype_cursorDown.call(this, wrap); }; var _Window_OneColumnItemList_prototype_processPageup = Window_OneColumnItemList.prototype.processPageup; Window_OneColumnItemList.prototype.processPageup = function () { if (!this._enableWindow) return; _Window_OneColumnItemList_prototype_processPageup.call(this); }; var _Window_OneColumnItemList_prototype_cursorPagedown = Window_OneColumnItemList.prototype.cursorPagedown; Window_OneColumnItemList.prototype.cursorPagedown = function () { if (!this._enableWindow) return; _Window_OneColumnItemList_prototype_cursorPagedown.call(this); }; var _Window_OneColumnItemList_prototype_cursorLeft = Window_OneColumnItemList.prototype.cursorLeft; Window_OneColumnItemList.prototype.cursorLeft = function (wrap) { if (!this._enableWindow) return; if (!!this._onCursorLRHandler) { this._onCursorLRHandler(this._winIndex, -1); } }; var _Window_OneColumnItemList_prototype_cursorRight = Window_OneColumnItemList.prototype.cursorRight; Window_OneColumnItemList.prototype.cursorRight = function (wrap) { if (!this._enableWindow) return; if (!!this._onCursorLRHandler) { this._onCursorLRHandler(this._winIndex, 1); } }; var _Window_OneColumnItemList_prototype_processOk = Window_OneColumnItemList.prototype.processOk; Window_OneColumnItemList.prototype.processOk = function () { if (!this._enableWindow) return; _Window_OneColumnItemList_prototype_processOk.call(this); }; })();