Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> [Scripting]Window_Selectable, Advanced Windowing, Fully Complete!
onidsouza
post May 29 2009, 10:52 AM
Post #1


image master of doom
Group Icon

Group: Revolutionary
Posts: 603
Type: None
RM Skill: Undisclosed




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~


__________________________
Gabba Gabba Hey! enjoy your life ^^
lol (by keet's brother)
some lol
more lol
even MORE lol
Serious Discussion
why all my lol's have Teh Parakeet involved?

me ^^

bacon

Spamming is always better with bacon
Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies
onidsouza
post Jun 1 2009, 03:36 AM
Post #2


image master of doom
Group Icon

Group: Revolutionary
Posts: 603
Type: None
RM Skill: Undisclosed




Doing part tree now, but i'm a little busy with my tests again.


__________________________
Gabba Gabba Hey! enjoy your life ^^
lol (by keet's brother)
some lol
more lol
even MORE lol
Serious Discussion
why all my lol's have Teh Parakeet involved?

me ^^

bacon

Spamming is always better with bacon
Go to the top of the page
 
+Quote Post
   



Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 21st May 2013 - 01:35 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker