赞 | 0 |
VIP | 0 |
好人卡 | 3 |
积分 | 1 |
经验 | 8526 |
最后登录 | 2017-4-28 |
在线时间 | 81 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 81 小时
- 注册时间
- 2016-1-6
- 帖子
- 150
|
今天又学了一点脚本,把昨天发的那个代码加了几句话,现在你可以自由切换头像在左或在右,只要你在对话内容里面加上<right>就行,最好把<wrap>也加上,这样的话能够自动换行,不至于出现头像被文字覆盖的情况。
该脚本原型是YED的Word Wrap,我只是添加了几句代码。- /*:
- * Yami Engine Delta - Word Wrap
- *
- * @plugindesc This plugin provides word wrap feature, so that a long text
- * will be properly broken down into lines.
- * @author Yami Engine Delta [Dr.Yami]
- *
- * @param Break Word
- * @desc Allows unbreakable words to be broken.
- * @default true
- *
- * @param Right Face
- * @desc 允许对话框头像可以左右切换。(默认值改不改其实都起效。)
- * @default false
- *
- * @help
- * The word wrap isn't enabled by default. To activate word wrap in any text,
- * for example in Message, you have to put following code into the text:
- *
- * ------------
- * <wrap>
- * ------------
- *
- * The word wrapper will nullify the break lines in editor, so that you have
- * to manually break line by using following code in text:
- *
- * ------------
- * <br>
- * ------------
- *
- * 新添加的左右头像对话效果,需要在文本开头输入以下字符:
- * 如果不输入则默认头像在左侧。
- *
- * ------------
- * <right>
- * ------------
- *
- * ============================================================================
- */
- /**
- * @namespace WordWrap
- * @memberof YED
- */
- var YED = YED || {};
- // init WordWrap module
- YED.WordWrap = {};
- YED.WordWrap.BreakWord
- = PluginManager.parameters('YED_WordWrap')['Break Word'];
- YED.WordWrap.RightFace
- = PluginManager.parameters('YED_WordWrap')['Right Face'];
-
- (function($WordWrap) {
- var _Window_Base_processNormalCharacter
- = Window_Base.prototype.processNormalCharacter;
- var _Window_Base_convertEscapeCharacters
- = Window_Base.prototype.convertEscapeCharacters;
-
- var breakWord = eval($WordWrap.BreakWord);
- Window_Message.prototype.drawMessageFace = function() {
- if (this._rightFace){
- this.drawFace($gameMessage.faceName(), $gameMessage.faceIndex(), Graphics.boxWidth-216, 0);//rightface
- }else{
- this.drawFace($gameMessage.faceName(), $gameMessage.faceIndex(), 0, 0);//leftface
- }
- };
- Window_Message.prototype.newLineX = function() {
- if (this._rightFace){
- return $gameMessage.faceName() === '' ? 0 : 0;//rightface
- }else{
- return $gameMessage.faceName() === '' ? 0 : 168;//leftface
- }
- };
-
- Window_Base.prototype.textAreaWidth = function() {
- return this.contentsWidth();
- };
- Window_Base.prototype.needWrap = function(textState) {
- var c = textState.text[textState.index],
- w = this.textWidth(c),
- nextSpaceIndex = 0,
- nextWord = "",
- nextWidth = 0,
- text = textState.text;
- if (!this._wordWrap) {
- return false;
- }
-
- if (this._rightFace){
- if (breakWord && (textState.x + w * 2) >= this.textAreaWidth()-144) {//rightface
- textState.index--; // hack for missing character
- return true;
- }
- }else{
- if (breakWord && (textState.x + w * 2) >= this.textAreaWidth()) {//leftface
- textState.index--; // hack for missing character
- return true;
- }
- }
- if (!breakWord && c === " ") {
- nextSpaceIndex = text.indexOf(" ", textState.index + 1);
- if (nextSpaceIndex < 0) {
- nextSpaceIndex = text.length + 1;
- }
- nextWord = text.substring(textState.index, nextSpaceIndex);
- nextWidth = this.textWidth(nextWord);
-
- if (this._rightFace){
- if (textState.x + nextWidth >= this.textAreaWidth()-144) {//rightface
- return true;
- }
- }else{
- if (textState.x + nextWidth >= this.textAreaWidth()) {//leftface
- return true;
- }
- }
- }
- return false;
- };
- Window_Base.prototype.convertEscapeCharacters = function(text) {
- text = _Window_Base_convertEscapeCharacters.call(this, text);
- text = this.convertWordWrapEscapeCharacters(text);
- return text;
- };
- Window_Base.prototype.convertWordWrapEscapeCharacters = function(text) {
- text = this.enableWordWrap(text);
-
- if (!!this._wordWrap) {
- text = text.replace(/[\n\r]+/g, '');
- text = text.replace(/\<br\>/gi, '\n');
- }
- return text;
- };
- Window.prototype.enableWordWrap = function(text) {
- this._wordWrap = false;
- this._rightFace = false;
- if (!!text.match(/\<wrap\>/i)) {
- this._wordWrap = true;
- }
- if (!!text.match(/\<right\>/i)) {
- this._rightFace = true;
- }
- text = text.replace(/\<wrap\>/gi, '');
- text = text.replace(/\<right\>/gi, '');
- return text;
- };
- Window_Base.prototype.processNormalCharacter = function(textState) {
- if (this.needWrap(textState)) {
- return this.processNewLine(textState);
- }
- _Window_Base_processNormalCharacter.call(this, textState);
- };
- }(YED.WordWrap));
复制代码 |
评分
-
查看全部评分
|