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
breadlord
post May 29 2009, 01:36 PM
Post #2


What did you expect...
Group Icon

Group: Revolutionary
Posts: 461
Type: Developer
RM Skill: Intermediate




Part 2 allready, onidsuoza, you are amazing.



__________________________

Check out my project http://www.rpgrevolution.com/forums/index....showtopic=29698
[Show/Hide] I thought my sig was to big so... Clicky clicky


[Show/Hide] My RRR card, Thanks Holder!!




[Show/Hide] What things am I, CLICK!!!

I taste a bit like Almonds.


Mmm, the taste of almonds - anathema to many with nut allergies, and a bad sign for many more, as my taste is not unlike that of cyanide. Am I good or am I poison? A risky thing to guess about. What Flavour Are You?



What Mystical creature are you?
Pegasus



You are a shy, night time person and you are very gentle and soft hearted. You are like the opposite from your cousin the unicorn.


Which Final Fantasy Character Are You?
Final Fantasy 7


[Show/Hide] Can you read this?
Cna yuo raed tihs? Olny 55% of plepoe can.
I cdnuolt blveiee taht I cluod aulaclty uesdnatnrd waht I was rdanieg. The phaonmneal pweor of the hmuan mnid, aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it dseno't mtaetr in waht oerdr the ltteres in a wrod are, the olny iproamtnt tihng is taht the frsit and lsat ltteer be in the rghit pclae. The rset can be a taotl mses and you can sitll raed it whotuit a pboerlm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Azanmig huh? yaeh and I awlyas tghuhot slpeling was ipmorantt!
fi yuo cna raed tihs, palce it in yuor siantugre.


[Show/Hide] Personality things




Your answers suggest you are a Strategist

The four aspects that make up this personality type are:



Summary of Strategists

* Quiet, easy-going and intellectually curious
* Use logical, objective thinking to find original solutions to problems
* Think of themselves as bright, logical and individualistic
* May be impractical, forgetting practical issues, such as paying bills or doing the shopping

More about Strategists

Strategists are quiet people who like to get to the heart of tough problems on their own and come up with innovative solutions. They analyse situations with a sceptical eye and develop ways of measuring everything, including themselves.

Strategists are the group most likely to say they are unhappy in their job, according to a UK survey.

Strategists are generally easy-going. They are intellectually curious and enjoy abstract ideas. Sometimes they like thinking of a solution to a problem more than taking practical steps to solve it.

In situations where they can't use their talents, are unappreciated, or not taken seriously, Strategists may become negatively critical or sarcastic. Under extreme stress, Strategists could be prone to inappropriate, tearful or angry outbursts.

Strategists may be insensitive to the emotional needs of others or how their behaviour impacts the people around them.


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: 25th May 2013 - 05:23 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker