Project1
标题:
关于API,让一个输入条支持中文
[打印本页]
作者:
英顺的马甲
时间:
2011-6-8 22:18
标题:
关于API,让一个输入条支持中文
本帖最后由 英顺的马甲 于 2011-6-8 22:23 编辑
怎么说呢,输入中文是没问题,
但是输出的时候就是一堆乱码,
这是脚本:
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Run-Time Script Caller
# Author: ForeverZer0
# Version: 1.0
# Date: 11.27.2010
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# Introduction:
#
# This script will allow you to open a small box while the game is running and
# type script calls into, which will execute when the Enter button is pressed.
#
# Feature:
#
# - Simple to use.
# - Built in rescue to keep game from crashing if the script call is written
# wrong, etc. Instead it shows the error and continues on.
# - Did I mention you can make up script calls and change things at run-time.
#
# Instructions:
#
# - Place script anywhere.
# - Configure call button below (F7 by default)
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#===============================================================================
# ** ScriptEditor
#===============================================================================
class ScriptEditor
CALL_BUTTON = Input::F7
# Set the button to call the script box.
def initialize
# Get game window title from Game.ini
ini = Win32API.new('kernel32', 'GetPrivateProfileString','PPPPLP', 'L')
@title = "\0" * 256
ini.call('Game', 'Title', '', @title, 256, '.\\Game.ini')
@title.delete!("\0")
# Set game window to an instance variable, using the title we found.
@main = Win32API.new('user32', 'FindWindowA', 'PP', 'L').call('RGSS Player', @title)
# Set variables to call for creating showing, and destroying the window.
@create_window = Win32API.new('user32','CreateWindowEx','lpplllllllll','l')
@show_window = Win32API.new('user32','ShowWindow',%w(l l),'l')
@destroy_window = Win32API.new('user32','DestroyWindow','p','l')
# Set variables to get the window size, position, text, etc, etc.
@window_text = Win32API.new('user32','GetWindowText',%w(n p n ),'l')
@metrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
@set_window_pos = Win32API.new('user32', 'SetWindowPos', 'LLIIIII', 'I')
@window_rect = Win32API.new('user32','GetWindowRect',%w(l p),'i')
# Define the coordinates to display the window.
@x = (@metrics.call(0) - 576) / 2
@y = (@metrics.call(1) - 22) / 2
# Updates the client area of the window.
@update_window = Win32API.new('user32','UpdateWindow','p','i')
# Set a button that will register when button is pressed.
@input = Win32API.new('user32','GetAsyncKeyState','i','i')
end
def destroy_window
# Disposes the created box for typing text, and sets variable to nil.
@destroy_window.call(@script_window)
@script_window = nil
end
def show_window
# End method now if window is already there.
if @script_window != nil
return
end
# Create text box for adding text into, using window dimensions.
@script_window = @create_window.call(768, 'Edit', '', 0x86000000, @x, @y, 576, 22, @main, 0, 0, 0)
# Set the 'visibility' of the window.
@show_window.call(@script_window, 1)
# Begin the loop for the text box.
start_script_update
end
def start_script_update
# Enter update loop.
loop {
# Update the Graphics, and the window. Breaks when Enter button is pressed.
Graphics.update
@update_window.call(@script_window)
break if @input.call(0x0D) & 0x01 == 1
}
# Get the text from the window.
text = "\0" * 256
@window_text.call(@script_window, text, 0x3E80)
text.delete!("\0")
# Evaluate the text, simply displaying a message if it throws an error.
begin
eval(text)
rescue#'start_script_update'
# Simply write the type of the error.
message = $!.message.gsub("(eval):1:in `start_script_update'") { '' }
message = message.gsub("(eval):1:in"){''}
print("执行脚本时发生了 #{$!.class}\r\n\r\n#{message}")
end
destroy_window
end
end
if $DEBUG
$editor = ScriptEditor.new
# Create in instance of the class so it is ready to call.
module Input
class << self
alias zer0_script_editor_upd update
end
def self.update
# Alias the Input.update method to check if call button is pressed.
$editor.show_window if self.trigger?(ScriptEditor::CALL_BUTTON)
zer0_script_editor_upd
end
end
end
复制代码
此脚本的原网站:
http://www.rpgmakers.net/showthread.php?tid=99
已尝试过紫苏的 to_unicode 和 to_UTF8
作者:
后知后觉
时间:
2011-6-8 22:18
在第 95 行前面插入如下 2 行:
text = EasyConv.s2u(text)
text.delete!("\000")
复制代码
然后再加上这个脚本:
#------------------------------------------------------------------------------
# Moonlight INN
# http://cgi.members.interq.or.jp/aquarius/rasetsu/
# RaTTiE
#
[email protected]
#------------------------------------------------------------
# EasyConv::s2u(text) : S-JIS -> UTF-8
# EasyConv::u2s(text) : UTF-8 -> S-JIS
#==============================================
module EasyConv
CP_ACP = 0
CP_UTF8 = 65001
#--------------------------------------------------------------------------
# 仠 S-JIS -> UTF-8
#--------------------------------------------------------------------------
def s2u(text)
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
# S-JIS -> Unicode
len = m2w.call(CP_ACP, 0, text, -1, nil, 0);
buf = "\0" * (len*2)
m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2);
# Unicode -> UTF-8
len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);
ret = "\0" * len
w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);
return ret
end
module_function :s2u
#--------------------------------------------------------------------------
# 仠 UTF-8 -> S-JIS
#--------------------------------------------------------------------------
def u2s(text)
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
# UTF-8 -> Unicode
len = m2w.call(CP_UTF8, 0, text, -1, nil, 0);
buf = "\0" * (len*2)
m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2);
# Unicode -> S-JIS
len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil);
ret = "\0" * len
w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil);
return ret
end
module_function :u2s
end
#========================================
# 本脚本来自www.66rpg.com
#========================================
复制代码
作者:
tamashii
时间:
2011-6-8 22:19
请参考RMXP中文输入法
作者:
h907308901
时间:
2011-6-9 08:53
RGSS默认使用UNICODE(具体我也不知道,反正是UNICODE的一种),WIN32API不支持这种编码,只有A(ANSI)和W(好像是WideChar)两种形式,所以必须转码后使用
我对字符串编码不熟悉,所以可能有说错的地方
作者:
END66RPG
时间:
2011-6-9 12:56
转来转去最终还不是要转换回来。。
不如不转
作者:
END66RPG
时间:
2011-6-9 13:10
END66RPG 发表于 2011-6-9 12:56
转来转去最终还不是要转换回来。。
不如不转
谔谔。。我起先用了转码,不过发现最后还XXX
最后不转了。。哇哈哈
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1