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

Project1

 找回密码
 注册会员
搜索
查看: 2408|回复: 0
打印 上一主题 下一主题

[通用发布] 【修改】《输入法名称输入》无声简易版

[复制链接]

Lv2.观梦者

梦石
0
星屑
840
在线时间
119 小时
注册时间
2011-6-12
帖子
377
跳转到指定楼层
1
发表于 2011-7-11 16:29:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
我用了来自《输入法名称输入》的脚本后,发现效果音造成了一定的麻烦,便简化了该脚本~
原帖地址:输入法名称输入
http://rpg.blue/forum.php?mod=vi ... &fromuid=198306
效果图可见原帖~
使用方法:把两个脚本都放在main前(分开放!),并把外带的中文字库放于游戏工程文件夹根目录下。
全键盘脚本(来自原帖):
  1. module Key
  2.   @key_code = {
  3.   # =============================
  4.   "BACK"=> 0x08,
  5.   "TAB"=> 0x09,
  6.   "SHIFT"=> 0x10,
  7.   "ALT"=> 0x12,
  8.   "CAP"=> 0x14,
  9.   "ESC"=> 0x1B,
  10.   "SPACE"=> 0x20,
  11.   "LEFT"=> 0x25,
  12.   "UP"=> 0x26,
  13.   "RIGHT"=> 0x27,
  14.   "DOWN"=> 0x28,
  15.   "ENTER" => 13,
  16.   "LCTRL" => 0xA2,
  17.   "RCTRL" => 0xA3,
  18.   "LALT" => 0xA4,
  19.   "RALT" => 0xA5,
  20.   "SPACE" => 0x20,
  21.   "DEL" => 0x2E,
  22.   # =============================
  23.   "A" => 0x41,
  24.   "B" => 0x42,
  25.   "C" => 0x43,
  26.   "D" => 0x44,
  27.   "E" => 0x45,
  28.   "F" => 0x46,
  29.   "G" => 0x47,
  30.   "H" => 0x48,
  31.   "I" => 0x49,
  32.   "J" => 0x4A,
  33.   "K" => 0x4B,
  34.   "L" => 0x4C,
  35.   "M" => 0x4D,
  36.   "N" => 0x4E,
  37.   "O" => 0x4F,
  38.   "P" => 0x50,
  39.   "Q" => 0x51,
  40.   "R" => 0x52,
  41.   "S" => 0x53,
  42.   "T" => 0x54,
  43.   "U" => 0x55,
  44.   "V" => 0x56,
  45.   "W" => 0x57,
  46.   "X" => 0x58,
  47.   "Y" => 0x59,
  48.   "Z" => 0x5A,
  49.   # =============================
  50.   "F1"  => 0x70,
  51.   "F2"  => 0x71,
  52.   "F3"  => 0x72,
  53.   "F4"  => 0x73,
  54.   "F5"  => 0x74,
  55.   "F6"  => 0x75,
  56.   "F7"  => 0x76,
  57.   "F8"  => 0x77,
  58.   "F9"  => 0x78,
  59.   "F10" => 0x79,
  60.   "F11" => 0x7A,
  61.   "F12" => 0x7B,
  62.   # =============================
  63.   "0" => 0x30,
  64.   "1" => 0x31,
  65.   "2" => 0x32,
  66.   "3" => 0x33,
  67.   "4" => 0x34,
  68.   "5" => 0x35,
  69.   "6" => 0x36,
  70.   "7" => 0x37,
  71.   "8" => 0x38,
  72.   "9" => 0x39,
  73.   # =============================
  74.   ";"  => 186,
  75.   "="  => 187,
  76.   ","  => 188,
  77.   "-"  => 189,
  78.   "."  => 190,
  79.   "/"  => 191,
  80.   "["  => 219,
  81.   "\\" => 220,
  82.   "]"  => 221,
  83.   "'"  => 222,
  84.   # =============================
  85.   "N0" => 0x60,
  86.   "N1" => 0x61,
  87.   "N2" => 0x62,
  88.   "N3" => 0x63,
  89.   "N4" => 0x64,
  90.   "N5" => 0x65,
  91.   "N6" => 0x66,
  92.   "N7" => 0x67,
  93.   "N8" => 0x68,
  94.   "N9" => 0x69
  95.   }
  96.   @upcase = {
  97.   48  => ")",
  98.   49  => "!",
  99.   50  => "@",
  100.   51  => "#",
  101.   52  => "$",
  102.   53  => "%",
  103.   54  => "^",
  104.   55  => "&",
  105.   56  => "*",
  106.   57  => "(",
  107.   186 => ":",
  108.   187 => "+",
  109.   188 => "<",
  110.   189 => "_",
  111.   190 => ">",
  112.   191 => "?",
  113.   219 => "{",
  114.   220 => "|",
  115.   221 => "}",
  116.   222 => '"'
  117.   }
  118.   module_function
  119.   @R_Key_Hash = {}
  120.   @trigger = {}
  121.   @R_Key_Repeat = {}
  122.   @press_key = [0]
  123.   GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
  124.   def update
  125.     @key_code.each_value do |i|
  126.       result = GetKeyState.call(i)
  127.       if @R_Key_Hash[i] == 1 and result != 0
  128.         @trigger[i] = false
  129.         next
  130.       end
  131.       if result != 0
  132.         @R_Key_Hash[i] = 1
  133.         @trigger[i] = true
  134.         next
  135.       else
  136.         @R_Key_Hash[i] = 0
  137.         @trigger[i] = false
  138.         next
  139.       end
  140.     end
  141.     if @press_key[0] > 0
  142.       @press_key[0] -= 1
  143.       unlash if @press_key == 0
  144.     end
  145.   end
  146.   def press?(rkey)
  147.     return GetKeyState.call(rkey) != 0
  148.   end
  149.   def repeat?(rkey)
  150.     result = GetKeyState.call(rkey)
  151.     if result != 0
  152.       if @R_Key_Repeat[rkey].nil?
  153.         @R_Key_Repeat[rkey] = 0
  154.         return true
  155.       end
  156.       @R_Key_Repeat[rkey] += 1
  157.     else
  158.       @R_Key_Repeat[rkey] = nil
  159.       @R_Key_Hash[rkey] = 0
  160.     end
  161.     if !@R_Key_Repeat[rkey].nil? and @R_Key_Repeat[rkey] > 10
  162.       @R_Key_Repeat[rkey] = 6
  163.       return true
  164.     else
  165.       return false
  166.     end
  167.   end
  168.   def trigger?(rkey)
  169.     return @trigger[rkey]
  170.   end
  171.   def [](key)
  172.     return @key_code[key]
  173.   end
  174.   def caps?
  175.     gks = Win32API.new("user32", "GetKeyState", 'i', 'i')
  176.     result = gks.call(0x14)
  177.     return result[0] == 1
  178.   end
  179.   #===================================================================
  180.   def get_string
  181.     n = nil
  182.     str = nil
  183.     @key_code.each_value do |i|
  184.       n = i if repeat?(i) and i != 16 and i != 13 and i != 8
  185.     end
  186.     if n != nil
  187.       str = @key_code.index(n)
  188.       unless self.caps?
  189.         str = str.downcase unless Key.press?(16)
  190.       else
  191.         str = str.downcase if Key.press?(16)
  192.       end
  193.       str = nil if str.scan(/./).size != 1
  194.       if self.press?(16) and @upcase.include?(n)
  195.         str = @upcase[n]
  196.       end
  197.       str = (n - 96).to_s if n.between?(96,105)
  198.     end
  199.     str = " " if n == 0x20
  200.     str = "  " if n == 0x09
  201.     return str.to_s
  202.   end
  203.   #===================================================================
  204. end

  205. module Input
  206.   @self_update = method('update') if @self_update.nil?
  207.   def self.update
  208.     @self_update.call
  209.     Key.update
  210.   end
  211. end
复制代码
输入法名称输入脚本(个人修改后已去除效果音,若想使用效果音请到原帖):
  1. =begin

  2. 【输入法名称输入】 by enghao_lim(小lim)

  3. Blog:http://www.lim-space.tk/
  4. 论坛:http://www.our-story.tk/

  5. =================================================

  6. 01. 增加姓名可以输入的可能性,采用汉语拼音方式,让华语和英语更好的结合。

  7. 02. 采用了字库的配合,有兴趣者既可扩展该字库,相信必能更加完善。

  8. 03. 目前之真对单字开发,不支持词语输入

  9. 04. 不支持多音多字,比如:重,如在chong里搜索不到,请重试zhong。

  10. 05. 此脚本需要与修改后的全键盘脚本一起使用。

  11. 06. 此脚本还需要外带字库,默认名字为:CnWordCabin.fonc。
  12.     记得将字库放在工程文件夹底下。

  13. =================================================

  14. *PS: 由于次脚本所用的文字库非常乱起八糟,具体只是根据阴阳上去来排列,
  15.      所以有些常用字可能还被排在了后头,比如说“是”。
  16.      
  17.      如有谁愿意继续开发该字库或者帮忙重新排列,请联络我。
  18.      稍微小小的补充,次字库包含超过两万个中文字。

  19. =end

  20. module LIM_INPUT
  21.   
  22.   # 代替空格的符号设置
  23.   Space_replace = "<>"

  24. end

  25. class Window_Input < Window_Base
  26.   #------------------------------
  27.   # 【初始化】
  28.   #------------------------------
  29.   def initialize
  30.     super(0,128,640,96)
  31.     self.contents = Bitmap.new(width-32,height-32)
  32.     self.back_opacity = self.opacity = 0
  33.     @old_text = nil
  34.     @text_length = 0
  35.   end
  36.   #------------------------------
  37.   # 【显示文字】
  38.   #------------------------------
  39.   def set_text(*arg)
  40.     # 获取显示的文字
  41.     if (arg[0].is_a?(Integer))
  42.       x = arg[0]
  43.       c = 6
  44.       text = arg[1]
  45.     else
  46.       x = 0
  47.       c = 0
  48.       text = arg[0]
  49.     end
  50.     x += 48
  51.     # 开始显示
  52.     if @old_text != text
  53.       self.contents.clear
  54.       self.contents.font.color = text_color(c)
  55.       self.contents.draw_text(x,16,width-32,32,text.gsub(/ /){LIM_INPUT::Space_replace})
  56.       @old_text = text
  57.       @text_length = self.contents.text_size(text.gsub(/ /){LIM_INPUT::Space_replace}).width
  58.     end
  59.   end
  60.   #------------------------------
  61.   # 【获取文字的长度】
  62.   #------------------------------
  63.   def text_length
  64.     return @text_length
  65.   end
  66. end

  67. class Window_Word < Window_Base
  68.   #------------------------------
  69.   # 【初始化】
  70.   #------------------------------
  71.   def initialize
  72.     super(0,224,640,96)
  73.     self.contents = Bitmap.new(width-32,height-32)
  74.     @old_word = []
  75.   end
  76.   #------------------------------
  77.   # 【显示文字选项】
  78.   #------------------------------
  79.   def set_text(word_array)
  80.     if @old_word != word_array
  81.       x = 0
  82.       bitmap = Bitmap.new(width-32,height-32)
  83.       for i in 0...word_array.size
  84.         k = (i+1)%10
  85.         bitmap.draw_text(x,0,22,32,k.to_s,1)
  86.         bitmap.draw_text(x,32,22,32,word_array[i],1)
  87.         x += 22
  88.         x += 22 if (i != word_array.size - 1)
  89.       end
  90.       self.contents.clear
  91.       _x = (width-32-x)/2
  92.       self.contents.blt(_x,0,bitmap,Rect.new(0,0,x,64))
  93.       @old_word = word_array
  94.     end
  95.   end
  96. end

  97. class Window_Name < Window_Base
  98.   #------------------------------
  99.   # 【初始化】
  100.   #------------------------------
  101.   def initialize(actor)
  102.     super(0,96,640,128)
  103.     self.contents = Bitmap.new(width-32,height-32)
  104.     @actor = actor
  105.     refresh
  106.   end
  107.   #------------------------------
  108.   # 【显示图片】
  109.   #------------------------------
  110.   def refresh
  111.     self.contents.draw_text(4,0,width-32,32,"请输入新的名字:")
  112.     draw_actor_graphic(@actor,24,88)
  113.   end
  114. end

  115. class Scene_Name
  116.   #------------------------------
  117.   # 【主循环】
  118.   #------------------------------
  119.   def main
  120.     # 获取角色 与 各种变量设置
  121.     @actor = $game_actors[$game_temp.name_actor_id]
  122.     @max_word = $game_temp.name_max_char
  123.     @inputed = @actor.name
  124.     @now_input = ""
  125.     @old_now_input = ""
  126.     @old_key = ""
  127.     @now_index = 0
  128.     @wait_count = 0
  129.     # 读取字库
  130.     word_cabin = File.open("CnWordCabin.fonc","rb")
  131.     @cn_key = Marshal.load(word_cabin)
  132.     @cn_word = Marshal.load(word_cabin)
  133.     # 生成各种窗口
  134.     @window_name = Window_Name.new(@actor)
  135.     @window_input = Window_Input.new
  136.     @window_input2 = Window_Input.new
  137.     @window_word = Window_Word.new
  138.     @window_word.visible = false
  139.     @window_count = Window_Help.new
  140.     @window_count.y = 416
  141.     @window_count.back_opacity = @window_count.opacity = 0
  142.     reset_text
  143.     @command_help = Window_Base.new(64,128,512,64)
  144.     @command_help.contents = Bitmap.new(480,32)
  145.     @command_help.contents.draw_text(0,0,480,32,"确定输入完毕?",1)
  146.     @command_help.visible = false
  147.     @command_exit = Window_Command.new(160,["是","否"])
  148.     @command_exit.x = 240
  149.     @command_exit.y = 196
  150.     @command_exit.active = @command_exit.visible = false
  151.     Graphics.transition(20)
  152.     # 开始循环
  153.     loop do
  154.       Graphics.update
  155.       Input.update
  156.       update
  157.       break if $scene != self
  158.     end
  159.     # 释放
  160.     @window_name.dispose
  161.     @window_input.dispose
  162.     @window_input2.dispose
  163.     @window_word.dispose
  164.     @window_count.dispose
  165.     @command_help.dispose
  166.     @command_exit.dispose
  167.   end
  168.   #------------------------------
  169.   # 【循环刷新】
  170.   #------------------------------
  171.   def update
  172.     # 各种刷新
  173.     @window_name.update
  174.     @window_input.update
  175.     @window_input2.update
  176.     @window_word.update
  177.     @window_count.update
  178.     @command_help.update
  179.     @command_exit.update
  180.     # 是否正在选取文字
  181.     if @window_word.visible and Key.trigger?(0x31) # Number 1
  182.       choose_the_word(1)
  183.       Key.get_string
  184.     elsif @window_word.visible and Key.trigger?(0x32) # Number 2
  185.       choose_the_word(2)
  186.       Key.get_string
  187.     elsif @window_word.visible and Key.trigger?(0x33) # Number 3
  188.       choose_the_word(3)
  189.       Key.get_string
  190.     elsif @window_word.visible and Key.trigger?(0x34) # Number 4
  191.       choose_the_word(4)
  192.       Key.get_string
  193.     elsif @window_word.visible and Key.trigger?(0x35) # Number 5
  194.       choose_the_word(5)
  195.       Key.get_string
  196.     elsif @window_word.visible and Key.trigger?(0x36) # Number 6
  197.       choose_the_word(6)
  198.       Key.get_string
  199.     elsif @window_word.visible and Key.trigger?(0x37) # Number 7
  200.       choose_the_word(7)
  201.       Key.get_string
  202.     elsif @window_word.visible and Key.trigger?(0x38) # Number 8
  203.       choose_the_word(8)
  204.       Key.get_string
  205.     elsif @window_word.visible and Key.trigger?(0x39) # Number 9
  206.       choose_the_word(9)
  207.       Key.get_string
  208.     elsif @window_word.visible and Key.trigger?(0x30) # Number 0
  209.       choose_the_word(10)
  210.       Key.get_string
  211.     elsif @window_word.visible and Key.trigger?(187) # Key +
  212.       if @now_index + 10 < @cn_word[@now_input].size
  213.         @now_index += 10
  214.         show_match_word(@now_input)
  215.       else
  216.       end
  217.       Key.get_string
  218.     elsif @window_word.visible and Key.trigger?(189) # Key -
  219.       if @now_index - 10 >= 0
  220.         @now_index -= 10
  221.         show_match_word(@now_input)
  222.       else

  223.       end
  224.       Key.get_string
  225.       @wait_count = 4
  226.     end
  227.     # 文字输入刷新
  228.     @now_input += Key.get_string
  229.     @window_input2.set_text(@window_input.text_length,@now_input)
  230.     # 判断匹配拼音
  231.     if @cn_key.include?(@now_input)
  232.       show_match_word(@now_input)
  233.       @window_word.visible = true
  234.     else
  235.       @window_word.visible = false
  236.     end
  237.     # 各种情况刷新
  238.     if @wait_count > 0
  239.       @wait_count -= 1
  240.       return
  241.     elsif @command_exit.active
  242.       command_exit_update
  243.     elsif Key.trigger?(13) # Enter
  244.       enter_trigger_update
  245.     elsif Key.trigger?(8) or Key.press?(8) # Backspace
  246.       return if (@now_input == "" and @inputed == "")
  247.       backspace_trigger_update
  248.     end
  249.   end
  250.   #------------------------------
  251.   # 【询问退出刷新】
  252.   #------------------------------
  253.   def command_exit_update
  254.     if Input.trigger?(Input::C)
  255.       case @command_exit.index
  256.       when 0
  257.         @actor.name = @inputed
  258.         $scene = Scene_Map.new
  259.       when 1
  260.         command_exit_activated?(false)
  261.       end
  262.     end
  263.     if Input.trigger?(Input::B)
  264.       command_exit_activated?(false)
  265.     end
  266.   end
  267.   #------------------------------
  268.   # 【确定输入的文字】
  269.   #------------------------------
  270.   def enter_trigger_update
  271.     # 还在输入的情况
  272.     if @now_input != ""
  273.       temp = @now_input.scan(/./)
  274.       for char in temp
  275.         if @inputed.scan(/./).size >= @max_word
  276.           break
  277.         end
  278.         @inputed += char
  279.       end
  280.       @now_input = ""
  281.       reset_text
  282.     # 没有输入的情况
  283.     else
  284.       command_exit_activated?(true)
  285.     end
  286.   end
  287.   #------------------------------
  288.   # 【确定输入的文字】
  289.   #------------------------------
  290.   def backspace_trigger_update
  291.     if @now_input != ""
  292.       temp = @now_input.scan(/./)
  293.       @now_input = ""
  294.       for i in 0...temp.size-1
  295.         @now_input += temp[i]
  296.       end
  297.     else
  298.       temp = @inputed.scan(/./)
  299.       @inputed = ""
  300.       for i in 0...temp.size-1
  301.         @inputed += temp[i]
  302.       end
  303.     end
  304.     @wait_count = 2
  305.     reset_text
  306.   end
  307.   #------------------------------
  308.   # 【重新显示文字】
  309.   #------------------------------
  310.   def reset_text
  311.     @window_input.set_text(@inputed)
  312.     @window_input2.set_text(@window_input.text_length,@now_input)
  313.     @window_count.set_text("还有 #{@[email protected](/./).size} 字可以输入",2)
  314.   end
  315.   #------------------------------
  316.   # 【匹配文字显示】
  317.   #------------------------------
  318.   def show_match_word(key)
  319.     if @old_key != key
  320.       @now_index = 0
  321.       @old_key = key
  322.     end
  323.     max = [@cn_word[key].size-@now_index,10].min
  324.     word_array = []
  325.     for i in 0...max
  326.       k = i + @now_index
  327.       word_array.push(@cn_word[key][k])
  328.     end
  329.     @window_word.set_text(word_array)
  330.   end
  331.   #------------------------------
  332.   # 【选择的文字】
  333.   #------------------------------
  334.   def choose_the_word(n)
  335.     n -= 1
  336.     char = @cn_word[@now_input][@now_index+n]
  337.     if @inputed.scan(/./).size == @max_word or char.nil?
  338.       return
  339.     end
  340.     @inputed += char
  341.     @now_input = ""
  342.     reset_text
  343.   end
  344.   #------------------------------
  345.   # 【激活退出选项】
  346.   #------------------------------
  347.   def command_exit_activated?(bool)
  348.     @window_name.visible = !bool
  349.     @window_input.visible = !bool
  350.     @window_input2.visible = !bool
  351.     @window_count.visible = !bool
  352.     @command_help.visible = bool
  353.     @command_exit.visible = bool
  354.     @command_exit.active = bool
  355.   end
  356. end
复制代码


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

本版积分规则

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

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

GMT+8, 2024-5-13 04:08

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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