/*:
* @plugindesc 主场景小提示插件
* @author BenJ
*
*
*
* @param tipIconPadding
* @desc 如果带icon图标的话,文字与图标的间距
* @default 36
*
*
* @help
*
* Plugin Command:
*
* myTipWindow showTip msg #添加一条消息
* myTipWindow showTip msg iconId #添加一条带icon的消息
*
*
*/
var parameters = PluginManager.parameters('myTipWindow');
var tipIconPadding = Number(parameters['tipIconPadding'] || 36);
var _myGame_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command,args){
_myGame_Interpreter_pluginCommand.call(this);
if(command == 'myTipWindow'){
$gameMap._showTip = true;//是否需要打开tip窗口
$gameMap._isShownTip = true;//tip窗口是否被打开
$gameMap._tip = {
msg : args[0] ,//tip的文本
icon : args[1] //tip的图标
//showed : false //是否已经显示过该信息 防止一直刷新
};
this.setWaitMode('tipMessage');
}
};
//修改Game_Map初始化,增加tip相关属性
var _jGame_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
_jGame_Map_setup.call(this,mapId);
this._showTip = false;
this._isShownTip = false;
this._tip = {};
};
//重写Scene_Map初始化部分窗口函数
var _jScene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function() {
_jScene_Map_createAllWindows.call(this);
this.createTipWindow();
};
//创建tipWindow加入到Scene_Map
Scene_Map.prototype.createTipWindow = function() {
this._tipWindow = new Window_JTip();
this.addWindow(this._tipWindow);
};
//todo 自定义提示窗体
function Window_JTip() {
this.initialize.apply(this, arguments);
}
Window_JTip.prototype = Object.create(Window_Base.prototype);
Window_JTip.prototype.constructor = Window_JTip;
Window_JTip.prototype.initialize = function() {
var width = this.windowWidth();
var height = this.windowHeight();
Window_Base.prototype.initialize.call(this, (Graphics.width - width)/2, 200, width, height);
this.openness = 0;//尝试了好多次,原来这就是关键点所在,初始化的时候,把openness设置为0的时候,调用open函数的时候,才会去刷新
};
//窗口宽度
Window_JTip.prototype.windowWidth = function() {
return Number(this.width || 240);
};
//窗口高度
Window_JTip.prototype.windowHeight = function() {
return this.fittingHeight(1);
};
//刷新tip窗口
Window_JTip.prototype.refresh = function(_tipArgs) {
this.contents.clear();
//this.visible = $gameMap.isTipWindowShow();
if(_tipArgs){
//this.resetTipWindow(_tipArgs);//这个函数里面执行过显示窗口函数核心Bitmap的resize,如果在后面resize,会清空内容栏,具体我也没看到哪里在清空,但是事实如此
//todo 绘制消息板
var _cnTest = /[\u4E00-\u9FA5]/;
var _msg = _tipArgs.msg.toString();
var _width = 0;
//通过文字计算窗口大小
for(var i=0 ; i<_msg.length ; i++){
//判断是否为中文,不是中文,只用字体大小的一半
if(_cnTest.test(_msg[i])){
_width += this.standardFontSize() ;
}else{
_width += this.standardFontSize() / 2 ;
}
}
//添加默认内容左右padding
_width += this.standardPadding() * 2;
//是否包含icon
if(_tipArgs.icon != undefined && _tipArgs.icon != 0){
_width += tipIconPadding;
}
this.width = _width;
this.x = (Graphics.width - _width)/2;
this.contents.resize(this.contentsWidth(),this.contentsHeight());//这里设置的内容的宽度,如果照官方的算法,这个宽度可能会显示不完我们的内容
//todo 绘制内容
//_tipArgs.showed = true; //显示过的信息改变此标示
if(_tipArgs.icon){
//显示带icon的信息
this.drawIcon(_tipArgs.icon,0,0);
this.drawText(_tipArgs.msg.toString(),tipIconPadding,0);
}else{
//显示普通信息
this.drawText(_tipArgs.msg.toString(),0,0);
}
}
};
Window_JTip.prototype.update = function(){
Window_Base.prototype.update.call(this);
//根据window_message的实现来看,弹出样式是打开和关闭的时候调用的updateOpen和updateClose
while(!this.isOpening() && !this.isClosing()){
//在非打开中和非关闭中,调用一遍所有需要执行的东西
//message处理的方式是检测文本信息是否已经消费完来启动
if(this.updateInput()){
return;
}else if(this.needShow()){
this.startTip();
}else{
return;
}
}
};
//启动tip窗口
Window_JTip.prototype.startTip = function() {
this.refresh($gameMap._tip);
this.open();
$gameSystem.disableMenu();
$gameMap._showTip = false;//启动了窗口就把是否启动tip关掉,否则update一直刷新启动造成死循环了
this.pause = true;//启动了窗口,并且刷新了窗口之后,设置暂停
};
Window_JTip.prototype.needShow = function() {
return $gameMap._showTip;
};
Window_JTip.prototype.isTriggered = function() {
return (Input.isRepeated('ok') || Input.isRepeated('cancel') || TouchInput.isRepeated());
};
//当窗口暂停,并且有按键触发,我们就关闭窗口
Window_JTip.prototype.updateInput = function() {
if(this.pause){
if(this.isTriggered()){
$gameSystem.enableMenu();
this.pause = false;
$gameMap._isShownTip = false;
this.close();
}
return true;
}else{
return false;
}
};
//这里由于官方内定了好几种等待模式,而且写得比较死,我就直接在官方的函数里拓展了,增加了tipMessage的标示
Game_Interpreter.prototype.updateWaitMode = function() {
var waiting = false;
switch (this._waitMode) {
case 'message':
waiting = $gameMessage.isBusy();
break;
case 'transfer':
waiting = $gamePlayer.isTransferring();
break;
case 'scroll':
waiting = $gameMap.isScrolling();
break;
case 'route':
waiting = this._character.isMoveRouteForcing();
break;
case 'animation':
waiting = this._character.isAnimationPlaying();
break;
case 'balloon':
waiting = this._character.isBalloonPlaying();
break;
case 'gather':
waiting = $gamePlayer.areFollowersGathering();
break;
case 'action':
waiting = BattleManager.isActionForced();
break;
case 'video':
waiting = Graphics.isVideoPlaying();
break;
case 'image':
waiting = !ImageManager.isReady();
break;
case 'tipMessage':
waiting = $gameMap._isShownTip;
break;
}
if (!waiting) {
this._waitMode = '';
}
return waiting;
};