modern_algebra

Quest Journal 1.0.3 [VXA]

Feb 19th, 2012
39,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 128.20 KB | None | 0 0
  1. #==============================================================================
  2. #    Quest Journal [VXA]
  3. #    Version: 1.0.3
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: 24 September 2012
  6. #    Support: http://rmrk.net/index.php/topic,45127.0.html
  7. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8. #  Description:
  9. #
  10. #    This script provides a graphical interface for showing quest progress. It
  11. #   is objective-based, meaning that you choose when to reveal objectives and
  12. #   you can set it so that they show up as complete or failed. That said, this
  13. #   script does not build quests for you; it is only a supplementary scene for
  14. #   showing them. As such, you need to event all of the quests yourself and
  15. #   update quest progress via script call. Therefore, pay close attention to
  16. #   the instructions here and in the Editable Regions at lines 232 and 612.
  17. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18. #  Instructions:
  19. #
  20. #    Paste this script into its own slot or slots, above Main and below
  21. #   Materials. If you are using the menu access feature, you should put any
  22. #   other menu scripts above this one.
  23. #
  24. #    All of the configuration is done in the QuestData module. While it is not
  25. #   necessary, it is recommended that you separate the configuration module
  26. #   from the rest of the script by cutting and pasting it into its own slot in
  27. #   the Script Editor (as you will see if you have the demo). The reason for
  28. #   this is that, if and when this script gets updated, you can preserve the
  29. #   configuration section and only replace the other parts of the script. If
  30. #   you wish to do that, you must cut everything from the first line down to
  31. #   the final end of the module. The first lines of the body script should be
  32. #   the equals bar right above # ** Game_Quest. Again, it's up to you whether
  33. #   you do it.
  34. #
  35. #    You can go to EDITABLE REGION A at line 232 to configure the default
  36. #   settings for the script. All of these will work fine without modification,
  37. #   of course, but even if do not want to configure now, you should familiarize
  38. #   yourself with all the settings so that you can make the best use of your
  39. #   script. I have included tons of settings so that you can make the Quest
  40. #   Journal unique for your game, even down to the order in which each section
  41. #   of the info window is drawn. A brief description of each setting is
  42. #   included either to the right or directly above each constant.
  43. #
  44. #    EDITABLE REGION B is the real heart of the script however - this is where
  45. #   you fill in all of the details for the quests. Read the instructions at
  46. #   line 612 very carefully!
  47. #
  48. #    You can activate and access a quest with this code in the Script event
  49. #   command:
  50. #
  51. #        quest(quest_id)
  52. #          quest_id : the integer ID of the quest you want to access
  53. #
  54. #   From that, you can access or alter any relevant data stored in the quest,
  55. #   like name, description, objectives, etc... Example:
  56. #         quest(1).name = "Rest in Pieces"
  57. #
  58. #    More relevantly, when it comes to controlling the progress of quests the
  59. #   following codes can be used in a Script event command. The arguments are
  60. #   the same for each command so I only explain them once. All of them are
  61. #   pretty self-explanatory and using any of them will activate the quest
  62. #   (unless you are using the MANUAL REVEAL setting at line 267).
  63. #    
  64. #        reveal_objective(quest_id, objective_id_1, ..., objective_id_n)
  65. #            quest_id : the integer ID of the quest you want to access.
  66. #            objective_id_1, ..., objective_id_n : a list of the IDs of the
  67. #              objectives you want to operate on. It can be as few as one or as
  68. #              many as all of them.
  69. #          Will show the listed objectives in the Quest's information
  70. #
  71. #        conceal_objective(quest_id, objective_id_1, ..., objective_id_n)
  72. #          Will hide the listed objectives in the Quest's information
  73. #
  74. #        complete_objective(quest_id, objective_id_1, ..., objective_id_n)
  75. #          Changes the colour of the listed objectives to the completed colour.
  76. #          The quest is completed once all prime objectives are.
  77. #
  78. #        uncomplete_objective (quest_id, objective_id_1, ..., objective_id_n)
  79. #          Changes the status of the listed complete objectives back to active
  80. #
  81. #        fail_objective(quest_id, objective_id_1, ..., objective_id_n)
  82. #          Changes the colour of the listed objectives to the failed colour.
  83. #          The quest is failed once one prime objective is.
  84. #
  85. #        unfail_objective(quest_id, objective_id_1, ..., objective_id_n)
  86. #          Changes the status of the listed failed objectives back to active
  87. #
  88. #        change_reward_status(quest_id, value)
  89. #            value : either true or false. If excluded, defaults to true.
  90. #          Totally optional, but this is just a personal switch which you can
  91. #          turn on when the reward is given. You can then make it a condition
  92. #          so you don't reward the players more than once. (see line 180)
  93. #
  94. #  EXAMPLES:
  95. #    reveal_objective(1, 0)
  96. #      This would reveal the first objective of the quest with ID 1
  97. #    complete_objective(6, 2, 3)
  98. #      This would complete the third & fourth objectives of the quest with ID 6
  99. #    change_reward_status(8)
  100. #      This would set the reward switch to true for the quest with ID 8.
  101. #
  102. #   Another new feature is the ability to set rewards that will show up in the
  103. #  menu (see EDITABLE REGION B). In addition to that, you can use the following
  104. #  code to automatically distribute the specified rewards for a quest if the
  105. #  quest is complete and no reward has yet been given:
  106. #
  107. #        distribute_quest_rewards(quest_id)
  108. #          quest_id : the ID of the quest whose rewards you want to distribute
  109. #
  110. #   Of course, it can only distribute the material rewards (items, weapons,
  111. #   armors, gold, or exp). It won't distribute rewards you specify by string.
  112. #   To that end though, you can also use this code in a conditional branch and
  113. #   it will be satisfied only if it distributes the rewards. Thus, if you
  114. #   wanted to add some special rewards or do things like that, you can just put
  115. #   that in the branch for when it is true. This feature is not really
  116. #   recommended, since I think it is better to do it by events.
  117. #
  118. #    Other codes for the Script event command that can be useful are:
  119. #    
  120. #        reset_quest(quest_id)
  121. #            quest_id : the integer ID of the quest you want to access.
  122. #          This will re-initialize the quest, meaning all quest progress to
  123. #          date will be lost
  124. #
  125. #        delete_quest(quest_id)
  126. #          Deactivates the quest and resets it
  127. #
  128. #        conceal_quest(quest_id)
  129. #          Deactivates the quest so it won't show up in the scene, but progress
  130. #          is saved
  131. #
  132. #        reveal_quest(quest_id)
  133. #          Activates or reactivates the quest. This command is NECESSARY if
  134. #          MANUAL_REVEAL at line 284 is true or it has previously been
  135. #          concealed. Otherwise, it is sufficient just to operate on the quest
  136. #
  137. #        change_quest_access(:symbol)
  138. #          :symbol must be one of six options (include the colon!):
  139. #            :disable - prevents access to the quest scene (greys out in menu)
  140. #            :enable - enables access to the quest scene
  141. #            :disable_menu - this removes the quest option from the menu
  142. #            :enable_menu - this adds the quest option to the menu
  143. #            :disable_map - this prevents access by key from the map
  144. #            :enable_map - this allows access by key to the map
  145. #
  146. #        change_quest_background("bg_filename", bg_opacity, bg_blend_type)
  147. #            bg_filename   : the filename of the picture for the background in  
  148. #              the Pictures folder
  149. #            bg_opacity    : the opacity of the background graphic. If
  150. #              excluded, this defaults to the value of the setting at line 434.
  151. #            bg_blend_type : the blend type of the background graphic. If
  152. #              excluded, this defaults to the value of the setting at line 437.
  153. #
  154. #        change_quest_windows ("windowskin_filename", tone, opacity)
  155. #            windowskin_filename : the name of the Window graphic in the
  156. #              System folder of Graphics
  157. #            opacity             : the opacity of the windows. If excluded,
  158. #              this defaults to the value of the setting at line 423.
  159. #            blend_type          : the blend_type of the windows. If excluded,
  160. #              this defaults to the value of the setting at line 426.
  161. #
  162. #    Also, there are a few codes that can be used in the Script command of a
  163. #   conditional branch. I note here that all of these are optional. You could
  164. #   use switch and variable checks and monitor quest progress solely through
  165. #   events. However, these commands make it a little easier and they are:
  166. #
  167. #        quest_revealed?(quest_id)
  168. #            quest_id : the integer ID of the quest you want to access.
  169. #          This is satisfied if the quest has been activated.
  170. #
  171. #        quest_complete?(quest_id)
  172. #          This is satisfied if all prime objectives of the quest are complete
  173. #
  174. #        quest_failed?(quest_id)
  175. #          This is satisfied if any prime objective of the quest is failed
  176. #
  177. #        quest_rewarded?(quest_id)
  178. #          This is satisfied if you have changed the reward status to true.
  179. #
  180. #        objective_revealed?(quest_id, objective_id_1, ... objective_id_n)
  181. #            objective_id_1, ..., objective_id_n : a list of the IDs of the
  182. #              objectives you want to operate on. It can be as few as one or as
  183. #              many as all of them.
  184. #          This is satisfied if the listed objectives have been revealed
  185. #
  186. #        objective_active?(quest_id, objective_id_1, ... objective_id_n)
  187. #          This is satisfied if all the listed objectives are revealed and
  188. #          neither complete nor failed.
  189. #
  190. #        objective_complete?(quest_id, objective_id_1, ... objective_id_n)
  191. #          This is satisfied if all the listed objectives have been completed
  192. #
  193. #        objective_failed?(quest_id, objective_id_1, ... objective_id_n)
  194. #          This is satisfied if all the listed objectives have been failed
  195. #
  196. #    If you want to call the Quest scene from an event, you use the following
  197. #   code in a call script:
  198. #
  199. #        call_quest_journal
  200. #        call_quest_journal(quest_id)
  201. #          quest_id : ID of the quest you want to open the scene on
  202. #
  203. #  If you do not specify a quest_id (line 198) then it will simply open the
  204. #  scene as it would normally. If you do specify a quest_id (line 199) then it
  205. #  will open the scene on that quest so long as it has been revealed and it is
  206. #  normally accessible through the quest menu.
  207. #
  208. #   Finally, the default way this script operates is that quests automatically
  209. #  complete or fail based on the status of the prime objectives. However, you
  210. #  can set it so that there are no prime objectives, in which case you can only
  211. #  complete, fail, or (re)activate a quest manually through the following code
  212. #  in a script call:
  213. #
  214. #        manually_complete_quest(quest_id)
  215. #          quest_id : ID of the quest you want to manually complete
  216. #        manually_fail_quest(quest_id)
  217. #          quest_id : ID of the quest you want to manually fail
  218. #        manually_activate_quest(quest_id)
  219. #          quest_id : ID of the quest you want to manually activate
  220. #==============================================================================
  221.  
  222. $imported ||= {}
  223. $imported[:"MA_QuestJournal_1.0"] = true
  224. $imported[:"MA_QuestJournal_1.0.1"] = true
  225.  
  226. #==============================================================================
  227. # *** QuestData
  228. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  229. #  This module contains all the configuration data for the quest journal
  230. #==============================================================================
  231.  
  232. module QuestData
  233.   #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  234.   #  BEGIN Editable Region A
  235.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  236.   #  MENU_ACCESS - If true, you can access the quest journal through a command
  237.   # in the menu. If false, there will be no such command.
  238.   MENU_ACCESS = true
  239.   #  MENU_INDEX - If MENU_ACCESS is true, this determines where it appears
  240.   MENU_INDEX = 4
  241.   #  MAP_ACCESS - If true, this allows you to access the quest journal by
  242.   # pressing a key on the map.
  243.   MAP_ACCESS = true
  244.   #  MAP_BUTTON - If MAP_ACCESS is true, this determines which button calls the
  245.   # Quest Journal
  246.   MAP_BUTTON = :L
  247.   #  OPEN_TO_LAST_REVEALED_QUEST - If true, then the first time you open the
  248.   # quest journal after revealing a new quest, it will open to the new quest.
  249.   OPEN_TO_LAST_REVEALED_QUEST = true
  250.   #  OPEN_TO_LAST_CHANGED_QUEST - If true, then the Quest Journal will open to
  251.   # the last quest whose objective status has changed.
  252.   OPEN_TO_LAST_CHANGED_QUEST = false
  253.   #  LIST_WINDOW_WIDTH - The width, in pixels, of the List Window
  254.   LIST_WINDOW_WIDTH = 192
  255.   #  BASIC_DATA_TYPES  - This lets you set up additional types of data. Just
  256.   # include an identifying signal in the Array. Then, you will need to give
  257.   # each signal an icon (in the ICONS hash at line 322) and a signal text (in
  258.   # the VOCAB array at line 333, though it can be an empty string). Then, you
  259.   # can set the data itself when setting up quests by simply adding a:
  260.   #    q[:symbol] = ""
  261.   # line to the quest. You will also need to include the data type somewhere in
  262.   # the DATA_LAYOUT at line 306. As an example of this, I have included :client
  263.   # and :location by default. You can CTRL+F for anything in this section with
  264.   # one of those symbols (excluding :) and you will there need to add something
  265.   # for any new data types you add.
  266.   BASIC_DATA_TYPES = [:client, :location]
  267.   #  BASIC_DATA_WIDTH - This determines how much room, in pixels, is given to  
  268.   # any basic data types you set up in the data window.
  269.   BASIC_DATA_WIDTH = 240
  270.   #  CONCURRENT_ACTIVITY - If true, then when in the Quest Journal scene, you
  271.   # can switch categories or scroll down the quest list at the same time. If
  272.   # false, you will first need to select a category before you can start
  273.   # scrolling through the quest list.
  274.   CONCURRENT_ACTIVITY = true
  275.   #  HIDE_CATEGORY_CURSOR - If true, then the Category Window will not have a
  276.   # cursor and will instead just highlight the currently selected category.
  277.   # This is best when CONCURRENT_ACTIVITY is true.
  278.   HIDE_CATEGORY_CURSOR = true
  279.   #  SHOW_QUEST_ICONS - If true, then the icon you choose for each quest will
  280.   # be displayed to the left of its name in the Quest List window
  281.   SHOW_QUEST_ICONS = true
  282.   #  MANUAL_REVEAL - If false, then quests will be revealed the moment you
  283.   # first reveal, complete, or fail an objective. If this is true, you will
  284.   # need to specifically reveal each quest via a separate script call:
  285.   #    reveal_quest(quest_id)
  286.   MANUAL_REVEAL = false
  287.   #  DATA_LAYOUT - This controls the way that the quest window lays out all of
  288.   # the relevant data. If you set one of the entries to be an array, then any
  289.   # of the commands there will be drawn at the same y. With exception to :line,
  290.   # none of the commands will be drawn if the quest is not set to have that
  291.   # particular data. The symbols are:
  292.   #    :line        - Draws a horizontal line across the window.
  293.   #    :name        - Draws the name of the quest
  294.   #    :level       - Draws the level of the quest
  295.   #    :banner      - Draws the banner for the quest
  296.   #    :client      - Draws the client set in the quest   (basic data)
  297.   #    :location    - Draws the location set in the quest (basic data)
  298.   #    :description - Draws the quest's description
  299.   #    :objectives  - Draws all the quest's objectives that have been revealed
  300.   #    :rewards     - Draws whatever rewards have been set
  301.   #
  302.   # You will also need to add an entry for any new BASIC_DATA that you place
  303.   # in BASIC_DATA_TYPES at line 264.
  304.   #
  305.   # Remember to place a comma after each entry. Also note that this is only the
  306.   # default layout. You can set a different layout for any quest, and when
  307.   # viewing that quest, it will be the custom layout that is shown.
  308.   DATA_LAYOUT = [
  309.     [:line, :name, :level],
  310.     :banner,
  311.     :client,
  312.     :location,
  313.     :description,
  314.     :objectives,
  315.     [:line, :rewards],
  316.     :line,
  317.   ] # <= Do not touch.
  318.   #  ICONS - This is where you setup many of the icons used in the script. The
  319.   # purpose of each is listed next to it. Also, if you make any custom
  320.   # categories, you NEED to give them an icon by placing a line like the
  321.   # others. So, if the new custom category is :romance then you would need to
  322.   # set it like this:
  323.   #    romance:     107,
  324.   ICONS = {
  325.     all:         226, # The icon for the All Quests category
  326.     active:      236, # The icon for the Active Quests category
  327.     complete:    238, # The icon for the Complete Quests category
  328.     failed:      227, # The icon for the Failed Quests category
  329.     client:      121, # The icon for client data. If none wanted, set to 0
  330.     location:    231, # The icon for location data. If none wanted, set to 0
  331.     reward_gold: 262, # The icon for gold rewards. If none wanted, set to 0
  332.     reward_exp:  117, # The icon for exp rewards. If none wanted, set to 0
  333.   } # <= Do not touch.
  334.   #  VOCAB - This lets you choose some of the words used in the quest scene
  335.   VOCAB = {
  336.     # menu_label:  The command name in the menu if MENU_ACCESS is true
  337.     menu_label:       "Quests",
  338.     # scene_label: The label at the top of the scene. If empty, no window
  339.     scene_label:      "Quest Journal",
  340.     # description: The heading to identify the description
  341.     description:      "Description",
  342.     # objectives: The heading to identify the objectives
  343.     objectives:       "Objectives",
  344.     # objective_bullet: The bullet which shows up to the left of every
  345.     #  objective. If %d is included, it shows the objective's ID.
  346.     objective_bullet: "♦",
  347.     # rewards: The heading to identify the rewards.
  348.     rewards:          "Rewards",
  349.     # reward_amount: For item rewards, this is the text to show the amount.
  350.     #  It should include %d to show the amount.
  351.     reward_amount:    "x%d",
  352.     # reward_gold: Text to identify gold rewards
  353.     reward_gold:      "",
  354.     # reward_exp: Text to identify exp rewards
  355.     reward_exp:       "",
  356.     # level: If LEVEL_ICON is 0, this is the text which precedes the level
  357.     level:            "Rank: ",
  358.     # location: The text label for quest location
  359.     location:         "",
  360.     # location: The text label for quest client
  361.     client:           "",
  362.   } # <= Do not touch.
  363.   #  CATEGORIES - This array allows you to set which categories are available
  364.   # in the Quest scene. The default categories are :all, :active, :complete,
  365.   # and :failed, and their names are self-explanatory. You can add custom
  366.   # categories as well, but note that you will need to make sure that each new
  367.   # category has an icon set in the ICONS hash, as well as a label set in the
  368.   # CATEGORY_VOCAB hash (if you are using SHOW_CATEGORY_LABEL). It is also
  369.   # advisable to give it a sort type, unless you are fine with it being sorted
  370.   # by ID, as is default.
  371.   CATEGORIES = [:all, :active, :complete, :failed]
  372.   #  SHOW_CATEGORY_LABEL - This allows you to choose whether to show the name
  373.   # of the currently selected category. If true, it will choose the name out
  374.   # of the CATEGORY_VOCAB hash.
  375.   SHOW_CATEGORY_LABEL = true
  376.   #  CATEGORY_LABEL_IN_SAME_WINDOW - If SHOW_CATEGORY_LABEL is true, then this
  377.   # options lets you choose whether the label is shown in the same window as
  378.   # the category icons or in a separate window below. true = same window.
  379.   CATEGORY_LABEL_IN_SAME_WINDOW = true
  380.   #  CATEGORY_VOCAB - If SHOW_CATEGORY_LABEL is true, this hash lets you set the
  381.   # label for each category. For any custom categories you create, you will
  382.   # need to add a line for each below and in the same format:
  383.   #    :category => "Label",
  384.   # Don't forget to add the comma at the end of each line.
  385.   CATEGORY_VOCAB = {
  386.     :all =>      "All Quests",      # The label for the :all category
  387.     :active =>   "Active Quests",   # The label for the :active category
  388.     :complete => "Complete Quests", # The label for the :complete category
  389.     :failed =>   "Failed Quests",   # The label for the :failed category
  390.   } # <= Do not touch.
  391.   #  SORT_TYPE - This hash allows you to choose how each category is sorted.
  392.   # For each category, default or custom, you can set a different sort method
  393.   # There are seven options to choose from:
  394.   #    :id - The quests are sorted from lowest to highest ID
  395.   #    :alphabet - The quests are sorted in alphabetical order
  396.   #    :level - The quests are sorted from the lowest to highest level
  397.   #    :reveal - The quests are sorted from most recently revealed on.
  398.   #            Every time a new quest is revealed, it will be at the top.
  399.   #    :change - The quests are sorted from the one whose status most recently
  400.   #            changed on. So, every time an objective is modified, that quest
  401.   #            will be thrown to the top.
  402.   #    :complete - The quests are sorted from the most recently completed on.
  403.   #            Every time a quest is completed, it will be thrown to the top.
  404.   #    :failed - The quests are sorted from the most recently failed on.
  405.   #            Every time a quest is failed, it will be thrown to the top.
  406.   #
  407.   # Additionally, you can put _r at the end of any of the sort options and it
  408.   # will reverse the order. So, for instance, if the sort method for a category
  409.   # is :alphabet_r, then the quests will show up from Z-A
  410.   SORT_TYPE = {
  411.     :all =>      :id,       # Sort type for the All Quests category
  412.     :active =>   :change,   # Sort type for the Active Quests category
  413.     :complete => :complete, # Sort type for the Complete Quests category
  414.     :failed =>   :failed,   # Sort type for the Failed Quests category
  415.   } # <= Do not touch.
  416.   #  WINDOWSKIN - The windowskin for each window in the Quest scene. It must
  417.   # refer to a graphic in the System folder of Graphics. If set to false, then
  418.   # it will use whatever windowskin is default. If you are using a script which
  419.   # lets the player choose the windowskin, false is the recommended value.
  420.   WINDOWSKIN = false
  421.   #  WINDOW_TONE - The tone for each window. It must be an array in the form:
  422.   #      WINDOW_TONE = [red, green, blue, gray]
  423.   # gray can be excluded, but the other three must be present. If you set this
  424.   # value to false, then the windows will have whatever tone is default.
  425.   WINDOW_TONE = false
  426.   #  WINDOW_OPACITY - The opacity of the windows in the Quest scene. If set to
  427.   # false, it will use the default opacity for windows.
  428.   WINDOW_OPACITY = false
  429.   #  BG_PICTURE - This is a string referring to a picture in the Picture folder
  430.   # of Graphics. If set to "", then there will be no picture. Otherwise, it
  431.   # will display the selected picture below the windows but above the map in
  432.   # the Quest scene.
  433.   BG_PICTURE = ""
  434.   #  BG_OPACITY - This allows you to set the opacity of the background picture,
  435.   # if you have selected one.
  436.   BG_OPACITY = 255
  437.   #  BG_BLEND_TYPE - This allows you to set the blend type of the background
  438.   # picture, if you have selected one.
  439.   BG_BLEND_TYPE = 0
  440.   #  DESCRIPTION_IN_BOX - This is a graphical option, and it allows you to
  441.   # choose whether the description should be shown in a box.
  442.   DESCRIPTION_IN_BOX = true
  443.   #  LEVEL_ICON - This sets how levels are shown. If set to an integer, then it
  444.   # will draw the same icon numerous times up to the level of the quest. Ie. If
  445.   # the level's quest is 1, then the icon will only be drawn once, but if the
  446.   # level's quest is 4, it will be drawn 4 times. LEVEL_ICONS_SPACE determines
  447.   # the space between them. If you set LEVEL_ICON to 0, however, then it will
  448.   # instead draw a signal for the level, corresponding to that index in the
  449.   # LEVEL_SIGNALS array. If the LEVEL_SIGNALS array is empty, then it will just
  450.   # draw the integer for the level. Finally, LEVEL_ICON can also be an array of
  451.   # integers, in which case the level will be represented only by the icon set
  452.   # which corresponds to it in the array.
  453.   LEVEL_ICON = 125
  454.   #  LEVEL_ICONS_SPACE - If LEVEL_ICON is an integer, this is the amount of
  455.   # space between each time the icon is drawn.
  456.   LEVEL_ICONS_SPACE = 16
  457.   #  LEVEL_SIGNALS - If LEVEL_ICON is 0, this allows you to set what string
  458.   # should be the signal for each level. If this array is empty, then it will
  459.   # just draw the level integer. Ie. if the Quest is Level 4, it will draw 4.
  460.   LEVEL_SIGNALS = ["F", "E", "D", "C", "B", "A", "S"]
  461.   #  COLOURS - This lets you change the colour for various aspects of the
  462.   # quest scene. Each can be set in one of three ways:
  463.   #    :symbol - If you use a symbol, the colour will be the result of calling
  464.   #      the method of the same name. For instance, if you set something to
  465.   #      :system_color, it will set the colour to the result of the Window_Base
  466.   #      system_color method.
  467.   #    Integer - If you set the colour to an integer, then it will take its
  468.   #      colour from the windowskin palette, just like using \c[x] in messages.
  469.   #    Array - You can also set the rgba values directly with an array in the
  470.   #      format: [red, green, blue, alpha]. alpha can be excluded, but you must
  471.   #      have values for red, green, and blue.
  472.   COLOURS = {
  473.     # active: This sets the colour for active quests in the list and the name
  474.     #  of the active quest when shown in the data window.
  475.     active:           :normal_color,
  476.     # complete: This sets the colour for complete quests in the list and the
  477.     #  name of the complete quest when shown in the data window.
  478.     complete:         3,
  479.     # failed: This sets the colour for failed quests in the list and the name
  480.     #  of the failed quest when shown in the data window.
  481.     failed:           10,
  482.     # line:  This sets the colour for lines or boxes drawn in the quest scene
  483.     line:             :system_color,
  484.     # line_shadow:  This sets the colour of the shadow for lines or boxes drawn
  485.     #  in the quest scene
  486.     line_shadow: [0, 0, 0, 128],
  487.     # scene_label: This sets the colour for the scene label, if shown
  488.     scene_label:      :system_color,
  489.     # category_label: This sets the colour for the category label, if shown
  490.     category_label:   :normal_color,
  491.     # level_signal: This sets the colour for the level signal, if shown
  492.     level_signal:     :normal_color,
  493.     # objective_bullet: This sets the colour for objectives; if set to
  494.     #  :maqj_objective_color, it will reflect the completion status of the
  495.     #  objective, but you can change it to something else if you prefer
  496.     objective_bullet: :maqj_objective_color,
  497.     # reward_amount: The colour of the item amount, when shown
  498.     reward_amount:    :normal_color,
  499.     # heading: The colour of any headings in the script, like "Description"
  500.     heading:          :system_color,
  501.     # basic_label: For basic data, like client, the colour of the label
  502.     basic_label:      :system_color,
  503.     # basic_value: For basic data, like client, the colour of the value
  504.     basic_value:      :normal_color,
  505.   } # <= Do not touch.
  506.   #  HEADING_ALIGN - This sets the alignment for the aspects listed. 0 is Left;
  507.   # 1 is Centre; 2 is Right
  508.   HEADING_ALIGN = {
  509.     description: 0, # Alignment for the Description heading
  510.     objectives:  0, # Alignment for the Objectives heading
  511.     rewards:     1, # Alignment for the Rewards heading
  512.     level:       2  # Alignment when showing the level
  513.   } # <= Do not touch.
  514.   #````````````````````````````````````````````````````````````````````````````
  515.   #    Font Aspects
  516.   #
  517.   #  All of the following options (FONTNAMES, FONTSIZES, FONTBOLDS, and
  518.   # FONTITALICS) allow you to alter the fonts used for various aspects of the
  519.   # scene. The only one listed there by default is normal:, which is the
  520.   # font used by default for the entire scene. However, you can change the  
  521.   # fonts for almost any aspect - all you need to do is add a line like so:
  522.   #
  523.   #    description: value,
  524.   #
  525.   # and that will change that font aspect when drawing the description. The
  526.   # following symbols are available for changing:
  527.   #
  528.   #   normal:         The default font used for every part of the scene
  529.   #   list:           The font used in the List Window
  530.   #   scene_label:    The font used when drawing the Scene Label, if shown
  531.   #   category_label: The font used when drawing the Category Label, if shown
  532.   #   heading:        The font used when drawing any headings, like "Description"
  533.   #   name:           The font used when drawing the quest name in data window
  534.   #   description:    The font used when drawing the Description
  535.   #   objectives:     The font used when drawing the objectives
  536.   #   rewards:        The font used when drawing the rewards
  537.   #   client:         The font used when drawing the client
  538.   #   location:       The font used when drawing the location
  539.   #
  540.   # For any of them, you need to set a value. What the value can be depends
  541.   # on which font aspect you are changing and is described below, but for any
  542.   # of them setting it to the false will mean it will simply use the default
  543.   #
  544.   # For any that you add, remember that you must put a comma after the value.
  545.   #````````````````````````````````````````````````````````````````````````````
  546.   #  FONTNAMES - Here you can change the font used for any of the various
  547.   # options. It can take any of the following types of values:
  548.   #     false    - The default font will be used
  549.   #     "String" - The font with the name "String" will be used.
  550.   #     [Array]  - The array must be in the form: ["String1", "String2", ...]
  551.   #               The font used will be the first one in the array that the
  552.   #               player has installed.
  553.   #
  554.   #  EXAMPLES:
  555.   #
  556.   #    normal:      false,
  557.   #      The font used for unaltered aspects of the scene is the default font
  558.   #    scene_label: "Algerian",
  559.   #      The font used for the Scene Label will be Algerian.
  560.   #    description: ["Cambria", "Times New Roman"],
  561.   #      The font used when drawing the description will be Cambria if the
  562.   #      player has Cambria installed. If the player does not have Cambria
  563.   #      installed, then the font used will be Times New Roman
  564.   FONTNAMES = {
  565.     normal: false, # normal: the default font name
  566.   } # <= Do not touch.
  567.   #  FONTSIZES - Here you can change the size of the font. There are two types
  568.   # of values you can set:
  569.   #    false   - The default fontsize will be used
  570.   #    Integer - The fontsize will be equal to the value of the Integer.
  571.   #  
  572.   # For everything but the label windows, this shouldn't exceed 24, since that
  573.   # is the line_height. However, for scene_label: and category_label:, the size
  574.   # of the window will be adjusted to whatever size you set the font.
  575.   FONTSIZES = {
  576.     normal:         false, # normal: default font size
  577.     scene_label:    28,    # scene_label: fontsize for the Scene Label window
  578.     category_label: 24,    # category_label: fontsize for Category Label window
  579.   } # <= Do not touch.
  580.   #  FONTBOLDS - Here you can set whether the font will be bolded. You can set
  581.   # it to either false, in which case it will not be bolded, or true, in which
  582.   # case it will be bolded.
  583.   FONTBOLDS = {
  584.     scene_label:  true, # scene_label: whether font is bold for Scene Label
  585.     heading:      true, # heading: whether font is bold for the headings
  586.     level_signal: true, # level_signal: whether font is bold for level
  587.   } # <= Do not touch.
  588.   #  FONTITALICS - Here you can set whether the font will be italicized. You
  589.   # can set it to either false, in which case it will not be italicized, or
  590.   # true, in which case it will be italicized.
  591.   FONTITALICS = {
  592.   }
  593.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  594.   #  END Editable Region A
  595.   #//////////////////////////////////////////////////////////////////////////
  596.   CATEGORIES = [:all] if !CATEGORIES || CATEGORIES.empty?
  597.   VOCAB.default = ""
  598.   ICONS.default = 0
  599.   CATEGORY_VOCAB.default = ""
  600.   SORT_TYPE.default = :id
  601.   COLOURS.default = :normal_color
  602.   HEADING_ALIGN.default = 0
  603.   FONTNAMES.default = false
  604.   FONTSIZES.default = false
  605.   FONTBOLDS.default = false
  606.   FONTITALICS.default = false
  607.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  608.   # * Setup Quest
  609.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  610.   def self.setup_quest(quest_id)
  611.     q = { objectives: [] }
  612.     case quest_id
  613.     #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  614.     #  BEGIN Editable Region B
  615.     #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  616.     #    Quest Setup
  617.     #
  618.     #  This is where you set up the data for every quest in the game. While
  619.     # it may seem complicated, I urge you to pay attention and, once you get
  620.     # the hang of it, I am sure it will quickly become second nature.
  621.     #
  622.     #  Every single quest should be set up in the following format, but note
  623.     # that if you are not setting anything for a particular aspect, you can
  624.     # delete that line. Anyway, this is what each quest should look like, with
  625.     # the values on the left being the default values if you don't set them:
  626.     #
  627.     #  when quest_id
  628.     #   q[:name]              = "??????"
  629.     #   q[:icon_index]        = 0
  630.     #   q[:level]             = 0
  631.     #   q[:description]       = ""
  632.     #   q[:banner]            = ""
  633.     #   q[:banner_hue]        = 0
  634.     #   q[:objectives][0]     = ""
  635.     #   q[:objectives][1]     = ""
  636.     #   q[:objectives][2]     = ""
  637.     #   q[:objectives][n]     = ""
  638.     #   q[:prime_objectives]  = [0, 1, 2, n]
  639.     #   q[:custom_categories] = []
  640.     #   q[:client]            = ""
  641.     #   q[:location]          = ""
  642.     #   q[:rewards]           = []
  643.     #   q[:common_event_id]   = 0
  644.     #   q[:layout]            = false
  645.     #
  646.     #  For each line, with the exception of objectives, it is only the value on
  647.     # the right of the equals sign that you will need to change. Now I will
  648.     # explain each line:
  649.     #
  650.     # when quest_id
  651.     #    quest_id - is an integer of your choosing, and this is how you
  652.     #        reference a quest in order to advance and do anything else. It
  653.     #        must be unique for every quest; if you use 1 for the first quest,
  654.     #        you cannot use 1 for any other quest.
  655.     #
  656.     #   q[:name]              = ""
  657.     #     "" - This line sets the name of the quest which shows in the Quest
  658.     #        List.
  659.     #  
  660.     #   q[:icon_index]        = 0
  661.     #     0  - This line sets the icon to be used for this quest. It will show
  662.     #        to the left of the quest's name in the Quest List.
  663.     #
  664.     #   q[:level]             = 0
  665.     #     0  - This line sets the level of the quest. If 0, no level will be
  666.     #        shown. See the level options at lines 441-458 for more detail.
  667.     #  
  668.     #   q[:description]       = ""
  669.     #     "" - This line sets the description of the quest. You can use message
  670.     #        codes in this string, but if you are using "" then you need to use
  671.     #        \\ to identify codes and not just \. Ie. It's \\v[x], not \v[x]
  672.     #
  673.     #   q[:objectives][0]     = ""
  674.     #   q[:objectives][1]     = ""
  675.     #   q[:objectives][2]     = ""
  676.     #   q[:objectives][n]     = ""
  677.     #  Objectives are slightly different. Notice that after q[:objectives] on
  678.     # each line there is an integer enclosed in square brackets:
  679.     #    [n] - This is the ID of the objective, and n MUST be an integer. No
  680.     #       quest can have more than one objective with the same ID. This is
  681.     #       how you identify which objective you want to reveal, complete or
  682.     #       fail. That said, you can make as many objectives as you want, as
  683.     #       long as you give them all distinct IDs. The IDs should be in
  684.     #       sequence as well, so there shouldn't be a q[:objectives][5] if
  685.     #       there is no q[:objectives][4].
  686.     #     "" - This is the text of the objective. You can use message codes in
  687.     #        this string, but if you are using "" then you will need to use
  688.     #        \\ to identify codes and not just \. Ie: It's \\v[x], not \v[x]
  689.     #
  690.     #   q[:prime_objectives]  = [0, 1, 2, n]
  691.     #     [0, 1, 2, n] - This array determines what objectives need to be
  692.     #        completed in order for the quest to be complete. In other words,
  693.     #        all of the objectives with the IDs in this array need to be
  694.     #        complete for the quest to be complete. If any one of them is
  695.     #        failed, the quest will be failed. If you remove this line
  696.     #        altogether, then all objectives are prime. If you set this to [],
  697.     #        then the quest will never be automatically completed or failed and
  698.     #        you need to use the manual options described at lines 208-219.
  699.     #
  700.     #   q[:custom_categories] = []
  701.     #     [] - This allows you to set an array of custom categories for this
  702.     #        quest, whiich means this quest will show up in each of those
  703.     #        categories if you add it to the CATEGORIES array at line 370.
  704.     #        Note that each category you make must be identified by a unique
  705.     #        :symbol, and you must set up all the category details for that
  706.     #        :symbol.
  707.     #
  708.     #   q[:banner]            = ""
  709.     #     "" - This line sets the banner to be used for a quest. It must be the
  710.     #        filename of an image in the Pictures folder of Graphics.
  711.     #
  712.     #   q[:banner_hue]        = 0
  713.     #     0 - The hue of the banner graphic, if used
  714.     #
  715.     #   q[:client]            = ""
  716.     #     "" - This line sets the client name for this quest. (basic data)
  717.     #
  718.     #   q[:location]          = ""
  719.     #     "" - This line sets the location of the quest. (basic data)
  720.     #
  721.     #   q[:rewards]           = []
  722.     #    [] - In this array, you can identify particular rewards that will
  723.     #       show up. Each reward should be in its own array and can be any of
  724.     #       the following:
  725.     #          [:item, ID, n],
  726.     #          [:weapon, ID, n],
  727.     #          [:armor, ID, n],
  728.     #          [:gold, n],
  729.     #          [:exp, n],
  730.     #       where ID is the ID of the item, weapon or armour you want
  731.     #       distributed and n is the amount of the item, weapon, armor, gold,
  732.     #       or experience you want distributed. Additionally, you can also set
  733.     #       some text to show up in the rewards format but which wouldn't be
  734.     #       automatically distributed. You would need to specify that type of
  735.     #       reward text in the following format:
  736.     #          [:string, icon_index, "string", "vocab"],
  737.     #       where icon_index is the icon to be shown, "string" is what you
  738.     #       would show up as the amount, and "vocab" is what would show up as a
  739.     #       label between the icon and the amount.
  740.     #      
  741.     #
  742.     #   q[:common_event_id]   = 0
  743.     #     0  - This allows you to call the identified common event immediately
  744.     #        and automatically once the quest is completed. It is generally
  745.     #        not recommended, as for most quests you should be controlling it
  746.     #        enough not to need this feature.
  747.     #
  748.     #   q[:layout]            = false
  749.     #     false - The default value for this is false, and when it is false the
  750.     #        layout for the quest will be inherited from the default you set at
  751.     #        302. However, you can also give the quest its own layout - the
  752.     #        format would be the same as you set for the default at line 307.
  753.     #  
  754.     # Template:
  755.     #
  756.     #  When making a new quest, I recommend that you copy and paste the
  757.     # following template, removing whichever lines you don't want to alter.
  758.     # Naturally, you need to remove the #~. You can do so by highlighting
  759.     # the entire thing and pressing CTRL+Q:
  760. #~     when 2 # <= REMINDER: The Quest ID MUST be unique
  761. #~       q[:name]              = "??????"
  762. #~       q[:icon_index]        = 0
  763. #~       q[:level]             = 0
  764. #~       q[:description]       = ""
  765. #~       # REMINDER: You can make as many objectives as you like, but each must
  766. #~       # have a unique ID.
  767. #~       q[:objectives][0]     = ""
  768. #~       q[:objectives][1]     = ""
  769. #~       q[:objectives][2]     = ""
  770. #~       q[:prime_objectives]  = [0, 1, 2]
  771. #~       q[:custom_categories] = []
  772. #~       q[:banner]            = ""
  773. #~       q[:banner_hue]        = 0
  774. #~       q[:client]            = ""
  775. #~       q[:location]          = ""
  776. #~       q[:rewards]           = []
  777. #~       q[:common_event_id]   = 0
  778.     when 1 # Quest 1 - SAMPLE QUEST
  779.       q[:name]              = "Runaway Bride"
  780.       q[:level]             = 3
  781.       q[:icon_index]        = 7
  782.       q[:description]       = "A local woman was abducted by bandits on the night of her wedding."
  783.       q[:objectives][0]     = "Talk to Boris"
  784.       q[:objectives][1]     = "Search the Haunted Woods for Boris' wife, Ladia"
  785.       q[:objectives][2]     = "Slay the Bandits"
  786.       q[:objectives][3]     = "Escort Ladia back to Boris"
  787.       q[:prime_objectives]  = [1, 2]
  788.       q[:custom_categories] = []
  789.       q[:banner]            = ""
  790.       q[:banner_hue]        = 0
  791.       q[:client]            = "Boris"
  792.       q[:location]          = "The Haunted Woods"
  793.       q[:common_event_id]   = 0
  794.       q[:rewards]           = [
  795.         [:item, 1, 3],
  796.         [:gold, 500],
  797.       ]
  798.       q[:layout]            = false
  799.     #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  800.     #  END Editable Region B
  801.     #//////////////////////////////////////////////////////////////////////
  802.     end
  803.     q
  804.   end
  805. end
  806.  
  807. #==============================================================================
  808. # *** DataManager
  809. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  810. #  Summary of Changes:
  811. #    aliased method - self.extract_save_contents
  812. #==============================================================================
  813.  
  814. class << DataManager
  815.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  816.   # * Extract Save Contents
  817.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  818.   alias maqj_extractsavecons_2kw5 extract_save_contents
  819.   def extract_save_contents(*args, &block)
  820.     maqj_extractsavecons_2kw5(*args, &block) # Call Original Method
  821.     if $game_party.quests.nil?
  822.       $game_party.init_maqj_data
  823.       $game_system.init_maqj_data
  824.     end
  825.   end
  826. end
  827.  
  828. #==============================================================================
  829. # ** MAQJ_SortedArray
  830. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  831. #  This module mixes in to an array to maintain the sorted order when inserting
  832. #==============================================================================
  833.  
  834. module MAQJ_SortedArray
  835.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  836.   # * Insert to Array
  837.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  838.   def maqj_insert_sort(el, &block)
  839.     index = bsearch_index(el, 0, size, &block)
  840.     index ? insert(index, el) : push(el)
  841.   end
  842.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  843.   # * Retrieve Index from Binary Search
  844.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  845.   def bsearch_index(el, b = 0, e = size, &block)
  846.     return bsearch_index(el, b, e) { |a,b| a <=> b } if block.nil?
  847.     return b if b == e # Return the discovered insertion index
  848.     return if b > e
  849.     m = (b + e) / 2    # Get Middle
  850.     block.call(el, self[m]) > 0 ? b = m + 1 : e = m
  851.     bsearch_index(el, b, e, &block)
  852.   end
  853. end
  854.  
  855. #==============================================================================
  856. # ** Game_Quest
  857. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  858. #  This class holds all instance data for a quest
  859. #==============================================================================
  860.  
  861. class Game_Quest
  862.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  863.   # * Public Instance Variables
  864.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  865.   attr_reader   :id                  # Unique identifier for this quest
  866.   attr_reader   :name                # The name to be shown for the quest
  867.   attr_reader   :level               # The level of difficulty of the quest
  868.   attr_reader   :objectives          # An array of objective strings
  869.   attr_reader   :prime_objectives    # An array of crucial objective IDs
  870.   attr_reader   :revealed_objectives # An array of revealed objective IDs
  871.   attr_reader   :complete_objectives # An array of completed objective IDs
  872.   attr_reader   :failed_objectives   # An array of failed objective IDs
  873.   attr_reader   :custom_categories   # An array of category symbols
  874.   attr_accessor :icon_index          # Icon associated with this quest
  875.   attr_accessor :common_event_id     # ID of common event to call upon complete
  876.   attr_accessor :description         # The description for the quest
  877.   attr_accessor :banner              # Picture shown to represent the quest
  878.   attr_accessor :banner_hue          # The hue of the banner
  879.   attr_accessor :layout              # The layout of this quest in scene
  880.   attr_accessor :rewards             # An array of rewards to show
  881.   attr_accessor :reward_given        # Boolean tracking if quest was rewarded
  882.   attr_accessor :concealed           # Whether or not the quest is visible
  883.   attr_accessor :manual_status       # Quest status if not using prime objectives
  884.   QuestData::BASIC_DATA_TYPES.each { |data_type| attr_accessor(data_type) }
  885.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  886.   # * Object Initialization
  887.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  888.   def initialize(quest_id)
  889.     @id = quest_id
  890.     @concealed = default_value_for(:concealed)
  891.     @reward_given = default_value_for(:reward_given)
  892.     reset
  893.   end
  894.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  895.   # * Reset
  896.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  897.   def reset
  898.     data = QuestData.setup_quest(@id)
  899.     data_symbol_array.each { |meth| instance_variable_set(:"@#{meth}",
  900.       data[meth] ? data[meth] : default_value_for(meth)) }
  901.     @revealed_objectives = [].send(:extend, MAQJ_SortedArray)
  902.     @complete_objectives = [].send(:extend, MAQJ_SortedArray)
  903.     @failed_objectives =   [].send(:extend, MAQJ_SortedArray)
  904.     @manual_status = default_value_for(:manual_status)
  905.   end
  906.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  907.   # * Data Symbol Array
  908.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  909.   def data_symbol_array
  910.     [:name, :level, :objectives, :prime_objectives, :custom_categories,
  911.       :icon_index, :description, :banner, :banner_hue, :common_event_id,
  912.       :layout, :rewards] + QuestData::BASIC_DATA_TYPES
  913.   end
  914.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  915.   # * Default Value
  916.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  917.   def default_value_for(method)
  918.     case method
  919.     when :name then "??????"
  920.     when :description, :banner then ""
  921.     when :level, :banner_hue, :icon_index, :common_event_id then 0
  922.     when :objectives, :rewards, :custom_categories then []
  923.     when :prime_objectives then Array.new(objectives.size) { |x| x }
  924.     when :concealed then QuestData::MANUAL_REVEAL
  925.     when :manual_status then :active
  926.     when :layout, :reward_given then false
  927.     else ""
  928.     end
  929.   end
  930.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  931.   # * Reveal/Conceal Objective
  932.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  933.   def reveal_objective(*obj)
  934.     valid_obj = obj.select {|x| x < objectives.size && !@revealed_objectives.include?(x) }
  935.     valid_obj.each {|i| @revealed_objectives.maqj_insert_sort(i) }
  936.     quest_status_changed unless valid_obj.empty?
  937.   end
  938.   def conceal_objective(*obj)
  939.     quest_status_changed unless (obj & @revealed_objectives).empty?
  940.     obj.each { |obj_id| @revealed_objectives.delete(obj_id) }
  941.   end
  942.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  943.   # * Complete/Uncomplete Objective
  944.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  945.   def complete_objective(*obj)
  946.     valid_obj = obj.select {|x| x < objectives.size && !@complete_objectives.include?(x) }
  947.     reveal_objective(*valid_obj)
  948.     unfail_objective(*valid_obj)
  949.     was_complete = status?(:complete)
  950.     valid_obj.each {|i| @complete_objectives.maqj_insert_sort(i) }
  951.     quest_status_changed unless valid_obj.empty?
  952.     # If just completed
  953.     if status?(:complete) && !was_complete
  954.       $game_temp.reserve_common_event(common_event_id)
  955.       $game_party.quests.add_to_sort_array(:complete, @id)
  956.     end
  957.   end
  958.   def uncomplete_objective(*obj)
  959.     quest_status_changed unless (obj & @complete_objectives).empty?
  960.     obj.each { |obj_id| @complete_objectives.delete(obj_id) }
  961.   end
  962.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  963.   # * Fail/Unfail Objective
  964.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  965.   def fail_objective(*obj)
  966.     valid_obj = obj.select {|x| x < objectives.size && !@failed_objectives.include?(x) }
  967.     reveal_objective(*valid_obj)
  968.     uncomplete_objective(*valid_obj)
  969.     was_failed = status?(:failed)
  970.     valid_obj.each {|i| @failed_objectives.maqj_insert_sort(i) }
  971.     quest_status_changed unless valid_obj.empty?
  972.     $game_party.quests.add_to_sort_array(:failed, @id) if status?(:failed) && !was_failed
  973.   end
  974.   def unfail_objective(*obj)
  975.     quest_status_changed unless (obj & @failed_objectives).empty?
  976.     obj.each { |obj_id| @failed_objectives.delete(obj_id) }
  977.   end
  978.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  979.   # * Updates when the quest status has been changed
  980.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  981.   def quest_status_changed
  982.     $game_party.quests.add_to_sort_array(:change, @id)
  983.     $game_system.last_quest_id = @id if QuestData::OPEN_TO_LAST_CHANGED_QUEST
  984.   end
  985.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  986.   # * Objective Status?
  987.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  988.   def objective_status?(status_check, *obj)
  989.     return false if obj.empty?
  990.     case status_check
  991.     when :failed   then !(obj & @failed_objectives).empty?
  992.     when :complete then obj.size == (obj & @complete_objectives).size
  993.     when :revealed then obj.size == (obj & @revealed_objectives).size
  994.     when :active then objective_status?(:revealed, *obj) &&
  995.       !objective_status?(:complete, *obj) && !objective_status?(:failed, *obj)
  996.     end
  997.   end
  998.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  999.   # * Status?
  1000.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1001.   def status?(status_check)
  1002.     case status_check
  1003.     when :failed  
  1004.       @prime_objectives.empty? ? @manual_status == :failed :
  1005.         !(@failed_objectives & @prime_objectives).empty?
  1006.     when :complete
  1007.       @prime_objectives.empty? ? @manual_status == :complete : !status?(:failed) &&
  1008.         ((@prime_objectives & @complete_objectives) == @prime_objectives)
  1009.     when :active then !concealed && !status?(:complete) && !status?(:failed)
  1010.     when :reward then @reward_given
  1011.     end
  1012.   end
  1013.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1014.   # * Set Name
  1015.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1016.   def name=(new_name)
  1017.     @name = new_name
  1018.     $game_party.quests.add_to_sort_array(:alphabet, @id) if $game_party &&
  1019.       $game_party.quests
  1020.   end
  1021.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1022.   # * Set Level
  1023.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1024.   def level=(new_lvl)
  1025.     @level = new_lvl
  1026.     $game_party.quests.add_to_sort_array(:level, @id) if $game_party &&
  1027.       $game_party.quests
  1028.   end
  1029. end
  1030.  
  1031. #==============================================================================
  1032. # ** Game_Quests
  1033. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1034. #  This is a wrapper for an array holding Game_Quest objects
  1035. #==============================================================================
  1036.  
  1037. class Game_Quests
  1038.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1039.   # * Object Initialization
  1040.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1041.   def initialize
  1042.     @data = {}
  1043.     @sort_arrays = {
  1044.       reveal: [], change: [], complete: [], failed: [],
  1045.       id:       [].send(:extend, MAQJ_SortedArray),
  1046.       alphabet: [].send(:extend, MAQJ_SortedArray),
  1047.       level:    [].send(:extend, MAQJ_SortedArray)
  1048.     }
  1049.   end
  1050.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1051.   # * Get Quest
  1052.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1053.   def [](quest_id)
  1054.     reset_quest(quest_id) if !@data[quest_id]
  1055.     @data[quest_id]
  1056.   end
  1057.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1058.   # * Set Quest <- Not sure when this would ever be useful.
  1059.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1060.   def []=(quest_id, value)
  1061.     @data[quest_id] = value
  1062.   end
  1063.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1064.   # * List
  1065.   #    list_type : the type of list to return
  1066.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1067.   def list(list_type = :all, sort_type = $game_system.quest_sort_type[list_type])
  1068.     sort_type_s = sort_type.to_s
  1069.     reverse = !(sort_type_s.sub!(/_r$/, "")).nil?
  1070.     sort_type = sort_type_s.to_sym
  1071.     list = @sort_arrays[sort_type].select { |quest_id| include?(quest_id, list_type) }
  1072.     list.reverse! if reverse
  1073.     list.collect { |quest_id| @data[quest_id] }
  1074.   end
  1075.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1076.   # * Include?
  1077.   #    determines whether to include a particular quest depending on list type
  1078.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1079.   def include?(quest_id, list_type = :all)
  1080.     return false if !revealed?(quest_id)
  1081.     case list_type
  1082.     when :all then true
  1083.     when :complete, :failed, :active then @data[quest_id].status?(list_type)
  1084.     else
  1085.       @data[quest_id].custom_categories.include?(list_type)
  1086.     end
  1087.   end
  1088.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1089.   # * Revealed?
  1090.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1091.   def revealed?(quest_id)
  1092.     (!@data[quest_id].nil? && !@data[quest_id].concealed)
  1093.   end
  1094.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1095.   # * Setup Quest
  1096.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1097.   def setup_quest(quest_id)
  1098.     return if @data[quest_id]
  1099.     @data[quest_id] = Game_Quest.new(quest_id)
  1100.     # Open to this quest next time the QJ is opened
  1101.     $game_system.last_quest_id = quest_id if QuestData::OPEN_TO_LAST_REVEALED_QUEST
  1102.     # Save sorting order in separate arrays to avoid re-sorting every time
  1103.     @sort_arrays.keys.each { |sym| add_to_sort_array(sym, quest_id) }
  1104.   end
  1105.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1106.   # * Delete Quest
  1107.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1108.   def delete_quest(quest_id)
  1109.     @data.delete(quest_id)
  1110.     @sort_arrays.values.each { |ary| ary.delete(quest_id) }
  1111.   end
  1112.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1113.   # * Reset Quest
  1114.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1115.   def reset_quest(quest_id)
  1116.     delete_quest(quest_id)
  1117.     setup_quest(quest_id)
  1118.   end
  1119.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1120.   # * Add to Sorted Array
  1121.   #    sort_type : array to alter
  1122.   #    quest_id  : ID of the quest to add.
  1123.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1124.   def add_to_sort_array(sort_type, quest_id)
  1125.     @sort_arrays[sort_type].delete(quest_id) # Make sure always unique
  1126.     case sort_type
  1127.     when :reveal, :change, :complete, :failed
  1128.       @sort_arrays[sort_type].unshift(quest_id)
  1129.     when :id
  1130.       @sort_arrays[sort_type].maqj_insert_sort(quest_id)
  1131.     when :alphabet
  1132.       @sort_arrays[sort_type].maqj_insert_sort(quest_id) { |a, b| @data[a].name.downcase <=> @data[b].name.downcase }
  1133.     when :level
  1134.       @sort_arrays[sort_type].maqj_insert_sort(quest_id) { |a, b| @data[a].level <=> self[b].level }
  1135.     end
  1136.   end
  1137.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1138.   # * Find Location
  1139.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1140.   def find_location(quest_id, cat = nil)
  1141.     if revealed?(quest_id)
  1142.       categories = $game_system.quest_categories.dup
  1143.       # If cat specified, check in that category first.
  1144.       if cat && categories.include?(cat)
  1145.         categories.delete(cat)
  1146.         categories.unshift(cat)
  1147.       end
  1148.       for category in categories # Check all categories
  1149.         index = list(category).index(@data[quest_id])
  1150.         return category, index if index != nil
  1151.       end
  1152.     end
  1153.     return nil, nil
  1154.   end
  1155.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1156.   # * Clear
  1157.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1158.   def clear
  1159.     @data.clear
  1160.   end
  1161. end
  1162.  
  1163. #==============================================================================
  1164. # ** Game System
  1165. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1166. #  Summary of Changes:
  1167. #    new attr_accessor - quest_menu_access; quest_map_access; quest_sort_type;
  1168. #      quest_bg_picture; quest_bg_opacity; quest_windowskin;
  1169. #      quest_window_opacity; quest_access_disabled; last_quest_cat;
  1170. #      last_quest_id
  1171. #    aliased methods - initialize
  1172. #    new methods - init_maqj_data
  1173. #==============================================================================
  1174.  
  1175. class Game_System
  1176.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1177.   # * Public Instance Variables
  1178.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1179.   attr_reader   :quest_menu_access     # Whether the scene is called from menu
  1180.   attr_accessor :quest_map_access      # Whether the scene is called from map
  1181.   attr_accessor :quest_sort_type       # The sort types for each category
  1182.   attr_accessor :quest_bg_picture      # The filename of the background picture
  1183.   attr_accessor :quest_bg_opacity      # The opacity of the background picture
  1184.   attr_accessor :quest_bg_blend_type   # The blend type of the background pic
  1185.   attr_accessor :quest_windowskin      # The windowskin used for the scene
  1186.   attr_accessor :quest_window_tone     # The tone of windows in the scene
  1187.   attr_accessor :quest_window_opacity  # The opacity of windows in the scene
  1188.   attr_accessor :quest_access_disabled # Whether access to Quests is disabled
  1189.   attr_accessor :quest_categories      # The categories to show in the scene
  1190.   attr_accessor :quest_scene_label     # The label to show in the scene
  1191.   attr_accessor :last_quest_cat        # The category to open to
  1192.   attr_accessor :last_quest_id         # The ID to open to
  1193.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1194.   # * Object Initialization
  1195.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1196.   alias maqj_initialze_2cy9 initialize
  1197.   def initialize(*args, &block)
  1198.     maqj_initialze_2cy9(*args, &block)
  1199.     init_maqj_data
  1200.   end
  1201.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1202.   # * Initialize Quest Data
  1203.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1204.   def init_maqj_data
  1205.     # Initialize new variables
  1206.     self.quest_menu_access = QuestData::MENU_ACCESS
  1207.     @quest_map_access = QuestData::MAP_ACCESS
  1208.     @quest_sort_type = QuestData::SORT_TYPE
  1209.     @quest_bg_picture = QuestData::BG_PICTURE
  1210.     @quest_bg_opacity = QuestData::BG_OPACITY
  1211.     @quest_bg_blend_type = QuestData::BG_BLEND_TYPE
  1212.     @quest_windowskin = QuestData::WINDOWSKIN
  1213.     @quest_window_tone = QuestData::WINDOW_TONE
  1214.     @quest_window_opacity = QuestData::WINDOW_OPACITY
  1215.     @quest_access_disabled = false
  1216.     @quest_categories = QuestData::CATEGORIES
  1217.     @quest_scene_label = QuestData::VOCAB[:scene_label]
  1218.     @last_quest_cat = @quest_categories[0]
  1219.     @last_quest_id = 0
  1220.   end
  1221.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1222.   # * Set Quest Menu Access
  1223.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1224.   def quest_menu_access=(boolean)
  1225.     @quest_menu_access = boolean
  1226.     maic_inserted_menu_commands.delete(:quest_journal)
  1227.     maic_inserted_menu_commands.push(:quest_journal) if @quest_menu_access
  1228.     maic_inserted_menu_commands.sort!
  1229.   end
  1230. end
  1231.  
  1232. #==============================================================================
  1233. # ** Game_Party
  1234. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1235. #  Summary of Changes:
  1236. #    new attr_reader - quests
  1237. #    aliased method - initialize
  1238. #    new method - init_maqj_data
  1239. #==============================================================================
  1240.  
  1241. class Game_Party
  1242.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1243.   # * Public Instance Variables
  1244.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1245.   attr_reader :quests
  1246.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1247.   # * Object Initialization
  1248.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1249.   alias maqj_intiaze_2si9 initialize
  1250.   def initialize(*args, &block)
  1251.     maqj_intiaze_2si9(*args, &block) # Call Original Method
  1252.     init_maqj_data
  1253.   end
  1254.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1255.   # * Initialize Quests
  1256.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1257.   def init_maqj_data
  1258.     @quests = Game_Quests.new # Initialize @quests
  1259.   end
  1260. end
  1261.  
  1262. #==============================================================================
  1263. # ** Game_Interpreter
  1264. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1265. #  Summary of Changes:
  1266. #    new methods - change_quest_access; change_quest_background;
  1267. #      change_quest_windows; setup_quest; delete_quest; reset_quest; quest;
  1268. #      reveal_quest; conceal_quest; manually_complete_quest;
  1269. #      manually_fail_quest; reveal_objective; conceal_objective;
  1270. #      complete_objective; uncomplete_objective; fail_objective;
  1271. #      unfail_objective; quest_revealed?; quest_complete?; quest_active?;
  1272. #      quest_failed?; objective_complete?; objective_active?;
  1273. #      objective_failed?; distribute_quest_rewards; distribute_quest_reward;
  1274. #      call_quest_journal
  1275. #==============================================================================
  1276.  
  1277. class Game_Interpreter
  1278.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1279.   # * Change Quest Access
  1280.   #    sym : symbol representing what aspect of access is being changed
  1281.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1282.   def change_quest_access(sym)
  1283.     case sym
  1284.     when :enable then $game_system.quest_access_disabled = false
  1285.     when :disable then $game_system.quest_access_disabled = true
  1286.     when :enable_menu then $game_system.quest_menu_access = true
  1287.     when :disable_menu then $game_system.quest_menu_access = false
  1288.     when :enable_map then $game_system.quest_map_access = true
  1289.     when :disable_map then $game_system.quest_map_access = false
  1290.     end
  1291.   end
  1292.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1293.   # * Change Quest Background
  1294.   #    picture : picture to show in the scene's background
  1295.   #    opacity : opacity of the picture shown in the scene's background
  1296.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1297.   def change_quest_background(picture, opacity = $game_system.quest_bg_opacity,
  1298.       blend_type = $game_system.quest_bg_blend_type)
  1299.     $game_system.quest_bg_picture = picture
  1300.     $game_system.quest_bg_opacity = opacity
  1301.     $game_system.quest_bg_blend_type = blend_type
  1302.   end
  1303.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1304.   # * Change Quest Windows
  1305.   #    skin    : windowskin name to use in the scene
  1306.   #    tone    : tone for the windowskin
  1307.   #    opacity : opacity of windows in the scene
  1308.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1309.   def change_quest_windows(skin, tone = $game_system.quest_window_tone,
  1310.       opacity = $game_system.quest_window_opacity)
  1311.     $game_system.quest_windowskin = skin
  1312.     $game_system.quest_window_tone = tone
  1313.     $game_system.quest_window_opacity = opacity
  1314.   end
  1315.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1316.   # * Setup/Delete/Reset Quest
  1317.   #    quest_id : ID of the quest to be setup or deleted or reset
  1318.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1319.   [:setup_quest, :delete_quest, :reset_quest].each { |method|
  1320.     define_method(method) do |quest_id|
  1321.       $game_party.quests.send(method, quest_id)
  1322.     end
  1323.   }
  1324.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1325.   # * Retrieve Quest
  1326.   #    quest_id : ID of the quest to retrieve
  1327.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1328.   def quest(quest_id);         $game_party.quests[quest_id];      end
  1329.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1330.   # * Reveal/Conceal Quest
  1331.   #    quest_id : ID of the quest to be revealed or concealed
  1332.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1333.   def reveal_quest(quest_id);  quest(quest_id).concealed = false; end
  1334.   def conceal_quest(quest_id); quest(quest_id).concealed = true;  end
  1335.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1336.   # * Manually Complete/Fail Quest
  1337.   #    quest_id : ID of the quest to be revealed or concealed
  1338.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1339.   def manually_complete_quest(quest_id)
  1340.     quest(quest_id).prime_objectives.clear
  1341.     quest(quest_id).manual_status = :complete
  1342.   end
  1343.   def manually_fail_quest(quest_id)
  1344.     quest(quest_id).prime_objectives.clear
  1345.     quest(quest_id).manual_status = :failed
  1346.   end
  1347.   def manually_activate_quest(quest_id)
  1348.     quest(quest_id).manual_status = :active
  1349.   end
  1350.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1351.   # * Reveal/Complete/Fail/Conceal/Uncomplete/Unfail Objective
  1352.   #    quest_id : ID of the quest whose objectives will be modified
  1353.   #    *obj     : IDs of objectives to reveal or complete or fail (or opposite)
  1354.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1355.   [:reveal_objective, :complete_objective, :fail_objective, :conceal_objective,
  1356.   :uncomplete_objective, :unfail_objective].each { |method|
  1357.     define_method(method) do |quest_id, *obj|
  1358.       quest(quest_id).send(method, *obj)
  1359.     end
  1360.   }
  1361.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1362.   # * Quest Revealed?
  1363.   #    quest_id : ID of the quest you are checking is revealed
  1364.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1365.   def quest_revealed?(quest_id)
  1366.     $game_party.quests.revealed?(quest_id)
  1367.   end
  1368.   [:complete, :failed, :active].each { |method|
  1369.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1370.     # * Quest Complete/Failed/Active?
  1371.     #    quest_id : ID of the quest whose completion status is being checked
  1372.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1373.     define_method(:"quest_#{method}?") do |quest_id|
  1374.       quest_revealed?(quest_id) && quest(quest_id).status?(method)
  1375.     end
  1376.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1377.     # * Objective Complete/Failed/Active?
  1378.     #    quest_id : ID of the quest whose objectives are being checked
  1379.     #    *obj     : IDs of objectives to check completion status
  1380.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1381.     define_method(:"objective_#{method}?") do |quest_id, *obj|
  1382.       quest_revealed?(quest_id) && quest(quest_id).objective_status?(method, *obj)
  1383.     end
  1384.   }
  1385.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1386.   # * Objective Revealed?
  1387.   #    quest_id : ID of the quest you are checking is revealed
  1388.   #    *obj     : IDs of objectives to check completion status
  1389.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1390.   def objective_revealed?(quest_id, *obj)
  1391.     quest_revealed?(quest_id) && quest(quest_id).objective_status?(:revealed, *obj)
  1392.   end
  1393.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1394.   # * Quest Rewarded?
  1395.   #    quest_id : ID of the quest you are checking is revealed
  1396.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1397.   def quest_rewarded?(quest_id)
  1398.     quest_revealed?(quest_id) && quest(quest_id).status?(:reward)
  1399.   end
  1400.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1401.   # * Change Reward Status
  1402.   #    quest_id : ID of the quest you are checking is revealed
  1403.   #    value    : true or false
  1404.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1405.   def change_reward_status(quest_id, value = true)
  1406.     quest(quest_id).reward_given = value
  1407.   end
  1408.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1409.   # * Distribute Rewards
  1410.   #    quest_id : ID of the quest whose rewards are to be distributed
  1411.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1412.   def distribute_quest_rewards(quest_id)
  1413.     if quest_revealed?(quest_id) && !quest_rewarded?(quest_id)
  1414.       params = @params.dup
  1415.       change_reward_status(quest_id, true)
  1416.       quest(quest_id).rewards.each { |reward| distribute_quest_reward(reward) }
  1417.       @params = params
  1418.       true
  1419.     else
  1420.       false
  1421.     end
  1422.   end
  1423.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1424.   # * Distribute Reward
  1425.   #    reward : an array identifying the reward
  1426.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1427.   def distribute_quest_reward(reward)
  1428.     @params = [reward[1], 0, 0, (reward[2] ? reward[2] : 1)]
  1429.     case reward[0]
  1430.     when :item, 0 then   command_126 # Item
  1431.     when :weapon, 1 then command_127 # Weapon
  1432.     when :armor, 2 then  command_128 # Armor
  1433.     when :gold, 3   # Gold
  1434.       @params = [0, 0, reward[1] ? reward[1] : 0]
  1435.       command_125
  1436.     when :exp, 4    # Exp
  1437.       @params = [0, 0, 0, 0, reward[1] ? reward[1] : 0, true]
  1438.       command_315
  1439.     end
  1440.   end
  1441.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1442.   # * Call Quest Journal
  1443.   #    quest_id : ID of the quest to open the journal to
  1444.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1445.   def call_quest_journal(quest_id = nil)
  1446.     return if $game_party.in_battle
  1447.     $game_system.last_quest_id = quest_id if quest_id
  1448.     SceneManager.call(Scene_Quest)
  1449.     Fiber.yield
  1450.   end
  1451. end
  1452.  
  1453. unless $imported[:"MA_ParagraphFormat_1.0"]
  1454. #==============================================================================
  1455. # ** MA_Window_ParagraphFormat
  1456. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1457. #  This module inserts into Window_Base and provides a method to format the
  1458. # strings so as to go to the next line if it exceeds a set limit. This is
  1459. # designed to work with draw_text_ex, and a string formatted by this method
  1460. # should go through that, not draw_text.
  1461. #==============================================================================
  1462.  
  1463. module MA_Window_ParagraphFormat
  1464.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1465.   # * Calc Line Width
  1466.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1467.   def mapf_calc_line_width(line, tw = 0, contents_dummy = false)
  1468.     return tw if line.nil?
  1469.     line = line.clone
  1470.     unless contents_dummy
  1471.       real_contents = contents # Preserve Real Contents
  1472.       # Create a dummy contents
  1473.       self.contents = Bitmap.new(contents_width, 24)
  1474.       reset_font_settings
  1475.     end
  1476.     pos = {x: 0, y: 0, new_x: 0, height: calc_line_height(line)}
  1477.     while line[/^(.*?)\e(.*)/]
  1478.       tw += text_size($1).width
  1479.       line = $2
  1480.       # Remove all ancillaries to the code, like parameters
  1481.       code = obtain_escape_code(line)
  1482.       # If direct setting of x, reset tw.
  1483.       tw = 0 if ($imported[:ATS_SpecialMessageCodes] && code.upcase == 'X') ||
  1484.         ($imported["YEA-MessageSystem"] && code.upcase == 'PX')
  1485.       #  If I need to do something special on the basis that it is testing,
  1486.       # alias process_escape_character and differentiate using @atsf_testing
  1487.       process_escape_character(code, line, pos)
  1488.     end
  1489.     #  Add width of remaining text, as well as the value of pos[:x] under the
  1490.     # assumption that any additions to it are because the special code is
  1491.     # replaced by something which requires space (like icons)
  1492.     tw += text_size(line).width + pos[:x]
  1493.     unless contents_dummy
  1494.       contents.dispose # Dispose dummy contents
  1495.       self.contents = real_contents # Restore real contents
  1496.     end
  1497.     return tw
  1498.   end
  1499.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1500.   # * Format Paragraph
  1501.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1502.   def mapf_format_paragraph(text, max_width = contents_width)
  1503.     text = text.clone
  1504.     #  Create a Dummy Contents - I wanted to boost compatibility by using the
  1505.     # default process method for escape codes. It may have the opposite effect,
  1506.     # for some :(
  1507.     real_contents = contents # Preserve Real Contents
  1508.     self.contents = Bitmap.new(contents_width, 24)
  1509.     reset_font_settings
  1510.     paragraph = ""
  1511.     while !text.empty?
  1512.       text.lstrip!
  1513.       oline, nline, tw = mapf_format_by_line(text.clone, max_width)
  1514.       # Replace old line with the new one
  1515.       text.sub!(/#{Regexp.escape(oline)}/m, nline)
  1516.       paragraph += text.slice!(/.*?(\n|$)/)
  1517.     end
  1518.     contents.dispose # Dispose dummy contents
  1519.     self.contents = real_contents # Restore real contents
  1520.     return paragraph
  1521.   end
  1522.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1523.   # * Format By Line
  1524.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1525.   def mapf_format_by_line(text, max_width = contents_width)
  1526.     oline, nline, tw = "", "", 0
  1527.     loop do
  1528.       #  Format each word until reach the width limit
  1529.       oline, nline, tw, done = mapf_format_by_word(text, nline, tw, max_width)
  1530.       return oline, nline, tw if done
  1531.     end
  1532.   end
  1533.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1534.   # * Format By Word
  1535.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1536.   def mapf_format_by_word(text, line, tw, max_width)
  1537.     return line, line, tw, true if text.nil? || text.empty?
  1538.     # Extract next word
  1539.     if text.sub!(/([ \t\r\f]*)(\S*)([\n\f]?)/, "") != nil
  1540.       prespace, word, line_end = $1, $2, $3
  1541.       ntw = mapf_calc_line_width(word, tw, true)
  1542.       pw = contents.text_size(prespace).width
  1543.       if (pw + ntw >= max_width)
  1544.         # Insert
  1545.         if line.empty?
  1546.           # If one word takes entire line
  1547.           return prespace + word, word + "\n", ntw, true
  1548.         else
  1549.           return line + prespace + word, line + "\n" + word, tw, true
  1550.         end
  1551.       else
  1552.         line += prespace + word
  1553.         tw = pw + ntw
  1554.         # If the line is force ended, then end
  1555.         return line, line, tw, true if !line_end.empty?
  1556.       end
  1557.     else
  1558.       return line, line, tw, true
  1559.     end
  1560.     return line, line, tw, false
  1561.   end
  1562. end
  1563.  
  1564. class Window_Base
  1565.   include MA_Window_ParagraphFormat
  1566. end
  1567.  
  1568. $imported[:"MA_ParagraphFormat_1.0"] = true
  1569. end
  1570.  
  1571. #==============================================================================
  1572. # *** MAQJ Window_QuestBase
  1573. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1574. #  This module mixes in with all quest windows
  1575. #==============================================================================
  1576.  
  1577. module MAQJ_Window_QuestBase
  1578.   attr_reader :maqj_objective_color
  1579.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1580.   # * Object Initialization
  1581.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1582.   def initialize(*args, &block)
  1583.     super(*args, &block)
  1584.     reset_font_settings
  1585.     set_data_font(:normal)
  1586.     @maqj_default_font = contents.font.dup
  1587.     # Change the windowskin, tone if they are set to be changed
  1588.     self.windowskin = Cache.system($game_system.quest_windowskin) if $game_system.quest_windowskin
  1589.     self.opacity = $game_system.quest_window_opacity if $game_system.quest_window_opacity
  1590.   end
  1591.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1592.   # * Reset Font Settings
  1593.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1594.   def reset_font_settings(*args, &block)
  1595.     super(*args, &block)
  1596.     set_data_font(@maqj_font_data_type) if @maqj_font_data_type
  1597.   end
  1598.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1599.   # * Set Data Font
  1600.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1601.   def set_data_font(data_type)
  1602.     @maqj_default_font = contents.font.dup unless @maqj_default_font
  1603.     contents.font.name = QuestData::FONTNAMES[data_type] ?
  1604.       QuestData::FONTNAMES[data_type] : @maqj_default_font.name
  1605.     contents.font.size = QuestData::FONTSIZES[data_type] ?
  1606.       QuestData::FONTSIZES[data_type] : @maqj_default_font.size
  1607.     contents.font.bold = QuestData::FONTBOLDS.keys.include?(data_type) ?
  1608.       QuestData::FONTBOLDS[data_type] : @maqj_default_font.bold
  1609.     contents.font.italic = QuestData::FONTITALICS.keys.include?(data_type) ?
  1610.       QuestData::FONTITALICS[data_type] : @maqj_default_font.italic
  1611.     case data_type
  1612.     when :objectives then change_color(@maqj_objective_color) if @maqj_objective_color
  1613.     when :name then change_color(quest_name_colour(@quest)) if @quest
  1614.     else
  1615.       change_color(text_color(QuestData::COLOURS[data_type])) if QuestData::COLOURS.keys.include?(data_type)
  1616.     end
  1617.   end
  1618.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1619.   # * Draw Horizontal Line
  1620.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1621.   def draw_horizontal_line(y, h = 2)
  1622.     contents.fill_rect(0, y, contents_width, h, text_color(QuestData::COLOURS[:line]))
  1623.     contents.fill_rect(0, y + h, contents_width, [h / 2, 1].max, text_color(QuestData::COLOURS[:line_shadow]))
  1624.   end
  1625.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1626.   # * MA Text Color
  1627.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1628.   def text_color(param)
  1629.     begin
  1630.       colour = case param
  1631.       when Integer then super(param) rescue normal_color
  1632.       when Symbol then send(param) rescue normal_color
  1633.       when Array then Color.new(*param) rescue normal_color
  1634.       else
  1635.         normal_color
  1636.       end
  1637.     end
  1638.     colour.is_a?(Color) ? colour : normal_color
  1639.   end
  1640.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1641.   # * Quest Name Colour
  1642.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1643.   def quest_name_colour(quest = @quest)
  1644.     return if !quest
  1645.     quest = $game_party.quests[quest] if quest.is_a?(Integer)
  1646.     s = [:failed, :complete, :active].find { |status| quest.status?(status) }
  1647.     text_color(QuestData::COLOURS[s])
  1648.   end
  1649.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1650.   # * Quest Objective Colour
  1651.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1652.   def quest_objective_colour(quest, obj_id)
  1653.     return if !quest
  1654.     quest = $game_party.quests[quest] if quest.is_a?(Integer)
  1655.     s = [:failed, :complete, :active].find { |status| quest.objective_status?(status, obj_id) }
  1656.     text_color(QuestData::COLOURS[s])
  1657.   end
  1658.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1659.   # * Update Tone
  1660.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1661.   def update_tone
  1662.     $game_system.quest_window_tone ?
  1663.       self.tone.set(*$game_system.quest_window_tone) : super
  1664.   end
  1665. end
  1666.  
  1667. unless $imported[:"MA_IconHorzCommand_1.0"]
  1668. #==============================================================================
  1669. # ** Window_MA_IconHorzCommand
  1670. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1671. #  This window is a base window to show a horizontal command window populated
  1672. # with icons.
  1673. #==============================================================================
  1674.  
  1675. class Window_MA_IconHorzCommand < Window_HorzCommand
  1676.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1677.   # * Public Instance Variable
  1678.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1679.   attr_reader   :observing_procs
  1680.   attr_accessor :cursor_hide
  1681.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1682.   # * Object Initialization
  1683.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1684.   def initialize(*args, &block)
  1685.     @observing_procs = {}
  1686.     super(*args, &block)
  1687.   end
  1688.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1689.   # * Column Max
  1690.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1691.   def col_max; [(width - standard_padding) / (24 + spacing), item_max].min; end
  1692.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1693.   # * Item
  1694.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1695.   def item
  1696.     @list[index] ? @list[index][:symbol] : nil
  1697.   end
  1698.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1699.   # * Enabled? / Current Item Enabled?
  1700.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1701.   def enable?(index); self.index == index; end
  1702.   def current_item_enabled?; !current_data.nil?; end
  1703.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1704.   # * Draw Item
  1705.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1706.   def draw_item(index)
  1707.     rect = item_rect(index)
  1708.     contents.clear_rect(rect)
  1709.     draw_icon(@list[index][:ext], rect.x + ((rect.width - 24) / 2), rect.y, enable?(index))
  1710.   end
  1711.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1712.   # * Set Index
  1713.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1714.   def index=(index)
  1715.     old_index = self.index
  1716.     super(index)
  1717.     draw_item(old_index)
  1718.     draw_item(self.index)
  1719.   end
  1720.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1721.   # * Frame Update
  1722.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1723.   def update
  1724.     super
  1725.     @observing_procs.values.each { |block| block.call(item) }
  1726.   end
  1727.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1728.   # * Add/Remove Observing Window
  1729.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1730.   def add_observing_proc(id, &block)
  1731.     @observing_procs[id] = block
  1732.     update
  1733.   end
  1734.   def remove_observing_proc(id)     ; @observing_procs.delete(id) ; end
  1735.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1736.   # * Update Cursor
  1737.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1738.   def update_cursor
  1739.     super
  1740.     cursor_rect.empty if @cursor_hide
  1741.   end
  1742. end
  1743. $imported[:"MA_IconHorzCommand_1.0"] = true
  1744. end
  1745.  
  1746. #==============================================================================
  1747. # ** Window_QuestCategory
  1748. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1749. #  This window allows the player to switch between quest categories.
  1750. #==============================================================================
  1751.  
  1752. class Window_QuestCategory < Window_MA_IconHorzCommand
  1753.   include MAQJ_Window_QuestBase
  1754.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1755.   # * Object Initialization
  1756.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1757.   def initialize(x, y, categories = $game_system.quest_categories)
  1758.     @cursor_hide = QuestData::HIDE_CATEGORY_CURSOR
  1759.     @categories = categories
  1760.     super(x, y)
  1761.   end
  1762.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1763.   # * Window Width
  1764.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1765.   def window_width; QuestData::LIST_WINDOW_WIDTH; end
  1766.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1767.   # * Category=
  1768.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1769.   def category=(category)
  1770.     self.index = @categories.index(category) if @categories.include?(category)
  1771.   end
  1772.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1773.   # * Make Command List
  1774.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1775.   def make_command_list
  1776.     @categories.each { |cat|
  1777.       add_command("", cat, false, QuestData::ICONS[cat]) }
  1778.   end
  1779. end
  1780.  
  1781. #==============================================================================
  1782. # ** Window QuestLabel
  1783. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1784. #  This window simply shows a label for the Quests scene
  1785. #==============================================================================
  1786.  
  1787. class Window_QuestLabel < Window_Base
  1788.   include MAQJ_Window_QuestBase
  1789.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1790.   # * Object Initialization
  1791.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1792.   def initialize(x, y, label = "")
  1793.     super(x, y, window_width, window_height)
  1794.     refresh(label)
  1795.   end
  1796.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1797.   # * Reset Font Settings
  1798.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1799.   def reset_font_settings; set_data_font(:scene_label); end
  1800.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1801.   # * Window Attributes
  1802.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1803.   def window_width
  1804.     w = ($game_system.quest_categories.size > 1 || QuestData::SHOW_CATEGORY_LABEL) ?
  1805.       Graphics.width - QuestData::LIST_WINDOW_WIDTH : QuestData::LIST_WINDOW_WIDTH
  1806.   end
  1807.   def window_height; line_height + (standard_padding*2); end
  1808.   def line_height(*args)
  1809.     line_h = super(*args)
  1810.     QuestData::FONTSIZES[:scene_label] ?
  1811.       [QuestData::FONTSIZES[:scene_label], line_h].max : line_h
  1812.   end
  1813.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1814.   # * Refresh
  1815.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1816.   def refresh(label = @label)
  1817.     @label = label.is_a?(String) ? convert_escape_characters(label) : ""
  1818.     contents.clear
  1819.     reset_font_settings
  1820.     tw = mapf_calc_line_width(@label)
  1821.     draw_text_ex((contents_width - tw) / 2, 0, @label)
  1822.   end
  1823. end
  1824.  
  1825. #==============================================================================
  1826. # ** Window QuestLabel
  1827. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1828. #  This window simply shows a label for category currently selected
  1829. #==============================================================================
  1830.  
  1831. class Window_QuestCategoryLabel < Window_QuestLabel
  1832.   include MAQJ_Window_QuestBase
  1833.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1834.   # * Reset Font Settings
  1835.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1836.   def reset_font_settings; set_data_font(:category_label); end
  1837.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1838.   # * Window Attributes
  1839.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1840.   def window_width; QuestData::LIST_WINDOW_WIDTH; end
  1841.   def line_height(*args)
  1842.     line_h = super(*args)
  1843.     QuestData::FONTSIZES[:category_label] ?
  1844.       [QuestData::FONTSIZES[:category_label], line_h].max : line_h
  1845.   end
  1846.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1847.   # * Set Category
  1848.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1849.   def category=(category)
  1850.     return if @category == category
  1851.     @category = category
  1852.     refresh(QuestData::CATEGORY_VOCAB[category])
  1853.   end
  1854. end
  1855.  
  1856. #==============================================================================
  1857. # ** Window_QuestCategoryDummy
  1858. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1859. #  This window shows up behind the category and category label window
  1860. #==============================================================================
  1861.  
  1862. class Window_QuestCategoryDummy < Window_Base
  1863.   include MAQJ_Window_QuestBase
  1864. end
  1865.  
  1866. #==============================================================================
  1867. # ** Window_QuestList
  1868. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1869. #  This window shows all quests in a selected category.
  1870. #==============================================================================
  1871.  
  1872. class Window_QuestList < Window_Selectable
  1873.   include MAQJ_Window_QuestBase
  1874.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1875.   # * Object Initialization
  1876.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1877.   def initialize(x, y, width, height)
  1878.     super
  1879.     @data = []
  1880.     self.index = 0
  1881.     activate
  1882.   end
  1883.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1884.   # * Set Category
  1885.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1886.   def category=(category)
  1887.     return if @category == category
  1888.     @category = category
  1889.     refresh
  1890.     self.index = 0
  1891.     update_help if @help_window
  1892.   end
  1893.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1894.   # * Get Quest
  1895.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1896.   def item; @data && index >= 0 ? @data[index] : nil; end
  1897.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1898.   # * Column/Item Max
  1899.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1900.   def col_max; 1; end
  1901.   def item_max; @data ? @data.size : 1; end
  1902.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1903.   # * Whether it should be drawn enabled
  1904.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1905.   def enable?(item); true; end
  1906.   def current_item_enabled?
  1907.     (@help_window && @help_window.maqj_visible_height < @help_window.contents_height)
  1908.   end
  1909.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1910.   # * Make Item List
  1911.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1912.   def make_item_list
  1913.     @data = @category ? $game_party.quests.list(@category) : []
  1914.   end
  1915.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1916.   # * Draw Item
  1917.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1918.   def draw_item(index)
  1919.     quest = @data[index]
  1920.     if quest
  1921.       rect = item_rect_for_text(index)
  1922.       if QuestData::SHOW_QUEST_ICONS
  1923.         draw_icon(quest.icon_index, rect.x, rect.y, enable?(quest))
  1924.         rect.x += 24
  1925.         rect.width -= 24
  1926.       end
  1927.       change_color(quest_name_colour(quest), enable?(quest))
  1928.       draw_text(rect, quest.name)
  1929.     end
  1930.   end
  1931.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1932.   # * Refresh
  1933.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1934.   def refresh
  1935.     make_item_list
  1936.     create_contents
  1937.     set_data_font(:list)
  1938.     draw_all_items
  1939.   end
  1940.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1941.   # * Update Help
  1942.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1943.   def update_help
  1944.     @help_window.quest = item
  1945.   end
  1946. end
  1947.  
  1948. #==============================================================================
  1949. # ** Window_QuestData
  1950. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1951. #  This window shows all quest data
  1952. #==============================================================================
  1953.  
  1954. class Window_QuestData < Window_Selectable
  1955.   include MAQJ_Window_QuestBase
  1956.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1957.   # * Object Initialization
  1958.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1959.   def initialize(x, y, w, h, layout = QuestData::DATA_LAYOUT)
  1960.     @dest_scroll_oy = 0
  1961.     super(x, y, w, h)
  1962.     @dest_scroll_oy = self.oy
  1963.     self.layout = layout
  1964.   end
  1965.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1966.   # * Contents Height
  1967.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1968.   alias maqj_visible_height contents_height
  1969.   def contents_height
  1970.     @q_contents_height ? [@q_contents_height, maqj_visible_height].max : maqj_visible_height
  1971.   end
  1972.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1973.   # * Calculate Contents Height
  1974.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1975.   def calc_contents_height
  1976.     @q_contents_height = 0
  1977.     @layout.each { |dt| @q_contents_height += data_height(dt) } if @quest
  1978.   end
  1979.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1980.   # * Draw Data?
  1981.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1982.   def draw_data?(data_type)
  1983.     case data_type
  1984.     when :line then true
  1985.     when :level then @quest.level > 0
  1986.     when :objectives then !@quest.revealed_objectives.empty?
  1987.     when Array then (data_type - [:line]).any? { |dt| draw_data?(dt) }
  1988.     else !@quest.send(data_type).empty? # :description, :name, etc...
  1989.     end
  1990.   end
  1991.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1992.   # * Get Data Height
  1993.   #    This method calculates the height required for a specified element of
  1994.   #   the current quest. This is to calculate the needed space in contents,
  1995.   #   as well as advance the @draw_y variable.
  1996.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1997.   def data_height(data_type)
  1998.     return 0 unless draw_data?(data_type)
  1999.     return line_height if QuestData::BASIC_DATA_TYPES.include?(data_type)
  2000.     @maqj_font_data_type = data_type
  2001.     reset_font_settings
  2002.     return case data_type
  2003.     when :line, :level, :name then line_height
  2004.     when :banner
  2005.       bmp = Cache.picture(@quest.banner)
  2006.       hght = bmp.rect.height
  2007.       bmp.dispose
  2008.       hght
  2009.     when :description
  2010.       buff = description_x*2
  2011.       paragraph = mapf_format_paragraph(@quest.description, contents_width - buff)
  2012.       line_num = paragraph.scan(/\n/).size + 1
  2013.       line_num += (QuestData::DESCRIPTION_IN_BOX ? 2 :
  2014.         !QuestData::VOCAB[:description].empty? ? 1 : 0)
  2015.       line_num*line_height
  2016.     when :objectives
  2017.       objectives = @quest.revealed_objectives.collect { |obj_id|
  2018.         @quest.objectives[obj_id] }
  2019.       line_num = QuestData::VOCAB[:objectives].empty? ? 0 : 1
  2020.       buff = (objective_x*2) + text_size(QuestData::VOCAB[:objective_bullet]).width
  2021.       objectives.each { |obj|
  2022.         paragraph = mapf_format_paragraph(obj, contents_width - buff)
  2023.         line_num += paragraph.scan(/\n/).size + 1 }
  2024.       line_num*line_height
  2025.     when :rewards
  2026.       line_num = QuestData::VOCAB[:rewards].empty? ? 0 : 1
  2027.       (line_num + @quest.rewards.size)*line_height
  2028.     when Array then data_height(data_type.max_by { |dt| data_height(dt) })
  2029.     else 0
  2030.     end
  2031.   end
  2032.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2033.   # * Set Quest
  2034.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2035.   def quest=(value)
  2036.     return if @quest == value
  2037.     @quest = value
  2038.     @layout = (@quest && @quest.layout) ? @quest.layout : @default_layout
  2039.     refresh
  2040.   end
  2041.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2042.   # * Set Layout
  2043.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2044.   def layout=(value)
  2045.     return if @default_layout == value && @layout == value
  2046.     @default_layout = value
  2047.     @layout = value
  2048.     refresh
  2049.   end
  2050.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2051.   # * Refresh
  2052.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2053.   def refresh
  2054.     contents.clear
  2055.     calc_contents_height
  2056.     create_contents
  2057.     return unless @quest && @layout
  2058.     self.oy = 0
  2059.     @dest_scroll_oy = 0
  2060.     #  The basic idea here is that each draw_ method will rely on and advance
  2061.     # the @draw_y variable. Where they are an array, the elements will be
  2062.     # drawn at the same @draw_y.
  2063.     @draw_y = 0
  2064.     @layout.each {|dt|
  2065.       next unless draw_data?(dt)
  2066.       dt.is_a?(Array) ? draw_data_array(dt) : draw_data(dt)
  2067.     }
  2068.   end
  2069.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2070.   # * Draw Data
  2071.   #    data_type : the data block to draw next
  2072.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2073.   def draw_data(data_type)
  2074.     @maqj_font_data_type = data_type
  2075.     reset_font_settings
  2076.     send(:"draw_#{data_type}") if self.class.method_defined?(:"draw_#{data_type}")
  2077.     @draw_y += data_height(data_type)
  2078.   end
  2079.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2080.   # * Draw Data Array
  2081.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2082.   def draw_data_array(layout_array)
  2083.     y, max_y = @draw_y, @draw_y
  2084.     # Draw each data aspect at the same starting @draw_y
  2085.     layout_array.each { |dt|
  2086.       @draw_y = y
  2087.       draw_data(dt)
  2088.       max_y = @draw_y if @draw_y > max_y
  2089.     }
  2090.     @draw_y = max_y
  2091.   end
  2092.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2093.   # * Draw Line
  2094.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2095.   def draw_line; draw_horizontal_line(@draw_y + (line_height / 2) - 1, 2); end
  2096.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2097.   # * Draw Name
  2098.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2099.   def draw_name
  2100.     set_data_font(:name)
  2101.     clear_and_draw_text(0, @draw_y, contents_width, line_height, @quest.name, 1)
  2102.   end
  2103.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2104.   # * Draw Level
  2105.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2106.   def draw_level
  2107.     case QuestData::LEVEL_ICON
  2108.     when Array then QuestData::LEVEL_ICON.empty? ? draw_level_text : draw_level_array
  2109.     when 0 then draw_level_text
  2110.     else
  2111.       draw_level_stacked
  2112.     end
  2113.   end
  2114.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2115.   # * Draw Stacked Level
  2116.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2117.   def draw_level_stacked(icon_index = QuestData::LEVEL_ICON)
  2118.     align = QuestData::HEADING_ALIGN[:level]
  2119.     es = QuestData::LEVEL_ICONS_SPACE*(@quest.level - 1)
  2120.     x = align == 2 ? contents_width - 24 : align == 1 ?
  2121.       (contents_width - 24 - (es)) / 2 : es
  2122.     @quest.level.times do
  2123.       draw_icon(icon_index, x, @draw_y)
  2124.       x -= QuestData::LEVEL_ICONS_SPACE
  2125.     end
  2126.   end
  2127.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2128.   # * Draw Array Level
  2129.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2130.   def draw_level_array(icon_index = QuestData::LEVEL_ICON)
  2131.     return if icon_index.empty?
  2132.     icon_index = icon_index[@quest.level - 1] ? icon_index[@quest.level - 1] : icon_index[-1]
  2133.     align = QuestData::HEADING_ALIGN[:level]
  2134.     x = align == 2 ? contents_width - 24 : align == 1 ? (contents_width-24)/2 : 0
  2135.     draw_icon(icon_index, x, @draw_y)
  2136.   end
  2137.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2138.   # * Draw Text Level
  2139.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2140.   def draw_level_text
  2141.     reset_font_settings
  2142.     level = QuestData::LEVEL_SIGNALS && QuestData::LEVEL_SIGNALS[@quest.level - 1] ?
  2143.       QuestData::LEVEL_SIGNALS[@quest.level - 1] : @quest.level.to_s
  2144.     align = QuestData::HEADING_ALIGN[:level]
  2145.     tw = text_size(QuestData::VOCAB[:level]).width + 4
  2146.     tw2 = text_size(level).width + 2
  2147.     space = contents_width - tw - tw2
  2148.     x = align == 2 ? space : align == 1 ? space / 2 : 0
  2149.     clear_and_draw_text(x, @draw_y, tw, line_height, QuestData::VOCAB[:level])
  2150.     set_data_font(:level_signal)
  2151.     clear_and_draw_text(x + tw, @draw_y, tw2, line_height, level, 2)
  2152.   end
  2153.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2154.   # * Draw Banner
  2155.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2156.   def draw_banner
  2157.     bmp = Cache.picture(@quest.banner) # Get Picture
  2158.     # Shift the hue if requested
  2159.     bmp.hue_change(@quest.banner_hue) unless @quest.banner_hue == 0
  2160.     x = (contents_width - bmp.rect.width) / 2
  2161.     if x < 0 # Stretch horizontally if the banner is too wide
  2162.       dest_rect = bmp.rect.dup
  2163.       dest_rect.width = contents_width
  2164.       contents.stretch_blt(dest_rect, bmp, bmp.rect)
  2165.     else
  2166.       contents.blt(x, @draw_y, bmp, bmp.rect)
  2167.     end
  2168.     bmp.dispose
  2169.   end
  2170.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2171.   # * Draw Description
  2172.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2173.   def draw_description
  2174.     buff = description_x*2
  2175.     paragraph = mapf_format_paragraph(@quest.description, contents_width - buff)
  2176.     y = @draw_y
  2177.     # Draw Rect
  2178.     draw_box(paragraph.scan(/\n/).size + 1) if QuestData::DESCRIPTION_IN_BOX
  2179.     # Draw Description Label
  2180.     draw_heading(:description, y) unless QuestData::VOCAB[:description].empty?
  2181.     # Draw Description
  2182.     y += line_height if !QuestData::VOCAB[:description].empty? || QuestData::DESCRIPTION_IN_BOX
  2183.     draw_text_ex(description_x, y, paragraph)
  2184.   end
  2185.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2186.   # * Draw Objectives
  2187.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2188.   def draw_objectives
  2189.     y = @draw_y
  2190.     unless QuestData::VOCAB[:objectives].empty?
  2191.       draw_heading(:objectives, y)
  2192.       y += line_height
  2193.     end
  2194.     @quest.revealed_objectives.each { |obj_id| y = draw_objective(obj_id, y) }
  2195.   end
  2196.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2197.   # * Draw Objective
  2198.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2199.   def draw_objective(obj_id, y)
  2200.     bullet = QuestData::VOCAB[:objective_bullet]
  2201.     bullet_tw = text_size(bullet).width + 2
  2202.     buff = (objective_x*2) + bullet_tw
  2203.     paragraph = mapf_format_paragraph(@quest.objectives[obj_id], contents_width - buff)
  2204.     line_num = 1 + paragraph.scan(/\n/).size
  2205.     # Since draw_text_ex resets the font, set colour here
  2206.     @maqj_objective_color = quest_objective_colour(@quest, obj_id)
  2207.     change_color(text_color(QuestData::COLOURS[:objective_bullet]))
  2208.     draw_text(objective_x, y, bullet_tw, line_height, sprintf(bullet, obj_id + 1))
  2209.     draw_text_ex(objective_x + bullet_tw, y, paragraph)
  2210.     @maqj_objective_color = false
  2211.     y += (line_num*line_height)
  2212.   end
  2213.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2214.   # * Draw Rewards
  2215.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2216.   def draw_rewards
  2217.     y = @draw_y
  2218.     unless QuestData::VOCAB[:rewards].empty?
  2219.       draw_heading(:rewards, y)
  2220.       y += line_height
  2221.     end
  2222.     for i in 0...@quest.rewards.size do draw_reward(i, y + i*line_height) end
  2223.   end
  2224.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2225.   # * Draw Reward
  2226.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2227.   def draw_reward(r_id, y)
  2228.     reward = @quest.rewards[r_id]
  2229.     case reward[0]
  2230.     when :item, 0   # Item
  2231.       draw_item_reward(y, $data_items[reward[1]], reward[2] ? reward[2] : 1)
  2232.     when :weapon, 1 # Weapon
  2233.       draw_item_reward(y, $data_weapons[reward[1]], reward[2] ? reward[2] : 1)
  2234.     when :armor, 2  # Armor
  2235.       draw_item_reward(y, $data_armors[reward[1]], reward[2] ? reward[2] : 1)
  2236.     when :gold, 3   # Gold
  2237.       draw_basic_data(y, QuestData::ICONS[:reward_gold],
  2238.         QuestData::VOCAB[:reward_gold], (reward[1] ? reward[1] : 0).to_s)
  2239.     when :exp, 4    # Exp
  2240.       draw_basic_data(y, QuestData::ICONS[:reward_exp],
  2241.         QuestData::VOCAB[:reward_exp], (reward[1] ? reward[1] : 0).to_s)
  2242.     when :string, 5 # String
  2243.       draw_basic_data(y, reward[1] ? reward[1] : 0, reward[3] ? reward[3].to_s : "",
  2244.         reward[2] ? reward[2].to_s : "")
  2245.     end
  2246.   end
  2247.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2248.   # * Draw Item Reward
  2249.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2250.   def draw_item_reward(y, item, amount = 1)
  2251.     w = contents_width
  2252.     w = QuestData::BASIC_DATA_WIDTH if QuestData::BASIC_DATA_WIDTH.between?(1, w)
  2253.     x = (contents_width - w) / 2
  2254.     draw_item_name(item, x, y, true, w - 40)
  2255.     if amount > 1
  2256.       change_color(text_color(QuestData::COLOURS[:reward_amount]))
  2257.       draw_text(x + w - 40, y, 40, line_height, sprintf(QuestData::VOCAB[:reward_amount], amount), 2)
  2258.     end
  2259.   end
  2260.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2261.   # * Draw Basic Data Methods
  2262.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2263.   QuestData::BASIC_DATA_TYPES.each { |data_type|
  2264.     define_method(:"draw_#{data_type}") {
  2265.       draw_basic_data(@draw_y, QuestData::ICONS[data_type],
  2266.         QuestData::VOCAB[data_type], @quest.send(data_type))
  2267.     }
  2268.   }
  2269.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2270.   # * Draw Basic Data
  2271.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2272.   def draw_basic_data(y, icon_index, vocab, value)
  2273.     w = contents_width
  2274.     w = QuestData::BASIC_DATA_WIDTH if QuestData::BASIC_DATA_WIDTH.between?(1, w)
  2275.     x = (contents_width - w) / 2
  2276.     unless icon_index == 0
  2277.       draw_icon(icon_index, x, y)
  2278.       x += 24
  2279.       w -= 24
  2280.     end
  2281.     tw = text_size(vocab).width
  2282.     change_color(text_color(QuestData::COLOURS[:basic_label]))
  2283.     draw_text(x, y, tw, line_height, vocab)
  2284.     change_color(text_color(QuestData::COLOURS[:basic_value]))
  2285.     draw_text(x + tw, y, w - tw, line_height, value, 2)
  2286.   end
  2287.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2288.   # * Draw Heading
  2289.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2290.   def draw_heading(data_type, y)
  2291.     set_data_font(:heading)
  2292.     clear_and_draw_text(40, y, contents_width - 80, line_height,
  2293.       QuestData::VOCAB[data_type], QuestData::HEADING_ALIGN[data_type])
  2294.     reset_font_settings
  2295.   end
  2296.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2297.   # * Clear and Draw Text
  2298.   #    Clear the field before drawing the text
  2299.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2300.   def clear_and_draw_text(*args)
  2301.     rect = []
  2302.     while !args[0].is_a?(String) do rect.push(args.shift) end
  2303.     rect[0].is_a?(Rect) ? rect = rect[0] : rect = Rect.new(*rect)
  2304.     align = args[1] ? args[1] : 0
  2305.     ts = text_size(args[0])
  2306.     ts.width = [ts.width + 4, rect.width].min
  2307.     align == 1 ? ts.x = rect.x + ((rect.width - ts.width) / 2) :
  2308.       align == 2 ? ts.x = rect.x + rect.width - ts.width : ts.x = rect.x
  2309.     ts.y = rect.y
  2310.     contents.clear_rect(ts)
  2311.     ts.x += 2
  2312.     draw_text(ts, args[0], align)
  2313.   end
  2314.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2315.   # * Draw Description Box
  2316.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2317.   def draw_box(line_num)
  2318.     return if line_num < 1
  2319.     x = (line_height / 2) - 1
  2320.     y = @draw_y + (line_height / 2) - 1
  2321.     w = contents_width - 2*x
  2322.     h = (1 + line_num)*line_height
  2323.     draw_rect_outline_with_shadow(x, y, w, h)
  2324.   end
  2325.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2326.   # * Draw Rect Outline
  2327.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2328.   def draw_rect_outline(x, y, w, h, colour)
  2329.     # Horizontal Lines
  2330.     contents.fill_rect(x, y, w, 2, colour)
  2331.     contents.fill_rect(x, y + h - 2, w, 2, colour)
  2332.     # Vertical Lines
  2333.     contents.fill_rect(x, y, 2, h, colour)
  2334.     contents.fill_rect(x + w - 2, y, 2, h, colour)
  2335.   end
  2336.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2337.   # * Draw Rect Outline with Shadow
  2338.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2339.   def draw_rect_outline_with_shadow(x, y, w, h)
  2340.     draw_rect_outline(x + 1, y + 1, w, h, text_color(QuestData::COLOURS[:line_shadow]))
  2341.     draw_rect_outline(x, y, w, h, text_color(QuestData::COLOURS[:line]))
  2342.   end
  2343.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2344.   # * Objective/Description X
  2345.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2346.   def objective_x; line_height / 2; end
  2347.   def description_x; QuestData::DESCRIPTION_IN_BOX ? line_height : (line_height/2); end
  2348.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2349.   # * Update
  2350.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2351.   def update(*args, &block)
  2352.     super(*args, &block)
  2353.     if open? && active && @dest_scroll_oy == self.oy
  2354.       scroll_down if Input.press?(:DOWN)
  2355.       scroll_up if Input.press?(:UP)
  2356.     end
  2357.     if self.oy != @dest_scroll_oy
  2358.       mod = (@dest_scroll_oy <=> self.oy)
  2359.       self.oy += 3*mod
  2360.       self.oy = @dest_scroll_oy if (@dest_scroll_oy <=> self.oy) != mod
  2361.     end
  2362.   end
  2363.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2364.   # * Scroll Down
  2365.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2366.   def scroll_down(*args, &block)
  2367.     max_oy = contents_height - maqj_visible_height
  2368.     dest = ((@dest_scroll_oy / line_height) + 1)*line_height
  2369.     @dest_scroll_oy = [dest, max_oy].min
  2370.   end
  2371.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2372.   # * Scroll Up
  2373.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2374.   def scroll_up(*args, &block)
  2375.     dest = ((@dest_scroll_oy / line_height) - 1)*line_height
  2376.     @dest_scroll_oy = [dest, 0].max
  2377.   end
  2378. end
  2379.  
  2380. #==============================================================================
  2381. # ** Scene_Quest
  2382. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2383. #  This class handles processing for the Quest scene
  2384. #==============================================================================
  2385.  
  2386. class Scene_Quest < Scene_MenuBase
  2387.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2388.   # * Start Scene Processing
  2389.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2390.   def start
  2391.     super
  2392.     @init_category, @init_quest_index = $game_party.quests.find_location($game_system.last_quest_id, $game_system.last_quest_cat)
  2393.     create_maqj_picture unless $game_system.quest_bg_picture.empty?
  2394.     create_all_windows
  2395.     adjust_window_positions
  2396.   end
  2397.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2398.   # * Terminate Scene
  2399.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2400.   def terminate
  2401.     $game_system.quest_categories = QuestData::CATEGORIES
  2402.     $game_system.quest_scene_label = QuestData::VOCAB[:scene_label]
  2403.     $game_system.last_quest_id = @quest_list_window.item ? @quest_list_window.item.id : 0
  2404.     $game_system.last_quest_cat = @quest_category_window ?
  2405.       @quest_category_window.item : $game_system.quest_categories[0]
  2406.     super
  2407.     dispose_maqj_picture
  2408.   end
  2409.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2410.   # * Create Background Picture
  2411.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2412.   def create_maqj_picture
  2413.     @maqj_picture_sprite = Sprite.new
  2414.     @maqj_picture_sprite.bitmap = Cache.picture($game_system.quest_bg_picture)
  2415.     @maqj_picture_sprite.opacity = $game_system.quest_bg_opacity
  2416.     @maqj_picture_sprite.blend_type = $game_system.quest_bg_blend_type
  2417.     @maqj_picture_sprite.z = @background_sprite.z + 1 if @background_sprite
  2418.   end
  2419.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2420.   # * Create All Windows
  2421.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2422.   def create_all_windows
  2423.     create_quest_label_window unless $game_system.quest_scene_label.empty?
  2424.     create_quest_category_window if $game_system.quest_categories.size > 1
  2425.     create_quest_category_label_window if QuestData::SHOW_CATEGORY_LABEL
  2426.     create_dummy_category_window if QuestData::CATEGORY_LABEL_IN_SAME_WINDOW &&
  2427.       @quest_category_window && @quest_category_label_window
  2428.     create_quest_list_window
  2429.     create_quest_data_window
  2430.   end
  2431.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2432.   # * Create QuestLabel Window
  2433.   #    This window shows the name of the scene
  2434.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2435.   def create_quest_label_window
  2436.     @quest_label_window = Window_QuestLabel.new(0, 0, $game_system.quest_scene_label)
  2437.   end
  2438.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2439.   # * Create QuestCategory Window
  2440.   #    This window allows the player to switch categories.
  2441.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2442.   def create_quest_category_window
  2443.     @quest_category_window = Window_QuestCategory.new(0, 0, $game_system.quest_categories)
  2444.     @quest_category_window.category = @init_category if @init_category
  2445.     @quest_category_window.set_handler(:cancel, method(:on_category_cancel))
  2446.     @quest_category_window.set_handler(:ok, method(:on_category_ok))
  2447.   end
  2448.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2449.   # * Create QuestCategoryLabel Window
  2450.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2451.   def create_quest_category_label_window
  2452.     if @quest_category_window
  2453.       @quest_category_label_window = Window_QuestCategoryLabel.new(0, @quest_category_window.height)
  2454.       @quest_category_window.add_observing_proc(:label) { |category|
  2455.         @quest_category_label_window.category = category }
  2456.     else
  2457.       @quest_category_label_window = Window_QuestCategoryLabel.new(0, 0)
  2458.       @quest_category_label_window.category = $game_system.quest_categories ? $game_system.quest_categories[0] : :all
  2459.     end
  2460.   end
  2461.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2462.   # * Create Dummy Category Label Window
  2463.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2464.   def create_dummy_category_window
  2465.     @quest_category_label_window.y -= 12
  2466.     @quest_category_label_window.opacity = 0
  2467.     @quest_category_window.opacity = 0
  2468.     w = [@quest_category_window.width, @quest_category_label_window.width].max
  2469.     h = @quest_category_window.height + @quest_category_label_window.height - 12
  2470.     @category_dummy_window = Window_QuestCategoryDummy.new(0, 0, w, h)
  2471.     @category_dummy_window.z = [@quest_category_window.z, @quest_category_label_window.z].min - 1
  2472.     # Draw Horz Line
  2473.     @category_dummy_window.draw_horizontal_line(@quest_category_window.height - @quest_category_window.padding - 7, 2)
  2474.   end
  2475.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2476.   # * Create QuestList Window
  2477.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2478.   def create_quest_list_window
  2479.     if @category_dummy_window
  2480.       y = @category_dummy_window.height
  2481.     else
  2482.       y = @quest_category_window ? @quest_category_window.height : 0
  2483.       y += @quest_category_label_window ? @quest_category_label_window.height : 0
  2484.       y = @quest_label_window.height if y == 0
  2485.     end
  2486.     @quest_list_window = Window_QuestList.new(0, y, QuestData::LIST_WINDOW_WIDTH,
  2487.       Graphics.height - y)
  2488.     @quest_list_window.set_handler(:ok, method(:on_list_ok))
  2489.     @quest_list_window.deactivate if !QuestData::CONCURRENT_ACTIVITY
  2490.     if !QuestData::CONCURRENT_ACTIVITY || !@quest_category_window
  2491.       @quest_list_window.set_handler(:cancel, method(:on_list_cancel))
  2492.     end
  2493.     if @quest_category_window
  2494.       @quest_category_window.add_observing_proc(:list) { |category|
  2495.         @quest_list_window.category = category }
  2496.     else
  2497.       @quest_list_window.category = $game_system.quest_categories[0]
  2498.     end
  2499.     @quest_list_window.index = @init_quest_index if @init_quest_index
  2500.   end
  2501.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2502.   # * Create QuestData Window
  2503.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2504.   def create_quest_data_window
  2505.     x = @quest_list_window.width
  2506.     y = (@quest_label_window && (@quest_category_window ||
  2507.       @quest_category_label_window)) ? @quest_label_window.height : 0
  2508.     @quest_data_window = Window_QuestData.new(x, y, Graphics.width - x,
  2509.       Graphics.height - y)
  2510.     @quest_list_window.help_window = @quest_data_window
  2511.     @quest_data_window.quest = @quest_list_window.item
  2512.     @quest_data_window.set_handler(:ok, method(:on_data_ok))
  2513.     @quest_data_window.set_handler(:cancel, method(:on_data_cancel))
  2514.   end
  2515.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2516.   # * Dispose Background Picture
  2517.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2518.   def dispose_maqj_picture
  2519.     @maqj_picture_sprite.dispose if @maqj_picture_sprite
  2520.   end
  2521.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2522.   # * Adjust Window Positions
  2523.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2524.   def adjust_window_positions
  2525.     if @quest_label_window && (@quest_category_window || @quest_category_label_window)
  2526.       @quest_label_window.x = QuestData::LIST_WINDOW_WIDTH
  2527.     end
  2528.   end
  2529.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2530.   # * Category OK
  2531.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2532.   def on_category_ok; @quest_list_window.activate; end
  2533.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2534.   # * Category Cancel
  2535.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2536.   def on_category_cancel; return_scene; end
  2537.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2538.   # * List OK
  2539.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2540.   def on_list_ok
  2541.     @quest_category_window.deactivate if @quest_category_window
  2542.     @quest_data_window.activate
  2543.   end
  2544.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2545.   # * List Cancel
  2546.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2547.   def on_list_cancel
  2548.     @quest_category_window ? @quest_category_window.activate : return_scene
  2549.   end
  2550.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2551.   # * Data OK
  2552.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2553.   def on_data_ok; on_data_cancel; end
  2554.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2555.   # * Data Cancel
  2556.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2557.   def on_data_cancel
  2558.     @quest_list_window.activate
  2559.     @quest_category_window.activate if @quest_category_window && QuestData::CONCURRENT_ACTIVITY
  2560.   end
  2561.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2562.   # * Update All Windows
  2563.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2564.   def update_all_windows(*args, &block)
  2565.     # To accomodate for concurrent activity, must deactivate category
  2566.     @quest_category_window.deactivate if @quest_category_window &&
  2567.       QuestData::CONCURRENT_ACTIVITY && @quest_list_window.active &&
  2568.       Input.trigger?(:C)
  2569.     super(*args, &block)
  2570.     @quest_category_window.activate if @quest_category_window &&
  2571.       QuestData::CONCURRENT_ACTIVITY && @quest_list_window.active
  2572.   end
  2573. end
  2574.  
  2575. #==============================================================================
  2576. # ** Scene_Map
  2577. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2578. #  Summary of Changes:
  2579. #    aliased method - update_scene
  2580. #    new methods - update_call_quest_journal; call_quest_journal
  2581. #==============================================================================
  2582.  
  2583. class Scene_Map
  2584.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2585.   # * Update Scene
  2586.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2587.   alias maqj_updascne_9kh4 update_scene
  2588.   def update_scene(*args, &block)
  2589.     maqj_updascne_9kh4(*args, &block)
  2590.     update_call_quest_journal if $game_system.quest_map_access && !scene_changing?
  2591.   end
  2592.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2593.   # * Update Call Quest Journal
  2594.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2595.   def update_call_quest_journal
  2596.     if $game_map.interpreter.running?
  2597.       @quest_journal_calling = false
  2598.     else
  2599.       if Input.trigger?(QuestData::MAP_BUTTON)
  2600.         $game_system.quest_access_disabled || $game_party.quests.list.empty? ?
  2601.           Sound.play_buzzer : @quest_journal_calling = true
  2602.       end
  2603.       call_quest_journal if @quest_journal_calling && !$game_player.moving?
  2604.     end
  2605.   end
  2606.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2607.   # * Call Quest Journal
  2608.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2609.   def call_quest_journal
  2610.     @quest_journal_calling = false
  2611.     Sound.play_ok
  2612.     SceneManager.call(Scene_Quest)
  2613.   end
  2614. end
  2615.  
  2616. # Menu Access
  2617. if !$imported[:MA_InsertCommand]
  2618. # Initialize the Insertion Hash
  2619. MA_COMMAND_INSERTS = {}
  2620. MA_InsertableMenuCommand = Struct.new(:name, :index, :enable, :scene, :other)
  2621.  
  2622. #==============================================================================
  2623. # ** Game_System
  2624. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2625. #  Summary of Changes:
  2626. #    new public instance variable - maic_menu_commands
  2627. #    aliased method - initialize
  2628. #==============================================================================
  2629.  
  2630. class Game_System
  2631.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2632.   # * Inserted Menu Commands
  2633.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2634.   def maic_inserted_menu_commands
  2635.     # Lazy Instantiation so that old save files are not corrupted
  2636.     if !@maic_inserted_menu_commands
  2637.       @maic_inserted_menu_commands = MA_COMMAND_INSERTS.keys
  2638.       # Sort by index
  2639.       @maic_inserted_menu_commands.sort! { |a, b| MA_COMMAND_INSERTS[a].index <=> MA_COMMAND_INSERTS[b].index }
  2640.     end
  2641.     @maic_inserted_menu_commands
  2642.   end
  2643. end
  2644.  
  2645. #==============================================================================
  2646. # ** Window_MenuCommand
  2647. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2648. #  Summary of Changes:
  2649. #    aliased method - make_command_list; maic_insert_command
  2650. #==============================================================================
  2651.  
  2652. class Window_MenuCommand
  2653.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2654.   # * Make Command List
  2655.   #``````````````````````````````````````````````````````````````````````````
  2656.   #  I alias this method instead of add_original_commands because I need to
  2657.   # have all commands created before I can insert at the correct index
  2658.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2659.   alias maic_mkcmmndl_6yd2 make_command_list
  2660.   def make_command_list(*args, &block)
  2661.     maic_mkcmmndl_6yd2(*args, &block) # Run Original Method
  2662.     # Insert new commands
  2663.     $game_system.maic_inserted_menu_commands.each { |sym| maic_insert_command(sym) }
  2664.   end
  2665.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2666.   # * Insert Command
  2667.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2668.   def maic_insert_command(symbol)
  2669.     command = MA_COMMAND_INSERTS[symbol]
  2670.     # Get the command name
  2671.     name = command.name.is_a?(Symbol) ? eval(command.name.to_s) : command.name
  2672.     # Check whether enabled
  2673.     enabled = case command.enable
  2674.     when Integer then command.enable == 0 ? true : $game_switches[command.enable]
  2675.     when String then eval(command.enable)
  2676.     when Symbol then self.send(command.enable)
  2677.     else
  2678.       enabled = true
  2679.     end
  2680.     # Add the command to the list
  2681.     add_command(name, symbol, enabled)
  2682.     added = @list.pop
  2683.     @list.insert([command.index, @list.size].min, added) # Insert at specific index
  2684.   end
  2685. end
  2686.  
  2687. #==============================================================================
  2688. # ** Scene_Menu
  2689. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2690. #  Summary of Changes:
  2691. #    aliased method - create_command_window; on_personal_ok
  2692. #    new methods - maic_set_insert_handler; maic_command_insert
  2693. #==============================================================================
  2694.  
  2695. class Scene_Menu
  2696.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2697.   # * Create Command Window
  2698.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2699.   alias maic_createcndwin_3ey7 create_command_window
  2700.   def create_command_window(*args, &block)
  2701.     maic_createcndwin_3ey7(*args, &block) # Run Original Method
  2702.     # Add handlers for all custom commands
  2703.     $game_system.maic_inserted_menu_commands.each { |symbol| maic_set_insert_handler(symbol) }
  2704.   end
  2705.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2706.   # * Set Inserted Handler
  2707.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2708.   def maic_set_insert_handler(symbol)
  2709.     other = MA_COMMAND_INSERTS[symbol].other
  2710.     handler = case other
  2711.     when Symbol then method(other)
  2712.     when String then lambda { eval(other) }
  2713.     when TrueClass then method(:command_personal)
  2714.     else
  2715.       handler = method(:maic_command_insert)
  2716.     end
  2717.     @command_window.set_handler(symbol, handler)
  2718.   end
  2719.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2720.   # * Custom Command
  2721.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2722.   def maic_command_insert
  2723.     SceneManager.call(Kernel.const_get(MA_COMMAND_INSERTS[@command_window.current_symbol].scene))
  2724.   end
  2725.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2726.   # * Personal OK
  2727.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2728.   alias maic_onpok_3ek9 on_personal_ok
  2729.   def on_personal_ok(*args, &block)
  2730.     if $game_system.maic_inserted_menu_commands.include?(@command_window.current_symbol)
  2731.       maic_command_insert
  2732.     else
  2733.       maic_onpok_3ek9(*args, &block) # Run Original Method
  2734.     end
  2735.   end
  2736. end
  2737.  
  2738. $imported[:MA_InsertCommand] = true
  2739. end
  2740.  
  2741. MA_COMMAND_INSERTS[:quest_journal] =
  2742.   MA_InsertableMenuCommand.new(QuestData::VOCAB[:menu_label], QuestData::MENU_INDEX,
  2743.   "!$game_system.quest_access_disabled && !$game_party.quests.list.empty?",
  2744.   :Scene_Quest, false)
Add Comment
Please, Sign In to add comment