Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2. -------------------------------------------------------------------------
  3. @title HMS: Message Pause Cursor
  4. @author Hime --> HimeWorks (http://himeworks.com)
  5. @version 1.2
  6. @date Dec 21, 2015
  7. @filename HIME_HMSMessagePauseCursor.js
  8. @url http://himeworks.com/2015/12/message-pause-cursor/
  9.  
  10. If you enjoy my work, consider supporting me on Patreon!
  11.  
  12. * https://www.patreon.com/himeworks
  13.  
  14. If you have any questions or concerns, you can contact me at any of
  15. the following sites:
  16.  
  17. * Main Website: http://himeworks.com
  18. * Facebook: https://www.facebook.com/himeworkscom/
  19. * Twitter: https://twitter.com/HimeWorks
  20. * Youtube: https://www.youtube.com/c/HimeWorks
  21. * Tumblr: http://himeworks.tumblr.com/
  22.  
  23. -------------------------------------------------------------------------------
  24. @plugindesc v1.2 - Allows you to customize your message pause cursor.
  25. @help
  26. -------------------------------------------------------------------------------
  27. == Description ==
  28.  
  29. By default, when a message has finished displaying all of the words and is
  30. waiting for player input, a little animated cursor is shown to indicate that
  31. the player should press the confirm button to proceed.
  32.  
  33. However, this cursor is stored inside the windowskin, which gives you enough
  34. freedom to have one 24x24 cursor with 4 frames of animation. You also cannot
  35. choose where the cursor should appear, or how fast it should animate.
  36.  
  37. With this plugin, you are given more control over that pause cursor.
  38.  
  39. You can change how it looks!
  40. You can change where it's positioned!
  41. You can change how fast it animates!
  42.  
  43. What kind of cursor will you create?
  44.  
  45. == Terms of Use ==
  46.  
  47. - Free for use in non-commercial projects with credits
  48. - Contact me for commercial use
  49.  
  50. == Change Log ==
  51.  
  52. 1.2 - Dec 21, 2015
  53.  * renamed to HMSMessagePauseCursor
  54.  * added support for 'end' text align
  55. 1.1 - Dec 15, 2015
  56.  * use "Default Align" plugin parameter
  57. 1.0 - Dec 14, 2015
  58.  * initial release
  59.  
  60. == Usage ==
  61.  
  62. Create an image called "MessagePauseCursor" and save it in the img/system
  63. folder of your project.
  64.  
  65. This image is broken down into a grid.
  66.  
  67. Each row represents a single cursor.
  68. Each column represents an animation frame for that cursor.
  69.  
  70. Each frame can be of any width or height, but all frames must have the
  71. same width and height.
  72.  
  73. You can have any number of frames per cursor, but all cursors must have
  74. the same number of frames.
  75.  
  76. Once you have set up your pause cursor image, go to the plugin manager
  77. and for this plugin "Hime_MessagePauseCursor", specify how many rows
  78. there are and how many frames there are in each row.
  79.  
  80. -- Changing Cursors --
  81.  
  82. To change which cursor is shown, you can use the script call
  83.  
  84.   $gameMessage.setCursorId(NUMBER)
  85.  
  86. Where the NUMBER is the ID of the cursor. The first cursor at the top
  87. is number 1. The second is number 2. So if you wanted to change to cursor 2,
  88. you would make the script call
  89.  
  90.   $gameMessage.setCursorId(2)
  91.  
  92. -- Changing Alignment --
  93.  
  94. Alignment determines where the cursor is positioned in the window.
  95. To change the alignment, use the script call
  96.  
  97.   $gameMessage.setCursorAlign( ALIGNMENT )
  98.  
  99. You have three options for the ALIGNMENT
  100.  
  101.   'center'  - center of window, at the bottom
  102.   'left'    - lower-left corner of the window
  103.   'right'   - lower right corner of the window
  104.   'end'     - right after the last character
  105.  
  106. -- Changing Animation Speed --
  107.  
  108. To change the animation speed, use the script call
  109.  
  110.   $gameMessage.setCursorSpeed( SPEED )
  111.  
  112. Where the SPEED is a number between 1 and probably 24.
  113. The higher the number, the faster it is. You can experiment with each
  114. number to see how fast they are.
  115.  
  116. -------------------------------------------------------------------------------
  117. @param Filename
  118. @desc Name of the file to use in the img/system folder (no extension)
  119. Change this if needed.
  120. @default MessagePauseCursor
  121.  
  122. @param Default Cursor ID
  123. @desc default cursor ID you want to start with as a number.
  124. First cursor at the top is 1, second is 2, and so on.
  125. @default 1
  126.  
  127. @param Number of Rows
  128. @desc Number of rows in the image. One cursor per row.
  129. @default 3
  130.  
  131. @param Number of Frames
  132. @desc Number of frames per animation.
  133. @default 4
  134.  
  135. @param Default Align
  136. @desc The alignment of the pause cursor in the message window.
  137. Can be 'left', 'center', 'right', or 'end' without quotes
  138. @default center
  139. -------------------------------------------------------------------------------
  140.  */
  141. var Imported = Imported || {} ;
  142. var TH = TH || {};
  143. Imported.TH_MessagePauseCursor = 1;
  144. TH.MessagePauseCursor = TH.MessagePauseCursor || {};
  145.  
  146. (function ($) {
  147.  
  148.   $.params = PluginManager.parameters("HIME_HMSMessagePauseCursor");
  149.  
  150.   $.filename = $.params["Filename"];
  151.   $.defaultId = Math.floor($.params["Default Cursor ID"])
  152.   $.numRows = Math.floor($.params["Number of Rows"])
  153.   $.numFrames = Math.floor($.params["Number of Frames"])
  154.   $.align = $.params["Default Align"].toLowerCase();  
  155.  
  156.     Window_Base.prototype.loadWindowskin = function() {
  157.       this.windowskin = ImageManager.loadSystem('Window');
  158.     this.windownew = ImageManager.loadSystem($.filename);
  159. };
  160.  
  161.  
  162.  
  163.   var TH_SceneBoot_loadSystemImages = Scene_Boot.prototype.loadSystemImages;
  164.   Scene_Boot.prototype.loadSystemImages = function() {
  165.     TH_SceneBoot_loadSystemImages.call(this);
  166.     ImageManager.loadSystem($.filename);
  167.   };
  168.  
  169.   var TH_GameMessage_initialize = Game_Message.prototype.initialize;
  170.   Game_Message.prototype.initialize = function() {
  171.     TH_GameMessage_initialize.call(this);
  172.     this._pauseCursorId = $.defaultId;
  173.     this._pauseCursorAlign = $.align
  174.     this._pauseCursorSpeed = 4
  175.     this._pauseCursorNeedsRefresh = false;
  176.   };
  177.  
  178.   Game_Message.prototype.setCursorId = function(id) {
  179.     this._pauseCursorId = id;
  180.     this.refreshPauseCursor();
  181.   };
  182.  
  183.   Game_Message.prototype.setCursorAlign = function(align) {
  184.     this._pauseCursorAlign = align.toLowerCase();
  185.     this.refreshPauseCursor();
  186.   };
  187.  
  188.   Game_Message.prototype.setCursorSpeed = function(speed) {
  189.     this._pauseCursorSpeed = speed;
  190.     this.refreshPauseCursor();
  191.   };
  192.  
  193.   Game_Message.prototype.refreshPauseCursor = function() {
  194.     this._pauseCursorNeedsRefresh = true;
  195.   }
  196.  
  197.   /***************************************************************************/
  198.  
  199.   var TH_WindowMessage_initialize = Window_Message.prototype.initialize;
  200.   Window_Message.prototype.initialize = function() {
  201.     TH_WindowMessage_initialize.call(this);
  202.     this._pauseCursorId = $.defaultId - 1
  203.     this._pauseCursorFrames = $.numFrames;
  204.     this._pauseCursorRows = $.numRows;
  205.     this._pauseCursorAlign = $.align
  206.     this._pauseCursorSpeed = 64 / (this._pauseCursorFrames * 4)
  207.    
  208.     bmp = ImageManager.loadSystem($.filename);
  209.     this._pauseCursorWidth = bmp.width / this._pauseCursorFrames;
  210.     this._pauseCursorHeight = bmp.height / this._pauseCursorRows;
  211.   };
  212.  
  213.   var TH_WindowMessage_startMessage = Window_Message.prototype.startMessage
  214.   Window_Message.prototype.startMessage = function() {
  215.     TH_WindowMessage_startMessage.call(this);
  216.     if ($gameMessage._pauseCursorNeedsRefresh) {
  217.       this._refreshPauseSign();
  218.       $gameMessage._pauseCursorNeedsRefresh = false;
  219.     }
  220.   };
  221.  
  222.   var TH_WindowMessage__refreshPauseSign = Window.prototype._refreshPauseSign;
  223.   Window_Message.prototype._refreshPauseSign = function() {
  224.     this._pauseCursorId = $gameMessage._pauseCursorId - 1;
  225.     this._pauseCursorAlign = $gameMessage._pauseCursorAlign;
  226.     this._pauseCursorSpeed = 64 / (this._pauseCursorFrames * $gameMessage._pauseCursorSpeed)
  227.     var sx = 0;
  228.     var sy = this._pauseCursorId * this._pauseCursorHeight;
  229.     this._windowPauseSignSprite.bitmap = ImageManager.loadSystem($.filename);
  230.     this._windowPauseSignSprite.anchor.x = 0.5;
  231.     this._windowPauseSignSprite.anchor.y = 1;
  232.     this._refreshPauseSignPosition();
  233.     this._windowPauseSignSprite.setFrame(sx, sy, this._pauseCursorWidth, this._pauseCursorHeight);
  234.     this._windowPauseSignSprite.alpha = 0;
  235.   };
  236.  
  237.   Window.prototype._refreshPauseSignPosition = function() {  
  238.     if (this._pauseCursorAlign == 'center') {
  239.       this._windowPauseSignSprite.move(this._width / 2, this._height);
  240.     }
  241.     else if (this._pauseCursorAlign == 'right') {
  242.       this._windowPauseSignSprite.move(this._width - this._pauseCursorWidth, this._height);
  243.     }
  244.     else if (this._pauseCursorAlign == 'left') {
  245.       this._windowPauseSignSprite.move(this._pauseCursorWidth, this._height);
  246.     }
  247.     else if (this._pauseCursorAlign == 'end') {
  248.       if (this._textState) {
  249.         this._windowPauseSignSprite.move(this._textState.x + this._pauseCursorWidth, this._textState.y + this._textState.height + this._pauseCursorHeight / 2);
  250.       }
  251.     };
  252.   }
  253.  
  254.   var TH_WindowMessage_onEndOfText = Window_Message.prototype.onEndOfText;
  255.   Window_Message.prototype.onEndOfText = function() {
  256.     this._refreshPauseSignPosition();
  257.     TH_WindowMessage_onEndOfText.call(this);    
  258.   };
  259.  
  260.   Window_Message.prototype._updatePauseSign = function() {
  261.     var sprite = this._windowPauseSignSprite;
  262.     var x = Math.floor(this._animationCount / this._pauseCursorSpeed) % $.numFrames;
  263.     var y = this._pauseCursorId;;
  264.     var sx = 0;
  265.     var sy = 0;
  266.     var pw = this._pauseCursorWidth;
  267.     var ph = this._pauseCursorHeight
  268.     if (!this.pause) {
  269.         sprite.alpha = 0;
  270.     } else if (sprite.alpha < 1) {
  271.         sprite.alpha = Math.min(sprite.alpha + 0.1, 1);
  272.     }
  273.     sprite.setFrame(sx+x*pw, sy+y*pw, pw, ph);
  274.     sprite.visible = this.isOpen();
  275.   };
  276. })(TH.MessagePauseCursor);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement