Auteur: Yukihiro matsumoto
#============================================
# Window_InputNumber
#----------------------------------------------
# å`ɥڲʹä롢äΥɥǤ
#============================================
#Corrig par Bodom-Child
class Window_InputNumber < Window_Base
#------------------------------------------
# ֥ȳڻ
# digits_max :
#------------------------------------------
def initialize(digits_max)
@digits_max = digits_max
@number = 0
# ֤η饫`ηӋ (09 ϵȷȁ)
dummy_bitmap = Bitmap.new(32, 32)
@cursor_width = dummy_bitmap.text_size("0").width + 14
dummy_bitmap.dispose
super(0, 0, @cursor_width * @digits_max + 32, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.z += 9999
self.opacity = 0
@index = 0
refresh
update_cursor_rect
end
#------------------------------------------
# ȡ
#------------------------------------------
def number
return @number
end
#------------------------------------------
# O
# number : ¤
#------------------------------------------
def number=(number)
@number = [[number, 0].max, 10 ** @digits_max - 1].min
refresh
end
#------------------------------------------
# `ξθ
#------------------------------------------
def update_cursor_rect
self.cursor_rect.set(@index * @cursor_width, 0, @cursor_width, 32)
end
#------------------------------------------
# ե`
#------------------------------------------
def update
super
# ܥϤ¤Ѻ줿
if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
# Fڤλ֤ȡää 0 ˤ
place = 10 ** (@digits_max - 1 - @index)
n = @number / place % 10
@number -= n * place
# Ϥʤ +1¤ʤ -1
n = (n + 1) % 10 if Input.repeat?(Input::UP)
n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
# Fڤλ֤O
@number += n * place
refresh
end
# `
if Input.repeat?(Input::RIGHT)
if @digits_max >= 2
$game_system.se_play($data_system.cursor_se)
@index = (@index + 1) % @digits_max
end
end
# `
if Input.repeat?(Input::LEFT)
if @digits_max >= 2
$game_system.se_play($data_system.cursor_se)
@index = (@index + @digits_max - 1) % @digits_max
end
end
update_cursor_rect
end
#------------------------------------------
# եå
#------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
s = sprintf("%0*d", @digits_max, @number)
for i in 0...@digits_max
self.contents.draw_text(i * @cursor_width + 1, 0, 32, 32, s[i,1])
end
end
end |
|