Source: Window_BattleStatus.js

Window_BattleStatus.js

//-----------------------------------------------------------------------------
// Window_BattleStatus
//
// The window for displaying the status of party members on the battle screen.
/**
 * The window for displaying the status of party members on the battle screen.
 *
 * @class
 * @extends Window_StatusBase
 */
function Window_BattleStatus() {
    this.initialize(...arguments);
}

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

Window_BattleStatus.prototype.initialize = function(rect) {
    Window_StatusBase.prototype.initialize.call(this, rect);
    this.frameVisible = false;
    this.openness = 0;
    this._bitmapsReady = 0;
    this.preparePartyRefresh();
};

/**
 * Get an extra height value for calculating the bottom of the basic gauges
 *
 * @return {number} Extra height in pixels
 */
Window_BattleStatus.prototype.extraHeight = function() {
    return 10;
};

/**
 * Get the max number of columns in the window
 *
 * @return {number} Max number of columns
 */
Window_BattleStatus.prototype.maxCols = function() {
    return 4;
};

/**
 * Get the height of an item
 *
 * @return {number} Height of an item
 */
Window_BattleStatus.prototype.itemHeight = function() {
    return this.innerHeight;
};

/**
 * Get the max number of items to display in the window
 *
 * @return {number} Amount of items
 */
Window_BattleStatus.prototype.maxItems = function() {
    return $gameParty.battleMembers().length;
};

/**
 * Get the spacing between rows
 *
 * @return {number} Spacing between rows
 */
Window_BattleStatus.prototype.rowSpacing = function() {
    return 0;
};

/**
 * Update the window padding
 */
Window_BattleStatus.prototype.updatePadding = function() {
    this.padding = 8;
};

/**
 * Get the actor object at a specific index in battle
 *
 * @param {number} index - The index of the actor in the battle members
 * @return {Game_Actor} The game actor object
 */
Window_BattleStatus.prototype.actor = function(index) {
    return $gameParty.battleMembers()[index];
};

/**
 * Selects the given actor
 *
 * @param {Game_Actor} actor - The actor object to select
 */
Window_BattleStatus.prototype.selectActor = function(actor) {
    const members = $gameParty.battleMembers();
    this.select(members.indexOf(actor));
};

Window_BattleStatus.prototype.update = function() {
    Window_StatusBase.prototype.update.call(this);
    if ($gameTemp.isBattleRefreshRequested()) {
        this.preparePartyRefresh();
    }
};

/**
 * Prepares a party refresh
 */
Window_BattleStatus.prototype.preparePartyRefresh = function() {
    $gameTemp.clearBattleRefreshRequest();
    this._bitmapsReady = 0;
    for (const actor of $gameParty.members()) {
        const bitmap = ImageManager.loadFace(actor.faceName());
        bitmap.addLoadListener(this.performPartyRefresh.bind(this));
    }
};

/**
 * Performs a party refresh
 */
Window_BattleStatus.prototype.performPartyRefresh = function() {
    this._bitmapsReady++;
    if (this._bitmapsReady >= $gameParty.members().length) {
        this.refresh();
    }
};

/**
 * Draws an item at a given index
 *
 * @param {number} index - The item index to draw
 */
Window_BattleStatus.prototype.drawItem = function(index) {
    this.drawItemImage(index);
    this.drawItemStatus(index);
};

/**
 * Draws the image of the item at the given index
 *
 * @param {number} index - The item index to draw image for
 */
Window_BattleStatus.prototype.drawItemImage = function(index) {
    const actor = this.actor(index);
    const rect = this.faceRect(index);
    this.drawActorFace(actor, rect.x, rect.y, rect.width, rect.height);
};

/**
 * Draws the status of the item at the given index
 *
 * @param {number} index - The item index to draw status for
 */
Window_BattleStatus.prototype.drawItemStatus = function(index) {
    const actor = this.actor(index);
    const rect = this.itemRectWithPadding(index);
    const nameX = this.nameX(rect);
    const nameY = this.nameY(rect);
    const stateIconX = this.stateIconX(rect);
    const stateIconY = this.stateIconY(rect);
    const basicGaugesX = this.basicGaugesX(rect);
    const basicGaugesY = this.basicGaugesY(rect);
    this.placeTimeGauge(actor, nameX, nameY);
    this.placeActorName(actor, nameX, nameY);
    this.placeStateIcon(actor, stateIconX, stateIconY);
    this.placeBasicGauges(actor, basicGaugesX, basicGaugesY);
};

/**
 * Gets the face rectangle for a given index
 *
 * @param {number} index - The item index to draw image for
 * @return {Rectangle} The rectangle object representing the drawn face image dimensions
 */
Window_BattleStatus.prototype.faceRect = function(index) {
    const rect = this.itemRect(index);
    rect.pad(-1);
    rect.height = this.nameY(rect) + this.gaugeLineHeight() / 2 - rect.y;
    return rect;
};

/**
 * Gets the x coordinate for the name sprite
 *
 * @param {Rectangle} rect - The rectangle where the overall status is drawn
 * @return {number} The x coordinate of the name sprite
 */
Window_BattleStatus.prototype.nameX = function(rect) {
    return rect.x;
};

/**
 * Gets the y coordinate for the name sprite
 *
 * @param {Rectangle} rect - The rectangle where the overall status is drawn
 * @return {number} The y coordinate of the name sprite
 */
Window_BattleStatus.prototype.nameY = function(rect) {
    return this.basicGaugesY(rect) - this.gaugeLineHeight();
};

/**
 * Gets the x coordinate for the state icon sprite
 *
 * @param {Rectangle} rect - The rectangle where the overall status is drawn
 * @return {number} The x coordinate of the state icon sprite
 */
Window_BattleStatus.prototype.stateIconX = function(rect) {
    return rect.x + rect.width - ImageManager.standardIconWidth / 2 + 4;
};

/**
 * Gets the y coordinate for the state icon sprite
 *
 * @param {Rectangle} rect - The rectangle where the overall status is drawn
 * @return {number} The y coordinate of the state icon sprite
 */
Window_BattleStatus.prototype.stateIconY = function(rect) {
    return rect.y + ImageManager.standardIconHeight / 2 + 4;
};

/**
 * Gets the x coordinate for the basic gauges
 *
 * @param {Rectangle} rect - The rectangle where the overall status is drawn
 * @return {number} The x coordinate of the basic gauges
 */
Window_BattleStatus.prototype.basicGaugesX = function(rect) {
    return rect.x;
};

/**
 * Gets the y coordinate for the basic gauges
 *
 * @param {Rectangle} rect - The rectangle where the overall status is drawn
 * @return {number} The y coordinate of the basic gauges
 */
Window_BattleStatus.prototype.basicGaugesY = function(rect) {
    const bottom = rect.y + rect.height - this.extraHeight();
    const numGauges = $dataSystem.optDisplayTp ? 3 : 2;
    return bottom - this.gaugeLineHeight() * numGauges;
};