Help - Search - Members - Calendar
Full Version: [Scripting]Window_Selectable
RPG RPG Revolution Forums > Scripting > Script Tutorials > RGSS
onidsouza
Window_Selectable Part 1: The most simple

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

end

class Window_SomeStatus < Window_Base
  
  attr_accessor :item
  attr_accessor :item_list #Our especial variables
  
  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

end

class Window_SomeStatus < Window_Base
  
  attr_accessor :item
  attr_accessor :item_list #Our especial variables
  
  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
  
end



~The End~
breadlord
Part 2 allready, onidsuoza, you are amazing.

onidsouza
Doing part tree now, but i'm a little busy with my tests again.
onidsouza
It's complete now!
breadlord
Thank you onidisouza, I can now make selectable windows smile.gif .
Vascious
I'm confused what is this script used for exactly?
breadlord
This isn't a script to be used in your game, it's an example to help learning scripters (Like me XD).
onidsouza
QUOTE (Vascious @ Jun 2 2009, 02:45 AM) *
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.
onidsouza
*BUMP*
noahflash14
Wow! This is great oni. Nice tutorial and I hope you can make some more. I know it'll really help a lot people who wants to learn how to script.

Thanks for this tutorial and I wish you make some more.
Godbless!
onidsouza
Thanks!
I will think on making some more...
I'm with new ideas for RPG Maker. I created a better, independent NPC system, with Artificcial Intelligence (AI)
But still it has some bugs... But it's a very simple system, i'm going to publish it very soon.
Khev
Ótimo tuto! ohmy.gif

Really in need of some scripting lessons.. I'm done with eventing tongue.gif

I wanna get to that point in which you only open an event for graphics or "Call Script" functions biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.