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

Project1

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

[有事请教] 如何在存档界面显示变量

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1258
在线时间
160 小时
注册时间
2022-9-17
帖子
101
跳转到指定楼层
1
发表于 2022-10-12 13:02:54 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
我使用了一个AltSaveScreen.js插件,这个插件的代码如下:
JS 代码复制
  1. //=============================================================================
  2. // RPG Maker MZ - Alternative Save Screen
  3. //=============================================================================
  4.  
  5. /*:
  6. * @target MZ
  7. * @plugindesc Alternative save/load screen layout.
  8. * @author Yoji Ojima
  9. *
  10. * @help AltSaveScreen.js
  11. *
  12. * This plugin changes the layout of the save/load screen.
  13. * It puts the file list on the top and the details on the bottom.
  14. *
  15. * It does not provide plugin commands.
  16. */
  17.  
  18. /*:ja
  19. * @target MZ
  20. * @plugindesc セーブ/ロード画面のレイアウトを変更します。
  21. * @author Yoji Ojima
  22. *
  23. * @help AltSaveScreen.js
  24. *
  25. * このプラグインは、セーブ/ロード画面のレイアウトを変更します。
  26. * ファイル一覧を上側に、詳細を下側に配置します。
  27. *
  28. * プラグインコマンドはありません。
  29. */
  30.  
  31. (() => {
  32.     const _Scene_File_create = Scene_File.prototype.create;
  33.     Scene_File.prototype.create = function() {
  34.         _Scene_File_create.apply(this, arguments);
  35.         this._listWindow.height = this._listWindow.fittingHeight(3);
  36.         const x = 0;
  37.         const y = this._listWindow.y + this._listWindow.height;
  38.         const width = Graphics.boxWidth;
  39.         const height = Graphics.boxHeight - y;
  40.         const rect = new Rectangle(x, y, width, height);
  41.         const statusWindow = new Window_SavefileStatus(rect);
  42.         this._listWindow.mzkp_statusWindow = statusWindow;
  43.         this.addWindow(statusWindow);
  44.     };
  45.  
  46.     const _Scene_File_start = Scene_File.prototype.start;
  47.     Scene_File.prototype.start = function() {
  48.         _Scene_File_start.apply(this, arguments);
  49.         this._listWindow.ensureCursorVisible();
  50.         this._listWindow.callUpdateHelp();
  51.     };
  52.  
  53.     Window_SavefileList.prototype.windowWidth = function() {
  54.         return Graphics.boxWidth;
  55.     };
  56.  
  57.     Window_SavefileList.prototype.maxCols = function() {
  58.         return 4;
  59.     };
  60.  
  61.     Window_SavefileList.prototype.itemHeight = function() {
  62.         return this.lineHeight() * 2 + 16;
  63.     };
  64.  
  65.     const _Window_SavefileList_callUpdateHelp =
  66.         Window_SavefileList.prototype.callUpdateHelp;
  67.     Window_SavefileList.prototype.callUpdateHelp = function() {
  68.         _Window_SavefileList_callUpdateHelp.apply(this, arguments);
  69.         if (this.active && this.mzkp_statusWindow) {
  70.             this.mzkp_statusWindow.setSavefileId(this.savefileId());
  71.         }
  72.     };
  73.  
  74.     function Window_SavefileStatus() {
  75.         this.initialize.apply(this, arguments);
  76.     }
  77.  
  78.     Window_SavefileStatus.prototype = Object.create(Window_Base.prototype);
  79.     Window_SavefileStatus.prototype.constructor = Window_SavefileStatus;
  80.  
  81.     Window_SavefileStatus.prototype.initialize = function(rect) {
  82.         Window_Base.prototype.initialize.call(this, rect);
  83.         this._savefileId = 1;
  84.     };
  85.  
  86.     Window_SavefileStatus.prototype.setSavefileId = function(id) {
  87.         this._savefileId = id;
  88.         this.refresh();
  89.     };
  90.  
  91.     Window_SavefileStatus.prototype.refresh = function() {
  92.         const info = DataManager.savefileInfo(this._savefileId);
  93.         const rect = this.contents.rect;
  94.         this.contents.clear();
  95.         this.resetTextColor();
  96.         this.drawTitle(this._savefileId, rect.x, rect.y);
  97.         if (info) {
  98.             this.drawContents(info, rect);
  99.         }
  100.     };
  101.  
  102.     Window_SavefileStatus.prototype.drawTitle = function(savefileId, x, y) {
  103.         if (savefileId === 0) {
  104.             this.drawText(TextManager.autosave, x, y, 180);
  105.         } else {
  106.             this.drawText(TextManager.file + " " + savefileId, x, y, 180);
  107.         }
  108.     };
  109.  
  110.     Window_SavefileStatus.prototype.drawContents = function(info, rect) {
  111.         const bottom = rect.y + rect.height;
  112.         const playtimeY = bottom - this.lineHeight();
  113.         this.drawText(info.title, rect.x + 192, rect.y, rect.width - 192);
  114.         this.drawText("处于第" + $gameVariables.value(1) +"层", rect.x + 330, rect.y, rect.width - 192);
  115.         this.drawPartyfaces(info.faces, rect.x, bottom - 144);
  116.         this.drawText(info.playtime, rect.x, playtimeY, rect.width, "right");
  117.     };
  118.  
  119.     Window_SavefileStatus.prototype.drawPartyfaces = function(faces, x, y) {
  120.         if (faces) {
  121.             for (let i = 0; i < faces.length; i++) {
  122.                 const data = faces[i];
  123.                 this.drawFace(data[0], data[1], x + i * 150, y);
  124.             }
  125.         }
  126.     };
  127. })();




我想在存档中显示一个表示层数的变量。
JS 代码复制
  1. this.drawText("处于第" + $gameVariables.value(1) +"层", rect.x + 330, rect.y, rect.width - 192)

但这么做很明显,无法显示每一个存档中存储到的1号变量。当前如图所示,显示的全是初始状态下的数字0。
请问应该如何修改?

Lv3.寻梦者

梦石
0
星屑
1258
在线时间
160 小时
注册时间
2022-9-17
帖子
101
2
 楼主| 发表于 2022-10-12 13:05:26 | 只看该作者
  1. (function() {

  2.         const pluginName = 'MapNameinSaveData';

  3.     const parameters = PluginManager.parameters(pluginName);
  4.     const MapName_x = Number(parameters['MapName_x'] || 0);
  5.     const MapName_y = Number(parameters['MapName_y'] || 0);
  6.     const Characters_x = Number(parameters['Characters_x'] || 0);
  7.     const Characters_y = Number(parameters['Characters_y'] || 0);
  8.     const Playtime_x = Number(parameters['Playtime_x'] || 0);
  9.     const Playtime_y = Number(parameters['Playtime_y'] || 0);

  10.         DataManager.makeSavefileInfo = function() {
  11.             const info = {};
  12.             info.title = $dataSystem.gameTitle;
  13.                 info.mapname= $gameMap.displayName();
  14.             info.characters = $gameParty.charactersForSavefile();
  15.             info.faces = $gameParty.facesForSavefile();
  16.             info.playtime = $gameSystem.playtimeText();
  17.             info.timestamp = Date.now();
  18.             return info;
  19.         };

  20.         Window_SavefileList.prototype.drawContents = function(info, rect, valid) {
  21.             const bottom = rect.y + rect.height;
  22.             if (rect.width >= 420) {
  23.                 this.drawGameMapName(info, rect.x + 192 + MapName_x, rect.y + MapName_y, rect.width - 192);
  24.                 this.drawPartyCharacters(info, rect.x + 220 + Characters_x, bottom + Characters_y);
  25.             }
  26.             const lineHeight = this.lineHeight();
  27.             const y2 = bottom - lineHeight;
  28.             if (y2 >= lineHeight) {
  29.                 this.drawPlaytime(info, rect.x + 192 + Playtime_x, rect.y + Playtime_y, rect.width - 192);
  30.             }
  31.         };

  32.         Window_SavefileList.prototype.drawGameMapName = function(info, x, y, width) {
  33.             if (info.mapname) {
  34.                 this.drawText(info.mapname, x, y, width);
  35.             }
  36.         };

  37. })();
复制代码

这是MapNameinSaveData.js插件,在存档中显示地图名称的。但自己没学到其中的精髓。
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1188
在线时间
87 小时
注册时间
2022-2-5
帖子
194
3
发表于 2022-10-12 20:01:52 | 只看该作者
本帖最后由 41workroom 于 2022-10-12 20:09 编辑

游戏内部的变量好像要在进入游戏之后才会赋予值,不然就是如图所示的0

我们先看看这个地图名称的插件怎么写的:

        DataManager.makeSavefileInfo = function() {
            const info = {};
            info.title = $dataSystem.gameTitle;
            info.maplevel= $gameVariables.value(1);   //根据周围的代码,推测出存入变量的方法,这里就是要加入的地下城层数
            info.characters = $gameParty.charactersForSavefile();
            info.faces = $gameParty.facesForSavefile();
            info.playtime = $gameSystem.playtimeText();
            info.timestamp = Date.now();
            return info;
        };

上面这段为写入存档信息(info,可以在二楼帖代码13行找到)

先在插件中加入如上这段话(那一大段都要,橘黄色的是新加入的关键语句)
然后把一楼帖代码114行改为

this.drawText("处于第" + info.maplevel(1) +"层", rect.x + 330, rect.y, rect.width - 192);

然后就大功告成了~

如果有帮助帮忙给个免费的支持,谢谢~
回复 支持 3 反对 0

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1258
在线时间
160 小时
注册时间
2022-9-17
帖子
101
4
 楼主| 发表于 2022-10-14 14:30:20 | 只看该作者
41workroom 发表于 2022-10-12 20:01
游戏内部的变量好像要在进入游戏之后才会赋予值,不然就是如图所示的0

我们先看看这个地图名称的插件怎么 ...

了解了,这样就可以实现存档显示自由了。非常感谢答疑解惑
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-4 11:10

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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