Advertisement
ZEkA10000

GALV_CreditRoll_MZ

Oct 4th, 2023 (edited)
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 14.50 KB | Source Code | 0 0
  1. //-----------------------------------------------------------------------------
  2. //  Galv's Roll Credits
  3. //-----------------------------------------------------------------------------
  4. //  For: RPGMAKER ~~MV~~ MZ
  5. //  GALV_RollCredits.js
  6. //-----------------------------------------------------------------------------
  7. //  2017-08-08 - Version 1.5 - fixed casing issues with file references
  8. //  2017-06-02 - Version 1.4 - fixed bug when using title screen credit option
  9. //  2017-05-01 - Version 1.3 - added code to wait for txt file to finish load
  10. //                             before running scene (in hope of fixing issue
  11. //                             some people seem to have).
  12. //  2016-09-07 - Version 1.2 - added touch to skip credit blocks
  13. //                             added music setting for title credits
  14. //  2016-09-01 - Version 1.1 - force windowskin to 0 opacity in case another
  15. //                             plugin changes that opacity
  16. //  2016-07-14 - Version 1.0 - release
  17. //-----------------------------------------------------------------------------
  18. // Terms can be found at:
  19. // galvs-scripts.com
  20. //-----------------------------------------------------------------------------
  21.  
  22. var Imported = Imported || {};
  23. Imported.Galv_RollCredits = true;
  24.  
  25. var Galv = Galv || {};            // Galv's main object
  26. Galv.CRED = Galv.CRED || {};        // Galv's stuff
  27.  
  28. //-----------------------------------------------------------------------------
  29. /*:
  30.  * @plugindesc (v.1.5) A plugin that calls a new scene to display scrolling information located in an external text file.
  31.  *
  32.  * @author Galv - galvs-scripts.com
  33.  *
  34.  * @param Folder
  35.  * @desc The folder name in your project where the Credits.txt file is located.
  36.  * @default data
  37.  *
  38.  * @param Skippable
  39.  * @desc true or false if cancel button skips all blocks and closes scene
  40.  * @default true
  41.  *
  42.  * @param Block Skipping
  43.  * @desc true or false if okay button skips current block to show next block
  44.  * @default true
  45.  *
  46.  * @param Title Menu
  47.  * @desc Text that appears in the title menu. Make blank to not show in title menu.
  48.  * @default Credits
  49.  *
  50.  * @param Title Credits Music
  51.  * @desc Music that plays when the credits are run from the title scene
  52.  * @default
  53.  *
  54.  *
  55.  * @help
  56.  *   Galv's Roll Credits
  57.  * ----------------------------------------------------------------------------
  58.  * This plugin uses external text files to control what text is displayed when
  59.  * calling a "Roll Credits" style scene. This text file contains tags to set
  60.  * how text blocks will display (eg. scroll or fade in/out).
  61.  *
  62.  * REQUIRED TAGS:
  63.  * Text must be placed inside the following tag and you can have multiple of
  64.  * these tages in the same .txt file to make each block of text display in
  65.  * a different way.
  66.  *
  67.  *     <block:time,scroll,fadeIn,fadeOut,ypos,align,image>
  68.  *     your text here
  69.  *     </block>
  70.  *
  71.  * time    = amount of time text within tag is displayed before the next tag.
  72.  *           this can be -1 for auto
  73.  * scroll  = how fast the text scrolls. negative for up, positive for down
  74.  * fadeIn  = how fast the tag text fades in (make this 255 to instant appear)
  75.  * fadeOut = how fast the tag text fades out (255 to instant disappear)
  76.  * ypos    = the starting y position of the block of text on screen. This can
  77.  *           be a pixel value or you can use offtop or offbot to have the text
  78.  *           begind offscreen (so you can scroll it on)
  79.  * align   = left,center or right
  80.  * image   = image name in /img/titles1/ folder to use as background. Leave
  81.  *           this out to use the previous image.
  82.  * ----------------------------------------------------------------------------
  83.  *  SCRIPT CALL
  84.  * ----------------------------------------------------------------------------
  85.  *
  86.  *    Galv.CRED.start("filename");    // filename of .txt file located in the
  87.  *                                    // folder you chose in the settings
  88.  *                                    // if no filename specified or if run
  89.  *                                    // directly using SceneManager.push,
  90.  *                                    // then it will use "Credits.txt"
  91.  *
  92.  * ----------------------------------------------------------------------------
  93.  * NOTE: For other scripts, the credit scene is called:
  94.  * Scene_Credits
  95.  * ----------------------------------------------------------------------------
  96.  */
  97.  
  98. //-----------------------------------------------------------------------------
  99. //  CODE STUFFS
  100. //-----------------------------------------------------------------------------
  101.  
  102. (function() {
  103.  
  104.  
  105. Galv.CRED.skippable = PluginManager.parameters('Galv_RollCredits')["Skippable"].toLowerCase() == 'true' ? true : false;
  106. Galv.CRED.bSkip = PluginManager.parameters('Galv_RollCredits')["Block Skipping"].toLowerCase() == 'true' ? true : false;
  107. Galv.CRED.titleText = PluginManager.parameters('Galv_RollCredits')["Title Menu"];
  108. Galv.CRED.bgm = {name:PluginManager.parameters('Galv_RollCredits')["Title Credits Music"],pan:0,pitch:100,volume:90};
  109.  
  110.  
  111.  
  112. // GET TXT FILE
  113. //-----------------------------------------------------------------------------
  114.  
  115. Galv.CRED.file = {};
  116. Galv.CRED.file.getString = function(filePath) {
  117.     var request = new XMLHttpRequest();
  118.     request.open("GET", filePath);
  119.     request.overrideMimeType('application/json');
  120.     request.onload = function() {
  121.         if (request.status < 400) {
  122.             Galv.CRED.createCreds(request.responseText);
  123.         }
  124.     };
  125.     request.send();
  126. };
  127.  
  128. Galv.CRED.createCreds = function(string) {
  129.     var lines = string.split("\n");
  130.     var bIndex = 0;
  131.     var record = false;
  132.     Galv.CRED.txtArray = [];
  133.  
  134.     for (var i = 0; i < lines.length; i++) {
  135.         if (lines[i].contains('</block>')) {
  136.             record = false;
  137.             bIndex += 1;
  138.         } else if (lines[i].contains('<block:')) {
  139.             Galv.CRED.txtArray[bIndex] = [];
  140.             record = true;
  141.         };
  142.  
  143.         if (record) Galv.CRED.txtArray[bIndex].push(lines[i]);
  144.     };
  145. };
  146.  
  147.  
  148. Galv.CRED.start = function(filename) {
  149.     Galv.CRED.tempFilename = filename;
  150.     Galv.CRED.fileName();
  151.     SceneManager.push(Scene_Credits);
  152. };
  153.  
  154. Galv.CRED.fileName = function() {
  155.     //if (!Galv.CRED.txtArray) {
  156.         var filename = Galv.CRED.tempFilename || "Credits";
  157.         var folder = PluginManager.parameters('Galv_RollCredits')["Folder"];
  158.         if (folder !== "") folder = folder + "/";
  159.         Galv.CRED.file.getString(folder + filename + ".txt");
  160.     //};
  161.  
  162. };
  163.  
  164. })();
  165.  
  166.  
  167.  
  168. // WINDOW CREDITS
  169. //-----------------------------------------------------------------------------
  170.  
  171. function Window_Credits() {
  172.     this.initialize.apply(this, arguments);
  173. }
  174.  
  175. Window_Credits.prototype = Object.create(Window_Base.prototype);
  176. Window_Credits.prototype.constructor = Window_Credits;
  177.  
  178. Window_Credits.prototype.initialize = function(blockId) {
  179.     var width = Graphics.width;
  180.     var height = Graphics.boxHeight;
  181.     Window_Base.prototype.initialize.call(this, new Rectangle(0, 0, width, height));
  182.     this.contents.fil
  183.     this._id = blockId;
  184.     this.createVars();
  185.     this.refresh();
  186.    
  187. };
  188.  
  189. Window_Credits.prototype.txt = function() {
  190.     return Galv.CRED.txtArray[this._id];
  191. };
  192.  
  193. Window_Credits.prototype.createVars = function() {
  194.     this._textArray = this.txt();
  195.     this._complete = false;
  196.     this.opacity = 0;
  197.     this.contentsOpacity = 0;
  198.  
  199.     // settings
  200.     var txt = this.txt() || ' ';
  201.     var a = txt[0].toLowerCase().match(/<block:(.*)>/i);
  202.     a = a[1].split(",");
  203.     if (!a) return;
  204.     this._timer = Number(a[0]);
  205.     this._scroll = Number(a[1]) * 0.5;
  206.     this._fadeIn = Number(a[2]);
  207.     this._fadeOut = Number(a[3]);
  208.     var isNumber = Number(a[4]);
  209.     if (isNumber) {
  210.         this.y = Number(a[4]);
  211.         this._ypos = "";
  212.     } else {
  213.         this._ypos = a[4] || "";
  214.     };
  215.     this._align = a[5] || "left";
  216.     // 6 is image
  217. };
  218.  
  219. Window_Credits.prototype.update = function() {
  220.     Window_Base.prototype.update.call(this);
  221.     this.opacity = 0;
  222.     if (this._timer > 0) { // timer active
  223.         this.contentsOpacity += this._fadeIn;
  224.         this._timer -= 1;
  225.     } else { // timer ends
  226.         this.contentsOpacity -= this._fadeOut;
  227.         if (this.contentsOpacity <= 0) this._complete = true;
  228.     };
  229.     this.y += this._scroll;
  230. };
  231.  
  232. Window_Credits.prototype.refresh = function() {
  233.     this._allTextHeight = 1;
  234.     // Draw all lines
  235.     for (var i = 1; i < this._textArray.length;i++) {
  236.         var textState = { index: 0 };
  237.         textState.text = this.convertEscapeCharacters(this._textArray[i]);
  238.         this.resetFontSettings();
  239.         this._allTextHeight += this.calcTextHeight(textState, false);
  240.     };
  241.    
  242.     // window height
  243.     this.height = this.contentsHeight() + this._padding * 2;
  244.     this.createContents();
  245.    
  246.     if (this._ypos.contains('offbot')) {
  247.         this.y = Graphics.height;
  248.     } else if (this._ypos.contains('offtop')) {
  249.         this.y = -height;
  250.     };
  251.    
  252.     // Set auto timer if -1 (auto)
  253.     if (this._timer < 0) {
  254.         if (this._scroll == 0) {
  255.             this._timer = 2 * this._allTextHeight; // set timer depending on amount of text
  256.         } else if (this._scroll < 0) {
  257.             // calc how many frames it will take for message to leave screen
  258.             var distance = Math.abs(this.y) + this.height;
  259.             this._timer = distance / Math.abs(this._scroll);
  260.         } else if (this._scroll > 0) {
  261.             // calc how many frames it will take for message to leave screen
  262.             //var distance = Math.abs(this.y);
  263.             //this._timer = distance / this._scroll;
  264.         };
  265.     };
  266.    
  267.     // Draw lines
  268.     var cy = 0;
  269.     for (var i = 1; i < this._textArray.length;i++) {
  270.         var textState = {index:0,text:this._textArray[i]};
  271.         var x = this._padding;
  272.         var w = this.testWidthEx(textState.text);
  273.         var h = this.cTextHeight;
  274.  
  275.        
  276.         if (this._align == 'center') {
  277.             x = this.contents.width / 2 - w / 2;
  278.         } else if (this._align == 'right') {
  279.             x = this.contents.width - this._padding - w;
  280.         };     
  281.         this.drawTextEx(textState.text, x, cy);
  282.         cy += h;
  283.     };
  284.    
  285.     this._allTextHeight = cy;
  286.     this.height = cy + this._padding * 2;
  287. };
  288.  
  289. Window_Credits.prototype.testWidthEx = function(text) {
  290.     return this.drawTextExTest(text, 0, this.contents.height);
  291. };
  292.  
  293. Window_Credits.prototype.drawTextExTest = function(text, x, y) {
  294.     this.testActive = false;
  295.     if (text) {
  296.         this.resetFontSettings();
  297.         this.testActive = true;
  298.         var textState = { index: 0, x: x, y: y, left: x };
  299.         textState.text = this.convertEscapeCharacters(text);
  300.         textState.height = this.calcTextHeight(textState, false);
  301.         this.cTextHeight = textState.height;
  302.         while (textState.index < textState.text.length) {
  303.             this.processCharacter(textState);
  304.         }
  305.         this.testActive = false;
  306.         return textState.x - x - 116;
  307.     } else {
  308.         return 0;
  309.     }
  310. };
  311.  
  312.  
  313. Window_Credits.prototype.contentsHeight = function() {
  314.     return Math.max(this._allTextHeight, 1);
  315. };
  316.  
  317.  
  318. // SCENE CREDITS
  319. //-----------------------------------------------------------------------------
  320.  
  321. function Scene_Credits() {
  322.     this.initialize.apply(this, arguments);
  323. }
  324.  
  325. Scene_Credits.prototype = Object.create(Scene_MenuBase.prototype);
  326. Scene_Credits.prototype.constructor = Scene_Credits;
  327.  
  328. Scene_Credits.prototype.initialize = function() {
  329.     this._blockId = 0;
  330.     //this._blocks = [];
  331.     this._txtLoaded = false;
  332.     this._bgs = [];
  333.     Scene_MenuBase.prototype.initialize.call(this);
  334. };
  335.  
  336. Scene_Credits.prototype.create = function() {
  337.     Scene_Base.prototype.create.call(this);
  338.     this.createBackground();
  339.     //this.createBlock();
  340. };
  341.  
  342. Scene_Credits.prototype.isReady = function() {
  343.     if (Scene_Base.prototype.isReady.call(this)) {
  344.         return Galv.CRED.txtArray;// && this._blocks[0];
  345.     } else {
  346.         return false;
  347.     }
  348. };
  349.  
  350. Scene_Credits.prototype.update = function() {
  351.     Scene_Base.prototype.update.call(this);
  352.     this.updateInput();
  353.     this.updateBlocks();
  354. };
  355.  
  356. Scene_Credits.prototype.updateInput = function() {
  357.     if (Input.isTriggered('cancel') && Galv.CRED.skippable) {
  358.         this.endScene();
  359.     } else if ((TouchInput.isPressed() || Input.isTriggered('ok')) && Galv.CRED.bSkip) {
  360.         if (this._blocks && this._blocks[this._blockId]) this._blocks[this._blockId]._timer = 0;
  361.     };
  362. };
  363.  
  364. Scene_Credits.prototype.updateBlocks = function() {
  365.  
  366.     if (!this._txtLoaded) {
  367.         // wait for load
  368.         if (Galv.CRED.txtArray) {
  369.             this._txtLoaded = true;
  370.             this._blocks = [];
  371.             this.createBlock();
  372.         }
  373.     } else {
  374.         // loaded, update as normal
  375.         // If CURRENT block timer is up, create next block
  376.         if (!Galv.CRED.txtArray[this._blockId]) {
  377.             this.endScene();
  378.             return;
  379.         }
  380.    
  381.         if (this._blocks[this._blockId]._complete) {
  382.             // If block is finished, remove window and continue to next
  383.             this.removeChild(this._blocks[this._blockId]);
  384.             this._blockId += 1;
  385.             if (Galv.CRED.txtArray[this._blockId]) {
  386.                 this.createBlock();
  387.             }
  388.         }
  389.     }
  390. };
  391.  
  392. Scene_Credits.prototype.createBlock = function() { 
  393.     if (Galv.CRED.txtArray[this._blockId]) {
  394.         var arr = Galv.CRED.txtArray[this._blockId][0].match(/<block:(.*)>/i);
  395.         arr = arr[1].split(",");
  396.         if (arr[6]) {
  397.             var id = this._bgs.length;
  398.             this._bgs[id] = new Sprite_CredBg(arr[6],this._blockId);
  399.             this.addChild(this._bgs[id]);
  400.         };
  401.     };
  402.    
  403.     this._blocks[this._blockId] = new Window_Credits(this._blockId);
  404.     this.addChild(this._blocks[this._blockId]);
  405. };
  406.  
  407.  
  408. Scene_Credits.prototype.endScene = function() {
  409.     Galv.CRED.tempFilename = null;
  410.     SceneManager.pop();
  411. };
  412.  
  413.  
  414.  
  415. // SPRITE CREDBG
  416. //-----------------------------------------------------------------------------
  417.  
  418. function Sprite_CredBg() {
  419.     this.initialize.apply(this, arguments);
  420. }
  421.  
  422. Sprite_CredBg.prototype = Object.create(Sprite.prototype);
  423. Sprite_CredBg.prototype.constructor = Sprite_CredBg;
  424.  
  425. Sprite_CredBg.prototype.initialize = function(image,id) {
  426.     Sprite.prototype.initialize.call(this);
  427.     this._id = id;
  428.     this.createBitmap(image);
  429.     this.update();
  430. };
  431.  
  432. Sprite_CredBg.prototype.createBitmap = function(image) {
  433.     this.bitmap = ImageManager.loadTitle1(image);
  434.     this.opacity = 0;
  435. };
  436.  
  437. Sprite_CredBg.prototype.update = function() {
  438.     Sprite.prototype.update.call(this);
  439.     this.opacity += 5;
  440. };
  441.  
  442.  
  443. // ADD TO TITLE
  444.  
  445. Scene_Title.prototype.commandCredits = function() {
  446.     this._commandWindow.close();
  447.     Galv.CRED.start('Credits');
  448.     AudioManager.playBgm(Galv.CRED.bgm);
  449. };
  450.  
  451. if (Galv.CRED.titleText != "") {
  452.     Galv.CRED.Scene_Title_createCommandWindow = Scene_Title.prototype.createCommandWindow;
  453.     Scene_Title.prototype.createCommandWindow = function() {
  454.         Galv.CRED.Scene_Title_createCommandWindow.call(this);
  455.         this._commandWindow.setHandler('credits',  this.commandCredits.bind(this));
  456.     };
  457.    
  458.     Galv.CRED.Window_TitleCommand_makeCommandList = Window_TitleCommand.prototype.makeCommandList;
  459.     Window_TitleCommand.prototype.makeCommandList = function() {
  460.         Galv.CRED.Window_TitleCommand_makeCommandList.call(this);
  461.         this.addCommand(Galv.CRED.titleText,   'credits');
  462.     };
  463. }
Tags: RPG Maker MZ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement