[php]#==============================================================================
# ** Texteingabe V2
# Texteingabe.rb von Caesar (09.09.2009)
#------------------------------------------------------------------------------
# http://www.rpg-studio.de/scriptdb/node/376
# http://www.rpg-studio.de/forum/index.php?page=Thread&threadID=8807
#==============================================================================
#/////////////////////////////////////////////Texteingabe V2////////////////////////////////////////////
#~~~~~~~~~~~~~~~~~~~~~~by Caesar~~~~~~~~~~~~~~~~~~~~~
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
class Window_InputNumber < Window_Base
# Der Schalter mit dieser ID bestimmt, ob ein Text (true) oder eine
# Zahl (false) eingegeben werden soll
SWITCH_ID = 1
# hier kann der Zeichenvorrat verändert werden
TEXT_ALPHABET = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
NUMBER_ALPHABET = "0123456789"
def initialize(chars_max)
@config = Array.new(chars_max, 0)
dummy_bitmap = Bitmap.new(32, 32)
@cursor_width = dummy_bitmap.text_size("0").width + 10
dummy_bitmap.dispose
super(0, 0, @cursor_width * chars_max + 64, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.z += 9999
self.opacity = 0
@index = 0
@alphabet = $game_switches[SWITCH_ID] ? TEXT_ALPHABET : NUMBER_ALPHABET
refresh
update_cursor_rect
end
#-----------------------
def number
return @config.collect{ |i| @alphabet
.chr }.join.strip if $game_switches[SWITCH_ID]
@config.collect{ |i| @alphabet[i].chr }.join.to_i
end
#-----------------------
def number=(number)
if $game_switches[SWITCH_ID] && number.is_a?(String) and number.length > 0
@config = number.split(//).collect {|chr| @alphabet.index(chr)}
elsif ( ! $game_switches[SWITCH_ID]) && number.is_a?(Integer)
@config = ("%0#{@config.length}d" % number).split(//).collect {|chr| chr.to_i }
end
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)
$game_system.se_play($data_system.cursor_se)
@config[@index] = (@config[@index] + 1) % @alphabet.size
refresh
end
if Input.repeat?(Input:
OWN)
$game_system.se_play($data_system.cursor_se)
@config[@index] = (@config[@index] + @alphabet.size-1) % @alphabet.size
refresh
end
if Input.repeat?(Input::RIGHT)
if @config.size >= 2
$game_system.se_play($data_system.cursor_se)
@index = (@index + 1) % @config.size
end
end
if Input.repeat?(Input::LEFT)
if @config.size >= 2
$game_system.se_play($data_system.cursor_se)
@index = (@index + @config.length - 1) % @config.length
end
end
update_cursor_rect
end
#-----------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
for i in 0...@config.size
self.contents.draw_text(i * @cursor_width + 4, 0, 24, 32, @alphabet[@config[i]].chr)
end
end
end[/php]