Home > RGSS Script Reference > Window_DebugRight
Window_DebugRight
Inherits from: Window_Selectable
Description: This window shows the ten individual switches or variables in the group that the user selects from the left debug window. Pressing Enter toggles a switch, and various variable operations can be carried out, also.
class Window_DebugRight < Window_Selectable
# ------------------------------------
attr_reader :mode
attr_reader :top_id
# ------------------------------------
def initialize
super(192, 0, 448, 352)
self.contents = Bitmap.new(width - 32, height - 32)
self.index = -1
self.active = false
@item_max = 10
@mode = 0
@top_id = 1
refresh
end
# ------------------------------------
def refresh
self.contents.clear
for i in 0..9
if @mode == 0
name = $data_system.switches[@top_id+i]
status = $game_switches[@top_id+i] ? "[ON]" : "[OFF]"
else
name = $data_system.variables[@top_id+i]
status = $game_variables[@top_id+i].to_s
end
if name == nil
name = ''
end
id_text = sprintf("%04d:", @top_id+i)
width = self.contents.text_size(id_text).width
self.contents.draw_text(4, i * 32, width, 32, id_text)
self.contents.draw_text(12 + width, i * 32, 296 - width, 32, name)
self.contents.draw_text(312, i * 32, 100, 32, status, 2)
end
end
# ------------------------------------
def mode=(mode)
if @mode != mode
@mode = mode
refresh
end
end
# ------------------------------------
def top_id=(id)
if @top_id != id
@top_id = id
refresh
end
end
end
|
Mode: This variable determines whether the window is showing a group of switches or variables (0 = Switches, 1 = Variables).
Top_ID: The number of the switch or variable that is the first item in the group.
Initialize
Arguments: None
Local Variables: None
How it Works: The method initializes the window. The x coordinate of the window is set to 192, the y coordinate of the window is set to 0, the width of the window is set to 448, and the height of the window is set to 352. The window's bitmap is then initialized. The rest of the method initializes the instance variables to dummy values. The values of @mode and @top_id are manipulated by the Scene_Debug class using the mode= and top_id= methods, explained below.
Refresh
Arguments: None
Local Variables:
ID_Text: The string representation of the ID number of the switch or variable.
Name: The name of the switch or variable.
Status: Either the string "ON" or "OFF" (for switches) or the string representation of the numerical value (for variables).
How it Works: This method draws the contents of the window.
After the window's current contents are cleared, the for loop draws the ten switches or variables and their values. Whether switches or variables are drawn depends on the value of the @mode instance variable. In either case, the value of the local variable name is set to the name of the switch or variable to show. If @mode is 0 (Switch mode), then the value of the local variable status is set to the string "ON" if the switch is on, or the string "OFF" if the switch is off. If @mode is 1 (Variable mode), then the value of status is set to the string representation of the variable's value. The last part of the method draws the text for the ID text, the name, and the status of the switch or variable. Notice that the statement self.contents.draw_text(312, i * 32, 100, 32, status, 2) contains the optional sixth argument "2", so the text is right-aligned within its bounding box.
Mode=
Arguments:
Mode: The new mode of the window.
Local Variables: None
How it Works: If the value passed to this method is different from the current mode of the window, then the mode is updated to this new value and the window is refreshed to reflect the change.
Top_ID=
Arguments:
ID: The new top ID of the window.
Local Variables: None
How it Works: If the number passed to this method is different from the number of the switch or variable that is currently the first item in the menu, then the top row value is changed and the window updated to reflect this change.
|
|