查看: 7092|回复: 9

[搬运汉化] 小说游戏风选择窗口插件 LL_GalgeChoiceWindow.js

[复制链接]
梦石
0
星屑
23542
在线时间
123 小时
注册时间
2019-5-18
回帖
44
发表于 2021-9-10 01:33:42 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
日文原地址【RPG Maker MZ/MV】
https://nine-yusha.com/plugin-galgechoicewindow/

















[fold=汉化小说游戏风格选择插件]//=============================================================================
// RPGツクールMZ - LL_GalgeChoiceWindow.js v1.0.2
//-----------------------------------------------------------------------------
// ルルの教会 (Lulu's Church)
// https://nine-yusha.com/
//
// URL below for license details.
// https://nine-yusha.com/plugin/
//=============================================================================

/*:
* @target MZ
* @plugindesc 小说游戏风选择窗口插件
* @author ルルの教会
* @url https://nine-yusha.com/plugin/
*
* @help LL_GalgeChoiceWindow.js
**显示小说游戏风格的选择窗口。
*也可以设置自己的窗口图像和按钮图像。
*(请将图像配置在/system文件夹中)
*
*插件命令:
*选项的显示:显示选项,用变量接收结果。
*
*使用规约:
*・不需要著作权记载。
*・使用时没有特别需要报告。
*・不论是商务还是非商务。
*・R18作品也没有使用限制。
*・可以根据游戏自由改变,没有问题。
*禁止作为插件素材的再发布(包括修改后)。
*
*作者:露露的教会
*制作日期:2021/6/22
* ノベルゲーム風の選択肢ウィンドウを表示します。
* 独自のウィンドウ画像、ボタン画像を設定することもできます。
* (画像はimg/systemフォルダに配置してください)
*
* プラグインコマンド:
*   選択肢の表示: 選択肢を表示し、結果を変数で受け取ります。
*
* 利用規約:
*   ・著作権表記は必要ございません。
*   ・利用するにあたり報告の必要は特にございません。
*   ・商用・非商用問いません。
*   ・R18作品にも使用制限はありません。
*   ・ゲームに合わせて自由に改変していただいて問題ございません。
*   ・プラグイン素材としての再配布(改変後含む)は禁止させていただきます。
*
* 作者: ルルの教会
* 作成日: 2021/6/22
*
* @command showChoice
* @text 选项显示
* @desc 显示选项,并用变量接收结果。
*
* @arg messageText
* @text 提问信息
* @desc 提问信息。(建议2行以内)
* \V[n]、\N[n]、\P[n]、\G的控制字符。
* @type multiline_string
*
* @arg choices
* @text 选择列表
* @desc 列出要作为选项显示的字符串。
* @default []
* @type struct<choices>[]
*
* @arg maxCols
* @text 选择列数
* @desc 它是设置显示选项的列数。
* @default 1
* @min 1
* @Max 20
* @type number
*
* @arg variableNumber
* @text 结果接收变量
* @desc 指定接收选择结果的变量 ID。
* @type variable
*
* @arg cancelType
* @text 取消许可
* @desc 如果取消的话-1会被代入变量中。
* @default true
* @type boolean
*
* @arg iniPosition
* @text 初始光标位置
* @desc 是光标的初始位置。(设为0则无选择)
* 也可以输入数值或者用变量来指定。
* @default 1
* @type combo
* @option $gameVariables.value(1)   // 変数ID:1の値
* @option 0
* @option 1
* @option 2
* @option 3
* @option 4
* @option 5
* @option 6
*
* @arg windowWidth
* @text 窗口宽度
* @desc 选项窗口的宽度。
* 使用背景图像的时候请调整宽度。
* @default 480
* @min 0
* @max 2000
* @type number
*
* @arg windowBgImage
* @text 窗口图像
* @desc 使用窗口图像的时候请选择图像。
* 标准的窗口框将被隐藏。
* @dir img/system
* @type file
* @require 1
*
* @arg buttonBgImage
* @text 按钮图像
* @desc 使用按钮图像的时候请选择图像。
* @dir img/system
* @type file
* @require 1
*
* @arg buttonFocusImage
* @text 按钮图像(选择时)
* @desc 请选择焦点时的按钮图像。
* 请务必统一基本的按钮图像和大小。
* @dir img/system
* @type file
* @require 1
*
* @arg buttonImageAdjustX
* @text 按钮图像X坐标
* @desc 按钮图像的显示位置(X)的调整值。(初始值:0)
* +向右,-向左调整。
* @default 0
* @min -2000
* @max 2000
* @type number
*
* @arg buttonImageAdjustY
* @text 按钮图像Y坐标
* @desc 按钮图像的显示位置(Y)的调整值。(初始值:0)
* +向下,-向上调整。
* @default 0
* @min -2000
* @max 2000
* @type number
*
* @arg itemHeightAdjust
* @text 选择项高度
* @desc 调整选项项的高度。(初始值:8)
* 如果图像重叠的话请把这个数值放大。
* @default 8
* @min -2000
* @max 2000
* @type number
*
* @arg backgroundBitmapOpacity
* @text 背景亮度
* @desc 显示选项时背景的亮度。(0~255)
* 设为0的话会变黑。
* @default 128
* @min 0
* @max 255
* @type number
*/

/*~struct~choices:
*
* @param label
* @text 选项字符串
* @desc 要作为选项显示的字符串。
* \V[n]、\N[n]、\P[n]、\G您可以使用 的控制字符。
* @type string
*
* @param switchId
* @text 开关スイッチID
* @desc 仅当您希望在开关打开时显示选项时进行设置。
* 通常,您可以将其保留为“无”。
* @type switch
*/

(() => {
    "use strict";
    const pluginName = "LL_GalgeChoiceWindow";

    const parameters = PluginManager.parameters(pluginName);

    // Padding
    const gcwWindowPadding = 32;
    // キャンセル許可時のタッチUI戻るボタンの表示
    const gcwCancelButtonEnabled = false;
    // フェードイン効果フレーム
    const gcwFadeInFrame = 32;

    // 設定保存用変数定義
    let messageTextLists = [];
    let choiceLists = [];
    let maxCols = 1;
    let variableNumber = 0;
    let cancelType = true;
    let iniPosition = 1;
    let gcwWindowWidth = 480;
    let backgroundImage = "";
    let gcwButtonImage = "";
    let gcwButtonFocusImage = "";
    let gcwButtonAdjustX = 0;
    let gcwButtonAdjustY = 0;
    let gcwItemHeightAdjust = 8;
    let backgroundBitmapOpacity = 128;

    PluginManager.registerCommand(pluginName, "showChoice", function(args) {
        // 戦闘中は実行不可
        if ($gameParty.inBattle()) return;
        // 設定を取得
        const messageText = String(args.messageText).split("\n");
        const choices = JSON.parse(args.choices || "null");
        maxCols = Number(args.maxCols || 1);
        variableNumber = Number(args.variableNumber);
        cancelType = String(args.cancelType) === "true" ? true : false;
        iniPosition = eval(args.iniPosition);
        gcwWindowWidth = Number(args.windowWidth || 480);
        backgroundImage = String(args.windowBgImage || "");
        gcwButtonImage = String(args.buttonBgImage || "");
        gcwButtonFocusImage = String(args.buttonFocusImage || "");
        gcwButtonAdjustX = Number(args.buttonImageAdjustX || 0);
        gcwButtonAdjustY = Number(args.buttonImageAdjustY || 0);
        gcwItemHeightAdjust = Number(args.itemHeightAdjust || 8);
        backgroundBitmapOpacity = Number(args.backgroundBitmapOpacity || 128);

        messageTextLists = [];
        if (messageText != "") {
            messageText.forEach((elm) => {
                messageTextLists.push(String(elm));
            });
        }

        // 選択肢を定義
        choiceLists = [];
        if (choices) {
            choices.forEach((elm) => {
                if (Number(JSON.parse(elm).switchId) === 0 || $gameSwitches.value(Number(JSON.parse(elm).switchId))) {
                    choiceLists.push(JSON.parse(elm));
                }
            });
        }

        // 選択肢が空の場合、終了
        if (choiceLists.length == 0) {
            console.log(pluginName + ": 有効な選択肢が存在しなかったため、コマンドがスキップされました");
            return;
        }

        SceneManager.push(Scene_GalgeChoice);
    });

    //-----------------------------------------------------------------------------
    // Scene_GalgeChoice
    //
    // ノベルゲーム風選択肢を表示する独自のシーンを定義します。

    function Scene_GalgeChoice() {
        this.initialize(...arguments);
    }

    Scene_GalgeChoice.prototype = Object.create(Scene_MenuBase.prototype);
    Scene_GalgeChoice.prototype.constructor = Scene_GalgeChoice;

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

    Scene_GalgeChoice.prototype.create = function() {
        Scene_MenuBase.prototype.create.call(this);
        this.createChoiceWindow();
    };

    Scene_GalgeChoice.prototype.start = function() {
        Scene_MenuBase.prototype.start.call(this);
    };

    Scene_GalgeChoice.prototype.createChoiceWindow = function() {
        this._choiceWindow = new Window_GalgeChoiceList();
        this._choiceWindow.setHandler("ok", this.popScene.bind(this));
        this._choiceWindow.setHandler("cancel", this.popScene.bind(this));
        this.addWindow(this._choiceWindow);
    };

    Scene_GalgeChoice.prototype.createButtons = function() {
        //
    };

    Scene_GalgeChoice.prototype.createBackground = function() {
        this._backgroundFilter = new PIXI.filters.BlurFilter();
        this._backgroundSprite = new Sprite();
        this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
        // this._backgroundSprite.filters = [this._backgroundFilter];
        this.addChild(this._backgroundSprite);
        this.setBackgroundOpacity(backgroundBitmapOpacity);
    };

    Scene_GalgeChoice.prototype.onInputOk = function() {
        this.popScene();
    };


    //-----------------------------------------------------------------------------
    // Window_GalgeChoiceList
    //
    // ノベルゲーム風選択肢ウィンドウを定義します。

    function Window_GalgeChoiceList() {
        this.initialize(...arguments);
    }

    Window_GalgeChoiceList.prototype = Object.create(Window_Command.prototype);
    Window_GalgeChoiceList.prototype.constructor = Window_GalgeChoiceList;

    Window_GalgeChoiceList.prototype.initialize = function() {
        const wh = this.calcWindowHeight();
        const ww = gcwWindowWidth;
        const wx = (Graphics.boxWidth - ww) / 2;
        const wy = (Graphics.boxHeight - wh) / 2;
        Window_Command.prototype.initialize.call(this, new Rectangle(wx, wy, ww, wh));
        this.openness = 0;
        // ウィンドウ画像
        this._bgSprite = null;
        // フォーカスアニメーション判定
        this._originalCursorSpriteFade = true;
        // 押しっぱなし判定
        this._pressedOkRelease = false;
        this.start();
    };

    Window_GalgeChoiceList.prototype.start = function() {
        this.open();
        this.setQuestionText();
        this.setSymbol();
        this.createOriginalBackground();
        this.createCancelButton();
        this.placeCancelButton();
    };

    Window_GalgeChoiceList.prototype.calcWindowHeight = function() {
        // ウィンドウの高さを計算
        const itemCols = Math.ceil(choiceLists.length / maxCols);
        let height = this.lineHeight() * messageTextLists.length;
        if (messageTextLists.length > 0) height += gcwWindowPadding;
        height += (this.itemHeight()) * itemCols;
        height += gcwWindowPadding * 2;  // padding
        return height;
    };

    Window_GalgeChoiceList.prototype.createCancelButton = function() {
        if (ConfigManager.touchUI) {
            this._cancelButton = new Sprite_Button("cancel");
            this._cancelButton.visible = false;
            this.addChild(this._cancelButton);
        }
    };

    Window_GalgeChoiceList.prototype.createOriginalBackground = function() {
        if (backgroundImage != "") {
            this._bgSprite = new Sprite();
            this._bgSprite.bitmap = ImageManager.loadSystem(backgroundImage);
            this._bgSprite.bitmap.addLoadListener(function() {
                this._bgSprite.x = this.width / 2 - this._bgSprite.width / 2;
                this._bgSprite.y = this.height / 2 - this._bgSprite.height / 2;
            }.bind(this));
            this._bgSprite.opacity = 0;
            this.addChildToBack(this._bgSprite);
            // ウィンドウ枠を消去
            this.opacity = 0;
        }
    };

    Window_GalgeChoiceList.prototype.drawAllItems = function() {
        this.createOriginalCursor();
        this.createOriginalButton();
        Window_Selectable.prototype.drawAllItems.call(this);
    };

    Window_GalgeChoiceList.prototype.createOriginalCursor = function() {
        if (gcwButtonFocusImage != "") {
            this._originalCursorSprite = null;
            this._originalCursorSprite = new Sprite();
            this._originalCursorSprite.bitmap = ImageManager.loadSystem(gcwButtonFocusImage);
            this._originalCursorSprite.opacity = 128;
            this._originalCursorSprite.visible = true;
            this.addChildToBack(this._originalCursorSprite);
        }
    };

    Window_GalgeChoiceList.prototype.createOriginalButton = function() {
        if (gcwButtonImage != "") {
            this._originalButtonSprite = null;
            this._originalButtonSprite = new Sprite();
            this._originalButtonSprite.visible = false;
            this.addChildToBack(this._originalButtonSprite);
        }
    };

    Window_GalgeChoiceList.prototype.drawBackgroundRect = function(rect) {
        const c1 = ColorManager.itemBackColor1();
        const c2 = ColorManager.itemBackColor2();
        const x = rect.x;
        const y = rect.y;
        const w = rect.width;
        const h = rect.height;
        if (gcwButtonImage != "") {
            const originalButtonSprite = new Sprite();
            originalButtonSprite.bitmap = ImageManager.loadSystem(gcwButtonImage);
            originalButtonSprite.x = x + gcwButtonAdjustX + gcwWindowPadding;
            originalButtonSprite.y = y + gcwButtonAdjustY + gcwWindowPadding;
            this._originalButtonSprite.addChild(originalButtonSprite);
        } else {
            this.contentsBack.gradientFillRect(x, y, w, h, c1, c2, true);
            this.contentsBack.strokeRect(x, y, w, h, c1);
        }
    };

    Window_GalgeChoiceList.prototype.refreshCursor = function() {
        if (this._cursorAll) {
            this.refreshCursorForAll();
        } else if (this.index() >= 0) {
            const rect = this.itemRect(this.index());
            if (gcwButtonFocusImage != "") {
                if (this._originalCursorSprite) {
                    this._originalCursorSprite.x = rect.x + gcwButtonAdjustX + gcwWindowPadding;
                    this._originalCursorSprite.y = rect.y + gcwButtonAdjustY + gcwWindowPadding;
                }
            } else {
                this.setCursorRect(rect.x, rect.y, rect.width, rect.height);
            }
        } else {
            this.setCursorRect(0, 0, 0, 0);
        }
    };

    Window_GalgeChoiceList.prototype.refreshCursorForAll = function() {
        const maxItems = this.maxItems();
        if (maxItems > 0) {
            const rect = this.itemRect(0);
            rect.enlarge(this.itemRect(maxItems - 1));
            if (gcwButtonFocusImage != "") {
                if (this._originalCursorSprite) {
                    this._originalCursorSprite.x = rect.x + gcwButtonAdjustX;
                    this._originalCursorSprite.y = rect.y + gcwButtonAdjustY;
                }
            } else {
                this.setCursorRect(rect.x, rect.y, rect.width, rect.height);
            }
        } else {
            this.setCursorRect(0, 0, 0, 0);
        }
    };

    Window_GalgeChoiceList.prototype.update = function() {
        Window_Command.prototype.update.call(this);
        this.updateCancelButton();
        this.updateOriginalButton();
        this.updateOriginalCursorButton();
        if (this._bgSprite) this._bgSprite.opacity = this.openness;

        // 押しっぱなし判定
        if (this.isOpen()) {
            if (!Input.isPressed("ok")) {
                this._pressedOkRelease = true;
            }
        }
    };

    Window_GalgeChoiceList.prototype.updateOriginalButton = function() {
        if (this._originalButtonSprite) {
            if (this.isOpen()) {
                this._originalButtonSprite.visible = true;
            } else {
                this._originalButtonSprite.visible = false;
            }
        }
    };

    Window_GalgeChoiceList.prototype.updateOriginalCursorButton = function() {
        if (this._originalCursorSprite) {
            if (this.isOpen() && this._index > -1) {
                this._originalCursorSprite.visible = true;
                if (this._originalCursorSprite.opacity >= 255) this._originalCursorSpriteFade = false;
                if (this._originalCursorSprite.opacity <= 128) this._originalCursorSpriteFade = true;
                this._originalCursorSprite.opacity += this._originalCursorSpriteFade ? 6 : -6;
            } else {
                this._originalCursorSprite.visible = false;
            }
        }
    };

    Window_GalgeChoiceList.prototype.updateOpen = function() {
        if (this._opening) {
            this.openness += gcwFadeInFrame;
            if (this.isOpen()) {
                this._opening = false;
            }
        }
    };

    Window_GalgeChoiceList.prototype.updateCancelButton = function() {
        if (this._cancelButton) {
            this._cancelButton.visible = this.needsCancelButton() && this.isOpen() && gcwCancelButtonEnabled;
        }
    };

    Window_GalgeChoiceList.prototype.needsCancelButton = function() {
        return cancelType;
    };

    Window_GalgeChoiceList.prototype.placeCancelButton = function() {
        if (this._cancelButton) {
            const spacing = 8;
            const button = this._cancelButton;
            const right = this.x + this.width;
            if (right < Graphics.boxWidth - button.width + spacing) {
                button.x = this.width + spacing;
            } else {
                button.x = -button.width - spacing;
            }
            button.y = this.height / 2 - button.height / 2;
        }
    };

    Window_GalgeChoiceList.prototype.maxCols = function() {
        return maxCols;
    };

    Window_GalgeChoiceList.prototype.setQuestionText = function() {
        messageTextLists.forEach((text, index) => {
            this.drawText(this.convertEscapeCharacters(text), 0, this.lineHeight() * index, this.innerWidth, "center");
        }, this);
    };

    Window_GalgeChoiceList.prototype.makeCommandList = function() {
        choiceLists.forEach(function(elm, index) {
            this.addCommand(String(elm.label), index + 1);
        }, this);
    };

    Window_GalgeChoiceList.prototype.processOk = function() {
        if (this._pressedOkRelease) {
            $gameVariables.setValue(variableNumber, this.currentSymbol());
            Window_Command.prototype.processOk.call(this);
        }
    };

    Window_GalgeChoiceList.prototype.processCancel = function() {
        if (!cancelType) return;
        $gameVariables.setValue(variableNumber, -1);
        Window_Command.prototype.processCancel.call(this);
    };

    Window_GalgeChoiceList.prototype.updatePadding = function() {
        this.padding = gcwWindowPadding;
    };

    Window_GalgeChoiceList.prototype.scrollBaseY = function(index) {
        let margin = this.lineHeight() * messageTextLists.length;
        if (messageTextLists.length > 0) margin += gcwWindowPadding;
        return this._scrollBaseY - margin;
    };

    Window_GalgeChoiceList.prototype.setSymbol = function() {
        if (iniPosition > 0) {
            this.selectSymbol(iniPosition);
        } else {
            this.deselect();
        }
    };

    Window_GalgeChoiceList.prototype.itemHeight = function() {
        return Window_Scrollable.prototype.itemHeight.call(this) + gcwItemHeightAdjust;
    };

    Window_GalgeChoiceList.prototype.drawItem = function(index) {
        const rect = this.itemLineRect(index);
        const align = this.itemTextAlign();
        this.resetTextColor();
        this.changePaintOpacity(this.isCommandEnabled(index));
        this.drawText(this.convertEscapeCharacters(this.commandName(index)), rect.x, rect.y, rect.width, align);
    };

})();
[/fold]|露露的教堂
梦石
0
星屑
784
在线时间
103 小时
注册时间
2021-7-12
回帖
28
发表于 2021-9-11 20:47:55 | 显示全部楼层
感谢分享!
回复 1 0

使用道具 举报

梦石
0
星屑
1689
在线时间
934 小时
注册时间
2008-7-26
回帖
126
发表于 2022-1-24 12:09:26 | 显示全部楼层
看完都不知道怎么用,用什么命令控制的
回复

使用道具 举报

梦石
0
星屑
613
在线时间
161 小时
注册时间
2020-10-11
回帖
30
发表于 2022-2-3 17:36:36 | 显示全部楼层
先插个眼日后再说
回复

使用道具 举报

梦石
0
星屑
15
在线时间
4 小时
注册时间
2022-8-14
回帖
7
发表于 2022-8-19 14:53:03 | 显示全部楼层
插个眼,插个眼
回复

使用道具 举报

梦石
0
星屑
4061
在线时间
191 小时
注册时间
2022-4-24
回帖
20
发表于 2022-9-17 18:18:45 | 显示全部楼层
插眼,以后有用研究
回复

使用道具 举报

梦石
0
星屑
335
在线时间
61 小时
注册时间
2023-1-3
回帖
20
发表于 2023-1-7 23:20:53 | 显示全部楼层
先收藏备用
回复

使用道具 举报

梦石
0
星屑
1270
在线时间
41 小时
注册时间
2013-8-14
回帖
210
发表于 2023-1-10 10:03:08 | 显示全部楼层
支持一下楼主
回复

使用道具 举报

梦石
0
星屑
40
在线时间
8 小时
注册时间
2023-10-30
回帖
14
发表于 2023-11-14 11:38:15 | 显示全部楼层
不明白,先收藏
回复

使用道具 举报

梦石
0
星屑
180
在线时间
16 小时
注册时间
2020-8-25
回帖
3
发表于 2023-12-1 13:31:35 | 显示全部楼层
差眼先~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部