Iavra

Iavra Minimap - Menu

Aug 16th, 2016 (edited)
576
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2.  * @plugindesc v1.00 Extends the ingame options menu with some optional entries regarding the minimap.
  3.  * <Iavra Minimap Menu>
  4.  * @author Iavra
  5.  *
  6.  * @param Label Zoom
  7.  * @desc Label to be used for the minimaps zoom. Leave empty to disable this option.
  8.  * @default
  9.  *
  10.  * @param Label Opacity
  11.  * @desc Label to be used for the minimaps opacity. Leave empty to disable this option.
  12.  * @default
  13.  *
  14.  * @help
  15.  * Make minimap zoom and/or opacity configurable via the ingame Options menu by specifying the label texts to be
  16.  * shown. Leave a label empty to disable the option.
  17.  */
  18.  
  19. (function($, undefined) {
  20.     "use strict";
  21.  
  22.     /**
  23.      * Basic helper function to extend objects. Mainly used for inheritance and other prototype-related operations.
  24.      */
  25.     $._extend || ($._extend = function(b, e) { for(var k in e) { b[k] = e[k]; } return b; });
  26.  
  27.     /**
  28.      * Reading plugin parameters.
  29.      */
  30.     var _params = $plugins.filter(function(p) { return p.description.contains('<Iavra Minimap Menu>'); })[0].parameters;
  31.     var _label_zoom = _params['Label Zoom'];
  32.     var _label_opacity = _params['Label Opacity'];
  33.  
  34.     //=============================================================================
  35.     // ConfigManager
  36.     //=============================================================================
  37.  
  38.     /**
  39.      * Store minimap data in the persistent configuration data.
  40.      */
  41.     var _configManager_makeData = ConfigManager.makeData;
  42.     ConfigManager.makeData = function() {
  43.         var config = _configManager_makeData.call(this);
  44.         config._iavra_minimap_zoom = this._iavra_minimap_zoom;
  45.         config._iavra_minimap_opacity = this._iavra_minimap_opacity;
  46.     };
  47.  
  48.     /**
  49.      * Read configuration data and extract minimap data, if present.
  50.      */
  51.     var _configManager_applyData = ConfigManager.applyData;
  52.     ConfigManager.applyData = function(config) {
  53.         _configManager_applyData.call(this, config);
  54.         if(config._iavra_minimap_zoom !== undefined) { this._iavra_minimap_zoom = config._iavra_minimap_zoom; }
  55.         if(config._iavra_minimap_opacity !== undefined) { this._iavra_minimap_opacity = config._iavra_minimap_opacity; }
  56.     };
  57.  
  58.     /**
  59.      * Add new properties to the ConfigManager.
  60.      */
  61.     Object.defineProperties(ConfigManager, {
  62.         _iavra_minimap_zoom: {
  63.             get: function() { return $.MINIMAP.zoom; },
  64.             set: function(value) { $.MINIMAP.zoom = value; }
  65.         },
  66.         _iavra_minimap_opacity: {
  67.             get: function() { return $.MINIMAP.opacity; },
  68.             set: function(value) { $.MINIMAP.opacity = value; }
  69.         }
  70.     });
  71.  
  72.     //=============================================================================
  73.     // Window_Options
  74.     //=============================================================================
  75.  
  76.     /**
  77.      * If the labels for minimap zoom and/or opacity are given, add new entries in the Options window.
  78.      */
  79.     var _windowOptions_makeCommandList = Window_Options.prototype.makeCommandList;
  80.     Window_Options.prototype.makeCommandList = function() {
  81.         _windowOptions_makeCommandList.call(this);
  82.         if(_label_zoom) { this.addCommand(_label_zoom, '_iavra_minimap_zoom'); }
  83.         if(_label_opacity) { this.addCommand(_label_opacity, '_iavra_minimap_opacity'); }
  84.     };
  85.  
  86.     /**
  87.      * Convert the minimap configuration data to percent, cutting off decimal in case rounding errors.
  88.      */
  89.     var _windowOptions_statusText = Window_Options.prototype.statusText;
  90.     Window_Options.prototype.statusText = function(index) {
  91.         var s = this.commandSymbol(index), v = this.getConfigValue(s);
  92.         if(s === '_iavra_minimap_zoom' || s === '_iavra_minimap_opacity') { return (v * 100).toFixed(0) + "%"; }
  93.         return _windowOptions_statusText.call(this, index);
  94.     };
  95.  
  96.     /**
  97.      * On enter, increase the data by 10%.
  98.      */
  99.     var _windowOptions_processOk = Window_Options.prototype.processOk;
  100.     Window_Options.prototype.processOk = function() {
  101.         return this._iavra_minimap_changeValue(0.1) || _windowOptions_processOk.call(this);
  102.     };
  103.  
  104.     /**
  105.      * On right, increase the data by 10%.
  106.      */
  107.     var _windowOptions_cursorRight = Window_Options.prototype.cursorRight;
  108.     Window_Options.prototype.cursorRight = function(wrap) {
  109.         return this._iavra_minimap_changeValue(0.1) || _windowOptions_cursorRight.call(this, wrap);
  110.     };
  111.  
  112.     /**
  113.      * On left, decrease the data by 10%.
  114.      */
  115.     var _windowOptions_cursorLeft = Window_Options.prototype.cursorLeft;
  116.     Window_Options.prototype.cursorLeft = function(wrap) {
  117.         return this._iavra_minimap_changeValue(-0.1) || _windowOptions_cursorLeft.call(this, wrap);
  118.     };
  119.  
  120.     /**
  121.      * Apply the requested change to minimap configuration data.
  122.      */
  123.     Window_Options.prototype._iavra_minimap_changeValue = function(offset) {
  124.         var s = this.commandSymbol(this.index()), v = this.getConfigValue(s);
  125.         if(s === '_iavra_minimap_zoom') { this.changeValue(s, v + offset); return true; }
  126.         if(s === '_iavra_minimap_opacity') { this.changeValue(s, v + offset); return true; }
  127.     };
  128.  
  129. })(this.IAVRA || (this.IAVRA = {}));
RAW Paste Data