LoginSignup
0
0

More than 1 year has passed since last update.

RPGツクールMVのWindowにヘッダーを付ける

Last updated at Posted at 2018-12-04

備忘録です。
面倒なので細かい解説は書きません。
この内容をプラグインとして入れると、装備画面で装備品一覧の上にテキストが挿入されます。
昔同じようなことをやったときよりも、安定して動くバージョンが書けました。


(function(){
  'use strict';

Window_EquipSlot.prototype.headerHeight =function(){
    return this.lineHeight();
};
Window_EquipSlot.prototype.headerRect =function(){
    const space = this.spacing();
    return new Rectangle(
         space,
         0,
         this.width - space * 2,
         this.headerHeight()-space * 2
    );
};

Window_EquipSlot.prototype.footerHeight =function(){
    return this.lineHeight();
};

Window_EquipSlot.prototype.footerRect = function(){
    const space = this.spacing();
    const footerHeight = this.footerHeight();
    const y =   this.headerHeight() + this.pageHeight();
    return new Rectangle(
        space,
        y,
        this.width -space *2,
        footerHeight
    );
};

Window_EquipSlot.prototype.pageHeight =function(){
    return this.height -(this.padding*2) -this.headerHeight() -this.footerHeight();
};

Window_EquipSlot.prototype.maxPageRows =function(){
    const pageHeight = this.pageHeight();
    return Math.floor(pageHeight /this.itemHeight());
};

const Window_EquipSlot_itemRect =Window_EquipSlot.prototype.itemRect;
Window_EquipSlot.prototype.itemRect =function(index){
    const rect = Window_EquipSlot_itemRect.call(this,index);
    rect.y += this.headerHeight();
    return rect;
};

Window_EquipSlot.prototype.drawHeader =function(){
    const rect = this.headerRect();
    this.resetTextColor();
    this.drawText("header文章",rect.x,rect.y,rect.width);
};

Window_EquipSlot.prototype.drawFooter =function(){
    const rect = this.footerRect();
    this.resetTextColor();
    this.drawText("ふったー",rect.x,rect.y,rect.width);
};

const Window_EquipSlot_drawAllItems =Window_EquipSlot.prototype.drawAllItems;
Window_EquipSlot.prototype.drawAllItems =function(){
    this.drawHeader();
    this.drawFooter();
    Window_EquipSlot_drawAllItems.call(this);
};


})();

なお、クラス構文で書く場合は以下の通りです。
コピペしてどうぞ。

class MyWindow extends Window_Selectable{
    headerHeight(){
        return this.lineHeight();
    }
    headerRect(){
        const space = this.spacing();
        return new Rectangle(
             space,
             0,
             this.width - space * 2,
             this.headerHeight()-space * 2
        );
    }
    footerHeight(){
        return this.lineHeight();
    }
    footerRect(){
        const space = this.spacing();
        const footerHeight = this.footerHeight();
        const y =   this.headerHeight() + this.pageHeight();
        return new Rectangle(
            space,
            y,
            this.width -space *2,
            footerHeight
        );
    }
    pageHeight(){
        return this.height -(this.padding*2) -this.headerHeight() -this.footerHeight();
    }
    maxPageRows(){
        const pageHeight = this.pageHeight();
        return Math.floor(pageHeight /this.itemHeight());
    }
    /**
     * @param {Number} index 
     */
    itemRect(index){
        const rect = super.itemRect(index);;
        rect.y += this.headerHeight();
        return rect;        
    }
    drawHedder(){
        const rect = this.headerRect();
    }
    drawFooter(){
        const rect = this.footerRect();
    }
    drawAllItems(){
        this.drawHedder();
        this.drawFooter();
        super.drawAllItems();
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0