Window_InputNumber

Publié le par chindan

#============================================
# ¡ö Window_InputNumber
#----------------------------------------------
# ¡¡¥á¥Ã¥»©`¥¸¥¦¥£¥ó¥É¥¦¤ÎÄÚ²¿¤ÇʹÓ乤롢Êý‚ŽÈëÁ¦ÓäΥ¦¥£¥ó¥É¥¦¤Ç¤¹¡£
#============================================

#Corrig¨¦ par Bodom-Child

class Window_InputNumber < Window_Base
#------------------------------------------
# ¡ñ ¥ª¥Ö¥¸¥§¥¯¥È³õÆÚ»¯
# digits_max : èìÊý
#------------------------------------------
def initialize(digits_max)
@digits_max = digits_max
@number = 0
# Êý×֤ηù¤«¤é¥«©`¥½¥ë¤Î·ù¤òÓ‹Ëã (0¡«9 ¤ÏµÈ·ù¤È¢¶¨)
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
Publicité

Publié dans poubelle

Pour être informé des derniers articles, inscrivez vous :
Commenter cet article