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

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Window_Command

Window_Command


Inherits from: Window_Selectable

Description: This window shows one column of commands. Unlike other classes that inherit from Window_Selectable, it is designed to be flexible, allowing a good-looking window to be easily constructed for any situation where you might want to prompt the user to select from between 2 and 8 static commands.

Code


class Window_Command < Window_Selectable
# ------------------------------------
def initialize(width, commands)
    super(0, 0, width, commands.size * 32 + 32)
    @item_max = commands.size
    @commands = commands
    self.contents = Bitmap.new(width - 32, @item_max * 32)
    refresh
    self.index = 0
  end
# ------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
# ------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end
# ------------------------------------
  def disable_item(index)
    draw_item(index, disabled_color)
  end
end

Properties


Commands: An array of strings representing the commands from which the user can select.

Methods


Initialize

Arguments:
Width: The width of the command window, in pixels.
Commands: An array of strings representing the commands from which the user can select.
Local Variables: None

How it Works: This method initializes the window. The x and y coordinates of the upper-left pixel of the window are both set at 0, though in most cases these will be changed by the class manipulating this object. The width is set according to the first argument passed to this method, and the height is set to 32 pixels, plus an additional 32 pixels for each command in the array passed as the second argument to this method. The item max of the window is set to the number of commands in the array passed to this method, and the @commands array is set equal to the second argument to this method. The index is then set to 0, so the cursor will appear at the top of the command window.

Refresh

Arguments: None
Local Variables: None

How it Works: This method draws the contents of the window. Like most other Refresh methods, the first thing this method does is clear the window's current contents. For each item in the array of strings in @commands, the method calls the draw_item method with that index and the normal text color. Note that this method can't draw any items disabled. This must be done seperately within the class that is manipulating this object.

Draw_Item

Arguments:
Index: The index of the item to be drawn.
Color: A Color object representing the text color of the item to be drawn.
Local Variables: None

How it Works: This method draws an individual command within the command window. The first thing the method does is set the font color to the color passed to the method. It then determines the drawing rectangle that will be used to place the command within the window. The x coordinate of the drawing rectangle is always 4. The y coordinate depends on the index of the command being drawn. For index zero, the y coordinate is 0. For every index above zero, the y coordinate is increased by 32. The width of the drawing rectangle is the width of the window bitmap, minus 8 pixels. The height of the drawing rectangle is always 32 pixels. I'm not particularly certain of the reason for the self.contents.fill_rect(rect, Color.new(0, 0, 0, 0)) statement, as it simply fills the bitmap with an invisible color. The final command draws the text of the command at the array index of @commands passed to this method using the rectangle defined above.

Disable_Item

Arguments:
Index: The index of the item to be disabled.
Local Variables: None

How it Works: This method is a shortcut for saying "draw_item(index, Color.new(255, 255, 255, 128)" (or whatever color you've set the to be the disabled color). 
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