Source: Scene_File.js

Scene_File.js

//-----------------------------------------------------------------------------
// Scene_File
//
// The superclass of Scene_Save and Scene_Load.

/**
 * The superclass of Scene_Save and Scene_Load.
 *
 * @class
 * @extends Scene_MenuBase
 */
function Scene_File() {
    this.initialize(...arguments);
}

Scene_File.prototype = Object.create(Scene_MenuBase.prototype);
Scene_File.prototype.constructor = Scene_File;

Scene_File.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};

Scene_File.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    DataManager.loadAllSavefileImages();
    this.createHelpWindow();
    this.createListWindow();
    this._helpWindow.setText(this.helpWindowText());
};

Scene_File.prototype.helpAreaHeight = function() {
    return 0;
};

Scene_File.prototype.start = function() {
    Scene_MenuBase.prototype.start.call(this);
    this._listWindow.refresh();
};

/**
 * Gets the currently selected save file ID
 * 
 * @return {number} The save file ID currently selected
 */
Scene_File.prototype.savefileId = function() {
    return this._listWindow.savefileId();
};

/**
 * Check if the save file at the given id is enabled
 * 
 * @param {number} savefileId - The save file id to check
 * @return {boolean} True if the save file at the given id is enabled
 */
Scene_File.prototype.isSavefileEnabled = function(savefileId) {
    return this._listWindow.isEnabled(savefileId);
};

/**
 * Creates the help window
 * 
 * @override
 */
Scene_File.prototype.createHelpWindow = function() {
    const rect = this.helpWindowRect();
    this._helpWindow = new Window_Help(rect);
    this.addWindow(this._helpWindow);
};

/**
 * Get the Rectangle object that provides the help window's x/y/width/height
 *
 * @return {Rectangle} The rectangle representing the help window
 * @override
 */
Scene_File.prototype.helpWindowRect = function() {
    const wx = 0;
    const wy = this.mainAreaTop();
    const ww = Graphics.boxWidth;
    const wh = this.calcWindowHeight(1, false);
    return new Rectangle(wx, wy, ww, wh);
};

/**
 * Creates the list window
 */
Scene_File.prototype.createListWindow = function() {
    const rect = this.listWindowRect();
    this._listWindow = new Window_SavefileList(rect);
    this._listWindow.setHandler("ok", this.onSavefileOk.bind(this));
    this._listWindow.setHandler("cancel", this.popScene.bind(this));
    this._listWindow.setMode(this.mode(), this.needsAutosave());
    this._listWindow.selectSavefile(this.firstSavefileId());
    this._listWindow.refresh();
    this.addWindow(this._listWindow);
};

/**
 * Get the Rectangle object that provides the list window's x/y/width/height
 *
 * @return {Rectangle} The rectangle representing the list window
 */
Scene_File.prototype.listWindowRect = function() {
    const wx = 0;
    const wy = this.mainAreaTop() + this._helpWindow.height;
    const ww = Graphics.boxWidth;
    const wh = this.mainAreaHeight() - this._helpWindow.height;
    return new Rectangle(wx, wy, ww, wh);
};

/**
 * Check the mode (save/load)
 *
 * @return {null} When called from Scene_File, this function returns null
 */
Scene_File.prototype.mode = function() {
    return null;
};

/**
 * Check if autosave is enabled
 *
 * @return {boolean} True if autosave is enabled
 */
Scene_File.prototype.needsAutosave = function() {
    return $gameSystem.isAutosaveEnabled();
};

/**
 * Sets the list window to active
 */
Scene_File.prototype.activateListWindow = function() {
    this._listWindow.activate();
};

/**
 * Get the text that should appear in the help window
 *
 * @return {string} The help window text
 */
Scene_File.prototype.helpWindowText = function() {
    return "";
};

/**
 * Get the first save file's id
 *
 * @return {number} The first save file's id
 */
Scene_File.prototype.firstSavefileId = function() {
    return 0;
};

/**
 * Processing for when a save file is selected
 */
Scene_File.prototype.onSavefileOk = function() {
    //
};