Advertisement
Astfgl

AstfglWCLA

Sep 13th, 2017
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Window Choice List Alias
  3. // by Astfgl
  4. // Date: 13/09/2017
  5. // Free to use both commercially and non commercially.
  6. // Edits allowed, but the product must be released with the same license.
  7. // Credits required: any of Astfgl/Pierre MATEO/Pierre MATEO (Astfgl)
  8. // Do not claim as your own
  9. //=============================================================================
  10. /*:
  11.  * @plugindesc Choice list modifications
  12.  * @author Astfgl
  13.  * @help Automatically centers the text for the choice window, and draws
  14.  * the rectangle appropriately.
  15.  */
  16. (function(){
  17.     var _Astfgl_newWCLIW = Window_ChoiceList.prototype.itemWidth
  18.     Window_ChoiceList.prototype.itemWidth = function(index) {
  19.         if (this.currentData()) {
  20.             return Math.floor((this.textWidthEx(this.currentData().name)) + this.spacing())
  21.         } else {
  22.             _Astfgl_newWCLIW.call(this,index)
  23.         }
  24.     }
  25.    
  26.     Window_ChoiceList.prototype.hitTest = function(x, y) {
  27.         if (this.isContentsArea(x, y)) {
  28.             var cx = x - this.padding;
  29.             var cy = y - this.padding;
  30.             var topIndex = this.topIndex();
  31.             for (var i = 0; i < this.maxPageItems(); i++) {
  32.                 var index = topIndex + i;
  33.                 if (index < this.maxItems()) {
  34.                     var rect = this.itemRect(index);
  35.                     var right = this.width; //changed this line from rect.width + rect.x
  36.                     var bottom = rect.y + rect.height;
  37.                     if (cx >= rect.x && cy >= rect.y && cx < right && cy < bottom) {
  38.                         return index;
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.         return -1;
  44.     };
  45.    
  46.     var _Astfgl_newWCLDI = Window_ChoiceList.prototype.drawItem
  47.     Window_ChoiceList.prototype.drawItem = function(index) {
  48.         var rect = this.itemRectForText(index);
  49.         this.drawTextEx(this.commandName(index), this.width/2 - this.textWidthEx(this.commandName(index))/2 - this.spacing() * 1.5 , rect.y);
  50.     };
  51.    
  52.     Window_ChoiceList.prototype.itemRect = function (index) {
  53.         var rect = new Rectangle();
  54.         var maxCols = this.maxCols();
  55.         rect.width = this.itemWidth();
  56.         rect.height = this.itemHeight();
  57.         if (this._list[index]) {
  58.             rect.x = this.width/2 - this.textWidthEx(this.commandName(index))/2 - this.spacing() * 2
  59.         } else {
  60.             rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
  61.         }
  62.         rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
  63.         return rect;
  64.     }
  65.  
  66. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement