/*: * @plugindesc Rewrites the Window_Selectable class to allow for smooth scrolling, scrollbars and other features. * <Iavra Selectable> * @author Iavra * * @param Scrollbar Width * @desc Width of the scrollbar (without padding). A minimum value of 1 is enforced to prevent errors. Default: 4 * @default 4 * * @param Scrollbar Padding * @desc Padding between the scrollbar background and the scrolling part. Gets applied to all 4 sides. Default: 1 * @default 1 */var IAVRA = IAVRA || {};//=============================================================================// IAVRA.SELECTABLE//=============================================================================(function($) { var _params = $plugins.filter(function(p) { return p.description.contains('<Iavra Selectable>'); })[0].parameters; $.params = { width: Math.max(parseInt(_params['Scrollbar Width']) || 0, 1), padding: Math.max(parseInt(_params['Scrollbar Padding']) || 0, 0) }; $.Sprite_Scrollbar = function() { this.initialize.apply(this, arguments); };})(IAVRA.SELECTABLE = {});//=============================================================================// IAVRA.SELECTABLE.Sprite_Scrollbar//=============================================================================(function($) { "use strict"; ($.prototype = Object.create(PIXI.DisplayObjectContainer.prototype)).constructor = $; $.prototype.initialize = function() { PIXI.DisplayObjectContainer.call(this); this._rate = 1; this.addChild(this._spriteBackground = new Sprite()); this.addChild(this._spriteScrollbar = new Sprite()); }; $.prototype.refreshAllParts = function() { var width = IAVRA.SELECTABLE.params.width, height = this.parent.height - this.parent.padding * 2; var padding = IAVRA.SELECTABLE.params.padding; var rect = new Rectangle(this.parent.width - 15, (this.parent.height - height) / 2, width + padding * 2, height); this.refreshBackground(rect, padding); this.refreshScrollbar(rect, padding); }; $.prototype.refreshBackground = function(rect, padding) { this._spriteBackground.bitmap = new Bitmap(rect.width, rect.height); this._spriteBackground.bitmap.fillAll('#FFF'); this._spriteBackground.move(rect.x, rect.y); }; $.prototype.refreshScrollbar = function(rect, padding) { this._rate = Math.min(this.parent.maxPageRows() / this.parent.maxRows(), 1); this._spriteScrollbar.bitmap = new Bitmap(rect.width - padding * 2, (rect.height - padding * 2) * this._rate); this._spriteScrollbar.bitmap.fillAll('#000'); this._spriteScrollbar.move(rect.x + padding, rect.y + padding); }; $.prototype.updatePlacement = function() { var diff = this._spriteBackground.height - this._spriteScrollbar.height - IAVRA.SELECTABLE.params.padding * 2; var max = Math.max(this.parent.maxRows() - this.parent.maxPageRows(), 1); var current = Math.min(this.parent.topRow(), max); this._spriteScrollbar.y = this._spriteBackground.y + current / max * diff + IAVRA.SELECTABLE.params.padding; };})(IAVRA.SELECTABLE.Sprite_Scrollbar);//=============================================================================// Window_Selectable//=============================================================================(function($) { "use strict"; var alias_initialize = $.prototype.initialize; $.prototype.initialize = function(x, y, width, height) { alias_initialize.call(this, x, y, width, height); this.addChild(this._scrollbar = new IAVRA.SELECTABLE.Sprite_Scrollbar()); this._scrollbar.refreshAllParts(); }; var alias_updateTransform = $.prototype.updateTransform; $.prototype.updateTransform = function() { this._scrollbar.visible = this._scrollbar._rate < 1 && this.isOpen(); alias_updateTransform.call(this); }; var alias_refreshAllParts = $.prototype._refreshAllParts; $.prototype._refreshAllParts = function() { alias_refreshAllParts.call(this); if(this._scrollbar) { this._scrollbar.refreshAllParts(); } }; var alias_refresh = $.prototype.refresh; $.prototype.refresh = function() { alias_refresh.call(this); this._scrollbar.updatePlacement(); }; })(Window_Selectable);