Source: Game_Message.js

Game_Message.js

//-----------------------------------------------------------------------------
// Game_Message
//
// The game object class for the state of the message window that displays text
// or selections, etc.
/**
 * The game object class for the state of the message window that displays text or selections, etc.
 *
 * @class
 */
function Game_Message() {
    this.initialize(...arguments);
}

/**
 * Initialize the class
 */
Game_Message.prototype.initialize = function() {
    this.clear();
};

/**
 * Clear message variables
 */
Game_Message.prototype.clear = function() {
    this._texts = [];
    this._choices = [];
    this._speakerName = "";
    this._faceName = "";
    this._faceIndex = 0;
    this._background = 0;
    this._positionType = 2;
    this._choiceDefaultType = 0;
    this._choiceCancelType = 0;
    this._choiceBackground = 0;
    this._choicePositionType = 2;
    this._numInputVariableId = 0;
    this._numInputMaxDigits = 0;
    this._itemChoiceVariableId = 0;
    this._itemChoiceItypeId = 0;
    this._scrollMode = false;
    this._scrollSpeed = 2;
    this._scrollNoFast = false;
    this._choiceCallback = null;
};

/**
 * Get the choice array
 *
 * @return {Array} The choice array
 */
Game_Message.prototype.choices = function() {
    return this._choices;
};

/**
 * Get the speaker name
 *
 * @return {string} The speaker name
 */
Game_Message.prototype.speakerName = function() {
    return this._speakerName;
};

/**
 * Get the face name (for face image file)
 *
 * @return {string} The face name
 */
Game_Message.prototype.faceName = function() {
    return this._faceName;
};

/**
 * Get the face index (for face image file)
 *
 * @return {number} The face index
 */
Game_Message.prototype.faceIndex = function() {
    return this._faceIndex;
};

/**
 * Get the background type
 *
 * @return {number} The background type
 */
Game_Message.prototype.background = function() {
    return this._background;
};

/**
 * Get the position type
 *
 * @return {number} The position type
 */
Game_Message.prototype.positionType = function() {
    return this._positionType;
};

/**
 * Get the default choice type
 *
 * @return {number} The default choice type
 */
Game_Message.prototype.choiceDefaultType = function() {
    return this._choiceDefaultType;
};

/**
 * Get the choice cancel type
 *
 * @return {number} The choice cancel type
 */
Game_Message.prototype.choiceCancelType = function() {
    return this._choiceCancelType;
};

/**
 * Get the choice background type
 *
 * @return {number} The choice background type
 */
Game_Message.prototype.choiceBackground = function() {
    return this._choiceBackground;
};

/**
 * Get the choice position type
 *
 * @return {number} The choice position type
 */
Game_Message.prototype.choicePositionType = function() {
    return this._choicePositionType;
};

/**
 * Get the number input variable id
 *
 * @return {number} The variable id
 */
Game_Message.prototype.numInputVariableId = function() {
    return this._numInputVariableId;
};

/**
 * Get the number input maximum allowed digits
 *
 * @return {number} The max allowed digits
 */
Game_Message.prototype.numInputMaxDigits = function() {
    return this._numInputMaxDigits;
};

/**
 * Get the item choice variable id
 *
 * @return {number} The variable id
 */
Game_Message.prototype.itemChoiceVariableId = function() {
    return this._itemChoiceVariableId;
};

/**
 * Get the item choice item type id
 *
 * @return {number} The item type id
 */
Game_Message.prototype.itemChoiceItypeId = function() {
    return this._itemChoiceItypeId;
};

/**
 * Check if scroll mode
 *
 * @return {boolean} True if scroll mode
 */
Game_Message.prototype.scrollMode = function() {
    return this._scrollMode;
};

/**
 * Get the scroll speed
 *
 * @return {number} The scroll speed
 */
Game_Message.prototype.scrollSpeed = function() {
    return this._scrollSpeed;
};

/**
 * Check if scroll no fast
 *
 * @return {boolean} True if scroll no fast
 */
Game_Message.prototype.scrollNoFast = function() {
    return this._scrollNoFast;
};

/**
 * Adds the given text to the message
 *
 * @param {string} text - The text to add
 */
Game_Message.prototype.add = function(text) {
    this._texts.push(text);
};

/**
 * Sets the speaker name
 *
 * @param {string} speakerName - The new speaker name
 */
Game_Message.prototype.setSpeakerName = function(speakerName) {
    this._speakerName = speakerName ? speakerName : "";
};

/**
 * Sets the face image settings
 *
 * @param {string} faceName - The face image file name
 * @param {number} faceIndex - The index of the face to use on the face sheet
 */
Game_Message.prototype.setFaceImage = function(faceName, faceIndex) {
    this._faceName = faceName;
    this._faceIndex = faceIndex;
};

/**
 * Sets the background type
 *
 * @param {number} background - The new background type
 */
Game_Message.prototype.setBackground = function(background) {
    this._background = background;
};

/**
 * Sets the position type
 *
 * @param {number} positionType - The new position type
 */
Game_Message.prototype.setPositionType = function(positionType) {
    this._positionType = positionType;
};

/**
 * Sets the choice settings
 *
 * @param {Array} choices - The array of choices
 * @param {number} defaultType - The choice default type
 * @param {number} cancelType - The choice cancel type
 */
Game_Message.prototype.setChoices = function(choices, defaultType, cancelType) {
    this._choices = choices;
    this._choiceDefaultType = defaultType;
    this._choiceCancelType = cancelType;
};

/**
 * Sets the choice background type
 *
 * @param {number} background - The new choice background type
 */
Game_Message.prototype.setChoiceBackground = function(background) {
    this._choiceBackground = background;
};

/**
 * Sets the choice position type
 *
 * @param {number} positionType - The new choice position type
 */
Game_Message.prototype.setChoicePositionType = function(positionType) {
    this._choicePositionType = positionType;
};

/**
 * Sets the number input settings
 *
 * @param {number} variableId - The number input variable id to use
 * @param {number} maxDigits - The number input max digits to use
 */
Game_Message.prototype.setNumberInput = function(variableId, maxDigits) {
    this._numInputVariableId = variableId;
    this._numInputMaxDigits = maxDigits;
};

/**
 * Sets the item choice settings
 *
 * @param {number} variableId - The item choice variable id to use
 * @param {number} itemType - The item type to use
 */
Game_Message.prototype.setItemChoice = function(variableId, itemType) {
    this._itemChoiceVariableId = variableId;
    this._itemChoiceItypeId = itemType;
};

/**
 * Sets the scroll settings
 *
 * @param {number} speed - The scroll speed
 * @param {boolean} noFast - If no fast mode scrolling
 */
Game_Message.prototype.setScroll = function(speed, noFast) {
    this._scrollMode = true;
    this._scrollSpeed = speed;
    this._scrollNoFast = noFast;
};

/**
 * Sets the choice callback function
 *
 * @param {Function|null} callback - The callback, null if none
 */
Game_Message.prototype.setChoiceCallback = function(callback) {
    this._choiceCallback = callback;
};

/**
 * Handling when a choice is made
 *
 * @param {number} n - The choice made
 */
Game_Message.prototype.onChoice = function(n) {
    if (this._choiceCallback) {
        this._choiceCallback(n);
        this._choiceCallback = null;
    }
};

/**
 * Check if there is text in the message
 *
 * @return {boolean} True if there is text
 */
Game_Message.prototype.hasText = function() {
    return this._texts.length > 0;
};

/**
 * Check if there are choices
 *
 * @return {boolean} True if there are choices
 */
Game_Message.prototype.isChoice = function() {
    return this._choices.length > 0;
};

/**
 * Check if there is number input
 *
 * @return {boolean} True if there is number input
 */
Game_Message.prototype.isNumberInput = function() {
    return this._numInputVariableId > 0;
};

/**
 * Check if there is an item choice
 *
 * @return {boolean} True if there is an item choice
 */
Game_Message.prototype.isItemChoice = function() {
    return this._itemChoiceVariableId > 0;
};

/**
 * Check if the message is busy
 *
 * @return {boolean} True if busy
 */
Game_Message.prototype.isBusy = function() {
    return (
        this.hasText() ||
        this.isChoice() ||
        this.isNumberInput() ||
        this.isItemChoice()
    );
};

/**
 * Creates a new page
 */
Game_Message.prototype.newPage = function() {
    if (this._texts.length > 0) {
        this._texts[this._texts.length - 1] += "\f";
    }
};

/**
 * Gets all of the text
 *
 * @return {string} All of the text
 */
Game_Message.prototype.allText = function() {
    return this._texts.join("\n");
};

/**
 * Check if the text is right to left
 *
 * @return {boolean} True if RTL
 */
Game_Message.prototype.isRTL = function() {
    return Utils.containsArabic(this.allText());
};