扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 121|回复: 0

[转载发布] 中文名输入插件

[复制链接]
累计送礼:
0 个
累计收礼:
0 个
  • TA的每日心情
    开心
    2025-2-4 02:05
  • 签到天数: 110 天

    连续签到: 2 天

    [LV.6]常住居民II

    2327

    主题

    395

    回帖

    1万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    6
    卡币
    10465
    OK点
    16
    推广点
    0
    同能卷
    0
    积分
    13215

    灌水之王

    发表于 2024-3-7 04:54:31 | 显示全部楼层 |阅读模式
    写插件貌似会上瘾,刚又整出来了一个中文名输入!
    游戏默认的输入方式太Low了,果断自己写一个替换掉!
    现在可以用输入法了,手机端没实验,有条件的帮忙试一下!
    移动端无法确定的BUG已修复!

    JAVASCRIPT 代码下载

    [JavaScript] 纯文本查看 复制代码
    /*:
     * 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();
      };
    })();
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2025-3-10 16:09 , Processed in 0.136708 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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