赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 95 |
最后登录 | 2012-7-23 |
在线时间 | 19 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 19 小时
- 注册时间
- 2011-7-9
- 帖子
- 14
|
- #==============================================================================
- # 全新打造系统(脚本版)
- # by EngShun
- #==============================================================================
- # 这个原本是enghao_lim的第一个作品,
- # 但我闲来无聊没事做擅自出了一个脚本版,
- # 由于本人有点白痴,所以做出来效果很差,
- # 将就点吧(厉害的人根本不需要将就,要改就改),
- # 不过我相信原作者绝对能写出比这个好上百倍的脚本
- # 调用方法:[b]$scene = Scene_MakeWeapon.new[/b]
- #
- # 更新日志
- #
- # 【脚本版0.3】
- # 1.武器的属性可自己附加
- # 2.发现了一个0.3的BUG,就是还没确认是否打造它就
- # 已经打造好了,你也同时的付了钱与得到该武器。
- # 3.注释(2)的BUG已解决,不过可能造成不便,就是
- # 确认是否打造时,必须使用回车键。(因为造成BUG
- # 的原因是自动帮你按了空格键)
- # 4.将脚本前的注释美化。
- #
- # 【脚本版0.2】
- # 1.解决不切实际的名称问题
- # 2.解决不切实际的说明问题
- # 3.修正数值输入框窗口遮盖提问是否打造窗口的问题
- # 4.修正打造武器后反而加钱的BUG
- #
- # 【脚本版0.1】
- # 1.将此系统改为脚本版
- # 2.附加属性改为随机两个
- # 3.减去的状态设为战斗不能以外,随机一个
- #------------------------------------------------------------------------------
- # ↓ 资料设定 ↓
- # 价钱设定
- $price_element = 10 # 附加属性的价钱
- $price_atk = 10 # 攻击力的价钱
- $price_pdef = 10 # 物理防御的价钱
- $price_mdef = 10 # 魔法防御的价钱
- $price_str = 10 # 力量的价钱
- $price_dex = 10 # 灵巧的价钱
- $price_agi = 10 # 速度的价钱
- $price_int = 10 # 魔力的价钱
- $最普通的剑编号 = 1
- $最普通的枪(矛)编号 = 2
- $最普通的斧头编号 = 3
- $最普通的匕首编号 = 4
- $最普通的弓编号 = 5
- $最普通的手枪编号 = 6
- $最普通的槌编号 = 7
- $最普通的杖编号 = 8
- #------------------------------------------------------------------------------
- #==============================================================================
- # ■ Window_InputNumber
- #------------------------------------------------------------------------------
- # 信息窗口内部使用、输入数值的窗口。
- #==============================================================================
- class Window_InputNumber < Window_Base
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # digits_max : 位数
- #--------------------------------------------------------------------------
- def initialize(digits_max,opacity=0)
- @digits_max = digits_max
- @number = 0
- # 从数字的幅度计算(假定与 0~9 等幅)光标的幅度
- dummy_bitmap = Bitmap.new(32, 32)
- @cursor_width = dummy_bitmap.text_size("0").width + 8
- dummy_bitmap.dispose
- super(0, 0, @cursor_width * @digits_max + 32, 64)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.z += 9999
- self.opacity = opacity
- @index = 0
- refresh
- update_cursor_rect
- end
- end
- #==============================================================================
- class Window_Edit < Window_Selectable
- def initialize
- super(120, 0, 160, 352)
- @item_max = 10
- @commands = ["攻击","防御","法技防御","力量+","灵巧+","速度+","魔力+","取名","说明","打造"]
- self.contents = Bitmap.new(width - 32, 320)
- refresh
- self.index = 0
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- for i in 0...@item_max
- draw_item(i, normal_color)
- end
- end
- #--------------------------------------------------------------------------
- # ● 描绘项目
- # index : 项目编号
- # color : 文字色
- #--------------------------------------------------------------------------
- def draw_item(index, color)
- self.contents.font.color = color
- rect = Rect.new(4, 32 * index, 160, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- self.contents.draw_text(rect, @commands[index])
- end
- end
- #==============================================================================
- class Window_Element < Window_Selectable
- def initialize
- super(120, 0, 232, 352)
- @item_max = 3
- @column_max = 2
- @commands = ["火系","电系","冰系"]
- self.contents = Bitmap.new(width - 32, 320)
- refresh
- self.index = 0
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- for i in 0...@item_max
- draw_item(i, normal_color)
- end
- end
- #--------------------------------------------------------------------------
- # ● 描绘项目
- # index : 项目编号
- # color : 文字色
- #--------------------------------------------------------------------------
- def draw_item(index, color)
- x = 4 + index % 2 * (82 + 32)
- y = index / 2 * 32
- self.contents.font.color = color
- rect = Rect.new(4, 32 * index, 232, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- self.contents.draw_text(x , y, 212, 32,@commands[index] , 0)
- end
- end
- class Scene_MakeWeapon
- #-----------------------------------------------------------------------------
- # ● 初始化
- #-----------------------------------------------------------------------------
- def initialize
- @new_weapon = $data_weapons[1].clone
- @new_weapon.id = $data_weapons.size
- @new_weapon.name = "新武器"
- @new_weapon.icon_name = ""
- @new_weapon.description = "新打造的武器。"
- @new_weapon.animation1_id = 0
- @new_weapon.animation2_id = 0
- @new_weapon.price = 0
- @new_weapon.atk = 10
- @new_weapon.pdef = 0
- @new_weapon.mdef = 0
- @new_weapon.str_plus = 0
- @new_weapon.dex_plus = 0
- @new_weapon.agi_plus = 0
- @new_weapon.int_plus = 0
- @new_weapon.element_set = []
- @new_weapon.plus_state_set = []
- @new_weapon.minus_state_set = []
- end
- #-----------------------------------------------------------------------------
- # ● 主处理
- #-----------------------------------------------------------------------------
- def main
- @background = Spriteset_Map.new
- # 生成命令窗口
- s1 = "剑"
- s2 = "枪"
- s3 = "斧头"
- s4 = "匕首"
- s5 = "弓"
- s6 = "铳"
- s7 = "槌"
- s8 = "杖"
- @type_window = Window_Command.new(88, [s1, s2, s3, s4, s5, s6, s7 ,s8])
- @type_window.active = true
- @input_number_window = Window_InputNumber.new(3,255)
- @input_number_window.x = 248
- @input_number_window.y = 160
- @input_number_window.z = 1000
- @input_number_window.active = false
- @window_element = Window_Element.new
- @window_element.x = 408
- @window_element.active = false
- @window_status = Window_Edit.new
- @window_status.x = 88
- @window_status.active = false
- @window_auto = Window_Command.new(160,["手动","自动"])
- @window_auto.x = 248
- @window_auto.active = false
- @window_text = Window_Base.new(0,352,640,129)
- @window_text.contents = Bitmap.new(400,160)
- @window_text.contents.font.size = 22
- @window_text.contents.draw_text(10, 10, 160, 32, "输入结束请按回车")
- @window_text.cursor_rect.set(50, 50, 532, 30)
- @window_text.active = false
- @gold_window = Window_Gold.new
- @gold_window.x = 248
- @gold_window.y = 96
- @confirm_window = Window_Base.new(140, 188, 400, 64)
- @confirm_window.contents = Bitmap.new(368, 32)
- string = "打造费是#{@new_weapon.price} 金币,是否打造?"
- @confirm_window.contents.font.name = "微软雅黑"
- @confirm_window.contents.font.size = 24
- @confirm_window.contents.draw_text(204, 0, 368, 32, string)
- @yes_no_window = Window_Command.new(100, ["打造", "算了"])
- @confirm_window.visible = false
- @confirm_window.z = 1500
- @yes_no_window.visible = false
- @yes_no_window.active = false
- @yes_no_window.x = 290
- @yes_no_window.y = 252
- @yes_no_window.z = 1500
- @v = Viewport.new(0,422,590,20)
- @v.color.set(0,0,0,0)
- @tf = Type_Field.new(@v,"",nil,20,Color.new(255,255,255),25*3-2)
- @tf.active = false
- # 执行过渡
- Graphics.transition
- # 主循环
- loop do
- # 刷新游戏画面
- Graphics.update
- # 刷新输入信息
- Input.update
- # 刷新画面
- update
- # 如果切换画面就中断循环
- if $scene != self
- break
- end
- end
- # 准备过渡
- Graphics.freeze
- # 释放窗口
- @window_element.dispose
- @confirm_window.dispose
- @yes_no_window.dispose
- @gold_window.dispose
- @tf.dispose
- @window_text.dispose
- @window_auto.dispose
- @window_status.dispose
- @input_number_window.dispose
- @background.dispose
- @type_window.dispose
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面 (命令窗口被激活的情况下)
- #--------------------------------------------------------------------------
- def update_command
- # 按下 B 键的情况下
- if Input.trigger?(Input::B)
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- # 切换的地图画面
- $scene = Scene_Map.new
- return
- end
- # 按下 C 键的情况下
- if Input.trigger?(Input::C)
- # 命令窗口的光标位置分支
- case @type_window.index
- when 0
- $game_system.se_play($data_system.decision_se)
- @type_weapon = 1
- @new_weapon.icon_name = "001-Weapon01"
- @new_weapon.animation2_id = 7
- $last_name = "剑"
- $last_des = "的剑"
- @window_element.active = false
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- when 1
- $game_system.se_play($data_system.decision_se)
- @type_weapon = 2
- @new_weapon.icon_name = "002-Weapon02"
- @new_weapon.animation2_id = 8
- $last_name = "枪"
- $last_des = "的枪"
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- when 2
- $game_system.se_play($data_system.decision_se)
- @type_weapon = 3
- @new_weapon.icon_name = "003-Weapon03"
- @new_weapon.animation2_id = 9
- $last_name = "斧头"
- $last_des = "的斧头"
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- when 3
- $game_system.se_play($data_system.decision_se)
- @type_weapon = 4
- @new_weapon.icon_name = "004-Weapon04"
- @new_weapon.animation2_id = 10
- $last_name = "匕首"
- $last_des = "的匕首"
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- when 4
- $game_system.se_play($data_system.decision_se)
- @type_weapon = 5
- @new_weapon.icon_name = "005-Weapon05"
- @new_weapon.animation2_id = 11
- $last_name = "弓"
- $last_des = "的弓"
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- when 5
- $game_system.se_play($data_system.decision_se)
- @type_weapon = 6
- @new_weapon.icon_name = "006-Weapon06"
- @new_weapon.animation2_id = 12
- $last_name = "铳"
- $last_des = "的铳"
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- when 6
- $game_system.se_play($data_system.decision_se)
- @type_weapon = 7
- @new_weapon.icon_name = "007-Weapon07"
- @new_weapon.animation2_id = 13
- $last_name = "槌"
- $last_des = "的槌"
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- when 7
- $game_system.se_play($data_system.decision_se)
- @type_weapon = 8
- @new_weapon.icon_name = "008-Weapon08"
- @new_weapon.animation2_id = 14
- $last_name = "杖"
- $last_des = "的杖"
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- end
- return
- end
- end
- #------------------------------------------------------------------------------
- def update_status
- # 按下 B 键的情况下
- if Input.trigger?(Input::B)
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- @window_status.index = 0
- @tf.active = false
- @window_text.active = false
- @type_window.active = true
- @window_auto.active = false
- @window_text.active = false
- @input_number_window.active = false
- @window_status.active = false
- return
- end
- # 按下 C 键的情况下
- if Input.trigger?(Input::C)
- # 命令窗口的光标位置分支
- case @window_status.index
- when 0..8
- $game_system.se_play($data_system.decision_se)
- @window_text.active = false
- @tf.active = false
- @type_window.active = false
- @window_status.active = false
- @input_number_window.active = false
- @window_auto.active = true
- when 9
- @window_element.active = true
- @window_status.active = false
- end
- return
- end
- end
- #------------------------------------------------------------------------------
- def update_auto
- if Input.trigger?(Input::B)
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- @window_auto.index = 0
- # 切换的地图画面
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- @window_status.active = true
- return
- end
- # 按下 C 键的情况下
- if Input.trigger?(Input::C)
- # 命令窗口的光标位置分支
- case @window_auto.index
- when 0
- $game_system.se_play($data_system.decision_se)
- @type_window.active = false
- @window_text.active = false
- @window_status.active = false
- @window_auto.active = false
- for n in 0..6
- if @window_status.index == n
- @tf.active = false
- @window_text.active = false
- @input_number_window.active = true
- end
- end
- if @window_status.index == 7
- @input_number_window.active = false
- @tf.active = true
- @window_text.active = true
- end
- if @window_status.index == 8
- @input_number_window.active = false
- @window_text.active = true
- @tf.active = true
- end
- when 1
- if @window_status.index == 0
- @type_set_atk = 2
- set_new_weapon_atk
- end
- if @window_status.index == 1
- @type_set_pdef = 2
- set_new_weapon_pdef
- end
- if @window_status.index == 2
- @type_set_mdef = 2
- set_new_weapon_mdef
- end
- if @window_status.index == 3
- @type_set_str_plus = 2
- set_new_weapon_str_plus
- end
- if @window_status.index == 4
- @type_set_dex_plus = 2
- set_new_weapon_dex_plus
- end
- if @window_status.index == 5
- @type_set_agi_plus = 2
- set_new_weapon_agi_plus
- end
- if @window_status.index == 6
- @type_set_int_plus = 2
- set_new_weapon_int_plus
- end
- if @window_status.index == 7
- set_new_weapon_auto_name
- end
- if @window_status.index == 8
- set_new_weapon_auto_description
- end
- $game_system.se_play($data_system.decision_se)
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_status.active = true
- @input_number_window.active = false
- @window_text.active = false
- @window_auto.active = false
- end
- return
- end
- end
- #------------------------------------------------------------------------------
- def update_number
- if Input.trigger?(Input::C)
- $game_system.se_play($data_system.decision_se)
- if @window_status.index == 0
- @new_weapon.atk = @input_number_window.number
- @type_set_atk = 1
- set_new_weapon_atk
- end
- if @window_status.index == 1
- @new_weapon.pdef = @input_number_window.number
- @type_set_pdef = 1
- set_new_weapon_pdef
- end
- if @window_status.index == 2
- @new_weapon.mdef = @input_number_window.number
- @type_set_mdef = 1
- set_new_weapon_mdef
- end
- if @window_status.index == 3
- @new_weapon.str_plus = @input_number_window.number
- @type_set_str_plus = 1
- set_new_weapon_str_plus
- end
- if @window_status.index == 4
- @new_weapon.dex_plus = @input_number_window.number
- @type_set_dex_plus = 1
- set_new_weapon_dex_plus
- end
- if @window_status.index == 5
- @new_weapon.agi_plus = @input_number_window.number
- @type_set_agi_plus = 1
- set_new_weapon_agi_plus
- end
- if @window_status.index == 6
- @new_weapon.int_plus = @input_number_window.number
- @type_set_int_plus = 1
- set_new_weapon_int_plus
- end
- @tf.active = false
- @window_text.active = false
- @type_window.active = false
- @window_status.active = true
- @input_number_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- return
- end
- end
- #------------------------------------------------------------------------------
- def update_text
- if RInput.trigger?(RInput::ENTER)
- $game_system.se_play($data_system.decision_se)
- if @window_status.index == 7
- @new_weapon.name = @tf.get_text
- @type_window.active = false
- @window_status.active = true
- @input_number_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- end
- if @window_status.index == 8
- @new_weapon.description = @tf.get_text
- @type_window.active = false
- @window_status.active = true
- @input_number_window.active = false
- @window_auto.active = false
- @input_number_window.active = false
- end
- return
- end
- end
- #------------------------------------------------------------------------------
- def update_element
- if Input.trigger?(Input::C)
- $game_system.se_play($data_system.decision_se)
- @window_element.active = false
- set_new_weapon_price
- case @window_element.index
- when 0..15
- @new_weapon.price + $price_element
- @ele = (@window_element.index + 1)
- @new_weapon.element_set = [@ele]
- @yes_no_window.visible = true
- @confirm_window.visible = true
- @confirm_window.contents.clear
- string = "打造费是#{@new_weapon.price} G,是否打造?"
- @confirm_window.contents.font.name = "黑体"
- @confirm_window.contents.font.size = 24
- @confirm_window.contents.draw_text(4, 0, 368, 32, string)
- @confirm_window.update
- @yes_no_window.active = true
- when 16
- @yes_no_window.visible = true
- @confirm_window.visible = true
- @confirm_window.contents.clear
- string = "打造费是#{@new_weapon.price} G,是否打造?"
- @confirm_window.contents.font.name = "黑体"
- @confirm_window.contents.font.size = 24
- @confirm_window.contents.draw_text(4, 0, 368, 32, string)
- @confirm_window.update
- @yes_no_window.active = true
- end
- return
- end
- end
- #-----------------------------------------------------------------------------
- def update_yn
- if RInput.trigger?(RInput::ENTER)
- case @yes_no_window.index
- when 0
- if $game_party.gold >= @new_weapon.price
- $game_party.gain_gold((- @new_weapon.price))
- @s = 2 + rand(17 - 2 + 1)
- @new_weapon.minus_state_set = [@s]
- create_new_weapon
- $scene = Scene_Map.new
- get_weapon(@new_weapon.name, 1)
- return
- else
- $game_system.se_play($data_system.buzzer_se)
- end
- when 1
- $scene = Scene_MakeWeapon.new
- return
- end
- return
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- # 刷新窗口
- @type_window.update
- @window_status.update
- @window_auto.update
- # 命令窗口被激活的情况下: 调用 update_command
- if @type_window.active
- update_command
- return
- end
- if @window_status.active
- update_status
- return
- end
- if @window_auto.active
- update_auto
- return
- end
- if @input_number_window.active
- @input_number_window.update
- update_number
- end
- if @window_text.active
- @window_text.update
- @tf.update
- update_text
- end
- if @window_element.active
- @window_element.update
- update_element
- end
- if @yes_no_window.active
- @yes_no_window.update
- update_yn
- end
- end
- #==============================================================================
- # ■新武器攻击设定
- #==============================================================================
- def set_new_weapon_atk
- case @type_set_atk
- when 1
- deviate = @new_weapon.atk * 10 / 100
- @new_weapon.atk += rand(deviate + 1) + rand(deviate + 1) - deviate
- if @type_new_weapon == 8
- @new_weapon.atk *= 2/3
- end
- when 2
- varience = 0
- for i in 1...$game_party.actors.size + 1
- varience += $game_actors[i].level
- end
- mean = (varience/$game_party.actors.size)+5
- @new_weapon.atk = rand(mean * 10) + 100
- deviate = @new_weapon.atk * 10 /100
- @new_weapon.atk += rand(deviate + 1) + rand(deviate + 1) - deviate
- if @type_new_weapon == 8
- @new_weapon.atk *= 2/3
- end
- end
- end
- #==============================================================================
- # ■新武器物理防御设定
- #==============================================================================
- def set_new_weapon_pdef
- case @type_set_pdef
- when 1
- deviate = @new_weapon.pdef * 10 /100
- @new_weapon.pdef += rand(deviate + 1) + rand(deviate + 1) - deviate
- if @type_new_weapon == 8
- @new_weapon.pdef *= 2/3
- end
- when 2
- varience = 0
- for i in 1...$game_party.actors.size + 1
- varience += $game_actors[i].level
- end
- mean = varience/$game_party.actors.size
- @new_weapon.pdef = rand(mean * 10) + 100
- deviate = @new_weapon.pdef * 10 /100
- @new_weapon.pdef += rand(deviate + 1) + rand(deviate + 1) - deviate
- if @type_new_weapon == 8
- @new_weapon.pdef *= 2/3
- end
- i = rand(99)
- case i
- when 0
- @new_weapon.pdef = 0
- when 40...44
- @new_weapon.pdef /= 2
- when 50...54
- @new_weapon.pdef /= 3
- else
- @new_weapon.pdef *= 1
- end
- end
- end
- #==============================================================================
- # ■新武器魔法防御设定
- #==============================================================================
- def set_new_weapon_mdef
- case @type_set_mdef
- when 1
- deviate = @new_weapon.mdef * 10 /100
- @new_weapon.mdef += rand(deviate + 1) + rand(deviate + 1) - deviate
- if @type_new_weapon == 8
- @new_weapon.mdef *= 2/3
- end
- when 2
- varience = 0
- for i in 1...$game_party.actors.size + 1
- varience += $game_actors[i].level
- end
- mean = varience/$game_party.actors.size
- @new_weapon.mdef = rand(mean * 10) + 100
- deviate = @new_weapon.mdef * 10 /100
- @new_weapon.mdef += rand(deviate + 1) + rand(deviate + 1) - deviate
- if @type_new_weapon == 8
- @new_weapon.mdef *= 2/3
- end
- i = rand(99)
- case i
- when 0
- @new_weapon.mdef = 0
- when 40...44
- @new_weapon.mdef /= 2
- when 50...54
- @new_weapon.mdef /= 3
- else
- @new_weapon.mdef *= 1
- end
- end
- end
- #==============================================================================
- # ■新武器附加力量设定
- #==============================================================================
- def set_new_weapon_str_plus
- case @type_set_str_plus
- when 1
- deviate = @new_weapon.str_plus / 10
- @new_weapon.str_plus += rand(deviate + 1) + rand(deviate + 1) - deviate
- if @type_new_weapon == 8
- @new_weapon.str_plus *= 2/3
- end
- when 2
- @new_weapon.str_plus = rand(200)
- if @type_new_weapon == 8
- @new_weapon.str_plus /= 2
- end
- i = rand(99)
- case i
- when 0
- @new_weapon.str_plus = 0
- when 40...44
- @new_weapon.str_plus /= 2
- when 50...54
- @new_weapon.str_plus /= 3
- else
- @new_weapon.str_plus *= 1
- end
- end
- end
- #==============================================================================
- # ■新武器附加灵巧设定
- #==============================================================================
- def set_new_weapon_dex_plus
- case @type_set_dex_plus
- when 1
- deviate = @new_weapon.dex_plus / 10
- @new_weapon.dex_plus += rand(deviate + 1) + rand(deviate + 1) - deviate
- when 2
- @new_weapon.dex_plus = rand(200)
- i = rand(99)
- case i
- when 0
- @new_weapon.dex_plus = 0
- when 40...44
- @new_weapon.dex_plus /= 2
- when 50...54
- @new_weapon.dex_plus /= 3
- else
- @new_weapon.dex_plus *= 1
- end
- end
- end
- #==============================================================================
- # ■新武器附加速度设定
- #==============================================================================
- def set_new_weapon_agi_plus
- case @type_set_agi_plus
- when 1
- deviate = @new_weapon.agi_plus / 10
- @new_weapon.agi_plus += rand(deviate + 1) + rand(deviate + 1) - deviate
- when 2
- @new_weapon.agi_plus = rand(200)
- i = rand(99)
- case i
- when 0
- @new_weapon.agi_plus = 0
- when 40...44
- @new_weapon.agi_plus /= 2
- when 50...54
- @new_weapon.agi_plus /= 3
- else
- @new_weapon.agi_plus *= 1
- end
- end
- end
- #==============================================================================
- # ■新武器附加魔力设定
- #==============================================================================
- def set_new_weapon_int_plus
- case @type_set_int_plus
- when 1
- deviate = @new_weapon.int_plus / 10
- @new_weapon.int_plus += rand(deviate + 1) + rand(deviate + 1) - deviate
- if @type_new_weapon == 8
- @new_weapon.int_plus *= 3/2
- end
- when 2
- @new_weapon.int_plus = rand(200)
- if @type_new_weapon == 8
- @new_weapon.int_plus *= 3/2
- end
- i = rand(99)
- case i
- when 0
- @new_weapon.int_plus = 0
- when 40...44
- @new_weapon.int_plus /= 2
- when 50...54
- @new_weapon.int_plus /= 3
- else
- @new_weapon.int_plus *= 1
- end
- end
- end
- #==============================================================================
- # ■新武器生成
- #==============================================================================
- def create_new_weapon
- $data_weapons.push(@new_weapon)
- case @type_weapon
- when 1
- for i in 1...$data_classes.size
- if $data_classes[i].weapon_set.include?($最普通的剑编号)
- $data_classes[i].weapon_set.push(@new_weapon.id)
- end
- end
- when 2
- for i in 1...$data_classes.size
- if $data_classes[i].weapon_set.include?($最普通的枪(矛)编号)
- $data_classes[i].weapon_set.push(@new_weapon.id)
- end
- end
- when 3
- for i in 1...$data_classes.size
- if $data_classes[i].weapon_set.include?($最普通的斧头编号)
- $data_classes[i].weapon_set.push(@new_weapon.id)
- end
- end
- when 4
- for i in 1...$data_classes.size
- if $data_classes[i].weapon_set.include?($最普通的匕首编号)
- $data_classes[i].weapon_set.push(@new_weapon.id)
- end
- end
- when 5
- for i in 1...$data_classes.size
- if $data_classes[i].weapon_set.include?($最普通的弓编号)
- $data_classes[i].weapon_set.push(@new_weapon.id)
- end
- end
- when 6
- for i in 1...$data_classes.size
- if $data_classes[i].weapon_set.include?($最普通的手枪编号)
- $data_classes[i].weapon_set.push(@new_weapon.id)
- end
- end
- when 7
- for i in 1...$data_classes.size
- if $data_classes[i].weapon_set.include?($最普通的槌编号)
- $data_classes[i].weapon_set.push(@new_weapon.id)
- end
- end
- when 8
- for i in 1...$data_classes.size
- if $data_classes[i].weapon_set.include?($最普通的杖编号)
- $data_classes[i].weapon_set.push(@new_weapon.id)
- end
- end
- end
- end
- #==============================================================================
- # ■获得新武器
- #==============================================================================
- def get_weapon(weapon_name, n)
- @weapon_name = weapon_name
- for i in 1...$data_weapons.size
- if $data_weapons[i].name == @weapon_name
- @weapon_id = i
- end
- end
- $game_party.gain_weapon(@weapon_id, n)
- enghao_showbar_weapon = $data_weapons[@weapon_id]
- enghao_showbar = Window_Base.new((640-300)/2,128,300,100)
- enghao_showbar.contents = Bitmap.new(enghao_showbar.width - 32, enghao_showbar.height - 32)
- if n >= 0
- enghao_showbar.contents.draw_text(0,0,240,32,"获得武器:")
- Audio.se_play("Audio/SE/"+"006-System06",80,100)
- else
- enghao_showbar.contents.draw_text(0,0,240,32,"失去武器:")
- Audio.se_play("Audio/SE/"+"005-System05",80,100)
- end
- enghao_showbar_bitmap = RPG::Cache.icon(enghao_showbar_weapon.icon_name)
- enghao_showbar.contents.blt(0, 32, enghao_showbar_bitmap, Rect.new(0, 0, 24, 24), 255)
- enghao_showbar.contents.draw_text(0 + 28, 32, 212, 32, enghao_showbar_weapon.name, 0)
- enghao_showbar.contents.draw_text(0, 32, 268, 32, "×"+n.abs.to_s, 2)
- enghao_showbar.opacity = 255
- enghao_showbar.z = 2000
- for i in 0...30
- Graphics.update
- end
- for i in 0...10
- enghao_showbar.opacity -= 30
- enghao_showbar.contents_opacity -= 30
- Graphics.update
- end
- enghao_showbar.dispose
- end
- #==============================================================================
- # ■新武器名称自动设定
- #==============================================================================
- def set_new_weapon_auto_name
- $start_name = ""
- $first_name = ""
- if @new_weapon.atk > @new_weapon.pdef * 2
- $start_name = "超·"
- elsif @new_weapon.atk == 0 and @new_weapon.pdef == 0 and @new_weapon.mdef ==0 and @new_weapon.dex_plus == 0 and @new_weapon.str_plus ==0 and @new_weapon.int_plus == 0 and @new_weapon.agi_plus ==0
- $start_name = "无用·"
- elsif @new_weapon.atk > @new_weapon.pdef * 2
- $start_name = "真·"
- elsif @new_weapon.atk == (@new_weapon.pdef - @new_weapon.mdef) * 2
- $start_name = "无双·"
- elsif @new_weapon.atk > @new_weapon.pdef and @new_weapon.atk > @new_weapon.mdef
- $start_name = "顽强·"
- elsif @new_weapon.mdef > @new_weapon.atk and @new_weapon.mdef > @new_weapon.pdef
- $start_name = "灵冥·"
- elsif @new_weapon.pdef > @new_weapon.atk and @new_weapon.pdef > @new_weapon.mdef
- $start_name = "绝气·"
- elsif @new_weapon.pdef == @new_weapon.atk and @new_weapon.atk == @new_weapon.mdef
- $start_name = "王者·"
- else
- $start_name = "普通·"
- end
- if @new_weapon.atk != 0 and @new_weapon.pdef != 0 and @new_weapon.mdef != 0 and @new_weapon.dex_plus != 0 and @new_weapon.str_plus != 0 and @new_weapon.int_plus != 0 and @new_weapon.agi_plus != 0
- if @new_weapon.pdef == @new_weapon.mdef
- $first_name += "天护"
- end
- if @new_weapon.str_plus > @new_weapon.dex_plus and @new_weapon.str_plus > @new_weapon.int_plus
- $first_name += "力量"
- end
- if @new_weapon.int_plus > @new_weapon.str_plus
- $first_name += "魔力"
- end
- if @new_weapon.agi_plus > @new_weapon.dex_plus
- $first_name += "闪电"
- end
- if @new_weapon.dex_plus > @new_weapon.str_plus and @new_weapon.dex_plus > @new_weapon.int_plus
- $first_name += "灵气"
- end
- if @new_weapon.str_plus == @new_weapon.dex_plus and @new_weapon.dex_plus == @new_weapon.agi_plus and @new_weapon.dex_plus == @new_weapon.int_plus
- $first_name += "灵王之"
- end
- if @new_weapon.str_plus == @new_weapon.int_plus
- $first_name += "玉龙"
- end
- if @new_weapon.agi_plus == @new_weapon.dex_plus
- $first_name += "神瞬"
- end
- if @new_weapon.dex_plus > @new_weapon.str_plus and @new_weapon.dex_plus > @new_weapon.int_plus
- $first_name += "流光"
- end
- if @new_weapon.atk == (@new_weapon.dex_plus + @new_weapon.agi_plus)/2
- $first_name += "快击"
- end
- elsif @new_weapon.atk == 0 and @new_weapon.pdef == 0 and @new_weapon.mdef == 0 and @new_weapon.dex_plus == 0 and @new_weapon.str_plus == 0 and @new_weapon.int_plus == 0 and @new_weapon.agi_plus == 0
- $first_name += "很烂的"
- else
- $first_name += ""
- end
- @new_weapon.name = $start_name + $first_name + $last_name
- end
- #==============================================================================
- # ■新武器说明自动设定
- #==============================================================================
- def set_new_weapon_auto_description
- $start_des = ""
- if @new_weapon.atk == 0 and @new_weapon.pdef == 0 and @new_weapon.mdef ==0 and @new_weapon.dex_plus == 0 and @new_weapon.str_plus ==0 and @new_weapon.int_plus == 0 and @new_weapon.agi_plus ==0
- $first_des = ",无用"
- elsif @new_weapon.dex_plus != 0 and @new_weapon.str_plus !=0 and @new_weapon.int_plus != 0 and @new_weapon.agi_plus !=0
- $first_des = ",提升"
- else
- $first_des = ""
- end
- if @new_weapon.atk > (@new_weapon.pdef + @new_weapon.mdef)/2
- $start_des = "增加攻击为主"
- elsif @new_weapon.atk < (@new_weapon.pdef + @new_weapon.mdef)/2
- $start_des = "增加防御为主"
- elsif @new_weapon.atk == 0 and @new_weapon.pdef == 0 and @new_weapon.mdef ==0
- $start_des = "无攻击与防御能力"
- elsif @new_weapon.atk == (@new_weapon.pdef + @new_weapon.mdef)/2 and @new_weapon.atk != 0
- $start_des = "攻守俱佳,"
- end
- if @new_weapon.str_plus != 0
- $first_des += "力量,"
- end
- if @new_weapon.int_plus != 0
- $first_des += "魔力,"
- end
- if @new_weapon.agi_plus != 0
- $first_des += "速度,"
- end
- if @new_weapon.dex_plus != 0
- $first_des += "灵气,"
- end
- @new_weapon.description = $start_des + $first_des + $last_des
- end
- #==============================================================================
- # ■新武器价格设定
- #==============================================================================
- def set_new_weapon_price
- price1 = (@new_weapon.atk * $price_atk)
- price2 = (@new_weapon.pdef * $price_pdef)
- price3 = (@new_weapon.mdef * $price_mdef)
- price4 = (@new_weapon.str_plus * $price_str)
- price5 = (@new_weapon.dex_plus * $price_dex)
- price6 = (@new_weapon.agi_plus * $price_agi)
- price7 = (@new_weapon.int_plus * $price_int)
- @new_weapon.price = (price1 + price2 + price3 + price4 + price5 + price6 + price7)
- end
- end
- #==============================================================================
- # ● 读取存档数据
- # file : 读取用文件对像 (已经打开)
- #==============================================================================
- class Scene_Load
- def read_save_data(file)
- # 读取描绘存档文件用的角色数据
- characters = Marshal.load(file)
- # 读取测量游戏时间用画面计数
- Graphics.frame_count = Marshal.load(file)
- # 读取各种游戏对像
- $game_system = Marshal.load(file)
- $game_switches = Marshal.load(file)
- $game_variables = Marshal.load(file)
- $game_self_switches = Marshal.load(file)
- $game_screen = Marshal.load(file)
- $game_actors = Marshal.load(file)
- $game_party = Marshal.load(file)
- $game_troop = Marshal.load(file)
- $game_map = Marshal.load(file)
- $game_player = Marshal.load(file)
- $data_weapons = Marshal.load(file)
- $data_classes = Marshal.load(file)
- # 魔法编号与保存时有差异的情况下
- # (加入编辑器的编辑过的数据)
- if $game_system.magic_number != $data_system.magic_number
- # 重新装载地图
- $game_map.setup($game_map.map_id)
- $game_player.center($game_player.x, $game_player.y)
- end
- # 刷新同伴成员
- $game_party.refresh
- end
- end
- #==============================================================================
- # ● 写入存档数据
- # file : 写入用文件对像 (已经打开)
- #==============================================================================
- class Scene_Save
- def write_save_data(file)
- # 生成描绘存档文件用的角色图形
- characters = []
- for i in 0...$game_party.actors.size
- actor = $game_party.actors[i]
- characters.push([actor.character_name, actor.character_hue])
- end
- # 写入描绘存档文件用的角色数据
- Marshal.dump(characters, file)
- # 写入测量游戏时间用画面计数
- Marshal.dump(Graphics.frame_count, file)
- # 增加 1 次存档次数
- $game_system.save_count += 1
- # 保存魔法编号
- # (将编辑器保存的值以随机值替换)
- $game_system.magic_number = $data_system.magic_number
- # 写入各种游戏对像
- Marshal.dump($game_system, file)
- Marshal.dump($game_switches, file)
- Marshal.dump($game_variables, file)
- Marshal.dump($game_self_switches, file)
- Marshal.dump($game_screen, file)
- Marshal.dump($game_actors, file)
- Marshal.dump($game_party, file)
- Marshal.dump($game_troop, file)
- Marshal.dump($game_map, file)
- Marshal.dump($game_player, file)
- Marshal.dump($data_weapons, file)
- Marshal.dump($data_classes, file)
- end
- end
复制代码- =begin
- 脚本:【完美输入法修正】
-
- 功能:输入法。
-
- 说明: 直接用Type_Field创建输入域即可进行输入,在此可根据Type_Field域对象
-
- 的活动标记active来自定义刷新等,在Type_Field中需要自己处理特殊按键
-
- 的处理方法。具体不明白之处请参考范例工程。
- 作者:灼眼的夏娜
-
- 补充: 至于以前那个版本也许很多人都注意到那个烦人的问题了吧,按Enter和Tab那
-
- 些会出现不爽的声音,这个版本解决了那个问题,并简化添加了Type_Field类
-
- 来方便创建输入域。
- =end
- #==============================================================================
- # ■ RInput
- #------------------------------------------------------------------------------
- # 全键盘处理的模块。
- #==============================================================================
- module RInput
-
- #--------------------------------------------------------------------------
- # ● 常量定义
- #--------------------------------------------------------------------------
- ENTER = 0x0D
- SPACE = 0x20
- UP = 0x26
- DOWN = 0x28
- LEFT = 0x25
- RIGHT = 0x27
-
- LCTRL = 0xA2
- LALT = 0xA4
- #--------------------------------------------------------------------------
- # ● 临时Hash
- #--------------------------------------------------------------------------
- @R_Key_Hash = {}
- @R_Key_Repeat = {}
-
- #--------------------------------------------------------------------------
- # ● 唯一API
- #--------------------------------------------------------------------------
- GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
- #--------------------------------------------------------------------------
- # ● 单键处理
- #--------------------------------------------------------------------------
- def self.trigger?(rkey)
- result = GetKeyState.call(rkey)
- if @R_Key_Hash[rkey] == 1 and result != 0
- return false
- end
- if result != 0
- @R_Key_Hash[rkey] = 1
- return true
- else
- @R_Key_Hash[rkey] = 0
- return false
- end
- end
- end
- #==============================================================================
- # ■ EasyConv
- #------------------------------------------------------------------------------
- # 转码模块。
- #==============================================================================
- module EasyConv
- #--------------------------------------------------------------------------
- # ● 常量定义
- #--------------------------------------------------------------------------
- CP_ACP = 0
- CP_UTF8 = 65001
- #--------------------------------------------------------------------------
- # ● 模块函数
- #--------------------------------------------------------------------------
- module_function
-
- #--------------------------------------------------------------------------
- # ● 转码
- #--------------------------------------------------------------------------
- def s2u(text)
- m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- 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)
- 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)
- ret[-1] = ""
-
- return ret
- end
- #--------------------------------------------------------------------------
- # ● 转码
- #--------------------------------------------------------------------------
- def u2s(text)
-
- m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- 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)
- 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
- end
- #==============================================================================
- # ■ TypeAPI
- #------------------------------------------------------------------------------
- # 输入法相关API模块。
- #==============================================================================
- module TypeAPI
-
- #--------------------------------------------------------------------------
- # ● API定义
- #--------------------------------------------------------------------------
- GPPS = Win32API.new("kernel32","GetPrivateProfileString",'pppplp','l')
- FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
- CreateWindow = Win32API.new("NetGame","CreatWnd",'l','l')
- SetHK = Win32API.new("NetGame","SetHK",'v','v')
- GetText = Win32API.new("NetGame","GetWndText",'l','p')
- SetFocus = Win32API.new("user32","SetFocus",'l','l')
- IfBack = Win32API.new("NetGame","If_Back",'v','i')
- StartType = Win32API.new("NetGame","StartType",'v','v')
- EndType = Win32API.new("NetGame","EndType",'v','v')
- GetKeyInfos = Win32API.new("NetGame","GetKeyInfo",'v','i')
-
- #--------------------------------------------------------------------------
- # ● 模块函数
- #--------------------------------------------------------------------------
- module_function
-
- #--------------------------------------------------------------------------
- # ● 获取参数
- #--------------------------------------------------------------------------
- def getParam
- val = "\0" * 256
- GPPS.call("Game","Title","",val,256,"./Game.ini")
- val.delete!("\0")
- return val
- end
-
- #--------------------------------------------------------------------------
- # ● 获取窗口
- #--------------------------------------------------------------------------
- def findWindow
- return FindWindow.call("RGSS Player",self.getParam)
- end
-
- #--------------------------------------------------------------------------
- # ● 创建窗口
- #--------------------------------------------------------------------------
- def createWindow(hwnd)
- return CreateWindow.call(hwnd)
- end
-
- #--------------------------------------------------------------------------
- # ● 设置HK
- #--------------------------------------------------------------------------
- def setHK
- SetHK.call
- end
-
- #--------------------------------------------------------------------------
- # ● 获取文字
- #--------------------------------------------------------------------------
- def getText
- return EasyConv.s2u(GetText.call(@subhwnd))
- end
-
- #--------------------------------------------------------------------------
- # ● 设置焦点
- #--------------------------------------------------------------------------
- def setFocus
- SetFocus.call(@subhwnd)
- end
-
- #--------------------------------------------------------------------------
- # ● 转换焦点
- #--------------------------------------------------------------------------
- def lostFocus
- SetFocus.call(@hwnd)
- end
-
- #--------------------------------------------------------------------------
- # ● 退格判定
- #--------------------------------------------------------------------------
- def ifBack
- return IfBack.call
- end
-
- #--------------------------------------------------------------------------
- # ● 开始输入
- #--------------------------------------------------------------------------
- def startType
- StartType.call
- end
-
- #--------------------------------------------------------------------------
- # ● 结束输入
- #--------------------------------------------------------------------------
- def endType
- EndType.call
- end
-
- #--------------------------------------------------------------------------
- # ● 输入中特殊按键处理
- #--------------------------------------------------------------------------
- def getKeyInfos
- return GetKeyInfos.call
- end
-
- #--------------------------------------------------------------------------
- # ● 获取句柄
- #--------------------------------------------------------------------------
- @hwnd = self.findWindow
-
- @subhwnd = self.createWindow(@hwnd)
- #--------------------------------------------------------------------------
- # ● 设置HK应用
- #--------------------------------------------------------------------------
- self.setHK
-
- end
- #==============================================================================
- # ■ Type_Field
- #------------------------------------------------------------------------------
- # 处理输入域的类。
- #==============================================================================
- class Type_Field
-
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr(:active)
-
- #--------------------------------------------------------------------------
- # ● 初始化
- #--------------------------------------------------------------------------
- def initialize(v,default_text = "",default_careth = nil,default_fonts = 16,\
- default_fontc = Color.new(255,255,255),size = 8)
- # active
- @active = true
- # 视口
- rect = v.rect
- @v = Viewport.new(rect.x,rect.y,rect.width,rect.height)
- @v.z = 10000
- @w = rect.width
- @h = rect.height
- # 属性
- @caret_h = default_careth.nil? ? @h : [@h,default_careth].min
- @caret_y = rect.y + (@h - @caret_h) / 2
- @font_size = [default_fonts,@h].min
- # 描绘contents
- @cts = Sprite.new(@v)
- @cts.bitmap = Bitmap.new(@w - 3,@h)
- @cts.bitmap.font.size = @font_size
- @cts.bitmap.font.color = default_fontc
- # 辅助属性
- @bk_count = 0
- @text = default_text.scan(/./)
- @max_size = size
- @caret_pos = @text.size
- @save_pos = @caret_pos
- # 光标Caret
- @v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
- @v1.z = 99999
- @caret_sp = Sprite.new(@v1)
- @caret_bitmap = Bitmap.new(3,@caret_h)
- @caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,255))
- @caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
- @caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
- @caret_sp.bitmap = @caret_bitmap
- @caret_sp.x = self.get_width(@text[0,@caret_pos].to_s) + 87
- @caret_sp.y = 0
- @caret_sp.visible = false
- @caret_flash_count = 0
- # 刷新
- refresh
- # 设置焦点
- TypeAPI.setFocus
- # 开始输入
- TypeAPI.startType
- end
-
- #--------------------------------------------------------------------------
- # ● 设置活动标记
- #--------------------------------------------------------------------------
- def active=(value)
- if value != true and value != false
- return
- end
- @active = value
- @caret_sp.visible = @active
- end
-
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- @caret_bitmap.dispose
- @caret_sp.bitmap.dispose
- @caret_sp.dispose
- @cts.bitmap.dispose
- @cts.dispose
- @v.dispose
- @v1.dispose
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- @cts.bitmap.clear
- @cts.bitmap.draw_text(85,0,@w,@h,@text.to_s)
- end
- #--------------------------------------------------------------------------
- # ● 获取文字
- #--------------------------------------------------------------------------
- def get_text
- return @text.to_s
- end
- #--------------------------------------------------------------------------
- # ● 取得字符宽度
- #--------------------------------------------------------------------------
- def get_width(str)
- return @cts.bitmap.text_size(str).width
- end
-
- #--------------------------------------------------------------------------
- # ● 更新
- #--------------------------------------------------------------------------
- def update
- @caret_sp.visible = @active
- # 非激活状态则返回
- unless @active
- return
- end
- # 获取按键信息
- key_info = TypeAPI.getKeyInfos
- case key_info
- when 0x09 # Tab
- # 按下 Tab 键的情况自己定义怎么处理
- return
- when 0x0d # Enter
- # 按下 Enter 键的情况自己定义怎么处理
- return
- when 0x1B # Esc
- # 按下 Esc 键的情况自己定义怎么处理
- return
- end
- self.update_text
- self.update_lrb
- self.update_back
- self.update_caret
- end
- #--------------------------------------------------------------------------
- # ● 更新文字
- #--------------------------------------------------------------------------
- def update_text
- # 文字刷新
- TypeAPI.setFocus
- text = TypeAPI.getText
- if text != ""
- for char in text.scan(/./)
- if self.get_text.size <= @max_size
- @text[@caret_pos,0] = char
- @caret_pos += 1
- else
- break
- end
- end
- refresh
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 更新左右按键
- #--------------------------------------------------------------------------
- def update_lrb
- if RInput.trigger?(RInput::LEFT) and @caret_pos > 0
- @caret_pos -= 1
- return
- end
- if RInput.trigger?(RInput::RIGHT) and @caret_pos < @text.size
- @caret_pos += 1
- return
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 更新退格
- #--------------------------------------------------------------------------
- def update_back
- # 前退格处理
- @bk_count += TypeAPI.ifBack
- if @bk_count > 0
- @bk_count -= 1
- if @caret_pos > 0
- @text.delete_at(@caret_pos - 1);@caret_pos -= 1;refresh
- end
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 更新光标闪烁
- #--------------------------------------------------------------------------
- def update_caret
- # 闪烁计时
- @caret_flash_count += 1
- if @caret_flash_count == 20
- @caret_sp.visible = !@caret_sp.visible
- @caret_flash_count = 0
- end
- # Caret位置刷新
- if @save_pos != @caret_pos
- @save_pos = @caret_pos
- @caret_sp.x = self.get_width(@text[0,@save_pos].to_s) + 87
- end
- end
-
- end=begin
- 脚本:【完美输入法修正】
-
- 功能:输入法。
-
- 说明: 直接用Type_Field创建输入域即可进行输入,在此可根据Type_Field域对象
-
- 的活动标记active来自定义刷新等,在Type_Field中需要自己处理特殊按键
-
- 的处理方法。具体不明白之处请参考范例工程。
- 作者:灼眼的夏娜
-
- 补充: 至于以前那个版本也许很多人都注意到那个烦人的问题了吧,按Enter和Tab那
-
- 些会出现不爽的声音,这个版本解决了那个问题,并简化添加了Type_Field类
-
- 来方便创建输入域。
- =end
- #==============================================================================
- # ■ RInput
- #------------------------------------------------------------------------------
- # 全键盘处理的模块。
- #==============================================================================
- module RInput
-
- #--------------------------------------------------------------------------
- # ● 常量定义
- #--------------------------------------------------------------------------
- ENTER = 0x0D
- SPACE = 0x20
- UP = 0x26
- DOWN = 0x28
- LEFT = 0x25
- RIGHT = 0x27
-
- LCTRL = 0xA2
- LALT = 0xA4
- #--------------------------------------------------------------------------
- # ● 临时Hash
- #--------------------------------------------------------------------------
- @R_Key_Hash = {}
- @R_Key_Repeat = {}
-
- #--------------------------------------------------------------------------
- # ● 唯一API
- #--------------------------------------------------------------------------
- GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
- #--------------------------------------------------------------------------
- # ● 单键处理
- #--------------------------------------------------------------------------
- def self.trigger?(rkey)
- result = GetKeyState.call(rkey)
- if @R_Key_Hash[rkey] == 1 and result != 0
- return false
- end
- if result != 0
- @R_Key_Hash[rkey] = 1
- return true
- else
- @R_Key_Hash[rkey] = 0
- return false
- end
- end
- end
- #==============================================================================
- # ■ EasyConv
- #------------------------------------------------------------------------------
- # 转码模块。
- #==============================================================================
- module EasyConv
- #--------------------------------------------------------------------------
- # ● 常量定义
- #--------------------------------------------------------------------------
- CP_ACP = 0
- CP_UTF8 = 65001
- #--------------------------------------------------------------------------
- # ● 模块函数
- #--------------------------------------------------------------------------
- module_function
-
- #--------------------------------------------------------------------------
- # ● 转码
- #--------------------------------------------------------------------------
- def s2u(text)
- m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- 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)
- 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)
- ret[-1] = ""
-
- return ret
- end
- #--------------------------------------------------------------------------
- # ● 转码
- #--------------------------------------------------------------------------
- def u2s(text)
-
- m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- 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)
- 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
- end
- #==============================================================================
- # ■ TypeAPI
- #------------------------------------------------------------------------------
- # 输入法相关API模块。
- #==============================================================================
- module TypeAPI
-
- #--------------------------------------------------------------------------
- # ● API定义
- #--------------------------------------------------------------------------
- GPPS = Win32API.new("kernel32","GetPrivateProfileString",'pppplp','l')
- FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
- CreateWindow = Win32API.new("NetGame","CreatWnd",'l','l')
- SetHK = Win32API.new("NetGame","SetHK",'v','v')
- GetText = Win32API.new("NetGame","GetWndText",'l','p')
- SetFocus = Win32API.new("user32","SetFocus",'l','l')
- IfBack = Win32API.new("NetGame","If_Back",'v','i')
- StartType = Win32API.new("NetGame","StartType",'v','v')
- EndType = Win32API.new("NetGame","EndType",'v','v')
- GetKeyInfos = Win32API.new("NetGame","GetKeyInfo",'v','i')
-
- #--------------------------------------------------------------------------
- # ● 模块函数
- #--------------------------------------------------------------------------
- module_function
-
- #--------------------------------------------------------------------------
- # ● 获取参数
- #--------------------------------------------------------------------------
- def getParam
- val = "\0" * 256
- GPPS.call("Game","Title","",val,256,"./Game.ini")
- val.delete!("\0")
- return val
- end
-
- #--------------------------------------------------------------------------
- # ● 获取窗口
- #--------------------------------------------------------------------------
- def findWindow
- return FindWindow.call("RGSS Player",self.getParam)
- end
-
- #--------------------------------------------------------------------------
- # ● 创建窗口
- #--------------------------------------------------------------------------
- def createWindow(hwnd)
- return CreateWindow.call(hwnd)
- end
-
- #--------------------------------------------------------------------------
- # ● 设置HK
- #--------------------------------------------------------------------------
- def setHK
- SetHK.call
- end
-
- #--------------------------------------------------------------------------
- # ● 获取文字
- #--------------------------------------------------------------------------
- def getText
- return EasyConv.s2u(GetText.call(@subhwnd))
- end
-
- #--------------------------------------------------------------------------
- # ● 设置焦点
- #--------------------------------------------------------------------------
- def setFocus
- SetFocus.call(@subhwnd)
- end
-
- #--------------------------------------------------------------------------
- # ● 转换焦点
- #--------------------------------------------------------------------------
- def lostFocus
- SetFocus.call(@hwnd)
- end
-
- #--------------------------------------------------------------------------
- # ● 退格判定
- #--------------------------------------------------------------------------
- def ifBack
- return IfBack.call
- end
-
- #--------------------------------------------------------------------------
- # ● 开始输入
- #--------------------------------------------------------------------------
- def startType
- StartType.call
- end
-
- #--------------------------------------------------------------------------
- # ● 结束输入
- #--------------------------------------------------------------------------
- def endType
- EndType.call
- end
-
- #--------------------------------------------------------------------------
- # ● 输入中特殊按键处理
- #--------------------------------------------------------------------------
- def getKeyInfos
- return GetKeyInfos.call
- end
-
- #--------------------------------------------------------------------------
- # ● 获取句柄
- #--------------------------------------------------------------------------
- @hwnd = self.findWindow
-
- @subhwnd = self.createWindow(@hwnd)
- #--------------------------------------------------------------------------
- # ● 设置HK应用
- #--------------------------------------------------------------------------
- self.setHK
-
- end
- #==============================================================================
- # ■ Type_Field
- #------------------------------------------------------------------------------
- # 处理输入域的类。
- #==============================================================================
- class Type_Field
-
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr(:active)
-
- #--------------------------------------------------------------------------
- # ● 初始化
- #--------------------------------------------------------------------------
- def initialize(v,default_text = "",default_careth = nil,default_fonts = 16,\
- default_fontc = Color.new(255,255,255),size = 8)
- # active
- @active = true
- # 视口
- rect = v.rect
- @v = Viewport.new(rect.x,rect.y,rect.width,rect.height)
- @v.z = 10000
- @w = rect.width
- @h = rect.height
- # 属性
- @caret_h = default_careth.nil? ? @h : [@h,default_careth].min
- @caret_y = rect.y + (@h - @caret_h) / 2
- @font_size = [default_fonts,@h].min
- # 描绘contents
- @cts = Sprite.new(@v)
- @cts.bitmap = Bitmap.new(@w - 3,@h)
- @cts.bitmap.font.size = @font_size
- @cts.bitmap.font.color = default_fontc
- # 辅助属性
- @bk_count = 0
- @text = default_text.scan(/./)
- @max_size = size
- @caret_pos = @text.size
- @save_pos = @caret_pos
- # 光标Caret
- @v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
- @v1.z = 99999
- @caret_sp = Sprite.new(@v1)
- @caret_bitmap = Bitmap.new(3,@caret_h)
- @caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,255))
- @caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
- @caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
- @caret_sp.bitmap = @caret_bitmap
- @caret_sp.x = self.get_width(@text[0,@caret_pos].to_s) + 87
- @caret_sp.y = 0
- @caret_sp.visible = false
- @caret_flash_count = 0
- # 刷新
- refresh
- # 设置焦点
- TypeAPI.setFocus
- # 开始输入
- TypeAPI.startType
- end
-
- #--------------------------------------------------------------------------
- # ● 设置活动标记
- #--------------------------------------------------------------------------
- def active=(value)
- if value != true and value != false
- return
- end
- @active = value
- @caret_sp.visible = @active
- end
-
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- @caret_bitmap.dispose
- @caret_sp.bitmap.dispose
- @caret_sp.dispose
- @cts.bitmap.dispose
- @cts.dispose
- @v.dispose
- @v1.dispose
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- @cts.bitmap.clear
- @cts.bitmap.draw_text(85,0,@w,@h,@text.to_s)
- end
- #--------------------------------------------------------------------------
- # ● 获取文字
- #--------------------------------------------------------------------------
- def get_text
- return @text.to_s
- end
- #--------------------------------------------------------------------------
- # ● 取得字符宽度
- #--------------------------------------------------------------------------
- def get_width(str)
- return @cts.bitmap.text_size(str).width
- end
-
- #--------------------------------------------------------------------------
- # ● 更新
- #--------------------------------------------------------------------------
- def update
- @caret_sp.visible = @active
- # 非激活状态则返回
- unless @active
- return
- end
- # 获取按键信息
- key_info = TypeAPI.getKeyInfos
- case key_info
- when 0x09 # Tab
- # 按下 Tab 键的情况自己定义怎么处理
- return
- when 0x0d # Enter
- # 按下 Enter 键的情况自己定义怎么处理
- return
- when 0x1B # Esc
- # 按下 Esc 键的情况自己定义怎么处理
- return
- end
- self.update_text
- self.update_lrb
- self.update_back
- self.update_caret
- end
- #--------------------------------------------------------------------------
- # ● 更新文字
- #--------------------------------------------------------------------------
- def update_text
- # 文字刷新
- TypeAPI.setFocus
- text = TypeAPI.getText
- if text != ""
- for char in text.scan(/./)
- if self.get_text.size <= @max_size
- @text[@caret_pos,0] = char
- @caret_pos += 1
- else
- break
- end
- end
- refresh
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 更新左右按键
- #--------------------------------------------------------------------------
- def update_lrb
- if RInput.trigger?(RInput::LEFT) and @caret_pos > 0
- @caret_pos -= 1
- return
- end
- if RInput.trigger?(RInput::RIGHT) and @caret_pos < @text.size
- @caret_pos += 1
- return
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 更新退格
- #--------------------------------------------------------------------------
- def update_back
- # 前退格处理
- @bk_count += TypeAPI.ifBack
- if @bk_count > 0
- @bk_count -= 1
- if @caret_pos > 0
- @text.delete_at(@caret_pos - 1);@caret_pos -= 1;refresh
- end
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 更新光标闪烁
- #--------------------------------------------------------------------------
- def update_caret
- # 闪烁计时
- @caret_flash_count += 1
- if @caret_flash_count == 20
- @caret_sp.visible = !@caret_sp.visible
- @caret_flash_count = 0
- end
- # Caret位置刷新
- if @save_pos != @caret_pos
- @save_pos = @caret_pos
- @caret_sp.x = self.get_width(@text[0,@save_pos].to_s) + 87
- end
- end
-
- end
复制代码 |
评分
-
查看全部评分
|