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

Project1

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

[已经解决] 【求高人!】如何像仙剑时空传2那样名称输入用自己的输入法?

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
38 小时
注册时间
2011-8-19
帖子
30
跳转到指定楼层
1
发表于 2011-11-19 13:15:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
输入法插件就算了把- -      仙剑时空传2的是用系统输入法输入的(就是说是用你打字的输入法,不是插件),要怎么用啊?

Lv1.梦旅人

被遗忘の机器

梦石
0
星屑
73
在线时间
402 小时
注册时间
2010-7-24
帖子
1492
2
发表于 2011-11-19 13:23:04 | 只看该作者
这个标题应该扣分的把= =
要是能用输入法的话就没必要写输入文字脚本了
然后要输入名称脚本请自行搜索
【镇楼】少年吃我大屌
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
38 小时
注册时间
2011-8-19
帖子
30
3
 楼主| 发表于 2011-11-19 13:33:32 | 只看该作者
本帖最后由 哀、浪者 于 2011-11-19 13:37 编辑
时光机 发表于 2011-11-19 13:23
这个标题应该扣分的把= =
要是能用输入法的话就没必要写输入文字脚本了
然后要输入名称脚本请自行搜索 ...


我都说了不要输入法脚本的了。。。    输入法脚本是软件带的输入法,我要的是用系统输入法弄的- -    你没玩过时空传2把- -
回复

使用道具 举报

Lv1.梦旅人

井蓝

梦石
0
星屑
58
在线时间
351 小时
注册时间
2011-1-14
帖子
277
4
发表于 2011-11-19 14:52:33 | 只看该作者
  1. #==============================================================================
  2. # ■ Scene_Name
  3. #------------------------------------------------------------------------------
  4. #  角色名称输入画面的类。
  5. #==============================================================================

  6. class Scene_Name
  7.   #--------------------------------------------------------------------------
  8.   # ● 主处理
  9.   #--------------------------------------------------------------------------
  10.   def main
  11.     # 获取角色
  12.     @actor = $game_actors[$game_temp.name_actor_id]
  13.     # 生成窗口
  14.    
  15.     @window = Window_Base.new(0,100,640,200)
  16.     @window.contents = Bitmap.new(400,160)
  17.     @window.contents.font.size = 22
  18.     @window.contents.draw_text(20, 20, 400, 38, "请输入您的角色名称:")
  19.     @window.cursor_rect.set(180, 65, 230, 30)
  20.     @window.active = true
  21.    
  22.     @window2 = Window_Base.new(540,400,100,80)
  23.     @window2.contents = Bitmap.new(68,28)
  24.     @window2.contents.draw_text(8, 8, 70, 21, "确定")
  25.     @window2.active = false
  26.    
  27.     @window3 = Window_Base.new(0,300,640,100)
  28.     @window3.contents = Bitmap.new(400,160)
  29.     @window3.contents.font.size = 22
  30.     @window3.contents.draw_text(20, 20, 400, 38, "提示:请切换到您常用的输入法,输入角色的名称。")
  31.     @window3.active = true
  32.    
  33.     @window4 = Window_Base.new(0,400,540,80)
  34.     @window4.contents = Bitmap.new(500,160)
  35.     @window4.contents.draw_text(8, 20, 400, 21, "提示:“←”“→”选择字目")
  36.     @window4.active = false
  37.    
  38.     @window5 = Window_Base.new(0,0,640,100)
  39.     @window5.contents = Bitmap.new(640-32,100-32)
  40.     @window5.contents.draw_text(8, 20, 400, 25, "提示:“Pageup”键切换输入/确定")
  41.     @window5.active = false
  42.    
  43.    
  44.    
  45.     @v = Viewport.new(170,185,320,20)
  46.     @v.color.set(0,0,0,120)
  47.     @tf = Type_Field.new(@v,@actor.name,nil,20,Color.new(0,0,0),$game_temp.name_max_char*3-2)
  48.     @tf.active = true
  49.     # 执行过渡
  50.     Graphics.transition
  51.     # 主循环
  52.     loop do
  53.       # 刷新游戏画面
  54.       Graphics.update
  55.       # 刷新输入信息
  56.       Input.update
  57.       # 刷新信息
  58.       update
  59.       # 如果画面切换就中断循环
  60.       if $scene != self
  61.         break
  62.       end
  63.     end
  64.     # 准备过渡
  65.     Graphics.freeze
  66.     # 释放窗口
  67.     @tf.dispose
  68.     @window.dispose
  69.     @window2.dispose
  70.     @window3.dispose
  71.     @window4.dispose
  72.     @window5.dispose
  73.     @v.dispose
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● 刷新画面
  77.   #--------------------------------------------------------------------------
  78.   def update
  79.     # 刷新窗口
  80.     @window.update
  81.     @window2.update
  82.     if @window2.active
  83.       @window2.cursor_rect.set(6, 6, 50, 28)
  84.       if Input.trigger?(Input::C)
  85.         if @tf.get_text != ""
  86.         @actor.name = @tf.get_text
  87.         $game_system.se_play($data_system.decision_se)
  88.         $scene = Scene_Gender.new
  89.         else
  90.         $game_system.se_play($data_system.buzzer_se)
  91.         end
  92.       end
  93.       if Input.trigger?(Input::L)
  94.         @window2.active = false
  95.         @window.active = true
  96.         @tf.active = true
  97.         @window2.cursor_rect.set(0, 0, 0, 0)
  98.       end
  99.       return
  100.     end
  101.     @window.cursor_rect.set(180, 65, 230, 30)
  102.     @tf.update
  103.     if Input.trigger?(Input::L)
  104.       @window2.active = true
  105.       @window.active = false
  106.       @tf.active = false
  107.       @tf.update
  108.       @window.cursor_rect.set(0, 0, 0, 0)
  109.     end
  110.   end
  111. end
复制代码
  1. =begin

  2.   脚本:【完美输入法修正】
  3.   
  4.   功能:输入法。
  5.   
  6.   说明: 直接用Type_Field创建输入域即可进行输入,在此可根据Type_Field域对象
  7.   
  8.         的活动标记active来自定义刷新等,在Type_Field中需要自己处理特殊按键
  9.         
  10.         的处理方法。具体不明白之处请参考范例工程。

  11.   作者:灼眼的夏娜
  12.   
  13.   补充: 至于以前那个版本也许很多人都注意到那个烦人的问题了吧,按Enter和Tab那
  14.   
  15.         些会出现不爽的声音,这个版本解决了那个问题,并简化添加了Type_Field类
  16.         
  17.         来方便创建输入域。

  18. =end

  19. #==============================================================================
  20. # ■ RInput
  21. #------------------------------------------------------------------------------
  22. #  全键盘处理的模块。
  23. #==============================================================================
  24. module RInput
  25.   #--------------------------------------------------------------------------
  26.   # ● 常量定义
  27.   #--------------------------------------------------------------------------
  28.   ENTER             = 0x0D
  29.   SPACE             = 0x20
  30.   UP                = 0x26
  31.   DOWN              = 0x28
  32.   LEFT              = 0x25
  33.   RIGHT             = 0x27
  34.   LCTRL             = 0xA2
  35.   #LATL              = 0xA4
  36.   #--------------------------------------------------------------------------
  37.   # ● 临时Hash
  38.   #--------------------------------------------------------------------------
  39.   @R_Key_Hash = {}
  40.   @R_Key_Repeat = {}
  41.   
  42.   #--------------------------------------------------------------------------
  43.   # ● 唯一API
  44.   #--------------------------------------------------------------------------
  45.   GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
  46.   #--------------------------------------------------------------------------
  47.   # ● 单键处理
  48.   #--------------------------------------------------------------------------
  49.   def self.trigger?(rkey)
  50.     result = GetKeyState.call(rkey)
  51.     if @R_Key_Hash[rkey] == 1 and result != 0
  52.       return false
  53.     end
  54.     if result != 0
  55.       @R_Key_Hash[rkey] = 1
  56.       return true
  57.     else
  58.       @R_Key_Hash[rkey] = 0
  59.       return false
  60.     end
  61.   end
  62. end

  63. #==============================================================================
  64. # ■ EasyConv
  65. #------------------------------------------------------------------------------
  66. #  转码模块。
  67. #==============================================================================
  68. module EasyConv

  69.   #--------------------------------------------------------------------------
  70.   # ● 常量定义
  71.   #--------------------------------------------------------------------------
  72.   CP_ACP = 0
  73.   CP_UTF8 = 65001

  74.   #--------------------------------------------------------------------------
  75.   # ● 模块函数
  76.   #--------------------------------------------------------------------------
  77.   module_function
  78.   
  79.   #--------------------------------------------------------------------------
  80.   # ● 转码
  81.   #--------------------------------------------------------------------------
  82.   def s2u(text)

  83.     m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  84.     w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

  85.     len = m2w.call(CP_ACP, 0, text, -1, nil, 0)
  86.     buf = "\0" * (len*2)
  87.     m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2)

  88.     len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil)
  89.     ret = "\0" * len
  90.     w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil)
  91.     ret[-1] = ""
  92.    
  93.     return ret
  94.   end

  95.   #--------------------------------------------------------------------------
  96.   # ● 转码
  97.   #--------------------------------------------------------------------------
  98.   def u2s(text)
  99.    
  100.     m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  101.     w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

  102.     len = m2w.call(CP_UTF8, 0, text, -1, nil, 0)
  103.     buf = "\0" * (len*2)
  104.     m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2)

  105.     len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
  106.     ret = "\0" * len
  107.     w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
  108.    
  109.     return ret
  110.   end

  111. end

  112. #==============================================================================
  113. # ■ TypeAPI
  114. #------------------------------------------------------------------------------
  115. #  输入法相关API模块。
  116. #==============================================================================
  117. module TypeAPI
  118.   
  119.   #--------------------------------------------------------------------------
  120.   # ● API定义
  121.   #--------------------------------------------------------------------------
  122.   GPPS         = Win32API.new("kernel32","GetPrivateProfileString",'pppplp','l')
  123.   FindWindow   = Win32API.new("user32", "FindWindow", 'pp', 'i')
  124.   CreateWindow = Win32API.new("NetGame","CreatWnd",'l','l')
  125.   SetHK        = Win32API.new("NetGame","SetHK",'v','v')
  126.   GetText      = Win32API.new("NetGame","GetWndText",'l','p')
  127.   SetFocus     = Win32API.new("user32","SetFocus",'l','l')
  128.   IfBack       = Win32API.new("NetGame","If_Back",'v','i')
  129.   StartType    = Win32API.new("NetGame","StartType",'v','v')
  130.   EndType      = Win32API.new("NetGame","EndType",'v','v')
  131.   GetKeyInfos  = Win32API.new("NetGame","GetKeyInfo",'v','i')
  132.   
  133.   
  134.   #--------------------------------------------------------------------------
  135.   # ● 模块函数
  136.   #--------------------------------------------------------------------------
  137.   module_function
  138.   
  139.   #--------------------------------------------------------------------------
  140.   # ● 获取参数
  141.   #--------------------------------------------------------------------------
  142.   def getParam
  143.     val = "\0" * 256
  144.     GPPS.call("Game","Title","",val,256,"./Game.ini")
  145.     val.delete!("\0")
  146.     return val
  147.   end
  148.   
  149.   #--------------------------------------------------------------------------
  150.   # ● 获取窗口
  151.   #--------------------------------------------------------------------------
  152.   def findWindow
  153.     return FindWindow.call("RGSS Player",self.getParam)
  154.   end
  155.   
  156.   #--------------------------------------------------------------------------
  157.   # ● 创建窗口
  158.   #--------------------------------------------------------------------------
  159.   def createWindow(hwnd)
  160.     return CreateWindow.call(hwnd)
  161.   end
  162.   
  163.   #--------------------------------------------------------------------------
  164.   # ● 设置HK
  165.   #--------------------------------------------------------------------------
  166.   def setHK
  167.     SetHK.call
  168.   end
  169.   
  170.   #--------------------------------------------------------------------------
  171.   # ● 获取文字
  172.   #--------------------------------------------------------------------------
  173.   def getText
  174.     return EasyConv.s2u(GetText.call(@subhwnd))
  175.   end
  176.   
  177.   #--------------------------------------------------------------------------
  178.   # ● 设置焦点
  179.   #--------------------------------------------------------------------------
  180.   def setFocus
  181.     SetFocus.call(@subhwnd)
  182.   end
  183.   
  184.   #--------------------------------------------------------------------------
  185.   # ● 转换焦点
  186.   #--------------------------------------------------------------------------
  187.   def lostFocus
  188.     SetFocus.call(@hwnd)
  189.   end
  190.   
  191.   #--------------------------------------------------------------------------
  192.   # ● 退格判定
  193.   #--------------------------------------------------------------------------
  194.   def ifBack
  195.     return IfBack.call
  196.   end
  197.   
  198.   #--------------------------------------------------------------------------
  199.   # ● 开始输入
  200.   #--------------------------------------------------------------------------
  201.   def startType
  202.     StartType.call
  203.   end
  204.   
  205.   #--------------------------------------------------------------------------
  206.   # ● 结束输入
  207.   #--------------------------------------------------------------------------
  208.   def endType
  209.     EndType.call
  210.   end
  211.   
  212.   #--------------------------------------------------------------------------
  213.   # ● 输入中特殊按键处理
  214.   #--------------------------------------------------------------------------
  215.   def getKeyInfos
  216.     return GetKeyInfos.call
  217.   end
  218.   
  219.   #--------------------------------------------------------------------------
  220.   # ● 获取句柄
  221.   #--------------------------------------------------------------------------
  222.   @hwnd    = self.findWindow
  223.   
  224.   @subhwnd = self.createWindow(@hwnd)

  225.   #--------------------------------------------------------------------------
  226.   # ● 设置HK应用
  227.   #--------------------------------------------------------------------------
  228.    self.setHK
  229. end

  230. #==============================================================================
  231. # ■ Type_Field
  232. #------------------------------------------------------------------------------
  233. #  处理输入域的类。
  234. #==============================================================================
  235. class Type_Field
  236.   
  237.   #--------------------------------------------------------------------------
  238.   # ● 定义实例变量
  239.   #--------------------------------------------------------------------------
  240.   attr(:active)
  241.   
  242.   #--------------------------------------------------------------------------
  243.   # ● 初始化
  244.   #--------------------------------------------------------------------------
  245.   def initialize(v,default_text = "",default_careth = nil,default_fonts = 16,\
  246.     default_fontc = Color.new(255,255,255),size = 8)
  247.     # active
  248.     @active = true
  249.     # 视口
  250.     rect = v.rect
  251.     @v = Viewport.new(rect.x,rect.y,rect.width,rect.height)
  252.     @v.z = 10000
  253.     @w = rect.width
  254.     @h = rect.height
  255.     # 属性
  256.     @caret_h = default_careth.nil? ? @h : [@h,default_careth].min
  257.     @caret_y = rect.y + (@h - @caret_h) / 2
  258.     @font_size = [default_fonts,@h].min
  259.     # 描绘contents
  260.     @cts = Sprite.new(@v)
  261.     @cts.bitmap = Bitmap.new(@w - 3,@h)
  262.     @cts.bitmap.font.size = @font_size
  263.     @cts.bitmap.font.color = default_fontc
  264.     # 辅助属性
  265.     @bk_count = 0
  266.     @text = default_text.scan(/./)
  267.     @max_size = size
  268.     @caret_pos = @text.size
  269.     @save_pos = @caret_pos
  270.     # 光标Caret
  271.     @v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
  272.     @v1.z = 99999
  273.     @caret_sp = Sprite.new(@v1)
  274.     @caret_bitmap = Bitmap.new(3,@caret_h)
  275.     @caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,255))
  276.     @caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
  277.     @caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
  278.     @caret_sp.bitmap = @caret_bitmap
  279.     @caret_sp.x = self.get_width(@text[0,@caret_pos].to_s) + 87
  280.     @caret_sp.y = 0
  281.     @caret_sp.visible = false
  282.     @caret_flash_count = 0
  283.     # 刷新
  284.     refresh
  285.     # 设置焦点
  286.     TypeAPI.setFocus
  287.     # 开始输入
  288.     TypeAPI.startType
  289.   end
  290.   
  291.   #--------------------------------------------------------------------------
  292.   # ● 设置活动标记
  293.   #--------------------------------------------------------------------------
  294.   def active=(value)
  295.     if value != true and value != false
  296.       return
  297.     end
  298.     @active = value
  299.     @caret_sp.visible = @active
  300.   end
  301.   
  302.   #--------------------------------------------------------------------------
  303.   # ● 释放
  304.   #--------------------------------------------------------------------------
  305.   def dispose
  306.     @caret_bitmap.dispose
  307.     @caret_sp.bitmap.dispose
  308.     @caret_sp.dispose
  309.     @cts.bitmap.dispose
  310.     @cts.dispose
  311.     @v.dispose
  312.     @v1.dispose
  313.   end

  314.   #--------------------------------------------------------------------------
  315.   # ● 刷新
  316.   #--------------------------------------------------------------------------
  317.   def refresh
  318.     @cts.bitmap.clear
  319.     @cts.bitmap.draw_text(85,0,@w,@h,@text.to_s)
  320.   end

  321.   #--------------------------------------------------------------------------
  322.   # ● 获取文字
  323.   #--------------------------------------------------------------------------
  324.   def get_text
  325.     return @text.to_s
  326.   end

  327.   #--------------------------------------------------------------------------
  328.   # ● 取得字符宽度
  329.   #--------------------------------------------------------------------------
  330.   def get_width(str)
  331.     return @cts.bitmap.text_size(str).width
  332.   end
  333.   
  334.   #--------------------------------------------------------------------------
  335.   # ● 更新
  336.   #--------------------------------------------------------------------------
  337.   def update
  338.     @caret_sp.visible = @active
  339.     # 非激活状态则返回
  340.     unless @active
  341.       return
  342.     end
  343.     # 获取按键信息
  344.     key_info = TypeAPI.getKeyInfos
  345.     case key_info
  346.     when 0x09 # Tab
  347.       # 按下 Tab 键的情况自己定义怎么处理
  348.       return
  349.     #when 0x0d # Enter
  350.       # 按下 Enter 键的情况自己定义怎么处理
  351.     #  return
  352.     when 0x1B # Esc
  353.       # 按下 Esc 键的情况自己定义怎么处理
  354.       return
  355.     end
  356.     self.update_text
  357.     self.update_lrb
  358.     self.update_back
  359.     self.update_caret
  360.   end

  361.   #--------------------------------------------------------------------------
  362.   # ● 更新文字
  363.   #--------------------------------------------------------------------------
  364.   def update_text
  365.     # 文字刷新
  366.     TypeAPI.setFocus
  367.     text = TypeAPI.getText
  368.     if text != ""
  369.       for char in text.scan(/./)
  370.         if self.get_text.size <= @max_size
  371.           @text[@caret_pos,0] = char
  372.           @caret_pos += 1
  373.         else
  374.           break
  375.         end
  376.       end
  377.       refresh
  378.     end
  379.   end
  380.   
  381.   #--------------------------------------------------------------------------
  382.   # ● 更新左右按键
  383.   #--------------------------------------------------------------------------
  384.   def update_lrb
  385.     if RInput.trigger?(RInput::LEFT) and @caret_pos > 0
  386.       @caret_pos -= 1
  387.       return
  388.     end
  389.     if RInput.trigger?(RInput::RIGHT) and @caret_pos < @text.size
  390.       @caret_pos += 1
  391.       return
  392.     end
  393.   end
  394.   
  395.   #--------------------------------------------------------------------------
  396.   # ● 更新退格
  397.   #--------------------------------------------------------------------------
  398.   def update_back
  399.     # 前退格处理
  400.     @bk_count += TypeAPI.ifBack
  401.     if @bk_count > 0
  402.       @bk_count -= 1
  403.       if @caret_pos > 0
  404.         @text.delete_at(@caret_pos - 1);@caret_pos -= 1;refresh
  405.       end
  406.     end
  407.   end
  408.   
  409.   #--------------------------------------------------------------------------
  410.   # ● 更新光标闪烁
  411.   #--------------------------------------------------------------------------
  412.   def update_caret
  413.     # 闪烁计时
  414.     @caret_flash_count += 1
  415.     if @caret_flash_count == 20
  416.       @caret_sp.visible = !@caret_sp.visible
  417.       @caret_flash_count = 0
  418.     end
  419.     # Caret位置刷新
  420.     if @save_pos != @caret_pos
  421.       @save_pos = @caret_pos
  422.       @caret_sp.x = self.get_width(@text[0,@save_pos].to_s) + 87
  423.     end
  424.   end
  425. end
复制代码
两个脚本都插上就可以了
第一个脚本我自己写的,可能提示语太多有点烦= =
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
38 小时
注册时间
2011-8-19
帖子
30
5
 楼主| 发表于 2011-11-19 17:15:51 | 只看该作者
本帖最后由 哀、浪者 于 2011-11-19 17:21 编辑
帕克 发表于 2011-11-19 14:52
两个脚本都插上就可以了
第一个脚本我自己写的,可能提示语太多有点烦= = ...


出现错误了- -    89行那边0 0

点评

把89行的$scene = Scene_Gender.new 改成 $scene = Scene_Map.new  发表于 2011-11-19 18:50
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
38 小时
注册时间
2011-8-19
帖子
30
6
 楼主| 发表于 2011-11-23 14:06:46 | 只看该作者
帕克 发表于 2011-11-19 14:52
两个脚本都插上就可以了
第一个脚本我自己写的,可能提示语太多有点烦= = ...

我想设置成按回车就能确定的,不要按:“Pageup”键切换输入/确定"
那要怎么弄?
回复

使用道具 举报

Lv1.梦旅人

井蓝

梦石
0
星屑
58
在线时间
351 小时
注册时间
2011-1-14
帖子
277
7
发表于 2011-11-23 19:56:15 | 只看该作者
哀、浪者 发表于 2011-11-23 14:06
我想设置成按回车就能确定的,不要按:“Pageup”键切换输入/确定"
那要怎么弄? ...

我的那个脚本就是用按回车确定改过来的- -不过原脚本我还要再想想……
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-7-21 04:30

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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