Jump to content
Rpg²S Forum

Message Background


Lomax_Iced
 Share

Recommended Posts

Dal titolo non si capisce bene cosa fa lo script. Ma inserendolo in una demo o analizzandone il codice, si capisce perfettamente.

In sostanza questa implementazione permette di inserire un'immagine che sostituisce la windowskin.
Ecco a voi la risorsa:


//-----------------------------------------------------------------------------
//  Galv's Message Background
//-----------------------------------------------------------------------------
//  For: RPGMAKER MV
//  Galv_MessageBackground.js
//-----------------------------------------------------------------------------
//  2015-10-30 - Version 1.3 - removed accidental code + compatiblity change
//  2015-10-27 - Version 1.2 - fixed a bug with images showing over top
//  2015-10-26 - Version 1.1 - fixed bug with variable setting
//  2015-10-25 - Version 1.0 - release
//-----------------------------------------------------------------------------
// Terms can be found at:
// galvs-scripts.com
//-----------------------------------------------------------------------------

var Imported = Imported || {};
Imported.Galv_MessageBackground = true;

var Galv = Galv || {};        // Galv's main object
Galv.MBG = Galv.MBG || {};    // Galv's Message Background stuff

//-----------------------------------------------------------------------------
/*:
 * @plugindesc Displays an image behind messages in place of the windowskin
 * 
 * @author Galv - galvs-scripts.com
 *
 * @param Image Variable ID
 * @desc Variable used to determine which image to display
 * /img/system/msgimg_X.png - where X is the variable's value
 * @default 1
 * @param Disable Switch ID
 * @desc Turn this switch ON usig control switches to disable the
 * message image and revert back to windowskin (make 0 to not use)
 * @default 1
 *
 * @help
 *   Galv's Message Background
 * ----------------------------------------------------------------------------
 * Set the variable ID number you would like to use in the settings.
 * This is the in-game variable that you wil change with "Control Variables"
 * event command. (Default is variable 1, which has a value of 0 by default)
 * This will select images from your project's folders:
 * /img/system/msgimg_X.png - where X is the variable's value
 *
 * You can also set a switch ID in the settings. If you choose a switch, then
 * during the game you can turn that switch number ON with "Control Switches"
 * to disable the background image and go back to using default windowskin.
 * This defaults to 0 meaning do not use this option.
 *
 * This 'Show Message' settings of "window", "Dim" and "Tranparent" have an
 * effect on the message background image. Window shows image normally, Dim
 * shows the image partially transparent and Transparent makes it invisible.
 */


//-----------------------------------------------------------------------------
//  CODE STUFFS
//-----------------------------------------------------------------------------



(function() {
	Galv.MBG.v = Number(PluginManager.parameters('Galv_MessageBackground')["Image Variable ID"]);
	Galv.MBG.s = Number(PluginManager.parameters('Galv_MessageBackground')["Disable Switch ID"]);
	
	
// ---------------- WINDOW MESSAGE

// WINDOW MESSAGE START MESSAGE - MOD
var Galv_Window_Message_startMessage = Window_Message.prototype.startMessage;
Window_Message.prototype.startMessage = function() {
	// Create graphic when window is displayed
	$gameMessage.msgWindow = this;
	Galv_Window_Message_startMessage.call(this);
};

// WINDOW MESSAGE SET BACKGROUND TYPE
if (Window_Message.prototype.setBackgroundType) {
	var Galv_Window_Message_setBackgroundType = Window_Message.prototype.setBackgroundType;
} else {
	var Galv_Window_Message_setBackgroundType = Window_Base.prototype.setBackgroundType;
};
Window_Message.prototype.setBackgroundType = function(type) {
	if (!$gameSwitches.value(Galv.MBG.s)) {
		this.opacity = 0;
		return;
	};
	Galv_Window_Message_setBackgroundType.call(this,type);
};



// ---------------- SPRITESET MAP



// SPRITESET MAP CREATE LOWER LAYER
var Galv_Spriteset_Map_createUpperLayer = Spriteset_Base.prototype.createUpperLayer;
Spriteset_Base.prototype.createUpperLayer = function() {
	Galv_Spriteset_Map_createUpperLayer.call(this);
	this.createMsgBg();
};

// SPRITESET MAP CREATE MSG BG
Spriteset_Base.prototype.createMsgBg = function() {
    if (this._msgBgSprite) return;
    this._msgBgSprite = new Sprite_GalvMsgBg();
    this.addChild(this._msgBgSprite);
};


// ---------------- SPRITE GALVMSGBG - NEW

function Sprite_GalvMsgBg() {
    this.initialize.apply(this, arguments);
}

Sprite_GalvMsgBg.prototype = Object.create(Sprite.prototype);
Sprite_GalvMsgBg.prototype.constructor = Sprite_GalvMsgBg;

Sprite_GalvMsgBg.prototype.initialize = function() {
    Sprite.prototype.initialize.call(this);
	this.opacity = 0;
	this.loadBitmap();
    this.update();
};

Sprite_GalvMsgBg.prototype.update = function() {
    Sprite.prototype.update.call(this);
    if ($gameMessage.msgWindow) this.controlBitmap() ;
};

Sprite_GalvMsgBg.prototype.loadBitmap = function() {
	this.imageID = $gameVariables.value(Galv.MBG.v);
    this.bitmap = ImageManager.loadSystem('msgimg_' + this.imageID);
	this.x = 0
	this.z = 10;
};

Sprite_GalvMsgBg.prototype.controlBitmap = function() {
	if ($gameSwitches.value(Galv.MBG.s) || $gameMessage.msgWindow.openness <= 0) {
		this.opacity = 0;
		this.maxopac = 255;
		return;
	};
    if (this.imageID != $gameVariables.value(Galv.MBG.v)) this.loadBitmap();  // If image changed, reload bitmap

	// Control image opacity
	switch ($gameMessage.background()) {
	case 0:
	// Window
		this.opacity = Math.min($gameMessage.msgWindow._openness,this.maxopac);
		break;
	case 1:
	// Dim
		this.opacity = $gameMessage.msgWindow._openness * 0.5;
		this.maxopac = this.opacity;
		break;
	case 2:
	// Transparent
		this.opacity = 0;
		this.maxopac = 0;
		break;
	};
	
	// Don't change y value if closing as it reverts to positiontype 2
	if ($gameMessage.msgWindow.isClosing()) return;
	
	// Control image position
	switch ($gameMessage.positionType()) {
	case 0:
	//top
		this.y = -(this.bitmap.height * 0.333);
		break;
	case 1:
	// middle
		this.y = (Graphics.boxHeight / 2) - (this.bitmap.height / 2)
		break;
	case 2:
	//bottom
		this.y = Graphics.boxHeight - (this.bitmap.height * 0.666);
		break;
	};
};

})();

 

 

Una volta inserito il plugin..andate in:
1. img

2. system

3. in cui al suo interno create un file immagine e nominatelo così msgimg_0.png
Potrete inserirne quante immagini di background volete e potrete modificare la skin in game.
Basta che i files che inserirete nella cartella system siano numerati in questo modo:
msgimg_0.png

msgimg_1.png
msgimg_2.png
msgimg_3.png
msgimg_4.png
msgimg_5.png
msgimg_6.png
ecc.
Per fare in modo che possiate cambiare i background in game, basterà:
1. creare un nuovo evento ove il quale verrà inserita una condizione
2. scegliendo potete fare si che essa sia complessa o a cascata a seconda del vostro giudizio.
inserendo ad esempio queste nozioni:

NON è JS, vi sto esponendo solo il concetto anche perché dovrete farlo ad eventi:
Fatta la dovuta premessa, ad esempio per 2 immagini, dovrete inserire la seguente condizione:


if la variabile di controllo 0001 == 0
  si inserisce msgimg_0.png
altrimenti
  si inserisce msgimg_1.png
fine


3. create un secondo evento
4. inserendo all'interno un'altra condizione che enuncia che..

se l'interruttore di controllo è in ON si attiva la windowskin normale
altrimenti appare al suo posto, l'immagine di background.  

Spero di essere stato chiaro nella spiegazione e che questo Plugin vi sia utile.

P.S: Mi raccomando per questa risorsa non citate me, ma Galv.
Buona domenica a tutti :)

Link to comment
Share on other sites

Ciao Lomax, stai iniziando a mettere un po' di bei plugin all'interno della nostra sezione del forum, grazie mille per questo impegno! :)

Se accetti, vorrei solo darti alcuni piccoli consigli per quanto riguarda i nuovi plugin di Rpg Maker MV:

- se riesci, dove è possibile, oltre a copia-incollare l'intero codice, inserisci il download diretto al file del plugin, pronto per essere spostato nella rispettiva cartella. I plugin per funzionare hanno bisogno del loro nome corretto, che gli viene assegnato dall'autore stesso. In questo modo eviteremo questioni del tipo "come mai il plugin non mi funziona?" o qualche altro utente meno esperto che non sa bene dove copiarsi tutte le righe di codice per crearsi il file plugin.

- inserisci il nome dell'autore del plugin sempre tra le prime righe in alto, in modo che sia ben visibile e, chi dovesse utilizzare il plugin, sappia subito a colpo d'occhio chi deve ringraziare per la risorsa.

- sulle ultime righe in fondo, alla fine del plugin, è sempre bene riportare i termini e le condizioni con cui è possibile utilizzare il plugin. E' disponibile sia per progetti commerciali che non, oppure solo per quelli non commerciali?

 

Spero che i consigli siano utili e ti ringrazio ancora per le risorse che pubblichi.

Per maggiori dettagli ti rimando al Regolamento e Template sezione PLUGIN e Javascript

Buon proseguimento! :)

Edited by Ste
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...