Guest User

Untitled

a guest
Jun 29th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 128.28 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:       "Missionen",
  338.     # scene_label: The label at the top of the scene. If empty, no window
  339.     scene_label:      "Missionsbrett",
  340.     # description: The heading to identify the description
  341.     description:      "Beschreibung",
  342.     # objectives: The heading to identify the objectives
  343.     objectives:       "Aufgaben",
  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:          "Belohnung",
  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:            "Stufe: ",
  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 =>      "Alle Missionen",      # The label for the :all category
  387.     :active =>   "Aktive Missionen",   # The label for the :active category
  388.     :complete => "Abgeschlossene", # The label for the :complete category
  389.     :failed =>   "Gescheiterte",   # 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 101 # Quest 1 - SAMPLE QUEST
  779.       q[:name]              = "[01] Heimtückische Wälder"
  780.       q[:level]             = 1
  781.       q[:description]       = "Zum aufbauen des Lagers werden Rohstoffe benötigt, vor allem aber Holz."
  782.       q[:objectives][0]     = "Reise zu den westlichen Wäldern"
  783.       q[:objectives][1]     = "Sammle 20 Einheiten Holz"
  784.       q[:objectives][2]     = "Schlachte die angreifenden Bäume"
  785.       q[:objectives][3]     = "Rette ???"
  786.       q[:prime_objectives]  = [0, 1]
  787.       q[:custom_categories] = []
  788.       q[:banner]            = ""
  789.       q[:banner_hue]        = 0
  790.       q[:client]            = "HQ"
  791.       q[:location]          = "Die westlichen Wälder"
  792.       q[:common_event_id]   = 0
  793.       q[:rewards]           = [
  794.         [:item, 1, 3],
  795.         [:gold, 500],
  796.       ]
  797.       q[:layout]            = false
  798.     #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  799.     #  END Editable Region B
  800.     #//////////////////////////////////////////////////////////////////////
  801.     end
  802.     q
  803.   end
  804. end
  805.  
  806. #==============================================================================
  807. # *** DataManager
  808. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  809. #  Summary of Changes:
  810. #    aliased method - self.extract_save_contents
  811. #==============================================================================
  812.  
  813. class << DataManager
  814.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  815.   # * Extract Save Contents
  816.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  817.   alias maqj_extractsavecons_2kw5 extract_save_contents
  818.   def extract_save_contents(*args, &block)
  819.     maqj_extractsavecons_2kw5(*args, &block) # Call Original Method
  820.     if $game_party.quests.nil?
  821.       $game_party.init_maqj_data
  822.       $game_system.init_maqj_data
  823.     end
  824.   end
  825. end
  826.  
  827. #==============================================================================
  828. # ** MAQJ_SortedArray
  829. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  830. #  This module mixes in to an array to maintain the sorted order when inserting
  831. #==============================================================================
  832.  
  833. module MAQJ_SortedArray
  834.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  835.   # * Insert to Array
  836.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  837.   def maqj_insert_sort(el, &block)
  838.     index = bsearch_index(el, 0, size, &block)
  839.     index ? insert(index, el) : push(el)
  840.   end
  841.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  842.   # * Retrieve Index from Binary Search
  843.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  844.   def bsearch_index(el, b = 0, e = size, &block)
  845.     return bsearch_index(el, b, e) { |a,b| a <=> b } if block.nil?
  846.     return b if b == e # Return the discovered insertion index
  847.     return if b > e
  848.     m = (b + e) / 2    # Get Middle
  849.     block.call(el, self[m]) > 0 ? b = m + 1 : e = m
  850.     bsearch_index(el, b, e, &block)
  851.   end
  852. end
  853.  
  854. #==============================================================================
  855. # ** Game_Quest
  856. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  857. #  This class holds all instance data for a quest
  858. #==============================================================================
  859.  
  860. class Game_Quest
  861.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  862.   # * Public Instance Variables
  863.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  864.   attr_reader   :id                  # Unique identifier for this quest
  865.   attr_reader   :name                # The name to be shown for the quest
  866.   attr_reader   :level               # The level of difficulty of the quest
  867.   attr_reader   :objectives          # An array of objective strings
  868.   attr_reader   :prime_objectives    # An array of crucial objective IDs
  869.   attr_reader   :revealed_objectives # An array of revealed objective IDs
  870.   attr_reader   :complete_objectives # An array of completed objective IDs
  871.   attr_reader   :failed_objectives   # An array of failed objective IDs
  872.   attr_reader   :custom_categories   # An array of category symbols
  873.   attr_accessor :icon_index          # Icon associated with this quest
  874.   attr_accessor :common_event_id     # ID of common event to call upon complete
  875.   attr_accessor :description         # The description for the quest
  876.   attr_accessor :banner              # Picture shown to represent the quest
  877.   attr_accessor :banner_hue          # The hue of the banner
  878.   attr_accessor :layout              # The layout of this quest in scene
  879.   attr_accessor :rewards             # An array of rewards to show
  880.   attr_accessor :reward_given        # Boolean tracking if quest was rewarded
  881.   attr_accessor :concealed           # Whether or not the quest is visible
  882.   attr_accessor :manual_status       # Quest status if not using prime objectives
  883.   QuestData::BASIC_DATA_TYPES.each { |data_type| attr_accessor(data_type) }
  884.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  885.   # * Object Initialization
  886.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  887.   def initialize(quest_id)
  888.     @id = quest_id
  889.     @concealed = default_value_for(:concealed)
  890.     @reward_given = default_value_for(:reward_given)
  891.     reset
  892.   end
  893.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  894.   # * Reset
  895.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  896.   def reset
  897.     data = QuestData.setup_quest(@id)
  898.     data_symbol_array.each { |meth| instance_variable_set(:"@#{meth}",
  899.       data[meth] ? data[meth] : default_value_for(meth)) }
  900.     @revealed_objectives = [].send(:extend, MAQJ_SortedArray)
  901.     @complete_objectives = [].send(:extend, MAQJ_SortedArray)
  902.     @failed_objectives =   [].send(:extend, MAQJ_SortedArray)
  903.     @manual_status = default_value_for(:manual_status)
  904.   end
  905.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  906.   # * Data Symbol Array
  907.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  908.   def data_symbol_array
  909.     [:name, :level, :objectives, :prime_objectives, :custom_categories,
  910.       :icon_index, :description, :banner, :banner_hue, :common_event_id,
  911.       :layout, :rewards] + QuestData::BASIC_DATA_TYPES
  912.   end
  913.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  914.   # * Default Value
  915.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  916.   def default_value_for(method)
  917.     case method
  918.     when :name then "??????"
  919.     when :description, :banner then ""
  920.     when :level, :banner_hue, :icon_index, :common_event_id then 0
  921.     when :objectives, :rewards, :custom_categories then []
  922.     when :prime_objectives then Array.new(objectives.size) { |x| x }
  923.     when :concealed then QuestData::MANUAL_REVEAL
  924.     when :manual_status then :active
  925.     when :layout, :reward_given then false
  926.     else ""
  927.     end
  928.   end
  929.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  930.   # * Reveal/Conceal Objective
  931.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  932.   def reveal_objective(*obj)
  933.     valid_obj = obj.select {|x| x < objectives.size && !@revealed_objectives.include?(x) }
  934.     valid_obj.each {|i| @revealed_objectives.maqj_insert_sort(i) }
  935.     quest_status_changed unless valid_obj.empty?
  936.   end
  937.   def conceal_objective(*obj)
  938.     quest_status_changed unless (obj & @revealed_objectives).empty?
  939.     obj.each { |obj_id| @revealed_objectives.delete(obj_id) }
  940.   end
  941.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  942.   # * Complete/Uncomplete Objective
  943.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  944.   def complete_objective(*obj)
  945.     valid_obj = obj.select {|x| x < objectives.size && !@complete_objectives.include?(x) }
  946.     reveal_objective(*valid_obj)
  947.     unfail_objective(*valid_obj)
  948.     was_complete = status?(:complete)
  949.     valid_obj.each {|i| @complete_objectives.maqj_insert_sort(i) }
  950.     quest_status_changed unless valid_obj.empty?
  951.     # If just completed
  952.     if status?(:complete) && !was_complete
  953.       $game_temp.reserve_common_event(common_event_id)
  954.       $game_party.quests.add_to_sort_array(:complete, @id)
  955.     end
  956.   end
  957.   def uncomplete_objective(*obj)
  958.     quest_status_changed unless (obj & @complete_objectives).empty?
  959.     obj.each { |obj_id| @complete_objectives.delete(obj_id) }
  960.   end
  961.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  962.   # * Fail/Unfail Objective
  963.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  964.   def fail_objective(*obj)
  965.     valid_obj = obj.select {|x| x < objectives.size && !@failed_objectives.include?(x) }
  966.     reveal_objective(*valid_obj)
  967.     uncomplete_objective(*valid_obj)
  968.     was_failed = status?(:failed)
  969.     valid_obj.each {|i| @failed_objectives.maqj_insert_sort(i) }
  970.     quest_status_changed unless valid_obj.empty?
  971.     $game_party.quests.add_to_sort_array(:failed, @id) if status?(:failed) && !was_failed
  972.   end
  973.   def unfail_objective(*obj)
  974.     quest_status_changed unless (obj & @failed_objectives).empty?
  975.     obj.each { |obj_id| @failed_objectives.delete(obj_id) }
  976.   end
  977.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  978.   # * Updates when the quest status has been changed
  979.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  980.   def quest_status_changed
  981.     $game_party.quests.add_to_sort_array(:change, @id)
  982.     $game_system.last_quest_id = @id if QuestData::OPEN_TO_LAST_CHANGED_QUEST
  983.   end
  984.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  985.   # * Objective Status?
  986.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  987.   def objective_status?(status_check, *obj)
  988.     return false if obj.empty?
  989.     case status_check
  990.     when :failed   then !(obj & @failed_objectives).empty?
  991.     when :complete then obj.size == (obj & @complete_objectives).size
  992.     when :revealed then obj.size == (obj & @revealed_objectives).size
  993.     when :active then objective_status?(:revealed, *obj) &&
  994.       !objective_status?(:complete, *obj) && !objective_status?(:failed, *obj)
  995.     end
  996.   end
  997.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  998.   # * Status?
  999.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1000.   def status?(status_check)
  1001.     case status_check
  1002.     when :failed  
  1003.       @prime_objectives.empty? ? @manual_status == :failed :
  1004.         !(@failed_objectives & @prime_objectives).empty?
  1005.     when :complete
  1006.       @prime_objectives.empty? ? @manual_status == :complete : !status?(:failed) &&
  1007.         ((@prime_objectives & @complete_objectives) == @prime_objectives)
  1008.     when :active then !concealed && !status?(:complete) && !status?(:failed)
  1009.     when :reward then @reward_given
  1010.     end
  1011.   end
  1012.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1013.   # * Set Name
  1014.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1015.   def name=(new_name)
  1016.     @name = new_name
  1017.     $game_party.quests.add_to_sort_array(:alphabet, @id) if $game_party &&
  1018.       $game_party.quests
  1019.   end
  1020.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1021.   # * Set Level
  1022.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1023.   def level=(new_lvl)
  1024.     @level = new_lvl
  1025.     $game_party.quests.add_to_sort_array(:level, @id) if $game_party &&
  1026.       $game_party.quests
  1027.   end
  1028. end
  1029.  
  1030. #==============================================================================
  1031. # ** Game_Quests
  1032. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1033. #  This is a wrapper for an array holding Game_Quest objects
  1034. #==============================================================================
  1035.  
  1036. class Game_Quests
  1037.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1038.   # * Object Initialization
  1039.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1040.   def initialize
  1041.     @data = {}
  1042.     @sort_arrays = {
  1043.       reveal: [], change: [], complete: [], failed: [],
  1044.       id:       [].send(:extend, MAQJ_SortedArray),
  1045.       alphabet: [].send(:extend, MAQJ_SortedArray),
  1046.       level:    [].send(:extend, MAQJ_SortedArray)
  1047.     }
  1048.   end
  1049.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1050.   # * Get Quest
  1051.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1052.   def [](quest_id)
  1053.     reset_quest(quest_id) if !@data[quest_id]
  1054.     @data[quest_id]
  1055.   end
  1056.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1057.   # * Set Quest <- Not sure when this would ever be useful.
  1058.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1059.   def []=(quest_id, value)
  1060.     @data[quest_id] = value
  1061.   end
  1062.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1063.   # * List
  1064.   #    list_type : the type of list to return
  1065.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1066.   def list(list_type = :all, sort_type = $game_system.quest_sort_type[list_type])
  1067.     sort_type_s = sort_type.to_s
  1068.     reverse = !(sort_type_s.sub!(/_r$/, "")).nil?
  1069.     sort_type = sort_type_s.to_sym
  1070.     list = @sort_arrays[sort_type].select { |quest_id| include?(quest_id, list_type) }
  1071.     list.reverse! if reverse
  1072.     list.collect { |quest_id| @data[quest_id] }
  1073.   end
  1074.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1075.   # * Include?
  1076.   #    determines whether to include a particular quest depending on list type
  1077.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1078.   def include?(quest_id, list_type = :all)
  1079.     return false if !revealed?(quest_id)
  1080.     case list_type
  1081.     when :all then true
  1082.     when :complete, :failed, :active then @data[quest_id].status?(list_type)
  1083.     else
  1084.       @data[quest_id].custom_categories.include?(list_type)
  1085.     end
  1086.   end
  1087.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1088.   # * Revealed?
  1089.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1090.   def revealed?(quest_id)
  1091.     (!@data[quest_id].nil? && !@data[quest_id].concealed)
  1092.   end
  1093.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1094.   # * Setup Quest
  1095.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1096.   def setup_quest(quest_id)
  1097.     return if @data[quest_id]
  1098.     @data[quest_id] = Game_Quest.new(quest_id)
  1099.     # Open to this quest next time the QJ is opened
  1100.     $game_system.last_quest_id = quest_id if QuestData::OPEN_TO_LAST_REVEALED_QUEST
  1101.     # Save sorting order in separate arrays to avoid re-sorting every time
  1102.     @sort_arrays.keys.each { |sym| add_to_sort_array(sym, quest_id) }
  1103.   end
  1104.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1105.   # * Delete Quest
  1106.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1107.   def delete_quest(quest_id)
  1108.     @data.delete(quest_id)
  1109.     @sort_arrays.values.each { |ary| ary.delete(quest_id) }
  1110.   end
  1111.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1112.   # * Reset Quest
  1113.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1114.   def reset_quest(quest_id)
  1115.     delete_quest(quest_id)
  1116.     setup_quest(quest_id)
  1117.   end
  1118.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1119.   # * Add to Sorted Array
  1120.   #    sort_type : array to alter
  1121.   #    quest_id  : ID of the quest to add.
  1122.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1123.   def add_to_sort_array(sort_type, quest_id)
  1124.     @sort_arrays[sort_type].delete(quest_id) # Make sure always unique
  1125.     case sort_type
  1126.     when :reveal, :change, :complete, :failed
  1127.       @sort_arrays[sort_type].unshift(quest_id)
  1128.     when :id
  1129.       @sort_arrays[sort_type].maqj_insert_sort(quest_id)
  1130.     when :alphabet
  1131.       @sort_arrays[sort_type].maqj_insert_sort(quest_id) { |a, b| @data[a].name.downcase <=> @data[b].name.downcase }
  1132.     when :level
  1133.       @sort_arrays[sort_type].maqj_insert_sort(quest_id) { |a, b| @data[a].level <=> self[b].level }
  1134.     end
  1135.   end
  1136.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1137.   # * Find Location
  1138.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1139.   def find_location(quest_id, cat = nil)
  1140.     if revealed?(quest_id)
  1141.       categories = $game_system.quest_categories.dup
  1142.       # If cat specified, check in that category first.
  1143.       if cat && categories.include?(cat)
  1144.         categories.delete(cat)
  1145.         categories.unshift(cat)
  1146.       end
  1147.       for category in categories # Check all categories
  1148.         index = list(category).index(@data[quest_id])
  1149.         return category, index if index != nil
  1150.       end
  1151.     end
  1152.     return nil, nil
  1153.   end
  1154.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1155.   # * Clear
  1156.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1157.   def clear
  1158.     @data.clear
  1159.   end
  1160. end
  1161.  
  1162. #==============================================================================
  1163. # ** Game System
  1164. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1165. #  Summary of Changes:
  1166. #    new attr_accessor - quest_menu_access; quest_map_access; quest_sort_type;
  1167. #      quest_bg_picture; quest_bg_opacity; quest_windowskin;
  1168. #      quest_window_opacity; quest_access_disabled; last_quest_cat;
  1169. #      last_quest_id
  1170. #    aliased methods - initialize
  1171. #    new methods - init_maqj_data
  1172. #==============================================================================
  1173.  
  1174. class Game_System
  1175.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1176.   # * Public Instance Variables
  1177.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1178.   attr_reader   :quest_menu_access     # Whether the scene is called from menu
  1179.   attr_accessor :quest_map_access      # Whether the scene is called from map
  1180.   attr_accessor :quest_sort_type       # The sort types for each category
  1181.   attr_accessor :quest_bg_picture      # The filename of the background picture
  1182.   attr_accessor :quest_bg_opacity      # The opacity of the background picture
  1183.   attr_accessor :quest_bg_blend_type   # The blend type of the background pic
  1184.   attr_accessor :quest_windowskin      # The windowskin used for the scene
  1185.   attr_accessor :quest_window_tone     # The tone of windows in the scene
  1186.   attr_accessor :quest_window_opacity  # The opacity of windows in the scene
  1187.   attr_accessor :quest_access_disabled # Whether access to Quests is disabled
  1188.   attr_accessor :quest_categories      # The categories to show in the scene
  1189.   attr_accessor :quest_scene_label     # The label to show in the scene
  1190.   attr_accessor :last_quest_cat        # The category to open to
  1191.   attr_accessor :last_quest_id         # The ID to open to
  1192.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1193.   # * Object Initialization
  1194.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1195.   alias maqj_initialze_2cy9 initialize
  1196.   def initialize(*args, &block)
  1197.     maqj_initialze_2cy9(*args, &block)
  1198.     init_maqj_data
  1199.   end
  1200.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1201.   # * Initialize Quest Data
  1202.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1203.   def init_maqj_data
  1204.     # Initialize new variables
  1205.     self.quest_menu_access = QuestData::MENU_ACCESS
  1206.     @quest_map_access = QuestData::MAP_ACCESS
  1207.     @quest_sort_type = QuestData::SORT_TYPE
  1208.     @quest_bg_picture = QuestData::BG_PICTURE
  1209.     @quest_bg_opacity = QuestData::BG_OPACITY
  1210.     @quest_bg_blend_type = QuestData::BG_BLEND_TYPE
  1211.     @quest_windowskin = QuestData::WINDOWSKIN
  1212.     @quest_window_tone = QuestData::WINDOW_TONE
  1213.     @quest_window_opacity = QuestData::WINDOW_OPACITY
  1214.     @quest_access_disabled = false
  1215.     @quest_categories = QuestData::CATEGORIES
  1216.     @quest_scene_label = QuestData::VOCAB[:scene_label]
  1217.     @last_quest_cat = @quest_categories[0]
  1218.     @last_quest_id = 0
  1219.   end
  1220.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1221.   # * Set Quest Menu Access
  1222.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1223.   def quest_menu_access=(boolean)
  1224.     @quest_menu_access = boolean
  1225.     maic_inserted_menu_commands.delete(:quest_journal)
  1226.     maic_inserted_menu_commands.push(:quest_journal) if @quest_menu_access
  1227.     maic_inserted_menu_commands.sort!
  1228.   end
  1229. end
  1230.  
  1231. #==============================================================================
  1232. # ** Game_Party
  1233. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1234. #  Summary of Changes:
  1235. #    new attr_reader - quests
  1236. #    aliased method - initialize
  1237. #    new method - init_maqj_data
  1238. #==============================================================================
  1239.  
  1240. class Game_Party
  1241.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1242.   # * Public Instance Variables
  1243.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1244.   attr_reader :quests
  1245.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1246.   # * Object Initialization
  1247.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1248.   alias maqj_intiaze_2si9 initialize
  1249.   def initialize(*args, &block)
  1250.     maqj_intiaze_2si9(*args, &block) # Call Original Method
  1251.     init_maqj_data
  1252.   end
  1253.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1254.   # * Initialize Quests
  1255.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1256.   def init_maqj_data
  1257.     @quests = Game_Quests.new # Initialize @quests
  1258.   end
  1259. end
  1260.  
  1261. #==============================================================================
  1262. # ** Game_Interpreter
  1263. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1264. #  Summary of Changes:
  1265. #    new methods - change_quest_access; change_quest_background;
  1266. #      change_quest_windows; setup_quest; delete_quest; reset_quest; quest;
  1267. #      reveal_quest; conceal_quest; manually_complete_quest;
  1268. #      manually_fail_quest; reveal_objective; conceal_objective;
  1269. #      complete_objective; uncomplete_objective; fail_objective;
  1270. #      unfail_objective; quest_revealed?; quest_complete?; quest_active?;
  1271. #      quest_failed?; objective_complete?; objective_active?;
  1272. #      objective_failed?; distribute_quest_rewards; distribute_quest_reward;
  1273. #      call_quest_journal
  1274. #==============================================================================
  1275.  
  1276. class Game_Interpreter
  1277.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1278.   # * Change Quest Access
  1279.   #    sym : symbol representing what aspect of access is being changed
  1280.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1281.   def change_quest_access(sym)
  1282.     case sym
  1283.     when :enable then $game_system.quest_access_disabled = false
  1284.     when :disable then $game_system.quest_access_disabled = true
  1285.     when :enable_menu then $game_system.quest_menu_access = true
  1286.     when :disable_menu then $game_system.quest_menu_access = false
  1287.     when :enable_map then $game_system.quest_map_access = true
  1288.     when :disable_map then $game_system.quest_map_access = false
  1289.     end
  1290.   end
  1291.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1292.   # * Change Quest Background
  1293.   #    picture : picture to show in the scene's background
  1294.   #    opacity : opacity of the picture shown in the scene's background
  1295.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1296.   def change_quest_background(picture, opacity = $game_system.quest_bg_opacity,
  1297.       blend_type = $game_system.quest_bg_blend_type)
  1298.     $game_system.quest_bg_picture = picture
  1299.     $game_system.quest_bg_opacity = opacity
  1300.     $game_system.quest_bg_blend_type = blend_type
  1301.   end
  1302.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1303.   # * Change Quest Windows
  1304.   #    skin    : windowskin name to use in the scene
  1305.   #    tone    : tone for the windowskin
  1306.   #    opacity : opacity of windows in the scene
  1307.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1308.   def change_quest_windows(skin, tone = $game_system.quest_window_tone,
  1309.       opacity = $game_system.quest_window_opacity)
  1310.     $game_system.quest_windowskin = skin
  1311.     $game_system.quest_window_tone = tone
  1312.     $game_system.quest_window_opacity = opacity
  1313.   end
  1314.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1315.   # * Setup/Delete/Reset Quest
  1316.   #    quest_id : ID of the quest to be setup or deleted or reset
  1317.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1318.   [:setup_quest, :delete_quest, :reset_quest].each { |method|
  1319.     define_method(method) do |quest_id|
  1320.       $game_party.quests.send(method, quest_id)
  1321.     end
  1322.   }
  1323.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1324.   # * Retrieve Quest
  1325.   #    quest_id : ID of the quest to retrieve
  1326.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1327.   def quest(quest_id);         $game_party.quests[quest_id];      end
  1328.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1329.   # * Reveal/Conceal Quest
  1330.   #    quest_id : ID of the quest to be revealed or concealed
  1331.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1332.   def reveal_quest(quest_id);  quest(quest_id).concealed = false; end
  1333.   def conceal_quest(quest_id); quest(quest_id).concealed = true;  end
  1334.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1335.   # * Manually Complete/Fail Quest
  1336.   #    quest_id : ID of the quest to be revealed or concealed
  1337.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1338.   def manually_complete_quest(quest_id)
  1339.     quest(quest_id).prime_objectives.clear
  1340.     quest(quest_id).manual_status = :complete
  1341.   end
  1342.   def manually_fail_quest(quest_id)
  1343.     quest(quest_id).prime_objectives.clear
  1344.     quest(quest_id).manual_status = :failed
  1345.   end
  1346.   def manually_activate_quest(quest_id)
  1347.     quest(quest_id).manual_status = :active
  1348.   end
  1349.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1350.   # * Reveal/Complete/Fail/Conceal/Uncomplete/Unfail Objective
  1351.   #    quest_id : ID of the quest whose objectives will be modified
  1352.   #    *obj     : IDs of objectives to reveal or complete or fail (or opposite)
  1353.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1354.   [:reveal_objective, :complete_objective, :fail_objective, :conceal_objective,
  1355.   :uncomplete_objective, :unfail_objective].each { |method|
  1356.     define_method(method) do |quest_id, *obj|
  1357.       quest(quest_id).send(method, *obj)
  1358.     end
  1359.   }
  1360.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1361.   # * Quest Revealed?
  1362.   #    quest_id : ID of the quest you are checking is revealed
  1363.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1364.   def quest_revealed?(quest_id)
  1365.     $game_party.quests.revealed?(quest_id)
  1366.   end
  1367.   [:complete, :failed, :active].each { |method|
  1368.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1369.     # * Quest Complete/Failed/Active?
  1370.     #    quest_id : ID of the quest whose completion status is being checked
  1371.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1372.     define_method(:"quest_#{method}?") do |quest_id|
  1373.       quest_revealed?(quest_id) && quest(quest_id).status?(method)
  1374.     end
  1375.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1376.     # * Objective Complete/Failed/Active?
  1377.     #    quest_id : ID of the quest whose objectives are being checked
  1378.     #    *obj     : IDs of objectives to check completion status
  1379.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1380.     define_method(:"objective_#{method}?") do |quest_id, *obj|
  1381.       quest_revealed?(quest_id) && quest(quest_id).objective_status?(method, *obj)
  1382.     end
  1383.   }
  1384.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1385.   # * Objective Revealed?
  1386.   #    quest_id : ID of the quest you are checking is revealed
  1387.   #    *obj     : IDs of objectives to check completion status
  1388.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1389.   def objective_revealed?(quest_id, *obj)
  1390.     quest_revealed?(quest_id) && quest(quest_id).objective_status?(:revealed, *obj)
  1391.   end
  1392.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1393.   # * Quest Rewarded?
  1394.   #    quest_id : ID of the quest you are checking is revealed
  1395.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1396.   def quest_rewarded?(quest_id)
  1397.     quest_revealed?(quest_id) && quest(quest_id).status?(:reward)
  1398.   end
  1399.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1400.   # * Change Reward Status
  1401.   #    quest_id : ID of the quest you are checking is revealed
  1402.   #    value    : true or false
  1403.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1404.   def change_reward_status(quest_id, value = true)
  1405.     quest(quest_id).reward_given = value
  1406.   end
  1407.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1408.   # * Distribute Rewards
  1409.   #    quest_id : ID of the quest whose rewards are to be distributed
  1410.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1411.   def distribute_quest_rewards(quest_id)
  1412.     if quest_revealed?(quest_id) && !quest_rewarded?(quest_id)
  1413.       params = @params.dup
  1414.       change_reward_status(quest_id, true)
  1415.       quest(quest_id).rewards.each { |reward| distribute_quest_reward(reward) }
  1416.       @params = params
  1417.       true
  1418.     else
  1419.       false
  1420.     end
  1421.   end
  1422.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1423.   # * Distribute Reward
  1424.   #    reward : an array identifying the reward
  1425.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1426.   def distribute_quest_reward(reward)
  1427.     @params = [reward[1], 0, 0, (reward[2] ? reward[2] : 1)]
  1428.     case reward[0]
  1429.     when :item, 0 then   command_126 # Item
  1430.     when :weapon, 1 then command_127 # Weapon
  1431.     when :armor, 2 then  command_128 # Armor
  1432.     when :gold, 3   # Gold
  1433.       @params = [0, 0, reward[1] ? reward[1] : 0]
  1434.       command_125
  1435.     when :exp, 4    # Exp
  1436.       @params = [0, 0, 0, 0, reward[1] ? reward[1] : 0, true]
  1437.       command_315
  1438.     end
  1439.   end
  1440.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1441.   # * Call Quest Journal
  1442.   #    quest_id : ID of the quest to open the journal to
  1443.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1444.   def call_quest_journal(quest_id = nil)
  1445.     return if $game_party.in_battle
  1446.     $game_system.last_quest_id = quest_id if quest_id
  1447.     SceneManager.call(Scene_Quest)
  1448.     Fiber.yield
  1449.   end
  1450. end
  1451.  
  1452. unless $imported[:"MA_ParagraphFormat_1.0"]
  1453. #==============================================================================
  1454. # ** MA_Window_ParagraphFormat
  1455. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1456. #  This module inserts into Window_Base and provides a method to format the
  1457. # strings so as to go to the next line if it exceeds a set limit. This is
  1458. # designed to work with draw_text_ex, and a string formatted by this method
  1459. # should go through that, not draw_text.
  1460. #==============================================================================
  1461.  
  1462. module MA_Window_ParagraphFormat
  1463.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1464.   # * Calc Line Width
  1465.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1466.   def mapf_calc_line_width(line, tw = 0, contents_dummy = false)
  1467.     return tw if line.nil?
  1468.     line = line.clone
  1469.     unless contents_dummy
  1470.       real_contents = contents # Preserve Real Contents
  1471.       # Create a dummy contents
  1472.       self.contents = Bitmap.new(contents_width, 24)
  1473.       reset_font_settings
  1474.     end
  1475.     pos = {x: 0, y: 0, new_x: 0, height: calc_line_height(line)}
  1476.     while line[/^(.*?)\e(.*)/]
  1477.       tw += text_size($1).width
  1478.       line = $2
  1479.       # Remove all ancillaries to the code, like parameters
  1480.       code = obtain_escape_code(line)
  1481.       # If direct setting of x, reset tw.
  1482.       tw = 0 if ($imported[:ATS_SpecialMessageCodes] && code.upcase == 'X') ||
  1483.         ($imported["YEA-MessageSystem"] && code.upcase == 'PX')
  1484.       #  If I need to do something special on the basis that it is testing,
  1485.       # alias process_escape_character and differentiate using @atsf_testing
  1486.       process_escape_character(code, line, pos)
  1487.     end
  1488.     #  Add width of remaining text, as well as the value of pos[:x] under the
  1489.     # assumption that any additions to it are because the special code is
  1490.     # replaced by something which requires space (like icons)
  1491.     tw += text_size(line).width + pos[:x]
  1492.     unless contents_dummy
  1493.       contents.dispose # Dispose dummy contents
  1494.       self.contents = real_contents # Restore real contents
  1495.     end
  1496.     return tw
  1497.   end
  1498.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1499.   # * Format Paragraph
  1500.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1501.   def mapf_format_paragraph(text, max_width = contents_width)
  1502.     text = text.clone
  1503.     #  Create a Dummy Contents - I wanted to boost compatibility by using the
  1504.     # default process method for escape codes. It may have the opposite effect,
  1505.     # for some :(
  1506.     real_contents = contents # Preserve Real Contents
  1507.     self.contents = Bitmap.new(contents_width, 24)
  1508.     reset_font_settings
  1509.     paragraph = ""
  1510.     while !text.empty?
  1511.       text.lstrip!
  1512.       oline, nline, tw = mapf_format_by_line(text.clone, max_width)
  1513.       # Replace old line with the new one
  1514.       text.sub!(/#{Regexp.escape(oline)}/m, nline)
  1515.       paragraph += text.slice!(/.*?(\n|$)/)
  1516.     end
  1517.     contents.dispose # Dispose dummy contents
  1518.     self.contents = real_contents # Restore real contents
  1519.     return paragraph
  1520.   end
  1521.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1522.   # * Format By Line
  1523.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1524.   def mapf_format_by_line(text, max_width = contents_width)
  1525.     oline, nline, tw = "", "", 0
  1526.     loop do
  1527.       #  Format each word until reach the width limit
  1528.       oline, nline, tw, done = mapf_format_by_word(text, nline, tw, max_width)
  1529.       return oline, nline, tw if done
  1530.     end
  1531.   end
  1532.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1533.   # * Format By Word
  1534.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1535.   def mapf_format_by_word(text, line, tw, max_width)
  1536.     return line, line, tw, true if text.nil? || text.empty?
  1537.     # Extract next word
  1538.     if text.sub!(/([ \t\r\f]*)(\S*)([\n\f]?)/, "") != nil
  1539.       prespace, word, line_end = $1, $2, $3
  1540.       ntw = mapf_calc_line_width(word, tw, true)
  1541.       pw = contents.text_size(prespace).width
  1542.       if (pw + ntw >= max_width)
  1543.         # Insert
  1544.         if line.empty?
  1545.           # If one word takes entire line
  1546.           return prespace + word, word + "\n", ntw, true
  1547.         else
  1548.           return line + prespace + word, line + "\n" + word, tw, true
  1549.         end
  1550.       else
  1551.         line += prespace + word
  1552.         tw = pw + ntw
  1553.         # If the line is force ended, then end
  1554.         return line, line, tw, true if !line_end.empty?
  1555.       end
  1556.     else
  1557.       return line, line, tw, true
  1558.     end
  1559.     return line, line, tw, false
  1560.   end
  1561. end
  1562.  
  1563. class Window_Base
  1564.   include MA_Window_ParagraphFormat
  1565. end
  1566.  
  1567. $imported[:"MA_ParagraphFormat_1.0"] = true
  1568. end
  1569.  
  1570. #==============================================================================
  1571. # *** MAQJ Window_QuestBase
  1572. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1573. #  This module mixes in with all quest windows
  1574. #==============================================================================
  1575.  
  1576. module MAQJ_Window_QuestBase
  1577.   attr_reader :maqj_objective_color
  1578.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1579.   # * Object Initialization
  1580.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1581.   def initialize(*args, &block)
  1582.     super(*args, &block)
  1583.     reset_font_settings
  1584.     set_data_font(:normal)
  1585.     @maqj_default_font = contents.font.dup
  1586.     # Change the windowskin, tone if they are set to be changed
  1587.     self.windowskin = Cache.system($game_system.quest_windowskin) if $game_system.quest_windowskin
  1588.     self.opacity = $game_system.quest_window_opacity if $game_system.quest_window_opacity
  1589.   end
  1590.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1591.   # * Reset Font Settings
  1592.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1593.   def reset_font_settings(*args, &block)
  1594.     super(*args, &block)
  1595.     set_data_font(@maqj_font_data_type) if @maqj_font_data_type
  1596.   end
  1597.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1598.   # * Set Data Font
  1599.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1600.   def set_data_font(data_type)
  1601.     @maqj_default_font = contents.font.dup unless @maqj_default_font
  1602.     contents.font.name = QuestData::FONTNAMES[data_type] ?
  1603.       QuestData::FONTNAMES[data_type] : @maqj_default_font.name
  1604.     contents.font.size = QuestData::FONTSIZES[data_type] ?
  1605.       QuestData::FONTSIZES[data_type] : @maqj_default_font.size
  1606.     contents.font.bold = QuestData::FONTBOLDS.keys.include?(data_type) ?
  1607.       QuestData::FONTBOLDS[data_type] : @maqj_default_font.bold
  1608.     contents.font.italic = QuestData::FONTITALICS.keys.include?(data_type) ?
  1609.       QuestData::FONTITALICS[data_type] : @maqj_default_font.italic
  1610.     case data_type
  1611.     when :objectives then change_color(@maqj_objective_color) if @maqj_objective_color
  1612.     when :name then change_color(quest_name_colour(@quest)) if @quest
  1613.     else
  1614.       change_color(text_color(QuestData::COLOURS[data_type])) if QuestData::COLOURS.keys.include?(data_type)
  1615.     end
  1616.   end
  1617.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1618.   # * Draw Horizontal Line
  1619.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1620.   def draw_horizontal_line(y, h = 2)
  1621.     contents.fill_rect(0, y, contents_width, h, text_color(QuestData::COLOURS[:line]))
  1622.     contents.fill_rect(0, y + h, contents_width, [h / 2, 1].max, text_color(QuestData::COLOURS[:line_shadow]))
  1623.   end
  1624.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1625.   # * MA Text Color
  1626.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1627.   def text_color(param)
  1628.     begin
  1629.       colour = case param
  1630.       when Integer then super(param) rescue normal_color
  1631.       when Symbol then send(param) rescue normal_color
  1632.       when Array then Color.new(*param) rescue normal_color
  1633.       else
  1634.         normal_color
  1635.       end
  1636.     end
  1637.     colour.is_a?(Color) ? colour : normal_color
  1638.   end
  1639.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1640.   # * Quest Name Colour
  1641.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1642.   def quest_name_colour(quest = @quest)
  1643.     return if !quest
  1644.     quest = $game_party.quests[quest] if quest.is_a?(Integer)
  1645.     s = [:failed, :complete, :active].find { |status| quest.status?(status) }
  1646.     text_color(QuestData::COLOURS[s])
  1647.   end
  1648.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1649.   # * Quest Objective Colour
  1650.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1651.   def quest_objective_colour(quest, obj_id)
  1652.     return if !quest
  1653.     quest = $game_party.quests[quest] if quest.is_a?(Integer)
  1654.     s = [:failed, :complete, :active].find { |status| quest.objective_status?(status, obj_id) }
  1655.     text_color(QuestData::COLOURS[s])
  1656.   end
  1657.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1658.   # * Update Tone
  1659.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1660.   def update_tone
  1661.     $game_system.quest_window_tone ?
  1662.       self.tone.set(*$game_system.quest_window_tone) : super
  1663.   end
  1664. end
  1665.  
  1666. unless $imported[:"MA_IconHorzCommand_1.0"]
  1667. #==============================================================================
  1668. # ** Window_MA_IconHorzCommand
  1669. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1670. #  This window is a base window to show a horizontal command window populated
  1671. # with icons.
  1672. #==============================================================================
  1673.  
  1674. class Window_MA_IconHorzCommand < Window_HorzCommand
  1675.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1676.   # * Public Instance Variable
  1677.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1678.   attr_reader   :observing_procs
  1679.   attr_accessor :cursor_hide
  1680.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1681.   # * Object Initialization
  1682.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1683.   def initialize(*args, &block)
  1684.     @observing_procs = {}
  1685.     super(*args, &block)
  1686.   end
  1687.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1688.   # * Column Max
  1689.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1690.   def col_max; [(width - standard_padding) / (24 + spacing), item_max].min; end
  1691.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1692.   # * Item
  1693.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1694.   def item
  1695.     @list[index] ? @list[index][:symbol] : nil
  1696.   end
  1697.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1698.   # * Enabled? / Current Item Enabled?
  1699.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1700.   def enable?(index); self.index == index; end
  1701.   def current_item_enabled?; !current_data.nil?; end
  1702.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1703.   # * Draw Item
  1704.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1705.   def draw_item(index)
  1706.     rect = item_rect(index)
  1707.     contents.clear_rect(rect)
  1708.     draw_icon(@list[index][:ext], rect.x + ((rect.width - 24) / 2), rect.y, enable?(index))
  1709.   end
  1710.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1711.   # * Set Index
  1712.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1713.   def index=(index)
  1714.     old_index = self.index
  1715.     super(index)
  1716.     draw_item(old_index)
  1717.     draw_item(self.index)
  1718.   end
  1719.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1720.   # * Frame Update
  1721.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1722.   def update
  1723.     super
  1724.     @observing_procs.values.each { |block| block.call(item) }
  1725.   end
  1726.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1727.   # * Add/Remove Observing Window
  1728.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1729.   def add_observing_proc(id, &block)
  1730.     @observing_procs[id] = block
  1731.     update
  1732.   end
  1733.   def remove_observing_proc(id)     ; @observing_procs.delete(id) ; end
  1734.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1735.   # * Update Cursor
  1736.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1737.   def update_cursor
  1738.     super
  1739.     cursor_rect.empty if @cursor_hide
  1740.   end
  1741. end
  1742. $imported[:"MA_IconHorzCommand_1.0"] = true
  1743. end
  1744.  
  1745. #==============================================================================
  1746. # ** Window_QuestCategory
  1747. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1748. #  This window allows the player to switch between quest categories.
  1749. #==============================================================================
  1750.  
  1751. class Window_QuestCategory < Window_MA_IconHorzCommand
  1752.   include MAQJ_Window_QuestBase
  1753.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1754.   # * Object Initialization
  1755.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1756.   def initialize(x, y, categories = $game_system.quest_categories)
  1757.     @cursor_hide = QuestData::HIDE_CATEGORY_CURSOR
  1758.     @categories = categories
  1759.     super(x, y)
  1760.   end
  1761.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1762.   # * Window Width
  1763.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1764.   def window_width; QuestData::LIST_WINDOW_WIDTH; end
  1765.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1766.   # * Category=
  1767.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1768.   def category=(category)
  1769.     self.index = @categories.index(category) if @categories.include?(category)
  1770.   end
  1771.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1772.   # * Make Command List
  1773.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1774.   def make_command_list
  1775.     @categories.each { |cat|
  1776.       add_command("", cat, false, QuestData::ICONS[cat]) }
  1777.   end
  1778. end
  1779.  
  1780. #==============================================================================
  1781. # ** Window QuestLabel
  1782. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1783. #  This window simply shows a label for the Quests scene
  1784. #==============================================================================
  1785.  
  1786. class Window_QuestLabel < Window_Base
  1787.   include MAQJ_Window_QuestBase
  1788.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1789.   # * Object Initialization
  1790.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1791.   def initialize(x, y, label = "")
  1792.     super(x, y, window_width, window_height)
  1793.     refresh(label)
  1794.   end
  1795.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1796.   # * Reset Font Settings
  1797.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1798.   def reset_font_settings; set_data_font(:scene_label); end
  1799.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1800.   # * Window Attributes
  1801.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1802.   def window_width
  1803.     w = ($game_system.quest_categories.size > 1 || QuestData::SHOW_CATEGORY_LABEL) ?
  1804.       Graphics.width - QuestData::LIST_WINDOW_WIDTH : QuestData::LIST_WINDOW_WIDTH
  1805.   end
  1806.   def window_height; line_height + (standard_padding*2); end
  1807.   def line_height(*args)
  1808.     line_h = super(*args)
  1809.     QuestData::FONTSIZES[:scene_label] ?
  1810.       [QuestData::FONTSIZES[:scene_label], line_h].max : line_h
  1811.   end
  1812.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1813.   # * Refresh
  1814.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1815.   def refresh(label = @label)
  1816.     @label = label.is_a?(String) ? convert_escape_characters(label) : ""
  1817.     contents.clear
  1818.     reset_font_settings
  1819.     tw = mapf_calc_line_width(@label)
  1820.     draw_text_ex((contents_width - tw) / 2, 0, @label)
  1821.   end
  1822. end
  1823.  
  1824. #==============================================================================
  1825. # ** Window QuestLabel
  1826. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1827. #  This window simply shows a label for category currently selected
  1828. #==============================================================================
  1829.  
  1830. class Window_QuestCategoryLabel < Window_QuestLabel
  1831.   include MAQJ_Window_QuestBase
  1832.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1833.   # * Reset Font Settings
  1834.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1835.   def reset_font_settings; set_data_font(:category_label); end
  1836.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1837.   # * Window Attributes
  1838.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1839.   def window_width; QuestData::LIST_WINDOW_WIDTH; end
  1840.   def line_height(*args)
  1841.     line_h = super(*args)
  1842.     QuestData::FONTSIZES[:category_label] ?
  1843.       [QuestData::FONTSIZES[:category_label], line_h].max : line_h
  1844.   end
  1845.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1846.   # * Set Category
  1847.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1848.   def category=(category)
  1849.     return if @category == category
  1850.     @category = category
  1851.     refresh(QuestData::CATEGORY_VOCAB[category])
  1852.   end
  1853. end
  1854.  
  1855. #==============================================================================
  1856. # ** Window_QuestCategoryDummy
  1857. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1858. #  This window shows up behind the category and category label window
  1859. #==============================================================================
  1860.  
  1861. class Window_QuestCategoryDummy < Window_Base
  1862.   include MAQJ_Window_QuestBase
  1863. end
  1864.  
  1865. #==============================================================================
  1866. # ** Window_QuestList
  1867. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1868. #  This window shows all quests in a selected category.
  1869. #==============================================================================
  1870.  
  1871. class Window_QuestList < Window_Selectable
  1872.   include MAQJ_Window_QuestBase
  1873.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1874.   # * Object Initialization
  1875.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1876.   def initialize(x, y, width, height)
  1877.     super
  1878.     @data = []
  1879.     self.index = 0
  1880.     activate
  1881.   end
  1882.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1883.   # * Set Category
  1884.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1885.   def category=(category)
  1886.     return if @category == category
  1887.     @category = category
  1888.     refresh
  1889.     self.index = 0
  1890.     update_help if @help_window
  1891.   end
  1892.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1893.   # * Get Quest
  1894.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1895.   def item; @data && index >= 0 ? @data[index] : nil; end
  1896.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1897.   # * Column/Item Max
  1898.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1899.   def col_max; 1; end
  1900.   def item_max; @data ? @data.size : 1; end
  1901.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1902.   # * Whether it should be drawn enabled
  1903.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1904.   def enable?(item); true; end
  1905.   def current_item_enabled?
  1906.     (@help_window && @help_window.maqj_visible_height < @help_window.contents_height)
  1907.   end
  1908.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1909.   # * Make Item List
  1910.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1911.   def make_item_list
  1912.     @data = @category ? $game_party.quests.list(@category) : []
  1913.   end
  1914.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1915.   # * Draw Item
  1916.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1917.   def draw_item(index)
  1918.     quest = @data[index]
  1919.     if quest
  1920.       rect = item_rect_for_text(index)
  1921.       if QuestData::SHOW_QUEST_ICONS
  1922.         draw_icon(quest.icon_index, rect.x, rect.y, enable?(quest))
  1923.         rect.x += 24
  1924.         rect.width -= 24
  1925.       end
  1926.       change_color(quest_name_colour(quest), enable?(quest))
  1927.       draw_text(rect, quest.name)
  1928.     end
  1929.   end
  1930.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1931.   # * Refresh
  1932.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1933.   def refresh
  1934.     make_item_list
  1935.     create_contents
  1936.     set_data_font(:list)
  1937.     draw_all_items
  1938.   end
  1939.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1940.   # * Update Help
  1941.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1942.   def update_help
  1943.     @help_window.quest = item
  1944.   end
  1945. end
  1946.  
  1947. #==============================================================================
  1948. # ** Window_QuestData
  1949. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1950. #  This window shows all quest data
  1951. #==============================================================================
  1952.  
  1953. class Window_QuestData < Window_Selectable
  1954.   include MAQJ_Window_QuestBase
  1955.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1956.   # * Object Initialization
  1957.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1958.   def initialize(x, y, w, h, layout = QuestData::DATA_LAYOUT)
  1959.     @dest_scroll_oy = 0
  1960.     super(x, y, w, h)
  1961.     @dest_scroll_oy = self.oy
  1962.     self.layout = layout
  1963.   end
  1964.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1965.   # * Contents Height
  1966.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1967.   alias maqj_visible_height contents_height
  1968.   def contents_height
  1969.     @q_contents_height ? [@q_contents_height, maqj_visible_height].max : maqj_visible_height
  1970.   end
  1971.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1972.   # * Calculate Contents Height
  1973.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1974.   def calc_contents_height
  1975.     @q_contents_height = 0
  1976.     @layout.each { |dt| @q_contents_height += data_height(dt) } if @quest
  1977.   end
  1978.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1979.   # * Draw Data?
  1980.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1981.   def draw_data?(data_type)
  1982.     case data_type
  1983.     when :line then true
  1984.     when :level then @quest.level > 0
  1985.     when :objectives then !@quest.revealed_objectives.empty?
  1986.     when Array then (data_type - [:line]).any? { |dt| draw_data?(dt) }
  1987.     else !@quest.send(data_type).empty? # :description, :name, etc...
  1988.     end
  1989.   end
  1990.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1991.   # * Get Data Height
  1992.   #    This method calculates the height required for a specified element of
  1993.   #   the current quest. This is to calculate the needed space in contents,
  1994.   #   as well as advance the @draw_y variable.
  1995.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1996.   def data_height(data_type)
  1997.     return 0 unless draw_data?(data_type)
  1998.     return line_height if QuestData::BASIC_DATA_TYPES.include?(data_type)
  1999.     @maqj_font_data_type = data_type
  2000.     reset_font_settings
  2001.     return case data_type
  2002.     when :line, :level, :name then line_height
  2003.     when :banner
  2004.       bmp = Cache.picture(@quest.banner)
  2005.       hght = bmp.rect.height
  2006.       bmp.dispose
  2007.       hght
  2008.     when :description
  2009.       buff = description_x*2
  2010.       paragraph = mapf_format_paragraph(@quest.description, contents_width - buff)
  2011.       line_num = paragraph.scan(/\n/).size + 1
  2012.       line_num += (QuestData::DESCRIPTION_IN_BOX ? 2 :
  2013.         !QuestData::VOCAB[:description].empty? ? 1 : 0)
  2014.       line_num*line_height
  2015.     when :objectives
  2016.       objectives = @quest.revealed_objectives.collect { |obj_id|
  2017.         @quest.objectives[obj_id] }
  2018.       line_num = QuestData::VOCAB[:objectives].empty? ? 0 : 1
  2019.       buff = (objective_x*2) + text_size(QuestData::VOCAB[:objective_bullet]).width
  2020.       objectives.each { |obj|
  2021.         paragraph = mapf_format_paragraph(obj, contents_width - buff)
  2022.         line_num += paragraph.scan(/\n/).size + 1 }
  2023.       line_num*line_height
  2024.     when :rewards
  2025.       line_num = QuestData::VOCAB[:rewards].empty? ? 0 : 1
  2026.       (line_num + @quest.rewards.size)*line_height
  2027.     when Array then data_height(data_type.max_by { |dt| data_height(dt) })
  2028.     else 0
  2029.     end
  2030.   end
  2031.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2032.   # * Set Quest
  2033.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2034.   def quest=(value)
  2035.     return if @quest == value
  2036.     @quest = value
  2037.     @layout = (@quest && @quest.layout) ? @quest.layout : @default_layout
  2038.     refresh
  2039.   end
  2040.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2041.   # * Set Layout
  2042.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2043.   def layout=(value)
  2044.     return if @default_layout == value && @layout == value
  2045.     @default_layout = value
  2046.     @layout = value
  2047.     refresh
  2048.   end
  2049.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2050.   # * Refresh
  2051.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2052.   def refresh
  2053.     contents.clear
  2054.     calc_contents_height
  2055.     create_contents
  2056.     return unless @quest && @layout
  2057.     self.oy = 0
  2058.     @dest_scroll_oy = 0
  2059.     #  The basic idea here is that each draw_ method will rely on and advance
  2060.     # the @draw_y variable. Where they are an array, the elements will be
  2061.     # drawn at the same @draw_y.
  2062.     @draw_y = 0
  2063.     @layout.each {|dt|
  2064.       next unless draw_data?(dt)
  2065.       dt.is_a?(Array) ? draw_data_array(dt) : draw_data(dt)
  2066.     }
  2067.   end
  2068.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2069.   # * Draw Data
  2070.   #    data_type : the data block to draw next
  2071.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2072.   def draw_data(data_type)
  2073.     @maqj_font_data_type = data_type
  2074.     reset_font_settings
  2075.     send(:"draw_#{data_type}") if self.class.method_defined?(:"draw_#{data_type}")
  2076.     @draw_y += data_height(data_type)
  2077.   end
  2078.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2079.   # * Draw Data Array
  2080.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2081.   def draw_data_array(layout_array)
  2082.     y, max_y = @draw_y, @draw_y
  2083.     # Draw each data aspect at the same starting @draw_y
  2084.     layout_array.each { |dt|
  2085.       @draw_y = y
  2086.       draw_data(dt)
  2087.       max_y = @draw_y if @draw_y > max_y
  2088.     }
  2089.     @draw_y = max_y
  2090.   end
  2091.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2092.   # * Draw Line
  2093.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2094.   def draw_line; draw_horizontal_line(@draw_y + (line_height / 2) - 1, 2); end
  2095.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2096.   # * Draw Name
  2097.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2098.   def draw_name
  2099.     set_data_font(:name)
  2100.     clear_and_draw_text(0, @draw_y, contents_width, line_height, @quest.name, 1)
  2101.   end
  2102.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2103.   # * Draw Level
  2104.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2105.   def draw_level
  2106.     case QuestData::LEVEL_ICON
  2107.     when Array then QuestData::LEVEL_ICON.empty? ? draw_level_text : draw_level_array
  2108.     when 0 then draw_level_text
  2109.     else
  2110.       draw_level_stacked
  2111.     end
  2112.   end
  2113.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2114.   # * Draw Stacked Level
  2115.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2116.   def draw_level_stacked(icon_index = QuestData::LEVEL_ICON)
  2117.     align = QuestData::HEADING_ALIGN[:level]
  2118.     es = QuestData::LEVEL_ICONS_SPACE*(@quest.level - 1)
  2119.     x = align == 2 ? contents_width - 24 : align == 1 ?
  2120.       (contents_width - 24 - (es)) / 2 : es
  2121.     @quest.level.times do
  2122.       draw_icon(icon_index, x, @draw_y)
  2123.       x -= QuestData::LEVEL_ICONS_SPACE
  2124.     end
  2125.   end
  2126.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2127.   # * Draw Array Level
  2128.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2129.   def draw_level_array(icon_index = QuestData::LEVEL_ICON)
  2130.     return if icon_index.empty?
  2131.     icon_index = icon_index[@quest.level - 1] ? icon_index[@quest.level - 1] : icon_index[-1]
  2132.     align = QuestData::HEADING_ALIGN[:level]
  2133.     x = align == 2 ? contents_width - 24 : align == 1 ? (contents_width-24)/2 : 0
  2134.     draw_icon(icon_index, x, @draw_y)
  2135.   end
  2136.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2137.   # * Draw Text Level
  2138.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2139.   def draw_level_text
  2140.     reset_font_settings
  2141.     level = QuestData::LEVEL_SIGNALS && QuestData::LEVEL_SIGNALS[@quest.level - 1] ?
  2142.       QuestData::LEVEL_SIGNALS[@quest.level - 1] : @quest.level.to_s
  2143.     align = QuestData::HEADING_ALIGN[:level]
  2144.     tw = text_size(QuestData::VOCAB[:level]).width + 4
  2145.     tw2 = text_size(level).width + 2
  2146.     space = contents_width - tw - tw2
  2147.     x = align == 2 ? space : align == 1 ? space / 2 : 0
  2148.     clear_and_draw_text(x, @draw_y, tw, line_height, QuestData::VOCAB[:level])
  2149.     set_data_font(:level_signal)
  2150.     clear_and_draw_text(x + tw, @draw_y, tw2, line_height, level, 2)
  2151.   end
  2152.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2153.   # * Draw Banner
  2154.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2155.   def draw_banner
  2156.     bmp = Cache.picture(@quest.banner) # Get Picture
  2157.     # Shift the hue if requested
  2158.     bmp.hue_change(@quest.banner_hue) unless @quest.banner_hue == 0
  2159.     x = (contents_width - bmp.rect.width) / 2
  2160.     if x < 0 # Stretch horizontally if the banner is too wide
  2161.       dest_rect = bmp.rect.dup
  2162.       dest_rect.width = contents_width
  2163.       contents.stretch_blt(dest_rect, bmp, bmp.rect)
  2164.     else
  2165.       contents.blt(x, @draw_y, bmp, bmp.rect)
  2166.     end
  2167.     bmp.dispose
  2168.   end
  2169.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2170.   # * Draw Description
  2171.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2172.   def draw_description
  2173.     buff = description_x*2
  2174.     paragraph = mapf_format_paragraph(@quest.description, contents_width - buff)
  2175.     y = @draw_y
  2176.     # Draw Rect
  2177.     draw_box(paragraph.scan(/\n/).size + 1) if QuestData::DESCRIPTION_IN_BOX
  2178.     # Draw Description Label
  2179.     draw_heading(:description, y) unless QuestData::VOCAB[:description].empty?
  2180.     # Draw Description
  2181.     y += line_height if !QuestData::VOCAB[:description].empty? || QuestData::DESCRIPTION_IN_BOX
  2182.     draw_text_ex(description_x, y, paragraph)
  2183.   end
  2184.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2185.   # * Draw Objectives
  2186.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2187.   def draw_objectives
  2188.     y = @draw_y
  2189.     unless QuestData::VOCAB[:objectives].empty?
  2190.       draw_heading(:objectives, y)
  2191.       y += line_height
  2192.     end
  2193.     @quest.revealed_objectives.each { |obj_id| y = draw_objective(obj_id, y) }
  2194.   end
  2195.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2196.   # * Draw Objective
  2197.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2198.   def draw_objective(obj_id, y)
  2199.     bullet = QuestData::VOCAB[:objective_bullet]
  2200.     bullet_tw = text_size(bullet).width + 2
  2201.     buff = (objective_x*2) + bullet_tw
  2202.     paragraph = mapf_format_paragraph(@quest.objectives[obj_id], contents_width - buff)
  2203.     line_num = 1 + paragraph.scan(/\n/).size
  2204.     # Since draw_text_ex resets the font, set colour here
  2205.     @maqj_objective_color = quest_objective_colour(@quest, obj_id)
  2206.     change_color(text_color(QuestData::COLOURS[:objective_bullet]))
  2207.     draw_text(objective_x, y, bullet_tw, line_height, sprintf(bullet, obj_id + 1))
  2208.     draw_text_ex(objective_x + bullet_tw, y, paragraph)
  2209.     @maqj_objective_color = false
  2210.     y += (line_num*line_height)
  2211.   end
  2212.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2213.   # * Draw Rewards
  2214.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2215.   def draw_rewards
  2216.     y = @draw_y
  2217.     unless QuestData::VOCAB[:rewards].empty?
  2218.       draw_heading(:rewards, y)
  2219.       y += line_height
  2220.     end
  2221.     for i in 0...@quest.rewards.size do draw_reward(i, y + i*line_height) end
  2222.   end
  2223.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2224.   # * Draw Reward
  2225.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2226.   def draw_reward(r_id, y)
  2227.     reward = @quest.rewards[r_id]
  2228.     case reward[0]
  2229.     when :item, 0   # Item
  2230.       draw_item_reward(y, $data_items[reward[1]], reward[2] ? reward[2] : 1)
  2231.     when :weapon, 1 # Weapon
  2232.       draw_item_reward(y, $data_weapons[reward[1]], reward[2] ? reward[2] : 1)
  2233.     when :armor, 2  # Armor
  2234.       draw_item_reward(y, $data_armors[reward[1]], reward[2] ? reward[2] : 1)
  2235.     when :gold, 3   # Gold
  2236.       draw_basic_data(y, QuestData::ICONS[:reward_gold],
  2237.         QuestData::VOCAB[:reward_gold], (reward[1] ? reward[1] : 0).to_s)
  2238.     when :exp, 4    # Exp
  2239.       draw_basic_data(y, QuestData::ICONS[:reward_exp],
  2240.         QuestData::VOCAB[:reward_exp], (reward[1] ? reward[1] : 0).to_s)
  2241.     when :string, 5 # String
  2242.       draw_basic_data(y, reward[1] ? reward[1] : 0, reward[3] ? reward[3].to_s : "",
  2243.         reward[2] ? reward[2].to_s : "")
  2244.     end
  2245.   end
  2246.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2247.   # * Draw Item Reward
  2248.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2249.   def draw_item_reward(y, item, amount = 1)
  2250.     w = contents_width
  2251.     w = QuestData::BASIC_DATA_WIDTH if QuestData::BASIC_DATA_WIDTH.between?(1, w)
  2252.     x = (contents_width - w) / 2
  2253.     draw_item_name(item, x, y, true, w - 40)
  2254.     if amount > 1
  2255.       change_color(text_color(QuestData::COLOURS[:reward_amount]))
  2256.       draw_text(x + w - 40, y, 40, line_height, sprintf(QuestData::VOCAB[:reward_amount], amount), 2)
  2257.     end
  2258.   end
  2259.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2260.   # * Draw Basic Data Methods
  2261.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2262.   QuestData::BASIC_DATA_TYPES.each { |data_type|
  2263.     define_method(:"draw_#{data_type}") {
  2264.       draw_basic_data(@draw_y, QuestData::ICONS[data_type],
  2265.         QuestData::VOCAB[data_type], @quest.send(data_type))
  2266.     }
  2267.   }
  2268.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2269.   # * Draw Basic Data
  2270.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2271.   def draw_basic_data(y, icon_index, vocab, value)
  2272.     w = contents_width
  2273.     w = QuestData::BASIC_DATA_WIDTH if QuestData::BASIC_DATA_WIDTH.between?(1, w)
  2274.     x = (contents_width - w) / 2
  2275.     unless icon_index == 0
  2276.       draw_icon(icon_index, x, y)
  2277.       x += 24
  2278.       w -= 24
  2279.     end
  2280.     tw = text_size(vocab).width
  2281.     change_color(text_color(QuestData::COLOURS[:basic_label]))
  2282.     draw_text(x, y, tw, line_height, vocab)
  2283.     change_color(text_color(QuestData::COLOURS[:basic_value]))
  2284.     draw_text(x + tw, y, w - tw, line_height, value, 2)
  2285.   end
  2286.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2287.   # * Draw Heading
  2288.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2289.   def draw_heading(data_type, y)
  2290.     set_data_font(:heading)
  2291.     clear_and_draw_text(40, y, contents_width - 80, line_height,
  2292.       QuestData::VOCAB[data_type], QuestData::HEADING_ALIGN[data_type])
  2293.     reset_font_settings
  2294.   end
  2295.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2296.   # * Clear and Draw Text
  2297.   #    Clear the field before drawing the text
  2298.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2299.   def clear_and_draw_text(*args)
  2300.     rect = []
  2301.     while !args[0].is_a?(String) do rect.push(args.shift) end
  2302.     rect[0].is_a?(Rect) ? rect = rect[0] : rect = Rect.new(*rect)
  2303.     align = args[1] ? args[1] : 0
  2304.     ts = text_size(args[0])
  2305.     ts.width = [ts.width + 4, rect.width].min
  2306.     align == 1 ? ts.x = rect.x + ((rect.width - ts.width) / 2) :
  2307.       align == 2 ? ts.x = rect.x + rect.width - ts.width : ts.x = rect.x
  2308.     ts.y = rect.y
  2309.     contents.clear_rect(ts)
  2310.     ts.x += 2
  2311.     draw_text(ts, args[0], align)
  2312.   end
  2313.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2314.   # * Draw Description Box
  2315.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2316.   def draw_box(line_num)
  2317.     return if line_num < 1
  2318.     x = (line_height / 2) - 1
  2319.     y = @draw_y + (line_height / 2) - 1
  2320.     w = contents_width - 2*x
  2321.     h = (1 + line_num)*line_height
  2322.     draw_rect_outline_with_shadow(x, y, w, h)
  2323.   end
  2324.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2325.   # * Draw Rect Outline
  2326.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2327.   def draw_rect_outline(x, y, w, h, colour)
  2328.     # Horizontal Lines
  2329.     contents.fill_rect(x, y, w, 2, colour)
  2330.     contents.fill_rect(x, y + h - 2, w, 2, colour)
  2331.     # Vertical Lines
  2332.     contents.fill_rect(x, y, 2, h, colour)
  2333.     contents.fill_rect(x + w - 2, y, 2, h, colour)
  2334.   end
  2335.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2336.   # * Draw Rect Outline with Shadow
  2337.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2338.   def draw_rect_outline_with_shadow(x, y, w, h)
  2339.     draw_rect_outline(x + 1, y + 1, w, h, text_color(QuestData::COLOURS[:line_shadow]))
  2340.     draw_rect_outline(x, y, w, h, text_color(QuestData::COLOURS[:line]))
  2341.   end
  2342.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2343.   # * Objective/Description X
  2344.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2345.   def objective_x; line_height / 2; end
  2346.   def description_x; QuestData::DESCRIPTION_IN_BOX ? line_height : (line_height/2); end
  2347.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2348.   # * Update
  2349.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2350.   def update(*args, &block)
  2351.     super(*args, &block)
  2352.     if open? && active && @dest_scroll_oy == self.oy
  2353.       scroll_down if Input.press?(:DOWN)
  2354.       scroll_up if Input.press?(:UP)
  2355.     end
  2356.     if self.oy != @dest_scroll_oy
  2357.       mod = (@dest_scroll_oy <=> self.oy)
  2358.       self.oy += 3*mod
  2359.       self.oy = @dest_scroll_oy if (@dest_scroll_oy <=> self.oy) != mod
  2360.     end
  2361.   end
  2362.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2363.   # * Scroll Down
  2364.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2365.   def scroll_down(*args, &block)
  2366.     max_oy = contents_height - maqj_visible_height
  2367.     dest = ((@dest_scroll_oy / line_height) + 1)*line_height
  2368.     @dest_scroll_oy = [dest, max_oy].min
  2369.   end
  2370.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2371.   # * Scroll Up
  2372.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2373.   def scroll_up(*args, &block)
  2374.     dest = ((@dest_scroll_oy / line_height) - 1)*line_height
  2375.     @dest_scroll_oy = [dest, 0].max
  2376.   end
  2377. end
  2378.  
  2379. #==============================================================================
  2380. # ** Scene_Quest
  2381. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2382. #  This class handles processing for the Quest scene
  2383. #==============================================================================
  2384.  
  2385. class Scene_Quest < Scene_MenuBase
  2386.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2387.   # * Start Scene Processing
  2388.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2389.   def start
  2390.     super
  2391.     @init_category, @init_quest_index = $game_party.quests.find_location($game_system.last_quest_id, $game_system.last_quest_cat)
  2392.     create_maqj_picture unless $game_system.quest_bg_picture.empty?
  2393.     create_all_windows
  2394.     adjust_window_positions
  2395.   end
  2396.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2397.   # * Terminate Scene
  2398.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2399.   def terminate
  2400.     $game_system.quest_categories = QuestData::CATEGORIES
  2401.     $game_system.quest_scene_label = QuestData::VOCAB[:scene_label]
  2402.     $game_system.last_quest_id = @quest_list_window.item ? @quest_list_window.item.id : 0
  2403.     $game_system.last_quest_cat = @quest_category_window ?
  2404.       @quest_category_window.item : $game_system.quest_categories[0]
  2405.     super
  2406.     dispose_maqj_picture
  2407.   end
  2408.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2409.   # * Create Background Picture
  2410.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2411.   def create_maqj_picture
  2412.     @maqj_picture_sprite = Sprite.new
  2413.     @maqj_picture_sprite.bitmap = Cache.picture($game_system.quest_bg_picture)
  2414.     @maqj_picture_sprite.opacity = $game_system.quest_bg_opacity
  2415.     @maqj_picture_sprite.blend_type = $game_system.quest_bg_blend_type
  2416.     @maqj_picture_sprite.z = @background_sprite.z + 1 if @background_sprite
  2417.   end
  2418.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2419.   # * Create All Windows
  2420.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2421.   def create_all_windows
  2422.     create_quest_label_window unless $game_system.quest_scene_label.empty?
  2423.     create_quest_category_window if $game_system.quest_categories.size > 1
  2424.     create_quest_category_label_window if QuestData::SHOW_CATEGORY_LABEL
  2425.     create_dummy_category_window if QuestData::CATEGORY_LABEL_IN_SAME_WINDOW &&
  2426.       @quest_category_window && @quest_category_label_window
  2427.     create_quest_list_window
  2428.     create_quest_data_window
  2429.   end
  2430.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2431.   # * Create QuestLabel Window
  2432.   #    This window shows the name of the scene
  2433.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2434.   def create_quest_label_window
  2435.     @quest_label_window = Window_QuestLabel.new(0, 0, $game_system.quest_scene_label)
  2436.   end
  2437.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2438.   # * Create QuestCategory Window
  2439.   #    This window allows the player to switch categories.
  2440.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2441.   def create_quest_category_window
  2442.     @quest_category_window = Window_QuestCategory.new(0, 0, $game_system.quest_categories)
  2443.     @quest_category_window.category = @init_category if @init_category
  2444.     @quest_category_window.set_handler(:cancel, method(:on_category_cancel))
  2445.     @quest_category_window.set_handler(:ok, method(:on_category_ok))
  2446.   end
  2447.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2448.   # * Create QuestCategoryLabel Window
  2449.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2450.   def create_quest_category_label_window
  2451.     if @quest_category_window
  2452.       @quest_category_label_window = Window_QuestCategoryLabel.new(0, @quest_category_window.height)
  2453.       @quest_category_window.add_observing_proc(:label) { |category|
  2454.         @quest_category_label_window.category = category }
  2455.     else
  2456.       @quest_category_label_window = Window_QuestCategoryLabel.new(0, 0)
  2457.       @quest_category_label_window.category = $game_system.quest_categories ? $game_system.quest_categories[0] : :all
  2458.     end
  2459.   end
  2460.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2461.   # * Create Dummy Category Label Window
  2462.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2463.   def create_dummy_category_window
  2464.     @quest_category_label_window.y -= 12
  2465.     @quest_category_label_window.opacity = 0
  2466.     @quest_category_window.opacity = 0
  2467.     w = [@quest_category_window.width, @quest_category_label_window.width].max
  2468.     h = @quest_category_window.height + @quest_category_label_window.height - 12
  2469.     @category_dummy_window = Window_QuestCategoryDummy.new(0, 0, w, h)
  2470.     @category_dummy_window.z = [@quest_category_window.z, @quest_category_label_window.z].min - 1
  2471.     # Draw Horz Line
  2472.     @category_dummy_window.draw_horizontal_line(@quest_category_window.height - @quest_category_window.padding - 7, 2)
  2473.   end
  2474.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2475.   # * Create QuestList Window
  2476.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2477.   def create_quest_list_window
  2478.     if @category_dummy_window
  2479.       y = @category_dummy_window.height
  2480.     else
  2481.       y = @quest_category_window ? @quest_category_window.height : 0
  2482.       y += @quest_category_label_window ? @quest_category_label_window.height : 0
  2483.       y = @quest_label_window.height if y == 0
  2484.     end
  2485.     @quest_list_window = Window_QuestList.new(0, y, QuestData::LIST_WINDOW_WIDTH,
  2486.       Graphics.height - y)
  2487.     @quest_list_window.set_handler(:ok, method(:on_list_ok))
  2488.     @quest_list_window.deactivate if !QuestData::CONCURRENT_ACTIVITY
  2489.     if !QuestData::CONCURRENT_ACTIVITY || !@quest_category_window
  2490.       @quest_list_window.set_handler(:cancel, method(:on_list_cancel))
  2491.     end
  2492.     if @quest_category_window
  2493.       @quest_category_window.add_observing_proc(:list) { |category|
  2494.         @quest_list_window.category = category }
  2495.     else
  2496.       @quest_list_window.category = $game_system.quest_categories[0]
  2497.     end
  2498.     @quest_list_window.index = @init_quest_index if @init_quest_index
  2499.   end
  2500.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2501.   # * Create QuestData Window
  2502.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2503.   def create_quest_data_window
  2504.     x = @quest_list_window.width
  2505.     y = (@quest_label_window && (@quest_category_window ||
  2506.       @quest_category_label_window)) ? @quest_label_window.height : 0
  2507.     @quest_data_window = Window_QuestData.new(x, y, Graphics.width - x,
  2508.       Graphics.height - y)
  2509.     @quest_list_window.help_window = @quest_data_window
  2510.     @quest_data_window.quest = @quest_list_window.item
  2511.     @quest_data_window.set_handler(:ok, method(:on_data_ok))
  2512.     @quest_data_window.set_handler(:cancel, method(:on_data_cancel))
  2513.   end
  2514.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2515.   # * Dispose Background Picture
  2516.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2517.   def dispose_maqj_picture
  2518.     @maqj_picture_sprite.dispose if @maqj_picture_sprite
  2519.   end
  2520.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2521.   # * Adjust Window Positions
  2522.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2523.   def adjust_window_positions
  2524.     if @quest_label_window && (@quest_category_window || @quest_category_label_window)
  2525.       @quest_label_window.x = QuestData::LIST_WINDOW_WIDTH
  2526.     end
  2527.   end
  2528.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2529.   # * Category OK
  2530.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2531.   def on_category_ok; @quest_list_window.activate; end
  2532.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2533.   # * Category Cancel
  2534.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2535.   def on_category_cancel; return_scene; end
  2536.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2537.   # * List OK
  2538.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2539.   def on_list_ok
  2540.     @quest_category_window.deactivate if @quest_category_window
  2541.     @quest_data_window.activate
  2542.   end
  2543.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2544.   # * List Cancel
  2545.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2546.   def on_list_cancel
  2547.     @quest_category_window ? @quest_category_window.activate : return_scene
  2548.   end
  2549.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2550.   # * Data OK
  2551.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2552.   #def on_data_ok; on_data_cancel; end
  2553.   def on_data_ok; return_scene; $game_temp.reserve_common_event(quest_id); 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