Advertisement
Kakakadafi

TheoAllen_AnywhereTexts

Sep 11th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // TheoAllen - Anywhere Texts on Screen
  3. // Version: 1.0
  4. // TheoAllen_AnywhereTexts.js
  5. //=============================================================================
  6.  
  7. var Imported = Imported || {};
  8. Imported.Theo_AnywhereText = true;
  9.  
  10. /*:
  11.  * @plugindesc
  12.  *  Anywhere Texts on Screen.
  13.  *
  14.  * @author TheoAllen (Ported by Kadafi)
  15.  *
  16.  * @help
  17.  * -----------------------------------------------------------------------------
  18.  * *) Introduction :
  19.  * -----------------------------------------------------------------------------
  20.  * This plugin allow you to have many texts written on screen.
  21.  *
  22.  * -----------------------------------------------------------------------------
  23.  * *) How to use :
  24.  * -----------------------------------------------------------------------------
  25.  * Write this following line to script call to add text on your screen
  26.  *
  27.  * this.text(key,x,y,text,z,show,width,height,color1,color2);
  28.  *
  29.  * Paramaters that must be filled:
  30.  * - key  >> Is a hash key. You may fill it with numeric or string. It's used to
  31.  *           delete your on screen text later
  32.  * - x    >> X coordinate from top-left
  33.  * - y    >> Y coordinate from top-left
  34.  * - text >> Is the text you want to display on screen. It's support escape
  35.  *           characters such as \N[1] in show text message. But, you have to use
  36.  *           double slash to activate. For example \\N[1]
  37.  *
  38.  * Parameters that can be ommited :
  39.  * - z      >> Z coordinate on screen. The larger number means the closer to
  40.  *             player text will be displayed. If it's ommited, the default value
  41.  *             is 0.
  42.  * - show   >> show duration in frame. If you want to text stay on screen until
  43.  *             you delete it manualy, use -1. The default value is -1
  44.  * - width  >> width of a rectangle that will be used to draw a box
  45.  * - height >> height of a rectangle that will be used to draw a box
  46.  * - color1 >> Color of the rectangle. Must be filled by
  47.  *             'rgba(red, green, blue, alpha)'
  48.  * - color2 >> Second Color of the rectangle. The default value is same as
  49.  *             color1
  50.  *
  51.  * To delete a certain text. Use this script call
  52.  * this.del_text(key);
  53.  *
  54.  * Key is a hash key. Same as above
  55.  *
  56.  * To clear entire screen, use
  57.  * this.clear_texts();
  58.  *
  59.  * -----------------------------------------------------------------------------
  60.  * *) Terms of use :
  61.  * -----------------------------------------------------------------------------
  62.  * TheoAllen:
  63.  * Credit me, TheoAllen. You are free to edit this script by your own. As long
  64.  * as you don't claim it yours. For commercial purpose, don't forget to give me
  65.  * a free copy of the game.
  66.  *
  67.  * Kadafi:
  68.  * Credit me, Kadafi. (Optional)
  69.  */
  70.  
  71. //-----------------------------------------------------------------------------
  72. // Game_Interpreter
  73. //-----------------------------------------------------------------------------
  74.  
  75. Game_Interpreter.prototype.text = function(key, x, y, text, z, show, width, height, color1, color2) {
  76.     var data = [x || 0, y || 0, text || "", z || 0, show || -1, width || 0, height || 0,
  77.                 color1 || 'rgba(0, 0, 0, 0)', color2 || 'rgba(0, 0, 0, 0)'];
  78.     $gameSystem.addAnyText(key, data);
  79. };
  80.  
  81. Game_Interpreter.prototype.del_text = function(key) {
  82.     $gameSystem.delAnyText(key);
  83. };
  84.  
  85. Game_Interpreter.prototype.clear_texts = function() {
  86.     $gameSystem.clearTexts();
  87. };
  88.  
  89. //-----------------------------------------------------------------------------
  90. // Game_System
  91. //-----------------------------------------------------------------------------
  92.  
  93. var Game_System_initialize = Game_System.prototype.initialize;
  94. Game_System.prototype.initialize = function() {
  95.     Game_System_initialize.call(this);
  96.     this._anywhereTexts = {};
  97. };
  98.  
  99. Game_System.prototype.addAnyText = function(key, data) {
  100.     if (SceneManager._scene._anywhereTextWindow) {
  101.         this._anywhereTexts[key] = data;
  102.         SceneManager._scene._anywhereTextWindow.refresh();
  103.     }
  104. };
  105.  
  106. Game_System.prototype.delAnyText = function(key) {
  107.     if (SceneManager._scene._anywhereTextWindow) {
  108.         delete this._anywhereTexts[key];
  109.         SceneManager._scene._anywhereTextWindow.refresh();
  110.     }
  111. };
  112.  
  113. Game_System.prototype.clearTexts = function() {
  114.     if (SceneManager._scene._anywhereTextWindow) {
  115.         this._anywhereTexts = {};
  116.         SceneManager._scene._anywhereTextWindow.refresh();
  117.     }
  118. };
  119.  
  120. //-----------------------------------------------------------------------------
  121. // Scene_Map
  122. //-----------------------------------------------------------------------------
  123.  
  124. var Scene_Map_createMapNameWindow = Scene_Map.prototype.createMapNameWindow;
  125. Scene_Map.prototype.createMapNameWindow = function() {
  126.     // Anywhere Text Window placed below Map Name Window
  127.     this._anywhereTextWindow = new Window_AnywhereText();
  128.     this.addChild(this._anywhereTextWindow);
  129.     Scene_Map_createMapNameWindow.call(this);
  130. };
  131.  
  132. //-----------------------------------------------------------------------------
  133. // Window_AnywhereText
  134. //-----------------------------------------------------------------------------
  135.  
  136. function Window_AnywhereText() {
  137.     this.initialize.apply(this, arguments);
  138. }
  139.  
  140. Window_AnywhereText.prototype = Object.create(Window_Base.prototype);
  141. Window_AnywhereText.prototype.constructor = Window_AnywhereText;
  142.  
  143. Window_AnywhereText.prototype.initialize = function() {
  144.     Window_Base.prototype.initialize.call(this, 0, 0, Graphics.boxWidth, Graphics.boxHeight);
  145.     this.opacity = 0;
  146.     this.contentsOpacity = 255;
  147.     this.refresh();
  148. };
  149.  
  150. Window_AnywhereText.prototype.update = function() {
  151.     Window_Base.prototype.update.call(this);
  152.     for (var key in $gameSystem._anywhereTexts) {
  153.         if ($gameSystem._anywhereTexts[key][4] >= 0) {
  154.             $gameSystem._anywhereTexts[key][4]--;
  155.             if ($gameSystem._anywhereTexts[key][4] === 0) {
  156.                 $gameSystem.delAnyText(key);
  157.             }
  158.         }
  159.     }
  160. };
  161.  
  162. Window_AnywhereText.prototype.standardPadding = function() {
  163.     return 0;
  164. };
  165.  
  166. Window_AnywhereText.prototype.refresh = function() {
  167.     this.contents.clear();
  168.     var textOrder = [];
  169.     for (var key in $gameSystem._anywhereTexts) {
  170.         textOrder.push([key, $gameSystem._anywhereTexts[key][3]]);
  171.     }
  172.     textOrder.sort(function(a, b) { return a[1] - b[1] });
  173.     for (var i = 0; i < textOrder.length; i++) {
  174.         var data = $gameSystem._anywhereTexts[textOrder[i][0]];
  175.         var x = data[0];
  176.         var y = data[1];
  177.         var text = data[2];
  178.         var width = data[5];
  179.         var height = data[6];
  180.         var color1 = data[7];
  181.         var color2 = data[8];
  182.         this.contents.gradientFillRect(x, y, width, height, color1, color2);
  183.         this.drawTextEx(text, x, y);
  184.         this.resetFontSettings();
  185.     }
  186. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement