Advertisement
Double_X

DoubleX RMMV Popularized ATB Clock v101a

Jan 24th, 2016 (edited)
708
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 Clock
  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/hEjUyYnY
  22.  *      Video:
  23.  *      1. https://www.youtube.com/watch?v=l9-IX16T9Gg
  24.  *      Mentioned Patreon Supporters:
  25.  *      https://www.patreon.com/posts/71738797
  26.  *----------------------------------------------------------------------------
  27.  *    # Author
  28.  *      DoubleX
  29.  *----------------------------------------------------------------------------
  30.  *    # Changelog
  31.  *      v1.01a(GMT 1200 25-3-2022):
  32.  *      1. Added the following parameters:
  33.  *         - turn_clock_bar_x
  34.  *         - turn_clock_bar_y
  35.  *         - turn_clock_bar_width
  36.  *         - turn_clock_bar_height
  37.  *         - turn_clock_bar_back_color
  38.  *         - turn_clock_bar_color1
  39.  *         - turn_clock_bar_color2
  40.  *      v1.00b(GMT 0400 3-7-2016):
  41.  *      1. Fixed below configuration changes not taking place in same battle:
  42.  *         - turn_clock_window_x
  43.  *         - turn_clock_window_y
  44.  *         - turn_clock_window_width
  45.  *         - turn_clock_window_height
  46.  *         - turn_clock_text_size
  47.  *         - turn_clock_text_x
  48.  *         - turn_clock_text_y
  49.  *      2. Increased this plugin's effectiveness, efficiency and flexibility
  50.  *      v1.00a(GMT 1000 24-1-2016):
  51.  *      1. 1st completed version of this plugin finished
  52.  *============================================================================*/
  53. /*:
  54.  * @plugindesc Lets users show the battle turn clock, unit and count in battle
  55.  * @author DoubleX
  56.  *
  57.  * @param show_turn_clock_window
  58.  * @desc Setups a window in battle showing the battle turn clock, unit and
  59.  *       count if show_turn_clock_window is set as true
  60.  * @default true
  61.  *
  62.  * @param turn_clock_window_x
  63.  * @desc Sets the x position of the battle turn clock window as
  64.  *       turn_clock_window_x
  65.  * @default 0
  66.  *
  67.  * @param turn_clock_window_y
  68.  * @desc Sets the y position of the battle turn clock window as
  69.  *       turn_clock_window_y
  70.  * @default 168
  71.  *
  72.  * @param turn_clock_window_width
  73.  * @desc Sets the width of the battle turn clock window as
  74.  *       turn_clock_window_width
  75.  * @default 400
  76.  *
  77.  * @param turn_clock_window_height
  78.  * @desc Sets the height of the battle turn clock window as
  79.  *       turn_clock_window_height
  80.  * @default 60
  81.  *
  82.  * @param turn_clock_text_size
  83.  * @desc Sets the size of the text shown in the battle turn clock window as
  84.  *       turn_clock_text_size
  85.  * @default 20
  86.  *
  87.  * @param turn_clock_text_x
  88.  * @desc Sets the x position of the text shown in the battle turn clock window
  89.  *       as turn_clock_text_x
  90.  * @default 0
  91.  *
  92.  * @param turn_clock_text_y
  93.  * @desc Sets the y position of the text shown in the battle turn clock window
  94.  *       as turn_clock_text_x
  95.  * @default -8
  96.  *
  97.  * @param turn_clock_text_act
  98.  * @desc Sets the text showing that the clock unit's action as
  99.  *       turn_clock_text_act
  100.  * @default Action
  101.  *
  102.  * @param turn_clock_text_sec
  103.  * @desc Sets the text showing that the clock unit's second as
  104.  *       turn_clock_text_sec
  105.  * @default Frame
  106.  *
  107.  * @param turn_clock_text_unavailable
  108.  * @desc Sets the text showing that the clock unit's unavailable as
  109.  *       turn_clock_text_unavailable
  110.  * @default Stopped
  111.  *
  112.  * @param turn_clock_bar_x
  113.  * @desc (v1.01a+)Sets the x offset of the turn clock bar as turn_clock_bar_x
  114.  * @default 0
  115.  *
  116.  * @param turn_clock_bar_y
  117.  * @desc (v1.01a+)Sets the y offset of the turn clock bar as turn_clock_bar_y
  118.  * @default 0
  119.  *
  120.  * @param turn_clock_bar_width
  121.  * @desc (v1.01a+)Sets the width of the turn clock bar as turn_clock_bar_width
  122.  * @default 360
  123.  *
  124.  * @param turn_clock_bar_height
  125.  * @desc (v1.01a+)Sets the height of the turn clock bar as turn_clock_bar_height
  126.  * @default 54
  127.  *
  128.  * @param turn_clock_bar_back_color
  129.  * @desc (v1.01a+)Sets the color of the turn clock back bar as
  130.  *       turn_clock_bar_back_color
  131.  *       turn_clock_bar_back_color must return a valid text color code
  132.  * @default 15
  133.  *
  134.  * @param turn_clock_bar_color1
  135.  * @desc (v1.01a+)Sets the 1st color of the turn clock bar as
  136.  *       turn_clock_bar_color1
  137.  *       turn_clock_bar_color1 must return a valid text color code
  138.  * @default 7
  139.  *
  140.  * @param turn_clock_bar_color2
  141.  * @desc (v1.01a+)Sets the 2nd color of the turn clock bar as
  142.  *       turn_clock_bar_color2
  143.  *       turn_clock_bar_color2 must return a valid text color code
  144.  * @default 8
  145.  *
  146.  * @help
  147.  * The battle turn clock text will be hardcoded in the below format:
  148.  * Turn Turn Count : Current Clock / Max Clock Unit
  149.  * The default plugin file name is DoubleX RMMV Popularized ATB Clock v101a
  150.  * If you want to change that, you must edit the value of
  151.  * DoubleX_RMMV.PATB_Clock_File, which must be done via opening the plugin js
  152.  * file directly
  153.  *============================================================================
  154.  *    ## Plugin Call Info
  155.  *----------------------------------------------------------------------------
  156.  *    # Configuration manipulations
  157.  *      1. $gameSystem.patb.param
  158.  *         - Returns the value of param listed in the plugin manager
  159.  *      2. $gameSystem.patb.param = val
  160.  *         - Sets the value of param listed in the plugin manager as val
  161.  *         - All $gameSystem.patb.param changes will be saved
  162.  *============================================================================
  163.  */
  164.  
  165. "use strict";
  166. var DoubleX_RMMV = DoubleX_RMMV || {};
  167. DoubleX_RMMV["PATB Clock"] = "v1.01a";
  168.  
  169. // The plugin file name must be the same as DoubleX_RMMV.PATB_Clock_File
  170. DoubleX_RMMV.PATB_Clock_File = "DoubleX RMMV Popularized ATB Clock v101a";
  171.  
  172. /*============================================================================
  173.  *    ## Plugin Implementations
  174.  *       You need not edit this part as it's about how this plugin works
  175.  *----------------------------------------------------------------------------
  176.  *    # Plugin Support Info:
  177.  *      1. Prerequisites
  178.  *         - Basic knowledge of this plugin on the user level, the default
  179.  *           battle system implementations and the atb system concepts
  180.  *         - Some Javascript coding proficiency to fully comprehend this
  181.  *           plugin
  182.  *      2. Function documentation
  183.  *         - The 1st part describes why this function's rewritten/extended for
  184.  *           rewritten/extended functions or what the function does for new
  185.  *           functions
  186.  *         - The 2nd part describes what the arguments of the function are
  187.  *         - The 3rd part informs which version rewritten, extended or created
  188.  *           this function
  189.  *         - The 4th part informs whether the function's rewritten or new
  190.  *         - The 5th part informs whether the function's a real or potential
  191.  *           hotspot
  192.  *         - The 6th part describes how this function works for new functions
  193.  *           only, and describes the parts added, removed or rewritten for
  194.  *           rewritten or extended functions only
  195.  *         Example:
  196.  * /*----------------------------------------------------------------------
  197.  *  *    Why rewrite/extended/What this function does
  198.  *  *----------------------------------------------------------------------*/
  199. /* // arguments: What these arguments are
  200.  * function_name = function(arguments) { // Version X+; Rewrite/New; Hotspot
  201.  *     // Added/Removed/Rewritten to do something/How this function works
  202.  *     function_name_code;
  203.  *     //
  204.  * } // function_name
  205.  *----------------------------------------------------------------------------*/
  206.  
  207. function Window_Patb_Clock() { this.initialize.apply(this, arguments); }
  208.  
  209. if (DoubleX_RMMV["PATB Core"]) {
  210.  
  211. /*----------------------------------------------------------------------------*/
  212.  
  213. /*----------------------------------------------------------------------------
  214.  *    # Edit class: Game_System
  215.  *      - Stores the values of all configurations listed in the plugin manager
  216.  *----------------------------------------------------------------------------*/
  217.  
  218. Game_System.prototype.init_patb_clock_params =
  219. Game_System.prototype.init_patb_params;
  220. Game_System.prototype.init_patb_params = function() {
  221.     this.init_patb_clock_params();
  222.     // Added
  223.     var val, ps = PluginManager.parameters(DoubleX_RMMV.PATB_Clock_File);
  224.     Object.keys(ps).forEach(function(param) {
  225.         val = +ps[param];
  226.         this._patb[param] = isNaN(val) ? ps[param] : val;
  227.     }, this);
  228.     this._patb.show_turn_clock_window = ps.show_turn_clock_window === "true";
  229.     //
  230. }; // Game_System.prototype.init_patb_params
  231.  
  232. Game_System.prototype.is_patb_clock_unit = function() { // New; Hotspot
  233.     var unit = this._patb.turn_unit_code;
  234.     return unit === "act" || unit === "sec";
  235. }; // Game_System.prototype.is_patb_clock_unit
  236.  
  237. /*----------------------------------------------------------------------------
  238.  *    # New class: Window_Patb_Clock
  239.  *----------------------------------------------------------------------------*/
  240.  
  241. /*----------------------------------------------------------------------------
  242.  *    New private instance variables
  243.  *----------------------------------------------------------------------------*/
  244. // _text: The cached battle turn clock text
  245. // _textSize: The cached battle system clock text size
  246. // _textX: The cached battle system clock text x offset
  247. // _textY: The cached battle system clock text y offset
  248. // (v1.01a+) _barX: The cached battle system clock bar x offset
  249. // (v1.01a+) _barY: The cached battle system clock bar y offset
  250. // (v1.01a+) _barW: The cached battle system clock bar width
  251. // (v1.01a+) _barH: The cached battle system clock bar height
  252. // (v1.01a+) _backColor: The cached battle system clock back bar color
  253. // (v1.01a+) _barColor1: The cached battle system clock bar 1st color
  254. // (v1.01a+) _barColor2: The cached battle system clock bar 2nd color
  255.  
  256. Window_Patb_Clock.prototype = Object.create(Window_Base.prototype);
  257. Window_Patb_Clock.prototype.constructor = Window_Patb_Clock;
  258.  
  259. Window_Patb_Clock.prototype.initialize = function() {
  260.     var patb = $gameSystem.patb, x = patb.turn_clock_window_x;
  261.     var y = patb.turn_clock_window_y, width = patb.turn_clock_window_width;
  262.     var height = patb.turn_clock_window_height;
  263.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  264. }; // Window_Patb_Clock.prototype.initialize
  265.  
  266. Window_Patb_Clock.prototype.update = function() { // v1.00b+; Hotspot
  267.     Window_Base.prototype.update.call(this);
  268.     this.visible = $gameSystem.patb.show_turn_clock_window;
  269.     if (!this.visible) { return; }
  270.     this.updateXYWH();
  271.     this.updateBarText();
  272. }; // Window_Patb_Clock.prototype.update
  273.  
  274. Window_Patb_Clock.prototype.updateXYWH = function() { // v1.00b+; Hotspot
  275.     var patb = $gameSystem.patb, width = patb.turn_clock_window_width;
  276.     var x = patb.turn_clock_window_x, y = patb.turn_clock_window_y;
  277.     var height = patb.turn_clock_window_height;
  278.     if (this.x !== x) { this.x = x; }
  279.     if (this.y !== y) { this.y = y; }
  280.     if (this.width !== width) { this.width = width; }
  281.     if (this.height !== height) { this.height = height; }
  282. }; // Window_Patb_Clock.prototype.updateXYWH
  283.  
  284. Window_Patb_Clock.prototype.updateBarText = function() { // v1.01a+; Hotspot
  285.     var x = this._barX, y = this._barY, w = this._barW, h = this._barH;
  286.     var backColor = this._barBackColor;
  287.     var color1 = this._barColor1, color2 = this._barColor2, text = this._text;
  288.     var textSize = this._textSize, textX = this._textX, textY = this._textY;
  289.     this.updateCache();
  290.     var updateText = x !== this._barX || y !== this._barY || w !== this._barW;
  291.     updateText = updateText || h !== this._barH || color1 !== this._barColor1;
  292.     updateText = updateText || color2 !== this._barColor2;
  293.     updateText = updateText || backColor !== this._barBackColor;
  294.     var isUpdateTextSize = textSize !== this._textSize;
  295.     updateText = updateText || text !== this._text || isUpdateTextSize;
  296.     updateText = updateText || textX !== this._textX || textY !== this._textY;
  297.     if (!updateText) { return; }
  298.     if (isUpdateTextSize) { this.resetFontSettings(); }
  299.     this.redrawBarText();
  300. }; // Window_Patb_Clock.prototype.updateBarText
  301.  
  302. Window_Patb_Clock.prototype.updateCache = function() { // v1.01a+; Hotspot
  303.     var patb = $gameSystem.patb;
  304.     this._barX = patb.turn_clock_bar_x, this._barY = patb.turn_clock_bar_y;
  305.     this._barW = patb.turn_clock_bar_width;
  306.     this._barH = patb.turn_clock_bar_height;
  307.     this._barBackColor = patb.turn_clock_bar_back_color;
  308.     this._barColor1 = patb.turn_clock_bar_color1;
  309.     this._barColor2 = patb.turn_clock_bar_color2;
  310.     this._text = this.setText(), this._textSize = patb.turn_clock_text_size;
  311.     this._textX = patb.turn_clock_text_x, this._textY = patb.turn_clock_text_y;
  312. }; // Window_Patb_Clock.prototype.updateCache
  313.  
  314. Window_Patb_Clock.prototype.setText = function() { // Hotspot
  315.     var text = "Turn " + $gameTroop.turnCount() + " : ";
  316.     var patb = $gameSystem.patb;
  317.     if ($gameSystem.is_patb_clock_unit()) {
  318.         var unit = patb.turn_unit_code;
  319.         text += BattleManager.patb_turn_clock[unit] + " / ";
  320.         text += $gameSystem.max_patb_turn_unit(unit) + " ";
  321.         return text + patb["turn_clock_text_" + unit];
  322.     }
  323.     return text + patb.turn_clock_text_unavailable;
  324. }; // Window_Patb_Clock.prototype.setText
  325.  
  326. Window_Patb_Clock.prototype.redrawBarText = function() { // v1.01a+; Hotspot
  327.     this.contents.clear();
  328.     var x = this._barX, y = this._barY, w = this._barW, h = this._barH;
  329.     this.contents.fillRect(x, y, w, h, this.textColor(this._barBackColor));
  330.     if ($gameSystem.is_patb_clock_unit()) {
  331.         var unit = $gameSystem.patb.turn_unit_code;
  332.         var current = BattleManager.patb_turn_clock[unit];
  333.         var fillW = w * current * 1.0 / $gameSystem.max_patb_turn_unit(unit);
  334.         var color1 = this.textColor(this._barColor1);
  335.         var color2 = this.textColor(this._barColor2);
  336.         this.contents.gradientFillRect(x, y, fillW, h, color1, color2);
  337.     }
  338.     var textW = this.textWidth(this._text);
  339.     this.drawText(this._text, this._textX, this._textY, textW);
  340. }; // Window_Patb_Clock.prototype.redrawBarText
  341.  
  342. Window_Patb_Clock.prototype.standardFontSize = function() { // Potential Hotspot
  343.     return this._textSize;
  344. }; // Window_Patb_Clock.prototype.standardFontSize
  345.  
  346. /*----------------------------------------------------------------------------
  347.  *    # Edit class: Scene_Battle
  348.  *----------------------------------------------------------------------------*/
  349.  
  350. /*----------------------------------------------------------------------------
  351.  *    New private instance variable
  352.  *----------------------------------------------------------------------------*/
  353. // _patb_clock_window: The battle turn clock window
  354.  
  355. Scene_Battle.prototype.createAllWindowsPatbClock =
  356. Scene_Battle.prototype.createAllWindows;
  357. Scene_Battle.prototype.createAllWindows = function() {
  358.     this.createAllWindowsPatbClock();
  359.     if ($gameSystem.is_patb()) { this.create_patb_clock_window(); } // Added
  360. }; // Scene_Battle.prototype.createAllWindows
  361.  
  362. Scene_Battle.prototype.update_patb_process_clock =
  363. Scene_Battle.prototype.update_patb_process;
  364. Scene_Battle.prototype.update_patb_process = function() { // Hotspot
  365.     this.update_patb_process_clock();
  366.     this._patb_clock_window.update(); // Added
  367. }; // Scene_Battle.prototype.update_patb_process
  368.  
  369. Scene_Battle.prototype.close_patb_windows_clock =
  370. Scene_Battle.prototype.close_patb_windows;
  371. Scene_Battle.prototype.close_patb_windows = function() {
  372.     this.close_patb_windows_clock();
  373.     this.close_patb_clock_windows(); // Added
  374. }; // Scene_Battle.prototype.close_patb_windows
  375.  
  376. Scene_Battle.prototype.create_patb_clock_window = function() { // New
  377.     this._patb_clock_window = new Window_Patb_Clock();
  378.     this.addWindow(this._patb_clock_window);
  379. }; // Scene_Battle.prototype.create_patb_clock_window
  380.  
  381. Scene_Battle.prototype.close_patb_clock_windows = function() { // New
  382.     this._patb_clock_window.hide();
  383.     this._patb_clock_window.deactivate();
  384.     this._patb_clock_window.close();
  385. }; // Scene_Battle.prototype.close_patb_clock_windows
  386.  
  387. /*----------------------------------------------------------------------------*/
  388.  
  389. } else {
  390.     alert("To use PATB Clock, place it below PATB Core.");
  391. }
  392.  
  393. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement