Foure4

ScreenVariables

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