Source: Window_StatusBase.js

Window_StatusBase.js

//-----------------------------------------------------------------------------
// Window_StatusBase
//
// The superclass of windows for displaying actor status.
/**
 * The superclass of windows for displaying actor status.
 *
 * @class
 * @extends Window_Selectable
 */
function Window_StatusBase() {
    this.initialize(...arguments);
}

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

Window_StatusBase.prototype.initialize = function(rect) {
    Window_Selectable.prototype.initialize.call(this, rect);
    this._additionalSprites = {};
    this.loadFaceImages();
};

/**
 * Loads face images for all actors in the party
 */
Window_StatusBase.prototype.loadFaceImages = function() {
    for (const actor of $gameParty.members()) {
        ImageManager.loadFace(actor.faceName());
    }
};

Window_StatusBase.prototype.refresh = function() {
    this.hideAdditionalSprites();
    Window_Selectable.prototype.refresh.call(this);
};

/**
 * Hides additional sprites
 */
Window_StatusBase.prototype.hideAdditionalSprites = function() {
    for (const sprite of Object.values(this._additionalSprites)) {
        sprite.hide();
    }
};

/**
 * Places the actor name sprite
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to place the sprite
 * @param {number} y - The y coordinate to place the sprite
 */
Window_StatusBase.prototype.placeActorName = function(actor, x, y) {
    const key = "actor%1-name".format(actor.actorId());
    const sprite = this.createInnerSprite(key, Sprite_Name);
    sprite.setup(actor);
    sprite.move(x, y);
    sprite.show();
};

/**
 * Places the state icon sprite
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to place the sprite
 * @param {number} y - The y coordinate to place the sprite
 */
Window_StatusBase.prototype.placeStateIcon = function(actor, x, y) {
    const key = "actor%1-stateIcon".format(actor.actorId());
    const sprite = this.createInnerSprite(key, Sprite_StateIcon);
    sprite.setup(actor);
    sprite.move(x, y);
    sprite.show();
};

/**
 * Places the gauge sprite
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {string} type - The gauge type (ex: hp/mp/tp)
 * @param {number} x - The x coordinate to place the sprite
 * @param {number} y - The y coordinate to place the sprite
 */
Window_StatusBase.prototype.placeGauge = function(actor, type, x, y) {
    const key = "actor%1-gauge-%2".format(actor.actorId(), type);
    const sprite = this.createInnerSprite(key, Sprite_Gauge);
    sprite.setup(actor, type);
    sprite.move(x, y);
    sprite.show();
};

/**
 * Creates a sprite as an inner child
 *
 * @param {string} key - The key used to refer to the sprite after creation
 * @param {Sprite} spriteClass - The sprite class to create
 * @return {Sprite} The created sprite
 */
Window_StatusBase.prototype.createInnerSprite = function(key, spriteClass) {
    const dict = this._additionalSprites;
    if (dict[key]) {
        return dict[key];
    } else {
        const sprite = new spriteClass();
        dict[key] = sprite;
        this.addInnerChild(sprite);
        return sprite;
    }
};

/**
 * Place the time gauge sprite (used for TPB battle system)
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to place the sprite
 * @param {number} y - The y coordinate to place the sprite
 */
Window_StatusBase.prototype.placeTimeGauge = function(actor, x, y) {
    if (BattleManager.isTpb()) {
        this.placeGauge(actor, "time", x, y);
    }
};

/**
 * Place the hp/mp/tp gauge sprites
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to place the sprite
 * @param {number} y - The y coordinate to place the sprite
 */
Window_StatusBase.prototype.placeBasicGauges = function(actor, x, y) {
    this.placeGauge(actor, "hp", x, y);
    this.placeGauge(actor, "mp", x, y + this.gaugeLineHeight());
    if ($dataSystem.optDisplayTp) {
        this.placeGauge(actor, "tp", x, y + this.gaugeLineHeight() * 2);
    }
};

/**
 * Get the height of a gauge line
 *
 * @return {number} Amount of pixels tall for a gauge line
 */
Window_StatusBase.prototype.gaugeLineHeight = function() {
    return 24;
};

/**
 * Draws the actor's character sprite
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to draw the sprite
 * @param {number} y - The y coordinate to draw the sprite
 */
Window_StatusBase.prototype.drawActorCharacter = function(actor, x, y) {
    this.drawCharacter(actor.characterName(), actor.characterIndex(), x, y);
};

// prettier-ignore
/**
 * Draws the actor's face sprite
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to draw the sprite
 * @param {number} y - The y coordinate to draw the sprite
 * @param {number} width - The width of the sprite
 * @param {number} height - The height of the sprite
 */
Window_StatusBase.prototype.drawActorFace = function(
    actor, x, y, width, height
) {
    this.drawFace(actor.faceName(), actor.faceIndex(), x, y, width, height);
};

/**
 * Draws the actor's name
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to draw the text
 * @param {number} y - The y coordinate to draw the text
 * @param {number} [width=168] - The max width of the name
 */
Window_StatusBase.prototype.drawActorName = function(actor, x, y, width) {
    width = width || 168;
    this.changeTextColor(ColorManager.hpColor(actor));
    this.drawText(actor.name(), x, y, width);
};

/**
 * Draws the actor's class
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to draw the text
 * @param {number} y - The y coordinate to draw the text
 * @param {number} [width=168] - The max width of the class
 */
Window_StatusBase.prototype.drawActorClass = function(actor, x, y, width) {
    width = width || 168;
    this.resetTextColor();
    this.drawText(actor.currentClass().name, x, y, width);
};

/**
 * Draws the actor's nickname
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to draw the text
 * @param {number} y - The y coordinate to draw the text
 * @param {number} [width=270] - The max width of the nickname
 */
Window_StatusBase.prototype.drawActorNickname = function(actor, x, y, width) {
    width = width || 270;
    this.resetTextColor();
    this.drawText(actor.nickname(), x, y, width);
};

/**
 * Draws the actor's level
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to draw the text
 * @param {number} y - The y coordinate to draw the text
 */
Window_StatusBase.prototype.drawActorLevel = function(actor, x, y) {
    this.changeTextColor(ColorManager.systemColor());
    this.drawText(TextManager.levelA, x, y, 48);
    this.resetTextColor();
    this.drawText(actor.level, x + 84, y, 36, "right");
};

/**
 * Draws the actor's icons
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to draw the icons
 * @param {number} y - The y coordinate to draw the icons
 * @param {number} [width=144] - The max width available to display icons in
 */
Window_StatusBase.prototype.drawActorIcons = function(actor, x, y, width) {
    width = width || 144;
    const delta = ImageManager.standardIconWidth - ImageManager.iconWidth;
    const iconWidth = ImageManager.standardIconWidth;
    const icons = actor.allIcons().slice(0, Math.floor(width / iconWidth));
    let iconX = x + delta / 2;
    for (const icon of icons) {
        this.drawIcon(icon, iconX, y + 2);
        iconX += iconWidth;
    }
};

/**
 * Draws simple status elements for an actor, including name/level/icons/class/gauges
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} x - The x coordinate to draw the status
 * @param {number} y - The y coordinate to draw the status
 */
Window_StatusBase.prototype.drawActorSimpleStatus = function(actor, x, y) {
    const lineHeight = this.lineHeight();
    const x2 = x + 180;
    this.drawActorName(actor, x, y);
    this.drawActorLevel(actor, x, y + lineHeight * 1);
    this.drawActorIcons(actor, x, y + lineHeight * 2);
    this.drawActorClass(actor, x2, y);
    this.placeBasicGauges(actor, x2, y + lineHeight);
};

/**
 * Gets the name of an equip slot at an index
 *
 * @param {Game_Actor} actor - The Game Actor object
 * @param {number} index - The index of the equip slot
 * @return {string} The name of the equip type for that slot
 */
Window_StatusBase.prototype.actorSlotName = function(actor, index) {
    const slots = actor.equipSlots();
    return $dataSystem.equipTypes[slots[index]];
};