赞 | 3 |
VIP | 21 |
好人卡 | 10 |
积分 | 2 |
经验 | 32573 |
最后登录 | 2024-6-13 |
在线时间 | 332 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 155
- 在线时间
- 332 小时
- 注册时间
- 2013-7-6
- 帖子
- 356
|
本帖最后由 wolves 于 2014-7-14 09:41 编辑
我有一个输入脚本比较不错,看看这个脚本:
(总共有四段,显示的位置在最下面)
第一个:获取窗口句柄- #==============================================================================
- # ■ Kernel
- #------------------------------------------------------------------------------
- # 该模块中定义了可供所有类使用的方法。Object 类中包含了该模块。
- #==============================================================================
- module Kernel
- #--------------------------------------------------------------------------
- # ● 需要的 Windows API 函数
- #--------------------------------------------------------------------------
- GetWindowThreadProcessId = Win32API.new("user32", "GetWindowThreadProcessId", "LP", "L")
- GetWindow = Win32API.new("user32", "GetWindow", "LL", "L")
- GetClassName = Win32API.new("user32", "GetClassName", "LPL", "L")
- GetCurrentThreadId = Win32API.new("kernel32", "GetCurrentThreadId", "V", "L")
- GetForegroundWindow = Win32API.new("user32", "GetForegroundWindow", "V", "L")
- #--------------------------------------------------------------------------
- # ● 获取窗口句柄
- #--------------------------------------------------------------------------
- def get_hWnd
- # 获取调用线程(RM 的主线程)的进程标识
- threadID = GetCurrentThreadId.call
- # 获取 Z 次序中最靠前的窗口
- hWnd = GetWindow.call(GetForegroundWindow.call, 0)
- # 枚举所有窗口
- while hWnd != 0
- # 如果创建该窗口的线程标识匹配本线程标识
- if threadID == GetWindowThreadProcessId.call(hWnd, 0)
- # 分配一个 11 个字节的缓冲区
- className = " " * 11
- # 获取该窗口的类名
- GetClassName.call(hWnd, className, 12)
- # 如果匹配 RGSS Player 则跳出循环
- break if className == "RGSS Player"
- end
- # 获取下一个窗口
- hWnd = GetWindow.call(hWnd, 2)
- end
- return hWnd
- end
- end
复制代码 第二个:TextBox- #==============================================================================
- # ■ TextBox by EngShun
- #------------------------------------------------------------------------------
- # 输入框的类。
- #==============================================================================
- class TextBox
- #--------------------------------------------------------------------------
- # ● 设置API
- #--------------------------------------------------------------------------
- CreateWindow = Win32API.new('user32','CreateWindowEx','lpplllllllll','l')
- ShowWindow = Win32API.new('user32','ShowWindow','ll','l')
- DestroyWindow = Win32API.new('user32','DestroyWindow','l','l')
- GetWindowText = Win32API.new('user32','GetWindowText','lpl','l')
- SetWindowText = Win32API.new("user32", "SetWindowText", "lp", "l")
- GetWindowTextLength = Win32API.new('user32','GetWindowTextLength','l','l')
- UpdateWindow = Win32API.new('user32','UpdateWindow','l','i')
- SetFocus = Win32API.new('user32','SetFocus','l','l')
- SendMessage = Win32API.new('user32','SendMessage','llll','l')
- MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- GetKeyState = Win32API.new("user32","GetAsyncKeyState",'I','I')
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_accessor :focus
- #--------------------------------------------------------------------------
- # ● 初始化
- #--------------------------------------------------------------------------
- def initialize(text = "",limit = 8,number=false)
- c = 0x40011000
- c = (c|0x00001000) if number
- [url=home.php?mod=space&uid=37298]@Window[/url] = CreateWindow.call(0, 'EDIT', u2s(text), c, 0, 480-22, 640, 22, get_hWnd, 0, 0, 0)
- SendMessage.call(@window,0xC5,limit,0)
- @focus = true
- @disposed = false
- end
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- @disposed = true
- DestroyWindow.call(@window)
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def update
- return if !@focus or @disposed
- UpdateWindow.call(@window)
- SetFocus.call(@window)
- end
- #--------------------------------------------------------------------------
- # ● 获取内容
- #--------------------------------------------------------------------------
- def text
- return if @disposed
- l = GetWindowTextLength.call(@window)
- str = "\0" * (l + 1)
- GetWindowText.call(@window, str, l+1)
- return s2u(str.delete("\0"))
- end
- #--------------------------------------------------------------------------
- # ● 更改内容
- #--------------------------------------------------------------------------
- def text=(str)
- SetWindowText.call(@window, u2s(str))
- return if @disposed
- end
- #--------------------------------------------------------------------------
- # ● 获取光标位置
- #--------------------------------------------------------------------------
- def sel_pos
- return if @disposed
- return (SendMessage.call(@window,0xB0,0,0) % 65535) / 2
- end
- #--------------------------------------------------------------------------
- # ● 设置光标位置
- #--------------------------------------------------------------------------
- def sel_pos=(i)
- return if @disposed
- SendMessage.call(@window,0xB1,i,i)
- end
- #--------------------------------------------------------------------------
- # ● 获取光标位置
- #--------------------------------------------------------------------------
- def limit
- return if @disposed
- return SendMessage.call(@window,0xD5,0,0)
- end
- #--------------------------------------------------------------------------
- # ● 设置光标位置
- #--------------------------------------------------------------------------
- def limit=(i)
- return if @disposed
- SendMessage.call(@window,0xC5,i,0)
- end
- #--------------------------------------------------------------------------
- # ● 是否按下回车键
- #--------------------------------------------------------------------------
- def press_enter?
- return if @disposed
- return (@focus and (GetKeyState.call(13) != 0))
- end
- #--------------------------------------------------------------------------
- # ● 转码:系统转UTF-8
- #--------------------------------------------------------------------------
- def s2u(text)
- len = MultiByteToWideChar.call(0, 0, text, -1, nil, 0);
- buf = "\0" * (len*2)
- MultiByteToWideChar.call(0, 0, text, -1, buf, buf.size/2);
- len = WideCharToMultiByte.call(65001, 0, buf, -1, nil, 0, nil, nil);
- ret = "\0" * len
- WideCharToMultiByte.call(65001, 0, buf, -1, ret, ret.size, nil, nil);
- return ret.delete("\000")
- end
- #--------------------------------------------------------------------------
- # ● 转码:UTF-8转系统
- #--------------------------------------------------------------------------
- def u2s(text)
- len = MultiByteToWideChar.call(65001, 0, text, -1, nil, 0);
- buf = "\0" * (len*2)
- MultiByteToWideChar.call(65001, 0, text, -1, buf, buf.size/2);
- len = WideCharToMultiByte.call(0, 0, buf, -1, nil, 0, nil, nil);
- ret = "\0" * len
- WideCharToMultiByte.call(0, 0, buf, -1, ret, ret.size, nil, nil);
- return ret.delete("\000")
- end
- private :u2s ,:s2u # 定义私有功能
- end
复制代码 第三个:Sprite_TextBox- #==============================================================================
- # ■ Sprite_TextBox by EngShun
- #------------------------------------------------------------------------------
- # 显示输入框用的活动块。
- #==============================================================================
- class Sprite_TextBox < Sprite
- #--------------------------------------------------------------------------
- # ● 设置缓存的类
- #--------------------------------------------------------------------------
- Cache = Struct.new(:bc ,:fc ,:fs ,:text ,:sel_pos)
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_accessor :textbox
- attr_accessor :back_color
- #--------------------------------------------------------------------------
- # ● 初始化
- #--------------------------------------------------------------------------
- def initialize(x = 0,y = 0,w = 128,h = 32,bc = Color.new(255,255,255),fc = Color.new(0,0,0),tb = TextBox.new)
- super(nil)
- self.x = x
- self.y = y
- self.bitmap = Bitmap.new(w,h)
- self.bitmap.font.color = fc
- @back_color = bc
- @textbox = tb
- [url=home.php?mod=space&uid=341345]@Cache[/url] = Cache.new
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def update
- super
- return unless @textbox.focus
- @textbox.update
- if (self.bitmap.font.color != @cache.fc) or
- (self.bitmap.font.size != @cache.fs) or
- (@textbox.sel_pos != @cache.sel_pos) or
- (@textbox.text != @cache.text) or
- (@back_color != @cache.bc)
- refresh
- end
- end
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- self.bitmap.dispose
- @textbox.dispose
- super
- end
- #--------------------------------------------------------------------------
- # ● 内容刷新
- #--------------------------------------------------------------------------
- def refresh
- @cache.fc = self.bitmap.font.color
- @cache.fs = self.bitmap.font.size
- @cache.sel_pos = @textbox.sel_pos
- @cache.text = @textbox.text
- @cache.bc = @back_color
- w = self.bitmap.width
- h = self.bitmap.height
- self.bitmap.fill_rect(0,0,w,h,@back_color)
- self.bitmap.draw_text(4,0,w-4,h,@textbox.text)
- t = @textbox.text.scan(/./)[0,@textbox.sel_pos].join("")
- s = self.bitmap.text_size(t).width
- self.bitmap.draw_text((4 + s)-16,0,32,h,"|",1)
- end
- private :refresh # 设置私有功能
- end
复制代码 第四个:Scene_Name- #==============================================================================
- # ■ Scene_Name
- #------------------------------------------------------------------------------
- # 处理名称输入画面的类。
- #==============================================================================
- class Scene_Name
- #--------------------------------------------------------------------------
- # ● 主处理
- #--------------------------------------------------------------------------
- def main
- @spriteset = Spriteset_Map.new
- @actor = $game_actors[$game_temp.name_actor_id]
- [url=home.php?mod=space&uid=37298]@Window[/url] = Window_Base.new(0,480-128,640,128)
- @window.contents = Bitmap.new(576,96)
- @window.draw_actor_graphic(@actor, 60, 70)
- @window.contents.draw_text(128,0,480,32,$input)
- @window.opacity = 180
- @sprite_tb = Sprite_TextBox.new(144,410,464)
- @sprite_tb.z = 500
- @sprite_tb.textbox.limit = $game_temp.name_max_char
- @sprite_tb.textbox.text = @actor.name
- @sprite_tb.textbox.sel_pos = @actor.name.length
- @sprite_tb.opacity = 180
- Graphics.transition
- loop do
- Graphics.update
- Input.update
- update
- break if $scene != self
- end
- Graphics.freeze
- @sprite_tb.dispose
- @window.dispose
- @spriteset.dispose
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- @sprite_tb.update
- if @sprite_tb.textbox.press_enter?
- if @sprite_tb.textbox.text == ""
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- @actor.name = @sprite_tb.textbox.text
- $scene = Scene_Map.new
- end
- end
- end
复制代码 调用方法: 修改某个角色的姓名,这个角色最好不用,因为他的名字就是你要输入的东西,角色姓名的调用方法自己百度吧,是个字符串,把这个字符串代入你要的变量,一切都ok了。 |
|