All that I can do is create commented scripts, any questions you can ask me.
Call:
CODE
$scene = Scene_ChooseSome.new
script
CODE
#First, let's create our window.
class Window_ChooseSome < Window_Selectable #We inherited Window_Selectable because it has methods that let us to create #Selectable Items.
def initialize super(0, 0, 544, 416) #Super method. We call this method in every Window creation. self.index = 0 # Position of the cursor. self.active = true # The player can select something. end
def update super # Necessary in order to the window work. items = ["Cherry Pie", "Apple Pie", "Ultra Death Pie"] @data = items # The items that the player can select. @item_max = @data.size #Max number of selectable items. create_contents #Also necessary for it in 0...@data.size draw_opt(it) end # We create the options # And pass to draw_opt the index of the option end
def draw_opt(itemm) rect = item_rect(itemm) #We create a rectangle instance self.contents.clear_rect(rect) # We clear that rectangle string = @data[itemm] # We recover the text rect.width -= 4 self.contents.draw_text(rect.x, rect.y, rect.width, WLH, string) # We draw the text in the window end
end
# Now let's create the scene!
class Scene_ChooseSome < Scene_Base
def start @window = Window_ChooseSome.new # We create the Window end
def terminate @window.dispose # We show the window in the screen end
def update super @window.update # We update the window end
end
Window_Selectable Part 2: Commands, Index and Multi-Windows
Script 2
CODE
class Pie_Types
attr_reader :name, :description
def initialize(name, description) @name = name @description = description end
end
#First, let's create our window.
class Window_ChooseSome < Window_Selectable #We inherited Window_Selectable because it has methods that let us to create #Selectable Items.
attr_reader :items #We create the items method.
def initialize super(0, 0, 390, 416) #Super method. We call this method in every Window creation. self.index = 0 # Position of the cursor. self.active = true # The player can select something. @items = [Pie_Types.new("Cherry Pie", "A special pie"), Pie_Types.new("Apple Pie", "A tasty pie"), Pie_Types.new("Ultra Death Pie", "Dangerous")] end
def update super # Necessary in order to the window work. @data = @items # The items that the player can select. @item_max = @data.size #Max number of selectable items. create_contents #Also necessary for it in 0...@data.size draw_opt(it) end # We create the options # And pass to draw_opt the index of the option end
def draw_opt(itemm) rect = item_rect(itemm) #We create a rectangle instance self.contents.clear_rect(rect) # We clear that rectangle string = @data[itemm].name # We recover the pie name rect.width -= 4 self.contents.draw_text(rect.x, rect.y, rect.width, WLH, string) # We draw the pie name in the window end
def initialize(item_list) super(390, 0, 154, 416) # WE create the window @item_list = item_list # Create a list with the pie types @item = 0 # Index variable end
def refresh self.contents.clear draw_information end
def draw_information # We draw the description of the text self.contents.draw_text(0, 0, 140, WLH, @item_list[item].description) end
end
# Now let's create the scene!
class Scene_ChooseSome < Scene_Base
def start @window = Window_ChooseSome.new @status = Window_SomeStatus.new(@window.items) # We create the Window end
def terminate @window.dispose @status.dispose # We show the window in the screen end
def update super if Input.trigger?(Input::B) $scene = Scene_Map.new end # If the player presses Esc, we return to the map. @window.update @status.item = @window.index @status.refresh # We update the window end
end
Window_Selectable Part 3: Selecting Items
Script 3
CODE
class Pie_Types
attr_reader :name, :description
def initialize(name, description) @name = name @description = description end
end
#First, let's create our window.
class Window_ChooseSome < Window_Selectable #We inherited Window_Selectable because it has methods that let us to create #Selectable Items.
attr_reader :items #We create the items method.
def initialize super(0, 0, 390, 416) #Super method. We call this method in every Window creation. self.index = 0 # Position of the cursor. self.active = true # The player can select something. @items = [Pie_Types.new("Cherry Pie", "A special pie"), Pie_Types.new("Apple Pie", "A tasty pie"), Pie_Types.new("Ultra Death Pie", "Dangerous")] end
def update super # Necessary in order to the window work. @data = @items # The items that the player can select. @item_max = @data.size #Max number of selectable items. create_contents #Also necessary for it in 0...@data.size draw_opt(it) end # We create the options # And pass to draw_opt the index of the option end
def draw_opt(itemm) rect = item_rect(itemm) #We create a rectangle instance self.contents.clear_rect(rect) # We clear that rectangle string = @data[itemm].name # We recover the pie name rect.width -= 4 self.contents.draw_text(rect.x, rect.y, rect.width, WLH, string) # We draw the pie name in the window end
end
# We create our invisible window class Window_PieStatus < Window_Base
attr_accessor :pie
def initialize(pie) super(200, 150, 200, 200) self.visible = false # We make our window invisible @pie = pie end
def refresh self.contents.clear draw_information end
def draw_information self.contents.draw_text(0, 0, 200, WLH, @pie.name) self.contents.draw_text(0, WLH + 4, 200, WLH, @pie.description) # We draw the pie information end
def initialize(item_list) super(390, 0, 154, 416) # WE create the window @item_list = item_list # Create a list with the pie types @item = 0 # Index variable end
def refresh self.contents.clear draw_information end
def draw_information # We draw the description of the text self.contents.draw_text(0, 0, 140, WLH, @item_list[item].description) end
end
# Now let's create the scene!
class Scene_ChooseSome < Scene_Base
def start @window = Window_ChooseSome.new @status = Window_SomeStatus.new(@window.items) @pie = Window_PieStatus.new(@window.items[0]) # We create the Window end
def terminate @window.dispose @status.dispose @pie.dispose # We show the window in the screen end
def update super if Input.trigger?(Input::B) if @pie.visible @pie.visible = false @window.active = true else $scene = Scene_Map.new end end # If the player presses Esc, we return to the map. if Input.trigger?(Input::C) unless @pie.visible @window.active = false @pie.visible = true end end # If the player press enter, we draw the pie information @window.update @status.item = @window.index @status.refresh @pie.refresh @pie.pie = @window.items[@window.index] # We update the window end
I'm confused what is this script used for exactly?
This is a tutorial to how to create windows that you can select things, like the items window. I created three scripts that explain everything. The first only create the window, the second created commands and uses more than one window and the last one shows how to "select" things on your window, like when you select an item.