| 本帖最后由 tuxyin 于 2022-4-14 11:55 编辑 
 根据 铅笔描绘的思念 的提示,提供一种方法:
 
 重写下面两个方法,在数据库中的所有物品乱序的情况下,物品名称前加上“x>”,比如:10>手机;3>手表;5>衣服。然后物品就可以按照:手表,衣服,手机的顺序排列显示。
 
 PS:下方的代码是在MZ中测试通过的,MV的话仅供参考。
 
 
 Window_ItemList.prototype.makeItemList = function() {    this._data = $gameParty.allItems().filter(item => this.includes(item));    if (this.includes(null)) {        this._data.push(null);    }     // 按照“x>”顺序重新排序物品    this._data.sort((a, b) => {        let aOrderNum = parseInt(a.name.split(">")[0]);        let bOrderNum = parseInt(b.name.split(">")[0]);        return aOrderNum - bOrderNum;    });}; Window_ItemList.prototype.drawItem = function(index) {    const item = this.itemAt(index);     // 显示物品名称时,去掉“x>”    let newItemName = item.name.split(">")[1];    if (newItemName) item.name = newItemName;     if (item) {        const numberWidth = this.numberWidth();        const rect = this.itemLineRect(index);        this.changePaintOpacity(this.isEnabled(item));        this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);        this.drawItemNumber(item, rect.x, rect.y, rect.width);        this.changePaintOpacity(1);    }};
Window_ItemList.prototype.makeItemList = function() { 
    this._data = $gameParty.allItems().filter(item => this.includes(item)); 
    if (this.includes(null)) { 
        this._data.push(null); 
    } 
  
    // 按照“x>”顺序重新排序物品 
    this._data.sort((a, b) => { 
        let aOrderNum = parseInt(a.name.split(">")[0]); 
        let bOrderNum = parseInt(b.name.split(">")[0]); 
        return aOrderNum - bOrderNum; 
    }); 
}; 
  
Window_ItemList.prototype.drawItem = function(index) { 
    const item = this.itemAt(index); 
  
    // 显示物品名称时,去掉“x>” 
    let newItemName = item.name.split(">")[1]; 
    if (newItemName) item.name = newItemName; 
  
    if (item) { 
        const numberWidth = this.numberWidth(); 
        const rect = this.itemLineRect(index); 
        this.changePaintOpacity(this.isEnabled(item)); 
        this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth); 
        this.drawItemNumber(item, rect.x, rect.y, rect.width); 
        this.changePaintOpacity(1); 
    } 
}; 
 |