| 赞 | 58 |
| VIP | |
| 好人卡 | |
| 积分 | 2 |
| 经验 | |
| 最后登录 | 2026-10-16 |
| 在线时间 | 1037 小时 |
- 梦石
- 0
- 星屑
- 196
- 在线时间
- 1037 小时
- 注册时间
- 2021-3-24
- 回帖
- 548

|
楼主 |
发表于 2021-6-6 11:25:54
|
显示全部楼层
初始化要处理的文字
- /**
- * 文本控制器
- * */
- 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
- }
- }
复制代码
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++}
- }
- }
- }
- }
复制代码

其余辅助方法
- /**
- *标记 处理
- */
- _.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]}
- };
复制代码
打印效果
|
|