Advertisement
Kakakadafi

HIME_HMSChoiceDisplayMode.js

May 6th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2. -------------------------------------------------------------------------
  3. @title HMS: Choice Display Mode
  4. @author Hime --> HimeWorks (http://himeworks.com)
  5. @date Oct 24, 2016
  6. @version 1.3
  7. @filename HIME_HMSChoiceDisplayMode.js
  8. @url http://himeworks.com/2016/04/hms-choice-display-mode/
  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.3 - Customize the way choices are displayed
  25. @help
  26. -------------------------------------------------------------------------------
  27. == Description ==
  28.  
  29. By default, when you present players with a set of choices for them to
  30. select, the choices will be displayed in a window separate from the message
  31. window.
  32.  
  33. However, what if you wanted to present your choices differently in certain
  34. situations?
  35.  
  36. This plugin allows you to display the choices in-line with your messages,
  37. with the option to switch between the default display method and the new
  38. display method.
  39.  
  40. == Terms of Use ==
  41.  
  42. - Free for use in non-commercial projects with credits
  43. - Free for use in commercial projects, but it would be nice to let me know
  44. - Please provide credits to HimeWorks
  45.  
  46. == Change Log ==
  47.  
  48. 1.3 - Oct 24, 2016
  49.  * Upgrade to 1.3.3 libraries: Window.prototype._maskWindow changed
  50. 1.2 - Aug 12, 2016
  51.  * Upgrade to 1.3.0 libraries
  52. 1.1 - Apr 27, 2016
  53.  * Implemented dynamic visible row calculation
  54.  * Fixed bug where choices are not shown correctly for empty message
  55.  * Display informative message when choices provided with no message
  56. 1.0 - Apr 27, 2016
  57.  * initial release
  58.  
  59. == Usage ==
  60.  
  61. --- Choice Display Mode ---
  62.  
  63. There are two ways to display choices
  64.  
  65. 1. Default
  66. 2. Embedded
  67.  
  68. Default mode means the choices will be displayed outside of the message as
  69. usual.
  70.  
  71. Embedded mode means the choices will be displayed inside the message.
  72.  
  73. --- Changing Display Mode ---
  74.  
  75. To switch between modes, use the script call
  76.  
  77.   HMS.setChoiceMode( MODE )
  78.  
  79. Where MODE is one of
  80.  
  81.   Default
  82.   Embed
  83.  
  84. All choices displayed after will use the specified mode.
  85.  
  86. --- Choice Indentation ---
  87.  
  88. When the choices are embedded in the message window, you can choose how
  89. much indentation they will have in the plugin parameters.
  90.  
  91. By default, it is 36 pixels.
  92.  
  93. --- Changing Choice Window Size ---
  94.  
  95.   HMS.setChoiceSize( width , height );
  96.  
  97.   *Only works on Default display mode (not embedded)
  98.  
  99. --- Changing Choice Window Position ---
  100.  
  101.   HMS.setChoicePosition( screenX , screenY );
  102.  
  103.   *Only works on Default display mode (not embedded)
  104.  
  105. --- Changing Choice Window Max Columns ---
  106.  
  107.   HMS.setChoiceColumn( maxCols );
  108.  
  109. -------------------------------------------------------------------------------
  110. @param Default Choice Mode
  111. @desc Choice mode to begin the game with.
  112. Options: Default, Embed (default: Default)
  113. @default Default
  114.  
  115. @param Choice Indent
  116. @desc Number of pixels that the choices should be indented
  117. @default 36
  118. -------------------------------------------------------------------------------
  119. */
  120. var Imported = Imported || {} ;
  121. var TH = TH || {};
  122. Imported.HMSChoiceDisplayMode = 1;
  123. TH.HMSChoiceDisplayMode = TH.HMSChoiceDisplayMode || {};
  124.  
  125. var HMS = HMS || {};
  126.  
  127. (function ($) {
  128.  
  129.   $._modes = {
  130.     "DEFAULT" : 0,
  131.     "EMBED" : 1,
  132.     "KEYWORD" : 2
  133.   };
  134.  
  135.   $.params = PluginManager.parameters("HIME_HMSChoiceDisplayMode");
  136.   $.defaultMode = $._modes[$.params["Default Choice Mode"].toUpperCase()];
  137.   $.indent = Math.floor($.params["Choice Indent"]);
  138.  
  139.   HMS.setChoiceMode = function(mode, msgId) {
  140.     msgId = msgId || 1;
  141.     var mode = $._modes[mode.toUpperCase()];
  142.     $gameMessage.setChoiceMode(mode);
  143.   };
  144.  
  145.   HMS.setChoicePosition = function(screenX, screenY) {
  146.     if ($gameMessage.choiceMode() !== 1) {
  147.         $gameMessage.setChoicePosition(screenX, screenY);
  148.     }
  149.   };
  150.  
  151.   HMS.setChoiceSize = function(width, height) {
  152.     if ($gameMessage.choiceMode() !== 1) {
  153.         $gameMessage.setChoiceSize(width, height);
  154.     }
  155.   };
  156.  
  157.   HMS.setChoiceColumn = function(maxCols) {
  158.     $gameMessage.setChoiceColumn(maxCols);
  159.   };
  160.  
  161.   var TH_GameMessage_initialize = Game_Message.prototype.initialize;
  162.   Game_Message.prototype.initialize = function() {
  163.     TH_GameMessage_initialize.call(this);
  164.     this.setChoiceMode($.defaultMode);
  165.     this._choicePosition = -1;
  166.     this._choiceMaxCols = 0;
  167.   };
  168.  
  169.   Game_Message.prototype.setChoiceMode = function(mode) {
  170.     this._choiceMode = mode;
  171.   };
  172.  
  173.   Game_Message.prototype.setChoiceSize = function(width, height) {
  174.     this._choiceCustomSize = true;
  175.     this._choiceWidth = width;
  176.     this._choiceHeight = height;
  177.   };
  178.  
  179.   Game_Message.prototype.disableChoiceCustomSize = function() {
  180.     this._choiceCustomSize = false;
  181.   };
  182.  
  183.   Game_Message.prototype.setChoicePosition = function(screenX, screenY) {
  184.     this._choicePosition = [screenX, screenY];
  185.   };
  186.  
  187.   Game_Message.prototype.setChoiceColumn = function(maxCols) {
  188.     this._choiceMaxCols = maxCols;
  189.   };
  190.  
  191.   Game_Message.prototype.choiceMode = function() {
  192.     return this._choiceMode;
  193.   };
  194.  
  195.   var TH_WindowChoiceList_start = Window_ChoiceList.prototype.start;
  196.   Window_ChoiceList.prototype.start = function() {
  197.     this.updateChoiceMode();
  198.     TH_WindowChoiceList_start.call(this);
  199.     $gameMessage.disableChoiceCustomSize();
  200.   };
  201.    
  202.   Window_ChoiceList.prototype.updateChoiceMode = function() {
  203.     this._choiceMode = $gameMessage.choiceMode();
  204.   };
  205.  
  206.   var TH_WindowChoiceList_updatePlacement = Window_ChoiceList.prototype.updatePlacement;
  207.   Window_ChoiceList.prototype.updatePlacement = function() {  
  208.     TH_WindowChoiceList_updatePlacement.call(this);
  209.     if (this._choiceMode === 1) {
  210.       var messageY = this._messageWindow.y;    
  211.       var textState = this._messageWindow._textState;    
  212.       if (!textState) {
  213.         throw new Error("Displaying embedded choices must have a Show Text command");
  214.       }
  215.       this.x = this._messageWindow.newLineX() + $.indent;    
  216.       var y = messageY + (textState.y)
  217.      
  218.       // if message is not empty, increase y-position
  219.       if (textState.text !== '') {
  220.         y += textState.height
  221.       }
  222.       this.y = y;
  223.     } else {
  224.         if ($gameMessage._choicePosition !== -1) {
  225.             this.x = $gameMessage._choicePosition[0];
  226.             this.y = $gameMessage._choicePosition[1];
  227.             $gameMessage._choicePosition = -1;
  228.         }
  229.     }
  230.   };    
  231.  
  232.   var TH_WindowChoiceList_updateBackground = Window_ChoiceList.prototype.updateBackground;
  233.   Window_ChoiceList.prototype.updateBackground = function() {
  234.     TH_WindowChoiceList_updateBackground.call(this);
  235.     if (this._choiceMode === 1) {
  236.       this._background = $gameMessage.choiceBackground();
  237.       this.setBackgroundType(2);
  238.     }
  239.   };
  240.  
  241.   /* TO DO. Currently only supports one option per row as defualt */
  242.   Window_ChoiceList.prototype.maxCols = function() {
  243.     if ($gameMessage._choiceMaxCols > 0) {
  244.         return $gameMessage._choiceMaxCols;
  245.     } else {
  246.         return 1;
  247.     }
  248.   };
  249.  
  250.   var TH_WindowChoiceList_windowWidth = Window_ChoiceList.prototype.windowWidth;
  251.   Window_ChoiceList.prototype.windowWidth = function() {
  252.     if ($gameMessage._choiceCustomSize) {
  253.         var width = $gameMessage._choiceWidth;
  254.         return Math.min(width, Graphics.boxWidth);
  255.     } else if (this._choiceMode === 1) {
  256.         var msgBoxWidth = this._messageWindow.width;
  257.         var width = msgBoxWidth - $.indent;
  258.         return Math.min(width, Graphics.boxWidth);
  259.     } else {
  260.         return TH_WindowChoiceList_windowWidth.call(this);
  261.     }
  262.   };
  263.  
  264.   var TH_WindowChoiceList_windowHeight = Window_ChoiceList.prototype.windowHeight;
  265.   Window_ChoiceList.prototype.windowHeight = function() {
  266.     if ($gameMessage._choiceCustomSize) {
  267.         var height = $gameMessage._choiceHeight;
  268.         return Math.min(height, Graphics.boxHeight);
  269.     } else {
  270.         return TH_WindowChoiceList_windowHeight.call(this);
  271.     }
  272.   };
  273.  
  274.   /* Number of visible rows is determined by how much space is in the
  275.    * message window. TO-DO, automatic scrolling
  276.    */
  277.   var TH_WindowChoiceList_numVisibleRows = Window_ChoiceList.prototype.numVisibleRows;
  278.   Window_ChoiceList.prototype.numVisibleRows = function() {  
  279.     // need to calculate how much space is left
  280.     if (this._choiceMode === 1) {
  281.       var textState = this._messageWindow._textState;
  282.       var y = textState.y;
  283.       var textHeight = textState.height;
  284.       var messageHeight = this._messageWindow.height - this.padding * 2
  285.       if (textState.text !== '') {
  286.         y += textHeight;
  287.       }
  288.       return Math.floor((messageHeight - y) / textHeight);
  289.     }
  290.     else {
  291.       return TH_WindowChoiceList_numVisibleRows.call(this);
  292.     }    
  293.   };
  294.  
  295.   // IAVRA windowlayer fix for now
  296.   delete WindowLayer.prototype._renderCanvas;
  297.   delete WindowLayer.prototype._canvasClearWindowRect;
  298.   delete WindowLayer.prototype._renderWebGL;
  299.   delete WindowLayer.prototype._webglMaskOutside;
  300.   delete WindowLayer.prototype._webglMaskWindow;
  301.   delete WindowLayer.prototype._webglMaskRect;
  302.  
  303.   /* 1.3.3 windowlayer masking fix */
  304.   var TH_WindowLayer_maskWindow = WindowLayer.prototype._maskWindow;
  305.   WindowLayer.prototype._maskWindow = function(window, shift) {
  306.     if (window instanceof Window_ChoiceList || window instanceof Window_Message) {
  307.       return
  308.     }
  309.     else {
  310.       TH_WindowLayer_maskWindow.call(this, window, shift);
  311.     }
  312.   };
  313.  
  314. })(TH.HMSChoiceDisplayMode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement