- 注册时间
- 2005-1-30
- 最后登录
- 2005-1-31
⑥精研
- 积分
- 1227
|
发表于 2005-1-30 21:29:03
|
显示全部楼层
修正版
#==============================================================================
# ■ Window_NameInput
#------------------------------------------------------------------------------
# 输入名称的画面、文字选择窗口。
#==============================================================================
class Window_NameInput < Window_Base
CHARACTER_TABLE =
[
\"A\",\"B\",\"C\",\"D\",\"E\",
\"F\",\"G\",\"H\",\"I\",\"J\",
\"K\",\"L\",\"M\",\"N\",\"O\",
\" \",\"Q\",\"R\",\"S\",\"T\",
\"U\",\"V\",\"W\",\"X\",\"Y\",
\"Z\",\",\",\".\",\"?\",\"!\",
\"a\",\"b\",\"c\",\"d\",\"e\",
\"f\", \"g\" ,\"h\", \"i\" ,\"j\",
\"k\",\"l\",\"m\",\"n\",\"o\",
\"p\", \"q\" ,\"r\", \"s\" ,\"t\",
\"u\",\"v\",\"w\",\"x\",\"y\",
\"z\",\"-\",\"@\",\"#\",\"$\",
\"一\",\"二\",\"三\",\"四\",\"五\",
\"六\",\"七\",\"八\",\"九\",\"十\",
\"千\",\"百\",\"万\",\"亿\",\"兆\",
\"生\",\"年\",\"不\",\"满\",\"百\",
\"常\",\"怀\",\"千\",\"岁\",\"忧\",
\"昼\",\"短\",\"苦\",\"夜\",\"长\",
\"何\",\"不\",\"秉\",\"烛\",\"游\"
]
CHARACTER_INDEX_RANGE = 0..CHARACTER_TABLE.length
CHAR_PER_PAGE = 180
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 128, 640, 352)
self.contents = Bitmap.new(width - 32, height - 32)
@index = 0
initial_pages
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# ● 初始化分页
#--------------------------------------------------------------------------
def initial_pages
@current_page = 0
@character_ranges = []
@page_count = (CHARACTER_TABLE.length / CHAR_PER_PAGE).to_i + 1
for i in 0..(@page_count - 1)
@character_ranges[ i ] = (i * CHAR_PER_PAGE)..([(i + 1) * CHAR_PER_PAGE - 1,CHARACTER_TABLE.length - 1].min)
end
end
#--------------------------------------------------------------------------
# ● 获得@index在字符数组中的绝对偏移量
#--------------------------------------------------------------------------
def abs_index
return -1 if @index >= CHAR_PER_PAGE
return @index + @character_ranges[@current_page].first
end
#--------------------------------------------------------------------------
# ● 获取文字
#--------------------------------------------------------------------------
def character
return CHARACTER_TABLE[abs_index] if CHARACTER_INDEX_RANGE === abs_index
return nil
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in @character_ranges[@current_page]
offset = i - @character_ranges[@current_page].first
x = 4 + offset / 5 / 9 * 152 + offset % 5 * 28
y = offset / 5 % 9 * 32
self.contents.draw_text(x, y, 28, 32, CHARACTER_TABLE[ i ], 1)
end
self.contents.draw_text(4, 9 * 32, 64, 32, \"第#{@current_page + 1}页\", 1)
self.contents.draw_text(72, 9 * 32, 64, 32, \"共#{@page_count}页\", 1)
self.contents.draw_text(544, 9 * 32, 64, 32, \"确定\", 1)
end
#--------------------------------------------------------------------------
# ● 刷新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置在 [确定] 的情况下
if @index >= CHAR_PER_PAGE
self.cursor_rect.set(544, 9 * 32, 64, 32)
# 光标位置在 [确定] 以外的情况下
else
x = 4 + @index / 5 / 9 * 152 + @index % 5 * 28
y = @index / 5 % 9 * 32
self.cursor_rect.set(x, y, 28, 32)
end
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
# 光标位置在 [确定] 的情况下
if @index >= CHAR_PER_PAGE
# 光标下
if Input.trigger?(Input: OWN)
$game_system.se_play($data_system.cursor_se)
@index -= CHAR_PER_PAGE
end
# 光标上
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@index -= CHAR_PER_PAGE - 40
end
# 光标位置在 [确定] 以外的情况下
else
# 按下方向键右的情况下
if Input.repeat?(Input::RIGHT)
# 按下状态不是重复的情况下、
# 光标位置不在右端的情况下
if Input.trigger?(Input::RIGHT) or
@index / 45 < 3 or @index % 5 < 4
# 光标向右移动
$game_system.se_play($data_system.cursor_se)
if @index % 5 < 4
@index += 1
else
@index += 45 - 4
end
if @index >= CHAR_PER_PAGE
@index -= CHAR_PER_PAGE
end
end
end
# 按下方向键左的情况下
if Input.repeat?(Input: EFT)
# 按下状态不是重复的情况下、
# 光标位置不在左端的情况下
if Input.trigger?(Input: EFT) or
@index / 45 > 0 or @index % 5 > 0
# 光标向右移动
$game_system.se_play($data_system.cursor_se)
if @index % 5 > 0
@index -= 1
else
@index -= 45 - 4
end
if @index < 0
@index += CHAR_PER_PAGE
end
end
end
# 按下方向键下的情况下
if Input.repeat?(Input: OWN)
# 光标向下移动
$game_system.se_play($data_system.cursor_se)
if @index % 45 < 40
@index += 5
else
@index += CHAR_PER_PAGE - 40
end
end
# 按下方向键上的情况下
if Input.repeat?(Input::UP)
# 按下状态不是重复的情况下、
# 光标位置不在上端的情况下
if Input.trigger?(Input::UP) or @index % 45 >= 5
# 光标向上移动
$game_system.se_play($data_system.cursor_se)
if @index % 45 >= 5
@index -= 5
else
@index += CHAR_PER_PAGE
end
end
end
#按下 L 键的情况
if Input.repeat?(Input: )
$game_system.se_play($data_system.cursor_se)
@index = 0
if @current_page > 0
@current_page -= 1
refresh
end
end
#按下 R 键的情况
if Input.repeat?(Input::R)
$game_system.se_play($data_system.cursor_se)
@index = 0
if @current_page < @page_count - 1
@current_page += 1
refresh
end
end
end
update_cursor_rect
end
end
[此贴子已经被作者于2005-1-30 21:40:30编辑过] |
|