查看: 16160|回复: 44

[已经解决] MV的名称输入处理怎么能用键盘输入中文?

[复制链接]
梦石
0
星屑
50
在线时间
32 小时
注册时间
2011-7-1
回帖
12
发表于 2015-12-27 22:14:33 | 显示全部楼层 |阅读模式

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

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

×
RT,怎么让它变成可以用键盘输入,而且可以打中文。 QQ图片20151227221209.png

评分

参与人数 1赞 +1 收起 理由
turboyuan + 1 精品文章

查看全部评分

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2015-12-28 00:14:30 | 显示全部楼层
参考html 的 input 标签
回复

使用道具 举报

梦石
0
星屑
50
在线时间
32 小时
注册时间
2011-7-1
回帖
12
 楼主| 发表于 2015-12-28 00:18:25 | 显示全部楼层
呢个,不是太清楚,可以告诉明确一点么?谢谢,而且本人小白,不懂代码和脚本{:4_132:}

点评

明天。  发表于 2015-12-28 00:23
回复

使用道具 举报

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2015-12-28 11:11:04 | 显示全部楼层
点击展开/收起
  1. //=============================================================================
  2. // NameInput.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc 名字输入
  6. * @author wangwang
  7. *
  8. *
  9. * @help
  10. * 帮助的信息
  11. * 用网页输入代替原本的名字输入
  12. *
  13. *
  14. *
  15. */




  16. function Window_BC() {
  17.     this.initialize.apply(this, arguments);
  18. }

  19. (function() {

  20. Scene_Name.prototype = Object.create(Scene_MenuBase.prototype);
  21. Scene_Name.prototype.constructor = Scene_Name;
  22. //初始化
  23. Scene_Name.prototype.initialize = function() {
  24.     Scene_MenuBase.prototype.initialize.call(this);
  25. };
  26. //准备
  27. Scene_Name.prototype.prepare = function(actorId, maxLength) {
  28.     this._actorId = actorId;
  29.     this._maxLength = maxLength;
  30. };
  31. //创建
  32. Scene_Name.prototype.create = function() {
  33.     Scene_MenuBase.prototype.create.call(this);
  34.     this._actor = $gameActors.actor(this._actorId);
  35.     this.createEditWindow();
  36.     this.createBCWindow();
  37. };
  38. //开始
  39. Scene_Name.prototype.start = function() {
  40.     Scene_MenuBase.prototype.start.call(this);
  41.     this._editWindow.refresh();
  42. };

  43. //创建编辑窗口
  44. Scene_Name.prototype.createEditWindow = function() {
  45.     this._editWindow = new Window_NameEdit(this._actor, this._maxLength);
  46.     this.addWindow(this._editWindow);
  47. };

  48. Scene_Name.prototype.createBCWindow = function() {

  49.         var x = this._editWindow.x + this._editWindow.left()
  50.         var y = this._editWindow.y + 54
  51.         var width = this._editWindow.charWidth() * this._maxLength
  52.         var height = this._editWindow.lineHeight()
  53.        
  54.     Graphics._addInput("text",x,y, width,height, this._editWindow.standardFontSize())
  55.     Graphics._input.maxLength = this._maxLength
  56.     Graphics._input.value = this._actor.name().slice(0, this._maxLength);
  57.    
  58.     this._bcWindow = new Window_BC("保存");
  59.     this._bcWindow.x = this._editWindow.x + this._editWindow.width - this._bcWindow.width
  60.     this._bcWindow.y = this._editWindow.y +this._editWindow.height
  61.         this._bcWindow.setHandler('dianji', this.onInputOk.bind(this));
  62.     this.addWindow(this._bcWindow);
  63.    
  64.     this._csWindow = new Window_BC("还原");
  65.     this._csWindow.x = this._editWindow.x + this._editWindow.width - this._bcWindow.width - this._bcWindow.width
  66.     this._csWindow.y = this._editWindow.y +this._editWindow.height
  67.         this._csWindow.setHandler('dianji', this.oncs.bind(this));
  68.     this.addWindow(this._csWindow);
  69. };

  70. //输入初始化
  71. Scene_Name.prototype.oncs = function() {
  72.         Graphics._input.value = this._actor.name().slice(0, this._maxLength);
  73. };


  74. //当输入确定
  75. Scene_Name.prototype.onInputOk = function() {
  76.         var name="" + Graphics._input.value
  77.     this._actor.setName(name);
  78.     this.popScene();
  79.     Graphics._removeInput()
  80. };

  81. //名称编辑窗口
  82. Window_NameEdit.prototype = Object.create(Window_Base.prototype);
  83. Window_NameEdit.prototype.constructor = Window_NameEdit;
  84. //初始化
  85. Window_NameEdit.prototype.initialize = function(actor, maxLength) {
  86.     var width = this.windowWidth();
  87.     var height = this.windowHeight();
  88.     var x = (Graphics.boxWidth - width) / 2;
  89.     var y = (Graphics.boxHeight - (height + this.fittingHeight(9) + 8)) / 2;
  90.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  91.     this._actor = actor;
  92.     this._name = actor.name().slice(0, this._maxLength);
  93.     this._index = this._name.length;
  94.     this._maxLength = maxLength;
  95.     this._defaultName = this._name;
  96.     this.deactivate();
  97.     this.refresh();
  98.     ImageManager.loadFace(actor.faceName());
  99. };

  100. //窗口宽
  101. Window_NameEdit.prototype.windowWidth = function() {
  102.     return 480;
  103. };

  104. //窗口高
  105. Window_NameEdit.prototype.windowHeight = function() {
  106.     return this.fittingHeight(4);
  107. };

  108. //名称
  109. Window_NameEdit.prototype.name = function() {
  110.     return this._name;
  111. };


  112. //脸宽
  113. Window_NameEdit.prototype.faceWidth = function() {
  114.     return 144;
  115. };
  116. //字符宽
  117. Window_NameEdit.prototype.charWidth = function() {
  118.     var text =  '我';
  119.     return this.textWidth(text);
  120. };

  121. //左
  122. Window_NameEdit.prototype.left = function() {
  123.     var nameCenter = (this.contentsWidth() + this.faceWidth()) / 2;
  124.     var nameWidth = (this._maxLength + 1) * this.charWidth();
  125.     return Math.min(nameCenter - nameWidth / 2, this.contentsWidth() - nameWidth);
  126. };

  127. //刷新
  128. Window_NameEdit.prototype.refresh = function() {
  129.     this.contents.clear();
  130.     this.drawActorFace(this._actor, 0, 0);
  131. };



  132. //随便写的点击窗口....
  133. Window_BC.prototype = Object.create(Window_Base.prototype);
  134. Window_BC.prototype.constructor = Window_BC;
  135. //初始化
  136. Window_BC.prototype.initialize = function(text) {
  137.     var width = 80
  138.     var height = this.fittingHeight(1);
  139.     Window_Base.prototype.initialize.call(this, 0, 0, width, height);
  140.     this._handlers = {};
  141.     this._text = '';
  142.     this.setText(text)
  143. };
  144. Window_BC.prototype.standardFontSize = function() {
  145.         return 16;
  146. };
  147. Window_BC.prototype.lineHeight = function() {
  148.         return 20;
  149. };

  150. Window_BC.prototype.standardPadding = function() {
  151.         return 16;
  152. };
  153. Window_BC.prototype.textPadding = function() {
  154.         return 0;
  155. };

  156. //设置文本
  157. Window_BC.prototype.setText = function(text) {
  158.     if (this._text !== text) {
  159.         this._text = text;
  160.         this.refresh();
  161.     }
  162. };

  163. //清除
  164. Window_BC.prototype.clear = function() {
  165.     this.setText('');
  166. };
  167. //刷新
  168. Window_BC.prototype.refresh = function() {
  169.     this.contents.clear();
  170.     this.drawTextEx(this._text, this.textPadding(), 0);
  171. };

  172. Window_BC.prototype.update = function() {
  173.     Window_Base.prototype.update.call(this);
  174.     this.dianji()
  175. };

  176. Window_BC.prototype.setHandler = function(symbol, method) {
  177.     this._handlers[symbol] = method;
  178. };
  179. Window_BC.prototype.isHandled = function(symbol) {
  180.     return !!this._handlers[symbol];
  181. };
  182. Window_BC.prototype.callHandler = function(symbol) {
  183.     if (this.isHandled(symbol)) {
  184.         this._handlers[symbol]();
  185.     }
  186. };

  187. Window_BC.prototype.dianji = function() {
  188.     if (this.isOpen()) {
  189.         if (TouchInput.isTriggered()) {
  190.                 var x = this.canvasToLocalX(TouchInput.x);
  191.                     var y = this.canvasToLocalY(TouchInput.y);
  192.                     if(x >= 0 && y >= 0 && x < this.width && y < this.height){
  193.                             this.callHandler("dianji")
  194.                     }
  195.         }
  196.     }
  197. };



  198. Graphics._createAllElements = function() {
  199.     this._createErrorPrinter();
  200.     this._createCanvas();
  201.     this._createVideo();
  202.     this._createUpperCanvas();
  203.     this._createRenderer();
  204.     this._createFPSMeter();
  205.     this._createModeBox();
  206.     this._createGameFontLoader();
  207.    
  208.     this._createInput()     //修改
  209. };

  210. /**更新所有成分
  211. * @static
  212. * @method _updateAllElements
  213. * @private
  214. */
  215. Graphics._updateAllElements = function() {
  216.     this._updateRealScale();
  217.     this._updateErrorPrinter();
  218.     this._updateCanvas();
  219.     this._updateVideo();
  220.     this._updateUpperCanvas();
  221.     this._updateRenderer();
  222.    
  223.     this._updateInput();     //添加
  224.    
  225.     this._paintUpperCanvas();
  226. };



  227. //创建输入
  228. Graphics._createInput = function() {
  229.     this._input = document.createElement("input");;
  230.     this._input.id = 'Input';
  231.     this._input.type ="text"
  232.     this._input._sx ={}
  233.     var sx = this._input._sx
  234.     sx.xs = false
  235.     sx.x= 0
  236.     sx.y=0   
  237.     sx.width =100
  238.     sx.height= 20
  239.     sx.fontSize = 18
  240.     //document.body.appendChild(this._input);
  241. };
  242. //添加输入
  243. Graphics._addInput = function(type,x,y,width,height,fontSize) {               
  244.         this._input.type = type || "text"
  245.         var sx = this._input._sx
  246.         sx.x= x
  247.         sx.y= y
  248.         sx.width = width|| 100
  249.         sx.height= height|| 20
  250.         sx.fontSize = fontSize || 18
  251.         this._updateInput()
  252.         sx.xs = true
  253.         document.body.appendChild(this._input);
  254.        

  255. };

  256. //移除输入
  257. Graphics._removeInput = function() {
  258.     this._input.remove()
  259.     this._input.value = null
  260.     this._input._xs = false
  261.     //document.body.appendChild(this._input);
  262. };
  263. //更新输入
  264. Graphics._updateInput =function () {   
  265.         this._input.style.zIndex = 12;
  266.         var sx = this._input._sx
  267.         var x = sx.x  * this._realScale + (window.innerWidth - this._width * this._realScale) / 2
  268.         var y = sx.y  * this._realScale + (window.innerHeight - this._height * this._realScale) / 2

  269.     var width = sx.width * this._realScale;
  270.     var height = sx.height * this._realScale;
  271.     var fontSize =        sx.fontSize * this._realScale;
  272.     this._input.style.position = 'absolute';
  273.     this._input.style.margin = 'auto';
  274.     this._input.style.top = y  + 'px';
  275.     this._input.style.left = x  + 'px' ;
  276.     this._input.style.width = width + 'px';
  277.     this._input.style.height = height + 'px';
  278.     this._input.style.fontSize = fontSize + 'px';
  279. }

  280. //防止默认
  281. Input._onKeyDown = function(event) {
  282.         //如果 需要避免默认 (键值)
  283.     if (this._shouldPreventDefault(event.keyCode)) {
  284.             
  285.             if (Graphics && Graphics._input && Graphics._input._sx && Graphics._input._sx.xs){
  286.                     //允许默认
  287.                 }else {
  288.                         //避免默认
  289.                         event.preventDefault();
  290.                 }
  291.     }
  292.     //键值===144
  293.     if (event.keyCode === 144) {    // Numlock  数字开关
  294.         //清除
  295.         this.clear();
  296.     }
  297.     var buttonName = this.keyMapper[event.keyCode];
  298.     //如果 键名
  299.     if (buttonName) {
  300.             //当前状态 键 =true
  301.         this._currentState[buttonName] = true;
  302.     }
  303. };



  304. })();
复制代码




BaiduShurufa_2015-12-28_11-7-21.png
BaiduShurufa_2015-12-28_11-7-40.png
BaiduShurufa_2015-12-28_11-6-55.png

点评

大神,我将代码保存为js文件放在plugin目录下,然后插件里启用,系统的名称输入就被自动覆盖成你这个了,很简单很强大,给你100个赞  发表于 2016-11-27 22:30
大神,请问怎么用啊  发表于 2016-11-27 22:22
.....有空再说吧  发表于 2016-2-23 19:32
做个虚拟按键[笑]  发表于 2016-2-23 18:53
额,无能为力……  发表于 2016-2-23 07:38

评分

参与人数 1星屑 +166 收起 理由
余烬之中 + 166 认可答案

查看全部评分

回复

使用道具 举报

梦石
0
星屑
193
在线时间
36 小时
注册时间
2011-4-8
回帖
16
发表于 2015-12-28 11:56:01 | 显示全部楼层
汪汪 发表于 2015-12-28 11:11
[fold]
//=============================================================================
// NameInput. ...

H5表单都可以用吧  然后用样式美化下  

点评

我是小白,...你说的完全听不懂........  发表于 2015-12-28 12:02
回复

使用道具 举报

梦石
0
星屑
50
在线时间
32 小时
注册时间
2011-7-1
回帖
12
 楼主| 发表于 2015-12-28 12:37:10 | 显示全部楼层
非常感谢两位大大,尤其是汪大,谢谢了。

点评

小白没办法。。刚找到在哪里点评。=。=  发表于 2015-12-29 21:34
其实我想说..你这样回复别人,别人是看不到的...使用点评或回复回帖别人才能收到消息  发表于 2015-12-28 13:02
回复

使用道具 举报

梦石
0
星屑
50
在线时间
31 小时
注册时间
2015-12-31
回帖
11
发表于 2016-2-5 18:25:34 | 显示全部楼层
汪汪 发表于 2015-12-28 11:11
[fold]
//=============================================================================
// NameInput. ...

太感谢了,请问可以自由使用吗?我会在名单上鸣谢你的,打算打包APP。

点评

可以.本来就是让大家用的.  发表于 2016-2-5 22:22
回复

使用道具 举报

梦石
0
星屑
50
在线时间
10 小时
注册时间
2016-6-2
回帖
10
发表于 2016-7-26 23:58:42 | 显示全部楼层
汪汪 发表于 2015-12-28 11:11
[fold]
//=============================================================================
// NameInput. ...

汪大,不知道为什么,我用了会闪退

点评

闪退这种很少遇到....你看看是不是其他插件的问题?  发表于 2016-7-28 07:56
可以加下qq吗?109602435  发表于 2016-7-28 00:05
不知道,我用其他的名称输入插件也会闪退,是因为插件冲突吗?  发表于 2016-7-28 00:04
确定是这个插件的问题吗?  发表于 2016-7-27 09:22
回复

使用道具 举报

梦石
0
星屑
50
在线时间
10 小时
注册时间
2016-6-2
回帖
10
发表于 2016-7-28 00:03:56 | 显示全部楼层
109602435 发表于 2016-7-26 23:58
汪大,不知道为什么,我用了会闪退

C:\Users\19\Desktop不知道,我用其他的名称输入插件也会闪退,是因为插件冲突吗?
回复

使用道具 举报

梦石
0
星屑
695
在线时间
1 小时
注册时间
2016-7-30
回帖
3
发表于 2016-7-30 12:13:27 | 显示全部楼层
汪汪 发表于 2015-12-28 11:11
[fold]
//=============================================================================
// NameInput. ...

厉害,但是我用的时候,放在脚本事件里,为什么显示语法输入错误呢?

点评

不好意思。。我自己的问题,刚刚发现直接复制过去的话,会复制不完全  发表于 2016-7-30 12:20
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部