设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 16798|回复: 34

[原创发布] 中文名输入插件

[复制链接]

Lv2.观梦者

梦石
0
星屑
256
在线时间
214 小时
注册时间
2008-12-18
帖子
44
发表于 2018-9-15 14:36:03 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 魏玉龙 于 2018-9-15 16:58 编辑

写插件貌似会上瘾,刚又整出来了一个中文名输入!
游戏默认的输入方式太Low了,果断自己写一个替换掉!
现在可以用输入法了,手机端没实验,有条件的帮忙试一下!
移动端无法确定的BUG已修复!

JAVASCRIPT 代码复制下载
  1. /*:
  2.  * ChineseNameEditor.js
  3.  * @plugindesc 中文名输入插件
  4.  * @author 魏玉龙
  5.  * @since 2018.09.15
  6.  * @version 1.0
  7.  *
  8.  * @param windowWidth
  9.  * @desc 设置窗口的宽度
  10.  * @default 580
  11.  *
  12.  * @param windowCenter
  13.  * @desc 设置为屏幕居中 true/false
  14.  * @default true
  15.  *
  16.  * @param windowOpacity
  17.  * @desc 设置窗口透明度 (0 ~ 255)
  18.  * @default 225
  19.  *
  20.  * @param askingText
  21.  * @desc 设置询问框文本
  22.  * @default 请输入一个角色名!
  23.  *
  24.  * @param fontColor
  25.  * @desc 设置字体颜色
  26.  * @default white
  27.  *
  28.  * @param fontSize
  29.  * @desc 设置字体大小
  30.  * @default 28
  31.  *
  32.  * @param showDefaultName
  33.  * @desc 显示默认角色名 true/false
  34.  * @default true
  35.  *
  36.  * @help
  37.  *
  38.  * 这个插件提供了一个输入框,可以让你在修改名称时输入中文文字
  39.  *
  40.  */
  41. (function () {
  42.   var parameters = PluginManager.parameters('ChineseNameEditor');
  43.   var windowWidth = Number(parameters['windowWidth'] || 580);
  44.   var windowCenter = JSON.parse(parameters['windowCenter'] || true);
  45.   var windowOpacity = Number(parameters['windowOpacity'] || 225);
  46.   var askText = String(parameters['askingText'] || '请输入一个角色名!');
  47.   var fontSize = Number(parameters['fontSize'] || 28);
  48.   var fontColor = String(parameters['fontColor'] || 'white');
  49.   var showDefaultName = JSON.parse(parameters['showDefaultName'] || true);
  50.  
  51.   function TextBox() {
  52.     this.initialize.apply(this, arguments);
  53.   };
  54.   TextBox.prototype.initialize = function (_editWindow) {
  55.     this._editWindow = _editWindow;
  56.     this.createTextBox();
  57.     this.getFocus();
  58.   };
  59.   TextBox.prototype.createTextBox = function () {
  60.     this._textBox = document.createElement('input');
  61.     this._textBox.type = 'text';
  62.     this._textBox.value = showDefaultName ? this._editWindow._name : '';
  63.     this._textBox.autofocus = false;
  64.     this._textBox.width = 1;
  65.     this._textBox.height = 1;
  66.     this._textBox.style.opacity = 0;
  67.     this._textBox.style.zIndex = 1000;
  68.     this._textBox.style.imeMode = 'active';
  69.     this._textBox.style.position = 'absolute';
  70.     this._textBox.style.top = 0;
  71.     this._textBox.style.left = 0;
  72.     this._textBox.style.right = 0;
  73.     this._textBox.style.bottom = 0;
  74.     this._textBox.onkeydown = this.onKeyDown.bind(this);
  75.     document.body.appendChild(this._textBox);
  76.   };
  77.   TextBox.prototype.setEvent = function (func) {
  78.     this._textBox.onchange = func;
  79.   };
  80.   TextBox.prototype.terminateTextBox = function () {
  81.     document.body.removeChild(this._textBox);
  82.   };
  83.   TextBox.prototype.onKeyDown = function (e) {
  84.     var keyCode = e.which;
  85.     this.getFocus();
  86.     if (keyCode < 32) {
  87.       if (keyCode === 8) {
  88.         this.backSpace();
  89.       } else if (keyCode === 13) {
  90.         if (this.getTextLength() <= 0) {
  91.           e.preventDefault();
  92.         }
  93.       }
  94.     }
  95.   };
  96.   TextBox.prototype.getTextLength = function () {
  97.     return this._textBox.value.length;
  98.   };
  99.   TextBox.prototype.getMaxLength = function () {
  100.     return this._editWindow._maxLength;
  101.   };
  102.   TextBox.prototype.backSpace = function () {
  103.     this._editWindow._name = this._editWindow._name.slice(0, this._textBox.value.length - 1);
  104.     this._editWindow._index = this._textBox.value.length;
  105.     this._textBox.value = this._editWindow._name;
  106.     this._editWindow.refresh();
  107.   };
  108.   TextBox.prototype.refreshNameEdit = function () {
  109.     this._editWindow._name = this._textBox.value.toString();
  110.     this._editWindow._index = this._textBox.value.length || 0;
  111.     this._editWindow.refresh();
  112.   };
  113.   TextBox.prototype.update = function () {
  114.     if (this.getTextLength() <= this._editWindow._maxLength) {
  115.       this.refreshNameEdit();
  116.     }
  117.   };
  118.   TextBox.prototype.getFocus = function () {
  119.     this._textBox.focus();
  120.   };
  121.   TextBox.prototype.terminate = function () {
  122.     this.terminateTextBox();
  123.   };
  124.  
  125.   Window_NameEdit.prototype.charWidth = function () {
  126.     var text = '\uAC00';
  127.     return this.textWidth(text)
  128.   };
  129.   Window_NameEdit.prototype.drawActorFace = function (actor, x, y, width, height) {
  130.     this.drawFace(actor.faceName(), actor.faceIndex(), x, y, width, height);
  131.     this.changeTextColor(this.hpColor(actor));
  132.     this.drawText(askText, this.left(), y + this.fittingHeight(1) / 2, this.width);
  133.   };
  134.   Window_NameEdit.prototype.itemRect = function (index) {
  135.     return {
  136.       x: this.left() + index * this.charWidth(),
  137.       y: this.fittingHeight(1),
  138.       width: this.charWidth(),
  139.       height: this.lineHeight()
  140.     };
  141.   };
  142.   Window_NameEdit.prototype.windowWidth = function () {
  143.     return windowWidth;
  144.   };
  145.   Window_NameEdit.prototype.drawChar = function (index) {
  146.     var rect = this.itemRect(index);
  147.     this.resetTextColor();
  148.     this.contents.outlineWidth = 1;
  149.     this.contents.outlineColor = 'black';
  150.     this.contents.fontColor = fontColor;
  151.     this.drawText(this._name[index] || '', rect.x, rect.y)
  152.   };
  153.   Window_NameEdit.prototype.standardFontSize = function () {
  154.     return fontSize;
  155.   };
  156.  
  157.   Scene_Name.prototype.create = function () {
  158.     Scene_MenuBase.prototype.create.call(this);
  159.     this._actor = $gameActors.actor(this._actorId);
  160.     this.createEditWindow();
  161.     this.createTextBox();
  162.     this._textBox.setEvent(this.onInputOk.bind(this));
  163.   };
  164.   Scene_Name.prototype.createTextBox = function () {
  165.     this._textBox = new TextBox(this._editWindow);
  166.     if (windowCenter) {
  167.       this._editWindow.y = Graphics.boxHeight / 2 - this._editWindow.height / 2;
  168.     }
  169.     this._editWindow.opacity = windowOpacity;
  170.   };
  171.   Scene_Name.prototype.update = function () {
  172.     this._textBox.getFocus();
  173.     this._textBox.update();
  174.     Scene_MenuBase.prototype.update.call(this);
  175.     if(Input.isRepeated('ok')){
  176.       this.onInputOk();
  177.     }
  178.   };
  179.   Scene_Name.prototype.terminate = function () {
  180.     Scene_MenuBase.prototype.terminate.call(this);
  181.     this._textBox.terminate();
  182.   };
  183. })();

评分

参与人数 4+4 收起 理由
PassFire + 1 精品文章
frost_king_hw + 1 精品文章
康姆图帕帕 + 1 塞糖
白嫩白嫩的 + 1 塞糖

查看全部评分

Lv2.观梦者

梦石
0
星屑
256
在线时间
214 小时
注册时间
2008-12-18
帖子
44
 楼主| 发表于 2018-9-15 14:43:42 | 显示全部楼层
突然想到,我这样一搞,估计手柄输入应该是没戏了!
所以用的人如果考虑游戏支持手柄,不建议使用该插件!
回复 支持 1 反对 0

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3074
在线时间
685 小时
注册时间
2018-6-1
帖子
272
发表于 2018-9-15 15:02:36 | 显示全部楼层
我用手机试试
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3074
在线时间
685 小时
注册时间
2018-6-1
帖子
272
发表于 2018-9-15 15:14:02 | 显示全部楼层
本帖最后由 q1456503215 于 2018-9-15 15:17 编辑

名字输入没有问题 但是在安卓端 确定好像无效 无法进行游戏

mv自带的输入名字就没有问题
QQ图片20180915151307.png
QQ图片20180915151313.png
QQ图片20180915151316.png
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
256
在线时间
214 小时
注册时间
2008-12-18
帖子
44
 楼主| 发表于 2018-9-15 15:25:57 | 显示全部楼层
手机回车键 不是13?
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3074
在线时间
685 小时
注册时间
2018-6-1
帖子
272
发表于 2018-9-15 15:28:36 | 显示全部楼层
魏玉龙 发表于 2018-9-15 15:25
手机回车键 不是13?

不知道 反正不管用  mv的回车键好像是 ok
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
256
在线时间
214 小时
注册时间
2008-12-18
帖子
44
 楼主| 发表于 2018-9-15 15:31:08 | 显示全部楼层
q1456503215 发表于 2018-9-15 15:28
不知道 反正不管用  mv的回车键好像是 ok

你最后点的是输入法上的 前往 还是点 虚拟按键的 O
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3074
在线时间
685 小时
注册时间
2018-6-1
帖子
272
发表于 2018-9-15 15:35:45 | 显示全部楼层
魏玉龙 发表于 2018-9-15 15:31
你最后点的是输入法上的 前往 还是点 虚拟按键的 O

前往和 O 都没效果  我那个O 就是mv的确定键
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
256
在线时间
214 小时
注册时间
2008-12-18
帖子
44
 楼主| 发表于 2018-9-15 15:41:16 | 显示全部楼层
q1456503215 发表于 2018-9-15 15:35
前往和 O 都没效果  我那个O 就是mv的确定键

你用的这个虚拟按键发给我
我用手机浏览器测试是没问题

点评

我这个虚拟按键是用java写的 不是插件  发表于 2018-9-15 15:43
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
256
在线时间
214 小时
注册时间
2008-12-18
帖子
44
 楼主| 发表于 2018-9-15 16:51:14 | 显示全部楼层
在 174行下面插入如下代码试试

  1.     if(Input.isRepeated('ok')){
  2.       this.onInputOk();
  3.     }
复制代码

点评

ok完美了  发表于 2018-9-15 16:56
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-3-29 22:35

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表