赞 | 1 |
VIP | 0 |
好人卡 | 0 |
积分 | 17 |
经验 | 47391 |
最后登录 | 2024-11-20 |
在线时间 | 235 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 1685
- 在线时间
- 235 小时
- 注册时间
- 2005-10-23
- 帖子
- 106
|
5楼
楼主 |
发表于 2023-4-13 19:34:00
|
只看该作者
本帖最后由 beiduo 于 2023-4-13 23:09 编辑
您说的极是。
从昨晚到现在跟GPT断断续续地磨,反反复复地引导它写这个插件,出了五六版,却总是缺胳膊少腿,有的不显示窗口,有的不能用插件命令,要不就是各种错误提示。
下面这个版本应该是最接近成功的,但还是用不了。
- //=============================================================================
- // PasswordInputWindowMZ.js
- // ----------------------------------------------------------------------------
- // (C)2021 Atelier Rgss3
- // This software is released under the MIT License.
- // http://opensource.org/licenses/mit-license.php
- // ----------------------------------------------------------------------------
- // Version
- // 1.0.0 2021/01/01 初版
- //=============================================================================
- /*:
- * @plugindesc 显示密码输入窗口的插件。密匙正确时,可以运行指定事件。
- * @target MZ
- * @url
- * @base
- * @orderAfter
- *
- * @param password
- * @desc 密码字符串
- * @type string
- * @default RPGMAKER
- *
- * @param commonEventId
- * @desc 密码正确时运行的公共事件ID。
- * @type common_event
- * @default 1
- *
- * @eventCommand @text Password Input Window
- * @parent --- Input Commands ---
- *
- * @command open
- * @text Open Password Input Window
- * @desc 打开密码输入窗口
- *
- * @command close
- * @text Close Password Input Window
- * @desc 关闭密码输入窗口
- *
- * @help
- * 此插件通过“Password Input Window”命令打开带有密码输入框的窗口。
- * 当输入的密码与指定密码相同时,可以运行指定的公共事件。
- *
- * 密码字符串可以在插件参数中指定。
- *
- * 公共事件ID可以在指定的插件参数中指定。运行时,使用该ID运行公共事件。
- *
- * 关于文章插件:
- * 推荐使用 SRD_ArticlePopupMZ.js 插件,以便在输入密码时显示帮助或密码提示。
- *
- * 本插件根据MIT许可条款重新分发。
- */
- (() => {
- const PLUGIN_NAME = "PasswordInputWindowMZ";
- const parameters = PluginManager.parameters(PLUGIN_NAME);
- const password = parameters["password"];
- const eventId = parseInt(parameters["commonEventId"]);
- // Custom input window class definition
- class Window_PasswordInput extends Window_Selectable {
- constructor() {
- super(0, 0, this.windowWidth(), this.windowHeight());
- this.initialize.apply(this, arguments);
- }
- initialize() {
- Window_Selectable.prototype.initialize.call(this, 0, 0, 0, 0);
- this._inputWindow = new Window_NameInput(this._editWindow);
- this._inputWindow.setHandler("ok", this.onInputOk.bind(this));
- this._inputWindow.setHandler("cancel", this.popScene.bind(this));
- this._word = "";
- }
- windowWidth() {
- return 480;
- }
- windowHeight() {
- return this.fittingHeight(3);
- }
- maxCols() {
- return 12;
- }
- maxLength() {
- return password.length;
- }
- characterWidth() {
- return this.innerWidth / this.maxCols();
- }
- onInputOk() {
- if (this._inputWindow.name() === password) {
- $gameTemp.reserveCommonEvent(eventId);
- SoundManager.playOk();
- this.popScene();
- } else {
- this._word = "";
- this.playBuzzerSound();
- this._editWindow.restoreDefault();
- }
- }
- drawItem(index) {
- const rect = this.itemRect(index);
- const align = "center";
- const character = this._inputWindow.charAt(index);
- this.resetTextColor();
- this.drawText(character, rect.x + 6, rect.y, rect.width - 12, align);
- }
- needsCancelButton() {
- return false;
- }
- word() {
- return this._word;
- }
- }
- // Custom command interpreter class definition
- class Game_Interpreter {
- command_OpenPasswordInputWindow() {
- SceneManager.push(Scene_PasswordInput);
- }
- }
- // Custom scene class definition
- class Scene_PasswordInput extends Scene_MenuBase {
- constructor() {
- super();
- this.initialize.apply(this, arguments);
- }
- initialize() {
- Scene_MenuBase.prototype.initialize.apply(this, arguments);
- }
- create() {
- Scene_MenuBase.prototype.create.call(this);
- this.cwCreateEditWindow();
- this.cwCreateInputWindow();
- }
- cwCreateEditWindow() {
- this._editWindow = new Window_PasswordEdit();
- this._editWindow.y = this._helpWindow.height;
- this.addWindow(this._editWindow);
- }
- cwCreateInputWindow() {
- this._inputWindow = new Window_PasswordInput(this._editWindow);
- this._inputWindow.y = this._editWindow.y + this._editWindow.height;
- this._inputWindow.setHandler("ok", this.onInputOk.bind(this));
- this.addWindow(this._inputWindow);
- }
- onInputOk() {}
- createHelpWindow() {
- Scene_MenuBase.prototype.createHelpWindow.call(this);
- this._helpWindow.setText("Enter the password:");
- }
- }
- // Custom edit window class definition
- class Window_PasswordEdit extends Window_NameEdit {
- constructor() {
- super();
- this.initialize.apply(this, arguments);
- }
- initialize() {
- Window_NameEdit.prototype.initialize.call(this, 0, 0, 0, "");
- this._defaultName = Array(password.length).fill("●");
- this._name = this._defaultName.slice();
- }
- name() {
- let name = "";
- for (let i = 0; i < this._name.length; i++) {
- name += this._name[i];
- }
- return name;
- }
- }
- // Register plugin command
- PluginManager.registerCommand(PLUGIN_NAME, "open", function () {
- $gameTemp.reserveCommonEvent(eventId);
- SceneManager.push(Scene_PasswordInput);
- });
- // Plugin command to close the window without executing event.
- PluginManager.registerCommand(PLUGIN_NAME, "close", function () {
- SoundManager.playCancel();
- SceneManager.pop();
- });
- // Add custom input window command to event list
- PluginManager.registerCommand(PLUGIN_NAME, "Password Input Window", () => {});
- // Add custom interpreter command to open the window
- const _Game_Interpreter_pluginCommand =
- Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function (command, args) {
- _Game_Interpreter_pluginCommand.call(this, command, args);
- if (command === "OpenPasswordInputWindow") {
- this.command_OpenPasswordInputWindow();
- }
- };
- })();
复制代码
|
|