Home > RGSS Script Reference > Window_DebugLeft
Window_DebugLeft
Inherits from: Window_Selectable
Description: The window shows groups of ten switches and variables that the user can choose. When the user chooses a group, the right-hand debug window shows the ten individual switches or variables for modification.
class Window_DebugLeft < Window_Selectable
# ------------------------------------
def initialize
super(0, 0, 192, 480)
self.index = 0
refresh
end
# ------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@switch_max = ($data_system.switches.size - 1 + 9) / 10
@variable_max = ($data_system.variables.size - 1 + 9) / 10
@item_max = @switch_max + @variable_max
self.contents = Bitmap.new(width - 32, @item_max * 32)
for i in 0...@switch_max
text = sprintf("S [%04d-%04d]", i*10+1, i*10+10)
self.contents.draw_text(4, i * 32, 152, 32, text)
end
for i in 0...@variable_max
text = sprintf("V [%04d-%04d]", i*10+1, i*10+10)
self.contents.draw_text(4, (@switch_max + i) * 32, 152, 32, text)
end
end
# ------------------------------------
def mode
if self.index < @switch_max
return 0
else
return 1
end
end
# ------------------------------------
def top_id
if self.index < @switch_max
return self.index * 10 + 1
else
return (self.index - @switch_max) * 10 + 1
end
end
end
|
Switch_Max: The number of groups of switches to show. The reason for the convoluted formula is that even though switches are numbered 1 - n for convenience, the switch array actually starts at index 0. The forumla accounts for this.
Variable_Max: The number of groups of variables to show.
Initialize
Arguments: None
Local Variables: None
How it Works: The method initializes the window. The x and y coordinates of the window are both set to 0. The width is set to 192, and the height is set to 480. The index is set at 0 (the top choice in the menu), and the window's contents are then drawn with the call to refresh.
Refresh
Arguments: None
Local Variables: None
How it Works: This method draws the contents of the window. Because this window can scroll, the contents are set to nil before proceeding. First, the values of @switch_max and @variable_max. In both cases, the values of these variables will be one for each ten or part of ten switches/variables. The value of @item_max (a property of Window_Selectable) is the sum or these two values. The bitmap is then declared, and the contents drawn. The first for loop draws the text for each group of switches. The sprintf statement prints a formatted string. The "%04d" means four integers will be printed, with leading zeros as necessary. For instance, for the first ten switches, the text = sprintf("S [%04d-%04d]", i*10+1, i*10+10) statement will print "S [0001 - 0010]". The same is then done for the variables.
Mode
Arguments: None
Local Variables: None
How it Works: This method determines whether the cursor is pointing at a group of switches or a group of variables. If the value of @index is less than @switch_max (the number of switch groups), then 0 is returned to the caller, meaning the cursor is pointing at a group of switches. Otherwise, 1 is returned to the caller, meaning that the cursor is pointing at a group of variables.
Top_ID
Arguments: None
Local Variables: None
How it Works: This method returns the number of the switch or variable that should appear at the top of the right-hand debug window. If the cursor is pointing at a group of switches, then the cursor index times ten, plus one, is returned (remember that the index of the first selection on the menu is 0). If the cursor is pointing at a group of variables, then the value of @switch_max is subtracted from the index before the calculation is done.
|
|