设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 89|回复: 2
打印 上一主题 下一主题

[有事请教] 想用新窗口显示一版变量

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3297
在线时间
135 小时
注册时间
2010-7-17
帖子
149
跳转到指定楼层
1
发表于 7 天前 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
/*:
* @target MZ
* @plugindesc 使用指定物品时,在新窗口显示 50 个变量的数据及名称
* @author 开发者
*
* @param itemId
* @text 物品 ID
* @desc 使用此物品会触发显示变量窗口
* @type item
* @default 1
*
* @param startVariableId
* @text 起始变量 ID
* @desc 从该 ID 开始显示 50 个连续变量的数据和名称
* @type variable
* @default 1
*
* @param windowX
* @text 窗口 X 坐标
* @desc 窗口在屏幕上的 X 坐标
* @type number
* @default 10
*
* @param windowY
* @text 窗口 Y 坐标
* @desc 窗口在屏幕上的 Y 坐标
* @type number
* @default 10
*
* @param windowWidth
* @text 窗口宽度
* @desc 窗口的宽度
* @type number
* @default 400
*
* @param windowHeight
* @text 窗口高度
* @desc 窗口的高度
* @type number
* @default 600
*
* @param fontSize
* @text 字体大小
* @desc 窗口内文本的字体大小
* @type number
* @min 12
* @Max 72
* @default 14
*
* @help
* 本插件允许你在使用指定物品时,在新窗口中显示 50 个变量的数据和名称。
* 请设置正确的物品 ID 和起始变量 ID。
*/
(() => {
    const pluginParams = PluginManager.parameters('ShowVariablesWithNames');
    const itemId = Number(pluginParams.itemId);
    const startVariableId = Number(pluginParams.startVariableId);
    const windowX = Number(pluginParams.windowX);
    const windowY = Number(pluginParams.windowY);
    const windowWidth = Number(pluginParams.windowWidth);
    const windowHeight = Number(pluginParams.windowHeight);
    const fontSize = Number(pluginParams.fontSize);

    class VariableDisplayWindow extends Window_Base {
        constructor() {
            try {
                console.log('开始创建 VariableDisplayWindow 窗口');
                super(new Rectangle(windowX, windowY, windowWidth, windowHeight));
                this.opacity = 255;
                this.visible = true;
                this.refresh();
                console.log('VariableDisplayWindow 窗口创建完成');
            } catch (error) {
                console.error('创建 VariableDisplayWindow 窗口时出错:', error);
            }
        }

        refresh() {
            try {
                console.log('开始刷新 VariableDisplayWindow 窗口内容');
                this.contents.clear();
                this.contents.fontSize = fontSize;
                let y = 0;
                for (let i = 0; i < 50; i++) {
                    const variableId = startVariableId + i;
                    const variableName = $dataSystem.variables[variableId];
                    const variableValue = $gameVariables.value(variableId);
                    const text = `${variableName}: ${variableValue}`;
                    this.drawText(text, 0, y, this.contents.width);
                    y += this.lineHeight();
                }
                console.log('VariableDisplayWindow 窗口内容刷新完成');
            } catch (error) {
                console.error('刷新 VariableDisplayWindow 窗口内容时出错:', error);
            }
        }
    }

    const _Game_Interpreter_command301 = Game_Interpreter.prototype.command301;
    Game_Interpreter.prototype.command301 = function () {
        console.log('使用物品,物品 ID:', this._params[0]);
        if (this._params[0] === itemId) {
            console.log('使用的物品 ID 匹配,开始创建窗口');
            const scene = SceneManager._scene;
            if (scene instanceof Scene_Map) {
                try {
                    scene._variableDisplayWindow = new VariableDisplayWindow();
                    if (scene._variableDisplayWindow) {
                        console.log('窗口对象创建成功');
                        scene.addWindow(scene._variableDisplayWindow);
                        console.log('窗口已添加到场景中');
                    } else {
                        console.error('窗口对象创建失败');
                    }
                } catch (error) {
                    console.error('创建变量显示窗口时出错:', error);
                }
            }
        }
        return _Game_Interpreter_command301.call(this);
    };
})();   

这插件有什么问题,使用指定物品后,并没有打开窗口

Lv3.寻梦者

梦石
0
星屑
3556
在线时间
158 小时
注册时间
2018-1-22
帖子
151
2
发表于 6 天前 | 只看该作者
因为command301根本就不是使用道具,地图场景没有直接使用道具的事件,整个逻辑都是都是错的
说实话这代码看着像AI,如果在地图场景做了使用道具的交互框架,可以去ItemBase里把useItem()移植过来再改造
自分自身の神様になること
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3297
在线时间
135 小时
注册时间
2010-7-17
帖子
149
3
 楼主| 发表于 4 天前 | 只看该作者
好的,我大概知道了
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-4-18 01:51

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表