Advertisement
Killveran89

K89_MessageBallon

Feb 23rd, 2020
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //====================================================
  2. //@filename K89_MessageBallon.js
  3. //====================================================
  4. /*>>
  5. */
  6. /*:
  7.  *@plugindesc Messaggio in balloon
  8.  *
  9.  *
  10.  *@author Killvern89
  11.  *
  12.  *
  13.  *@help
  14.  *V:0.2 - D:2020/02/23
  15.  * =============================
  16.  * Target
  17.  * =============================
  18.  *
  19.  *  Per identificare la posizione del messaggio è necessario inserire
  20.  *  il codice: \T[n]
  21.  *      n = ID dell'evento target del messaggio
  22.  *      Per n = 0 il target del messaggio è il party leader
  23.  *
  24.  *  
  25.  *  Il codice \T[n] verrà sostituito con il nome del leader del
  26.  *  party (n = 0) o il nome dell'evento (n = ID evento)
  27.  *
  28.  *
  29.  *  Non è possibile utilizzare il balloon senza identificare un target.
  30.  *  
  31.  *
  32.  *  Per modificare il nome del party leader durante i dialoghi,
  33.  *  si può usare questo script:
  34.  *  >>    $gameParty.leader()._name = '';
  35.  *
  36.  *  
  37.  *  Per cambare il nome dell'evento durante i messaggi, si può usare
  38.  *  lo script:
  39.  *  >>    $gameMap._events[n].event().name = '';
  40.  *  
  41.  *  Si consiglia di inserire nell'evento il nome definitivo.
  42.  *  
  43.  *
  44.  * =============================
  45.  * Font size
  46.  * =============================
  47.  *
  48.  *  La dimensione del testo nel balloon può essere diversa
  49.  *  da quella dei testi standard (28).
  50.  *  La dimensione del balloon si adatta dinamamicamente.
  51.  *  
  52.  *  È possibile modificare la dimensione del font tramite
  53.  *  script in questo modo:
  54.  *  >>  K89.MB.FontSize = n;
  55.  *
  56.  * =============================
  57.  * Face
  58.  * =============================
  59.  *
  60.  *  Nel balloon può essere mostrata l'immagine face come nei messaggi standard.
  61.  *  Il ballon si adatta dinamicamente in altezza ed in larghezza secodno la
  62.  *  dimensione base del face impostate in Window_Base.
  63.  *  
  64.  *  Tramite il valore 'Face full height' = false, si inidica allo switch di non
  65.  *  considerare l'altezza del face nella creazione della finestra di messaggio.
  66.  *
  67.  *  È possibile modificare questa ipostazione tramite script:
  68.  *  >>  K89.MB.FullFace = true/false;
  69.  *
  70.  *
  71.  * =============================
  72.  * Offset
  73.  * =============================
  74.  *
  75.  * Possibilità di inserire compesazione per posizione X e Y del messaggio
  76.  *
  77.  * Possibile modificare in game con script:
  78.  * >>   K89.MB.OffSetX = n;
  79.  * >>   K89.MB.OffSetY = n;
  80.  *
  81.  * =============================
  82.  * Log
  83.  * =============================
  84.  *  V:0.1 - D:2020/02/23
  85.  *
  86.  *  V:0.2 - D:2020/02/23
  87.  *      - Add y positionig based on chara size
  88.  *      - Add offsett x & y
  89.  *
  90.  * =============================
  91.  *
  92.  *  @param Font size
  93.  *  @desc Text font size fore message ballon
  94.  *  @default 20
  95.  *
  96.  *  @param Face full height
  97.  *  @desc Full face in message balloon
  98.  *  @default true
  99.  *
  100.  *  @param Offset X
  101.  *  @desc Standard offset X
  102.  *  @default 0
  103.  *
  104.  *  @param Offset Y
  105.  *  @desc Standard offset Y
  106.  *  @default 0
  107.  */
  108.  
  109. var K89 = K89 || {};
  110. K89.MB = {};
  111. K89.MB.Par = PluginManager.parameters('K89_MessageBallon');
  112.  
  113. //----------------------------------------------
  114. //Set Parameters
  115. //----------------------------------------------
  116. K89.MB.FontSize = Number(K89.MB.Par['Font size']);
  117. K89.MB.FullFace = Boolean(K89.MB.Par['Face full height']);
  118. K89.MB.OffSetX = Number(K89.MB.Par['Offset X']);
  119. K89.MB.OffSetY = Number(K89.MB.Par['Offset Y']);
  120.  
  121. console.log('OffSet X' + K89.MB.OffSetX);
  122. console.log('OffSet Y' + K89.MB.OffSetY);
  123.  
  124.  
  125.  
  126. // Modifico funzione posizionamento finestra messaggio
  127. Window_Message.prototype.updatePlacement = function() {
  128.     this._positionType = $gameMessage.positionType();
  129.     this.contents.fontSize = K89.MB.FontSize;
  130.     this.padding = 10;
  131.     if (this._textTarget != undefined) {
  132.         this.width = this.eval_Width(this.textlenght)
  133.         this.height = this.eval_Height(this.textlenght)
  134.         if ($gameMessage._faceName != '') {
  135.             this.width += Window_Base._faceWidth + this.padding*2;
  136.             if (K89.MB.FullFace) {
  137.                 this.height = (Window_Base._faceHeight + this.padding*2);
  138.             }
  139.         }
  140.         this.y = this.eval_Y();
  141.         this.x = this.eval_X();
  142.     } else {
  143.         this.x = 0;
  144.         this.padding = 18;
  145.         this.width = this.windowWidth();
  146.         this.contents.fontSize = Window_Base.prototype.standardFontSize();
  147.         this.height = 180;
  148.         this._positionType = $gameMessage.positionType();
  149.         this.y = this._positionType * (Graphics.boxHeight - this.height) / 2;
  150.         this._goldWindow.y = this.y > 0 ? 0 : Graphics.boxHeight - this._goldWindow.height;
  151.     }
  152.     this._goldWindow.y = this.y > 0 ? 0 : Graphics.boxHeight - this._goldWindow.height;
  153. };
  154.  
  155.  
  156. // TODO: Verificare che la finestra non esca dallo schermo e definire posizionamento alternativo
  157. //          Valutare se necessario
  158.  
  159. //Valutazione X balloon
  160. Window_Message.prototype.eval_X = function () {
  161.     if (this._textTarget == '0') {
  162.         caller_X = $gamePlayer.screenX();
  163.     } else {
  164.         caller_X = $gameMap._events[this._textTarget].screenX();
  165.     }
  166.     caller_X = caller_X - this.width/2 + K89.MB.OffSetX;
  167.     return caller_X
  168. }
  169.  
  170. //Valutazione Y balloon, basata su altezza sprite target
  171. Window_Message.prototype.eval_Y = function () {
  172.     caller_height = 48;
  173.     if (this._textTarget == '0') {
  174.         caller_Y = $gamePlayer.screenY();
  175.         spritesetLenght = SceneManager._scene._spriteset._characterSprites.length;
  176.         caller_height = SceneManager._scene._spriteset._characterSprites[spritesetLenght-1].height;
  177.     } else {
  178.         caller_Y = $gameMap._events[this._textTarget].screenY();
  179.         caller_height = SceneManager._scene._spriteset._characterSprites[this._textTarget-1].height;
  180.     }
  181.     caller_Y = caller_Y - (this.height + caller_height) + K89.MB.OffSetY;
  182.     return caller_Y
  183. }
  184.  
  185. //Valutazione larghezza balloon
  186. Window_Message.prototype.eval_Width = function (text) {
  187.     let width = 1;
  188.     let letter = 0;
  189.     for (let i = 0; i < text.length; i++) {
  190.         letter = text[i].toString().length;
  191.         if (letter > width) {
  192.             width = letter;
  193.         };
  194.     };
  195.     width *= (K89.MB.FontSize*0.58);
  196.     if (letter <= 14) {
  197.         width += (K89.MB.FontSize/1.5);
  198.     }
  199.  
  200.     return width
  201. }
  202.  
  203. //Valutazione altezza balloon
  204. Window_Message.prototype.eval_Height = function (text) {
  205.     let height = text.length;
  206.     height *= (K89.MB.FontSize*1.5);
  207.     height += 30;
  208.  
  209.     return height
  210. }
  211.  
  212.  
  213. // Modifico funzione conversione escape character per leggere target messaggio, definire posizione finestra e inserire nome target
  214. Window_Base.prototype.convertEscapeCharacters = function(text) {
  215.     text = text.replace(/\\/g, '\x1b');
  216.     text = text.replace(/\x1b\x1b/g, '\\');
  217.     text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
  218.         return $gameVariables.value(parseInt(arguments[1]));
  219.     }.bind(this));
  220.     text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
  221.         return $gameVariables.value(parseInt(arguments[1]));
  222.     }.bind(this));
  223.     text = text.replace(/\x1bN\[(\d+)\]/gi, function() {
  224.         return this.actorName(parseInt(arguments[1]));
  225.     }.bind(this));
  226.     text = text.replace(/\x1bP\[(\d+)\]/gi, function() {
  227.         return this.partyMemberName(parseInt(arguments[1]));
  228.     }.bind(this));
  229.     text = text.replace(/\x1bG/gi, TextManager.currencyUnit);
  230.    
  231.     //> Kill : Gestione target messaggio
  232.     // console.log('text:' + text);
  233.     this._textTarget = text.match(/\x1bT\[(\d+)\]/gi);
  234.     if (this._textTarget != null) {
  235.         this._textTarget = this._textTarget.toString().match(/\d+/g);
  236.         speacker = this.getSpeakerName(this._textTarget)
  237.         text = text.replace(/\x1bT\[(\d+)\]/gi, speacker);
  238.         this.textlenght = text.split('\n')
  239.     };
  240.     return text;
  241. };
  242.  
  243. //Calcolo nome attore/evento da inserire nel messaggio al posto di /t[x]
  244. Window_Message.prototype.getSpeakerName = function (index) {
  245.     if (index == '0') {
  246.         name = $gameParty.leader()._name;
  247.     } else {
  248.         name = $gameMap.events()[index-1].event().name;
  249.     }
  250.     return name
  251. }
  252.  
  253. //Inizializazione messaggio, per gestire primi valori, potrebbe non servire...
  254. Window_Message.prototype.initialize = function() {
  255.     var width = this.windowWidth();
  256.     var height = this.windowHeight();
  257.     var x = 0;
  258.     var y = 0;
  259.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  260.     this.openness = 0;
  261.     this.initMembers();
  262.     this.createSubWindows();
  263.     this.updatePlacement();
  264. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement