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

Project1

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

[已经过期] 关于API,让一个输入条支持中文

 关闭 [复制链接]

Lv1.梦旅人

路人党员

梦石
0
星屑
51
在线时间
2276 小时
注册时间
2010-12-30
帖子
3225
跳转到指定楼层
1
发表于 2011-6-8 22:18:34 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
1星屑
本帖最后由 英顺的马甲 于 2011-6-8 22:23 编辑

怎么说呢,输入中文是没问题,
但是输出的时候就是一堆乱码,
这是脚本:
  1. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::​
  2. # Run-Time Script Caller
  3. # Author: ForeverZer0
  4. # Version: 1.0
  5. # Date: 11.27.2010
  6. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::​
  7. #
  8. # Introduction:
  9. #
  10. #  This script will allow you to open a small box while the game is running and
  11. #  type script calls into, which will execute when the Enter button is pressed.
  12. #
  13. # Feature:
  14. #
  15. #  - Simple to use.
  16. #  - Built in rescue to keep game from crashing if the script call is written
  17. #    wrong, etc. Instead it shows the error and continues on.
  18. #  - Did I mention you can make up script calls and change things at run-time.
  19. #
  20. # Instructions:
  21. #
  22. #  - Place script anywhere.
  23. #  - Configure call button below (F7 by default)
  24. #
  25. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::​

  26. #===============================================================================​
  27. # ** ScriptEditor
  28. #===============================================================================​

  29. class ScriptEditor
  30.   
  31.   CALL_BUTTON = Input::F7
  32.   # Set the button to call the script box.
  33.   
  34.   def initialize
  35.     # Get game window title from Game.ini
  36.     ini = Win32API.new('kernel32', 'GetPrivateProfileString','PPPPLP', 'L')
  37.     @title = "\0" * 256
  38.     ini.call('Game', 'Title', '', @title, 256, '.\\Game.ini')
  39.     @title.delete!("\0")
  40.     # Set game window to an instance variable, using the title we found.
  41.     @main = Win32API.new('user32', 'FindWindowA', 'PP', 'L').call('RGSS Player', @title)
  42.     # Set variables to call for creating showing, and destroying the window.
  43.     @create_window = Win32API.new('user32','CreateWindowEx','lpplllllllll','l')
  44.     @show_window = Win32API.new('user32','ShowWindow',%w(l l),'l')
  45.     @destroy_window = Win32API.new('user32','DestroyWindow','p','l')
  46.     # Set variables to get the window size, position, text, etc, etc.
  47.     @window_text = Win32API.new('user32','GetWindowText',%w(n p n ),'l')
  48.     @metrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
  49.     @set_window_pos = Win32API.new('user32', 'SetWindowPos', 'LLIIIII', 'I')
  50.     @window_rect = Win32API.new('user32','GetWindowRect',%w(l p),'i')
  51.     # Define the coordinates to display the window.
  52.     @x = (@metrics.call(0) - 576) / 2
  53.     @y = (@metrics.call(1) - 22) / 2
  54.     # Updates the client area of the window.
  55.     @update_window = Win32API.new('user32','UpdateWindow','p','i')
  56.     # Set a button that will register when button is pressed.
  57.     @input = Win32API.new('user32','GetAsyncKeyState','i','i')
  58.   end  
  59.   
  60.   def destroy_window
  61.     # Disposes the created box for typing text, and sets variable to nil.
  62.     @destroy_window.call(@script_window)
  63.     @script_window = nil
  64.   end
  65.    
  66.   def show_window
  67.     # End method now if window is already there.
  68.     if @script_window != nil
  69.       return
  70.     end
  71.     # Create text box for adding text into, using window dimensions.
  72.     @script_window = @create_window.call(768, 'Edit', '', 0x86000000, @x, @y, 576, 22, @main, 0, 0, 0)
  73.     # Set the 'visibility' of the window.
  74.     @show_window.call(@script_window, 1)
  75.     # Begin the loop for the text box.
  76.     start_script_update
  77.   end  
  78.   
  79.   def start_script_update
  80.     # Enter update loop.
  81.     loop {
  82.       # Update the Graphics, and the window. Breaks when Enter button is pressed.
  83.       Graphics.update
  84.       @update_window.call(@script_window)
  85.       break if @input.call(0x0D) & 0x01 == 1
  86.     }
  87.     # Get the text from the window.
  88.     text = "\0" * 256
  89.     @window_text.call(@script_window, text, 0x3E80)
  90.     text.delete!("\0")
  91.     # Evaluate the text, simply displaying a message if it throws an error.
  92.     begin
  93.       eval(text)
  94.     rescue#'start_script_update'
  95.       # Simply write the type of the error.
  96.       message = $!.message.gsub("(eval):1:in `start_script_update'") { '' }
  97.       message = message.gsub("(eval):1:in"){''}
  98.       print("执行脚本时发生了 #{$!.class}\r\n\r\n#{message}")
  99.     end
  100.     destroy_window
  101.   end
  102. end

  103. if $DEBUG
  104.   
  105.   $editor = ScriptEditor.new
  106.   # Create in instance of the class so it is ready to call.
  107.   
  108.   module Input
  109.    
  110.     class << self
  111.       alias zer0_script_editor_upd update
  112.     end
  113.    
  114.     def self.update
  115.       # Alias the Input.update method to check if call button is pressed.
  116.       $editor.show_window if self.trigger?(ScriptEditor::CALL_BUTTON)
  117.       zer0_script_editor_upd
  118.     end
  119.   end
  120. end
复制代码
此脚本的原网站:http://www.rpgmakers.net/showthread.php?tid=99
已尝试过紫苏的 to_unicode 和 to_UTF8
本人擅长XP,如果有脚本或者Ruby方面的问题欢迎发电邮到[email protected]咨询,本人很少检查电邮所以不一定会及时回复,本人不会直接出手解决问题只会提供一个方向,所以谢绝伸手党
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-5-16 02:49

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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