Home > RGSS Script Reference > Window_Base
Window_Base
Inherits from: Window
Description: This class is the main window class. All other window classes inherit from this class. This class contains methods you might want to call in a variety of windows. If you intend to add a method you will invoke in many windows throughout your game, you should add it to this class.
class Window_Base < Window
# ------------------------------------
def initialize(x, y, width, height)
super()
@windowskin_name = $game_system.windowskin_name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
self.x = x
self.y = y
self.width = width
self.height = height
self.z = 100
end
# ------------------------------------
def dispose
if self.contents != nil
self.contents.dispose
end
super
end
# ------------------------------------
def text_color(n)
case n
when 0
return Color.new(255, 255, 255, 255)
when 1
return Color.new(128, 128, 255, 255)
when 2
return Color.new(255, 128, 128, 255)
when 3
return Color.new(128, 255, 128, 255)
when 4
return Color.new(128, 255, 255, 255)
when 5
return Color.new(255, 128, 255, 255)
when 6
return Color.new(255, 255, 128, 255)
when 7
return Color.new(192, 192, 192, 255)
else
normal_color
end
end
# ------------------------------------
def normal_color
return Color.new(255, 255, 255, 255)
end
# ------------------------------------
def disabled_color
return Color.new(255, 255, 255, 128)
end
# ------------------------------------
def system_color
return Color.new(192, 224, 255, 255)
end
# ------------------------------------
def crisis_color
return Color.new(255, 255, 64, 255)
end
# ------------------------------------
def knockout_color
return Color.new(255, 64, 0)
end
# ------------------------------------
def update
super
if $game_system.windowskin_name != @windowskin_name
@windowskin_name = $game_system.windowskin_name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
end
end
# ------------------------------------
def draw_actor_graphic(actor, x, y)
bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
cw = bitmap.width / 4
ch = bitmap.height / 4
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
end
# ------------------------------------
def draw_actor_name(actor, x, y)
self.contents.font.color = normal_color
self.contents.draw_text(x, y, 120, 32, actor.name)
end
# ------------------------------------
def draw_actor_class(actor, x, y)
self.contents.font.color = normal_color
self.contents.draw_text(x, y, 236, 32, actor.class_name)
end
# ------------------------------------
def draw_actor_level(actor, x, y)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 32, 32, "Lv")
self.contents.font.color = normal_color
self.contents.draw_text(x + 32, y, 24, 32, actor.level.to_s, 2)
end
# ------------------------------------
def make_battler_state_text(battler, width, need_normal)
brackets_width = self.contents.text_size("[]").width
text = ""
for i in battler.states
if $data_states[i].rating >= 1
if text == ""
text = $data_states[i].name
else
new_text = text + "/" + $data_states[i].name
text_width = self.contents.text_size(new_text).width
if text_width > width - brackets_width
break
end
text = new_text
end
end
end
if text == ""
if need_normal
text = "[Normal]"
end
else
text = "[" + text + "]"
end
return text
end
# ------------------------------------
def draw_actor_state(actor, x, y, width = 112)
text = make_battler_state_text(actor, width, true)
self.contents.font.color = actor.hp == 0 ? knockout_color : normal_color
self.contents.draw_text(x, y, width, 32, text)
end
# ------------------------------------
def draw_actor_exp(actor, x, y)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 24, 32, "E")
self.contents.font.color = normal_color
self.contents.draw_text(x + 24, y, 84, 32, actor.exp_s, 2)
self.contents.draw_text(x + 108, y, 12, 32, "/", 1)
self.contents.draw_text(x + 120, y, 84, 32, actor.next_exp_s)
end
# ------------------------------------
def draw_actor_hp(actor, x, y, width = 144)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 32, 32, $data_system.words.hp)
if width - 32 >= 108
hp_x = x + width - 108
flag = true
elsif width - 32 >= 48
hp_x = x + width - 48
flag = false
end
self.contents.font.color = actor.hp == 0 ? knockout_color :
actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)
if flag
self.contents.font.color = normal_color
self.contents.draw_text(hp_x + 48, y, 12, 32, "/", 1)
self.contents.draw_text(hp_x + 60, y, 48, 32, actor.maxhp.to_s)
end
end
# ------------------------------------
def draw_actor_sp(actor, x, y, width = 144)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 32, 32, $data_system.words.sp)
if width - 32 >= 108
sp_x = x + width - 108
flag = true
elsif width - 32 >= 48
sp_x = x + width - 48
flag = false
end
self.contents.font.color = actor.sp == 0 ? knockout_color :
actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
self.contents.draw_text(sp_x, y, 48, 32, actor.sp.to_s, 2)
if flag
self.contents.font.color = normal_color
self.contents.draw_text(sp_x + 48, y, 12, 32, "/", 1)
self.contents.draw_text(sp_x + 60, y, 48, 32, actor.maxsp.to_s)
end
end
# ------------------------------------
def draw_actor_parameter(actor, x, y, type)
case type
when 0
parameter_name = $data_system.words.atk
parameter_value = actor.atk
when 1
parameter_name = $data_system.words.pdef
parameter_value = actor.pdef
when 2
parameter_name = $data_system.words.mdef
parameter_value = actor.mdef
when 3
parameter_name = $data_system.words.str
parameter_value = actor.str
when 4
parameter_name = $data_system.words.dex
parameter_value = actor.dex
when 5
parameter_name = $data_system.words.agi
parameter_value = actor.agi
when 6
parameter_name = $data_system.words.int
parameter_value = actor.int
end
self.contents.font.color = system_color
self.contents.draw_text(x, y, 120, 32, parameter_name)
self.contents.font.color = normal_color
self.contents.draw_text(x + 120, y, 36, 32, parameter_value.to_s, 2)
end
# ------------------------------------
def draw_item_name(item, x, y)
if item == nil
return
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.font.color = normal_color
self.contents.draw_text(x + 28, y, 212, 32, item.name)
end
end
|
Windowskin_Name: The filename of the window's window skin.
Initialize
Arguments:
X: The X coordinate of the upper-left pixel of the window.
Y: The Y coordinate of the upper-left pixel of the window.
Width: The width of the window.
Height: The height of the window.
Local Variables: None
How it Works: This method initializes the window coordinates, window skin, width, height, x coordinate, y coordinate, and z coordinate. The width, height, x coordinate, and y coordinate are acquired from the arguments passed to this method. The window skin is set to either the window skin defined in the "System" section of the database, or the last window skin to be set using the "Change Window Skin" event command. The z coordinate is set to 100 by default. Windows with higher z coordinates will appear on top of windows with lower z coordinates if they occupy the same space.
Dispose
Arguments: None
Local Variables: None
How it Works: This method diposes of the contents of the window if they are not nil, then calls Window#Dispose to dispose of the window itself.
Text_Color
Arguments:
n: The internal ID number of the color.
Local Variables: None
How it Works: This method returns a color to the caller. By default, only the Window_Message#Refresh method calls this method, but any window can call it to get these colors. The eight colors defined in the case statement are as follows:
0: White
1: Dark Blue
2: Reddish-Pink
3: Light Green
4: Light Blue
5: Purple
6: Yellow
7: Gray
Normal_Color
Arguments: None
Local Variables: None
How it Works: Returns the "normal" text color (white by default).
Disabled_Color
Arguments: None
Local Variables: None
How it Works: Returns the color for disabled menu items (a white translucent color by default).
System_Color
Arguments: None
Local Variables: None
How it Works: Returns the color for the "system" text, used when drawing system words like "HP", "SP", "Play Time", etc. By default, this is a medium-blue color.
Crisis_Color
Arguments: None
Local Variables: None
How it Works: Returns the "crisis" color that is used to draw a character's HP or SP when it is low. This is a yellow color by default.
Knockout_Color
Arguments: None
Local Variables: None
How it Works: Returns the "knockout" color that is used to draw a character's HP or SP when it is zero. This color is red by default.
Update
Arguments: None
Local Variables: None
How it Works: This method calls Window#Update to perform the updating common to all window classes. Then, it checks to see if the current window skin has changed. If it has, then the value of @windowskin is updated and the window skin graphic is updated.
Draw_Actor_Graphic
Arguments:
Actor: The actor whose graphics will be drawn.
X: The X coordinate of the upper-left pixel of the bitmap rectangle.
Y: The Y coordinate of the upper-left pixel of the bitmap rectangle.
Local Variables: None
How it Works: This method draws the sprite you see next to each character's status on the menu screen. It first acquires the filename and the hue modification for that character's sprite. Since the file that has been acquired holds all of the character's walking graphics, the next three statements are necessary to restrict the view to the the first frame of the character's down-facing walk graphics. The self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect) statement then shows the character's image. Note that cw is divided by 2 in order to center the character within the bitmap and src_rect restricts the view to that one frame of animation.
Draw_Actor_Name
Arguments:
Actor: The actor whose name will be drawn.
X: The X coordinate of the upper-left pixel of the text rectangle.
Y: The Y coordinate of the upper-left pixel of the text rectangle.
Local Variables: None
How it Works: This method draws the name of the actor passed to this method in the normal text color at the X and Y coordinates passed to this method. By default, the allowed width of the name is 120 pixels and the allowed height is 32 pixels.
Draw_Actor_Class
Arguments:
Actor: The actor whose class will be drawn.
X: The X coordinate of the upper-left pixel of the text rectangle.
Y: The Y coordinate of the upper-left pixel of the text rectangle.
Local Variables: None
How it Works: This method draws the class of the actor passed to this method in the normal text color at the X and Y coordinates passed to this method. By default, the allowed width of the class is 236 pixels and the allowed height is 32 pixels.
Draw_Actor_Level
Arguments:
Actor: The actor whose level will be drawn.
X: The X coordinate of the upper-left pixel of the text rectangle.
Y: The Y coordinate of the upper-left pixel of the text rectangle.
Local Variables: None
How it Works: This method draws the level of the actor passed to this method. The method first draws the string "Lv" in the system color at the x and y coordinates passed to this method. It then draws the numerical value associated with the character's level at the x coordinate passed to this method, plus 32, and the y coordinate passed to this method. By default the allowed width for the number is 24 pixels and the allowed height is 32 pixels.
Make_Battler_State_Text
Arguments:
Battler: The battler whose status text will be drawn.
Width: The width of the status text rectangle..
Need_Normal: If this flag is set, then the battler's state is reset to normal.
Local Variables:
Text: The value that is used in the process of building the battler's status text. This is returned to the draw_actor_state method.
How it Works: This method creates the text string for a battler's status ailments in order to return it to the draw_actor_state method. The first thing to be done is determine the width of the characters "[" and "]" for the current font, since by default, the status text is surrounded by brackets. The text string itself is set to a null string to begin. The main for loop in this method iterates through each of the battler's status ailments. For the first status ailment, the value of text is set to the status ailments's name. For the second and subsequent status ailment, the string "/" plus the status ailment's name is added to the text string. For each status ailment, the width is checked to see if the total width of the string plus the width of the brackets exceeds the alloted width. If it does, then the method breaks out of the loop, possibly not showing some status ailments. If the loop returns a null string and the need_normal flag is set, then the string that will be returned is "[Normal]". Otherwise, the string that is returned is "[", plus the string formed in the loop above, plus "]".
Draw_Actor_State
Arguments:
Actor: The actor whose status text will be drawn.
X: The X coordinate of the upper-left pixel of the text rectangle.
Y: The Y coordinate of the upper-left pixel of the text rectangle.
Width: The width of the text rectangle.
Local Variables:
Text: The status text to draw.
How it Works: This method draws an actor's status ailment text. The value of text is loaded with all the actor's current status ailments by calling make_battler_state_text (see directly above for documentation). The self.contents.font.color = actor.hp == 0 ? knockout_color : normal_color statement means that if the actor's HP is 0, then the text should be drawn in the "knockout color". Otherwise, it should be drawn in the normal color. The status ailment text is then drawn at the x and y coordinates passed to this method. By default, the allowed space for the text is 112 pixels, but this can be overridden by passing a third argument to this method when it is called.
Draw_Actor_Exp
Arguments:
Actor: The actor whose experience points will be drawn.
X: The X coordinate of the upper-left pixel of the text rectangle.
Y: The Y coordinate of the upper-left pixel of the text rectangle.
Local Variables: None
How it Works: This method draws the experience points of the actor passed to this method. The method first draws the string "E" in the system color at the x and y coordinates passed to this method. It then draws the numerical value associated with the character's current experience points at the x coordinate passed to this method, plus 24, and the Y coordinate passed to this method. It then draws the string "/" at the x coordinate passed to this method, plus 108, and the Y coordinate passed to this method. Finally, it draws the numerical value associated with the amount of experience points the character needs to reach the next level at the x coordinate passed to this method, plus 120, and the Y coordinate passed to this method. For the two numbers, the allowed width is 84 pixels. For all the strings, the allowed height is 32 pixels.
Draw_Actor_HP
Arguments:
Actor: The actor whose HP will be drawn.
X: The X coordinate of the upper-left pixel of the text rectangle.
Y: The Y coordinate of the upper-left pixel of the text rectangle.
Width: The width of the text rectangle.
Local Variables:
Flag: This flag determines whether or not the actor's maximum HP will be drawn in addition to its current HP.
How it Works: This method draws the actor's HP. First, the method draws the system string for "HP" in the system color at the x and y coordinates passed to the method. The if width - 32 >= 108 clause is there to determine at what x coordinate the current HP value should be shown, as well as whether the allowed space is wide enough to show the maximum HP value. If the width is 144 or greater, then the current HP will be shown (width - 108) pixels away from the "HP" system word, and flag is set to true, meaning that the maximum HP value will be shown. If the width is 143 or less, then the current HP will be shown (width - 48) pixels away from the "HP" system word and flag is set to false, meaning that the maximum HP value will not be shown. Next, the method determines in what color to show the current HP value. If the actor has 26%-100% of its HP remaining, the text is shown in the normal color. If the actor has between 1 HP and 25% of its maximum HP remaining, the text is shown in the crisis color. If the actor's HP is 0, then the text is shown in the knockout color. The text is shown at the x coordinate determined above. If the maximum HP flag is set, then the string "/" and the maximum HP are shown in the normal color starting 48 pixels away from the current HP value.
Draw_Actor_SP
Arguments:
Actor: The actor whose SP will be drawn.
X: The X coordinate of the upper-left pixel of the text rectangle.
Y: The Y coordinate of the upper-left pixel of the text rectangle.
Width: The width of the text rectangle.
Local Variables:
Flag: This flag determines whether or not the actor's maximum SP will be drawn in addition to its current SP.
How it Works: This method draws the actor's SP. First, the method draws the system string for "SP" in the system color at the x and y coordinates passed to the method. The if width - 32 >= 108 clause is there to determine at what x coordinate the current SP value should be shown, as well as whether the allowed space is wide enough to show the maximum SP value. If the width is 144 or greater, then the current SP will be shown (width - 108) pixels away from the "SP" system word, and flag is set to true, meaning that the maximum SP value will be shown. If the width is 143 or less, then the current SP will be shown (width - 48) pixels away from the "SP" system word and flag is set to false, meaning that the maximum SP value will not be shown. Next, the method determines in what color to show the current SP value. If the actor has 26%-100% of its SP remaining, the text is shown in the normal color. If the actor has between 1 SP and 25% of its maximum SP remaining, the text is shown in the crisis color. If the actor's SP is 0, then the text is shown in the knockout color. The text is shown at the x coordinate determined above. If the maximum SP flag is set, then the string "/" and the maximum SP are shown in the normal color starting 48 pixels away from the current SP value.
Draw_Actor_Parameter
Arguments:
Actor: The actor whose parameters will be drawn.
X: The X coordinate of the upper-left pixel of the text rectangle.
Y: The Y coordinate of the upper-left pixel of the text rectangle.
Type: Which parameter to draw (0 = Attack Power, 1 = Physical Defense, 2 = Magical Defense, 3 = Strength, 4 = Dexterity, 5 = Agility, 6 = Intelligence)
Local Variables: None
How it Works: This method draws one of the parameters of the of the actor passed to this method according to the value of the type argument. The method first draws the name of the parameter in the system color at the x and y coordinates passed to this method. It then draws the numerical value associated with that paramter at the x coordinate passed to this method, plus 120, and the Y coordinate passed to this method. For the paramter, the allowed width is 120 pixels. For the number, the allowed width is 36 pixels. For all the strings, the allowed height is 32 pixels.
Draw_Item_Name
Arguments:
Item: The item that will be drawn.
X: The X coordinate of the upper-left pixel of the bitmap rectangle.
Y: The Y coordinate of the upper-left pixel of the bitmap rectangle.
Local Variables:
Bitmap: The bitmap of the item icon.
How it Works: This method draws an item icon, followed by its name. This method is used in the item and equip menus. If the value of item is nil, then the method does nothing and returns. If the item exists, then the value of bitmap is set to the item's icon name (note that item could be a RPG::Item, RPG::Weapon, or RPG::Armor, but they all have an icon name, so the method doesn't care). The icon bitmap is then shown at the x coordinate passed to the method, and y coordinate passed to the method, plus 4. The item's name is then drawn in the normal color at the x coordinate passed to the method, plus 28, and y coordinate passed to the method.
|
|