[MZ][VisuStella主菜单] 变量窗口编辑

大家好!我正在使用 Visustella 主菜单插件,并且成功设置了变量窗口以显示玩家所在位置,这非常棒,但我遇到了一个问题。

如你所见,位置名称和“Location”变量名重叠了。我在想是否有可能让位置名称显示在“Location”变量名下方的另一行。

我知道 Visustella 的配置比较复杂,但无论如何,以下是相关代码:

const rows = VisuMZ.MainMenuCore.Settings.Variable.VarList.length;

const ww = this.mainCommandWidth();

const wh = this.calcWindowHeight(rows, false);

const wx = this.isRightInputMode() ? Graphics.boxWidth - ww : 0;

let wy = this.mainAreaBottom() - wh;

if (this._goldWindow) wy -= this._goldWindow.height;

return new Rectangle(wx, wy, ww, wh);

感谢你的时间!

据我理解,你需要两部分修改:增加窗口的高度,并调整窗口内的绘制顺序。

关于高度,在同一个 JS 文件中,为 X、Y、W、H 参数中的每个变量分配两行代码,而不是一行:

const wh = this.calcWindowHeight(rows * 2, false);

绘制本身没有作为参数暴露,因此这部分需要一个小型插件文件,放置在插件管理器中的 VisuMZ_1_MainMenuCore 下方:

Window_MenuVariables.prototype.itemHeight = function() {
    return this.lineHeight() * 2;
};

Window_MenuVariables.prototype.drawItem = function(index) {
    const list = VisuMZ.MainMenuCore.Settings.Variable.VarList.filter(id => Number(id) > 0);
    const varId = Number(list[index]);
    if (varId <= 0) return;
    const rect = this.itemRect(index);
    this.resetFontSettings();
    this.drawTextEx($dataSystem.variables[varId], rect.x, rect.y, rect.width);
    this.drawText($gameVariables.value(varId), rect.x, rect.y + this.lineHeight(), rect.width, "left");
};

我尚未在你的环境中测试此代码,因此在继续之前,请按 F8 打开控制台,并输入 Window_MenuVariables 以确认其返回的是一个类而不是 undefined。如果返回 undefined,则说明你的版本中该窗口的名称不同,此重写将不会绑定到任何对象。

希望我做得没错

返回的结果如下

Screenshot 2026-09-04 175449

就是这个,这样重写就能有东西可以挂载了。

下一步是将这段代码放入 js/plugins 文件夹中的一个新的 .js 文件里,在插件管理器中将其添加在 VisuMZ_1_MainMenuCore 下方,并将 JS 中的 wh 行参数 X、Y、W、H 修改为使用行数 * 2。请截图显示窗口最终的效果,我们可以据此继续操作。

成功了!现在我只希望“Runa’s Place”或实际地点名称能像菜单中的其他文字一样显示为白色。

尝试在两次绘制之间添加颜色重置:

    this.drawTextEx($dataSystem.variables[varId], rect.x, rect.y, rect.width);
    this.resetTextColor();
    this.drawText($gameVariables.value(varId), rect.x, rect.y + this.lineHeight(), rect.width, "left");

drawTextEx 在开始时重置字体设置,但在结束时不会重置。因此,如果数据库中的变量名称里包含类似 \C[16] 的颜色代码,那么在绘制下一行的值时,该颜色仍然处于激活状态。

搞定了!再次非常感谢!:face_holding_back_tears: :face_holding_back_tears: