#==============================================================================
# Name Input Script v1.4
#--------------------------------------------------------------------------
# Script by BlueScope
#==============================================================================
class Window_NameEdit < Window_Base
#--------------------------------------------------------------------------
attr_reader :name
attr_reader :index
#--------------------------------------------------------------------------
def initialize(actor, max_char)
super(0, 128, 640, 160)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
@name = actor.name
@max_char = max_char
if @max_char < 9
self.x = 128
self.width = 384
end
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
@size = 0 # 0 for small sprites, 1 for bigger sprites
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
def restore_default
@name = @default_name
@index = @name.split(//).size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
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 - 16 * 14 + i * 28
self.contents.draw_text(x, 49, 28, 32, c, 1)
end
draw_actor_graphic(@actor, 56, @size == 0 ? 92 : 112)
end
#--------------------------------------------------------------------------
def update_cursor_rect
if @index < @max_char-1
self.cursor_rect.set((@max_char > 8 ? -128 : -16) + @max_char * 14 + @index * 28, 48, 28, 32)
else
self.cursor_rect.set((@max_char > 8 ? -128 : -16) + @max_char * 14 + (@max_char-1) * 28, 48, 28, 32)
end
end
#--------------------------------------------------------------------------
def update
super
update_cursor_rect
end
#--------------------------------------------------------------------------
end
class Window_NameHint < Window_Base
#--------------------------------------------------------------------------
def initialize
super(128, 288, 384, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 0
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, self.width-40, 32, "Please enter Hero Name using the Keyboard", 1)
end
#--------------------------------------------------------------------------
end
class Scene_Name
#--------------------------------------------------------------------------
def main
@actor = $game_actors[$game_temp.name_actor_id]
@edit_window = Window_NameEdit.new(@actor, $game_temp.name_max_char)
@hint_window = Window_NameHint.new
@dummy_window = Window_Base.new(128, 288, 384, 64)
if $game_temp.name_max_char > 8
@dummy_window.x = 0
@dummy_window.width = 640
end
Graphics.transition
loop do
Graphics.update
update
if $scene != self
break
end
end
Graphics.freeze
@edit_window.dispose
@hint_window.dispose
@dummy_window.dispose
end
#--------------------------------------------------------------------------
def change_name
@actor.name = @edit_window.name
$game_system.se_play($data_system.decision_se)
$scene = Scene_Map.new
if @edit_window.index == $game_temp.name_max_char
$game_system.se_play($data_system.buzzer_se)
return
end
end
#--------------------------------------------------------------------------
def input_processing
if @edit_window.index == $game_temp.name_max_char
$game_system.se_play($data_system.buzzer_se)
else
$game_system.se_play($data_system.cursor_se)
end
end
#--------------------------------------------------------------------------
def update
@edit_window.update
if Input.triggered?(27) # [ESCAPE]
$game_system.se_play($data_system.decision_se)
@edit_window.restore_default
return
end
if Input.triggered?(8) # [BACKSPACE]
if @edit_window.index == 0
return
end
$game_system.se_play($data_system.cancel_se)
@edit_window.back
return
end
if Input.triggered?(13) # [ENTER]
if @edit_window.name == ""
@edit_window.restore_default
return
end
change_name
end
if Input.triggered?(32) # [SPACE]
input_processing
@edit_window.add(" ")
end
for letter in 'A'..'Z'
if Input.triggered?(letter[0])
if Input.pressed?(16)
input_processing
@edit_window.add(letter.upcase)
else
input_processing
@edit_window.add(letter.downcase)
end
end
end
end
#--------------------------------------------------------------------------
end