Home > RGSS Script Reference > Window_Skill
Window_Skill
Inherits from: Window_Selectable
Description: This window lists the skills that an actor can use. This window is used both on the main menu and in battle.
class Window_Skill < Window_Selectable
# ------------------------------------
def initialize(actor)
super(0, 128, 640, 352)
@actor = actor
@column_max = 2
refresh
self.index = 0
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
# ------------------------------------
def skill
return @data[self.index]
end
# ------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 0...@actor.skills.size
@data.push($data_skills[@actor.skills[i]])
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
# ------------------------------------
def draw_item(index)
skill = @data[index]
if @actor.skill_can_use?(skill.id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(skill.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
end
# ------------------------------------
def update_help
@help_window.set_text(self.skill == nil ? "" : self.skill.description)
end
end
|
Actor: The actor who is using the skill selected from this window.
Data: An array containing the skills to be drawn. The contents of this array are determined in the refresh method.
Initialize
Arguments:
Actor: The actor who is using the skill selected from this window.
Local Variables: None
How it Works: This method initializes the window. The window's x coordinate is initialized to 0, the y coordinate is initialized to 128, the width to 640, and the height to 352. The value of @actor is initialized to the actor passed to this method. All the data is then drawn by the refresh method. If the party is in battle, the skill window must be made smaller, so the height is set to 256 in this case. The skill window is also partially transparent in battle, as opposed to completely opaque in the menu, so the back opacity is set to 160.
Skill
Arguments: None
Local Variables: None
How it Works: This method returns the skill in the @data array corresponding to the index of the currently selected skill.
Refresh
Arguments: None
Local Variables: None
How it Works: This method draws the contents of the skill window. First, the window disposes of its contents and constructs an entirely new bitmap, since the height of the bitmap is tailored to the number of skills to be displayed. The @data array is then initialized to an empty array. The @data array is constructed by adding every skill the actor knows to the array. The value of @item_max is now set to the size of the now-full @data array. The bitmap is created, and then the draw_item method is used to draw each individual skill on the menu.
Draw_Item
Arguments:
Index: The index of the skill to be drawn.
Local Variables: None
How it Works: This method draws an individual skill in the window. First, a determination about whether the actor whose skills are being displayed in this window can use the skill being drawn by this method. If the actor can use the skill, its name is drawn in the normal color. If not, the name is drawn in the disabled color. The next thing to do is acquire the coordinates at which the skill's name and icon should be drawn. If the skill's index is even, then the x coordinate at which the skill is drawn is 4. If the skill's index is odd, then x coordinate is 324. The y coordinate at which the skill is drawn is half the index (rounded down) multiplied by 32. The method then acquires the bitmap of the skill's icon. The skill's icon is then drawn in a 24x24 rectangle. The skill's name is drawn, followed by the skill's SP cost to the right of its name. Note that the optional argument "2" is present in the call draw_text for the SP cost. This means that the SP cost will be drawn right-aligned within its bounding box.
Update_Help
Arguments: None
Local Variables: None
How it Works: This method updates the help window with the description of the currently selected skill, or nil if an empty space is currently selected.
|
|