Home > RGSS Script Reference > Window_NameInput
Window_NameInput
Inherits from: Window_Base
Description: This window is the window where the player actually selects letters for the character's name.
Note: In the code below, the definition of the array constant containing all the characters that can be entered has been omitted.
class Window_NameInput < Window_Base
# ------------------------------------
[...]
# ------------------------------------
def initialize
super(0, 128, 640, 352)
self.contents = Bitmap.new(width - 32, height - 32)
@index = 0
refresh
update_cursor_rect
end
# ------------------------------------
def character
return CHARACTER_TABLE[@index]
end
# ------------------------------------
def refresh
self.contents.clear
for i in 0..179
x = 4 + i / 5 / 9 * 152 + i % 5 * 28
y = i / 5 % 9 * 32
self.contents.draw_text(x, y, 28, 32, CHARACTER_TABLE[i], 1)
end
self.contents.draw_text(544, 9 * 32, 64, 32, "Done", 1)
end
# ------------------------------------
def update_cursor_rect
if @index >= 180
self.cursor_rect.set(544, 9 * 32, 64, 32)
else
x = 4 + @index / 5 / 9 * 152 + @index % 5 * 28
y = @index / 5 % 9 * 32
self.cursor_rect.set(x, y, 28, 32)
end
end
# ------------------------------------
def update
super
if @index >= 180
if Input.trigger?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
@index -= 180
end
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@index -= 180 - 40
end
else
if Input.repeat?(Input::RIGHT)
if Input.trigger?(Input::RIGHT) or
@index / 45 < 3 or @index % 5 < 4
$game_system.se_play($data_system.cursor_se)
if @index % 5 < 4
@index += 1
else
@index += 45 - 4
end
if @index >= 180
@index -= 180
end
end
end
if Input.repeat?(Input::LEFT)
if Input.trigger?(Input::LEFT) or
@index / 45 > 0 or @index % 5 > 0
$game_system.se_play($data_system.cursor_se)
if @index % 5 > 0
@index -= 1
else
@index -= 45 - 4
end
if @index < 0
@index += 180
end
end
end
if Input.repeat?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
if @index % 45 < 40
@index += 5
else
@index += 180 - 40
end
end
if Input.repeat?(Input::UP)
if Input.trigger?(Input::UP) or @index % 45 >= 5
$game_system.se_play($data_system.cursor_se)
if @index % 45 >= 5
@index -= 5
else
@index += 180
end
end
end
if Input.repeat?(Input::L) or Input.repeat?(Input::R)
$game_system.se_play($data_system.cursor_se)
if @index / 45 < 2
@index += 90
else
@index -= 90
end
end
end
update_cursor_rect
end
end
|
This class has no properties
Initialize
Arguments: None
Local Variables: None
How it Works: This class initializes the window. First, the x coordinate of the upper-left pixel is set to 0, the y coordinate is set to 128, the width of the window is set to 640, and the height of the window is set to 352. The index is set to 0, the window's contents are drawn with the refresh method, and the cursor rectangle is updated.
Character
Arguments: None
Local Variables: None
How it Works: This method returns the character from the CHARACTER_TABLE array constant with the index equal to the index of the cursor selection.
Refresh
Arguments: None
Local Variables: None
How it Works: This method draws the contents of the window. The first thing this method does is clear the window's current contents. To be honest, I have no idea how they came up with the formulas for the x and y coordinates of each character, but the effect is that the characters will drawn in sets of five columns, with a slight break between each set.
Update_Cursor_Rect
Arguments: None
Local Variables: None
How it Works: This method updates the position of the cursor rectangle. If the cursor index is 180 or greater, then the cursor rectangle is positioned at (544, 288) and is 64 pixels wide and 32 pixels high. Otherwise, the same convulted formula as the one used to find the position at which to draw the characters is used to determine the cursor rectangle's coordinates. In this case, the rectangle is 28 pixels wide and 32 pixels high. The rectangle is longer in the first case because an index of 180 or greater means the cursor has selected the word "Done", which is wider than the individual characters.
Update
Arguments: None
Local Variables: None
How it Works: This method updates the window each frame and handles input to the window. First, the window calls the superclass method to perform updating common to all windows. The part of the if @index >= 180 clause before the else handles what happens when input is received when the cursor is selecting "Done". If the user has preseed the down arrow, then the cursor sound effect is played and the index is decreased by 180 (the practical effect of this is that the cursor will be pointing at a character near the upper-right corner of the window). If the user has pressed the up arrow, then the index is decreased by 140. The else part of the clause deals with what happens when input is received when the cursor has selected a letter. The rest of this method uses the same freaky formulas used throughout this class, so suffice it to say that in each input case, the cursor sound effect is played, and the cursor position is updated according to the input received.
|
|