Advertisement
ezmash

Toggle Page (MV)

Jan 13th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2.  * Toggle Page by Shaz
  3.  * Ver 1.00 2018.01.14
  4.  * Shaz_TogglePage.js
  5.  *
  6.  *
  7.  * @plugindesc Disables/enables event pages on the current map.
  8.  * @author Shaz
  9.  *
  10.  * @help This plugin allows you to temporarily disable a page on an event on
  11.  * the current map, and to re-enable it again.  You can affect the current
  12.  * page on the current event, a specific page on the current event, or a
  13.  * specific page on another event on the current map.
  14.  *
  15.  * Like the Erase Event command, this lasts only until you leave the map.
  16.  * When you return, all pages will be enabled.
  17.  *
  18.  * Plugin Commands:
  19.  * TogglePage                - toggles the current page of the current event
  20.  * TogglePage pageId         - toggles the specified page of the current event
  21.  * TogglePage eventId pageId - toggles the specified page of the specified event
  22.  *
  23.  * Example:
  24.  * TogglePage enables/disables the current page
  25.  * TogglePage 5 enables/disables page 5 on the current event
  26.  * TogglePage 10 3 enables/disables page 3 of event 10 on the current map
  27.  * TogglePage $gameVariables(1) $gameVariables(2) enables/disables the page
  28.  *            number contained in variable 2, of the event whose id is in
  29.  *            variable 1
  30.  *
  31.  *
  32.  * NOTE:
  33.  * pageId refers to the event tab as seen in the editor.  The first event page
  34.  * is pageId 1.
  35.  *
  36.  * eventId and pageId can be formulae, but there must be no spaces.
  37.  *
  38.  * This plugin OVERWRITES the Game_Event.findProperPageIndex function.  There
  39.  * may be compatibility issues with other plugins that also overwrite the same
  40.  * function.  
  41.  *
  42.  */
  43.  
  44. var Imported = Imported || {};
  45. Imported.Shaz_TogglePage = true;
  46.  
  47. var Shaz = Shaz || {};
  48. Shaz.TP = Shaz.TP || {};
  49. Shaz.TP.Version = 1.00;
  50.  
  51. (function() {
  52.     var _Shaz_TP_Game_Event_initialize = Game_Event.prototype.initialize;
  53.     Game_Event.prototype.initialize = function(mapId, eventId) {
  54.         this._activePages = Array($dataMap.events[eventId].pages.length);
  55.         for (var i = 0; i < this._activePages.length; i++) {
  56.             this._activePages[i] = true;
  57.         }
  58.         _Shaz_TP_Game_Event_initialize.call(this, mapId, eventId);
  59.     };
  60.  
  61.     Game_Event.prototype.findProperPageIndex = function() {
  62.         var pages = this.event().pages;
  63.         for (var i = pages.length - 1; i >= 0; i--) {
  64.             var page = pages[i];
  65.             if (this._activePages[i] && this.meetsConditions(page)) {
  66.                 return i;
  67.             }
  68.         }
  69.         return -1;
  70.     };
  71.  
  72.     Game_Event.prototype.togglePage = function(id) {
  73.         id = id ? id - 1 : this._pageIndex;
  74.         if (id >= 0 && id < this._activePages.length) {
  75.             this._activePages[id] = !(this._activePages[id]);
  76.             this.refresh();
  77.         }
  78.     }
  79.  
  80.     var _Shaz_TP_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  81.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  82.         switch(command.toUpperCase()) {
  83.             case 'TOGGLEPAGE':
  84.                 for (var i = 0; i < args.length; i++) {
  85.                     args[i] = eval(args[i]);
  86.                 }
  87.                 switch(args.length) {
  88.                     case 0:
  89.                         $gameMap.event(this._eventId).togglePage();
  90.                         break;
  91.                     case 1:
  92.                         $gameMap.event(this._eventId).togglePage(args[0]);
  93.                         break;
  94.                     case 2:
  95.                         $gameMap.event(args[0]).togglePage(args[1]);
  96.                         break;
  97.                 }
  98.                 break;
  99.             default:
  100.                 _Shaz_TP_Game_Interpreter_pluginCommand.call(this, command, args);
  101.         }
  102.     };
  103.  
  104. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement