#==============================================================================
# ■ Window_WeaponNameEdit
#------------------------------------------------------------------------------
# 武器名称输入画面、编辑名称的窗口。
#==============================================================================
class Window_WeaponNameEdit < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :name # 名称
attr_reader :index # 光标位置
#--------------------------------------------------------------------------
# ● 初始化对像
# weapon : 武器
# max_char : 最大字数
#--------------------------------------------------------------------------
def initialize(weapon, max_char)
super(0, 0, 640, 128)
self.contents = Bitmap.new(width - 32, height - 32)
[url=home.php?mod=space&uid=36793]@weapon[/url] = weapon
@name = weapon.name
@max_char = max_char
# 控制名字在最大字数以内
name_array = @name.split(//)[0...@max_char]
@name = ""
for i in 0...name_array.size
@name += name_array[i]
end
@default_name = @name
@index = name_array.size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# ● 还原为默认的名称
#--------------------------------------------------------------------------
def restore_default
@name = @default_name
@index = @name.split(//).size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# ● 添加文字
# character : 要添加的文字
#--------------------------------------------------------------------------
def add(character)
if @index < @max_char and character != ""
@name += character
@index += 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# ● 删除文字
#--------------------------------------------------------------------------
def back
if @index > 0
# 删除一个字
name_array = @name.split(//)
@name = ""
for i in 0...name_array.size-1
@name += name_array[i]
end
@index -= 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# 描绘名称
name_array = @name.split(//)
for i in 0...@max_char
c = name_array[i]
if c == nil
c = "_"
end
x = 320 - @max_char * 14 + i * 28
self.contents.draw_text(x, 32, 28, 32, c, 1)
end
# 描绘图形
bitmap = RPG::Cache.icon(@weapon.icon_name)
self.contents.blt(320 - @max_char * 14 - 40, 32, bitmap, Rect.new(0,0,24,24))
end
#--------------------------------------------------------------------------
# ● 刷新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
x = 320 - @max_char * 14 + @index * 28
self.cursor_rect.set(x, 32, 28, 32)
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
update_cursor_rect
end
end
#==============================================================================
# ■ Scene_WeaponName
#------------------------------------------------------------------------------
# 处理武器名称输入画面的类。
#==============================================================================
class Scene_WeaponName
# 初始化
def initialize(weapon_id, max_char)
@weapon = $data_weapons[weapon_id]
@max_char = max_char
end
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
$game_temp.name_max_char = @max_char
# 生成窗口
@edit_window = Window_WeaponNameEdit.new(@weapon, @max_char)
@input_window = Window_NameInput.new
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新信息
update
# 如果画面切换就中断循环
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
# 释放窗口
@edit_window.dispose
@input_window.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 刷新窗口
@edit_window.update
@input_window.update
# 按下 B 键的情况下
if Input.repeat?(Input::B)
# 光标位置为 0 的情况下
if @edit_window.index == 0
return
end
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
# 删除文字
@edit_window.back
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 光标位置为 [确定] 的情况下
if @input_window.character == nil
# 名称为空的情况下
if @edit_window.name == ""
# 还原为默认名称
@edit_window.restore_default
# 名称为空的情况下
if @edit_window.name == ""
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
return
end
# 储存
$game_system.weapon_names = {} if $game_system.weapon_names == nil
if @edit_window.name == @weapon.ori_name
$game_system.weapon_names.delete(@weapon.id)
else
$game_system.weapon_names[@weapon.id] = @edit_window.name
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 切换到地图画面
$scene = Scene_Map.new
return
end
# 光标位置为最大的情况下
if @edit_window.index == $game_temp.name_max_char
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 文字为空的情况下
if @input_window.character == ""
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 添加文字
@edit_window.add(@input_window.character)
return
end
end
end
class Game_System
attr_accessor :weapon_names
alias weapon_name_initialize initialize
def initialize
@weapon_names = {}
weapon_name_initialize
end
end
class RPG::Weapon
def name
if $game_system.weapon_names == nil || $game_system.weapon_names[@id] == nil
return @name
end
return $game_system.weapon_names[@id]
end
def ori_name
@name
end
end