pigu_6

Galv|Visual Novel Choice 1.8

Dec 13th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.23 KB | None | 0 0
  1. #------------------------------------------------------------------------------#
  2. # Galv's Visual Novel Choices
  3. #------------------------------------------------------------------------------#
  4. # For: RPGMAKER VX ACE
  5. # Version 1.8
  6. #------------------------------------------------------------------------------#
  7. # 2012-11-28 - Version 1.8 - Z level setting added
  8. # 2012-11-28 - Version 1.7 - Added compatability for some cursor scripts
  9. # 2012-11-28 - Version 1.6 - Fixed a bug that could crash the game.
  10. # 2012-11-28 - Version 1.5 - Added offset to change postion of cursor x and y
  11. # 2012-11-28 - Version 1.4 - Fixed z levels and made cursor use an image
  12. # 2012-11-27 - Version 1.3 - Fixed a bug with cancel choice selection
  13. # 2012-11-27 - Version 1.2 - added a switch to disable script effects
  14. # 2012-11-27 - Version 1.1 - added ability to use different image per choice
  15. # - added a couple more options
  16. # 2012-11-27 - Version 1.0 - release
  17. #------------------------------------------------------------------------------#
  18. # This script overwrites the default "Show Choices" list. The choices are
  19. # changed so they display centered on the screen with a graphic behind each
  20. # of them. Made with visual novel choice selection in mind.
  21. #------------------------------------------------------------------------------#
  22. # INSTRUCTIONS:
  23. # Copy the graphic from the demo /Graphics/System into your project.
  24. # Copy the script into your script list, below Materials and above Main
  25. #
  26. # Some setup options below, most only need to be changed if you use your own
  27. # custom choice image.
  28. #------------------------------------------------------------------------------#
  29. # Codes:
  30. #------------------------------------------------------------------------------#
  31. # Most of the usual codes that work in messages should work in choices.
  32. # (eg. \V[x], \N[x], \C[x], etc. Look at message tooltip to know more.)
  33. #
  34. # A new one has been added so you can change the background image for separate
  35. # choice options.
  36. #
  37. # \B[x]
  38. #
  39. # This works by adding the number x (as you put in the code above) to the end
  40. # of the CHOICE IMAGE file name. For example, the default choice image is:
  41. # "Choice.png" located in /Graphics/System/. If you put the code anywhere in
  42. # a choice box: \B[3] it will look for "Choice3.png" image in the same
  43. # location.
  44. #------------------------------------------------------------------------------#
  45.  
  46. ($imported ||= {})["Galvs_Image_Choices"] = true
  47. module Galv_Choice
  48.  
  49. #------------------------------------------------------------------------------#
  50. # SCRIPT SETUP OPTIONS
  51. #------------------------------------------------------------------------------#
  52.  
  53. CURSOR_IMAGE = "Cursor" # Images used to determine which option you select
  54. CURSOR_OPACITY = 255 # Opacity of the cursor
  55. CURSOR_Y_OFFSET = 0 # Nudge cursor position vertically
  56. CURSOR_X_OFFSET = 0 # Nudge cursor position horizontally
  57.  
  58. CHOICE_IMAGE = "Choice" # Image for each choice located in /Graphics/System
  59. IMAGE_Y_OFFSET = 3 # Nudge your choice image vertically if needed
  60. IMAGE_OPACITY = 215 # The opacity of the image
  61.  
  62. CHOICE_HEIGHT = 45 # How tall each choice.
  63. CHOICE_ITEM_Y = 2 # Offset for choice item text
  64.  
  65. CENTER_TEXT = true # left aligned if false, centered if true
  66.  
  67. DISABLE_SWITCH = 1 # Turn this switch ON to disable this script
  68.  
  69. CHOICES_Z = 50 # The z value of the choices window. Try changing it
  70. # if pictures or other scripts are appear over or
  71. # under the choices window to how you like.
  72.  
  73. #------------------------------------------------------------------------------#
  74. OTHER_Y_OFFSET = 12 # May fix other cursor scripts positioning
  75. #------------------------------------------------------------------------------#
  76. # SCRIPT SETUP OPTIONS
  77. #------------------------------------------------------------------------------#
  78.  
  79. end
  80.  
  81. class Window_ChoiceList < Window_Command
  82.  
  83. alias galv_choice_initialize initialize
  84. def initialize(message_window)
  85. galv_choice_initialize(message_window)
  86. self.z = Galv_Choice::CHOICES_Z
  87. end
  88.  
  89. def start
  90. @index = 0
  91. setup_choices
  92. make_cursor
  93. refresh
  94. open
  95. activate
  96. update_placement
  97. update_bgs
  98. refresh
  99. select(0)
  100. end
  101.  
  102. def make_cursor
  103. return if $game_switches[Galv_Choice::DISABLE_SWITCH]
  104. @cursor_sprite = Sprite.new
  105. @cursor_sprite.bitmap = Cache.system(Galv_Choice::CURSOR_IMAGE)
  106. end
  107.  
  108. def setup_choices
  109. @choice_sprite = []
  110. if !$game_switches[Galv_Choice::DISABLE_SWITCH]
  111. self.opacity = 0
  112. get_widths
  113. else
  114. self.opacity = 255
  115. end
  116. end
  117.  
  118. alias galv_choice_update_placement update_placement
  119. def update_placement
  120. if $game_switches[Galv_Choice::DISABLE_SWITCH]
  121. galv_choice_update_placement
  122. else
  123. self.width = [max_choice_width + 12, 96].max + padding * 4
  124. self.width = [width, Graphics.width].min
  125. self.height = contents_height + Galv_Choice::CHOICE_HEIGHT - 10
  126. self.x = (Graphics.width - width) / 2
  127.  
  128. if @message_window.openness < 100
  129. self.y = Graphics.height - contents_height + item_height / 2
  130.  
  131. elsif @message_window.y >= Graphics.height / 2
  132. self.y = @message_window.y - contents_height + item_height / 2
  133. else
  134. self.y = @message_window.y + @message_window.height + item_height / 2
  135. end
  136. end
  137. end
  138.  
  139. alias galv_choice_contents_height contents_height
  140. def contents_height
  141. if $game_switches[Galv_Choice::DISABLE_SWITCH]
  142. galv_choice_contents_height
  143. else
  144. (item_max + 1) * item_height
  145. end
  146. end
  147.  
  148. def draw_item(index)
  149. rect = item_rect_for_text(index)
  150. draw_text_ex(rect.x, rect.y, command_name(index))
  151. if !$game_switches[Galv_Choice::DISABLE_SWITCH]
  152. draw_bgs(index)
  153. end
  154. end
  155.  
  156. def item_rect_for_text(index)
  157. rect = item_rect(index)
  158.  
  159. if $game_switches[Galv_Choice::DISABLE_SWITCH]
  160. rect.x += 4
  161. rect.width -= 8
  162. rect
  163. else
  164. if Galv_Choice::CENTER_TEXT
  165. rect.x = (max_choice_width - @text_sizes.collect {|s| text_size(s).width }[index] + (padding * 3)) / 2
  166. else
  167. rect.x += 4
  168. end
  169. rect.width -= 8
  170. rect.y += Galv_Choice::CHOICE_ITEM_Y
  171. rect
  172. end
  173. end
  174.  
  175. def get_widths
  176. @text_sizes = []
  177. @choice_background = []
  178. $game_message.choices.each_with_index do |c,i|
  179. @text_sizes[i] = esc_characters(c,i)
  180. end
  181. end
  182.  
  183. def esc_characters(text,index)
  184. result = text.to_s.clone
  185. result.gsub!(/\\/) { "\e" }
  186. result.gsub!(/\e\e/) { "\\" }
  187. result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  188. result.gsub!(/\eN\[(\d+)\]/i) { $game_actors[$1.to_i].name}
  189. result.gsub!(/\eP\[(\d+)\]/i) {
  190. if $game_party.members[$1.to_i].nil?
  191. ""
  192. else
  193. $game_party.members[$1.to_i].name
  194. end
  195. }
  196. result.gsub!(/\eG/i) { Vocab::currency_unit }
  197. result.gsub!(/\eC\[(\d+)\]/i) { "" }
  198. result.gsub!(/\eI\[(\d+)\]/i) { " " }
  199. result.gsub!(/\eB\[(\d+)\]/i) { @choice_background[index] = $1.to_i }
  200. result.gsub!(/\eB\[(\d+)\]/i) { "" }
  201. result
  202. end
  203.  
  204. def convert_escape_characters(text)
  205. result = text.to_s.clone
  206. result.gsub!(/\\/) { "\e" }
  207. result.gsub!(/\e\e/) { "\\" }
  208. result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  209. result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  210. result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
  211. result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  212. result.gsub!(/\eG/i) { Vocab::currency_unit }
  213. result.gsub!(/\eB\[(\d+)\]/i) { "" }
  214. result
  215. end
  216.  
  217. def item_height
  218. return line_height if $game_switches[Galv_Choice::DISABLE_SWITCH]
  219. return Galv_Choice::CHOICE_HEIGHT
  220. end
  221.  
  222. def item_rect(index)
  223. rect = Rect.new
  224. rect.width = item_width
  225. rect.height = item_height - 15
  226. rect.height += 15 if $game_switches[Galv_Choice::DISABLE_SWITCH]
  227. rect.x = index % col_max * (item_width + spacing)
  228. rect.y = index / col_max * item_height
  229. rect
  230. end
  231.  
  232. def draw_bgs(index)
  233. return if @choice_sprite[index] != nil
  234.  
  235. if @choice_background[index].nil?
  236. b = ""
  237. else
  238. b = @choice_background[index]
  239. end
  240. @choice_sprite[index] = Sprite.new
  241. @choice_sprite[index].bitmap = Cache.system(Galv_Choice::CHOICE_IMAGE + b.to_s)
  242. @choice_sprite[index].x = index % col_max * (item_width + spacing)
  243. @choice_sprite[index].y = index / col_max * item_height
  244. @choice_sprite[index].z = self.z - 2
  245. end
  246.  
  247. def update_bgs
  248. @choice_sprite.each_with_index do |s,i|
  249. s.y = self.y + i * Galv_Choice::CHOICE_HEIGHT + Galv_Choice::IMAGE_Y_OFFSET
  250. s.x = (Graphics.width - s.width) / 2
  251. s.opacity = Galv_Choice::IMAGE_OPACITY
  252. end
  253. end
  254.  
  255. def dispose_bgs
  256. @choice_sprite.each_with_index do |s,i|
  257. s.dispose
  258. s.bitmap.dispose
  259. end
  260. if !$game_switches[Galv_Choice::DISABLE_SWITCH]
  261. @cursor_sprite.dispose
  262. @cursor_sprite.bitmap.dispose
  263. @choice_sprite = []
  264. end
  265. end
  266.  
  267. alias galv_choice_call_ok_handler call_ok_handler
  268. def call_ok_handler
  269. galv_choice_call_ok_handler
  270. dispose_bgs
  271. end
  272. alias galv_choice_call_cancel_handler call_cancel_handler
  273. def call_cancel_handler
  274. galv_choice_call_cancel_handler
  275. dispose_bgs
  276. end
  277.  
  278. def update_cursor
  279. if $game_switches[Galv_Choice::DISABLE_SWITCH]
  280. super
  281. else
  282. cursor_rect.empty
  283. return if @cursor_sprite.nil? || @choice_sprite.nil?
  284. if @index < 0
  285. @cursor_sprite.opacity = 0
  286. else
  287. @cursor_sprite.opacity = Galv_Choice::CURSOR_OPACITY
  288. @cursor_sprite.x = @choice_sprite[@index].x + Galv_Choice::CURSOR_X_OFFSET
  289. @cursor_sprite.y = @choice_sprite[@index].y + Galv_Choice::CURSOR_Y_OFFSET
  290. @cursor_sprite.z = self.z - 1
  291. cursor_rect.y = (item_height * @index) + Galv_Choice::OTHER_Y_OFFSET
  292. end
  293. end
  294. end
  295.  
  296. end # Window_ChoiceList < Window_Command
Advertisement
Add Comment
Please, Sign In to add comment