cooldoode325

Large Choices

Feb 24th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.28 KB | None | 0 0
  1. =begin
  2. #==============================================================================
  3. Title Large Choices
  4. Author: Tsukihime
  5. Date: Nov 18, 2013
  6. ------------------------------------------------------------------------------
  7. ** Change log
  8. Nov 18, 2013
  9. - updated to preserve the event page's original list
  10. Apr 10, 2013
  11. - added option to disable automatic show combining
  12. Mar 26, 2013
  13. - fixed bug where cancel choice was not properly updated
  14. Jan 12, 2013
  15. - fixed bug where the first set of nested options were numbered incorrectly
  16. Dec 7, 2012
  17. - implemented proper branch canceling
  18. Dec 6, 2012
  19. - Initial release
  20. ------------------------------------------------------------------------------
  21. ** Terms of Use
  22. * Free to use in non-commercial projects
  23. * Contact me for commercial use
  24. * No real support. The script is provided as-is
  25. * Will do bug fixes, but no compatibility patches
  26. * Features may be requested but no guarantees, especially if it is non-trivial
  27. * Preserve this header
  28. ------------------------------------------------------------------------------
  29. ** Description
  30.  
  31. This script combines groups of "show choice" options together as one large
  32. command. This allows you to create more than 4 choices by simply creating
  33. several "show choice" commands.
  34. ------------------------------------------------------------------------------
  35. ** Installation
  36.  
  37. Place this script below Materials and above Main
  38.  
  39. ------------------------------------------------------------------------------
  40. ** Usage
  41.  
  42. Add a show choice command.
  43. If you want more choices, add another one, and fill it out as usual.
  44.  
  45. Note that you should only specify one cancel choice (if you specify more than
  46. one, then the last one is taken).
  47.  
  48. For "branch" canceling, note that *all* cancel branches are executed.
  49. You should only have a cancel branch on the last set of choices
  50.  
  51. You can disable automatic choice combining by enabling the "Manual Combine"
  52. option, which will require you to make this script call before the first
  53. show choice command
  54.  
  55. combine_choices
  56.  
  57. In order to combine choices together
  58. #==============================================================================
  59. =end
  60. $imported = {} if $imported.nil?
  61. $imported["TH_LargeChoices"] = true
  62. #==============================================================================
  63. # ** Configuration
  64. #==============================================================================
  65. module TH
  66. module Large_Choices
  67.  
  68. # Turning this option on will require you to manually specify that
  69. # a sequence of Show Choice options should be combined
  70. Manual_Combine = false
  71.  
  72. #==============================================================================
  73. # ** Rest of the script
  74. #==============================================================================
  75. Code_Filter = [402, 403, 404]
  76. Regex = /<large choices>/i
  77. end
  78. end
  79.  
  80. class Game_Temp
  81.  
  82. # temp solution to get this working
  83. attr_accessor :branch_choice
  84.  
  85. def branch_choice
  86. @branch_choice || 5
  87. end
  88. end
  89.  
  90. class Game_Interpreter
  91.  
  92. #-----------------------------------------------------------------------------
  93. # Clean up
  94. #-----------------------------------------------------------------------------
  95. alias :th_large_choices_clear :clear
  96. def clear
  97. th_large_choices_clear
  98. @first_choice_cmd = nil
  99. @choice_search = 0
  100. @combine_choices = false
  101. end
  102.  
  103. #-----------------------------------------------------------------------------
  104. # Prepare for more choices
  105. #-----------------------------------------------------------------------------
  106. alias :th_large_choices_setup_choices :setup_choices
  107. def setup_choices(params)
  108.  
  109. # Make a copy of our list so we don't modify the original
  110. @list = Marshal.load(Marshal.dump(@list))
  111.  
  112. # start with our original choices
  113. th_large_choices_setup_choices(params)
  114.  
  115. return if TH::Large_Choices::Manual_Combine && !@combine_choices
  116.  
  117. # store our "first" choice in the sequence
  118. @first_choice_cmd = @list[@index]
  119.  
  120. # reset branch choice
  121. $game_temp.branch_choice = @first_choice_cmd.parameters[1]
  122.  
  123. # Start searching for more choices
  124. @num_choices = $game_message.choices.size
  125. @choice_search = @index + 1
  126. search_more_choices
  127. end
  128.  
  129. def combine_choices
  130. @combine_choices = true
  131. end
  132.  
  133. #-----------------------------------------------------------------------------
  134. # New. Check whether the next command (after all branches) is another choice
  135. # command. If so, merge it with the first choice command.
  136. #-----------------------------------------------------------------------------
  137. def search_more_choices
  138. skip_choice_branches
  139. next_cmd = @list[@choice_search]
  140.  
  141. # Next command isn't a "show choice" so we're done
  142. return if next_cmd.code != 102
  143.  
  144. @choice_search += 1
  145. # Otherwise, push the choices into the first choice command to merge
  146. # the commands.
  147. @first_choice_cmd.parameters[0].concat(next_cmd.parameters[0])
  148.  
  149. # Update all cases to reflect merged choices
  150. update_show_choices(next_cmd.parameters)
  151. update_cancel_choice(next_cmd.parameters)
  152. update_choice_numbers
  153.  
  154. # delete the command to effectively merge the branches
  155. @list.delete(next_cmd)
  156.  
  157. # Now search for more
  158. search_more_choices
  159. end
  160.  
  161. #-----------------------------------------------------------------------------
  162. # New. Update the options for the first "show choice" command
  163. #-----------------------------------------------------------------------------
  164. def update_show_choices(params)
  165. params[0].each {|s| $game_message.choices.push(s) }
  166. end
  167.  
  168. #-----------------------------------------------------------------------------
  169. # New. If cancel specified, update it to reflect merged choice numbers
  170. # The last one is taken if multiple cancel choices are specified
  171. #-----------------------------------------------------------------------------
  172. def update_cancel_choice(params)
  173.  
  174. # disallow, just ignore
  175. return if params[1] == 0
  176.  
  177. # branch on cancel
  178. return update_branch_choice if params[1] == 5
  179.  
  180. # num_choices is not one-based
  181. cancel_choice = params[1] + (@num_choices)
  182. # update cancel choice, as well as the first choice command
  183. $game_message.choice_cancel_type = cancel_choice
  184. @first_choice_cmd.parameters[1] = cancel_choice
  185. end
  186.  
  187. #-----------------------------------------------------------------------------
  188. # New. Set the initial choice command to "branch cancel"
  189. #-----------------------------------------------------------------------------
  190. def update_branch_choice
  191. branch_choice = $game_message.choices.size + 1
  192. $game_message.choice_cancel_type = branch_choice
  193. $game_temp.branch_choice = branch_choice
  194. @first_choice_cmd.parameters[1] = branch_choice
  195. end
  196.  
  197. def command_403
  198. command_skip if @branch[@indent] != $game_temp.branch_choice - 1
  199. end
  200.  
  201. #-----------------------------------------------------------------------------
  202. # New. For each branch, update it to reflect the merged choice numbers.
  203. #-----------------------------------------------------------------------------
  204. def update_choice_numbers
  205.  
  206. # Begin searching immediately after cmd 102 (show choice)
  207. i = @choice_search
  208.  
  209. # Rough search for "When" commands. The search must skip nested commands
  210. while TH::Large_Choices::Code_Filter.include?(@list[i].code) || @list[i].indent != @indent
  211. if @list[i].code == 402 && @list[i].indent == @indent
  212. @list[i].parameters[0] = @num_choices
  213. @num_choices += 1
  214. end
  215. i += 1
  216. end
  217. end
  218.  
  219. #-----------------------------------------------------------------------------
  220. # New. Returns the next command after our choice branches
  221. #-----------------------------------------------------------------------------
  222. def skip_choice_branches
  223. # start search at the next command
  224. # skip all choice branch-related commands and any branches
  225. while TH::Large_Choices::Code_Filter.include?(@list[@choice_search].code) || @list[@choice_search].indent != @indent
  226. @choice_search += 1
  227. end
  228. return @choice_search
  229. end
  230. end
Advertisement
Add Comment
Please, Sign In to add comment