Home > RGSS Script Reference > Window_BattleResult
Window_BattleResult
Inherits from: Window_Base
Description: This is the class for the window that appears when you win a battle. It shows the amount of experience points and money obtained, as well as any items the enemy dropped.
class Window_BattleResult < Window_Base
# ------------------------------------
def initialize(exp, gold, treasures)
@exp = exp
@gold = gold
@treasures = treasures
super(160, 0, 320, @treasures.size * 32 + 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.y = 160 - height / 2
self.back_opacity = 160
self.visible = false
refresh
end
# ------------------------------------
def refresh
self.contents.clear
x = 4
self.contents.font.color = normal_color
cx = contents.text_size(@exp.to_s).width
self.contents.draw_text(x, 0, cx, 32, @exp.to_s)
x += cx + 4
self.contents.font.color = system_color
cx = contents.text_size("EXP").width
self.contents.draw_text(x, 0, 64, 32, "EXP")
x += cx + 16
self.contents.font.color = normal_color
cx = contents.text_size(@gold.to_s).width
self.contents.draw_text(x, 0, cx, 32, @gold.to_s)
x += cx + 4
self.contents.font.color = system_color
self.contents.draw_text(x, 0, 128, 32, $data_system.words.gold)
y = 32
for item in @treasures
draw_item_name(item, 4, y)
y += 32
end
end
end
|
Exp: The experience point value to show in the window.
Gold: The money value to show in the window.
Treasures: An array representing the items dropped by the enemy.
Initialize
Arguments:
Exp: The experience point value to show in the window.
Gold: The money value to show in the window.
Treasures: An array representing the items dropped by the enemy.
Local Variables: None
How it Works: This method initializes the window's state. The @experience, @gold, and @treasures instances variables are set to the values passed to this method. The super(160, 0, 320, @treasures.size * 32 + 64) statement sets the width of the window at 320 pixels, and the height of the window at 64, plus 32 for each item the monsters dropped. The Y coordinate of the window is then set to 160 minus half the height of the window.
Refresh
Arguments: None
Local Variables: None
How it Works: This method draws the window contents. First, all contents are cleared from the window. The experience point value and money value are drawn on one line. For all four strings on the first line, the y coordinate is 0. The first thing drawn is the number of experience points earned. This is drawn at x coordinate 4. Next, the x coordinate is moved to the right by 4 plus how wide the experience value string is, in pixels. The string "EXP" is drawn in the system color at the new x coordinate. The x coordinate is again moved to the right by 16 plus the width of the string "EXP" in the current font, in pixels. At that new x coordinate, the amount of money gained is drawn. The x coordinate is moved to the right one last time by 4 pixels plus the width of the money value in the current font, in pixels. At this new x coordinate, the system string for "money" is drawn in the system color. The y coordinate is then set to 32. For each treasure in the array, the Window_Base#draw_item_name method is called to draw the item's icon and name at x coordinate 4 and the current y coordinate, which is increased by 32 for each item drawn.
|
|