查看: 15867|回复: 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 | 显示全部楼层
[fold]
[pre lang="JavaScript" file="NameInput.js"]//=============================================================================
// NameInput.js
//=============================================================================
/*:
* @plugindesc 名字输入
* @author wangwang
*
*
* @help
* 帮助的信息
* 用网页输入代替原本的名字输入
*
*
*
*/




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

(function() {

Scene_Name.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Name.prototype.constructor = Scene_Name;
//初始化
Scene_Name.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};
//准备
Scene_Name.prototype.prepare = function(actorId, maxLength) {
    this._actorId = actorId;
    this._maxLength = maxLength;
};
//创建
Scene_Name.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this._actor = $gameActors.actor(this._actorId);
    this.createEditWindow();
    this.createBCWindow();
};
//开始
Scene_Name.prototype.start = function() {
    Scene_MenuBase.prototype.start.call(this);
    this._editWindow.refresh();
};

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

Scene_Name.prototype.createBCWindow = function() {

        var x = this._editWindow.x + this._editWindow.left()
        var y = this._editWindow.y + 54
        var width = this._editWindow.charWidth() * this._maxLength
        var height = this._editWindow.lineHeight()
       
    Graphics._addInput("text",x,y, width,height, this._editWindow.standardFontSize())
    Graphics._input.maxLength = this._maxLength
    Graphics._input.value = this._actor.name().slice(0, this._maxLength);
   
    this._bcWindow = new Window_BC("保存");
    this._bcWindow.x = this._editWindow.x + this._editWindow.width - this._bcWindow.width
    this._bcWindow.y = this._editWindow.y +this._editWindow.height
        this._bcWindow.setHandler('dianji', this.onInputOk.bind(this));
    this.addWindow(this._bcWindow);
   
    this._csWindow = new Window_BC("还原");
    this._csWindow.x = this._editWindow.x + this._editWindow.width - this._bcWindow.width - this._bcWindow.width
    this._csWindow.y = this._editWindow.y +this._editWindow.height
        this._csWindow.setHandler('dianji', this.oncs.bind(this));
    this.addWindow(this._csWindow);
};

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


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

//名称编辑窗口
Window_NameEdit.prototype = Object.create(Window_Base.prototype);
Window_NameEdit.prototype.constructor = Window_NameEdit;
//初始化
Window_NameEdit.prototype.initialize = function(actor, maxLength) {
    var width = this.windowWidth();
    var height = this.windowHeight();
    var x = (Graphics.boxWidth - width) / 2;
    var y = (Graphics.boxHeight - (height + this.fittingHeight(9) + 8)) / 2;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this._actor = actor;
    this._name = actor.name().slice(0, this._maxLength);
    this._index = this._name.length;
    this._maxLength = maxLength;
    this._defaultName = this._name;
    this.deactivate();
    this.refresh();
    ImageManager.loadFace(actor.faceName());
};

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

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

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


//脸宽
Window_NameEdit.prototype.faceWidth = function() {
    return 144;
};
//字符宽
Window_NameEdit.prototype.charWidth = function() {
    var text =  '我';
    return this.textWidth(text);
};

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

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



//随便写的点击窗口....
Window_BC.prototype = Object.create(Window_Base.prototype);
Window_BC.prototype.constructor = Window_BC;
//初始化
Window_BC.prototype.initialize = function(text) {
    var width = 80
    var height = this.fittingHeight(1);
    Window_Base.prototype.initialize.call(this, 0, 0, width, height);
    this._handlers = {};
    this._text = '';
    this.setText(text)
};
Window_BC.prototype.standardFontSize = function() {
        return 16;
};
Window_BC.prototype.lineHeight = function() {
        return 20;
};

Window_BC.prototype.standardPadding = function() {
        return 16;
};
Window_BC.prototype.textPadding = function() {
        return 0;
};

//设置文本
Window_BC.prototype.setText = function(text) {
    if (this._text !== text) {
        this._text = text;
        this.refresh();
    }
};

//清除
Window_BC.prototype.clear = function() {
    this.setText('');
};
//刷新
Window_BC.prototype.refresh = function() {
    this.contents.clear();
    this.drawTextEx(this._text, this.textPadding(), 0);
};

Window_BC.prototype.update = function() {
    Window_Base.prototype.update.call(this);
    this.dianji()
};

Window_BC.prototype.setHandler = function(symbol, method) {
    this._handlers[symbol] = method;
};
Window_BC.prototype.isHandled = function(symbol) {
    return !!this._handlers[symbol];
};
Window_BC.prototype.callHandler = function(symbol) {
    if (this.isHandled(symbol)) {
        this._handlers[symbol]();
    }
};

Window_BC.prototype.dianji = function() {
    if (this.isOpen()) {
        if (TouchInput.isTriggered()) {
                var x = this.canvasToLocalX(TouchInput.x);
                    var y = this.canvasToLocalY(TouchInput.y);
                    if(x >= 0 && y >= 0 && x < this.width && y < this.height){
                            this.callHandler("dianji")
                    }
        }
    }
};



Graphics._createAllElements = function() {
    this._createErrorPrinter();
    this._createCanvas();
    this._createVideo();
    this._createUpperCanvas();
    this._createRenderer();
    this._createFPSMeter();
    this._createModeBox();
    this._createGameFontLoader();
   
    this._createInput()     //修改
};

/**更新所有成分
* @static
* @method _updateAllElements
* @private
*/
Graphics._updateAllElements = function() {
    this._updateRealScale();
    this._updateErrorPrinter();
    this._updateCanvas();
    this._updateVideo();
    this._updateUpperCanvas();
    this._updateRenderer();
   
    this._updateInput();     //添加
   
    this._paintUpperCanvas();
};



//创建输入
Graphics._createInput = function() {
    this._input = document.createElement("input");;
    this._input.id = 'Input';
    this._input.type ="text"
    this._input._sx ={}
    var sx = this._input._sx
    sx.xs = false
    sx.x= 0
    sx.y=0   
    sx.width =100
    sx.height= 20
    sx.fontSize = 18
    //document.body.appendChild(this._input);
};
//添加输入
Graphics._addInput = function(type,x,y,width,height,fontSize) {               
        this._input.type = type || "text"
        var sx = this._input._sx
        sx.x= x
        sx.y= y
        sx.width = width|| 100
        sx.height= height|| 20
        sx.fontSize = fontSize || 18
        this._updateInput()
        sx.xs = true
        document.body.appendChild(this._input);
       

};

//移除输入
Graphics._removeInput = function() {
    this._input.remove()
    this._input.value = null
    this._input._xs = false
    //document.body.appendChild(this._input);
};
//更新输入
Graphics._updateInput =function () {   
        this._input.style.zIndex = 12;
        var sx = this._input._sx
        var x = sx.x  * this._realScale + (window.innerWidth - this._width * this._realScale) / 2
        var y = sx.y  * this._realScale + (window.innerHeight - this._height * this._realScale) / 2

    var width = sx.width * this._realScale;
    var height = sx.height * this._realScale;
    var fontSize =        sx.fontSize * this._realScale;
    this._input.style.position = 'absolute';
    this._input.style.margin = 'auto';
    this._input.style.top = y  + 'px';
    this._input.style.left = x  + 'px' ;
    this._input.style.width = width + 'px';
    this._input.style.height = height + 'px';
    this._input.style.fontSize = fontSize + 'px';
}

//防止默认
Input._onKeyDown = function(event) {
        //如果 需要避免默认 (键值)
    if (this._shouldPreventDefault(event.keyCode)) {
            
            if (Graphics && Graphics._input && Graphics._input._sx && Graphics._input._sx.xs){
                    //允许默认
                }else {
                        //避免默认
                        event.preventDefault();
                }
    }
    //键值===144
    if (event.keyCode === 144) {    // Numlock  数字开关
        //清除
        this.clear();
    }
    var buttonName = this.keyMapper[event.keyCode];
    //如果 键名
    if (buttonName) {
            //当前状态 键 =true
        this._currentState[buttonName] = true;
    }
};



})();[/pre]


[/fold]
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.

在本版发帖返回顶部