Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # * Window_Base
- #------------------------------------------------------------------------------
- # Defines the draw_quest_icon method in Window_Base
- #==============================================================================
- class Window_Base
- #--------------------------------------------------------------------------
- # * Draw Quest Icon
- # icon_name : filename of the icon
- # x : draw spot x-coordinate
- # y : draw spot y-coordinate
- #--------------------------------------------------------------------------
- def draw_quest_icon(icon_name, x, y)
- begin
- bitmap = RPG::Cache.picture(icon_name)
- rescue
- bitmap = RPG::Cache.picture(Data_Quest::PATH + Data_Quest::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_Quest
- #------------------------------------------------------------------------------
- # A quest object.
- # Stores information about the particular quest.
- # All icons are assumed to be stored in the same directory
- #==============================================================================
- class Data_Quest
- # The path in the pictures folder
- PATH = "Quest/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
- #==============================================================================
- # ** Quest_Criteria
- #------------------------------------------------------------------------------
- # This class simple gets a criteria and tells if it is fulfilled or not.
- # Used in Game_Quest to determine how much the quest 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 Quest_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 = "Quest_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_Quest
- #------------------------------------------------------------------------------
- # Manages the process in the quests.
- #==============================================================================
- class Game_Quest
- attr_reader :completed
- attr_reader :active
- attr_reader :current_quest
- #--------------------------------------------------------------------------
- # * Object Initialization
- # quest : Must be a Data_Quest
- #--------------------------------------------------------------------------
- def initialize
- @data = []
- # Completed quest
- @completed_quest = []
- # A quest is not completed in the start
- @completed = false
- # Neither is it active
- @active = false
- # Updates
- update
- end # def
- #--------------------------------------------------------------------------
- # * Resets the quest
- #--------------------------------------------------------------------------
- def reset
- # Remove the current quest
- @current_quest = nil
- # A quest is not completed in the start
- @completed = false
- # Neither is it active
- @active = false
- # Updates
- update
- end # def
- #--------------------------------------------------------------------------
- # * Updates the current_quest
- #--------------------------------------------------------------------------
- def update
- # Return if the quest have completed
- @completed = false
- #------------------------------------------------------------------------
- # Checks if the quest is completed. Assumes that @completed_quest only has
- # 2 (or more) elements if the first element is a Data_Quest and the second
- # is a Quest_Criteria.
- #------------------------------------------------------------------------
- if (@completed_quest.size > 1) && @completed_quest[1].check
- @completed = true
- @current_quest = @completed_quest[0]
- # No need to update the quest further
- return
- end # if
- # Checks the status of the quest
- for i in 0...@data.size
- # Runs through the elements backwards.
- j = @data.size - (i + 1)
- # Checks if the conditions for the quest part are met
- if @data[j][1].check
- # Sets the current_quest to the quest which conditions are met
- @current_quest = @data[j][0]
- # Checks if the quest should be considered completed
- if i == 0 and @completed_quest.size <= 1
- @completed = true
- @completed_quest = @data[j]
- end # if
- break
- end # if
- end # for
- # Checks if the quest should be actived
- if !@active && @current_quest.is_a?(Data_Quest)
- @active = true # Is actived
- end
- end # def
- #--------------------------------------------------------------------------
- # * Add a quest (quest part)
- # quest : Must be a Data_Quest
- #--------------------------------------------------------------------------
- def add_quest(quest, condition)
- if quest.is_a?(Data_Quest) && condition.is_a?(Quest_Criteria)
- @data.push([quest,condition])
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Set the completed quest part
- # quest : Must be a Data_Quest
- #--------------------------------------------------------------------------
- def set_completed_quest(quest, condition)
- if quest.is_a?(Data_Quest)
- @completed_quest = [quest, 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_Quests
- #------------------------------------------------------------------------------
- # This class handles quests. It's a wrapper for the built-in class "Array."
- # Refer to "$game_quests" for the instance of this class.
- #
- # The quest potion 0 is considered to be the main quest. ($game_quests[0])
- #==============================================================================
- class Game_Quests
- # Adds a method to read the data
- attr_reader :data
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- @data = []
- end # def
- #--------------------------------------------------------------------------
- # * Get Quest
- # quest_id : quest ID
- #--------------------------------------------------------------------------
- def [](quest_id)
- return @data[quest_id]
- end # def
- #--------------------------------------------------------------------------
- # * Set Quest
- # quest_id : quest ID
- # quest : the quest
- #--------------------------------------------------------------------------
- def []=(quest_id, quest)
- if quest.is_a?(Game_Quest) && quest_id % @data.size == 0
- @data[quest_id] = quest
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Add Quest
- # quest : the quest
- #--------------------------------------------------------------------------
- def add(quest)
- if quest.is_a?(Game_Quest)
- @data.push(quest)
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Resets the quests
- #--------------------------------------------------------------------------
- def reset
- for quest in @data
- quest.reset
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Gets active quests. Newest will be listed first
- # Note: The main quest if active will always have position 0. (result[0])
- #--------------------------------------------------------------------------
- def get_active_quests
- result = []
- # Goes through the quests
- 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 quest 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 quest have index 0 followed by the newest
- # quest at index 1, the second newest at index 2 and so on.
- result.reverse!
- # Returns the resulting array
- return result
- end # def
- #--------------------------------------------------------------------------
- # * Gets completed quests. Newest will be listed first
- # Note: The main quest will always be on position 0. (result[0])
- #--------------------------------------------------------------------------
- def get_completed_quests
- result = []
- # Goes through the quests
- 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 quest is active and not completed (index 0 in @data)
- if @data[0].completed
- result.push(@data[0])
- end # if
- # Reverse result so the main quest have index 0 followed by the newest
- # quest 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 quests
- $game_quests = Game_Quests.new
- #==============================================================================
- # ** Window_Questbook_Header
- #------------------------------------------------------------------------------
- # This window designates quest information in the header of the questbook.
- #==============================================================================
- class Window_Questbook_Header < Window_Base
- #--------------------------------------------------------------------------
- # * Object Initialization
- # quest : The quest which information will be used
- #--------------------------------------------------------------------------
- def initialize(quest)
- super(0, 0, 640, 128)
- # Creates the Bitmap
- self.contents = Bitmap.new(width - 32, height - 32)
- # Draws the header
- refresh(quest)
- end # def
- #--------------------------------------------------------------------------
- # * Refresh
- # quest : The quest which information will be used
- #--------------------------------------------------------------------------
- def refresh(quest)
- # Redraw text
- self.contents.clear
- # checks if the quest is a Game_Quest.
- if quest.is_a?(Game_Quest)
- # Gets the current quest part
- current_quest = quest.current_quest
- else
- if quest.is_a?(Integer)
- # Draws the no completed quest header
- draw_noquest_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 quest next to "Who:" in gray
- self.contents.font.color = text_color(7)
- self.contents.draw_text(80, 0, 540, 32, current_quest.owner)
- # Draws the location of the quest next to "Where:" in blue
- self.contents.font.color = text_color(1)
- self.contents.draw_text(80, 32, 540, 32, current_quest.location)
- # Draws the goal of the quest next to "What:" in yellow
- self.contents.font.color = text_color(6)
- self.contents.draw_text(80, 64, 540, 32, current_quest.goal)
- end # def
- #--------------------------------------------------------------------------
- # * Draws the header in the case where no quests have been completed
- #--------------------------------------------------------------------------
- def draw_noquest_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 quests 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_Questbook_Header
- #------------------------------------------------------------------------------
- # This window designates quest information in the questbook.
- #==============================================================================
- class Window_Questbook_Info < Window_Base
- #============================================================================
- # ** Details
- #----------------------------------------------------------------------------
- # This window contains the details of the quest.
- # 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
- # quest : The quest which information will be drawn
- #------------------------------------------------------------------------
- def refresh(quest)
- # Resets the position of the bitmap
- self.oy = 0
- # Splits the info into lines
- info = quest.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
- # quest : The quest which information will be drawn (Game_Quest)
- #--------------------------------------------------------------------------
- def refresh(quest)
- return unless quest.is_a?(Game_Quest)
- # Gets the current_quest part
- current_quest = quest.current_quest
- # Redraw text (the top part)
- self.contents.clear
- # Draws who gave the current quest part
- self.contents.font.color = text_color(7)
- self.contents.font.bold = false
- self.contents.draw_text(0, 0, 440, 32, current_quest.owner, 1)
- # Draws the area
- self.contents.font.color = text_color(1)
- self.contents.draw_text(0, 32, 440, 32, current_quest.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_quest)
- 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_Questbook
- #------------------------------------------------------------------------------
- # This window designates the quest selection on the questbook screen.
- #==============================================================================
- class Window_Questbook < Window_Selectable
- # Constants
- MAIN_MENU_ICON_PATH = "Quest/Icons/mainmenu.png"
- # Attributes
- #attr_accessor :active_quests # Tells whether active quests are show or not
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(questset)
- super(0, 128, 640, 352)
- # Saves the quest set given
- @data = questset
- # 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 quests are shown at start up
- @active_quests = 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_quest.get_icon)
- end # for
- # Checks if there is a mainmenu icon
- if @active_quests
- # 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 quests 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 quest 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 quest icon at the given position
- draw_quest_icon(icon_name, x, y + 18)
- end # def
- #--------------------------------------------------------------------------
- # * Sets a new set quests as data
- #--------------------------------------------------------------------------
- def set_data(questset, active_quests)
- if questset == @data && active_quests == @active_quests
- return
- end
- # Stores old data
- @old_data[[@data,@active_quests]] = self.contents
- # Sets whether or not the questset is of the active quests
- @active_quests = active_quests
- # Sets the questset as data
- @data = questset
- # Amount of items
- @item_max = @data.size
- # Creates Bitmap
- if @old_data[[@data,@active_quests]] != nil
- self.contents = @old_data[[@data,@active_quests]]
- 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
- #==============================================================================
- # ** Questbook
- #------------------------------------------------------------------------------
- # Zeriab
- # 1.2
- # 2007-10-01 (year-month-day)
- #==============================================================================
- #==============================================================================
- # ** Scene_Questbook
- #------------------------------------------------------------------------------
- # This window designates the quest selection on the questbook screen.
- #==============================================================================
- class Scene_Questbook
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(scene = Scene_Menu.new)
- # Gets the active quests
- @active_questset = $game_quests.get_active_quests
- # Gets the completed quests
- @completed_questset = $game_quests.get_completed_quests
- # Starts at the main_menu
- @last_index = 0
- # The completed quests starts in the top-left corner
- @other_index = 0
- # Active quests are shown when the questlog has opened
- @active_quests = true
- # Sets the current quest set
- @current_questset = @active_questset
- # 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)
- # Quest selection window
- @quest_select = Window_Questbook.new(@current_questset)
- @quest_select.opacity = WINDOW_OPACITY
- # Quest info-header window
- @quest_header = Window_Questbook_Header.new(@current_questset[0])
- @quest_header.opacity = WINDOW_OPACITY
- # Quest information window
- @quest_info = Window_Questbook_Info.new
- @quest_info.opacity = WINDOW_OPACITY
- @quest_info.visible = false
- # Execute transition
- Graphics.transition
- # Scene Objects
- @scene_objects = [@back_sprite, @quest_select, @quest_header, @quest_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 = @quest_select.index
- @quest_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 quests shown
- if @active_quests
- # Completed quests is to be shown. (Active quest NOT shown)
- @active_quests = false
- # Sets the current questset to the completed questset
- @current_questset = @completed_questset
- else
- # Active quests is to be shown.
- @active_quests = true
- # Sets the current questset to the active questset
- @current_questset = @active_questset
- end # if
- # Sets the data in the selection window
- @quest_select.set_data(@current_questset, @active_quests)
- # Checks if there are any fields
- if @quest_select.index > -1
- # Opdates the header
- @quest_header.refresh(@current_questset[0])
- else
- # Opdates the header
- @quest_header.refresh(1)
- end # if
- end # def
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # If RIGHT Button Is Pressed
- if Input.trigger?(Input::RIGHT) && !@quest_info.visible
- # Checks if there are any items to select.
- if @quest_select.index <= -1
- # Switches between active and completed quests
- switch
- end # if
- end # if
- # If LEFT Button Is Pressed
- if Input.trigger?(Input::LEFT) && !@quest_info.visible
- # Checks if the last index is the same as the current. (All left)
- if @last_index == @quest_select.index || @quest_select.index <= -1
- # Switches between active and completed quests
- switch
- end # if
- end # if
- # Checks if the index in @quest_select have changed
- if @last_index != @quest_select.index && @quest_select.index > -1
- # Updates the last_index
- @last_index = @quest_select.index
- # Updates the header
- @quest_header.refresh(@current_questset[@last_index])
- end # if
- # If C Button Is Pressed
- if Input.trigger?(Input::C) && @quest_select.index > -1
- # Checks if the main menu icon is present
- if @active_quests
- # Checks that a quest is not select. (So it must be the main menu)
- if (@quest_select.index >= $game_quests.get_active_quests.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 quest_info
- # Visible => Invisible, Invisible => Visible
- @quest_info.visible = !@quest_info.visible
- # The quest select is not active if the info is visible, else it is
- @quest_select.active = !@quest_info.visible
- # Refreshes the quest info
- @quest_info.refresh(@current_questset[@quest_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 @quest_info.visible
- # Changes the quest info to become invisible
- @quest_info.visible = false
- # The quest select is active as the info is not visible
- @quest_select.active = true
- # Refreshes the quest info
- @quest_info.refresh(@current_questset[@quest_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_quests on the proper
- # time.
- #==============================================================================
- class Scene_Load < Scene_File
- # Check if the alias already exists (To avoid F12 errors)
- unless self.method_defined?(:zeriab_questbook_scene_load_on_decision)
- alias zeriab_questbook_scene_load_on_decision :on_decision
- end
- def on_decision(*args)
- # Call the original method
- zeriab_questbook_scene_load_on_decision(*args)
- # Check if the scene has changed
- unless $scene == self
- # Reset quest data
- $game_quests.reset
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement