WCouillard

Battle Turn Count Display v2.00

Sep 16th, 2021 (edited)
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 12.82 KB | Gaming | 0 0
  1. var Imported = Imported || {};
  2. Imported.Coolie_BattleTurnCount = true;
  3.  
  4. var Coolie = Coolie || {};
  5. Coolie.BTW = Coolie.BTW || {};
  6. Coolie.BTW.version = 2.00;
  7.  
  8. /*:
  9.  * @plugindesc v2.00 Display a turn count window in battle
  10.  * @author Coolie (William Couillard)
  11.  *
  12.  * @help
  13.  * =============================================================================
  14.  *  ABOUT THIS PLUGIN (Coolie_BattleTurnCount)
  15.  * =============================================================================
  16.  * Adds a window to Scene_Battle that shows the current turn count.
  17.  *
  18.  * =============================================================================
  19.  *  PLUGIN PARAMETERS
  20.  * =============================================================================
  21.  * This window position is customizable through Plugin Parameters, as well as
  22.  * the text string used to represent the Turn Count.
  23.  *
  24.  * Escape codes can be used.
  25.  *
  26.  * =============================================================================
  27.  *  PLUGIN COMMANDS
  28.  * =============================================================================
  29.  *  ShowTurnCount
  30.  *
  31.  * The above Plugin Command will force the Turn Count window to open.
  32.  *
  33.  *  HideTurnCount
  34.  *
  35.  * The above Plugin Command will force the Turn Count window to close. Both
  36.  * Plugin Commands are case-insensitive and will only work during battle.
  37.  *
  38.  * =============================================================================
  39.  *  TERMS OF USE
  40.  * =============================================================================
  41.  * This plugin, 'Coolie_BattleTurnCount v2.00', is OK to use in commercial and
  42.  * non-commercial projects, free of charge.
  43.  *
  44.  * It is prohibited to redistribute this plugin, or copy JavaScript from it for
  45.  * use elsewhere.
  46.  *
  47.  * =============================================================================
  48.  *  TIPS
  49.  * =============================================================================
  50.  * - If you are using AB_EnemyBook plugin, place this plugin ABOVE it to avoid
  51.  *   a visual bug.
  52.  *
  53.  * - If you are using Nasty Replace Window With Picture plugin, the name of the
  54.  *   window to use is Window_TurnCount.
  55.  *
  56.  * =============================================================================
  57.  *  VERSION & UPDATE HISTORY
  58.  * =============================================================================
  59.  * > v2.0 : New Parameters added, Plugin Commands added, bugfixes
  60.  *   > October 6th, 2025
  61.  *
  62.  * > v1.0 : Initial Release
  63.  *   > September 16th, 2021
  64.  *
  65.  * @param General Settings
  66.  *
  67.  * @param Hide On Skill/Item
  68.  * @parent General Settings
  69.  * @type boolean
  70.  * @desc Should the turn count window close while the skill or item window is open?
  71.  * Default: true
  72.  * @default true
  73.  *
  74.  * @param Window Settings
  75.  *
  76.  * @param Window Width
  77.  * @parent Window Settings
  78.  * @type number
  79.  * @min 0
  80.  * @desc The width, in pixels, of the Turn Count Window.
  81.  * Default: 160
  82.  * @default 160
  83.  *
  84.  * @param Window X Position
  85.  * @parent Window Settings
  86.  * @type number
  87.  * @min 0
  88.  * @desc The X position, in pixels, of the Turn Count Window.
  89.  * Default: 0
  90.  * @default 0
  91.  *
  92.  * @param Window Y Position
  93.  * @parent Window Settings
  94.  * @type number
  95.  * @min 0
  96.  * @desc The Y position, in pixels, of the Turn Count Window.
  97.  * Default: 372
  98.  * @default 372
  99.  *
  100.  * @param Window Opacity
  101.  * @parent Window Settings
  102.  * @type number
  103.  * @min 0
  104.  * @max 255
  105.  * @desc The window's overall opacity (0 = fully transparent, 255 = fully opaque)
  106.  * @default 255
  107.  *
  108.  * @param Window Back Opacity
  109.  * @parent Window Settings
  110.  * @type number
  111.  * @min 0
  112.  * @max 255
  113.  * @desc The window's background opacity (0 = fully transparent, 255 = fully opaque)
  114.  * @default 192
  115.  *
  116.  * @param Use Battlelog Style
  117.  * @parent Window Settings
  118.  * @type boolean
  119.  * @desc If true, the window will use the same style as the BattleLog window (faded black bar, no frame)
  120.  * @default false
  121.  *
  122.  * @param Text Settings
  123.  *
  124.  * @param Window Text
  125.  * @parent Text Settings
  126.  * @type text
  127.  * @desc The label to show before the turn number. Escape codes can be used.
  128.  * Default: Turn
  129.  * @default Turn
  130.  */
  131.  
  132. // =============================================================================
  133. // Plugin Parameters
  134. // =============================================================================
  135. Coolie.Parameters = PluginManager.parameters('Coolie_BattleTurnCount');
  136. Coolie.Param = Coolie.Param || {};
  137.  
  138. Coolie.Param.BTWHideOnSkillItem = String(Coolie.Parameters['Hide On Skill/Item']).toLowerCase() === 'true';
  139. Coolie.Param.BTWWindowWidth = Number(Coolie.Parameters['Window Width']);
  140. Coolie.Param.BTWWindowX = Number(Coolie.Parameters['Window X Position']);
  141. Coolie.Param.BTWWindowY = Number(Coolie.Parameters['Window Y Position']);
  142. Coolie.Param.BTWWindowOpacity = Number(Coolie.Parameters['Window Opacity'] || 255);
  143. Coolie.Param.BTWWindowBackOpacity = Number(Coolie.Parameters['Window Back Opacity'] || 192);
  144. Coolie.Param.BTWUseBattleLogStyle = String(Coolie.Parameters['Use Battlelog Style']).toLowerCase() === 'true';
  145. Coolie.Param.BTWWindowText = String(Coolie.Parameters['Window Text']);
  146.  
  147. // =============================================================================
  148. // Window_TurnCount
  149. // =============================================================================
  150. function Window_TurnCount() {
  151.     this.initialize.apply(this, arguments);
  152. }
  153.  
  154. Window_TurnCount.prototype = Object.create(Window_Selectable.prototype);
  155. Window_TurnCount.prototype.constructor = Window_TurnCount;
  156.  
  157. // =============================================================================
  158. // Window_TurnCount (initialize)
  159. // =============================================================================
  160. Window_TurnCount.prototype.initialize = function() {
  161.     var x = Coolie.Param.BTWWindowX;
  162.     var y = Coolie.Param.BTWWindowY;
  163.     var width = Coolie.Param.BTWWindowWidth;
  164.     var height = this.fittingHeight(1);
  165.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  166.  
  167.     // Opacity
  168.     this.opacity = Coolie.Param.BTWWindowOpacity;
  169.     this.backOpacity = Coolie.Param.BTWWindowBackOpacity;
  170.  
  171.     // BattleLog Style
  172.     if (Coolie.Param.BTWUseBattleLogStyle) {
  173.         this.opacity = 0;
  174.         this.backOpacity = 0;
  175.         this._battleLogStyle = true;
  176.     } else {
  177.         this._battleLogStyle = false;
  178.     }
  179.  
  180.     this.refresh();
  181. };
  182.  
  183. // =============================================================================
  184. // Window_TurnCount (refresh)
  185. // =============================================================================
  186. Window_TurnCount.prototype.refresh = function() {
  187.     var x = 0;
  188.     var y = 0;
  189.     var text = Coolie.Param.BTWWindowText;
  190.     var turnNum = Math.floor($gameTroop.turnCount() + 1).toString();
  191.     this.contents.clear();
  192.     this.drawBackground();
  193.     this.drawTextEx(text + ' ' + turnNum, x + 4, y);
  194. };
  195.  
  196. // =============================================================================
  197. // Window_TurnCount (open)
  198. // =============================================================================
  199. Window_TurnCount.prototype.open = function() {
  200.     this.refresh();
  201.     Window_Selectable.prototype.open.call(this);
  202. };
  203.  
  204. // =============================================================================
  205. // Window_TurnCount (drawBackground)
  206. // =============================================================================
  207. Window_TurnCount.prototype.drawBackground = function() {
  208.     if (this._battleLogStyle) {
  209.         var rect = this.contents.rect;
  210.         var x = 0;
  211.         var y = 0;
  212.         var width = this.contentsWidth();
  213.         var height = this.contentsHeight();
  214.         this.contents.paintOpacity = 160;
  215.         this.contents.fillRect(x, y, width, height, '#000000');
  216.         this.contents.paintOpacity = 255;
  217.     }
  218. };
  219.  
  220. // =============================================================================
  221. // Scene_Battle (createAllWindows)
  222. // =============================================================================
  223. var alias_Coolie_BattleTurnCount_createAllWindows = Scene_Battle.prototype.createAllWindows;
  224. Scene_Battle.prototype.createAllWindows = function() {
  225.     alias_Coolie_BattleTurnCount_createAllWindows.call(this);
  226.     this.createTurnsWindow();
  227. };
  228.  
  229. // =============================================================================
  230. // Scene_Battle (createTurnsWindow)
  231. // =============================================================================
  232. Scene_Battle.prototype.createTurnsWindow = function() {
  233.     this._turnsWindow = new Window_TurnCount();
  234.     this.addWindow(this._turnsWindow);
  235.     this._turnsWindow.open();
  236. };
  237.  
  238. // =============================================================================
  239. // Scene_Battle (refreshTurnCount)
  240. // =============================================================================
  241. Scene_Battle.prototype.refreshTurnCount = function() {
  242.     this._turnsWindow.refresh();
  243. };
  244.  
  245. // =============================================================================
  246. // Scene_Battle (startPartyCommandSelection)
  247. // =============================================================================
  248. var alias_Coolie_BattleTurnCount_startPartyCommandSelection = Scene_Battle.prototype.startPartyCommandSelection;
  249. Scene_Battle.prototype.startPartyCommandSelection = function() {
  250.     alias_Coolie_BattleTurnCount_startPartyCommandSelection.call(this);
  251.     this.refreshTurnCount();
  252. };
  253.  
  254. // =============================================================================
  255. // Scene_Battle (terminate)
  256. // =============================================================================
  257. var alias_Coolie_BattleTurnCount_terminate = Scene_Battle.prototype.terminate;
  258. Scene_Battle.prototype.terminate = function() {
  259.     if (this._turnsWindow) this._turnsWindow.close();
  260.     alias_Coolie_BattleTurnCount_terminate.call(this);
  261. };
  262.  
  263. // =============================================================================
  264. // Scene_Battle (commandSkill)
  265. // =============================================================================
  266. var _Coolie_BTW_commandSkill = Scene_Battle.prototype.commandSkill;
  267. Scene_Battle.prototype.commandSkill = function() {
  268.     if (Coolie.Param.BTWHideOnSkillItem && this._turnsWindow) this._turnsWindow.close();
  269.     _Coolie_BTW_commandSkill.apply(this, arguments);
  270. };
  271.  
  272. // =============================================================================
  273. // Scene_Battle (commandItem)
  274. // =============================================================================
  275. var _Coolie_BTW_commandItem = Scene_Battle.prototype.commandItem;
  276. Scene_Battle.prototype.commandItem = function() {
  277.     if (Coolie.Param.BTWHideOnSkillItem && this._turnsWindow) this._turnsWindow.close();
  278.     _Coolie_BTW_commandItem.apply(this, arguments);
  279. };
  280.  
  281. // =============================================================================
  282. // Scene_Battle (onSkillCancel)
  283. // =============================================================================
  284. var _Coolie_BTW_onSkillCancel = Scene_Battle.prototype.onSkillCancel;
  285. Scene_Battle.prototype.onSkillCancel = function() {
  286.     _Coolie_BTW_onSkillCancel.apply(this, arguments);
  287.     if (Coolie.Param.BTWHideOnSkillItem && this._turnsWindow) this._turnsWindow.open();
  288. };
  289.  
  290. // =============================================================================
  291. // Scene_Battle (onItemCancel)
  292. // =============================================================================
  293. var _Coolie_BTW_onItemCancel = Scene_Battle.prototype.onItemCancel;
  294. Scene_Battle.prototype.onItemCancel = function() {
  295.     _Coolie_BTW_onItemCancel.apply(this, arguments);
  296.     if (Coolie.Param.BTWHideOnSkillItem && this._turnsWindow) this._turnsWindow.open();
  297. };
  298.  
  299. // =============================================================================
  300. // Scene_Battle (startActorCommandSelection)
  301. // =============================================================================
  302. var _Coolie_BTW_startActorCommandSelection = Scene_Battle.prototype.startActorCommandSelection;
  303. Scene_Battle.prototype.startActorCommandSelection = function() {
  304.     _Coolie_BTW_startActorCommandSelection.apply(this, arguments);
  305.     if (Coolie.Param.BTWHideOnSkillItem && this._turnsWindow) this._turnsWindow.open();
  306. };
  307.  
  308. // =============================================================================
  309. // Plugin Command: ShowTurnCount / HideTurnCount
  310. // =============================================================================
  311. var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  312. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  313.     _Game_Interpreter_pluginCommand.apply(this, arguments);
  314.     if (!SceneManager._scene || !SceneManager._scene._turnsWindow) return;
  315.     switch (command.toLowerCase()) {
  316.         case 'showturncount':
  317.             SceneManager._scene._turnsWindow.open();
  318.             break;
  319.         case 'hideturncount':
  320.             SceneManager._scene._turnsWindow.close();
  321.             break;
  322.     }
  323. };
Tags: Plugin RMMV
Advertisement
Add Comment
Please, Sign In to add comment