Project1
标题: 【脚本整理】消息框DIY [打印本页]
作者: 清澈淌漾 时间: 2021-6-6 00:27
标题: 【脚本整理】消息框DIY
本帖最后由 清澈淌漾 于 2021-6-6 00:28 编辑
本帖会逐步拆解我最近在研究的一套全新对话插件的代码与注释,
由于是第一次制作如此底层的脚本。(写的时候也很震惊- - 显示个文字居然能这么复杂。)
写的也比较乱,做完显示文字和立绘后。跟选择项做接口。
代码和脑袋已经是一团浆糊了,急需进行一波整理
供各位有学习脚本意愿的同好参考
你可以在其中找到制作思路与还未接触到的原生方法
插件功能
*该插件目前还在开发阶段,无法投入使用
1.直接读取data下的自定义json文件
2.覆盖了原本的消息框 (目前使用后 事件内的 选项 数字全部失效,会在陆续后续更新)
3.粗加工富文本并对文本框进行自适应 json配置后自动替换立绘 更新名称栏。
附上效果图
数据源与事件调用
效果
一:获得要显示的对话
懒是推进人类文明的基石。
事件内一个个添加文本 对文本进行排版实在是折磨我。
于是我便有了改造文本框的想法。
首先要解决的就是怎么通过配表的方式获得一个个对话文本
/**
* 加载地图中的对话
* 改方法原生为 角色切换地图时会加载对应的map数据
* 这里追加读取了 自定义的map[地图编号]_info 用$dataMapinfo存储当前地图的对话信息
* 之后使用脚本方法InfoLoad() 传入的key值 来显示对话
* */
DataManager.loadMapData = function(mapId) {
if (mapId > 0) {
let filename = 'Map%1.json'.format(mapId.padZero(3));
let filename2 = 'Map%1_info.json'.format(mapId.padZero(3));
this._mapLoader = ResourceHandler.createLoader('data/' + filename, this.loadDataFile.bind(this, '$dataMap', filename));
this.loadDataFile('$dataMap', filename);
this.loadDataFile('$dataMapinfo', filename2);
}
else {this.makeEmptyMap();}
};
/**
* 加载地图中的对话
* 改方法原生为 角色切换地图时会加载对应的map数据
* 这里追加读取了 自定义的map[地图编号]_info 用$dataMapinfo存储当前地图的对话信息
* 之后使用脚本方法InfoLoad() 传入的key值 来显示对话
* */
DataManager.loadMapData = function(mapId) {
if (mapId > 0) {
let filename = 'Map%1.json'.format(mapId.padZero(3));
let filename2 = 'Map%1_info.json'.format(mapId.padZero(3));
this._mapLoader = ResourceHandler.createLoader('data/' + filename, this.loadDataFile.bind(this, '$dataMap', filename));
this.loadDataFile('$dataMap', filename);
this.loadDataFile('$dataMapinfo', filename2);
}
else {this.makeEmptyMap();}
};
/**
* 加载一段文本
* */
_.InfoLoad = function(i) {
let data =$dataMapinfo[i]
if(!data) return
let str=data.info.replace(/\s+/g,"")
console.log(str)
// if(str.length>0) {
// $gameMessage.add(str);
// $gameMessage.addport(data.port)
// $gameMessage.addnick(data.nick)
// }
}
/**
* 加载一段文本
* */
_.InfoLoad = function(i) {
let data =$dataMapinfo[i]
if(!data) return
let str=data.info.replace(/\s+/g,"")
console.log(str)
// if(str.length>0) {
// $gameMessage.add(str);
// $gameMessage.addport(data.port)
// $gameMessage.addnick(data.nick)
// }
}
数据源
打印效果
-
QQ截图20210606002725.png
(41.24 KB, 下载次数: 17)
作者: 清澈淌漾 时间: 2021-6-6 08:53
//对话框大小
_.width = parseInt(params["Width"])||650;
_.height = parseInt(params["Height"])||190;
//对话框渐入 渐出帧数
_.animatime = parseInt(params["AnimaTime"])||15;
//换行缩进
_.indent = parseInt(params["Indent"])||45;
_.firstline = parseInt(params["Firstline"])||25;
//默认字体大小
_.fontsize = parseInt(params["Fontsize"])||19;
//边距
_.padding1 = parseInt(params["Padding1"])||30;
_.padding2 = parseInt(params["Padding2"])||20;
//行距
_.lineheight = parseInt(params["Lineheight"])||30;
//字距
_.spacing = parseInt(params["Spacing"])||22;
//每个字出现帧数
_.outframe = parseInt(params["Outframe"])||3;
//逗号标点后间隔帧数
_.commaframe = parseInt(params["Commaframe"])||8;
//对话框动画每帧的偏移
_.anima_y=(_.height-_.padding2)/_.animatime-_.padding2
/**
* 更换对话框
* */
_.F_scene_map_createmessagewindow = Scene_Map.prototype.createMessageWindow
Scene_Map.prototype.createMessageWindow = function() {
//新 窗口消息()
this._messageWindow = new Window_Limpid_DialogBox();
//添加窗口
this.addWindow(this._messageWindow);
//添加立绘精灵
this.createPort()
};
/**创建场景立绘*/
Scene_Map.prototype.createPort = function() {
//静态立绘
_.paint=new Sprite();
this.addChild(_.paint);
_.paint.scale.x=0.7
_.paint.scale.y=0.7
_.paint.x=190
_.paint.y=640
_.paint.use=false
//动态立绘
_.port=new Sprite();
this.addChild(_.port);
_.port.scale.x=0.7
_.port.scale.y=0.7
_.port.x=190
_.port.y=640
}
/**文本框*/
Window_Limpid_DialogBox= function () {this.initialize.apply(this, arguments);}
Window_Limpid_DialogBox.prototype = Object.create(Window_Base.prototype);
Window_Limpid_DialogBox.prototype.constructor = Window_Limpid_DialogBox;
Window_Limpid_DialogBox.prototype.initialize = function()
{
//精灵回收
this.dustbin();
Window_Base.prototype.initialize.call(this, (Graphics.boxWidth -_.width-_.padding1), Graphics.boxHeight+30 , _.width, _.height);
this.stressing();
_.window_Limpid_DialogBox=this;
//名称
this.namebox = new Window_Limpid_NameBox();
this.addChild(this.namebox);
};
Window_Limpid_DialogBox.prototype.stressing = function()
{
this._active=false;
this._anime=0;
this.opacity=0
//背景图
this.back=new Sprite(ImageManager.loadDialog("box"));
this.addChild(this.back);
};
/**名称框*/
Window_Limpid_NameBox= function () {this.initialize.apply(this, arguments);}
Window_Limpid_NameBox.prototype = Object.create(Window_Base.prototype);
Window_Limpid_NameBox.prototype.constructor = Window_Limpid_NameBox;
Window_Limpid_NameBox.prototype.initialize = function()
{
Window_Base.prototype.initialize.call(this, -20, -20 , 282, 41);
this.stressing();
}
Window_Limpid_NameBox.prototype.stressing = function()
{
this.opacity=0;
this.back=new Sprite(ImageManager.loadDialog("boxname"));
this.addChild(this.back);
this.nick=new Sprite(new Bitmap(282, 41));
this.nick.bitmap.fontSize = 22
this.addChild(this.nick);
};
/**绘制名称*/
Window_Limpid_NameBox.prototype.drawname = function(name)
{
this.nick.bitmap.clear()
this.nick.bitmap.drawText(name, 0, 0, 282, 41, "center");
};
/*一段文本结束后 从数组中删除*/
Game_Message.prototype.endText = function() {
this._texts.splice(0,1)
// this._port.splice(0,1)
// this._nick.splice(0,1)
};
/**
* 工具类
* */
Window_Base.prototype.dustbin = function () {this.clear_Arr = new Array()};
Window_Base.prototype.clear = function () {
if (this.clear_Arr.length > 0) {
for (var i = 0; i < this.children.length; i++)
if (this.clear_Arr.indexOf(this.children[i].spriteId) > -1)
this.children.splice(i--, 1);
this.clear_Arr = new Array()
}
this.contents.clear();
};
/*图片加载*/
ImageManager.loadDialog = function (filename, hue) {return this.loadBitmap('img/dialog/', filename, hue, true);}
ImageManager.loadDialogPort = function (filename, hue) {return this.loadBitmap('img/dialog/port/s_', filename, hue, true);}
ImageManager.reserveDialogPort = function (filename, hue) {return this.reserveBitmap('img/dialog/port/s_', filename, hue, true);};
//对话框大小
_.width = parseInt(params["Width"])||650;
_.height = parseInt(params["Height"])||190;
//对话框渐入 渐出帧数
_.animatime = parseInt(params["AnimaTime"])||15;
//换行缩进
_.indent = parseInt(params["Indent"])||45;
_.firstline = parseInt(params["Firstline"])||25;
//默认字体大小
_.fontsize = parseInt(params["Fontsize"])||19;
//边距
_.padding1 = parseInt(params["Padding1"])||30;
_.padding2 = parseInt(params["Padding2"])||20;
//行距
_.lineheight = parseInt(params["Lineheight"])||30;
//字距
_.spacing = parseInt(params["Spacing"])||22;
//每个字出现帧数
_.outframe = parseInt(params["Outframe"])||3;
//逗号标点后间隔帧数
_.commaframe = parseInt(params["Commaframe"])||8;
//对话框动画每帧的偏移
_.anima_y=(_.height-_.padding2)/_.animatime-_.padding2
/**
* 更换对话框
* */
_.F_scene_map_createmessagewindow = Scene_Map.prototype.createMessageWindow
Scene_Map.prototype.createMessageWindow = function() {
//新 窗口消息()
this._messageWindow = new Window_Limpid_DialogBox();
//添加窗口
this.addWindow(this._messageWindow);
//添加立绘精灵
this.createPort()
};
/**创建场景立绘*/
Scene_Map.prototype.createPort = function() {
//静态立绘
_.paint=new Sprite();
this.addChild(_.paint);
_.paint.scale.x=0.7
_.paint.scale.y=0.7
_.paint.x=190
_.paint.y=640
_.paint.use=false
//动态立绘
_.port=new Sprite();
this.addChild(_.port);
_.port.scale.x=0.7
_.port.scale.y=0.7
_.port.x=190
_.port.y=640
}
/**文本框*/
Window_Limpid_DialogBox= function () {this.initialize.apply(this, arguments);}
Window_Limpid_DialogBox.prototype = Object.create(Window_Base.prototype);
Window_Limpid_DialogBox.prototype.constructor = Window_Limpid_DialogBox;
Window_Limpid_DialogBox.prototype.initialize = function()
{
//精灵回收
this.dustbin();
Window_Base.prototype.initialize.call(this, (Graphics.boxWidth -_.width-_.padding1), Graphics.boxHeight+30 , _.width, _.height);
this.stressing();
_.window_Limpid_DialogBox=this;
//名称
this.namebox = new Window_Limpid_NameBox();
this.addChild(this.namebox);
};
Window_Limpid_DialogBox.prototype.stressing = function()
{
this._active=false;
this._anime=0;
this.opacity=0
//背景图
this.back=new Sprite(ImageManager.loadDialog("box"));
this.addChild(this.back);
};
/**名称框*/
Window_Limpid_NameBox= function () {this.initialize.apply(this, arguments);}
Window_Limpid_NameBox.prototype = Object.create(Window_Base.prototype);
Window_Limpid_NameBox.prototype.constructor = Window_Limpid_NameBox;
Window_Limpid_NameBox.prototype.initialize = function()
{
Window_Base.prototype.initialize.call(this, -20, -20 , 282, 41);
this.stressing();
}
Window_Limpid_NameBox.prototype.stressing = function()
{
this.opacity=0;
this.back=new Sprite(ImageManager.loadDialog("boxname"));
this.addChild(this.back);
this.nick=new Sprite(new Bitmap(282, 41));
this.nick.bitmap.fontSize = 22
this.addChild(this.nick);
};
/**绘制名称*/
Window_Limpid_NameBox.prototype.drawname = function(name)
{
this.nick.bitmap.clear()
this.nick.bitmap.drawText(name, 0, 0, 282, 41, "center");
};
/*一段文本结束后 从数组中删除*/
Game_Message.prototype.endText = function() {
this._texts.splice(0,1)
// this._port.splice(0,1)
// this._nick.splice(0,1)
};
/**
* 工具类
* */
Window_Base.prototype.dustbin = function () {this.clear_Arr = new Array()};
Window_Base.prototype.clear = function () {
if (this.clear_Arr.length > 0) {
for (var i = 0; i < this.children.length; i++)
if (this.clear_Arr.indexOf(this.children[i].spriteId) > -1)
this.children.splice(i--, 1);
this.clear_Arr = new Array()
}
this.contents.clear();
};
/*图片加载*/
ImageManager.loadDialog = function (filename, hue) {return this.loadBitmap('img/dialog/', filename, hue, true);}
ImageManager.loadDialogPort = function (filename, hue) {return this.loadBitmap('img/dialog/port/s_', filename, hue, true);}
ImageManager.reserveDialogPort = function (filename, hue) {return this.reserveBitmap('img/dialog/port/s_', filename, hue, true);};
脚本大框
/**
* 帧事件
* 重点
* 每帧更新 判断有没有文本输入
* */
Window_Limpid_DialogBox.prototype.update = function() {
//没有要处理的文本
if (!$gameMessage.hasText()) {
if (!this._show) return
//淡出
else if (this._anime > 0) {
this.y = (Graphics.boxHeight - _.height) + (_.animatime - (--this._anime)) * _.anima_y;
this.alpha = this._anime / _.animatime
} else this._show = false;
}
//存在要处理的文本
else {
if (this._show) {
$gameMessage.endText()
//进入这里时表示有文本输入进来
//之后这里会大量处理逻辑
//这里先立即排出文本 测试文本框淡入淡出效果
}
//淡入 -2是为了让文本框与底部留出一部分边距
else if (this._anime < _.animatime-2) {
this.y = (Graphics.boxHeight - _.height) + (_.animatime - (++this._anime)) * _.anima_y;
this.alpha = this._anime / _.animatime
}
else this._show = true
}
};
/**
* 帧事件
* 重点
* 每帧更新 判断有没有文本输入
* */
Window_Limpid_DialogBox.prototype.update = function() {
//没有要处理的文本
if (!$gameMessage.hasText()) {
if (!this._show) return
//淡出
else if (this._anime > 0) {
this.y = (Graphics.boxHeight - _.height) + (_.animatime - (--this._anime)) * _.anima_y;
this.alpha = this._anime / _.animatime
} else this._show = false;
}
//存在要处理的文本
else {
if (this._show) {
$gameMessage.endText()
//进入这里时表示有文本输入进来
//之后这里会大量处理逻辑
//这里先立即排出文本 测试文本框淡入淡出效果
}
//淡入 -2是为了让文本框与底部留出一部分边距
else if (this._anime < _.animatime-2) {
this.y = (Graphics.boxHeight - _.height) + (_.animatime - (++this._anime)) * _.anima_y;
this.alpha = this._anime / _.animatime
}
else this._show = true
}
};
作者: 清澈淌漾 时间: 2021-6-6 11:25
初始化要处理的文字
/**
* 文本控制器
* */
Window_Limpid_DialogBox.prototype.textHandler = function() {
if(!this._Info||this._Info.end==2)
{
this._Info= _.Text_template_init()
_.Text_template_load($gameMessage.getData(),this._Info);
this._Info.x=0;
this._Info.y=0;
this._Info.z=0
return false
}
else {console.log(this._Info)}
}
/**
* 文本控制器
* */
Window_Limpid_DialogBox.prototype.textHandler = function() {
if(!this._Info||this._Info.end==2)
{
this._Info= _.Text_template_init()
_.Text_template_load($gameMessage.getData(),this._Info);
this._Info.x=0;
this._Info.y=0;
this._Info.z=0
return false
}
else {console.log(this._Info)}
}
上段的逻辑处 调用该方法 this.Info 初始化如下
/**
* 初始一段对话的信息
* */
_.Text_template_init = function() {
return {
txtarr:new Array()
//记录文字走到哪行
,line:0
//字体大小
,fs:_.fontsize
//第一行缩进
,x:0
,y:0
,z:0
,spacing:_.spacing
,lineheight:_.lineheight
,color:"fff"
//延迟点
,lagarr:[]
//停顿点
,pausearr:[]
//记录停顿点
,index:0
,index_old:-1
,index_skip:0
//静态图像
,paint:[]
//每个停顿点出现的动态图像
,port:[]
//每个停顿点使用的名称
,nick:[]
//每个停顿点播放的声音
,sound:[]
//等待帧
,interval:0
//加速显示到下一停顿点
,fast:false
//等待点击
,stop:0
//本文本全显示
,skip:false
//下一文本判断
// 执行中 ---0
// 等待输入 ---1
// 等待填充 ---2
,end:0
}
}
/**
* 初始一段对话的信息
* */
_.Text_template_init = function() {
return {
txtarr:new Array()
//记录文字走到哪行
,line:0
//字体大小
,fs:_.fontsize
//第一行缩进
,x:0
,y:0
,z:0
,spacing:_.spacing
,lineheight:_.lineheight
,color:"fff"
//延迟点
,lagarr:[]
//停顿点
,pausearr:[]
//记录停顿点
,index:0
,index_old:-1
,index_skip:0
//静态图像
,paint:[]
//每个停顿点出现的动态图像
,port:[]
//每个停顿点使用的名称
,nick:[]
//每个停顿点播放的声音
,sound:[]
//等待帧
,interval:0
//加速显示到下一停顿点
,fast:false
//等待点击
,stop:0
//本文本全显示
,skip:false
//下一文本判断
// 执行中 ---0
// 等待输入 ---1
// 等待填充 ---2
,end:0
}
}
info加载
/**
* 信息加载
* */
_.Text_template_load = function(filling,vessel) {
//文本框的宽
let boxwidth= _.width-_.padding1
//段落首字缩进
let indent=_.indent+_.padding1
vessel.x= indent
//标记
let x=0,y=0
//预加载立绘
let portset = new Set(filling.port.port)
if (filling.port.paint&&filling.port.paint.length>0) portset.add(filling.port.paint)
portset.forEach(function (item) {ImageManager.reserveDialogPort(item)})
//填入 立绘 声音 名称
vessel.port=filling.port
vessel.sound=filling.sound
for(let i=0;i<filling.nick.length;i++)
{
if(filling.nick[i][0]=="!") vessel.nick.push(_.Sign_process(filling.nick[i]).mes)
else vessel.nick.push(filling.nick[i])
}
//开关 表示进入指令标记
let sign=false
//处理的指令
let instruct=""
//半角填充数
let uate = 2
//循环每个字符
for(var i=0;i<filling.text.length;i++) {
if (sign) {
//标记开关开启并遇到">" 处理该段标记
if(filling.text[i] == ">")
{
let data=_.Sign_process(instruct,filling)
switch (data.code) {
//换行
case 0:
filling.x = _.padding1+_.indent;y++;x = 0;break
//文本替换
case 1:
filling.text=filling.text.slice(0,i)+data.mes+filling.text.slice(i+1);i--;break
}
instruct="";sign=false
}
//记录后续指令
else instruct+=filling.text[i];
}
//遇到"<" 开启标记开关
else if (filling.text[i] == "<") {sign = true}
//读取普通文字
else {
//文本索引
vessel.z++
/*绘制精灵*/
let fs=vessel.fs + 5
let sprite = new Sprite(new Bitmap(fs, fs));
sprite.x = vessel.x
sprite.bitmap.fontSize = vessel.fs
sprite.bitmap.outlineWidth = 3
sprite.bitmap.outlineColor = 'rgba(36, 36, 36, 0.88)'
sprite.bitmap.drawText(filling.text[i], 0, 0, fs, fs, "center")
//放入数组
//x为0 每行的第一个字
if (x == 0) {vessel.txtarr.push(new Array(sprite));}
else {vessel.txtarr[y].push(sprite);}
//检查下一个字
if (i < filling.text.length - 1) {
//下个字是全角半角
var nat = filling.text[i + 1].charCodeAt() < 256 ? true : false
//当前字是全角半角
var at = filling.text[i].charCodeAt() < 256 ? true : false
//以字距对下一字的x进行位移
vessel.x += vessel.spacing * (at&&nat?0.5:1)
//如果下一字的x大于文本框 并且(他是全角 或者半角填充数已经为0)进行自动换行
if (vessel.x >= boxwidth && (!at || uate-- == 0)) {vessel.x = _.padding1;y++;x=0;uate = 2}
else {x++}
}
}
}
}
/**
* 信息加载
* */
_.Text_template_load = function(filling,vessel) {
//文本框的宽
let boxwidth= _.width-_.padding1
//段落首字缩进
let indent=_.indent+_.padding1
vessel.x= indent
//标记
let x=0,y=0
//预加载立绘
let portset = new Set(filling.port.port)
if (filling.port.paint&&filling.port.paint.length>0) portset.add(filling.port.paint)
portset.forEach(function (item) {ImageManager.reserveDialogPort(item)})
//填入 立绘 声音 名称
vessel.port=filling.port
vessel.sound=filling.sound
for(let i=0;i<filling.nick.length;i++)
{
if(filling.nick[i][0]=="!") vessel.nick.push(_.Sign_process(filling.nick[i]).mes)
else vessel.nick.push(filling.nick[i])
}
//开关 表示进入指令标记
let sign=false
//处理的指令
let instruct=""
//半角填充数
let uate = 2
//循环每个字符
for(var i=0;i<filling.text.length;i++) {
if (sign) {
//标记开关开启并遇到">" 处理该段标记
if(filling.text[i] == ">")
{
let data=_.Sign_process(instruct,filling)
switch (data.code) {
//换行
case 0:
filling.x = _.padding1+_.indent;y++;x = 0;break
//文本替换
case 1:
filling.text=filling.text.slice(0,i)+data.mes+filling.text.slice(i+1);i--;break
}
instruct="";sign=false
}
//记录后续指令
else instruct+=filling.text[i];
}
//遇到"<" 开启标记开关
else if (filling.text[i] == "<") {sign = true}
//读取普通文字
else {
//文本索引
vessel.z++
/*绘制精灵*/
let fs=vessel.fs + 5
let sprite = new Sprite(new Bitmap(fs, fs));
sprite.x = vessel.x
sprite.bitmap.fontSize = vessel.fs
sprite.bitmap.outlineWidth = 3
sprite.bitmap.outlineColor = 'rgba(36, 36, 36, 0.88)'
sprite.bitmap.drawText(filling.text[i], 0, 0, fs, fs, "center")
//放入数组
//x为0 每行的第一个字
if (x == 0) {vessel.txtarr.push(new Array(sprite));}
else {vessel.txtarr[y].push(sprite);}
//检查下一个字
if (i < filling.text.length - 1) {
//下个字是全角半角
var nat = filling.text[i + 1].charCodeAt() < 256 ? true : false
//当前字是全角半角
var at = filling.text[i].charCodeAt() < 256 ? true : false
//以字距对下一字的x进行位移
vessel.x += vessel.spacing * (at&&nat?0.5:1)
//如果下一字的x大于文本框 并且(他是全角 或者半角填充数已经为0)进行自动换行
if (vessel.x >= boxwidth && (!at || uate-- == 0)) {vessel.x = _.padding1;y++;x=0;uate = 2}
else {x++}
}
}
}
}
其余辅助方法
/**
*标记 处理
*/
_.Sign_process = function(sign,vessel)
{
let sign_s=sign.split(':')
switch (sign_s[0]) {
case "&p":vessel.pausearr.push(vessel.z-1);break
case "&c":vessel.lagarr.push(vessel.z-1);break
case "&n":return {code:0};break
case "!v":return {code:1,mes:$gameVariables.value(sign_s[1])};break
case "!an":return {code:1,mes:_.getAName(sign_s[1])};break
case "!ac":return {code:1,mes:_.getAClassName(sign_s[1])};break
case "!ai":return {code:1,mes:_.getANickname(sign_s[1])};break
case "!pn":return {code:1,mes:_.getPName(sign_s[1])};break
case "!pc":return {code:1,mes:_.getPClassName(sign_s[1])};break
case "!pi":return {code:1,mes:_.getPNickname(sign_s[1])};break
}
return {code:-1}
}
/**
* 字符转文字
* */
_.getAName = function(n) {
let actor = n >= 1 ? $gameActors.actor(n) : null;
return actor ? actor.name() : '';
};
_.getAClassName = function(n) {
let actor = n >= 1 ? $gameActors.actor(n) : null;
return actor ? actor.currentClass().name : '';
};
_.getANickname = function(n) {
let actor = n >= 1 ? $gameActors.actor(n) : null;
return actor ? actor.nickname() : '';
};
_.getPName = function(n) {
let actor = n >= 1 ? $gameParty.members()[n - 1] : null;
return actor ? actor.name() : '';
};
_.getPClassName = function(n) {
let actor = n >= 1 ? $gameParty.members()[n - 1] : null;
return actor ? actor.currentClass().name : '';
};
_.getPNickname = function(n) {
let actor = n >= 1 ? $gameParty.members()[n - 1] : null;
return actor ? actor.nickname() : '';
};
/**
*标记 处理
*/
_.Sign_process = function(sign,vessel)
{
let sign_s=sign.split(':')
switch (sign_s[0]) {
case "&p":vessel.pausearr.push(vessel.z-1);break
case "&c":vessel.lagarr.push(vessel.z-1);break
case "&n":return {code:0};break
case "!v":return {code:1,mes:$gameVariables.value(sign_s[1])};break
case "!an":return {code:1,mes:_.getAName(sign_s[1])};break
case "!ac":return {code:1,mes:_.getAClassName(sign_s[1])};break
case "!ai":return {code:1,mes:_.getANickname(sign_s[1])};break
case "!pn":return {code:1,mes:_.getPName(sign_s[1])};break
case "!pc":return {code:1,mes:_.getPClassName(sign_s[1])};break
case "!pi":return {code:1,mes:_.getPNickname(sign_s[1])};break
}
return {code:-1}
}
/**
* 字符转文字
* */
_.getAName = function(n) {
let actor = n >= 1 ? $gameActors.actor(n) : null;
return actor ? actor.name() : '';
};
_.getAClassName = function(n) {
let actor = n >= 1 ? $gameActors.actor(n) : null;
return actor ? actor.currentClass().name : '';
};
_.getANickname = function(n) {
let actor = n >= 1 ? $gameActors.actor(n) : null;
return actor ? actor.nickname() : '';
};
_.getPName = function(n) {
let actor = n >= 1 ? $gameParty.members()[n - 1] : null;
return actor ? actor.name() : '';
};
_.getPClassName = function(n) {
let actor = n >= 1 ? $gameParty.members()[n - 1] : null;
return actor ? actor.currentClass().name : '';
};
_.getPNickname = function(n) {
let actor = n >= 1 ? $gameParty.members()[n - 1] : null;
return actor ? actor.nickname() : '';
};
/*传入立绘*/
Game_Message.prototype.addPort=function(port) {this._port.push(port);}
/*传入名称*/
Game_Message.prototype.addNick=function(nick) {this._nick.push(nick);}
/*传入声音*/
Game_Message.prototype.addSound=function(sound) {this._sound.push(sound);}
/*获得文本信息*/
Game_Message.prototype.getData = function(i) {
return i&&!i<this._texts.length?
{text:this._texts[i],nick:this._nick[i],port:this._port[i],sound:this._sound[i]}:
{text:this._texts[0],nick:this._nick[0],port:this._port[0],sound:this._sound[0]}
};
/*传入立绘*/
Game_Message.prototype.addPort=function(port) {this._port.push(port);}
/*传入名称*/
Game_Message.prototype.addNick=function(nick) {this._nick.push(nick);}
/*传入声音*/
Game_Message.prototype.addSound=function(sound) {this._sound.push(sound);}
/*获得文本信息*/
Game_Message.prototype.getData = function(i) {
return i&&!i<this._texts.length?
{text:this._texts[i],nick:this._nick[i],port:this._port[i],sound:this._sound[i]}:
{text:this._texts[0],nick:this._nick[0],port:this._port[0],sound:this._sound[0]}
};
打印效果
作者: 清澈淌漾 时间: 2021-6-6 13:48
/**
* 帧事件
* 重点
* 每帧更新 判断有没有文本输入
* */
Window_Limpid_DialogBox.prototype.update = function() {
//没有要处理的文本
if (!$gameMessage.hasText()) {
if (!this._show) return
//淡出
else if (this._anime > 0) {
this.y = (Graphics.boxHeight - _.height) + (_.animatime - (--this._anime)) * _.anima_y;
this.alpha = this._anime / _.animatime
this.showSport(false)
} else this._show = false;
}
//存在要处理的文本
else {
if (this._show) this.textHandler();
//淡入 -2是为了让文本框与底部留出一部分边距
else if (this._anime < _.animatime-2) {
this.y = (Graphics.boxHeight - _.height) + (_.animatime - (++this._anime)) * _.anima_y;
this.alpha = this._anime / _.animatime
this.showSport(true)
}
else this._show = true
}
};
/**
* 文本控制器
* */
Window_Limpid_DialogBox.prototype.textHandler = function() {
if(!this._Info||this._Info.end==2)
{
this._Info= _.Text_template_init()
_.Text_template_load($gameMessage.getData(),this._Info);
this._Info.x=0;
this._Info.y=0;
this._Info.z=0
return false
}
else {
if( this._Info.index_old!=this._Info.index)
{
this._Info.index_old=this._Info.index
/*更新立绘*/
this.updatePort(this._Info.index)
/*更新名称*/
this.updateNick(this._Info.index)
}
}
}
/**
* 更新动态立绘
*/
Window_Limpid_DialogBox.prototype.updatePort=function(index)
{
//隐藏动态立绘
if(index==-1||this._Info.port.length==0) {_.port.bitmap=new Bitmap();return}
//更新动态立绘
var Portdata = this._Info.port.length>index?this._Info.port[index]:this._Info.port[this._Info.port.length-1]
_.port.bitmap=ImageManager.loadDialogPort(Portdata)
_.port.anchor.x = 0.5
_.port.anchor.y = 0.5
/*用静态立绘充当过度*/
if( _.paint._active){_.paint.alpha=0;_.paint._active=false}
else {
_.paint.bitmap = ImageManager.loadDialogPort(Portdata)
_.paint.anchor.x = 0.5
_.paint.anchor.y = 0.5
}
}
/**
* 更新名称框
*/
Window_Limpid_DialogBox.prototype.updateNick=function(index)
{
if(index==-1||this._Info.nick.length==0) {this.namebox.drawName("");return}
this.namebox.drawName(this._Info.nick.length>index?this._Info.nick[index]:this._Info.nick[this._Info.nick.length-1])
}
/***
* 显示静态立绘
*/
Window_Limpid_DialogBox.prototype.showSport=function(show){
_.paint.alpha = this._anime / _.animatime
if(_.paint._active!=show)
{
_.paint._active=show
if (show)
{
_.paint.bitmap=ImageManager.loadDialogPort($gameMessage.getPort().paint)
_.paint.anchor.x = 0.5
_.paint.anchor.y = 0.5
}
}
}
/**
* 帧事件
* 重点
* 每帧更新 判断有没有文本输入
* */
Window_Limpid_DialogBox.prototype.update = function() {
//没有要处理的文本
if (!$gameMessage.hasText()) {
if (!this._show) return
//淡出
else if (this._anime > 0) {
this.y = (Graphics.boxHeight - _.height) + (_.animatime - (--this._anime)) * _.anima_y;
this.alpha = this._anime / _.animatime
this.showSport(false)
} else this._show = false;
}
//存在要处理的文本
else {
if (this._show) this.textHandler();
//淡入 -2是为了让文本框与底部留出一部分边距
else if (this._anime < _.animatime-2) {
this.y = (Graphics.boxHeight - _.height) + (_.animatime - (++this._anime)) * _.anima_y;
this.alpha = this._anime / _.animatime
this.showSport(true)
}
else this._show = true
}
};
/**
* 文本控制器
* */
Window_Limpid_DialogBox.prototype.textHandler = function() {
if(!this._Info||this._Info.end==2)
{
this._Info= _.Text_template_init()
_.Text_template_load($gameMessage.getData(),this._Info);
this._Info.x=0;
this._Info.y=0;
this._Info.z=0
return false
}
else {
if( this._Info.index_old!=this._Info.index)
{
this._Info.index_old=this._Info.index
/*更新立绘*/
this.updatePort(this._Info.index)
/*更新名称*/
this.updateNick(this._Info.index)
}
}
}
/**
* 更新动态立绘
*/
Window_Limpid_DialogBox.prototype.updatePort=function(index)
{
//隐藏动态立绘
if(index==-1||this._Info.port.length==0) {_.port.bitmap=new Bitmap();return}
//更新动态立绘
var Portdata = this._Info.port.length>index?this._Info.port[index]:this._Info.port[this._Info.port.length-1]
_.port.bitmap=ImageManager.loadDialogPort(Portdata)
_.port.anchor.x = 0.5
_.port.anchor.y = 0.5
/*用静态立绘充当过度*/
if( _.paint._active){_.paint.alpha=0;_.paint._active=false}
else {
_.paint.bitmap = ImageManager.loadDialogPort(Portdata)
_.paint.anchor.x = 0.5
_.paint.anchor.y = 0.5
}
}
/**
* 更新名称框
*/
Window_Limpid_DialogBox.prototype.updateNick=function(index)
{
if(index==-1||this._Info.nick.length==0) {this.namebox.drawName("");return}
this.namebox.drawName(this._Info.nick.length>index?this._Info.nick[index]:this._Info.nick[this._Info.nick.length-1])
}
/***
* 显示静态立绘
*/
Window_Limpid_DialogBox.prototype.showSport=function(show){
_.paint.alpha = this._anime / _.animatime
if(_.paint._active!=show)
{
_.paint._active=show
if (show)
{
_.paint.bitmap=ImageManager.loadDialogPort($gameMessage.getPort().paint)
_.paint.anchor.x = 0.5
_.paint.anchor.y = 0.5
}
}
}
覆盖帧更新 文本控制器
效果如下
更改下json配置 便可控制 名称 立绘 显示
-
GIF 2021-6-6 12-55-41.gif
(637.14 KB, 下载次数: 15)
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |