Zeriab

[RGSS] Quest Book

Nov 13th, 2011
947
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # * Window_Base
  3. #------------------------------------------------------------------------------
  4. #  Defines the draw_quest_icon method in Window_Base
  5. #==============================================================================
  6.  
  7. class Window_Base
  8.   #--------------------------------------------------------------------------
  9.   # * Draw Quest Icon
  10.   #     icon_name : filename of the icon
  11.   #     x         : draw spot x-coordinate
  12.   #     y         : draw spot y-coordinate
  13.   #--------------------------------------------------------------------------
  14.   def draw_quest_icon(icon_name, x, y)
  15.     begin
  16.       bitmap = RPG::Cache.picture(icon_name)
  17.     rescue
  18.       bitmap = RPG::Cache.picture(Data_Quest::PATH + Data_Quest::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_Quest
  30. #------------------------------------------------------------------------------
  31. #  A quest object.
  32. #  Stores information about the particular quest.
  33. #  All icons are assumed to be stored in the same directory
  34. #==============================================================================
  35.  
  36. class Data_Quest
  37.   # The path in the pictures folder
  38.   PATH = "Quest/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. # ** Quest_Criteria
  120. #------------------------------------------------------------------------------
  121. #  This class simple gets a criteria and tells if it is fulfilled or not.
  122. #  Used in Game_Quest to determine how much the quest 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 Quest_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 = "Quest_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_Quest
  206. #------------------------------------------------------------------------------
  207. #  Manages the process in the quests.
  208. #==============================================================================
  209.  
  210. class Game_Quest
  211.   attr_reader :completed
  212.   attr_reader :active
  213.   attr_reader :current_quest
  214.   #--------------------------------------------------------------------------
  215.   # * Object Initialization
  216.   #     quest : Must be a Data_Quest
  217.   #--------------------------------------------------------------------------
  218.   def initialize
  219.     @data = []
  220.     # Completed quest
  221.     @completed_quest = []
  222.     # A quest 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 quest
  232.   #--------------------------------------------------------------------------
  233.   def reset
  234.     # Remove the current quest
  235.     @current_quest = nil
  236.     # A quest 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_quest
  246.   #--------------------------------------------------------------------------
  247.   def update
  248.     # Return if the quest have completed
  249.     @completed = false
  250.     #------------------------------------------------------------------------
  251.     # Checks if the quest is completed. Assumes that @completed_quest only has
  252.     # 2 (or more) elements if the first element is a Data_Quest and the second
  253.     # is a Quest_Criteria.
  254.     #------------------------------------------------------------------------
  255.     if (@completed_quest.size > 1) && @completed_quest[1].check
  256.       @completed = true
  257.       @current_quest = @completed_quest[0]
  258.       # No need to update the quest further
  259.       return
  260.     end # if
  261.     # Checks the status of the quest
  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 quest part are met
  266.       if @data[j][1].check
  267.         # Sets the current_quest to the quest which conditions are met
  268.         @current_quest = @data[j][0]
  269.         # Checks if the quest should be considered completed
  270.         if i == 0 and @completed_quest.size <= 1
  271.           @completed = true
  272.           @completed_quest = @data[j]
  273.         end # if
  274.         break
  275.       end # if
  276.     end # for
  277.     # Checks if the quest should be actived
  278.     if !@active && @current_quest.is_a?(Data_Quest)
  279.       @active = true  # Is actived
  280.     end
  281.   end # def
  282.  
  283.   #--------------------------------------------------------------------------
  284.   # * Add a quest (quest part)
  285.   #     quest : Must be a Data_Quest
  286.   #--------------------------------------------------------------------------
  287.   def add_quest(quest, condition)
  288.     if quest.is_a?(Data_Quest) && condition.is_a?(Quest_Criteria)
  289.       @data.push([quest,condition])
  290.     end # if
  291.   end # def
  292.  
  293.   #--------------------------------------------------------------------------
  294.   # * Set the completed quest part
  295.   #     quest : Must be a Data_Quest
  296.   #--------------------------------------------------------------------------
  297.   def set_completed_quest(quest, condition)
  298.     if quest.is_a?(Data_Quest)
  299.       @completed_quest = [quest, 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_Quests
  317. #------------------------------------------------------------------------------
  318. #  This class handles quests. It's a wrapper for the built-in class "Array."
  319. #  Refer to "$game_quests" for the instance of this class.
  320. #  
  321. #  The quest potion 0 is considered to be the main quest. ($game_quests[0])
  322. #==============================================================================
  323.  
  324. class Game_Quests
  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 Quest
  335.   #     quest_id : quest ID
  336.   #--------------------------------------------------------------------------
  337.   def [](quest_id)
  338.     return @data[quest_id]
  339.   end # def
  340.   #--------------------------------------------------------------------------
  341.   # * Set Quest
  342.   #     quest_id : quest ID
  343.   #     quest    : the quest
  344.   #--------------------------------------------------------------------------
  345.   def []=(quest_id, quest)
  346.     if quest.is_a?(Game_Quest) && quest_id % @data.size == 0
  347.       @data[quest_id] = quest
  348.     end  # if
  349.   end # def
  350.   #--------------------------------------------------------------------------
  351.   # * Add Quest
  352.   #     quest : the quest
  353.   #--------------------------------------------------------------------------
  354.   def add(quest)
  355.     if quest.is_a?(Game_Quest)
  356.       @data.push(quest)
  357.     end # if
  358.   end # def
  359.   #--------------------------------------------------------------------------
  360.   # * Resets the quests
  361.   #--------------------------------------------------------------------------
  362.   def reset
  363.     for quest in @data
  364.       quest.reset
  365.     end # if
  366.   end # def
  367.   #--------------------------------------------------------------------------
  368.   # * Gets active quests. Newest will be listed first
  369.   #   Note: The main quest if active will always have position 0. (result[0])
  370.   #--------------------------------------------------------------------------
  371.   def get_active_quests
  372.     result = []
  373.     # Goes through the quests
  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 quest 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 quest have index 0 followed by the newest
  390.     # quest 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 quests. Newest will be listed first
  397.   #   Note: The main quest will always be on position 0. (result[0])
  398.   #--------------------------------------------------------------------------
  399.   def get_completed_quests
  400.     result = []
  401.     # Goes through the quests
  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 quest 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 quest have index 0 followed by the newest
  417.     # quest 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 quests
  425. $game_quests = Game_Quests.new
  426.  
  427. #==============================================================================
  428. # ** Window_Questbook_Header
  429. #------------------------------------------------------------------------------
  430. #  This window designates quest information in the header of the questbook.
  431. #==============================================================================
  432.  
  433. class Window_Questbook_Header < Window_Base
  434.   #--------------------------------------------------------------------------
  435.   # * Object Initialization
  436.   #       quest : The quest which information will be used
  437.   #--------------------------------------------------------------------------
  438.   def initialize(quest)
  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(quest)
  444.   end # def
  445.  
  446.   #--------------------------------------------------------------------------
  447.   # * Refresh
  448.   #       quest : The quest which information will be used
  449.   #--------------------------------------------------------------------------
  450.   def refresh(quest)
  451.     # Redraw text
  452.     self.contents.clear
  453.     # checks if the quest is a Game_Quest.
  454.     if quest.is_a?(Game_Quest)
  455.       # Gets the current quest part
  456.       current_quest = quest.current_quest
  457.     else
  458.       if quest.is_a?(Integer)
  459.         # Draws the no completed quest header
  460.         draw_noquest_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 quest next to "Who:" in gray
  479.     self.contents.font.color = text_color(7)
  480.     self.contents.draw_text(80, 0, 540, 32, current_quest.owner)
  481.     # Draws the location of the quest next to "Where:" in blue
  482.     self.contents.font.color = text_color(1)
  483.     self.contents.draw_text(80, 32, 540, 32, current_quest.location)
  484.     # Draws the goal of the quest next to "What:" in yellow
  485.     self.contents.font.color = text_color(6)
  486.     self.contents.draw_text(80, 64, 540, 32, current_quest.goal)
  487.   end # def
  488.  
  489.   #--------------------------------------------------------------------------
  490.   # * Draws the header in the case where no quests have been completed
  491.   #--------------------------------------------------------------------------
  492.   def draw_noquest_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 quests 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_Questbook_Header
  512. #------------------------------------------------------------------------------
  513. #  This window designates quest information in the questbook.
  514. #==============================================================================
  515.  
  516. class Window_Questbook_Info < Window_Base
  517.  
  518.   #============================================================================
  519.   # ** Details
  520.   #----------------------------------------------------------------------------
  521.   #  This window contains the details of the quest.
  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.     #       quest : The quest which information will be drawn
  542.     #------------------------------------------------------------------------
  543.     def refresh(quest)
  544.       # Resets the position of the bitmap
  545.       self.oy = 0
  546.       # Splits the info into lines
  547.       info = quest.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.   #       quest : The quest which information will be drawn (Game_Quest)
  616.   #--------------------------------------------------------------------------
  617.   def refresh(quest)
  618.     return unless quest.is_a?(Game_Quest)
  619.     # Gets the current_quest part
  620.     current_quest = quest.current_quest
  621.     # Redraw text (the top part)
  622.     self.contents.clear
  623.     # Draws who gave the current quest 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_quest.owner, 1)
  627.     # Draws the area
  628.     self.contents.font.color = text_color(1)
  629.     self.contents.draw_text(0, 32, 440, 32, current_quest.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_quest)
  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_Questbook
  653. #------------------------------------------------------------------------------
  654. #  This window designates the quest selection on the questbook screen.
  655. #==============================================================================
  656.  
  657. class Window_Questbook < Window_Selectable
  658.   # Constants
  659.   MAIN_MENU_ICON_PATH = "Quest/Icons/mainmenu.png"
  660.  
  661.   # Attributes
  662.   #attr_accessor   :active_quests # Tells whether active quests are show or not
  663.  
  664.   #--------------------------------------------------------------------------
  665.   # * Object Initialization
  666.   #--------------------------------------------------------------------------
  667.   def initialize(questset)
  668.     super(0, 128, 640, 352)
  669.     # Saves the quest set given
  670.     @data = questset
  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 quests are shown at start up
  680.     @active_quests = 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_quest.get_icon)
  695.     end # for
  696.     # Checks if there is a mainmenu icon
  697.     if @active_quests
  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 quests 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 quest 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 quest icon at the given position
  723.     draw_quest_icon(icon_name, x, y + 18)
  724.   end # def
  725.  
  726.   #--------------------------------------------------------------------------
  727.   # * Sets a new set quests as data
  728.   #--------------------------------------------------------------------------
  729.   def set_data(questset, active_quests)
  730.     if questset == @data && active_quests == @active_quests
  731.       return
  732.     end
  733.     # Stores old data
  734.     @old_data[[@data,@active_quests]] = self.contents
  735.     # Sets whether or not the questset is of the active quests
  736.     @active_quests = active_quests
  737.     # Sets the questset as data
  738.     @data = questset
  739.     # Amount of items
  740.     @item_max = @data.size
  741.     # Creates Bitmap
  742.     if @old_data[[@data,@active_quests]] != nil
  743.       self.contents = @old_data[[@data,@active_quests]]
  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. # ** Questbook
  818. #------------------------------------------------------------------------------
  819. # Zeriab
  820. # 1.2
  821. # 2007-10-01 (year-month-day)
  822. #==============================================================================
  823.  
  824. #==============================================================================
  825. # ** Scene_Questbook
  826. #------------------------------------------------------------------------------
  827. #  This window designates the quest selection on the questbook screen.
  828. #==============================================================================
  829.  
  830. class Scene_Questbook
  831.   #--------------------------------------------------------------------------
  832.   # * Object Initialization
  833.   #--------------------------------------------------------------------------
  834.   def initialize(scene = Scene_Menu.new)
  835.     # Gets the active quests
  836.     @active_questset = $game_quests.get_active_quests
  837.     # Gets the completed quests
  838.     @completed_questset = $game_quests.get_completed_quests
  839.     # Starts at the main_menu
  840.     @last_index = 0
  841.     # The completed quests starts in the top-left corner
  842.     @other_index = 0
  843.     # Active quests are shown when the questlog has opened
  844.     @active_quests = true
  845.     # Sets the current quest set
  846.     @current_questset = @active_questset
  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.     # Quest selection window
  863.     @quest_select = Window_Questbook.new(@current_questset)
  864.     @quest_select.opacity = WINDOW_OPACITY
  865.     # Quest info-header window
  866.     @quest_header = Window_Questbook_Header.new(@current_questset[0])
  867.     @quest_header.opacity = WINDOW_OPACITY
  868.     # Quest information window
  869.     @quest_info = Window_Questbook_Info.new
  870.     @quest_info.opacity = WINDOW_OPACITY
  871.     @quest_info.visible = false
  872.     # Execute transition
  873.     Graphics.transition
  874.     # Scene Objects
  875.     @scene_objects = [@back_sprite, @quest_select, @quest_header, @quest_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 = @quest_select.index
  901.     @quest_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 quests shown
  906.     if @active_quests
  907.       # Completed quests is to be shown. (Active quest NOT shown)
  908.       @active_quests = false
  909.       # Sets the current questset to the completed questset
  910.       @current_questset = @completed_questset
  911.     else
  912.       # Active quests is to be shown.
  913.       @active_quests = true
  914.       # Sets the current questset to the active questset
  915.       @current_questset = @active_questset
  916.     end # if
  917.     # Sets the data in the selection window
  918.     @quest_select.set_data(@current_questset, @active_quests)
  919.     # Checks if there are any fields
  920.     if @quest_select.index > -1
  921.       # Opdates the header
  922.       @quest_header.refresh(@current_questset[0])
  923.     else
  924.       # Opdates the header
  925.       @quest_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) && !@quest_info.visible
  935.       # Checks if there are any items to select.
  936.       if @quest_select.index <= -1
  937.         # Switches between active and completed quests
  938.         switch
  939.       end # if
  940.     end # if
  941.     # If LEFT Button Is Pressed
  942.     if Input.trigger?(Input::LEFT) && !@quest_info.visible
  943.       # Checks if the last index is the same as the current. (All left)
  944.       if @last_index == @quest_select.index || @quest_select.index <= -1
  945.         # Switches between active and completed quests
  946.         switch
  947.       end # if
  948.     end # if
  949.     # Checks if the index in @quest_select have changed
  950.     if @last_index != @quest_select.index && @quest_select.index > -1
  951.       # Updates the last_index
  952.       @last_index = @quest_select.index
  953.       # Updates the header
  954.       @quest_header.refresh(@current_questset[@last_index])
  955.     end # if
  956.     # If C Button Is Pressed
  957.     if Input.trigger?(Input::C) && @quest_select.index > -1
  958.       # Checks if the main menu icon is present
  959.       if @active_quests
  960.         # Checks that a quest is not select. (So it must be the main menu)
  961.         if (@quest_select.index >= $game_quests.get_active_quests.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 quest_info
  973.       # Visible => Invisible, Invisible => Visible        
  974.       @quest_info.visible = !@quest_info.visible
  975.       # The quest select is not active if the info is visible, else it is
  976.       @quest_select.active = !@quest_info.visible
  977.       # Refreshes the quest info
  978.       @quest_info.refresh(@current_questset[@quest_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 @quest_info.visible
  986.       # Changes the quest info to become invisible
  987.       @quest_info.visible = false
  988.       # The quest select is active as the info is not visible
  989.       @quest_select.active = true
  990.       # Refreshes the quest info
  991.       @quest_info.refresh(@current_questset[@quest_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_quests 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_questbook_scene_load_on_decision)
  1016.     alias zeriab_questbook_scene_load_on_decision :on_decision
  1017.   end
  1018.   def on_decision(*args)
  1019.     # Call the original method
  1020.     zeriab_questbook_scene_load_on_decision(*args)
  1021.     # Check if the scene has changed
  1022.     unless $scene == self
  1023.       # Reset quest data
  1024.       $game_quests.reset
  1025.     end
  1026.   end
  1027. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×