Project1

标题: 如何跳過CategoryWindow選擇視窗,直接在itemWindow繪製道具 [打印本页]

作者: xcv15963    时间: 2019-2-4 00:58
标题: 如何跳過CategoryWindow選擇視窗,直接在itemWindow繪製道具
本帖最后由 xcv15963 于 2019-2-5 17:53 编辑

Scene_Mixing.prototype.createItemWindow = function() {
    this._itemWindow = new Window_ItemList(0, 0, 400, 400);
    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
    this._itemWindow.setHandler('cancel', this.popScene.bind(this));
    this._itemWindow.activate();
    this._itemWindow.selectLast();
    this.addWindow(this._itemWindow);
    this._itemWindow.setItemWindow(this._itemWindow);
    this._category = 'item';
};

Scene_Mixing.prototype.useItem = function() {
    Scene_ItemBase.prototype.useItem.call(this);
    this._itemWindow.redrawCurrentItem();
};

// Scene_Mixing.prototype.onCategoryOk = function() {
//     this._itemWindow.activate();
//     this._itemWindow.selectLast();
// };

Scene_Mixing.prototype.onItemOk = function() {
    $gameParty.setLastItem(this.item());
    this.determineItem();
};

// Scene_Mixing.prototype.onItemCancel = function() {
//     this._itemWindow.deselect();
//     this._categoryWindow.activate();
// };

Scene_Mixing.prototype.useItem = function() {
    Scene_ItemBase.prototype.useItem.call(this);
    this._itemWindow.redrawCurrentItem();
};

Window_ItemList.prototype.setItemWindow = function(itemWindow) {
    this._itemWindow = itemWindow;
};

Window_ItemList.prototype.includes = function(item) {
    DataManager.isItem(item) && item.itypeId === 1;
};

程式碼是這樣子的↑↑
請問如果我想跳過createCategoryWindow 選擇道具的視窗,
直接就在itemWindow 繪製身上有的消耗類道具,該怎麼做呢?
我有試著直接指定this._category = item ,但是好像沒什麼用......

有視窗.png (113.17 KB, 下载次数: 12)

目前有一個新的視窗,但是裡面沒有東西。

目前有一個新的視窗,但是裡面沒有東西。

作者: yang1zhi    时间: 2019-2-4 16:38
createCategoryWindow 要进入itemWindow
是什么原理应该先搞清楚。
也就是在createCategoryWindow 上点击一下进入的
this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
也就是这一条
当按下OK就执行this.onCategoryOk
所以我们找一下onCategoryOk
找到的是
Scene_Item.prototype.onCategoryOk = function() {
    this._itemWindow.activate();
    this._itemWindow.selectLast();
};
也就是itemWindow变成可操作
但是这样还看不到itemWindow显示的变化。
所以,我们再来看看itemWindow是怎么样的
this._itemWindow = new Window_ItemList(0, wy, Graphics.boxWidth, wh);
itemWindow是Window_ItemList的新建
我们就去Window_ItemList看看是怎么写的


我们看到,这里是设定,类型的,也就是你选择道具,装备,重要道具,那个类型
Window_ItemList.prototype.setCategory = function(category) {
    if (this._category !== category) {
        this._category = category;
        this.refresh();
        this.resetScroll();
    }
};

//然后我们还看到,这里是判断这个道具是哪个类型的
Window_ItemList.prototype.includes = function(item) {
    switch (this._category) {
//类型选择是道具
    case 'item':
//判断ITEM是道具,道具类型是1
        return DataManager.isItem(item) && item.itypeId === 1;
//类型选择是武器
    case 'weapon':
//判断ITEM是武器
        return DataManager.isWeapon(item);
//类型选择是防具
    case 'armor':
//判断ITEM是防具
        return DataManager.isArmor(item);
//类型选择是重要道具
    case 'keyItem':
//判断ITEM是道具,道具类型是2
        return DataManager.isItem(item) && item.itypeId === 2;
//没有选择时
    default:
        return false;
    }
};





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1