Advertisement
Foure4

ScreenVariables

Sep 20th, 2019 (edited)
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*=============================================================================
  2.  * Screen Variables
  3.  *=============================================================================*/
  4.  
  5.  /*:
  6.  * @plugindesc v1.04 Show Text on your screen.
  7.  * <ScreenVariables>
  8.  * @author Krimer
  9.  *
  10.  * @param Variable Number
  11.  * @desc Number of variable where your text data saved
  12.  * @default 0
  13.  *
  14.  * @param Auto-Refresh
  15.  * @desc Text auto-refresh. true or false
  16.  * @default false
  17.  *
  18.  * @help
  19.  *
  20.  * Available script calls:
  21.  * 'Key' - Is text identifier, provide access to each text separately.
  22.  * 'visibility' - text visibility, On(true)\Off(false)
  23.  * this.addVarHudText('Key','your text',Х,Y,visibility) - add text to your screen.
  24.  * Example: this.addVarHudText('test','Text Check',66,66,true)
  25.  *
  26.  * this.textVarTurnOn('Key') - Change text visibility on true, using text key
  27.  * this.textVarTurnOff('Key') - Change text visibility on false, using text key
  28.  * this.textVarSetXY('Key',Х,Y) - Change Х & Y for text using text key.
  29.  * this.textVarGetX('Key') - Get current Х of the text using text key.
  30.  * this.textVarGetY('Key') - Get current Y of the text using text key.
  31.  * this.changeVarText('Key', 'your text') - Change text using text key.
  32.  * this.showAllVarText() - Change all texts visibility on true
  33.  * this.hideAllVarText() - Change all texts visibility on false
  34.  * this.showVarWindow() - Show all texts, doesn't change visibility setting on text.
  35.  * this.hideVarWindow() - Hide all texts, doesn't change visibility setting on text.
  36.  * this.deleteVar() - Delete text using text key.
  37.  * this.varHudRefresh() - Manual refresh for all texts.
  38.  *
  39.  * =============================================================================
  40.  * Text support some standard special characters:
  41.  * \\V[n] - Will be replaced with the value of the nth variable.
  42.  * \\N[n] - Will be replaced with the name of the nth actor.
  43.  * \\P[n] - Will be replaced by the name of the nth (arranged order) party member.
  44.  * \\G - Will be replaced by the currency unit.
  45.  * \\C[n] - Draw the subsequent text in the nth color.
  46.  * \\I[n] - Draws the nth icon.
  47.  * \\{ - Increases the text by 1 step.
  48.  * \\} - Decreases the text by 1 step.
  49.  * Double slash is necessary
  50.  * =============================================================================
  51.  *
  52.  */
  53.  
  54.  
  55. (function() {
  56.     var parameters = $plugins.filter(function(p) {return p.description.contains('<ScreenVariables>');})[0].parameters;
  57.     var dVariableNumber = Number(parameters['Variable Number'] || 0);
  58.     var dAtoRefresh = eval(String(parameters['Auto-Refresh']));
  59.    
  60.     /*=============== Window_Variable ===============*/
  61.     function Window_Variable() {
  62.         this.initialize.apply(this, arguments);
  63.     }
  64.  
  65.     Window_Variable.prototype = Object.create(Window_Base.prototype);
  66.     Window_Variable.prototype.constructor = Window_Variable;
  67.  
  68.     Window_Variable.prototype.initialize = function(x, y) {
  69.         var width = Graphics.width + this.standardPadding() * 2
  70.         var height = Graphics.height + this.standardPadding() * 2;
  71.         Window_Base.prototype.initialize.call(this, x, y, width, height);
  72.         this.refresh();
  73.     };
  74.  
  75.     Window_Variable.prototype.standardPadding = function() {
  76.         return 0;
  77.     };
  78.    
  79.     Window_Variable.prototype.refresh = function() {
  80.         this.contents.clear();
  81.         for(var key in $gameVariables._data[dVariableNumber]){
  82.             var hudObj = $gameVariables._data[dVariableNumber][key];
  83.             if (hudObj.visible === true){
  84.                 this.drawTextEx(hudObj.hudText, hudObj.x, hudObj.y);
  85.             }
  86.         }
  87.     }; 
  88.     /*=============== Window_Variable end ===============*/
  89.    
  90.     /*=============== Game_Interpreter ===============*/
  91.     Game_Interpreter.prototype.isRefreshAvailable = function() {
  92.         return ((typeof SceneManager._scene._variableWindow != "undefined") && (SceneManager._scene._varWindowAutoRefresh === false))
  93.     };
  94.    
  95.     Game_Interpreter.prototype.isHudCreated = function() {
  96.         return ((typeof SceneManager._scene._variableWindow != "undefined") && (typeof $gameVariables._data[dVariableNumber] === 'object'))
  97.     };
  98.  
  99.     Game_Interpreter.prototype.addVarHudText = function() {
  100.         if (!this.isHudCreated()){
  101.             $gameVariables._data[dVariableNumber] = {};
  102.         }
  103.         var args = arguments;
  104.         $gameVariables._data[dVariableNumber][args[0]] = {hudText:args[1], x:args[2], y:args[3], visible:args[4]};
  105.         if (this.isRefreshAvailable()){
  106.             this.varHudRefresh()
  107.         }
  108.     };
  109.  
  110.     Game_Interpreter.prototype.textVarTurnOn = function(key) {
  111.         if (!this.isHudCreated()){
  112.             $gameVariables._data[dVariableNumber] = {};
  113.         }
  114.         var args = arguments;
  115.         $gameVariables._data[dVariableNumber][String(key)].visible = true;
  116.         if (this.isRefreshAvailable()){
  117.             this.varHudRefresh()
  118.         }
  119.     };
  120.  
  121.     Game_Interpreter.prototype.textVarTurnOff = function(key) {
  122.         if (!this.isHudCreated()){
  123.             $gameVariables._data[dVariableNumber] = {};
  124.         }
  125.         var args = arguments;
  126.         $gameVariables._data[dVariableNumber][String(key)].visible = false;
  127.         if (this.isRefreshAvailable()){
  128.             this.varHudRefresh()
  129.         }
  130.     };
  131.  
  132.     Game_Interpreter.prototype.textVarSetXY = function(key, valueX, valueY) {
  133.         if (!this.isHudCreated()){
  134.             $gameVariables._data[dVariableNumber] = {};
  135.         }
  136.         var valueX = Number(valueX) || 0;
  137.         var valueY = Number(valueY) || 0;
  138.         $gameVariables._data[dVariableNumber][String(key)].x = valueX;
  139.         $gameVariables._data[dVariableNumber][String(key)].y = valueY;
  140.         if (this.isRefreshAvailable()){
  141.             this.varHudRefresh()
  142.         }
  143.     };
  144.  
  145.     Game_Interpreter.prototype.textVarGetX = function(key) {
  146.         if (!this.isHudCreated()){
  147.             $gameVariables._data[dVariableNumber] = {};
  148.         }
  149.         return $gameVariables._data[dVariableNumber][String(key)].x;
  150.     };
  151.  
  152.     Game_Interpreter.prototype.textVarGetY = function(key) {
  153.         if (!this.isHudCreated()){
  154.             $gameVariables._data[dVariableNumber] = {};
  155.         }
  156.         return $gameVariables._data[dVariableNumber][String(key)].y;
  157.     };
  158.    
  159.     Game_Interpreter.prototype.changeVarText = function(key, textValue) {
  160.         if (!this.isHudCreated()){
  161.             $gameVariables._data[dVariableNumber] = {};
  162.         }
  163.         $gameVariables._data[dVariableNumber][String(key)].hudText = textValue;
  164.         if (this.isRefreshAvailable()){
  165.             this.varHudRefresh()
  166.         }
  167.     };
  168.  
  169.     Game_Interpreter.prototype.showAllVarText = function() {
  170.         if (!this.isHudCreated()){
  171.             $gameVariables._data[dVariableNumber] = {};
  172.         }
  173.         for(var key in $gameVariables._data[dVariableNumber]){
  174.             var hudObj = $gameVariables._data[dVariableNumber][key];
  175.             hudObj.visible = true;
  176.         }
  177.         if (this.isRefreshAvailable()){
  178.             this.varHudRefresh()
  179.         }
  180.     };
  181.  
  182.     Game_Interpreter.prototype.hideAllVarText = function() {
  183.         if (!this.isHudCreated()){
  184.             $gameVariables._data[dVariableNumber] = {};
  185.         }
  186.         for(var key in $gameVariables._data[dVariableNumber]){
  187.             var hudObj = $gameVariables._data[dVariableNumber][key];
  188.             hudObj.visible = false;
  189.         }
  190.         if (this.isRefreshAvailable()){
  191.             this.varHudRefresh()
  192.         }
  193.     };
  194.    
  195.     Game_Interpreter.prototype.hideVarWindow = function() {
  196.         if (!this.isHudCreated()){
  197.             $gameVariables._data[dVariableNumber] = {};
  198.         }
  199.         if (typeof SceneManager._scene._variableWindow != "undefined"){
  200.             SceneManager._scene._variableWindow.hide();
  201.         }
  202.     };
  203.    
  204.     Game_Interpreter.prototype.showVarWindow = function() {
  205.         if (!this.isHudCreated()){
  206.             $gameVariables._data[dVariableNumber] = {};
  207.         }
  208.         if (typeof SceneManager._scene._variableWindow != "undefined"){
  209.             SceneManager._scene._variableWindow.show();
  210.         }
  211.     };
  212.    
  213.     Game_Interpreter.prototype.deleteVar = function(key) {
  214.         if (!this.isHudCreated()){
  215.             $gameVariables._data[dVariableNumber] = {};
  216.         }
  217.         delete $gameVariables._data[dVariableNumber][String(key)]
  218.     };
  219.    
  220.     Game_Interpreter.prototype.varHudRefresh = function() {
  221.         if (!this.isHudCreated()){
  222.             $gameVariables._data[dVariableNumber] = {};
  223.         }
  224.         SceneManager._scene.refreshVarWindow()
  225.     }; 
  226.     /*=============== Game_Interpreter end ===============*/
  227.    
  228.     Scene_Base.prototype.createVarLayer = function() {
  229.         var width = Graphics.boxWidth;
  230.         var height = Graphics.boxHeight;
  231.         var x = (Graphics.width - width) / 2;
  232.         var y = (Graphics.height - height) / 2;
  233.         this._varLayer = new WindowLayer();
  234.         this._varLayer.move(x, y, width, height);
  235.         this.addChild(this._varLayer);
  236.     };
  237.    
  238.     /*=============== Scene_Map ===============*/
  239.     DVarHud_Scene_Map_initialize = Scene_Map.prototype.initialize;
  240.     Scene_Map.prototype.initialize = function() {
  241.         DVarHud_Scene_Map_initialize.call(this);
  242.         this._varWindowAutoRefresh = dAtoRefresh;
  243.     };
  244.  
  245.    
  246.     Scene_Map.prototype.createDisplayObjects = function() {
  247.         this.createSpriteset();
  248.         this.createMapNameWindow();
  249.         this.createVarLayer();
  250.         this.createWindowLayer();
  251.         this.createAllWindows();
  252.     };
  253.    
  254.     DVarHud_Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
  255.     Scene_Map.prototype.createAllWindows = function() {
  256.         this.createVariableWindow();
  257.         DVarHud_Scene_Map_createAllWindows.call(this);
  258.     };
  259.  
  260.     Scene_Map.prototype.createVariableWindow = function() {
  261.         this._variableWindow = new Window_Variable();
  262.         this._variableWindow.setBackgroundType(2)
  263.         this._varLayer.addChild(this._variableWindow);
  264.     };
  265.  
  266.     Scene_Map.prototype.refreshVarWindow = function() {
  267.         if (typeof this._variableWindow != "undefined"){
  268.             this._variableWindow.refresh();
  269.         }  
  270.     };
  271.  
  272.     DVarHud_Scene_Map_update = Scene_Map.prototype.update;
  273.     Scene_Map.prototype.update = function() {
  274.         DVarHud_Scene_Map_update.call(this);
  275.         if (this._varWindowAutoRefresh == true){
  276.             this._variableWindow.refresh();
  277.         }
  278.     };
  279.    
  280.     DVarHud_Scene_Map_terminate = Scene_Map.prototype.terminate;
  281.     Scene_Map.prototype.terminate = function() {
  282.     DVarHud_Scene_Map_terminate.call(this);
  283.     this.removeChild(this._varLayer);
  284.     };
  285.     /*=============== Scene_Map end ===============*/
  286.    
  287.     DVarHud_DataManager_setupNewGame = DataManager.setupNewGame
  288.     DataManager.setupNewGame = function() {
  289.         DVarHud_DataManager_setupNewGame.call(this);
  290.         $gameVariables._data[dVariableNumber] = {};
  291.     };
  292. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement