Auteur: Yukihiro matsumoto
#============================================
# ¡ Window_NameEdit
#----------------------------------------------
# @–¼‘O“ü—͉æ–Ê‚ÅA–¼‘O‚ð•ÒW‚·‚éƒEƒBƒ“ƒhƒE‚Å‚·B
#============================================
class Window_NameEdit < Window_Base
#------------------------------------------
# œ ŒöŠJƒCƒ“ƒXƒ^ƒ“ƒX•Ï”
#------------------------------------------
attr_reader :name # –¼‘O
attr_reader :index # ƒJ[ƒƒ‹ˆÊ’u
#------------------------------------------
# œ ƒIƒuƒWƒFƒNƒg‰Šú‰»
# actor : ƒAƒNƒ^[
# max_char : ő啶Žš”
#------------------------------------------
def initialize(actor, max_char)
super(0, 0, 640, 128)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
@actor = actor
@name = actor.name
@max_char = max_char
# –¼‘O‚ðő啶Žš”ˆÈ“à‚ÉŽû‚ß‚é
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
#------------------------------------------
# œ ƒfƒtƒHƒ‹ƒg‚Ì–¼‘O‚É–ß‚·
#------------------------------------------
def restore_default
@name = @default_name
@index = @name.split(//).size
refresh
update_cursor_rect
end
#------------------------------------------
# œ •¶Žš‚̒ljÁ
# character : ’ljÁ‚·‚镶Žš
#------------------------------------------
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
#------------------------------------------
# œ ƒŠƒtƒŒƒbƒVƒ…
#------------------------------------------
def refresh
self.contents.clear
# –¼‘O‚ð•`‰æ
name_array = @name.split(//)
for i in 0...@max_char
c = name_array[i]
if c == nil
c = "Q"
end
x = 320 - @max_char * 14 + i * 28
self.contents.draw_text(x, 32, 28, 32, c, 1)
end
# ƒOƒ‰ƒtƒBƒbƒN‚ð•`‰æ
draw_actor_graphic(@actor, 320 - @max_char * 14 - 40, 80)
end
#------------------------------------------
# œ ƒJ[ƒƒ‹‚Ì‹éŒ`XV
#------------------------------------------
def update_cursor_rect
x = 320 - @max_char * 14 + @index * 28
self.cursor_rect.set(x, 32, 28, 32)
end
#------------------------------------------
# œ ƒtƒŒ[ƒ€XV
#------------------------------------------
def update
super
update_cursor_rect
end
end |
|