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

Project1

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

[已经解决] 大家都是怎么解决物品排序问题的?

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1282
在线时间
257 小时
注册时间
2021-2-16
帖子
247
1
发表于 2022-4-14 11:16:48 | 显示全部楼层
本帖最后由 tuxyin 于 2022-4-14 11:55 编辑

根据 铅笔描绘的思念 的提示,提供一种方法:

重写下面两个方法,在数据库中的所有物品乱序的情况下,物品名称前加上“x>”,比如:10>手机;3>手表;5>衣服。然后物品就可以按照:手表,衣服,手机的顺序排列显示。

PS:下方的代码是在MZ中测试通过的,MV的话仅供参考。

JAVASCRIPT 代码复制
  1. Window_ItemList.prototype.makeItemList = function() {
  2.     this._data = $gameParty.allItems().filter(item => this.includes(item));
  3.     if (this.includes(null)) {
  4.         this._data.push(null);
  5.     }
  6.  
  7.     // 按照“x>”顺序重新排序物品
  8.     this._data.sort((a, b) => {
  9.         let aOrderNum = parseInt(a.name.split(">")[0]);
  10.         let bOrderNum = parseInt(b.name.split(">")[0]);
  11.         return aOrderNum - bOrderNum;
  12.     });
  13. };
  14.  
  15. Window_ItemList.prototype.drawItem = function(index) {
  16.     const item = this.itemAt(index);
  17.  
  18.     // 显示物品名称时,去掉“x>”
  19.     let newItemName = item.name.split(">")[1];
  20.     if (newItemName) item.name = newItemName;
  21.  
  22.     if (item) {
  23.         const numberWidth = this.numberWidth();
  24.         const rect = this.itemLineRect(index);
  25.         this.changePaintOpacity(this.isEnabled(item));
  26.         this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);
  27.         this.drawItemNumber(item, rect.x, rect.y, rect.width);
  28.         this.changePaintOpacity(1);
  29.     }
  30. };
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-14 22:16

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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