Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



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.

Code


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

Properties


This class has no properties

Methods


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. 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal