Source: Window_MenuCommand.js

Window_MenuCommand.js

//-----------------------------------------------------------------------------
// Window_MenuCommand
//
// The window for selecting a command on the menu screen.
/**
 * The window for selecting a command on the menu screen.
 *
 * @class
 * @extends Window_Command
 */
function Window_MenuCommand() {
    this.initialize(...arguments);
}

Window_MenuCommand.prototype = Object.create(Window_Command.prototype);
Window_MenuCommand.prototype.constructor = Window_MenuCommand;

Window_MenuCommand.prototype.initialize = function(rect) {
    Window_Command.prototype.initialize.call(this, rect);
    this.selectLast();
    this._canRepeat = false;
};

Window_MenuCommand._lastCommandSymbol = null;

/**
 * Initializes the command position
 */
Window_MenuCommand.initCommandPosition = function() {
    this._lastCommandSymbol = null;
};

/**
 * Make the commands in the window
 */
Window_MenuCommand.prototype.makeCommandList = function() {
    this.addMainCommands();
    this.addFormationCommand();
    this.addOriginalCommands();
    this.addOptionsCommand();
    this.addSaveCommand();
    this.addGameEndCommand();
};

/**
 * Adds commands in the main category, such as item/skill/equip/status
 */
Window_MenuCommand.prototype.addMainCommands = function() {
    const enabled = this.areMainCommandsEnabled();
    if (this.needsCommand("item")) {
        this.addCommand(TextManager.item, "item", enabled);
    }
    if (this.needsCommand("skill")) {
        this.addCommand(TextManager.skill, "skill", enabled);
    }
    if (this.needsCommand("equip")) {
        this.addCommand(TextManager.equip, "equip", enabled);
    }
    if (this.needsCommand("status")) {
        this.addCommand(TextManager.status, "status", enabled);
    }
};

/**
 * Adds the formation command
 */
Window_MenuCommand.prototype.addFormationCommand = function() {
    if (this.needsCommand("formation")) {
        const enabled = this.isFormationEnabled();
        this.addCommand(TextManager.formation, "formation", enabled);
    }
};

/**
 * Add any custom commands, to be overridden by plugins
 */
Window_MenuCommand.prototype.addOriginalCommands = function() {
    //
};

/**
 * Adds the options command
 */
Window_MenuCommand.prototype.addOptionsCommand = function() {
    if (this.needsCommand("options")) {
        const enabled = this.isOptionsEnabled();
        this.addCommand(TextManager.options, "options", enabled);
    }
};

/**
 * Adds the save command
 */
Window_MenuCommand.prototype.addSaveCommand = function() {
    if (this.needsCommand("save")) {
        const enabled = this.isSaveEnabled();
        this.addCommand(TextManager.save, "save", enabled);
    }
};

/**
 * Adds the game end command
 */
Window_MenuCommand.prototype.addGameEndCommand = function() {
    const enabled = this.isGameEndEnabled();
    this.addCommand(TextManager.gameEnd, "gameEnd", enabled);
};

/**
 * Check if the window should display the given command
 *
 * @param {string} name - The name of the command
 * @return {boolean} True if the command should display
 */
Window_MenuCommand.prototype.needsCommand = function(name) {
    const table = ["item", "skill", "equip", "status", "formation", "save"];
    const index = table.indexOf(name);
    if (index >= 0) {
        return $dataSystem.menuCommands[index];
    }
    return true;
};

/**
 * Check if the main commands should be enabled
 *
 * @return {boolean} True if the main commands are enabled
 */
Window_MenuCommand.prototype.areMainCommandsEnabled = function() {
    return $gameParty.exists();
};

/**
 * Check if the formation command should be enabled
 *
 * @return {boolean} True if the formation command is enabled
 */
Window_MenuCommand.prototype.isFormationEnabled = function() {
    return $gameParty.size() >= 2 && $gameSystem.isFormationEnabled();
};

/**
 * Check if the options command should be enabled
 *
 * @return {boolean} True if the options command is enabled
 */
Window_MenuCommand.prototype.isOptionsEnabled = function() {
    return true;
};

/**
 * Check if the save command should be enabled
 *
 * @return {boolean} True if the save command is enabled
 */
Window_MenuCommand.prototype.isSaveEnabled = function() {
    return !DataManager.isEventTest() && $gameSystem.isSaveEnabled();
};

/**
 * Check if the game end command should be enabled
 *
 * @return {boolean} True if the game end command is enabled
 */
Window_MenuCommand.prototype.isGameEndEnabled = function() {
    return true;
};

/**
 * Processing for OK Input
 */
Window_MenuCommand.prototype.processOk = function() {
    Window_MenuCommand._lastCommandSymbol = this.currentSymbol();
    Window_Command.prototype.processOk.call(this);
};

/**
 * Select the last command
 */
Window_MenuCommand.prototype.selectLast = function() {
    this.selectSymbol(Window_MenuCommand._lastCommandSymbol);
};