//-----------------------------------------------------------------------------
// Scene_MenuBase
//
// The superclass of all the menu-type scenes.
/**
* The superclass of all the menu-type scenes.
*
* @class
* @extends Scene_Base
*/
function Scene_MenuBase() {
this.initialize(...arguments);
}
Scene_MenuBase.prototype = Object.create(Scene_Base.prototype);
Scene_MenuBase.prototype.constructor = Scene_MenuBase;
Scene_MenuBase.prototype.initialize = function() {
Scene_Base.prototype.initialize.call(this);
};
Scene_MenuBase.prototype.create = function() {
Scene_Base.prototype.create.call(this);
this.createBackground();
this.updateActor();
this.createWindowLayer();
this.createButtons();
};
Scene_MenuBase.prototype.update = function() {
Scene_Base.prototype.update.call(this);
this.updatePageButtons();
};
/**
* Gets the top of the help area
*
* @return {number} Y Pixel for the top coordinate of the help area
*/
Scene_MenuBase.prototype.helpAreaTop = function() {
if (this.isBottomHelpMode()) {
return this.mainAreaBottom();
} else if (this.isBottomButtonMode()) {
return 0;
} else {
return this.buttonAreaBottom();
}
};
/**
* Gets the bottom of the help area
*
* @return {number} Y Pixel for the bottom coordinate of the help area
*/
Scene_MenuBase.prototype.helpAreaBottom = function() {
return this.helpAreaTop() + this.helpAreaHeight();
};
/**
* Gets the height needed for the help area
*
* @return {number} Number of pixels tall the help area is
*/
Scene_MenuBase.prototype.helpAreaHeight = function() {
return this.calcWindowHeight(2, false);
};
/**
* Gets the top of the main area
*
* @return {number} Y Pixel for the top coordinate of the main area
*/
Scene_MenuBase.prototype.mainAreaTop = function() {
if (!this.isBottomHelpMode()) {
return this.helpAreaBottom();
} else if (this.isBottomButtonMode()) {
return 0;
} else {
return this.buttonAreaBottom();
}
};
/**
* Gets the bottom of the main area
*
* @return {number} Y Pixel for the bottom coordinate of the main area
*/
Scene_MenuBase.prototype.mainAreaBottom = function() {
return this.mainAreaTop() + this.mainAreaHeight();
};
/**
* Gets the total height of the main area in pixels
*
* @return {number} Total height of the main area
*/
Scene_MenuBase.prototype.mainAreaHeight = function() {
return Graphics.boxHeight - this.buttonAreaHeight() - this.helpAreaHeight();
};
/**
* Gets the actor object of the scene
*
* @return {Game_Actor} The scene's actor object
*/
Scene_MenuBase.prototype.actor = function() {
return this._actor;
};
/**
* Sets the actor object of the scene
*/
Scene_MenuBase.prototype.updateActor = function() {
this._actor = $gameParty.menuActor();
};
/**
* Create the background image for the scene
*/
Scene_MenuBase.prototype.createBackground = function() {
this._backgroundFilter = new PIXI.filters.BlurFilter();
this._backgroundSprite = new Sprite();
this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
this._backgroundSprite.filters = [this._backgroundFilter];
this.addChild(this._backgroundSprite);
this.setBackgroundOpacity(192);
};
/**
* Set the background image opacity
*
* @param {number} opacity - The opacity to set the background image to
*/
Scene_MenuBase.prototype.setBackgroundOpacity = function(opacity) {
this._backgroundSprite.opacity = opacity;
};
/**
* Create the scene's help window
*/
Scene_MenuBase.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
*/
Scene_MenuBase.prototype.helpWindowRect = function() {
const wx = 0;
const wy = this.helpAreaTop();
const ww = Graphics.boxWidth;
const wh = this.helpAreaHeight();
return new Rectangle(wx, wy, ww, wh);
};
/**
* Creates the Touch UI buttons
*/
Scene_MenuBase.prototype.createButtons = function() {
if (ConfigManager.touchUI) {
if (this.needsCancelButton()) {
this.createCancelButton();
}
if (this.needsPageButtons()) {
this.createPageButtons();
}
}
};
/**
* Check if the scene should create the cancel button
*
* @return {boolean} True if there should be a cancel button in the scene
*/
Scene_MenuBase.prototype.needsCancelButton = function() {
return true;
};
/**
* Creates the cancel button
*/
Scene_MenuBase.prototype.createCancelButton = function() {
this._cancelButton = new Sprite_Button("cancel");
this._cancelButton.x = Graphics.boxWidth - this._cancelButton.width - 4;
this._cancelButton.y = this.buttonY();
this.addWindow(this._cancelButton);
};
/**
* Check if the scene should create the page buttons
*
* @return {boolean} True if there should be page buttons in the scene
*/
Scene_MenuBase.prototype.needsPageButtons = function() {
return false;
};
/**
* Creates the page up/down buttons
*/
Scene_MenuBase.prototype.createPageButtons = function() {
this._pageupButton = new Sprite_Button("pageup");
this._pageupButton.x = 4;
this._pageupButton.y = this.buttonY();
const pageupRight = this._pageupButton.x + this._pageupButton.width;
this._pagedownButton = new Sprite_Button("pagedown");
this._pagedownButton.x = pageupRight + 4;
this._pagedownButton.y = this.buttonY();
this.addWindow(this._pageupButton);
this.addWindow(this._pagedownButton);
this._pageupButton.setClickHandler(this.previousActor.bind(this));
this._pagedownButton.setClickHandler(this.nextActor.bind(this));
};
/**
* Updates the page up / down buttons visibility
*/
Scene_MenuBase.prototype.updatePageButtons = function() {
if (this._pageupButton && this._pagedownButton) {
const enabled = this.arePageButtonsEnabled();
this._pageupButton.visible = enabled;
this._pagedownButton.visible = enabled;
}
};
/**
* Check if page buttons should be enabled
*
* @return {boolean} True if page buttons should be enabled
*/
Scene_MenuBase.prototype.arePageButtonsEnabled = function() {
return true;
};
/**
* Cycle to the next actor in the menu
*/
Scene_MenuBase.prototype.nextActor = function() {
$gameParty.makeMenuActorNext();
this.updateActor();
this.onActorChange();
};
/**
* Cycle to the previous actor in the menu
*/
Scene_MenuBase.prototype.previousActor = function() {
$gameParty.makeMenuActorPrevious();
this.updateActor();
this.onActorChange();
};
/**
* Processing for when the scene's actor changes
*/
Scene_MenuBase.prototype.onActorChange = function() {
SoundManager.playCursor();
};