/*: * ChineseNameEditor.js * @plugindesc 中文名输入插件 * @author 魏玉龙 * @since 2018.09.15 * @version 1.0 * * @param windowWidth * @desc 设置窗口的宽度 * @default 580 * * @param windowCenter * @desc 设置为屏幕居中 true/false * @default true * * @param windowOpacity * @desc 设置窗口透明度 (0 ~ 255) * @default 225 * * @param askingText * @desc 设置询问框文本 * @default 请输入一个角色名! * * @param fontColor * @desc 设置字体颜色 * @default white * * @param fontSize * @desc 设置字体大小 * @default 28 * * @param showDefaultName * @desc 显示默认角色名 true/false * @default true * * @help * * 这个插件提供了一个输入框,可以让你在修改名称时输入中文文字 * */ (function () { var parameters = PluginManager.parameters('ChineseNameEditor'); var windowWidth = Number(parameters['windowWidth'] || 580); var windowCenter = JSON.parse(parameters['windowCenter'] || true); var windowOpacity = Number(parameters['windowOpacity'] || 225); var askText = String(parameters['askingText'] || '请输入一个角色名!'); var fontSize = Number(parameters['fontSize'] || 28); var fontColor = String(parameters['fontColor'] || 'white'); var showDefaultName = JSON.parse(parameters['showDefaultName'] || true); function TextBox() { this.initialize.apply(this, arguments); }; TextBox.prototype.initialize = function (_editWindow) { this._editWindow = _editWindow; this.createTextBox(); this.getFocus(); }; TextBox.prototype.createTextBox = function () { this._textBox = document.createElement('input'); this._textBox.type = 'text'; this._textBox.value = showDefaultName ? this._editWindow._name : ''; this._textBox.autofocus = false; this._textBox.width = 1; this._textBox.height = 1; this._textBox.style.opacity = 0; this._textBox.style.zIndex = 1000; this._textBox.style.imeMode = 'active'; this._textBox.style.position = 'absolute'; this._textBox.style.top = 0; this._textBox.style.left = 0; this._textBox.style.right = 0; this._textBox.style.bottom = 0; this._textBox.onkeydown = this.onKeyDown.bind(this); document.body.appendChild(this._textBox); }; TextBox.prototype.setEvent = function (func) { this._textBox.onchange = func; }; TextBox.prototype.terminateTextBox = function () { document.body.removeChild(this._textBox); }; TextBox.prototype.onKeyDown = function (e) { var keyCode = e.which; this.getFocus(); if (keyCode < 32) { if (keyCode === 8) { this.backSpace(); } else if (keyCode === 13) { if (this.getTextLength() <= 0) { e.preventDefault(); } } } }; TextBox.prototype.getTextLength = function () { return this._textBox.value.length; }; TextBox.prototype.getMaxLength = function () { return this._editWindow._maxLength; }; TextBox.prototype.backSpace = function () { this._editWindow._name = this._editWindow._name.slice(0, this._textBox.value.length - 1); this._editWindow._index = this._textBox.value.length; this._textBox.value = this._editWindow._name; this._editWindow.refresh(); }; TextBox.prototype.refreshNameEdit = function () { this._editWindow._name = this._textBox.value.toString(); this._editWindow._index = this._textBox.value.length || 0; this._editWindow.refresh(); }; TextBox.prototype.update = function () { if (this.getTextLength() <= this._editWindow._maxLength) { this.refreshNameEdit(); } }; TextBox.prototype.getFocus = function () { this._textBox.focus(); }; TextBox.prototype.terminate = function () { this.terminateTextBox(); }; Window_NameEdit.prototype.charWidth = function () { var text = '\uAC00'; return this.textWidth(text) }; Window_NameEdit.prototype.drawActorFace = function (actor, x, y, width, height) { this.drawFace(actor.faceName(), actor.faceIndex(), x, y, width, height); this.changeTextColor(this.hpColor(actor)); this.drawText(askText, this.left(), y + this.fittingHeight(1) / 2, this.width); }; Window_NameEdit.prototype.itemRect = function (index) { return { x: this.left() + index * this.charWidth(), y: this.fittingHeight(1), width: this.charWidth(), height: this.lineHeight() }; }; Window_NameEdit.prototype.windowWidth = function () { return windowWidth; }; Window_NameEdit.prototype.drawChar = function (index) { var rect = this.itemRect(index); this.resetTextColor(); this.contents.outlineWidth = 1; this.contents.outlineColor = 'black'; this.contents.fontColor = fontColor; this.drawText(this._name[index] || '', rect.x, rect.y) }; Window_NameEdit.prototype.standardFontSize = function () { return fontSize; }; Scene_Name.prototype.create = function () { Scene_MenuBase.prototype.create.call(this); this._actor = $gameActors.actor(this._actorId); this.createEditWindow(); this.createTextBox(); this._textBox.setEvent(this.onInputOk.bind(this)); }; Scene_Name.prototype.createTextBox = function () { this._textBox = new TextBox(this._editWindow); if (windowCenter) { this._editWindow.y = Graphics.boxHeight / 2 - this._editWindow.height / 2; } this._editWindow.opacity = windowOpacity; }; Scene_Name.prototype.update = function () { this._textBox.getFocus(); this._textBox.update(); Scene_MenuBase.prototype.update.call(this); if(Input.isRepeated('ok')){ this.onInputOk(); } }; Scene_Name.prototype.terminate = function () { Scene_MenuBase.prototype.terminate.call(this); this._textBox.terminate(); }; })();
QQ图片20180915151307.png (293.67 KB, 下载次数: 53)
QQ图片20180915151313.png (235.62 KB, 下载次数: 53)
QQ图片20180915151316.png (242.92 KB, 下载次数: 57)
魏玉龙 发表于 2018-9-15 15:25
手机回车键 不是13?
q1456503215 发表于 2018-9-15 15:28
不知道 反正不管用 mv的回车键好像是 ok
魏玉龙 发表于 2018-9-15 15:31
你最后点的是输入法上的 前往 还是点 虚拟按键的 O
q1456503215 发表于 2018-9-15 15:35
前往和 O 都没效果 我那个O 就是mv的确定键
peifectsun 发表于 2018-10-5 23:59
大神,求教一下,插件装上后,askingText选项,说明和开始输入姓名的上面都是“口口h口口t口”的乱码怎么解 ...
魏玉龙 发表于 2018-10-8 09:18
注意一下你复制保存插件的格式是不是utf-8
如果是GBK肯定会乱码的
2345截图20190604110149.png (370.36 KB, 下载次数: 55)
Zeldashu 发表于 2019-7-28 13:17
询问文本的内容无法替换,显示默认名称也是无法切换,请问是什么情况 ...
_9LE5%1U24ENF2G0]KCAZY6.png (536.97 KB, 下载次数: 2)
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |