Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # * Window_Base
- #------------------------------------------------------------------------------
- # Defines the draw_bestiary_icon method in Window_Base
- #==============================================================================
- class Window_Base
- #--------------------------------------------------------------------------
- # * Draw Bestiary Icon
- # icon_name : filename of the icon
- # x : draw spot x-coordinate
- # y : draw spot y-coordinate
- #--------------------------------------------------------------------------
- def draw_bestiary_icon(icon_name, x, y)
- begin
- bitmap = RPG::Cache.picture(icon_name)
- rescue
- bitmap = RPG::Cache.picture(Data_Bestiary::PATH + Data_Bestiary::DEFAULT_ICON)
- end
- cw = 80
- ch = 80
- src_rect = Rect.new(0, 0, cw, ch)
- self.contents.blt(x, y, bitmap, src_rect)
- end # def
- end # class
- #==============================================================================
- # ** Data_Bestiary
- #------------------------------------------------------------------------------
- # A bestiary object.
- # Stores information about the particular bestiary.
- # All icons are assumed to be stored in the same directory
- #==============================================================================
- class Data_Bestiary
- # The path in the pictures folder
- PATH = "Bestiary/Icons/"
- # The name of the default icon
- DEFAULT_ICON = "default_icon.png"
- # The following are of the String class.
- attr_reader :owner # Who
- attr_reader :location # Where
- attr_reader :goal # What
- attr_reader :info # details
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- @owner = ""
- @location = ""
- @goal = ""
- @info = ""
- @icon = DEFAULT_ICON
- end # def
- #--------------------------------------------------------------------------
- # * Gets the name and location of the icon in the picture folder
- #--------------------------------------------------------------------------
- def get_icon
- return PATH + @icon
- end # def
- #--------------------------------------------------------------------------
- # * Set Owner
- # string : A string containing the owner
- #--------------------------------------------------------------------------
- def owner=(string)
- if string.is_a?(String)
- @owner = string
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Set Location
- # string : A string containing the location
- #--------------------------------------------------------------------------
- def location=(string)
- if string.is_a?(String)
- @location = string
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Set Goal
- # string : A string containing the goal
- #--------------------------------------------------------------------------
- def goal=(string)
- if string.is_a?(String)
- @goal = string
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Set Info
- # string : A string containing the information
- #--------------------------------------------------------------------------
- def info=(string)
- if string.is_a?(String)
- @info = string
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Set Info
- # string : A string containing the filename of the icon
- # No change is done if the file does not exists
- #--------------------------------------------------------------------------
- def icon=(string)
- if string.is_a?(String)
- @icon = string
- end # if
- end # def
- end # class
- #==============================================================================
- # ** Bestiary_Criteria
- #------------------------------------------------------------------------------
- # This class simple gets a criteria and tells if it is fulfilled or not.
- # Used in Game_Bestiary to determine how much the bestiary has progressed
- #
- # Variable condition:
- # ["variable", variable_number, condition, number]
- # -------------------
- # The "variable" just tells the script that you want to check a variable
- # The variable_number is the number on the variable you want to use.
- # Condition is which condition you want to check.
- # "<" - less than
- # "<=" - less than or equal ("=<" will give you an error)
- # "==" - equal ("=" is converted to "==")
- # ">=" - greater than or equal ("=>" will give you an error)
- # ">" - greater than
- # "!=" - not equal
- # The number is the number you want to check with.
- # For example:
- # ["variable", 4, ">", 3] - Variable number 4 must be bigger than 3
- # ["variable", 2, "==", 5] - Variable number 2 must be equal 5
- #
- #
- # Switch Condition:
- # ["switch", switch_number, state]
- # -------------------------------------
- # The "switch" just tells the script that you want to check a switch
- # The switch_number is the number on the switch you want to use.
- # The state is what the state of the switch should be for the conditions to
- # be fulfilled. Write 'true' if the switch must be ON and 'false' if the
- # switch must be OFF
- #
- # For example:
- # ["switch", 7, true] - Switch number 7 must be true
- # ["switch", 3, false] - Switch number 3 must be false
- #
- #
- # Use the 'check' method to see if all conditions are met. If they are then
- # 'true' will be returned, otherwise 'false'
- #==============================================================================
- class Bestiary_Criteria
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(*args)
- # Each argument is considered as a condition and is stored in @conditions
- @conditions = args
- end # def
- #--------------------------------------------------------------------------
- # * Checks the conditions. Returns true if all the conditions are met
- #--------------------------------------------------------------------------
- def check
- # Goes through the conditions
- for condition in @conditions
- # Creates a begin-rescue block to catch errors.
- begin
- break if !condition.is_a?(Array) && !condition[0].is_a?(String)
- case condition[0].downcase # The first field in the array
- when "variable"
- # Converts '=' into '==' to avoid changing the variable
- condition[2] = "==" if condition[2] == "="
- command = "$game_variables[#{condition[1]}] #{condition[2]} " +
- "#{condition[3]}"
- return false unless eval(command)
- when "switch"
- return false unless $game_switches[condition[1]] == condition[2]
- end
- rescue Exception => err
- # Prints an error message if and only if $DEBUG is true
- # The erroneous condition is considered to be "true"
- if $DEBUG
- output = "Bestiary_Criteria:Check\n\n"+ err.type.to_s + "\n" +
- err.to_s + "\n\n" + "Backtrace(10):\n\n" +
- err.backtrace[0...10].join("\n").to_s
- print output
- end
- end # begin
- end # for
- # Returns true if no condition is false.
- return true
- end # def
- end # class
- #==============================================================================
- # ** Game_Bestiary
- #------------------------------------------------------------------------------
- # Manages the process in the bestiaries.
- #==============================================================================
- class Game_Bestiary
- attr_reader :completed
- attr_reader :active
- attr_reader :current_bestiary
- #--------------------------------------------------------------------------
- # * Object Initialization
- # bestiary : Must be a Data_Bestiary
- #--------------------------------------------------------------------------
- def initialize
- @data = []
- # Completed bestiary
- @completed_bestiary = []
- # A bestiary is not completed in the start
- @completed = false
- # Neither is it active
- @active = false
- # Updates
- update
- end # def
- #--------------------------------------------------------------------------
- # * Resets the bestiary
- #--------------------------------------------------------------------------
- def reset
- # Remove the current bestiary
- @current_bestiary = nil
- # A bestiary is not completed in the start
- @completed = false
- # Neither is it active
- @active = false
- # Updates
- update
- end # def
- #--------------------------------------------------------------------------
- # * Updates the current_bestiary
- #--------------------------------------------------------------------------
- def update
- # Return if the bestiary have completed
- @completed = false
- #------------------------------------------------------------------------
- # Checks if the bestiary is completed. Assumes that @completed_bestiary only has
- # 2 (or more) elements if the first element is a Data_Bestiary and the second
- # is a Bestiary_Criteria.
- #------------------------------------------------------------------------
- if (@completed_bestiary.size > 1) && @completed_bestiary[1].check
- @completed = true
- @current_bestiary = @completed_bestiary[0]
- # No need to update the bestiary further
- return
- end # if
- # Checks the status of the bestiary
- for i in 0...@data.size
- # Runs through the elements backwards.
- j = @data.size - (i + 1)
- # Checks if the conditions for the bestiary part are met
- if @data[j][1].check
- # Sets the current_bestiary to the bestiary which conditions are met
- @current_bestiary = @data[j][0]
- # Checks if the bestiary should be considered completed
- if i == 0 and @completed_bestiary.size <= 1
- @completed = true
- @completed_bestiary = @data[j]
- end # if
- break
- end # if
- end # for
- # Checks if the bestiary should be actived
- if !@active && @current_bestiary.is_a?(Data_Bestiary)
- @active = true # Is actived
- end
- end # def
- #--------------------------------------------------------------------------
- # * Add a bestiary (bestiary part)
- # bestiary : Must be a Data_Bestiary
- #--------------------------------------------------------------------------
- def add_bestiary(bestiary, condition)
- if bestiary.is_a?(Data_Bestiary) && condition.is_a?(Bestiary_Criteria)
- @data.push([bestiary,condition])
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Set the completed bestiary part
- # bestiary : Must be a Data_Bestiary
- #--------------------------------------------------------------------------
- def set_completed_bestiary(bestiary, condition)
- if bestiary.is_a?(Data_Bestiary)
- @completed_bestiary = [bestiary, condition]
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Error handling
- # string : A String containing the error message
- #--------------------------------------------------------------------------
- def error(err)
- # Only prints the error message if the game is played through the editor
- if $DEBUG
- print err
- end # if
- end # def
- end # class
- #==============================================================================
- # ** Game_Bestiaries
- #------------------------------------------------------------------------------
- # This class handles bestiaries. It's a wrapper for the built-in class "Array."
- # Refer to "$game_bestiaries" for the instance of this class.
- #
- # The bestiary potion 0 is considered to be the main bestiary. ($game_bestiaries[0])
- #==============================================================================
- class Game_Bestiaries
- # Adds a method to read the data
- attr_reader :data
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- @data = []
- end # def
- #--------------------------------------------------------------------------
- # * Get Bestiary
- # bestiary_id : bestiary ID
- #--------------------------------------------------------------------------
- def [](bestiary_id)
- return @data[bestiary_id]
- end # def
- #--------------------------------------------------------------------------
- # * Set Bestiary
- # bestiary_id : bestiary ID
- # bestiary : the bestiary
- #--------------------------------------------------------------------------
- def []=(bestiary_id, bestiary)
- if bestiary.is_a?(Game_Bestiary) && bestiary_id % @data.size == 0
- @data[bestiary_id] = bestiary
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Add Bestiary
- # bestiary : the bestiary
- #--------------------------------------------------------------------------
- def add(bestiary)
- if bestiary.is_a?(Game_Bestiary)
- @data.push(bestiary)
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Resets the bestiaries
- #--------------------------------------------------------------------------
- def reset
- for bestiary in @data
- bestiary.reset
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Gets active bestiaries. Newest will be listed first
- # Note: The main bestiary if active will always have position 0. (result[0])
- #--------------------------------------------------------------------------
- def get_active_bestiaries
- result = []
- # Goes through the bestiaries
- for i in 1...@data.size
- element = @data[i]
- # Updates the element
- element.update
- # Checks if element is active and not completed
- if element.active && !element.completed
- # Pushes the active element into the results
- result.push(element)
- end # if
- end # for
- # Checks if the main bestiary is active and not completed (index 0 in @data)
- @data[0].update
- if @data[0].active && !@data[0].completed
- result.push(@data[0])
- end # if
- # Reverse result so the main bestiary have index 0 followed by the newest
- # bestiary at index 1, the second newest at index 2 and so on.
- result.reverse!
- # Returns the resulting array
- return result
- end # def
- #--------------------------------------------------------------------------
- # * Gets completed bestiaries. Newest will be listed first
- # Note: The main bestiary will always be on position 0. (result[0])
- #--------------------------------------------------------------------------
- def get_completed_bestiaries
- result = []
- # Goes through the bestiaries
- for i in 1...@data.size
- element = @data[i]
- # Updates the element
- element.update
- # Checks if element is completed.
- if element.completed
- # Pushes the active element into the results
- result.push(element)
- end # if
- end # for
- # Checks if the main bestiary is active and not completed (index 0 in @data)
- if @data[0].completed
- result.push(@data[0])
- end # if
- # Reverse result so the main bestiary have index 0 followed by the newest
- # bestiary at index 1, the second newest at index 2 and so on.
- result.reverse!
- # Returns the resulting array
- return result
- end # def
- end # class
- # The global variable used for storing bestiaries
- $game_bestiaries = Game_Bestiaries.new
- #==============================================================================
- # ** Window_Bestiary_Header
- #------------------------------------------------------------------------------
- # This window designates bestiary information in the header of the bestiary.
- #==============================================================================
- class Window_Bestiary_Header < Window_Base
- #--------------------------------------------------------------------------
- # * Object Initialization
- # bestiary : The bestiary which information will be used
- #--------------------------------------------------------------------------
- def initialize(bestiary)
- super(0, 0, 640, 128)
- # Creates the Bitmap
- self.contents = Bitmap.new(width - 32, height - 32)
- # Draws the header
- refresh(bestiary)
- end # def
- #--------------------------------------------------------------------------
- # * Refresh
- # bestiary : The bestiary which information will be used
- #--------------------------------------------------------------------------
- def refresh(bestiary)
- # Redraw text
- self.contents.clear
- # checks if the bestiary is a Game_Bestiary.
- if bestiary.is_a?(Game_Bestiary)
- # Gets the current bestiary part
- current_bestiary = bestiary.current_bestiary
- else
- if bestiary.is_a?(Integer)
- # Draws the no completed bestiary header
- draw_nobestiary_header
- else
- # Draws the mainmenu header
- draw_mainmenu_header
- end
- # Stops processing this method (Refresh)
- return
- end
- # Changes the color of the text to Teal
- self.contents.font.color = text_color(4)
- # Bolds the text
- self.contents.font.bold = true
- # Draws the non-changing text in bold
- self.contents.draw_text(4, 0, 80, 32, "Who:")
- self.contents.draw_text(4, 32, 80, 32, "Where:")
- self.contents.draw_text(4, 64, 80, 32, "What:")
- # Unbolds the text
- self.contents.font.bold = false
- # Draws the owner of the bestiary next to "Who:" in gray
- self.contents.font.color = text_color(7)
- self.contents.draw_text(80, 0, 540, 32, current_bestiary.owner)
- # Draws the location of the bestiary next to "Where:" in blue
- self.contents.font.color = text_color(1)
- self.contents.draw_text(80, 32, 540, 32, current_bestiary.location)
- # Draws the goal of the bestiary next to "What:" in yellow
- self.contents.font.color = text_color(6)
- self.contents.draw_text(80, 64, 540, 32, current_bestiary.goal)
- end # def
- #--------------------------------------------------------------------------
- # * Draws the header in the case where no bestiaries have been completed
- #--------------------------------------------------------------------------
- def draw_nobestiary_header
- # Changes the color of the text to Gray
- self.contents.font.color = text_color(7)
- # Draws the text centered in the window
- self.contents.draw_text(0, 32, 608, 32, "No bestiaries have been completed", 1)
- end # def
- #--------------------------------------------------------------------------
- # * Draws the header in the case where the main menu icon is selected
- #--------------------------------------------------------------------------
- def draw_mainmenu_header
- # Changes the color of the text to Teal
- self.contents.font.color = text_color(4)
- # Draws the text centered in the window
- self.contents.draw_text(0, 32, 608, 32, "Return to the main menu", 1)
- end # def
- end # class
- #==============================================================================
- # ** Window_Bestiary_Header
- #------------------------------------------------------------------------------
- # This window designates bestiary information in the bestiary.
- #==============================================================================
- class Window_Bestiary_Info < Window_Base
- #============================================================================
- # ** Details
- #----------------------------------------------------------------------------
- # This window contains the details of the bestiary.
- # Only the text are show. (No window)
- # Provides scrolling to the details only. (Not the header)
- #============================================================================
- class Details < Window_Base
- #------------------------------------------------------------------------
- # * Object Initialization
- #------------------------------------------------------------------------
- def initialize
- super(80, 130, 480, 290)
- # Must be higher than the parent window or the details will not be shown
- self.z = 210
- # No window, only text is shown
- self.opacity = 0
- # Creates the Bitmap
- self.contents = Bitmap.new(width - 32, height - 32)
- end # def
- #------------------------------------------------------------------------
- # * Refresh
- # bestiary : The bestiary which information will be drawn
- #------------------------------------------------------------------------
- def refresh(bestiary)
- # Resets the position of the bitmap
- self.oy = 0
- # Splits the info into lines
- info = bestiary.info.split(/\n/)
- # Disposes of the old bitmap
- self.contents.dispose
- # Creates an appropriately big bitmap
- self.contents = Bitmap.new(width - 32, info.size*32+16)
- # Clears the bitmap
- self.contents.clear
- # Sets the text color to the standard color (White)
- self.contents.font.color = text_color(0)
- # Draws all the lines except the last on
- for i in 0...info.size - 1
- text = info[i].dup
- text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
- self.contents.draw_text(0, i*32, 480, 32, text)
- end # for
- # Sets the text color to yellow
- self.contents.font.color = text_color(6)
- # Only prints the last info if there actually are something to print
- if info[-1].is_a?(String)
- text = info[-1].dup
- text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
- # The last line of the info (if any is present) is consider as the
- # goal and positioned a bit different, centered and drawn in yellow.
- self.contents.draw_text(0, info.size*32-22, 440, 32, text, 1)
- end # if
- end # def
- #------------------------------------------------------------------------
- # * Update
- #------------------------------------------------------------------------
- def update
- # Calls the parent method
- super
- # Checks if the text is big enough for scrolling to be necessary
- if self.contents.height > height
- # Moves the text up if the UP key is pressed. (Warps)
- if Input.repeat?(Input::UP)
- self.oy = (self.oy - 10) % (self.contents.height - height + 64)
- end # if
- # Moves the text down if the DOWN key is pressed. (Warps)
- if Input.repeat?(Input::DOWN)
- self.oy = (self.oy + 10) % (self.contents.height - height + 64)
- end # if
- end # if
- end # def
- end # class
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- super(80, 60, 480, 360)
- # Puts this on top of the other windoes
- self.z = 200
- # Creates the Bitmap
- self.contents = Bitmap.new(width - 32, height - 32)
- # Creates the detail part.
- @details = Details.new
- # The details window is by standard not immediately visible
- @details.visible = false
- end # def
- #--------------------------------------------------------------------------
- # * Refresh
- # bestiary : The bestiary which information will be drawn (Game_Bestiary)
- #--------------------------------------------------------------------------
- def refresh(bestiary)
- return unless bestiary.is_a?(Game_Bestiary)
- # Gets the current_bestiary part
- current_bestiary = bestiary.current_bestiary
- # Redraw text (the top part)
- self.contents.clear
- # Draws who gave the current bestiary part
- self.contents.font.color = text_color(7)
- self.contents.font.bold = false
- self.contents.draw_text(0, 0, 440, 32, current_bestiary.owner, 1)
- # Draws the area
- self.contents.font.color = text_color(1)
- self.contents.draw_text(0, 32, 440, 32, current_bestiary.location, 1)
- # Draws a seperator line
- self.contents.font.color = text_color(0)
- self.contents.draw_text(0, 8, 480, 32,
- "__________________________________________", 1)
- # Refreshes the details.
- @details.refresh(current_bestiary)
- end # def
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- # Calls the parent method
- super
- # Updates the details if it is visible
- @details.visible = self.visible
- @details.update
- end # def
- end # class
- #==============================================================================
- # ** Window_Bestiary
- #------------------------------------------------------------------------------
- # This window designates the bestiary selection on the bestiary screen.
- #==============================================================================
- class Window_Bestiary < Window_Selectable
- # Constants
- MAIN_MENU_ICON_PATH = "Bestiary/Icons/mainmenu.png"
- # Attributes
- #attr_accessor :active_bestiaries # Tells whether active bestiaries are show or not
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(bestiary_set)
- super(0, 128, 640, 352)
- # Saves the bestiary set given
- @data = bestiary_set
- # Old data (stores refrences to old data)
- @old_data = {}
- # Amount of items
- @item_max = @data.size
- # The amount of items on each line (Items per row)
- @column_max = 6
- # Starts on index 0 (Top-Left)
- @index = 0
- # Active bestiaries are shown at start up
- @active_bestiaries = true
- # Creates Bitmap
- self.contents = Bitmap.new(width - 32, @item_max / @column_max * 96 + 96)
- refresh
- end # def
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- # Redraw text
- self.contents.clear
- # Draws the icons
- for i in 0...@item_max
- draw_icon(i,@data[i].current_bestiary.get_icon)
- end # for
- # Checks if there is a mainmenu icon
- if @active_bestiaries
- # An extra icon is drawn with the main menu icon (Another item)
- @item_max = @data.size + 1
- draw_icon(@item_max - 1, MAIN_MENU_ICON_PATH)
- else
- # There are as many items as there are bestiaries in the data
- @item_max = @data.size
- end # if
- # Checks if there are any items
- if @item_max == 0
- # Removes the cursor when there are no item
- @index = -1
- elsif @index == -1
- # Sets the cursor to the first element
- @index = 0
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Draws the icon of the bestiary at the i'th space
- #--------------------------------------------------------------------------
- def draw_icon(i, icon_name)
- # Calculates the x- and y-coordinates
- x = (i % @column_max) * 99 + 16
- y = (i / @column_max) * 96 - 10
- # Draws the given bestiary icon at the given position
- draw_bestiary_icon(icon_name, x, y + 18)
- end # def
- #--------------------------------------------------------------------------
- # * Sets a new set bestiaries as data
- #--------------------------------------------------------------------------
- def set_data(bestiary_set, active_bestiaries)
- if bestiary_set == @data && active_bestiaries == @active_bestiaries
- return
- end
- # Stores old data
- @old_data[[@data,@active_bestiaries]] = self.contents
- # Sets whether or not the bestiary_set is of the active bestiaries
- @active_bestiaries = active_bestiaries
- # Sets the bestiary_set as data
- @data = bestiary_set
- # Amount of items
- @item_max = @data.size
- # Creates Bitmap
- if @old_data[[@data,@active_bestiaries]] != nil
- self.contents = @old_data[[@data,@active_bestiaries]]
- else
- self.contents = Bitmap.new(width - 32, @item_max / @column_max * 96 + 96)
- end
- # Refreshes (redraws) the window with the new data
- refresh
- end
- #--------------------------------------------------------------------------
- # * Update Cursor Rectangle
- #--------------------------------------------------------------------------
- def update_cursor_rect
- # If cursor position is less than 0
- if @index < 0
- self.cursor_rect.empty
- return
- end # if
- # Get current row
- row = @index / @column_max
- # If current row is before top row
- if row < self.top_row
- # Scroll so that current row becomes top row
- self.top_row = row
- end # if
- # If current row is more to back than back row
- if row > self.top_row + (self.page_row_max - 1)
- # Scroll so that current row becomes back row
- self.top_row = row - (self.page_row_max - 1)
- end # if
- # Calculate cursor coordinates
- x = (@index % @column_max) * 99 + 8 #112
- y = (@index / @column_max) * 96 - self.oy
- self.cursor_rect.set(x, y, 96, 96)
- end # def
- #--------------------------------------------------------------------------
- # * Get Top Row
- #--------------------------------------------------------------------------
- def top_row
- # Divide y-coordinate of window contents transfer origin by 1 row
- # height of 96
- return self.oy / 96
- end # def
- #--------------------------------------------------------------------------
- # * Set Top Row
- # row : row shown on top
- #--------------------------------------------------------------------------
- def top_row=(row)
- row = row % row_max
- self.oy = row * 96
- end # def
- #--------------------------------------------------------------------------
- # * Get Number of Rows Displayable on 1 Page
- #--------------------------------------------------------------------------
- def page_row_max
- # Subtract a frame height of 32 from the window height, and divide it by
- # 1 row height of 96
- return (self.height - 32) / 96
- end # def
- #--------------------------------------------------------------------------
- # * Dispose
- #--------------------------------------------------------------------------
- def dispose
- super
- # Disposes the stored bitmaps
- @old_data.each_value {|value| value.dispose}
- end
- end # class
- #==============================================================================
- # ** Bestiary
- #------------------------------------------------------------------------------
- # Zeriab
- # 1.2
- # 2007-10-01 (year-month-day)
- #==============================================================================
- #==============================================================================
- # ** Scene_Bestiary
- #------------------------------------------------------------------------------
- # This window designates the bestiary selection on the bestiary screen.
- #==============================================================================
- class Scene_Bestiary
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(scene = Scene_Menu.new)
- # Gets the active bestiaries
- @active_bestiary_set = $game_bestiaries.get_active_bestiaries
- # Gets the completed bestiaries
- @completed_bestiary_set = $game_bestiaries.get_completed_bestiaries
- # Starts at the main_menu
- @last_index = 0
- # The completed bestiaries starts in the top-left corner
- @other_index = 0
- # Active bestiaries are shown when the bestiarylog has opened
- @active_bestiaries = true
- # Sets the current bestiary set
- @current_bestiary_set = @active_bestiary_set
- # The next scene it will skip to is the scene given
- @next_scene = scene
- end # def
- #--------------------------------------------------------------------------
- # * Main Processing
- #--------------------------------------------------------------------------
- def main
- # The background image
- @back_sprite = Sprite.new(Viewport.new(0,0,640,480))
- picname = BACK_PICS[$game_variables[BACK_VAR]]
- unless picname.is_a?(String)
- picname = BACK_PICS["standard"]
- end
- @back_sprite.bitmap = RPG::Cache.picture(BACKGROUND_DIR+picname)
- # Bestiary selection window
- @bestiary_select = Window_Bestiary.new(@current_bestiary_set)
- @bestiary_select.opacity = WINDOW_OPACITY
- # Bestiary info-header window
- @bestiary_header = Window_Bestiary_Header.new(@current_bestiary_set[0])
- @bestiary_header.opacity = WINDOW_OPACITY
- # Bestiary information window
- @bestiary_info = Window_Bestiary_Info.new
- @bestiary_info.opacity = WINDOW_OPACITY
- @bestiary_info.visible = false
- # Execute transition
- Graphics.transition
- # Scene Objects
- @scene_objects = [@back_sprite, @bestiary_select, @bestiary_header, @bestiary_info]
- # Main loop
- loop do
- # Update game screen
- Graphics.update
- # Update input information
- Input.update
- # Updates Scene Objects
- @scene_objects.each { |x| x.update}
- ## Frame update
- update
- # Abort loop if screen is changed
- break if $scene != self
- end # loop
- # Prepare for transition
- Graphics.freeze
- # Dispose Scene Objects
- @scene_objects.each { |x| x.dispose }
- end # def
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def switch
- # Switch to the previously remembered index (In case L or R was used)
- tmp = @bestiary_select.index
- @bestiary_select.index = @other_index
- @other_index = tmp
- # Plays the Cursor sound effect
- $game_system.se_play($data_system.cursor_se)
- # Checks if there are active bestiaries shown
- if @active_bestiaries
- # Completed bestiaries is to be shown. (Active bestiary NOT shown)
- @active_bestiaries = false
- # Sets the current bestiary_set to the completed bestiary_set
- @current_bestiary_set = @completed_bestiary_set
- else
- # Active bestiaries is to be shown.
- @active_bestiaries = true
- # Sets the current bestiary_set to the active bestiary_set
- @current_bestiary_set = @active_bestiary_set
- end # if
- # Sets the data in the selection window
- @bestiary_select.set_data(@current_bestiary_set, @active_bestiaries)
- # Checks if there are any fields
- if @bestiary_select.index > -1
- # Opdates the header
- @bestiary_header.refresh(@current_bestiary_set[0])
- else
- # Opdates the header
- @bestiary_header.refresh(1)
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # If RIGHT Button Is Pressed
- if Input.trigger?(Input::RIGHT) && !@bestiary_info.visible
- # Checks if there are any items to select.
- if @bestiary_select.index <= -1
- # Switches between active and completed bestiaries
- switch
- end # if
- end # if
- # If LEFT Button Is Pressed
- if Input.trigger?(Input::LEFT) && !@bestiary_info.visible
- # Checks if the last index is the same as the current. (All left)
- if @last_index == @bestiary_select.index || @bestiary_select.index <= -1
- # Switches between active and completed bestiaries
- switch
- end # if
- end # if
- # Checks if the index in @bestiary_select have changed
- if @last_index != @bestiary_select.index && @bestiary_select.index > -1
- # Updates the last_index
- @last_index = @bestiary_select.index
- # Updates the header
- @bestiary_header.refresh(@current_bestiary_set[@last_index])
- end # if
- # If C Button Is Pressed
- if Input.trigger?(Input::C) && @bestiary_select.index > -1
- # Checks if the main menu icon is present
- if @active_bestiaries
- # Checks that a bestiary is not select. (So it must be the main menu)
- if (@bestiary_select.index >= $game_bestiaries.get_active_bestiaries.size)
- # Plays the Cancel sound effect
- $game_system.se_play($data_system.cancel_se)
- # Changes the scene to the main menu
- $scene = Scene_Menu.new
- # Stops processing this method
- return
- end # if
- end # if
- # Plays the Decision sound effect
- $game_system.se_play($data_system.decision_se)
- # Change the visibility of the bestiary_info
- # Visible => Invisible, Invisible => Visible
- @bestiary_info.visible = !@bestiary_info.visible
- # The bestiary select is not active if the info is visible, else it is
- @bestiary_select.active = !@bestiary_info.visible
- # Refreshes the bestiary info
- @bestiary_info.refresh(@current_bestiary_set[@bestiary_select.index])
- end # if
- # If B Button Is Pressed
- if Input.trigger?(Input::B)
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # Switch to next scene
- $scene = @next_scene unless @bestiary_info.visible
- # Changes the bestiary info to become invisible
- @bestiary_info.visible = false
- # The bestiary select is active as the info is not visible
- @bestiary_select.active = true
- # Refreshes the bestiary info
- @bestiary_info.refresh(@current_bestiary_set[@bestiary_select.index])
- # Stops processing this method
- return
- end # if
- # If L Button Is Pressed
- if Input.trigger?(Input::L)
- switch
- end # if
- # If R Button Is Pressed
- if Input.trigger?(Input::R)
- switch
- end # if
- end # def
- end # class
- #==============================================================================
- # ** Scene_Load
- #------------------------------------------------------------------------------
- # Aliases and uses the on_decision method to reset $game_bestiaries on the proper
- # time.
- #==============================================================================
- class Scene_Load < Scene_File
- # Check if the alias already exists (To avoid F12 errors)
- unless self.method_defined?(:zeriab_bestiary_scene_load_on_decision)
- alias zeriab_bestiary_scene_load_on_decision :on_decision
- end
- def on_decision(*args)
- # Call the original method
- zeriab_bestiary_scene_load_on_decision(*args)
- # Check if the scene has changed
- unless $scene == self
- # Reset bestiary data
- $game_bestiaries.reset
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement