Advertisement
Double_X

DoubleX RMMV Popularized ATB CTB v100c

Jan 23rd, 2016 (edited)
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.  *    ## Plugin Info                                                          
  3.  *----------------------------------------------------------------------------
  4.  *    # Plugin Name                                                          
  5.  *      DoubleX RMMV Popularized ATB CTB                                      
  6.  *----------------------------------------------------------------------------
  7.  *    # Terms Of Use                                                          
  8.  *      You shall keep this plugin's Plugin Info part's contents intact      
  9.  *      You shalln't claim that this plugin's written by anyone other than    
  10.  *      DoubleX or his aliases                                                
  11.  *      None of the above applies to DoubleX or his aliases                  
  12.  *----------------------------------------------------------------------------
  13.  *    # Prerequisites                                                        
  14.  *      Plugins:                                                              
  15.  *      1. DoubleX RMMV Popularized ATB Core                                  
  16.  *      Abilities:                                                            
  17.  *      1. Little Javascript coding proficiency to fully utilize this plugin  
  18.  *----------------------------------------------------------------------------
  19.  *    # Links                                                                
  20.  *      This plugin:                                                          
  21.  *      1. http://pastebin.com/rFw3nsAZ                                      
  22.  *      Video:                                                                
  23.  *      1. https://www.youtube.com/watch?v=o-DF-tPTsF0                        
  24.  *      Mentioned Patreon Supporters:
  25.  *      https://www.patreon.com/posts/71738797
  26.  *----------------------------------------------------------------------------
  27.  *    # Author                                                                
  28.  *      DoubleX                                                              
  29.  *----------------------------------------------------------------------------
  30.  *    # Changelog                                                            
  31.  *      v1.00c(GMT 0500 3-7-2016):                                            
  32.  *      1. Fixed below configuration changes not taking place in same battle:
  33.  *         - battle_system_window_x                                          
  34.  *         - battle_system_window_y                                          
  35.  *         - battle_system_window_width                                      
  36.  *         - battle_system_window_height                                      
  37.  *         - battle_system_text_size                                          
  38.  *         - battle_system_text_x                                            
  39.  *         - battle_system_text_y                                            
  40.  *      2. Increased this plugin's effectiveness, efficiency and flexibility  
  41.  *      v1.00b(GMT 1000 24-1-2016):                                          
  42.  *      1. Fixed not clearing old text before showing new ones bug            
  43.  *      2. Increased this plugin's compactness, readability and simplicity    
  44.  *      v1.00a(GMT 1400 23-1-2016):                                          
  45.  *      1. 1st completed version of this plugin finished                      
  46.  *============================================================================*/
  47. /*:
  48.  * @plugindesc Lets users switch the battle system to mimic charge turn battle
  49.  * @author DoubleX
  50.  *
  51.  * @param show_battle_system_window
  52.  * @desc Setups a window in battle indicating whether atb or ctb's used if
  53.  *       show_battle_system_window is set as true
  54.  * @default true
  55.  *
  56.  * @param battle_system_window_x
  57.  * @desc Sets the x position of the battle system indicator window as
  58.  *       battle_system_window_x
  59.  * @default 0
  60.  *
  61.  * @param battle_system_window_y
  62.  * @desc Sets the y position of the battle system indicator window as
  63.  *       battle_system_window_y
  64.  * @default 108
  65.  *
  66.  * @param battle_system_window_width
  67.  * @desc Sets the width of the battle system indicator window as
  68.  *       battle_system_window_width
  69.  * @default 220
  70.  *
  71.  * @param battle_system_window_height
  72.  * @desc Sets the height of the battle system indicator window as
  73.  *       battle_system_window_height
  74.  * @default 60
  75.  *
  76.  * @param battle_system_text_size
  77.  * @desc Sets the size of the text shown in the battle system indicator window
  78.  *       as battle_system_text_size
  79.  * @default 20
  80.  *
  81.  * @param battle_system_text_x
  82.  * @desc Sets the x position of the text shown in the battle system indicator
  83.  *       window as battle_system_text_x
  84.  * @default 0
  85.  *
  86.  * @param battle_system_text_y
  87.  * @desc Sets the y position of the text shown in the battle system indicator
  88.  *       window as battle_system_text_y
  89.  * @default -8
  90.  *
  91.  * @param atb_battle_system_text
  92.  * @desc Sets the text shown in a window indicating atb's used in battle as
  93.  *       atb_battle_system_text
  94.  * @default Active Time Battle
  95.  *
  96.  * @param ctb_battle_system_text
  97.  * @desc Sets the text shown in a window indicating ctb's used in battle as
  98.  *       ctb_battle_system_text
  99.  * @default Charge Turn Battle
  100.  *
  101.  * @help
  102.  * battle_system_code now supports ctb as well, which changes the battle
  103.  * system into ctb
  104.  * The default plugin file name is DoubleX RMMV Popularized ATB CTB v100c
  105.  * If you want to change that, you must edit the value of
  106.  * DoubleX_RMMV.PATB_CTB_File, which must be done via opening the plugin js
  107.  * file directly
  108.  *============================================================================
  109.  *    ## Plugin Call Info                                                    
  110.  *----------------------------------------------------------------------------
  111.  *    # Configuration manipulations                                          
  112.  *      1. $gameSystem.patb.param                                            
  113.  *         - Returns the value of param listed in the plugin manager          
  114.  *      2. $gameSystem.patb.param = val                                      
  115.  *         - Sets the value of param listed in the plugin manager as val      
  116.  *         - All $gameSystem.patb.param changes will be saved                
  117.  *============================================================================
  118.  */
  119.  
  120. "use strict";
  121. var DoubleX_RMMV = DoubleX_RMMV || {};
  122. DoubleX_RMMV["PATB CTB"] = "v1.00c";
  123.  
  124. // The plugin file name must be the same as DoubleX_RMMV.PATB_CTB_File
  125. DoubleX_RMMV.PATB_CTB_File = "DoubleX RMMV Popularized ATB CTB v100c";
  126.  
  127. /*============================================================================
  128.  *    ## Plugin Implementations                                              
  129.  *       You need not edit this part as it's about how this plugin works      
  130.  *----------------------------------------------------------------------------
  131.  *    # Plugin Support Info:                                                  
  132.  *      1. Prerequisites                                                      
  133.  *         - Basic knowledge of this plugin on the user level, the default    
  134.  *           battle system implementations and the atb system concepts        
  135.  *         - Some Javascript coding proficiency to fully comprehend this      
  136.  *           plugin                                                          
  137.  *      2. Function documentation                                            
  138.  *         - The 1st part describes why this function's rewritten/extended for
  139.  *           rewritten/extended functions or what the function does for new  
  140.  *           functions                                                        
  141.  *         - The 2nd part describes what the arguments of the function are    
  142.  *         - The 3rd part informs which version rewritten, extended or created
  143.  *           this function                                                    
  144.  *         - The 4th part informs whether the function's rewritten or new    
  145.  *         - The 5th part informs whether the function's a real or potential  
  146.  *           hotspot                                                          
  147.  *         - The 6th part describes how this function works for new functions
  148.  *           only, and describes the parts added, removed or rewritten for    
  149.  *           rewritten or extended functions only                            
  150.  *         Example:                                                          
  151.  * /*----------------------------------------------------------------------
  152.  *  *    Why rewrite/extended/What this function does                      
  153.  *  *----------------------------------------------------------------------*/
  154. /* // arguments: What these arguments are                                    
  155.  * function_name = function(arguments) { // Version X+; Rewrite/New; Hotspot  
  156.  *     // Added/Removed/Rewritten to do something/How this function works    
  157.  *     function_name_code;                                                    
  158.  *     //                                                                    
  159.  * } // function_name                                                        
  160.  *----------------------------------------------------------------------------*/
  161.  
  162. function Window_Patb_Ctb() { this.initialize.apply(this, arguments); }
  163.  
  164. if (DoubleX_RMMV["PATB Core"]) {
  165.  
  166. /*----------------------------------------------------------------------------*/
  167.  
  168. /*----------------------------------------------------------------------------
  169.  *    # Edit class: BattleManager                                            
  170.  *      - Implements the ctb system replication when it's asked and allowed  
  171.  *----------------------------------------------------------------------------*/
  172.  
  173. /*----------------------------------------------------------------------------
  174.  *    Runs the global and battler atb clocks until they've to stop            
  175.  *----------------------------------------------------------------------------*/
  176. BattleManager.update_patb_ctb = BattleManager.update_patb;
  177. BattleManager.update_patb = function() { // Hotspot
  178.     // Rewritten
  179.     do { this.update_patb_ctb(); } while (this.can_update_patb_ctb());
  180.     //
  181. }; // BattleManager.update_patb
  182.  
  183. /*----------------------------------------------------------------------------
  184.  *    Checks if the atb frame updates can behave in the ctb manner            
  185.  *----------------------------------------------------------------------------*/
  186. BattleManager.can_update_patb_ctb = function() { // New; Hotspot
  187.     if ($gameSystem.patb.battle_system_code !== "ctb") { return false; }
  188.     if (this._phase === 'action' || this.isInputting()) { return false; }
  189.     return !this.isBusy() && !this._need_patb_refresh;
  190. }; // BattleManager.can_update_patb_ctb
  191.  
  192. /*----------------------------------------------------------------------------
  193.  *    # Edit class: Game_System                                              
  194.  *      - Stores the values of all configurations listed in the plugin manager
  195.  *----------------------------------------------------------------------------*/
  196.  
  197. Game_System.prototype.init_patb_ctb_params =
  198. Game_System.prototype.init_patb_params;
  199. Game_System.prototype.init_patb_params = function() {
  200.     this.init_patb_ctb_params();
  201.     // Added
  202.     var val, params = PluginManager.parameters(DoubleX_RMMV.PATB_CTB_File);
  203.     Object.keys(params).forEach(function(param) {
  204.         val = +params[param];
  205.         this._patb[param] = isNaN(val) ? params[param] : val;
  206.     }, this);
  207.     this._patb.show_battle_system_window =
  208.     params.show_battle_system_window === "true";
  209.     //
  210. }; // Game_System.prototype.init_patb_params
  211.  
  212. Game_System.prototype.is_patb_ctb = Game_System.prototype.is_patb;
  213. Game_System.prototype.is_patb = function() { // Hotspot
  214.     // Rewritten
  215.     return this.is_patb_ctb() || this._patb.battle_system_code === "ctb";
  216.     //
  217. }; // Game_System.prototype.is_patb
  218.  
  219. /*----------------------------------------------------------------------------
  220.  *    # New class: Window_Patb_Ctb                                            
  221.  *----------------------------------------------------------------------------*/
  222.  
  223. /*----------------------------------------------------------------------------
  224.  *    New private instance variables                                          
  225.  *----------------------------------------------------------------------------*/
  226. // _text: The cached battle system text
  227. // _textSize: The cached battle system text size
  228.  
  229. Window_Patb_Ctb.prototype = Object.create(Window_Base.prototype);
  230. Window_Patb_Ctb.prototype.constructor = Window_Patb_Ctb;
  231.  
  232. Window_Patb_Ctb.prototype.initialize = function() {
  233.     var patb = $gameSystem.patb, width = patb.battle_system_window_width;
  234.     var x = patb.battle_system_window_x, y = patb.battle_system_window_y;
  235.     var height = patb.battle_system_window_height;
  236.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  237. }; // Window_Patb_Ctb.prototype.initialize
  238.  
  239. Window_Patb_Ctb.prototype.update = function() { // v1.00b+; Hotspot
  240.     Window_Base.prototype.update.call(this);
  241.     this.visible = $gameSystem.patb.show_battle_system_window;
  242.     if (!this.visible) { return; }
  243.     this.updateXYWH();
  244.     this.updateText();
  245. }; // Window_Patb_Ctb.prototype.update
  246.  
  247. Window_Patb_Ctb.prototype.updateXYWH = function() { // v1.00b+; Hotspot
  248.     var patb = $gameSystem.patb, width = patb.battle_system_window_width;
  249.     var x = patb.battle_system_window_x, y = patb.battle_system_window_y;
  250.     var height = patb.battle_system_window_height;
  251.     if (this.x !== x) this.x = x;
  252.     if (this.y !== y) this.y = y;
  253.     if (this.width !== width) this.width = width;
  254.     if (this.height !== height) this.height = height;
  255. }; // Window_Patb_Ctb.prototype.updateXYWH
  256.  
  257. Window_Patb_Ctb.prototype.updateText = function() { // Hotspot
  258.     var patb = $gameSystem.patb, textSize = this._textSize, updateText;
  259.     var textX = this._textX, textY = this._textY;
  260.     var text = patb[patb.battle_system_code + "_battle_system_text"];
  261.     this._textSize = patb.battle_system_text_size;
  262.     this._textX = patb.battle_system_text_x;
  263.     this._textY = patb.battle_system_text_y;
  264.     updateText = this._text !== text || this._textSize !== textSize;
  265.     updateText = updateText || this._textX !== textX || this._textY !== textY;
  266.     if (!updateText) { return; }
  267.     if (this._textSize !== textSize) { this.resetFontSettings(); }
  268.     this._text = text, textX = this._textX, textY = this._textY;
  269.     this.contents.clear();
  270.     this.drawText(this._text, textX, textY, this.textWidth(this._text));
  271. }; // Window_Patb_Ctb.prototype.updateText
  272.  
  273. Window_Patb_Ctb.prototype.standardFontSize = function() { // Potential Hotspot
  274.     return this._textSize;
  275. }; // Window_Patb_Ctb.prototype.standardFontSize
  276.  
  277. /*----------------------------------------------------------------------------
  278.  *    # Edit class: Scene_Battle                                              
  279.  *----------------------------------------------------------------------------*/
  280.  
  281. /*----------------------------------------------------------------------------
  282.  *    New private instance variable                                          
  283.  *----------------------------------------------------------------------------*/
  284. // _patb_ctb_window: The battle system indicator window
  285.  
  286. Scene_Battle.prototype.createAllWindowsPatbCtb =
  287. Scene_Battle.prototype.createAllWindows;
  288. Scene_Battle.prototype.createAllWindows = function() {
  289.     this.createAllWindowsPatbCtb();
  290.     if ($gameSystem.is_patb()) { this.create_patb_ctb_window(); } // Added
  291. }; // Scene_Battle.prototype.createAllWindows
  292.  
  293. Scene_Battle.prototype.update_patb_process_ctb =
  294. Scene_Battle.prototype.update_patb_process;
  295. Scene_Battle.prototype.update_patb_process = function() { // Hotspot
  296.     this.update_patb_process_ctb();
  297.     this._patb_ctb_window.update; // Added
  298. }; // Scene_Battle.prototype.update_patb_process
  299.  
  300. Scene_Battle.prototype.close_patb_windows_ctb =
  301. Scene_Battle.prototype.close_patb_windows;
  302. Scene_Battle.prototype.close_patb_windows = function() {
  303.     this.close_patb_windows_ctb();
  304.     this.close_patb_ctb_windows(); // Added
  305. }; // Scene_Battle.prototype.close_patb_windows
  306.  
  307. Scene_Battle.prototype.create_patb_ctb_window = function() { // New
  308.     this._patb_ctb_window = new Window_Patb_Ctb();
  309.     this.addWindow(this._patb_ctb_window);
  310. }; // Scene_Battle.prototype.create_patb_ctb_window
  311.  
  312. Scene_Battle.prototype.close_patb_ctb_windows = function() { // New
  313.     this._patb_ctb_window.hide();
  314.     this._patb_ctb_window.deactivate();
  315.     this._patb_ctb_window.close();
  316. }; // Scene_Battle.prototype.close_patb_ctb_windows
  317.  
  318. /*----------------------------------------------------------------------------*/
  319.  
  320. } else {
  321.     alert("To use PATB CTB, place it below PATB Core.");
  322. }
  323.  
  324. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement