Source: Window_EquipSlot.js

Window_EquipSlot.js

//-----------------------------------------------------------------------------
// Window_EquipSlot
//
// The window for selecting an equipment slot on the equipment screen.
/**
 * The window for selecting an equipment slot on the equipment screen.
 *
 * @class
 * @extends Window_StatusBase
 */
function Window_EquipSlot() {
    this.initialize(...arguments);
}

Window_EquipSlot.prototype = Object.create(Window_StatusBase.prototype);
Window_EquipSlot.prototype.constructor = Window_EquipSlot;

Window_EquipSlot.prototype.initialize = function(rect) {
    Window_StatusBase.prototype.initialize.call(this, rect);
    this._actor = null;
    this.refresh();
};

/**
 * Sets the actor object for the window
 *
 * @param {Game_Actor} actor - The Game Actor object
 */
Window_EquipSlot.prototype.setActor = function(actor) {
    if (this._actor !== actor) {
        this._actor = actor;
        this.refresh();
    }
};

Window_EquipSlot.prototype.update = function() {
    Window_StatusBase.prototype.update.call(this);
    if (this._itemWindow) {
        this._itemWindow.setSlotId(this.index());
    }
};

/**
 * Gets the max amount of items in the window
 *
 * @return {number} Amount of equip slots
 */
Window_EquipSlot.prototype.maxItems = function() {
    return this._actor ? this._actor.equipSlots().length : 0;
};

/**
 * Gets the currently selected item
 *
 * @return {Object|null} The equipment object that is currently selected, or null if no equip in that slot
 */
Window_EquipSlot.prototype.item = function() {
    return this.itemAt(this.index());
};

/**
 * Gets the item at the given index
 *
 * @param {number} index - The index to check
 * @return {Object|null} The equipment object at the given index, or null if no equip in that slot
 */
Window_EquipSlot.prototype.itemAt = function(index) {
    return this._actor ? this._actor.equips()[index] : null;
};

/**
 * Draws the item at the given index
 *
 * @param {number} index - The index to draw
 */
Window_EquipSlot.prototype.drawItem = function(index) {
    if (this._actor) {
        const slotName = this.actorSlotName(this._actor, index);
        const item = this.itemAt(index);
        const slotNameWidth = this.slotNameWidth();
        const rect = this.itemLineRect(index);
        const itemWidth = rect.width - slotNameWidth;
        this.changeTextColor(ColorManager.systemColor());
        this.changePaintOpacity(this.isEnabled(index));
        this.drawText(slotName, rect.x, rect.y, slotNameWidth, rect.height);
        this.drawItemName(item, rect.x + slotNameWidth, rect.y, itemWidth);
        this.changePaintOpacity(true);
    }
};

/**
 * Gets the width for a slot name in pixels
 *
 * @return {number} The width of the slot name
 */
Window_EquipSlot.prototype.slotNameWidth = function() {
    return 138;
};

/**
 * Check if the item at the given index is enabled
 *
 * @param {number} index - The index to check
 * @return {boolean} True if the slot should be enabled
 */
Window_EquipSlot.prototype.isEnabled = function(index) {
    return this._actor ? this._actor.isEquipChangeOk(index) : false;
};

/**
 * Check if the currently selected item is enabled
 *
 * @return {boolean} True if the slot should be enabled
 */
Window_EquipSlot.prototype.isCurrentItemEnabled = function() {
    return this.isEnabled(this.index());
};

/**
 * Sets the status window
 *
 * @param {Window_EquipStatus} statusWindow - The status window
 */
Window_EquipSlot.prototype.setStatusWindow = function(statusWindow) {
    this._statusWindow = statusWindow;
    this.callUpdateHelp();
};

/**
 * Sets the item window
 *
 * @param {Window_EquipItem} itemWindow - The item window
 */
Window_EquipSlot.prototype.setItemWindow = function(itemWindow) {
    this._itemWindow = itemWindow;
};

Window_EquipSlot.prototype.updateHelp = function() {
    Window_StatusBase.prototype.updateHelp.call(this);
    this.setHelpWindowItem(this.item());
    if (this._statusWindow) {
        this._statusWindow.setTempActor(null);
    }
};