Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Panda's Text Opacity
/*global PluginManager, Bitmap, Window_Message*/
/*:
* @plugindesc
* Adds the option to change text opacity given a command on the message
* window.
*
* @param Special Character
* @desc The special character used in the message. Ex.: \O[60]
* Default: O
* @default O
*
* @param Preserve Text Outline Opacity
* @desc If the outline opacity should copy the text opacity.
* Default: true
* @default true
*
* @author Kyo Panda
*
* @help
*
* MIT License
*
* Copyright (c) 2017 Kyo Panda
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*:pt
* @plugindesc
* Adiciona a opção de mudar a opacidade do texto dado um comando na janela
* de mensagens.
*
* @param Special Character
* @desc O caractere usado para mudar a opacidade. Ex.: \O[60]
* Padrão: O
* @default O
*
* @param Preserve Text Outline Opacity
* @desc Se a opacidade da borda deve seguir a opacidade do texto.
* Padrão: true
* @default true
*
* @author Kyo Panda
*
* @help
*
* MIT License
*
* Copyright (c) 2017 Kyo Panda
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function() {
'use strict';
/**
* Variable conventionally used for identifying imported plugins.
*
* @namespace Imported
* @type {Object}
*/
var Imported = window.Imported || {};
/**
* Marks Panda's Text Opacity plugin as imported.
*
* @name Imported#Panda_TextOpacity
* @type {Boolean}
*/
Imported.Panda_TextOpacity = true;
/**
* Variable used to namespace Panda's plugins.
*
* @namespace Panda
* @type {Object}
*/
var Panda = window.Panda || {};
/**
* The namespace for Panda's Text Opacity
*
* @namespace Panda.TextOpacity
* @type {Object}
*/
Panda.TextOpacity = Panda.TextOpacity || {};
/**
* The version of Panda's Text Opacity
*
* @name Panda.TextOpacity#version
* @type {String}
*/
Panda.TextOpacity.version = '1.0.0';
/**
* Short alias for Panda's Text Opacity
*
* @ignore
*/
var $ = Panda.TextOpacity;
/**
* Namespace for holding aliases for Panda's Text Opacity.
*
* @namespace Panda.TextOpacity.Aliases
* @type {Object}
*/
$.Aliases = $.Aliases || {};
/**
* Class that manages plugins within RPG Maker.
*
* @external PluginManager
*/
/**
* Holds the parameters for Panda's Text Opacity plugin.
*
* @namespace Params
* @memberof Panda.TextOpacity
* @type {Object}
*/
$.Params = (function() {
var _params = PluginManager.parameters('Panda_TextOpacity');
return {
/**
* The special character used to change text opacity in
* Window_Message.
*
* @name specialCharacter
* @memberof Panda.TextOpacity.Params
* @type {String}
*/
specialCharacter: _params['Special Character'] || 'O',
/**
* If the text outline should have its opacity changed.
*
* @name preserveTextOutlineOpacity
* @memberof Panda.TextOpacity.Params
* @type {Boolean}
*/
preserveTextOutlineOpacity: (
_params['Preserve Text Outline Opacity'] === 'true'
)
};
}());
/**
* Namespace for holding Bitmap's aliases.
*
* @namespace Panda.TextOpacity.Aliases.Bitmap
* @type {Object}
*/
$.Aliases.Bitmap = $.Aliases.Bitmap || {};
/**
* Class representing bitmaps in the game.
* @external Bitmap
*/
/**
* Alias for text draw.
*
* @function drawText;
* @memberof Panda.TextOpacity.Aliases.Bitmap
*/
$.Aliases.Bitmap.drawText = Bitmap.prototype.drawText;
/**
* Draws the outline text to the bitmap.
*
* @function drawText
* @memberof external:Bitmap.prototype
*
* @param {String} text The text that will be drawn
* @param {Number} x The x coordinate for the left of the text
* @param {Number} y The y coordinate for the top of the text
* @param {Number} maxWidth The maximum allowed width of the text
* @param {Number} lineHeight The height of the text line
* @param {String} align The alignment of the text
*
* @returns {void}
*/
Bitmap.prototype.drawText = function() {
if (this._preserveTextOutlineOpacity) {
this._originalGlobalAlpha = this._context.globalAlpha;
}
$.Aliases.Bitmap.drawText.apply(this, arguments);
};
/**
* Alias for text outline draw.
*
* @function _drawTextOutline
* @memberof Panda.TextOpacity.Aliases.Bitmap
*/
$.Aliases.Bitmap._drawTextOutline = Bitmap.prototype._drawTextOutline;
/**
* Draw the text outline.
*
* @function _drawTextOutline
* @memberof external:Bitmap.prototype
*
* @param {String} text The text to be drawn.
* @param {Number} tx The X coordinate of the text.
* @param {Number} ty The Y coordinate of the text.
* @param {Number} maxWidth The max width in which the text can be drawn.
*
* @returns {void}
*/
Bitmap.prototype._drawTextOutline = function() {
if (this._preserveTextOutlineOpacity) {
this._context.globalAlpha = this._originalGlobalAlpha;
}
$.Aliases.Bitmap._drawTextOutline.apply(this, arguments);
};
/**
* Namespace for holding Window Message's aliases.
*
* @namespace Panda.TextOpacity.Aliases.Window_Message
* @type {Object}
*/
$.Aliases.Window_Message = $.Aliases.Window_Message || {};
/**
* Window responsible for showing messages.
*
* @external Window_Message
*/
/**
* Alias for Window_Message's constructor.
*
* @function initialize
* @memberof Panda.TextOpacity.Aliases.Window_Message
*/
$.Aliases.Window_Message.initialize =
Window_Message.prototype.initialize
;
/**
* Window_Message's constructor.
*
* @function initialize
* @memberof external:Window_Message.prototype
*
* @returns {void}
*/
Window_Message.prototype.initialize = function() {
$.Aliases.Window_Message.initialize.apply(this, arguments);
this.contents._preserveTextOutlineOpacity = (
$.Params.preserveTextOutlineOpacity
);
};
/**
* Alias for process escape character.
*
* @function proccessEscapeCharacter
* @memberof Panda.TextOpacity.Aliases.Window_Message
*/
$.Aliases.Window_Message.processEscapeCharacter =
Window_Message.prototype.processEscapeCharacter
;
/**
* Processes special characters on message window text draw.
*
* @function processEscapeCharacter
* @memberof externa:Window_Message.prototype
*
* @param {String} code The code of the special character.
* @param {String} textState The value of the special character.
*
* @returns {void}
*/
Window_Message.prototype.processEscapeCharacter = function(
code, textState
) {
switch (code) {
case $.Params.specialCharacter:
var alpha = Number(this.obtainEscapeParam(textState)) || 255;
this.changeTextOpacity(alpha);
break;
default:
$.Aliases.Window_Message.processEscapeCharacter.apply(
this, arguments
);
}
};
/**
* Changes the text opacity.
*
* @function changeTextOpacity
* @memberof external:Window_Message.prototype
*
* @param {String} alpha The new opacity.
*
* @returns {void}
*/
Window_Message.prototype.changeTextOpacity = function(alpha) {
this.contents.paintOpacity = alpha;
};
/**
* Returns the namespaces to the global context.
*/
window.Imported = Imported;
window.Panda = Panda;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment