Sphinx-GUI
Comme tous mes plugins, ce script est publié sous licence CC BY 4.0.
Ce plugin est une extension d’un autre plugin que j’utilise : Tonyryu_GUI. Il est nécessaire d’importer le plugin Tonyryu_GUI pour pouvoir utiliser les fonctions apportées par mon plugin.
//=============================================================================
// Sphinx-GUI.js
//=============================================================================
/*:
* @plugindesc Extension du script Tonyryu_GUI
* @author Sphinx
*
* @help
* - Dépendances : Tonyryu_GUI
*/
// Game_Actors
Game_Actors.prototype.getFace = function(id) {
if($gameCharacterCreations.hasInfo(id, "face")) {
return $gameCharacterCreations.getInfo(id, "face");
}
return {
faceName: this.actor(id).faceName(),
faceIndex: this.actor(id).faceIndex()
}
}
// Gui_Base
Gui_Base.prototype.sphinxInitialize = Gui_Base.prototype.initialize;
Gui_Base.prototype.initialize = function(pOptions) {
Gui_Base.prototype.sphinxInitialize.call(this, pOptions);
this._parent = undefined;
}
/**********************************************************************
* Méthode : getGuis
* Fonction :
* Params : --
**********************************************************************/
Window_Gui.prototype.getGuis = function() {
return this._tabGui;
};
/**********************************************************************
* Méthode : removeHandler
* Fonction : Supprime un lien entre un événement et une fonction
* Params : symbol : nom de l'événement (onrollover, onfocus, etc...)
**********************************************************************/
Gui_Base.prototype.removeHandler = function(symbol) {
delete this._handlers[symbol];
};
/**********************************************************************
* Méthode : move
* Fonction : Déplace ou modifie un Gui
* Params : pOptions : Json contenant la liste des options à modifier
**********************************************************************/
Gui_Base.prototype.move = function(pOptions) {
for(var nomOption in pOptions) {
if(nomOption === 'x')
this.x += pOptions.x;
if(nomOption === 'y')
this.y += pOptions.y;
if(nomOption === 'width')
this.width += pOptions.width;
if(nomOption === 'height')
this.height += pOptions.height;
if(nomOption === 'opacity')
this.opacity = Math.min(255, Math.max(0, this.opacity + pOptions.opacity));
}
this.refresh();
};
/**********************************************************************
* Méthode : getOption
* Fonction : Permet de récupérer la valeur d'une option
* Params : nomOption : Nom de options à lire
**********************************************************************/
Gui_Base.prototype.getOption = function(nomOption) {
if(nomOption === 'groupe')
return this._groupe;
if(nomOption === 'active')
return this._active;
if(nomOption === 'x')
return this.x;
if(nomOption === 'y')
return this.y;
if(nomOption === 'width')
return this.width;
if(nomOption === 'height')
return this.height;
if(nomOption === 'opacity')
return this.opacity;
if(nomOption === 'offsetImgFragment')
return this._offsetImgFragment;
if(nomOption === 'imageUrl')
return this._imageUrl;
if(nomOption === 'rectBitmap')
return this._rectBitmap;
if(nomOption === 'backColor')
return this._backColor;
if(nomOption === 'frameColor')
return this._frameColor;
if(nomOption === 'text')
return this._text;
if(nomOption === 'textColor')
return this._textColor;
if(nomOption === 'textAlign')
return this._textAlign;
if(nomOption === 'fontFace')
return this._fontFace;
if(nomOption === 'fontSize')
return this._fontSize;
if(nomOption === 'fontItalic')
return this._fontItalic;
if(nomOption === 'padding')
return this._padding;
if(nomOption === 'visible')
return this.visible;
if(nomOption === 'focusable')
return this._focusable;
if(nomOption === 'validOnSpace')
return this._validOnSpace;
if(nomOption === 'selectColor')
return this._selectColor;
if(nomOption === 'selectFrameColor')
return this._selectFrameColor;
if(nomOption === 'dragCode')
return this._dragCode;
if(nomOption === 'dropCode')
return this._dropCode;
if(nomOption === 'dragData')
return this._dragData;
if(nomOption === 'selected')
return this._selectSprite.visible;
if(nomOption === 'selectOpacity')
return this._selectSprite.opacity;
if(nomOption === 'popupText')
return this._popupText;
};
/**********************************************************************
* Méthode : setOptions (surcharge)
* Fonction : Permet de modifier les options
* Params : pOptions : Json des options à modifier
**********************************************************************/
Gui_Base.prototype.sphinxSetOptions = Gui_Base.prototype.setOptions;
Gui_Base.prototype.setOptions = function(pOptions) {
for(var nomOption in pOptions) {
var value = pOptions[nomOption];
if(nomOption === "opacity")
this.opacity = value;
if(nomOption === "parent")
this._parent = value;
}
Gui_Base.prototype.sphinxSetOptions.call(this, pOptions);
}
/**********************************************************************
* Méthode : callHandler (surcharge)
* Fonction : Appel la fonction attachée à l'event
* Params : --
**********************************************************************/
Gui_Base.prototype.sphinxCallHandler = Gui_Base.prototype.callHandler;
Gui_Base.prototype.callHandler = function(symbol) {
if(this._active) {
Gui_Base.prototype.sphinxCallHandler.call(this, symbol);
}
};
/**********************************************************************
*----------------------------------------------------------------------
* Création d'une nouvelle "classe" Gui_Face
* hérite de la classe Gui_Base
*----------------------------------------------------------------------
**********************************************************************/
function Gui_Face() {
this.initialize.apply(this, arguments);
}
Gui_Face.prototype = Object.create(Gui_Base.prototype);
Gui_Face.prototype.constructor = Gui_Face;
/**********************************************************************
* Méthode : initialize (surcharge)
* Fonction : Génère un nouveau Gui au visage du personnage
* Params : pOptions : Json contenant la liste des options à modifier
**********************************************************************/
Gui_Face.prototype.initialize = function(pOptions) {
Gui_Base.prototype.initialize.call(this);
this._faceInfo = undefined;
if(pOptions)
this.setOptions(pOptions);
};
/**********************************************************************
* Méthode : setOptions (surcharge)
* Fonction : modification des options
* Params : pOptions : JSON des options à modifier
**********************************************************************/
var _Gui_Face_setOptions = Gui_Base.prototype.setOptions;
Gui_Face.prototype.setOptions = function(pOptions) {
_Gui_Face_setOptions.call(this, pOptions);
for(var nomOption in pOptions){
var value = pOptions[nomOption];
if(nomOption === 'faceInfo'){
this._faceInfo = value;
this._needCreateBitmap = true;
this.refresh();
}
}
};
/**********************************************************************
* Méthode : refresh
* Fonction : Permet de recréer l'affichage du Gui
* Params : --
**********************************************************************/
Gui_Face.prototype.refresh = function() {
Gui_Base.prototype.refresh.call(this);
if(this._faceInfo) {
this.drawFace();
}
};
/**********************************************************************
* Méthode : drawActorFace
* Fonction : Construit l'image du visage du héros
* Params : --
**********************************************************************/
Gui_Face.prototype.drawFace = function() {
var bitmap;
var sw = Window_Base._faceWidth;
var sh = Window_Base._faceHeight;
var sx = 0;
var sy = 0;
if(this._faceInfo && this._faceInfo.Body) {
bitmap = $gameCharacterCreations.buildBitmapFace(0, this._faceInfo);
} else if(this._faceInfo && this._faceInfo.faceName) {
bitmap = ImageManager.loadFace(this._faceInfo.faceName);
sx = this._faceInfo.faceIndex % 4 * sw;
sy = Math.floor(this._faceInfo.faceIndex / 4) * sh;
}
var _this = this;
bitmap.addLoadListener(function() {
_this.bitmap.blt(bitmap, sx, sy, sw, sh, 0, 0, _this.width, _this.height);
});
};
// Window_Gui
/**********************************************************************
* Méthode : removeGui
* Fonction : Permet de supprimer un Gui positionné sur la fenêtre
* Params : pSymbol : nom du Gui
**********************************************************************/
Window_Gui.prototype.removeGui = function(pSymbol) {
delete this._tabGui[pSymbol];
};
// Input
/**********************************************************************
* Méthode : getLetter (surcharge)
* Fonction : permet de récupérer la lettre enregistré
* Params : --
**********************************************************************/
Input.sphinxGetLetter = Input.getLetter;
Input.getLetter = function(){
letter = this.sphinxGetLetter();
this._letter = "";
return letter;
};
// Gui_TextInput
/**********************************************************************
* Méthode : initialize
* Fonction : initialisation des propriétés du Gui_TextInput
* Params : --
**********************************************************************/
Gui_TextInput.prototype.sphinxInitialize = Gui_TextInput.prototype.initialize;
Gui_TextInput.prototype.initialize = function(pOptions) {
this._cursorColor = "#000000";
Gui_TextInput.prototype.sphinxInitialize.call(this, pOptions);
this._spriteCursor.width = 1;
this._keyboard = false;
};
Gui_TextInput.prototype.refresh = function() {
if(this._needRefreshCursor){
this._spriteCursor.bitmap.resize(1, this.height - ((this._padding + 2) * 2));
this._spriteCursor.height = this.height - ((this._padding + 2) * 2);
this._spriteCursor.bitmap.fillRect(0, 0, 1, this._spriteCursor.height - 1, this._cursorColor);
this._spriteCursor.y = 2 + this._padding;
this._needRefreshCursor = false;
}
Gui_Base.prototype.refresh.call(this);
};
Gui_TextInput.prototype.sphinxSetOptions = Gui_TextInput.prototype.setOptions;
Gui_TextInput.prototype.setOptions = function(pOptions) {
Gui_TextInput.prototype.sphinxSetOptions.call(this, pOptions);
for(var nomOption in pOptions){
var value = pOptions[nomOption];
if(nomOption === 'cursorColor'){
this._cursorColor = value;
this.refresh();
}
}
};
Gui_TextInput.prototype.updateValue = function(){
var lettre = Input.getLetter();
if(lettre !== ''){
this._text = this._text.slice(0, this._posCursor) + lettre + this._text.slice(this._posCursor);
this._posCursor += lettre.length;
this.refresh();
this.onChangeValue();
}
if(Input.isRepeated('backspace') && this._posCursor > 0){
this._text = this._text.slice(0, Math.max(this._posCursor - 1)) + this._text.slice(this._posCursor);
this._posCursor --;
this.refresh();
this.onChangeValue();
}
if(Input.isRepeated('delete') && this._posCursor < this._text.length){
this._text = this._text.slice(0, Math.max(this._posCursor)) + this._text.slice(this._posCursor + 1);
this.refresh();
this.onChangeValue();
}
if(Input.isRepeated('left') && this._posCursor > 0){
this._posCursor --;
if(this.positionCursor())
this.refresh();
}
if(Input.isRepeated('right') && this._posCursor < this._text.length){
this._posCursor ++;
if(this.positionCursor())
this.refresh();
}
if(Input.isRepeated('home') && this._posCursor > 0){
this._posCursor = 0;
if(this.positionCursor())
this.refresh();
}
if(Input.isRepeated('end') && this._posCursor < this._text.length){
this._posCursor = this._text.length;
if(this.positionCursor())
this.refresh();
}
this._cursorFrame ++;
if(this._cursorFrame > this._cursorNbFrame)
this._spriteCursor.visible = false;
else
this._spriteCursor.visible = true;
if(this._cursorFrame > this._cursorNbFrame * 2)
this._cursorFrame = 0;
};
Gui_TextInput.prototype.sphinxUpdate = Gui_TextInput.prototype.update;
Gui_TextInput.prototype.update = function(){
Gui_TextInput.prototype.sphinxUpdate.call(this);
if(this._parent instanceof Window_Keyboard && this._active) {
this.updateValue();
}
};
Gui_TextInput.prototype.sphinxOnFocus = Gui_TextInput.prototype.onFocus;
Gui_TextInput.prototype.onFocus = function(){
Gui_TextInput.prototype.sphinxOnFocus.call(this);
if(!(this._parent instanceof Window_Keyboard)) {
SceneManager._scene.showKeyboard(this);
}
};
Gui_TextInput.prototype.sphinxOnChangeValue = Gui_TextInput.prototype.onChangeValue
Gui_TextInput.prototype.onChangeValue = function(){
Gui_TextInput.prototype.sphinxOnChangeValue.call(this);
};
Gui_TextInput.prototype.onClick = function(){
var x = TouchInput._x - this.x - this._padding;
if(!!this._parent) {
x -= this._parent.x + this._parent._padding;
}
this._posCursor = 0;
if(x > 0) {
if(x < this._textBitmap.measureTextWidth(this.textInGui())) {
for(var posCursor = 0; posCursor < this.textInGui().length; posCursor++) {
var testFragment = this.textInGui().slice(0, posCursor);
var posCursorPxl = this._textBitmap.measureTextWidth(testFragment);
if(posCursorPxl > x)
break;
}
this._posCursor = posCursor - 1;
} else {
this._posCursor = this.textInGui().length;
}
}
this.positionCursor();
};