Advertisement
Zetu

RMDV 2

Jan 2nd, 2015
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.06 KB | None | 0 0
  1. #===============================================================================
  2. # Zetu Engine V: Choices Extention
  3. # by Zetu
  4. # --- Created: 12/30/2014
  5. # --- Updated: 01/06/2015 v1.02
  6. #-------------------------------------------------------------------------------
  7. # Instructions: Place special commands inside Display Choices.
  8. # [mode=?]
  9. # Option: H
  10. # Displays choices horizontally
  11. # Option: C
  12. # Centers choice display
  13. # Option: X
  14. # Shows no back window while displayed
  15. # Option: F
  16. # Fixes location of first selection
  17. # Option: U, Adds F, H, C
  18. # Centers options on item, rather than window
  19. # Option: R, Ignores H, U
  20. # Counts as X. Display choices in a circular fasion.
  21. # [img=?]
  22. # Displays an image with the specified filename as an option. Option: I
  23. # [switch=?]
  24. # Only shows if specified switch ID is ON.
  25. #-------------------------------------------------------------------------------
  26. # Changelog:
  27. # v1.01
  28. # * Fixed bug causing normal text to not adapt window size.
  29. # < Reported by ArbitraryGuy >
  30. # v1.02
  31. # + Added [icon=?]
  32. # + Added [switch=?]
  33. # + Added F mode option.
  34. # + Added U mode option.
  35. # + Added Feature to combine Choice Box Dialogs.
  36. #===============================================================================
  37.  
  38. class Window_Command < Window_Selectable
  39.  
  40. #=============================================================================
  41. # Create Objects
  42. #-----------------------------------------------------------------------------
  43. alias :zev_choice_add_command :add_command
  44. def add_command(name, symbol, enabled = true, ext = nil)
  45. command = name.dup
  46. if command =~ /\[mode\=(.+?)\]/i
  47. modes = $1.lstrip.rstrip.upcase
  48. modes.split(//).each do |m|
  49. @modes |= [m]
  50. case m
  51. when "U"
  52. @modes |= ["H", "C", "F"]
  53. end
  54. end
  55. command.gsub!(/\[mode\=.+?\]/i, "")
  56. end
  57. if name =~ /\[img\=(.+?)\]/i
  58. @modes |= ["I"]
  59. filename = $1.lstrip.rstrip
  60. width = Cache.system(filename).width
  61. height = Cache.system(filename).height
  62. @list.push({:name=>command, :symbol=>symbol, :enabled=>enabled, :ext=>ext,
  63. :zev_ext=>:image, :filename=>filename, :width=>width, :height=>height})
  64. else
  65. zev_choice_add_command(command, symbol, enabled, ext)
  66. end
  67. end
  68.  
  69. #=============================================================================
  70. # Clear
  71. #-----------------------------------------------------------------------------
  72. alias :zev_stabs_clear_command_list :clear_command_list
  73. def clear_command_list
  74. @modes = []
  75. zev_stabs_clear_command_list
  76. end
  77.  
  78. #=============================================================================
  79. # Conditions
  80. #-----------------------------------------------------------------------------
  81. def mode_include?(s)
  82. return false unless @modes
  83. return true if @modes.include?(s)
  84. return false
  85. end
  86.  
  87. end
  88.  
  89. class Window_ChoiceList < Window_Command
  90.  
  91. alias :zev_sbp_start :start
  92. def start
  93. zev_sbp_start
  94. update_placement
  95. select(0)
  96. end
  97.  
  98. #=============================================================================
  99. # Update
  100. #-----------------------------------------------------------------------------
  101. def update
  102. super
  103. update_xy(self.index)
  104. end
  105.  
  106. def update_placement
  107. update_size
  108. update_xy
  109. self.opacity = mode_include?("X") ? 0 : 255
  110. end
  111.  
  112. def update_size
  113. self.width = contents_width + padding * 2
  114. self.height = contents_height + padding * 2
  115. end
  116.  
  117. def update_xy(index = 0)
  118. self.x = Graphics.width - width
  119. if @message_window.y >= Graphics.height / 2
  120. self.y = @message_window.y - height
  121. else
  122. if mode_include?("C")
  123. self.y = Graphics.height + @message_window.y + @message_window.height - self.height
  124. else
  125. self.y = @message_window.y + @message_window.height
  126. end
  127. end
  128. if mode_include?("C")
  129. self.x /= 2
  130. self.y /= 2
  131. end
  132. if mode_include?("U")
  133. self.x = (Graphics.width - item_rect(index).width) / 2
  134. end
  135. if mode_include?("F")
  136. if mode_include?("H")
  137. self.x -= get_special_x(index)
  138. else
  139. self.y -= get_special_y(index)
  140. end
  141. end
  142. end
  143.  
  144. def update_padding_bottom
  145. if mode_include?("I")
  146. self.padding_bottom = 0
  147. else
  148. super
  149. end
  150. end
  151.  
  152. def ensure_cursor_visible
  153. unless mode_include?("R")
  154. super
  155. end
  156. end
  157.  
  158. #=============================================================================
  159. # Object Calls
  160. #-----------------------------------------------------------------------------
  161. def call_cancel_handler
  162. $game_message.choice_cancel_proc.call($game_message.choice_cancel_type - 1)
  163. close
  164. end
  165.  
  166. #=============================================================================
  167. # Conditions
  168. #-----------------------------------------------------------------------------
  169. def cancel_enabled?
  170. $game_message.choice_cancel_data != nil
  171. end
  172.  
  173. #=============================================================================
  174. # Reference Objects
  175. #-----------------------------------------------------------------------------
  176. def contents_width
  177. if mode_include?("H")
  178. return sp_global_width
  179. elsif mode_include?("R")
  180. return 3 * sp_item_width(24)
  181. else
  182. return sp_item_width
  183. end
  184. end
  185.  
  186. def contents_height
  187. if mode_include?("H")
  188. return sp_item_height
  189. elsif mode_include?("R")
  190. return 3 * sp_item_height(24)
  191. else
  192. return sp_global_height
  193. end
  194. end
  195.  
  196. def sp_text_size(string)
  197. return Rect.new(0,0,0,0) if string.nil?
  198. bitmap = Bitmap.new(1,1)
  199. w = 8
  200. string = string.gsub(/\\i\[\d+?\]/i) do |s|
  201. w += 24
  202. ""
  203. end
  204. string = string.gsub(/\[mode\=.+?\]/i, "")
  205. rect = bitmap.text_size(string)
  206. rect.width += w
  207. bitmap.dispose
  208. rect
  209. end
  210.  
  211. def sp_item_width(min = 96)
  212. @list.each.with_index.inject(0) { |sum, (hash,i)|
  213. [sum, (hash[:width] || [min, sp_text_size($game_message.choices[i]).width].max)].max
  214. }
  215. end
  216.  
  217. def sp_item_height(min = line_height)
  218. @list.inject(0) { |sum, hash|
  219. [sum, (hash[:height] || [min,line_height].max)].max
  220. } || 0
  221. end
  222.  
  223. def sp_global_width(min = 96)
  224. @list.each.with_index.inject(0) { |sum, (hash,i)|
  225. sum+(hash[:width]|| [min, sp_text_size($game_message.choices[i]).width].max)
  226. }
  227. end
  228.  
  229. def sp_global_height(min = line_height)
  230. @list.inject(0) { |sum, hash|
  231. sum + (hash[:height] || [min,line_height].max)
  232. } || 0
  233. end
  234.  
  235. def item_rect(index)
  236. data = @list[index]||{}
  237. rect = Rect.new
  238. if mode_include?("R")
  239. rect.width = sp_item_width(24)
  240. rect.height = sp_item_height(24)
  241. r = index.to_f / item_max
  242. r *= 2 * Math.acos(-1)
  243. rect.x = Math.cos(r) * sp_item_width(24) + self.contents.width / 2
  244. rect.x -= sp_item_width(24) / 2
  245. #rect.y = Math.sin(r) * line_height + sp_item_height(24)
  246. rect.y = Math.sin(r) * sp_item_height(24) + self.contents.height / 2
  247. rect.y -= sp_item_height(24) / 2
  248. elsif mode_include?("H")
  249. rect.width = data[:width] || 96
  250. rect.height = contents_height
  251. rect.x = get_special_x(index)
  252. rect.y = 0
  253. else
  254. rect.width = contents_width
  255. rect.height = data[:height] || item_height
  256. rect.x = 0
  257. rect.y = get_special_y(index)
  258. end
  259. rect
  260. end
  261.  
  262. def get_special_x(index)
  263. @list[0...index].inject(0) do |sum, hash|
  264. sum + (hash[:width] || 96)
  265. end || 0
  266. end
  267.  
  268. def get_special_y(index)
  269. @list[0...index].inject(0) do |sum, hash|
  270. sum + (hash[:height] || line_height)
  271. end || 0
  272. end
  273.  
  274. def col_max
  275. return @list.size if mode_include?("H")
  276. return super
  277. end
  278.  
  279. def row_max
  280. return 1 if mode_include?("H")
  281. return super
  282. end
  283.  
  284. def alignment
  285. return 1 if mode_include?("R")
  286. return 0
  287. end
  288.  
  289. #=============================================================================
  290. # Drawing
  291. #-----------------------------------------------------------------------------
  292.  
  293. alias :zev_choice_draw_item :draw_item
  294. def draw_item(index)
  295. data = @list[index]
  296. case data[:zev_ext]
  297. when nil
  298. zev_choice_draw_item(index)
  299. when :image
  300. bitmap = Cache.system(data[:filename])
  301. irect = item_rect(index)
  302. brect = Rect.new(0,0,data[:width],data[:height])
  303. contents.blt(irect.x, irect.y, bitmap, brect)
  304. end
  305. end
  306.  
  307. end
  308.  
  309. class Game_Message
  310. attr_accessor :choice_data
  311. attr_accessor :choice_cancel_data
  312. attr_accessor :choice_cancel_proc
  313. end
  314.  
  315. class Game_Interpreter
  316.  
  317. alias :zev_choice_clear :clear
  318. def clear
  319. zev_choice_clear
  320. @choice_skip = {}
  321. end
  322.  
  323. def add_zev_special_choice_data(ti)
  324. choice_data = {}
  325. @list[ti].parameters[0].each_with_index do |c, i|
  326. name = c.dup
  327. if name =~ /\[switch\=(\d+?)\]/i
  328. next unless $game_switches[$1.to_i]
  329. name.gsub!(/\[switch\=\d+?\]/i, "")
  330. end
  331. choice_data[i] = name
  332. end
  333. s_index = $game_message.choices.size
  334. skip = $game_message.choice_data.size
  335. choice_data.values.each {|s| $game_message.choices.push(s) }
  336. $game_message.choice_data << {
  337. :si => s_index,
  338. :skip => skip,
  339. :choice_data => choice_data.keys
  340. }
  341. if @list[ti].parameters[1] != 0
  342. $game_message.choice_cancel_data = {
  343. :skip => skip,
  344. :n => @list[ti].parameters[1] - 1
  345. }
  346. end
  347. end
  348.  
  349. alias :zev_choice_setup_choices :setup_choices
  350. def setup_choices(params)
  351. $game_message.choice_data = []
  352. $game_message.choice_cancel_data = nil
  353. add_zev_special_choice_data(@index)
  354. ti = @index
  355. while @list[ti] and @list[ti].code == 102
  356. ti += 1
  357. ti += 1 while @list[ti].indent > @indent or [402,403,404].include? @list[ti].code
  358. break if @list[ti].code != 102
  359. add_zev_special_choice_data(ti)
  360. end
  361. $game_message.choice_proc = Proc.new {|n|
  362. data = $game_message.choice_data.select do |h|
  363. h[:si] <= n
  364. end.max_by do |h|
  365. h[:si]
  366. end
  367. @choice_skip[@indent] = data[:skip]
  368. @branch[@indent] = data[:choice_data][n - data[:si]]
  369. }
  370. $game_message.choice_cancel_proc = Proc.new{|n|
  371. data = $game_message.choice_cancel_data
  372. @choice_skip[@indent] = data[:skip]
  373. @branch[@indent] = data[:n]
  374. }
  375. end
  376.  
  377. alias :zev_choice_command_102 :command_102
  378. def command_102
  379. return if @list[@index - 1].code == 404 if @list[@index - 1]
  380. zev_choice_command_102
  381. end
  382.  
  383. def command_402
  384. command_skip if @branch[@indent] != @params[0] or @choice_skip[@indent] != 0
  385. end
  386.  
  387. def command_403
  388. command_skip if @branch[@indent] != 4 or @choice_skip[@indent] != 0
  389. end
  390.  
  391. def command_404
  392. @choice_skip[@indent] -= 1 if @choice_skip[@indent]
  393. end
  394.  
  395. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement