| 
 
| 赞 | 0 |  
| VIP | 2 |  
| 好人卡 | 0 |  
| 积分 | 10 |  
| 经验 | 4249 |  
| 最后登录 | 2013-8-30 |  
| 在线时间 | 119 小时 |  
 Lv3.寻梦者 
	梦石0 星屑1020 在线时间119 小时注册时间2011-6-12帖子377 | 
| 
我用了来自《输入法名称输入》的脚本后,发现效果音造成了一定的麻烦,便简化了该脚本~
x
加入我们,或者,欢迎回来。您需要 登录 才可以下载或查看,没有帐号?注册会员  原帖地址:输入法名称输入
 http://rpg.blue/forum.php?mod=vi ... &fromuid=198306
 效果图可见原帖~
 使用方法:把两个脚本都放在main前(分开放!),并把外带的中文字库放于游戏工程文件夹根目录下。
 全键盘脚本(来自原帖):
 输入法名称输入脚本(个人修改后已去除效果音,若想使用效果音请到原帖):复制代码module Key
  @key_code = {
  # =============================
  "BACK"=> 0x08,
  "TAB"=> 0x09,
  "SHIFT"=> 0x10,
  "ALT"=> 0x12,
  "CAP"=> 0x14,
  "ESC"=> 0x1B,
  "SPACE"=> 0x20,
  "LEFT"=> 0x25,
  "UP"=> 0x26,
  "RIGHT"=> 0x27,
  "DOWN"=> 0x28,
  "ENTER" => 13,
  "LCTRL" => 0xA2,
  "RCTRL" => 0xA3,
  "LALT" => 0xA4,
  "RALT" => 0xA5,
  "SPACE" => 0x20,
  "DEL" => 0x2E,
  # =============================
  "A" => 0x41,
  "B" => 0x42,
  "C" => 0x43,
  "D" => 0x44,
  "E" => 0x45,
  "F" => 0x46,
  "G" => 0x47,
  "H" => 0x48,
  "I" => 0x49,
  "J" => 0x4A,
  "K" => 0x4B,
  "L" => 0x4C,
  "M" => 0x4D,
  "N" => 0x4E,
  "O" => 0x4F,
  "P" => 0x50,
  "Q" => 0x51,
  "R" => 0x52,
  "S" => 0x53,
  "T" => 0x54,
  "U" => 0x55,
  "V" => 0x56,
  "W" => 0x57,
  "X" => 0x58,
  "Y" => 0x59,
  "Z" => 0x5A,
  # =============================
  "F1"  => 0x70,
  "F2"  => 0x71,
  "F3"  => 0x72,
  "F4"  => 0x73,
  "F5"  => 0x74,
  "F6"  => 0x75,
  "F7"  => 0x76,
  "F8"  => 0x77,
  "F9"  => 0x78,
  "F10" => 0x79,
  "F11" => 0x7A,
  "F12" => 0x7B,
  # =============================
  "0" => 0x30,
  "1" => 0x31,
  "2" => 0x32,
  "3" => 0x33,
  "4" => 0x34,
  "5" => 0x35,
  "6" => 0x36,
  "7" => 0x37,
  "8" => 0x38,
  "9" => 0x39,
  # =============================
  ";"  => 186,
  "="  => 187,
  ","  => 188,
  "-"  => 189,
  "."  => 190,
  "/"  => 191,
  "["  => 219,
  "\\" => 220,
  "]"  => 221,
  "'"  => 222,
  # =============================
  "N0" => 0x60,
  "N1" => 0x61,
  "N2" => 0x62,
  "N3" => 0x63,
  "N4" => 0x64,
  "N5" => 0x65,
  "N6" => 0x66,
  "N7" => 0x67,
  "N8" => 0x68,
  "N9" => 0x69
  }
  @upcase = {
  48  => ")",
  49  => "!",
  50  => "@",
  51  => "#",
  52  => "$",
  53  => "%",
  54  => "^",
  55  => "&",
  56  => "*",
  57  => "(",
  186 => ":",
  187 => "+",
  188 => "<",
  189 => "_",
  190 => ">",
  191 => "?",
  219 => "{",
  220 => "|",
  221 => "}",
  222 => '"'
  }
  module_function
  @R_Key_Hash = {}
  @trigger = {}
  @R_Key_Repeat = {}
  @press_key = [0]
  GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
  def update
    @key_code.each_value do |i|
      result = GetKeyState.call(i)
      if @R_Key_Hash[i] == 1 and result != 0
        @trigger[i] = false
        next
      end
      if result != 0
        @R_Key_Hash[i] = 1
        @trigger[i] = true
        next
      else
        @R_Key_Hash[i] = 0
        @trigger[i] = false
        next
      end
    end
    if @press_key[0] > 0
      @press_key[0] -= 1
      unlash if @press_key == 0
    end
  end
  def press?(rkey)
    return GetKeyState.call(rkey) != 0
  end
  def repeat?(rkey)
    result = GetKeyState.call(rkey)
    if result != 0
      if @R_Key_Repeat[rkey].nil?
        @R_Key_Repeat[rkey] = 0
        return true
      end
      @R_Key_Repeat[rkey] += 1
    else
      @R_Key_Repeat[rkey] = nil
      @R_Key_Hash[rkey] = 0
    end
    if !@R_Key_Repeat[rkey].nil? and @R_Key_Repeat[rkey] > 10
      @R_Key_Repeat[rkey] = 6
      return true
    else
      return false
    end
  end
  def trigger?(rkey)
    return @trigger[rkey]
  end
  def [](key)
    return @key_code[key]
  end
  def caps?
    gks = Win32API.new("user32", "GetKeyState", 'i', 'i')
    result = gks.call(0x14)
    return result[0] == 1
  end
  #===================================================================
  def get_string
    n = nil
    str = nil
    @key_code.each_value do |i|
      n = i if repeat?(i) and i != 16 and i != 13 and i != 8
    end
    if n != nil
      str = @key_code.index(n)
      unless self.caps?
        str = str.downcase unless Key.press?(16)
      else
        str = str.downcase if Key.press?(16)
      end
      str = nil if str.scan(/./).size != 1
      if self.press?(16) and @upcase.include?(n)
        str = @upcase[n]
      end
      str = (n - 96).to_s if n.between?(96,105)
    end
    str = " " if n == 0x20
    str = "  " if n == 0x09
    return str.to_s
  end
  #===================================================================
end
module Input
  @self_update = method('update') if @self_update.nil?
  def self.update
    @self_update.call
    Key.update
  end
end
复制代码=begin
【输入法名称输入】 by enghao_lim(小lim)
Blog:http://www.lim-space.tk/
论坛:http://www.our-story.tk/
=================================================
01. 增加姓名可以输入的可能性,采用汉语拼音方式,让华语和英语更好的结合。
02. 采用了字库的配合,有兴趣者既可扩展该字库,相信必能更加完善。
03. 目前之真对单字开发,不支持词语输入
04. 不支持多音多字,比如:重,如在chong里搜索不到,请重试zhong。
05. 此脚本需要与修改后的全键盘脚本一起使用。
06. 此脚本还需要外带字库,默认名字为:CnWordCabin.fonc。
    记得将字库放在工程文件夹底下。
=================================================
*PS: 由于次脚本所用的文字库非常乱起八糟,具体只是根据阴阳上去来排列,
     所以有些常用字可能还被排在了后头,比如说“是”。
     
     如有谁愿意继续开发该字库或者帮忙重新排列,请联络我。
     稍微小小的补充,次字库包含超过两万个中文字。
=end
module LIM_INPUT
  
  # 代替空格的符号设置
  Space_replace = "<>"
end
class Window_Input < Window_Base
  #------------------------------
  # 【初始化】
  #------------------------------
  def initialize
    super(0,128,640,96)
    self.contents = Bitmap.new(width-32,height-32)
    self.back_opacity = self.opacity = 0
    @old_text = nil
    @text_length = 0
  end
  #------------------------------
  # 【显示文字】
  #------------------------------
  def set_text(*arg)
    # 获取显示的文字
    if (arg[0].is_a?(Integer))
      x = arg[0]
      c = 6
      text = arg[1]
    else
      x = 0
      c = 0
      text = arg[0]
    end
    x += 48
    # 开始显示
    if @old_text != text
      self.contents.clear
      self.contents.font.color = text_color(c)
      self.contents.draw_text(x,16,width-32,32,text.gsub(/ /){LIM_INPUT::Space_replace})
      @old_text = text
      @text_length = self.contents.text_size(text.gsub(/ /){LIM_INPUT::Space_replace}).width
    end
  end
  #------------------------------
  # 【获取文字的长度】
  #------------------------------
  def text_length
    return @text_length
  end
end
class Window_Word < Window_Base
  #------------------------------
  # 【初始化】
  #------------------------------
  def initialize
    super(0,224,640,96)
    self.contents = Bitmap.new(width-32,height-32)
    @old_word = []
  end
  #------------------------------
  # 【显示文字选项】
  #------------------------------
  def set_text(word_array)
    if @old_word != word_array
      x = 0
      bitmap = Bitmap.new(width-32,height-32)
      for i in 0...word_array.size
        k = (i+1)%10
        bitmap.draw_text(x,0,22,32,k.to_s,1)
        bitmap.draw_text(x,32,22,32,word_array[i],1)
        x += 22
        x += 22 if (i != word_array.size - 1)
      end
      self.contents.clear
      _x = (width-32-x)/2
      self.contents.blt(_x,0,bitmap,Rect.new(0,0,x,64))
      @old_word = word_array
    end
  end
end
class Window_Name < Window_Base
  #------------------------------
  # 【初始化】
  #------------------------------
  def initialize(actor)
    super(0,96,640,128)
    self.contents = Bitmap.new(width-32,height-32)
    @actor = actor
    refresh
  end
  #------------------------------
  # 【显示图片】
  #------------------------------
  def refresh
    self.contents.draw_text(4,0,width-32,32,"请输入新的名字:")
    draw_actor_graphic(@actor,24,88)
  end
end
class Scene_Name
  #------------------------------
  # 【主循环】
  #------------------------------
  def main
    # 获取角色 与 各种变量设置
    @actor = $game_actors[$game_temp.name_actor_id]
    @max_word = $game_temp.name_max_char
    @inputed = @actor.name
    @now_input = ""
    @old_now_input = ""
    @old_key = ""
    @now_index = 0
    @wait_count = 0
    # 读取字库
    word_cabin = File.open("CnWordCabin.fonc","rb")
    @cn_key = Marshal.load(word_cabin)
    @cn_word = Marshal.load(word_cabin)
    # 生成各种窗口
    @window_name = Window_Name.new(@actor)
    @window_input = Window_Input.new
    @window_input2 = Window_Input.new
    @window_word = Window_Word.new
    @window_word.visible = false
    @window_count = Window_Help.new
    @window_count.y = 416
    @window_count.back_opacity = @window_count.opacity = 0
    reset_text
    @command_help = Window_Base.new(64,128,512,64)
    @command_help.contents = Bitmap.new(480,32)
    @command_help.contents.draw_text(0,0,480,32,"确定输入完毕?",1)
    @command_help.visible = false
    @command_exit = Window_Command.new(160,["是","否"])
    @command_exit.x = 240
    @command_exit.y = 196
    @command_exit.active = @command_exit.visible = false
    Graphics.transition(20)
    # 开始循环
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    # 释放
    @window_name.dispose
    @window_input.dispose
    @window_input2.dispose
    @window_word.dispose
    @window_count.dispose
    @command_help.dispose
    @command_exit.dispose
  end
  #------------------------------
  # 【循环刷新】
  #------------------------------
  def update
    # 各种刷新
    @window_name.update
    @window_input.update
    @window_input2.update
    @window_word.update
    @window_count.update
    @command_help.update
    @command_exit.update
    # 是否正在选取文字
    if @window_word.visible and Key.trigger?(0x31) # Number 1
      choose_the_word(1)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x32) # Number 2
      choose_the_word(2)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x33) # Number 3
      choose_the_word(3)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x34) # Number 4
      choose_the_word(4)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x35) # Number 5
      choose_the_word(5)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x36) # Number 6
      choose_the_word(6)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x37) # Number 7
      choose_the_word(7)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x38) # Number 8
      choose_the_word(8)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x39) # Number 9
      choose_the_word(9)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(0x30) # Number 0
      choose_the_word(10)
      Key.get_string
    elsif @window_word.visible and Key.trigger?(187) # Key +
      if @now_index + 10 < @cn_word[@now_input].size
        @now_index += 10
        show_match_word(@now_input)
      else
      end
      Key.get_string
    elsif @window_word.visible and Key.trigger?(189) # Key -
      if @now_index - 10 >= 0
        @now_index -= 10
        show_match_word(@now_input)
      else
      end
      Key.get_string
      @wait_count = 4
    end
    # 文字输入刷新
    @now_input += Key.get_string
    @window_input2.set_text(@window_input.text_length,@now_input)
    # 判断匹配拼音
    if @cn_key.include?(@now_input)
      show_match_word(@now_input)
      @window_word.visible = true
    else
      @window_word.visible = false
    end
    # 各种情况刷新
    if @wait_count > 0
      @wait_count -= 1
      return
    elsif @command_exit.active
      command_exit_update
    elsif Key.trigger?(13) # Enter
      enter_trigger_update
    elsif Key.trigger?(8) or Key.press?(8) # Backspace
      return if (@now_input == "" and @inputed == "")
      backspace_trigger_update
    end
  end
  #------------------------------
  # 【询问退出刷新】
  #------------------------------
  def command_exit_update
    if Input.trigger?(Input::C)
      case @command_exit.index
      when 0
        @actor.name = @inputed
        $scene = Scene_Map.new
      when 1
        command_exit_activated?(false)
      end
    end
    if Input.trigger?(Input::B)
      command_exit_activated?(false)
    end
  end
  #------------------------------
  # 【确定输入的文字】
  #------------------------------
  def enter_trigger_update
    # 还在输入的情况
    if @now_input != ""
      temp = @now_input.scan(/./)
      for char in temp
        if @inputed.scan(/./).size >= @max_word
          break
        end
        @inputed += char
      end
      @now_input = ""
      reset_text
    # 没有输入的情况
    else
      command_exit_activated?(true)
    end
  end
  #------------------------------
  # 【确定输入的文字】
  #------------------------------
  def backspace_trigger_update
    if @now_input != ""
      temp = @now_input.scan(/./)
      @now_input = ""
      for i in 0...temp.size-1
        @now_input += temp[i]
      end
    else
      temp = @inputed.scan(/./)
      @inputed = ""
      for i in 0...temp.size-1
        @inputed += temp[i]
      end
    end
    @wait_count = 2
    reset_text
  end
  #------------------------------
  # 【重新显示文字】
  #------------------------------
  def reset_text
    @window_input.set_text(@inputed)
    @window_input2.set_text(@window_input.text_length,@now_input)
    @window_count.set_text("还有 #{@[email protected](/./).size} 字可以输入",2)
  end
  #------------------------------
  # 【匹配文字显示】
  #------------------------------
  def show_match_word(key)
    if @old_key != key
      @now_index = 0
      @old_key = key
    end
    max = [@cn_word[key].size-@now_index,10].min
    word_array = []
    for i in 0...max
      k = i + @now_index
      word_array.push(@cn_word[key][k])
    end
    @window_word.set_text(word_array)
  end
  #------------------------------
  # 【选择的文字】
  #------------------------------
  def choose_the_word(n)
    n -= 1
    char = @cn_word[@now_input][@now_index+n]
    if @inputed.scan(/./).size == @max_word or char.nil?
      return
    end
    @inputed += char
    @now_input = ""
    reset_text
  end
  #------------------------------
  # 【激活退出选项】
  #------------------------------
  def command_exit_activated?(bool)
    @window_name.visible = !bool
    @window_input.visible = !bool
    @window_input2.visible = !bool
    @window_count.visible = !bool
    @command_help.visible = bool
    @command_exit.visible = bool
    @command_exit.active = bool
  end
end
 | 
 |