Advertisement
Zeriab

Bestiary (Questbook conversion)

Mar 12th, 2013
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 39.29 KB | None | 0 0
  1. #==============================================================================
  2. # * Window_Base
  3. #------------------------------------------------------------------------------
  4. #  Defines the draw_bestiary_icon method in Window_Base
  5. #==============================================================================
  6.  
  7. class Window_Base
  8.   #--------------------------------------------------------------------------
  9.   # * Draw Bestiary Icon
  10.   #     icon_name : filename of the icon
  11.   #     x         : draw spot x-coordinate
  12.   #     y         : draw spot y-coordinate
  13.   #--------------------------------------------------------------------------
  14.   def draw_bestiary_icon(icon_name, x, y)
  15.     begin
  16.       bitmap = RPG::Cache.picture(icon_name)
  17.     rescue
  18.       bitmap = RPG::Cache.picture(Data_Bestiary::PATH + Data_Bestiary::DEFAULT_ICON)
  19.     end
  20.     cw = 80
  21.     ch = 80
  22.     src_rect = Rect.new(0, 0, cw, ch)
  23.     self.contents.blt(x, y, bitmap, src_rect)
  24.   end # def
  25.  
  26. end # class
  27.  
  28. #==============================================================================
  29. # ** Data_Bestiary
  30. #------------------------------------------------------------------------------
  31. #  A bestiary object.
  32. #  Stores information about the particular bestiary.
  33. #  All icons are assumed to be stored in the same directory
  34. #==============================================================================
  35.  
  36. class Data_Bestiary
  37.   # The path in the pictures folder
  38.   PATH = "Bestiary/Icons/"
  39.   # The name of the default icon
  40.   DEFAULT_ICON = "default_icon.png"
  41.  
  42.   # The following are of the String class.
  43.   attr_reader   :owner          # Who
  44.   attr_reader   :location       # Where
  45.   attr_reader   :goal           # What
  46.   attr_reader   :info           # details
  47.  
  48.   #--------------------------------------------------------------------------
  49.   # * Object Initialization
  50.   #--------------------------------------------------------------------------
  51.   def initialize
  52.     @owner = ""
  53.     @location = ""
  54.     @goal = ""
  55.     @info = ""
  56.     @icon = DEFAULT_ICON
  57.   end # def
  58.  
  59.   #--------------------------------------------------------------------------
  60.   # * Gets the name and location of the icon in the picture folder
  61.   #--------------------------------------------------------------------------
  62.   def get_icon
  63.     return PATH + @icon
  64.   end # def
  65.  
  66.   #--------------------------------------------------------------------------
  67.   # * Set Owner
  68.   #     string : A string containing the owner
  69.   #--------------------------------------------------------------------------
  70.   def owner=(string)
  71.     if string.is_a?(String)
  72.       @owner = string
  73.     end # if
  74.   end # def
  75.  
  76.   #--------------------------------------------------------------------------
  77.   # * Set Location
  78.   #     string : A string containing the location
  79.   #--------------------------------------------------------------------------
  80.   def location=(string)
  81.     if string.is_a?(String)
  82.       @location = string
  83.     end # if
  84.   end # def
  85.  
  86.   #--------------------------------------------------------------------------
  87.   # * Set Goal
  88.   #     string : A string containing the goal
  89.   #--------------------------------------------------------------------------
  90.   def goal=(string)
  91.     if string.is_a?(String)
  92.       @goal = string
  93.     end # if
  94.   end # def
  95.  
  96.   #--------------------------------------------------------------------------
  97.   # * Set Info
  98.   #     string : A string containing the information
  99.   #--------------------------------------------------------------------------
  100.   def info=(string)
  101.     if string.is_a?(String)
  102.       @info = string
  103.     end # if
  104.   end # def
  105.  
  106.   #--------------------------------------------------------------------------
  107.   # * Set Info
  108.   #     string : A string containing the filename of the icon
  109.   #              No change is done if the file does not exists
  110.   #--------------------------------------------------------------------------
  111.   def icon=(string)
  112.     if string.is_a?(String)
  113.       @icon = string
  114.     end # if
  115.   end # def
  116. end # class
  117.  
  118. #==============================================================================
  119. # ** Bestiary_Criteria
  120. #------------------------------------------------------------------------------
  121. #  This class simple gets a criteria and tells if it is fulfilled or not.
  122. #  Used in Game_Bestiary to determine how much the bestiary has progressed
  123. #
  124. #  Variable condition:
  125. #  ["variable", variable_number, condition, number]
  126. #  -------------------
  127. #  The "variable" just tells the script that you want to check a variable
  128. #  The variable_number is the number on the variable you want to use.
  129. #  Condition is which condition you want to check.
  130. #    "<" - less than
  131. #    "<=" - less than or equal   ("=<" will give you an error)
  132. #    "==" - equal  ("=" is converted to "==")
  133. #    ">=" - greater than or equal   ("=>" will give you an error)
  134. #    ">" - greater than
  135. #    "!=" - not equal
  136. #  The number is the number you want to check with.
  137. #  For example:
  138. #  ["variable", 4, ">", 3] - Variable number 4 must be bigger than 3
  139. #  ["variable", 2, "==", 5] - Variable number 2 must be equal 5
  140. #
  141. #
  142. #  Switch Condition:
  143. #  ["switch", switch_number, state]
  144. #  -------------------------------------
  145. #  The "switch" just tells the script that you want to check a switch
  146. #  The switch_number is the number on the switch you want to use.
  147. #  The state is what the state of the switch should be for the conditions to
  148. #  be fulfilled. Write 'true' if the switch must be ON and 'false' if the
  149. #  switch must be OFF
  150. #
  151. #  For example:
  152. #  ["switch", 7, true] - Switch number 7 must be true
  153. #  ["switch", 3, false] - Switch number 3 must be false
  154. #
  155. #
  156. #  Use the 'check' method to see if all conditions are met. If they are then
  157. #  'true' will be returned, otherwise 'false'
  158. #==============================================================================
  159.  
  160. class Bestiary_Criteria
  161.   #--------------------------------------------------------------------------
  162.   # * Object Initialization
  163.   #--------------------------------------------------------------------------
  164.   def initialize(*args)
  165.     # Each argument is considered as a condition and is stored in @conditions
  166.     @conditions = args
  167.   end # def
  168.  
  169.   #--------------------------------------------------------------------------
  170.   # * Checks the conditions. Returns true if all the conditions are met
  171.   #--------------------------------------------------------------------------
  172.   def check
  173.     # Goes through the conditions
  174.     for condition in @conditions
  175.       # Creates a begin-rescue block to catch errors.
  176.       begin
  177.         break   if !condition.is_a?(Array) && !condition[0].is_a?(String)
  178.         case condition[0].downcase   # The first field in the array
  179.         when "variable"
  180.           # Converts '=' into '==' to avoid changing the variable
  181.           condition[2] = "=="   if condition[2] == "="
  182.           command = "$game_variables[#{condition[1]}] #{condition[2]} " +
  183.                     "#{condition[3]}"
  184.           return false    unless eval(command)
  185.         when "switch"
  186.           return false    unless $game_switches[condition[1]] == condition[2]
  187.         end
  188.       rescue Exception => err
  189.         # Prints an error message if and only if $DEBUG is true
  190.         # The erroneous condition is considered to be "true"
  191.         if $DEBUG
  192.           output = "Bestiary_Criteria:Check\n\n"+ err.type.to_s + "\n" +
  193.                    err.to_s + "\n\n" + "Backtrace(10):\n\n" +
  194.                    err.backtrace[0...10].join("\n").to_s
  195.           print output
  196.         end
  197.       end # begin
  198.     end # for
  199.     # Returns true if no condition is false.
  200.     return true
  201.   end # def
  202. end # class
  203.  
  204. #==============================================================================
  205. # ** Game_Bestiary
  206. #------------------------------------------------------------------------------
  207. #  Manages the process in the bestiaries.
  208. #==============================================================================
  209.  
  210. class Game_Bestiary
  211.   attr_reader :completed
  212.   attr_reader :active
  213.   attr_reader :current_bestiary
  214.   #--------------------------------------------------------------------------
  215.   # * Object Initialization
  216.   #     bestiary : Must be a Data_Bestiary
  217.   #--------------------------------------------------------------------------
  218.   def initialize
  219.     @data = []
  220.     # Completed bestiary
  221.     @completed_bestiary = []
  222.     # A bestiary is not completed in the start
  223.     @completed = false
  224.     # Neither is it active
  225.     @active = false
  226.     # Updates
  227.     update
  228.   end # def
  229.  
  230.   #--------------------------------------------------------------------------
  231.   # * Resets the bestiary
  232.   #--------------------------------------------------------------------------
  233.   def reset
  234.     # Remove the current bestiary
  235.     @current_bestiary = nil
  236.     # A bestiary is not completed in the start
  237.     @completed = false
  238.     # Neither is it active
  239.     @active = false
  240.     # Updates
  241.     update
  242.   end # def
  243.  
  244.   #--------------------------------------------------------------------------
  245.   # * Updates the current_bestiary
  246.   #--------------------------------------------------------------------------
  247.   def update
  248.     # Return if the bestiary have completed
  249.     @completed = false
  250.     #------------------------------------------------------------------------
  251.     # Checks if the bestiary is completed. Assumes that @completed_bestiary only has
  252.     # 2 (or more) elements if the first element is a Data_Bestiary and the second
  253.     # is a Bestiary_Criteria.
  254.     #------------------------------------------------------------------------
  255.     if (@completed_bestiary.size > 1) && @completed_bestiary[1].check
  256.       @completed = true
  257.       @current_bestiary = @completed_bestiary[0]
  258.       # No need to update the bestiary further
  259.       return
  260.     end # if
  261.     # Checks the status of the bestiary
  262.     for i in 0...@data.size
  263.       # Runs through the elements backwards.
  264.       j = @data.size - (i + 1)
  265.       # Checks if the conditions for the bestiary part are met
  266.       if @data[j][1].check
  267.         # Sets the current_bestiary to the bestiary which conditions are met
  268.         @current_bestiary = @data[j][0]
  269.         # Checks if the bestiary should be considered completed
  270.         if i == 0 and @completed_bestiary.size <= 1
  271.           @completed = true
  272.           @completed_bestiary = @data[j]
  273.         end # if
  274.         break
  275.       end # if
  276.     end # for
  277.     # Checks if the bestiary should be actived
  278.     if !@active && @current_bestiary.is_a?(Data_Bestiary)
  279.       @active = true  # Is actived
  280.     end
  281.   end # def
  282.  
  283.   #--------------------------------------------------------------------------
  284.   # * Add a bestiary (bestiary part)
  285.   #     bestiary : Must be a Data_Bestiary
  286.   #--------------------------------------------------------------------------
  287.   def add_bestiary(bestiary, condition)
  288.     if bestiary.is_a?(Data_Bestiary) && condition.is_a?(Bestiary_Criteria)
  289.       @data.push([bestiary,condition])
  290.     end # if
  291.   end # def
  292.  
  293.   #--------------------------------------------------------------------------
  294.   # * Set the completed bestiary part
  295.   #     bestiary : Must be a Data_Bestiary
  296.   #--------------------------------------------------------------------------
  297.   def set_completed_bestiary(bestiary, condition)
  298.     if bestiary.is_a?(Data_Bestiary)
  299.       @completed_bestiary = [bestiary, condition]
  300.     end # if
  301.   end # def
  302.  
  303.   #--------------------------------------------------------------------------
  304.   # * Error handling
  305.   #     string : A String containing the error message
  306.   #--------------------------------------------------------------------------
  307.   def error(err)
  308.     # Only prints the error message if the game is played through the editor
  309.     if $DEBUG
  310.       print err
  311.     end # if
  312.   end # def
  313. end # class
  314.  
  315. #==============================================================================
  316. # ** Game_Bestiaries
  317. #------------------------------------------------------------------------------
  318. #  This class handles bestiaries. It's a wrapper for the built-in class "Array."
  319. #  Refer to "$game_bestiaries" for the instance of this class.
  320. #  
  321. #  The bestiary potion 0 is considered to be the main bestiary. ($game_bestiaries[0])
  322. #==============================================================================
  323.  
  324. class Game_Bestiaries
  325.   # Adds a method to read the data
  326.   attr_reader     :data
  327.   #--------------------------------------------------------------------------
  328.   # * Object Initialization
  329.   #--------------------------------------------------------------------------
  330.   def initialize
  331.     @data = []
  332.   end # def
  333.   #--------------------------------------------------------------------------
  334.   # * Get Bestiary
  335.   #     bestiary_id : bestiary ID
  336.   #--------------------------------------------------------------------------
  337.   def [](bestiary_id)
  338.     return @data[bestiary_id]
  339.   end # def
  340.   #--------------------------------------------------------------------------
  341.   # * Set Bestiary
  342.   #     bestiary_id : bestiary ID
  343.   #     bestiary    : the bestiary
  344.   #--------------------------------------------------------------------------
  345.   def []=(bestiary_id, bestiary)
  346.     if bestiary.is_a?(Game_Bestiary) && bestiary_id % @data.size == 0
  347.       @data[bestiary_id] = bestiary
  348.     end  # if
  349.   end # def
  350.   #--------------------------------------------------------------------------
  351.   # * Add Bestiary
  352.   #     bestiary : the bestiary
  353.   #--------------------------------------------------------------------------
  354.   def add(bestiary)
  355.     if bestiary.is_a?(Game_Bestiary)
  356.       @data.push(bestiary)
  357.     end # if
  358.   end # def
  359.   #--------------------------------------------------------------------------
  360.   # * Resets the bestiaries
  361.   #--------------------------------------------------------------------------
  362.   def reset
  363.     for bestiary in @data
  364.       bestiary.reset
  365.     end # if
  366.   end # def
  367.   #--------------------------------------------------------------------------
  368.   # * Gets active bestiaries. Newest will be listed first
  369.   #   Note: The main bestiary if active will always have position 0. (result[0])
  370.   #--------------------------------------------------------------------------
  371.   def get_active_bestiaries
  372.     result = []
  373.     # Goes through the bestiaries
  374.     for i in 1...@data.size
  375.       element = @data[i]
  376.       # Updates the element
  377.       element.update
  378.       # Checks if element is active and not completed
  379.       if element.active && !element.completed
  380.         # Pushes the active element into the results
  381.         result.push(element)
  382.       end # if
  383.     end # for
  384.     # Checks if the main bestiary is active and not completed (index 0 in @data)
  385.     @data[0].update
  386.     if @data[0].active && !@data[0].completed
  387.       result.push(@data[0])
  388.     end # if
  389.     # Reverse result so the main bestiary have index 0 followed by the newest
  390.     # bestiary at index 1, the second newest at index 2 and so on.
  391.     result.reverse!
  392.     # Returns the resulting array
  393.     return result
  394.   end # def
  395.   #--------------------------------------------------------------------------
  396.   # * Gets completed bestiaries. Newest will be listed first
  397.   #   Note: The main bestiary will always be on position 0. (result[0])
  398.   #--------------------------------------------------------------------------
  399.   def get_completed_bestiaries
  400.     result = []
  401.     # Goes through the bestiaries
  402.     for i in 1...@data.size
  403.       element = @data[i]
  404.       # Updates the element
  405.       element.update
  406.       # Checks if element is completed.
  407.       if element.completed
  408.         # Pushes the active element into the results
  409.         result.push(element)
  410.       end # if
  411.     end # for
  412.     # Checks if the main bestiary is active and not completed (index 0 in @data)
  413.     if @data[0].completed
  414.       result.push(@data[0])
  415.     end # if
  416.     # Reverse result so the main bestiary have index 0 followed by the newest
  417.     # bestiary at index 1, the second newest at index 2 and so on.
  418.     result.reverse!
  419.     # Returns the resulting array
  420.     return result
  421.   end # def
  422. end # class
  423.  
  424. # The global variable used for storing bestiaries
  425. $game_bestiaries = Game_Bestiaries.new
  426.  
  427. #==============================================================================
  428. # ** Window_Bestiary_Header
  429. #------------------------------------------------------------------------------
  430. #  This window designates bestiary information in the header of the bestiary.
  431. #==============================================================================
  432.  
  433. class Window_Bestiary_Header < Window_Base
  434.   #--------------------------------------------------------------------------
  435.   # * Object Initialization
  436.   #       bestiary : The bestiary which information will be used
  437.   #--------------------------------------------------------------------------
  438.   def initialize(bestiary)
  439.     super(0, 0, 640, 128)
  440.     # Creates the Bitmap
  441.     self.contents = Bitmap.new(width - 32, height - 32)
  442.     # Draws the header
  443.     refresh(bestiary)
  444.   end # def
  445.  
  446.   #--------------------------------------------------------------------------
  447.   # * Refresh
  448.   #       bestiary : The bestiary which information will be used
  449.   #--------------------------------------------------------------------------
  450.   def refresh(bestiary)
  451.     # Redraw text
  452.     self.contents.clear
  453.     # checks if the bestiary is a Game_Bestiary.
  454.     if bestiary.is_a?(Game_Bestiary)
  455.       # Gets the current bestiary part
  456.       current_bestiary = bestiary.current_bestiary
  457.     else
  458.       if bestiary.is_a?(Integer)
  459.         # Draws the no completed bestiary header
  460.         draw_nobestiary_header
  461.       else
  462.         # Draws the mainmenu header
  463.         draw_mainmenu_header
  464.       end
  465.       # Stops processing this method (Refresh)
  466.       return
  467.     end
  468.     # Changes the color of the text to Teal
  469.     self.contents.font.color = text_color(4)
  470.     # Bolds the text
  471.     self.contents.font.bold = true
  472.     # Draws the non-changing text in bold
  473.     self.contents.draw_text(4, 0, 80, 32, "Who:")
  474.     self.contents.draw_text(4, 32, 80, 32, "Where:")
  475.     self.contents.draw_text(4, 64, 80, 32, "What:")
  476.     # Unbolds the text
  477.     self.contents.font.bold = false
  478.     # Draws the owner of the bestiary next to "Who:" in gray
  479.     self.contents.font.color = text_color(7)
  480.     self.contents.draw_text(80, 0, 540, 32, current_bestiary.owner)
  481.     # Draws the location of the bestiary next to "Where:" in blue
  482.     self.contents.font.color = text_color(1)
  483.     self.contents.draw_text(80, 32, 540, 32, current_bestiary.location)
  484.     # Draws the goal of the bestiary next to "What:" in yellow
  485.     self.contents.font.color = text_color(6)
  486.     self.contents.draw_text(80, 64, 540, 32, current_bestiary.goal)
  487.   end # def
  488.  
  489.   #--------------------------------------------------------------------------
  490.   # * Draws the header in the case where no bestiaries have been completed
  491.   #--------------------------------------------------------------------------
  492.   def draw_nobestiary_header
  493.     # Changes the color of the text to Gray
  494.     self.contents.font.color = text_color(7)
  495.     # Draws the text centered in the window
  496.     self.contents.draw_text(0, 32, 608, 32, "No bestiaries have been completed", 1)
  497.   end # def
  498.  
  499.   #--------------------------------------------------------------------------
  500.   # * Draws the header in the case where the main menu icon is selected
  501.   #--------------------------------------------------------------------------
  502.   def draw_mainmenu_header
  503.     # Changes the color of the text to Teal
  504.     self.contents.font.color = text_color(4)
  505.     # Draws the text centered in the window
  506.     self.contents.draw_text(0, 32, 608, 32, "Return to the main menu", 1)
  507.   end # def
  508. end # class
  509.  
  510. #==============================================================================
  511. # ** Window_Bestiary_Header
  512. #------------------------------------------------------------------------------
  513. #  This window designates bestiary information in the bestiary.
  514. #==============================================================================
  515.  
  516. class Window_Bestiary_Info < Window_Base
  517.  
  518.   #============================================================================
  519.   # ** Details
  520.   #----------------------------------------------------------------------------
  521.   #  This window contains the details of the bestiary.
  522.   #  Only the text are show. (No window)
  523.   #  Provides scrolling to the details only. (Not the header)
  524.   #============================================================================
  525.   class Details < Window_Base
  526.     #------------------------------------------------------------------------
  527.     # * Object Initialization
  528.     #------------------------------------------------------------------------
  529.     def initialize
  530.       super(80, 130, 480, 290)
  531.       # Must be higher than the parent window or the details will not be shown
  532.       self.z = 210
  533.       # No window, only text is shown
  534.       self.opacity = 0
  535.       # Creates the Bitmap
  536.       self.contents = Bitmap.new(width - 32, height - 32)
  537.     end # def
  538.    
  539.     #------------------------------------------------------------------------
  540.     # * Refresh
  541.     #       bestiary : The bestiary which information will be drawn
  542.     #------------------------------------------------------------------------
  543.     def refresh(bestiary)
  544.       # Resets the position of the bitmap
  545.       self.oy = 0
  546.       # Splits the info into lines
  547.       info = bestiary.info.split(/\n/)
  548.       # Disposes of the old bitmap
  549.       self.contents.dispose
  550.       # Creates an appropriately big bitmap
  551.       self.contents = Bitmap.new(width - 32, info.size*32+16)
  552.      
  553.       # Clears the bitmap
  554.       self.contents.clear
  555.       # Sets the text color to the standard color (White)
  556.       self.contents.font.color = text_color(0)
  557.       # Draws all the lines except the last on
  558.       for i in 0...info.size - 1
  559.         text = info[i].dup
  560.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  561.         self.contents.draw_text(0, i*32, 480, 32, text)
  562.       end # for
  563.      
  564.       # Sets the text color to yellow
  565.       self.contents.font.color = text_color(6)
  566.       # Only prints the last info if there actually are something to print
  567.       if info[-1].is_a?(String)
  568.         text = info[-1].dup
  569.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  570.         # The last line of the info (if any is present) is consider as the
  571.         # goal and positioned a bit different, centered and drawn in yellow.
  572.         self.contents.draw_text(0, info.size*32-22, 440, 32, text, 1)
  573.       end # if
  574.     end # def
  575.    
  576.     #------------------------------------------------------------------------
  577.     # * Update
  578.     #------------------------------------------------------------------------
  579.     def update
  580.       # Calls the parent method
  581.       super
  582.       # Checks if the text is big enough for scrolling to be necessary
  583.       if self.contents.height > height
  584.         # Moves the text up if the UP key is pressed. (Warps)
  585.         if Input.repeat?(Input::UP)
  586.           self.oy = (self.oy - 10) % (self.contents.height - height + 64)
  587.         end # if
  588.         # Moves the text down if the DOWN key is pressed. (Warps)
  589.         if Input.repeat?(Input::DOWN)
  590.           self.oy = (self.oy + 10) % (self.contents.height - height + 64)
  591.         end # if
  592.       end # if
  593.     end # def
  594.    
  595.   end # class
  596.  
  597.  
  598.   #--------------------------------------------------------------------------
  599.   # * Object Initialization
  600.   #--------------------------------------------------------------------------
  601.   def initialize
  602.     super(80, 60, 480, 360)
  603.     # Puts this on top of the other windoes
  604.     self.z = 200  
  605.     # Creates the Bitmap
  606.     self.contents = Bitmap.new(width - 32, height - 32)
  607.     # Creates the detail part.
  608.     @details = Details.new
  609.     # The details window is by standard not immediately visible
  610.     @details.visible = false
  611.   end # def
  612.  
  613.   #--------------------------------------------------------------------------
  614.   # * Refresh
  615.   #       bestiary : The bestiary which information will be drawn (Game_Bestiary)
  616.   #--------------------------------------------------------------------------
  617.   def refresh(bestiary)
  618.     return unless bestiary.is_a?(Game_Bestiary)
  619.     # Gets the current_bestiary part
  620.     current_bestiary = bestiary.current_bestiary
  621.     # Redraw text (the top part)
  622.     self.contents.clear
  623.     # Draws who gave the current bestiary part
  624.     self.contents.font.color = text_color(7)
  625.     self.contents.font.bold = false
  626.     self.contents.draw_text(0, 0, 440, 32, current_bestiary.owner, 1)
  627.     # Draws the area
  628.     self.contents.font.color = text_color(1)
  629.     self.contents.draw_text(0, 32, 440, 32, current_bestiary.location, 1)
  630.     # Draws a seperator line
  631.     self.contents.font.color = text_color(0)
  632.     self.contents.draw_text(0, 8, 480, 32,
  633.                             "__________________________________________", 1)
  634.     # Refreshes the details.
  635.     @details.refresh(current_bestiary)
  636.   end # def
  637.  
  638.   #--------------------------------------------------------------------------
  639.   # * Update
  640.   #--------------------------------------------------------------------------
  641.   def update
  642.     # Calls the parent method
  643.     super
  644.     # Updates the details if it is visible
  645.     @details.visible = self.visible
  646.     @details.update
  647.   end # def
  648.  
  649. end # class
  650.  
  651. #==============================================================================
  652. # ** Window_Bestiary
  653. #------------------------------------------------------------------------------
  654. #  This window designates the bestiary selection on the bestiary screen.
  655. #==============================================================================
  656.  
  657. class Window_Bestiary < Window_Selectable
  658.   # Constants
  659.   MAIN_MENU_ICON_PATH = "Bestiary/Icons/mainmenu.png"
  660.  
  661.   # Attributes
  662.   #attr_accessor   :active_bestiaries # Tells whether active bestiaries are show or not
  663.  
  664.   #--------------------------------------------------------------------------
  665.   # * Object Initialization
  666.   #--------------------------------------------------------------------------
  667.   def initialize(bestiary_set)
  668.     super(0, 128, 640, 352)
  669.     # Saves the bestiary set given
  670.     @data = bestiary_set
  671.     # Old data (stores refrences to old data)
  672.     @old_data = {}
  673.     # Amount of items
  674.     @item_max = @data.size
  675.     # The amount of items on each line   (Items per row)
  676.     @column_max = 6
  677.     # Starts on index 0 (Top-Left)
  678.     @index = 0
  679.     # Active bestiaries are shown at start up
  680.     @active_bestiaries = true
  681.     # Creates Bitmap
  682.     self.contents = Bitmap.new(width - 32, @item_max / @column_max * 96 + 96)
  683.     refresh
  684.   end # def
  685.  
  686.   #--------------------------------------------------------------------------
  687.   # * Refresh
  688.   #--------------------------------------------------------------------------
  689.   def refresh
  690.     # Redraw text
  691.     self.contents.clear
  692.     # Draws the icons
  693.     for i in 0...@item_max
  694.       draw_icon(i,@data[i].current_bestiary.get_icon)
  695.     end # for
  696.     # Checks if there is a mainmenu icon
  697.     if @active_bestiaries
  698.       # An extra icon is drawn with the main menu icon     (Another item)
  699.       @item_max = @data.size + 1
  700.       draw_icon(@item_max - 1, MAIN_MENU_ICON_PATH)
  701.     else
  702.       # There are as many items as there are bestiaries in the data
  703.       @item_max = @data.size
  704.     end # if
  705.     # Checks if there are any items
  706.     if @item_max == 0
  707.       # Removes the cursor when there are no item
  708.       @index = -1
  709.     elsif @index == -1
  710.       # Sets the cursor to the first element
  711.       @index = 0
  712.     end # if
  713.   end # def
  714.  
  715.   #--------------------------------------------------------------------------
  716.   # * Draws the icon of the bestiary at the i'th space
  717.   #--------------------------------------------------------------------------
  718.   def draw_icon(i, icon_name)
  719.     # Calculates the x- and y-coordinates
  720.     x = (i % @column_max) * 99 + 16
  721.     y = (i / @column_max) * 96 - 10
  722.     # Draws the given bestiary icon at the given position
  723.     draw_bestiary_icon(icon_name, x, y + 18)
  724.   end # def
  725.  
  726.   #--------------------------------------------------------------------------
  727.   # * Sets a new set bestiaries as data
  728.   #--------------------------------------------------------------------------
  729.   def set_data(bestiary_set, active_bestiaries)
  730.     if bestiary_set == @data && active_bestiaries == @active_bestiaries
  731.       return
  732.     end
  733.     # Stores old data
  734.     @old_data[[@data,@active_bestiaries]] = self.contents
  735.     # Sets whether or not the bestiary_set is of the active bestiaries
  736.     @active_bestiaries = active_bestiaries
  737.     # Sets the bestiary_set as data
  738.     @data = bestiary_set
  739.     # Amount of items
  740.     @item_max = @data.size
  741.     # Creates Bitmap
  742.     if @old_data[[@data,@active_bestiaries]] != nil
  743.       self.contents = @old_data[[@data,@active_bestiaries]]
  744.     else
  745.       self.contents = Bitmap.new(width - 32, @item_max / @column_max * 96 + 96)
  746.     end
  747.     # Refreshes (redraws) the window with the new data
  748.     refresh
  749.   end
  750.  
  751.   #--------------------------------------------------------------------------
  752.   # * Update Cursor Rectangle
  753.   #--------------------------------------------------------------------------
  754.   def update_cursor_rect
  755.     # If cursor position is less than 0
  756.     if @index < 0
  757.       self.cursor_rect.empty
  758.       return
  759.     end # if
  760.     # Get current row
  761.     row = @index / @column_max
  762.     # If current row is before top row
  763.     if row < self.top_row
  764.       # Scroll so that current row becomes top row
  765.       self.top_row = row
  766.     end # if
  767.     # If current row is more to back than back row
  768.     if row > self.top_row + (self.page_row_max - 1)
  769.       # Scroll so that current row becomes back row
  770.       self.top_row = row - (self.page_row_max - 1)
  771.     end # if
  772.     # Calculate cursor coordinates
  773.     x = (@index % @column_max) * 99 + 8       #112
  774.     y = (@index / @column_max) * 96 - self.oy
  775.     self.cursor_rect.set(x, y, 96, 96)
  776.   end # def
  777.  
  778.   #--------------------------------------------------------------------------
  779.   # * Get Top Row
  780.   #--------------------------------------------------------------------------
  781.   def top_row
  782.     # Divide y-coordinate of window contents transfer origin by 1 row
  783.     # height of 96
  784.     return self.oy / 96
  785.   end # def
  786.  
  787.   #--------------------------------------------------------------------------
  788.   # * Set Top Row
  789.   #     row : row shown on top
  790.   #--------------------------------------------------------------------------
  791.   def top_row=(row)
  792.     row = row % row_max
  793.     self.oy = row * 96
  794.   end # def
  795.  
  796.   #--------------------------------------------------------------------------
  797.   # * Get Number of Rows Displayable on 1 Page
  798.   #--------------------------------------------------------------------------
  799.   def page_row_max
  800.     # Subtract a frame height of 32 from the window height, and divide it by
  801.     # 1 row height of 96
  802.     return (self.height - 32) / 96
  803.   end # def
  804.  
  805.   #--------------------------------------------------------------------------
  806.   # * Dispose
  807.   #--------------------------------------------------------------------------
  808.   def dispose
  809.     super
  810.     # Disposes the stored bitmaps
  811.     @old_data.each_value {|value| value.dispose}
  812.   end
  813.  
  814. end # class
  815.  
  816. #==============================================================================
  817. # ** Bestiary
  818. #------------------------------------------------------------------------------
  819. # Zeriab
  820. # 1.2
  821. # 2007-10-01 (year-month-day)
  822. #==============================================================================
  823.  
  824. #==============================================================================
  825. # ** Scene_Bestiary
  826. #------------------------------------------------------------------------------
  827. #  This window designates the bestiary selection on the bestiary screen.
  828. #==============================================================================
  829.  
  830. class Scene_Bestiary
  831.   #--------------------------------------------------------------------------
  832.   # * Object Initialization
  833.   #--------------------------------------------------------------------------
  834.   def initialize(scene = Scene_Menu.new)
  835.     # Gets the active bestiaries
  836.     @active_bestiary_set = $game_bestiaries.get_active_bestiaries
  837.     # Gets the completed bestiaries
  838.     @completed_bestiary_set = $game_bestiaries.get_completed_bestiaries
  839.     # Starts at the main_menu
  840.     @last_index = 0
  841.     # The completed bestiaries starts in the top-left corner
  842.     @other_index = 0
  843.     # Active bestiaries are shown when the bestiarylog has opened
  844.     @active_bestiaries = true
  845.     # Sets the current bestiary set
  846.     @current_bestiary_set = @active_bestiary_set
  847.     # The next scene it will skip to is the scene given
  848.     @next_scene = scene
  849.   end # def
  850.  
  851.   #--------------------------------------------------------------------------
  852.   # * Main Processing
  853.   #--------------------------------------------------------------------------
  854.   def main
  855.     # The background image
  856.     @back_sprite = Sprite.new(Viewport.new(0,0,640,480))
  857.     picname = BACK_PICS[$game_variables[BACK_VAR]]
  858.     unless picname.is_a?(String)
  859.       picname = BACK_PICS["standard"]
  860.     end
  861.     @back_sprite.bitmap = RPG::Cache.picture(BACKGROUND_DIR+picname)
  862.     # Bestiary selection window
  863.     @bestiary_select = Window_Bestiary.new(@current_bestiary_set)
  864.     @bestiary_select.opacity = WINDOW_OPACITY
  865.     # Bestiary info-header window
  866.     @bestiary_header = Window_Bestiary_Header.new(@current_bestiary_set[0])
  867.     @bestiary_header.opacity = WINDOW_OPACITY
  868.     # Bestiary information window
  869.     @bestiary_info = Window_Bestiary_Info.new
  870.     @bestiary_info.opacity = WINDOW_OPACITY
  871.     @bestiary_info.visible = false
  872.     # Execute transition
  873.     Graphics.transition
  874.     # Scene Objects
  875.     @scene_objects = [@back_sprite, @bestiary_select, @bestiary_header, @bestiary_info]
  876.     # Main loop
  877.     loop do
  878.       # Update game screen
  879.       Graphics.update
  880.       # Update input information
  881.       Input.update
  882.       # Updates Scene Objects
  883.       @scene_objects.each { |x| x.update}
  884.       ## Frame update
  885.       update
  886.       # Abort loop if screen is changed
  887.       break if $scene != self
  888.     end # loop
  889.     # Prepare for transition
  890.     Graphics.freeze
  891.     # Dispose Scene Objects
  892.     @scene_objects.each { |x| x.dispose }
  893.   end # def
  894.  
  895.   #--------------------------------------------------------------------------
  896.   # * Refresh
  897.   #--------------------------------------------------------------------------
  898.   def switch
  899.     # Switch to the previously remembered index (In case L or R was used)
  900.     tmp = @bestiary_select.index
  901.     @bestiary_select.index = @other_index
  902.     @other_index = tmp
  903.     # Plays the Cursor sound effect
  904.     $game_system.se_play($data_system.cursor_se)
  905.     # Checks if there are active bestiaries shown
  906.     if @active_bestiaries
  907.       # Completed bestiaries is to be shown. (Active bestiary NOT shown)
  908.       @active_bestiaries = false
  909.       # Sets the current bestiary_set to the completed bestiary_set
  910.       @current_bestiary_set = @completed_bestiary_set
  911.     else
  912.       # Active bestiaries is to be shown.
  913.       @active_bestiaries = true
  914.       # Sets the current bestiary_set to the active bestiary_set
  915.       @current_bestiary_set = @active_bestiary_set
  916.     end # if
  917.     # Sets the data in the selection window
  918.     @bestiary_select.set_data(@current_bestiary_set, @active_bestiaries)
  919.     # Checks if there are any fields
  920.     if @bestiary_select.index > -1
  921.       # Opdates the header
  922.       @bestiary_header.refresh(@current_bestiary_set[0])
  923.     else
  924.       # Opdates the header
  925.       @bestiary_header.refresh(1)
  926.     end # if
  927.   end # def
  928.  
  929.   #--------------------------------------------------------------------------
  930.   # * Frame Update
  931.   #--------------------------------------------------------------------------
  932.   def update
  933.     # If RIGHT Button Is Pressed
  934.     if Input.trigger?(Input::RIGHT) && !@bestiary_info.visible
  935.       # Checks if there are any items to select.
  936.       if @bestiary_select.index <= -1
  937.         # Switches between active and completed bestiaries
  938.         switch
  939.       end # if
  940.     end # if
  941.     # If LEFT Button Is Pressed
  942.     if Input.trigger?(Input::LEFT) && !@bestiary_info.visible
  943.       # Checks if the last index is the same as the current. (All left)
  944.       if @last_index == @bestiary_select.index || @bestiary_select.index <= -1
  945.         # Switches between active and completed bestiaries
  946.         switch
  947.       end # if
  948.     end # if
  949.     # Checks if the index in @bestiary_select have changed
  950.     if @last_index != @bestiary_select.index && @bestiary_select.index > -1
  951.       # Updates the last_index
  952.       @last_index = @bestiary_select.index
  953.       # Updates the header
  954.       @bestiary_header.refresh(@current_bestiary_set[@last_index])
  955.     end # if
  956.     # If C Button Is Pressed
  957.     if Input.trigger?(Input::C) && @bestiary_select.index > -1
  958.       # Checks if the main menu icon is present
  959.       if @active_bestiaries
  960.         # Checks that a bestiary is not select. (So it must be the main menu)
  961.         if (@bestiary_select.index >= $game_bestiaries.get_active_bestiaries.size)
  962.           # Plays the Cancel sound effect
  963.           $game_system.se_play($data_system.cancel_se)
  964.           # Changes the scene to the main menu
  965.           $scene = Scene_Menu.new
  966.           # Stops processing this method
  967.           return
  968.         end # if
  969.       end # if
  970.       # Plays the Decision sound effect
  971.       $game_system.se_play($data_system.decision_se)
  972.       # Change the visibility of the bestiary_info
  973.       # Visible => Invisible, Invisible => Visible        
  974.       @bestiary_info.visible = !@bestiary_info.visible
  975.       # The bestiary select is not active if the info is visible, else it is
  976.       @bestiary_select.active = !@bestiary_info.visible
  977.       # Refreshes the bestiary info
  978.       @bestiary_info.refresh(@current_bestiary_set[@bestiary_select.index])
  979.     end # if
  980.     # If B Button Is Pressed
  981.     if Input.trigger?(Input::B)
  982.       # Play cancel SE
  983.       $game_system.se_play($data_system.cancel_se)
  984.       # Switch to next scene
  985.       $scene = @next_scene unless @bestiary_info.visible
  986.       # Changes the bestiary info to become invisible
  987.       @bestiary_info.visible = false
  988.       # The bestiary select is active as the info is not visible
  989.       @bestiary_select.active = true
  990.       # Refreshes the bestiary info
  991.       @bestiary_info.refresh(@current_bestiary_set[@bestiary_select.index])
  992.       # Stops processing this method
  993.       return
  994.     end # if
  995.     # If L Button Is Pressed
  996.     if Input.trigger?(Input::L)
  997.       switch
  998.     end # if
  999.     # If R Button Is Pressed
  1000.     if Input.trigger?(Input::R)
  1001.       switch
  1002.     end # if
  1003.   end # def
  1004. end # class
  1005.  
  1006. #==============================================================================
  1007. # ** Scene_Load
  1008. #------------------------------------------------------------------------------
  1009. #  Aliases and uses the on_decision method to reset $game_bestiaries on the proper
  1010. #  time.
  1011. #==============================================================================
  1012.  
  1013. class Scene_Load < Scene_File
  1014.   # Check if the alias already exists (To avoid F12 errors)
  1015.   unless self.method_defined?(:zeriab_bestiary_scene_load_on_decision)
  1016.     alias zeriab_bestiary_scene_load_on_decision :on_decision
  1017.   end
  1018.   def on_decision(*args)
  1019.     # Call the original method
  1020.     zeriab_bestiary_scene_load_on_decision(*args)
  1021.     # Check if the scene has changed
  1022.     unless $scene == self
  1023.       # Reset bestiary data
  1024.       $game_bestiaries.reset
  1025.     end
  1026.   end
  1027. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement