pigu_6

Tsukihime| Large Choice

Dec 20th, 2012
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. =begin
  2. #==============================================================================
  3. ** Large Choices
  4. Author: Tsukihime
  5. Date: Dec 6, 2012
  6. ------------------------------------------------------------------------------
  7. ** Change log
  8. Dec 7, 2012
  9. - implemented proper branch canceling
  10. Dec 6, 2012
  11. - Initial release
  12. ------------------------------------------------------------------------------
  13. ** Terms of Use
  14. * Free to use in commercial/non-commercial projects
  15. * No real support. The script is provided as-is
  16. * Will do bug fixes, but no compatibility patches
  17. * Features may be requested but no guarantees, especially if it is non-trivial
  18. * Preserve this header
  19. ------------------------------------------------------------------------------
  20. ** Description
  21.  
  22. This script combines groups of "show choice" options together as one large
  23. command. This allows you to create more than 4 choices by simply creating
  24. several "show choice" commands.
  25. ------------------------------------------------------------------------------
  26. ** Usage
  27.  
  28. Add a show choice command.
  29. If you want more choices, add another one, and fill it out as usual.
  30.  
  31. Note that you should only specify one cancel choice (if you specify more than
  32. one, then the last one is taken).
  33.  
  34. For "branch" canceling, note that *all* cancel branches are executed.
  35. You should only have a cancel branch on the last set of choices
  36. #==============================================================================
  37. =end
  38. $imported = {} if $imported.nil?
  39. $imported["Tsuki_LargeChoices"] = true
  40. #==============================================================================
  41. # ** Configuration
  42. #==============================================================================
  43. module Tsuki
  44. module Large_Choices
  45. Code_Filter = [402, 403, 404]
  46. end
  47. end
  48. #==============================================================================
  49. # ** Rest of the script
  50. #==============================================================================
  51. class Game_Temp
  52.  
  53. # temp solution to get this working
  54. attr_accessor :branch_choice
  55.  
  56. def branch_choice
  57. @branch_choice || 5
  58. end
  59. end
  60. class Game_Interpreter
  61.  
  62. #-----------------------------------------------------------------------------
  63. # Clean up
  64. #-----------------------------------------------------------------------------
  65. alias :th_large_choices_clear :clear
  66. def clear
  67. th_large_choices_clear
  68. @first_choice_cmd = nil
  69. @choice_search = 0
  70. end
  71.  
  72. #-----------------------------------------------------------------------------
  73. # Prepare for more choices
  74. #-----------------------------------------------------------------------------
  75. alias :th_large_choices_setup_choices :setup_choices
  76. def setup_choices(params)
  77. # start with our original choices
  78. th_large_choices_setup_choices(params)
  79.  
  80. # store our "first" choice in the sequence
  81. @first_choice_cmd = @list[@index]
  82.  
  83. # reset branch choice
  84. $game_temp.branch_choice = @first_choice_cmd.parameters[1]
  85.  
  86. # Start searching for more choices
  87. @num_choices = $game_message.choices.size
  88. @choice_search = @index + 1
  89. search_more_choices
  90. end
  91.  
  92. #-----------------------------------------------------------------------------
  93. # New. Check whether the next command (after all branches) is another choice
  94. # command. If so, merge it with the first choice command.
  95. #-----------------------------------------------------------------------------
  96. def search_more_choices
  97. skip_choice_branches
  98. next_cmd = @list[@choice_search]
  99.  
  100. # Next command isn't a "show choice" so we're done
  101. return if next_cmd.code != 102
  102.  
  103. @choice_search += 1
  104. # Otherwise, push the choices into the first choice command to merge
  105. # the commands.
  106. @first_choice_cmd.parameters[0].concat(next_cmd.parameters[0])
  107.  
  108. # Update all cases to reflect merged choices
  109. update_show_choices(next_cmd.parameters)
  110. update_cancel_choice(next_cmd.parameters)
  111. update_choice_numbers
  112.  
  113. # delete the command to effectively merge the branches
  114. @list.delete(next_cmd)
  115.  
  116. # Now search for more
  117. search_more_choices
  118. end
  119.  
  120. #-----------------------------------------------------------------------------
  121. # New. Update the options for the first "show choice" command
  122. #-----------------------------------------------------------------------------
  123. def update_show_choices(params)
  124. params[0].each {|s| $game_message.choices.push(s) }
  125. end
  126.  
  127. #-----------------------------------------------------------------------------
  128. # New. If cancel specified, update it to reflect merged choice numbers
  129. # The last one is taken if multiple cancel choices are specified
  130. #-----------------------------------------------------------------------------
  131. def update_cancel_choice(params)
  132.  
  133. # disallow, just ignore
  134. return if params[1] == 0
  135.  
  136. # branch on cancel
  137. return update_branch_choice if params[1] == 5
  138.  
  139. # num_choices is not one-based
  140. cancel_choice = params[1] + (@num_choices - 1)
  141.  
  142. # update cancel choice, as well as the first choice command
  143. $game_message.choice_cancel_type = cancel_choice
  144. @first_choice_cmd.parameters[1] = cancel_choice
  145. end
  146.  
  147. #-----------------------------------------------------------------------------
  148. # New. Set the initial choice command to "branch cancel"
  149. #-----------------------------------------------------------------------------
  150. def update_branch_choice
  151. branch_choice = $game_message.choices.size + 1
  152. $game_message.choice_cancel_type = branch_choice
  153. $game_temp.branch_choice = branch_choice
  154. @first_choice_cmd.parameters[1] = branch_choice
  155. end
  156.  
  157. def command_403
  158. p $game_temp.branch_choice - 1
  159. command_skip if @branch[@indent] != $game_temp.branch_choice - 1
  160. end
  161.  
  162. #-----------------------------------------------------------------------------
  163. # New. For each branch, update it to reflect the merged choice numbers.
  164. #-----------------------------------------------------------------------------
  165. def update_choice_numbers
  166. i = @choice_search
  167. while Tsuki::Large_Choices::Code_Filter.include?(@list[i].code) || @list[i].indent != @indent
  168. if @list[i].code == 402
  169. @list[i].parameters[0] = @num_choices
  170. @num_choices += 1
  171. end
  172. i += 1
  173. end
  174. end
  175.  
  176. #-----------------------------------------------------------------------------
  177. # New. Returns the next command after our choice branches
  178. #-----------------------------------------------------------------------------
  179. def skip_choice_branches
  180. # start search at the next command
  181. # skip all choice branch-related commands and any branches
  182. while Tsuki::Large_Choices::Code_Filter.include?(@list[@choice_search].code) || @list[@choice_search].indent != @indent
  183. @choice_search += 1
  184. end
  185. return @choice_search
  186. end
  187. end
Advertisement
Add Comment
Please, Sign In to add comment