Home > RGSS Script Reference > Window_PartyCommand
Window_PartyCommand
Inherits from: Window_Selectable
Description: This window shows the "Fight" and "Flee" options that appear at the beginning of each turn in battle.
class Window_PartyCommand < Window_Selectable
# ------------------------------------
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 160
@commands = ["Fight", "Flee"]
@item_max = 2
@column_max = 2
draw_item(0, normal_color)
draw_item(1, $game_temp.battle_can_escape ? normal_color : disabled_color)
self.active = false
self.visible = false
self.index = 0
end
# ------------------------------------
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(160 + index * 160 + 4, 0, 128 - 10, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
end
# ------------------------------------
def update_cursor_rect
self.cursor_rect.set(160 + index * 160, 0, 128, 32)
end
end
|
Commands: An array containing the two commands that are shown.
Initialize
Arguments: None
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. The width is set to 640 pixels, and the height to 64 pixels. Because this window appears in battle, its back opacity is set to 160 (translucent). The @commands array is then set to be ["Fight", "Flee"]. Because the items are to appear horizontally, both @item_max and @column_max are set to 2. Index 0 (Fight) is always drawn in the normal color. If the party can escape from this battle, then index 1 (Flee) is also drawn in the normal color. If the party can't escape, it is drawn in the disabled color. The window is then made inactive and invisible. Lastly, the window's contents are drawn with the refresh method.
Draw_Item
Arguments:
Index: The number of the index in @commands that will be drawn.
Color: The color in which the item will be drawn.
Local Variables: None
How it Works: This method draws one of the items in the party command window in the specified color. First, the font color is set to the color passed to this method. Next, the rectangle in which the command will be drawn is defined. The x coordinate is 160, plus 160 times the index of the command to be drawn, plus 4. The y coordinate is always 0. The width is always 118, and the height is always 32. The text is then drawn in the rectangle that was just defined. Notice that the optional alignment argument "1" is used in the self.contents.draw_text statement, meaning that the text will be centered within its rectangle.
Update_Cursor_Rect
Arguments: None
Local Variables: None
How it Works: This method updates the position of the cursor rectangle. If the index is 0 (Fight), the rectangle is drawn at (160,0). If the index is 1 (Flee), the rectangle is drawn at (320,0). In both cases, the width of the rectangle is 128 and the height is 32.
|
|