Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. // ============================================================================
  2. // TimeFantasyScreenSize.js
  3. // ============================================================================
  4.  
  5. // eslint-disable-next-line spaced-comment
  6. /*:
  7. * @plugindesc Changes the menu size to allow for TimeFantasy sprites and
  8. * tilesets whithout clashing too much with menus and other stuff.
  9. * As an effect the menu will drawn on a smaller surface (with it size defined
  10. * by this plugin) and rescaled to the actual screen size to make it appear more
  11. * block/pixelated.
  12. * Warning: This plugin is not finished! It only works in canvas mode and it
  13. * does not work with mouse/touch input.
  14. * <TimeFantasyScreenSize>
  15. * @author psuessenb
  16. *
  17. * @param menuWidth
  18. * @text Original menu width in pixels
  19. * @type number
  20. * @default 816
  21. *
  22. * @param menuHeight
  23. * @text Original menu height in pixels
  24. * @type number
  25. * @default 624
  26. *
  27. * @help This plugin does not provide plugin commands.
  28. *
  29. */
  30.  
  31. // eslint-disable-next-line no-var
  32. var TimeFantasyScreenSize = TimeFantasyScreenSize || {};
  33.  
  34. (($) => {
  35. 'use strict';
  36.  
  37. const params = $plugins.filter((p) => {
  38. return p.description.contains('<TimeFantasyScreenSize>');
  39. })[0].parameters;
  40. const menuWidth = params['menuWidth'];
  41. const menuHeight = params['menuHeight'];
  42.  
  43. Scene_Base.prototype.createWindowLayer = function() {
  44. this._windowLayer = new WindowLayer();
  45. this._windowLayer.move(0, 0, menuWidth, menuHeight);
  46. this.addChild(this._windowLayer);
  47. };
  48.  
  49. // Scene_MenuBase
  50. (($) => {
  51. let origBoxHeight = 0;
  52. let origBoxWidth = 0;
  53.  
  54. const aliasCreate = $.prototype.create;
  55. $.prototype.create = function() {
  56. origBoxHeight = Graphics.boxHeight;
  57. origBoxWidth = Graphics.boxWidth;
  58. Graphics.boxHeight = menuHeight;
  59. Graphics.boxWidth = menuWidth;
  60. aliasCreate.call(this);
  61. };
  62.  
  63. const aliasTerminate = $.prototype.terminate;
  64. $.prototype.terminate = function() {
  65. aliasTerminate.call(this);
  66. Graphics.boxWidth = origBoxWidth;
  67. Graphics.boxHeight = origBoxHeight;
  68. };
  69. })(Scene_MenuBase);
  70.  
  71. // Window_TitleCommand
  72. (($) => {
  73. const aliasUpdatePlacement = $.prototype.updatePlacement;
  74. $.prototype.updatePlacement = function() {
  75. const origBoxHeight = Graphics.boxHeight;
  76. const origBoxWidth = Graphics.boxWidth;
  77. Graphics.boxHeight = menuHeight;
  78. Graphics.boxWidth = menuWidth;
  79. aliasUpdatePlacement.call(this);
  80. Graphics.boxHeight = origBoxHeight;
  81. Graphics.boxWidth = origBoxWidth;
  82. };
  83. })(Window_TitleCommand);
  84.  
  85. // WindowLayer
  86. (($) => {
  87. let _widthRatio;
  88. let _heightRatio;
  89.  
  90. function calcWidthRatio() {
  91. return _widthRatio || Graphics.width / menuWidth;
  92. }
  93. function calcHeightRatio() {
  94. return _heightRatio || Graphics.height / menuHeight;
  95. }
  96.  
  97. $.prototype.renderCanvas = function(renderer) {
  98. if (!this.visible || !this.renderable) {
  99. return;
  100. }
  101.  
  102. if (!this._tempCanvas) {
  103. this._tempCanvas = document.createElement('canvas');
  104. }
  105.  
  106. this._tempCanvas.width = menuWidth;
  107. this._tempCanvas.height = menuHeight;
  108.  
  109. const realCanvasContext = renderer.context;
  110. const context = this._tempCanvas.getContext('2d');
  111.  
  112. context.save();
  113. context.clearRect(0, 0, Graphics.width, Graphics.height);
  114. context.beginPath();
  115. context.rect(this.x, this.y, this.width, this.height);
  116. context.closePath();
  117. context.clip();
  118.  
  119. renderer.context = context;
  120.  
  121. for (let i = 0; i < this.children.length; i++) {
  122. const child = this.children[i];
  123. if (child._isWindow && child.visible && child.openness > 0) {
  124. this._canvasClearWindowRect(renderer, child);
  125. context.save();
  126. child.renderCanvas(renderer);
  127. context.restore();
  128. }
  129. }
  130.  
  131. context.restore();
  132.  
  133. renderer.context = realCanvasContext;
  134. renderer.context.setTransform(calcWidthRatio(), 0, 0, calcHeightRatio(),
  135. 0, 0);
  136. renderer.context.globalCompositeOperation = 'source-over';
  137. renderer.context.globalAlpha = 1;
  138. renderer.context.drawImage(this._tempCanvas, 0, 0);
  139.  
  140. for (let j = 0; j < this.children.length; j++) {
  141. if (!this.children[j]._isWindow) {
  142. this.children[j].renderCanvas(renderer);
  143. }
  144. }
  145. };
  146. })(WindowLayer);
  147. })(TimeFantasyScreenSize);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement