Advertisement
dsiver144

DSI Custom Choices

Mar 13th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. #==============================================================================
  2. # DSI Custom Choices
  3. # -- Last Updated: 2017.03.13
  4. # -- Author: dsiver144
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. # -- Conmission for: The007who
  8. #==============================================================================
  9. $imported = {} if $imported.nil?
  10. $imported["DSI-CustomChoices"] = true
  11. #==============================================================================
  12. # + Updates
  13. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  14. # 2017.03.12 - Finish first version.
  15. #==============================================================================
  16. # + Instructions
  17. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  18. # To install this script, open up your script editor and copy/paste this script
  19. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  20. # Put this below "Sixth Menu Add Ons"! <- IMPORTANT!
  21. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. # Script Call: None
  23. #==============================================================================
  24. module DSIVER144
  25. module AUTOMATIC_CHOICE
  26. TOGGLE_SWITCH = 15 # Turn on this switch will activate script.
  27. DEFAULT_CHOICE_WAIT_TIME = 60*3 # 3 Seconds. Don't change this.
  28. RESET_CHOICE_WAIT_TIME = true # Auto set wait time to default each time
  29. # using Show Choice Command.
  30. #--------------------------------------------------------------------------
  31. # * new method: automatic?
  32. #--------------------------------------------------------------------------
  33. def self.automatic?
  34. return $game_switches[TOGGLE_SWITCH] == true
  35. end
  36. end # AUTOMATIC_CHOICE
  37. end # DSIVER144
  38.  
  39. class Window_Message
  40. include DSIVER144
  41. #--------------------------------------------------------------------------
  42. # * Choice Input Processing
  43. #--------------------------------------------------------------------------
  44. alias_method(:dsi_input_choice_automatic, :input_choice)
  45. def input_choice
  46. $limit_time = 0 if AUTOMATIC_CHOICE.automatic?
  47. dsi_input_choice_automatic
  48. end
  49. end # Window_Message
  50.  
  51. #==============================================================================
  52. # ** Window_ChoiceList
  53. #------------------------------------------------------------------------------
  54. # This window is used for the event command [Show Choices].
  55. #==============================================================================
  56.  
  57. class Window_ChoiceList < Window_Command
  58. include DSIVER144
  59. alias_method(:dsi_start_choice_list, :start)
  60. #--------------------------------------------------------------------------
  61. # * Start Input Processing
  62. #--------------------------------------------------------------------------
  63. def start
  64. if AUTOMATIC_CHOICE.automatic?
  65. self.opacity = 0
  66. self.contents_opacity = 0
  67. update_placement
  68. refresh
  69. select(0)
  70. open
  71. activate
  72. else
  73. self.opacity = 255
  74. self.contents_opacity = 255
  75. dsi_start_choice_list
  76. end
  77. end
  78. #--------------------------------------------------------------------------
  79. # * method: update
  80. #--------------------------------------------------------------------------
  81. alias_method(:dsi_update_autmatic, :update)
  82. def update
  83. dsi_update_autmatic
  84. @cursor_sprite.y = @cursor_baseY + self.index*@cursor_distance if @cursor_sprite && @begin_count
  85. if $limit_time && $limit_time < ($game_system.choiceWaitTime ? $game_system.choiceWaitTime : AUTOMATIC_CHOICE::DEFAULT_CHOICE_WAIT_TIME) && @begin_count
  86. $limit_time += 1
  87. if @timer_sprite
  88. sec = $limit_time / 60 % 60
  89. @timer_sprite.bitmap = Cache.system("timer#{sec}") if sec < 3
  90. end
  91. elsif $limit_time && @begin_count
  92. select(0)
  93. @cursor_sprite.y = @cursor_baseY + 0*@cursor_distance if @cursor_sprite
  94. process_ok
  95. $limit_time = nil
  96. @begin_count = nil
  97. $game_system.choiceWaitTime = nil if AUTOMATIC_CHOICE::RESET_CHOICE_WAIT_TIME
  98. end
  99. end
  100. #--------------------------------------------------------------------------
  101. # * alias method: update_placement
  102. #--------------------------------------------------------------------------
  103. alias_method(:dsi_update_placement_choice, :update_placement)
  104. def update_placement
  105. dsi_update_placement_choice
  106. return unless AUTOMATIC_CHOICE.automatic?
  107. @choice_sprites ||= []
  108. @choice_sprites.each do |sprite|
  109. sprite.dispose
  110. end
  111. @choice_sprites.clear
  112. choice_bitmap = Cache.system("Choice")
  113. distance = 48
  114. start_y = ((Graphics.height - (choice_bitmap.height)*$game_message.choices.size)) * 0.5 - 40
  115. @cursor_baseY = start_y
  116. @cursor_distance = distance
  117. des_x = (Graphics.width - choice_bitmap.width) * 0.5
  118. $game_message.choices.each_with_index do |choice,i|
  119. c_sprite = Sprite.new
  120. c_sprite.x = i % 2 == 0 ? -choice_bitmap.width : Graphics.width
  121. c_sprite.start_x = c_sprite.x
  122. c_sprite.change_x = des_x - c_sprite.start_x
  123. c_sprite.y = start_y + i*distance
  124. c_sprite.bitmap = choice_bitmap.clone
  125. c_sprite.bitmap.draw_text(0,0,choice_bitmap.width,choice_bitmap.height,choice,1)
  126. @choice_sprites << c_sprite
  127. end
  128. @cursor_sprite = Sprite.new
  129. @cursor_sprite.bitmap = Cache.system("Cursor")
  130. @cursor_sprite.x = des_x
  131. @cursor_sprite.y = @cursor_baseY
  132. @cursor_sprite.z = 100
  133. @cursor_sprite.opacity = 0
  134. @timer_sprite = Sprite.new
  135. @timer_sprite.bitmap = Cache.system("timer0")
  136. @timer_sprite.x = -50
  137. @timer_sprite.y = 0
  138. @timer_sprite.opacity = 0
  139. start_time = Graphics.frame_count
  140. while (current_time = Graphics.frame_count - start_time ) < 45
  141. @choice_sprites.each do |sprite|
  142. sprite.x = easeInOutQuad(current_time, sprite.start_x, sprite.change_x, 45)
  143. @cursor_sprite.opacity = easeInOutQuad(current_time, 0, 255, 45)
  144. @timer_sprite.x = easeInOutQuad(current_time, -50, 50, 45)
  145. @timer_sprite.opacity = easeInOutQuad(current_time, 0, 255, 45)
  146. end
  147. Fiber.yield
  148. end
  149. @choice_sprites.each_with_index do |sprite,i|
  150. sprite.start_x = sprite.x
  151. des_x = i % 2 == 0 ? Graphics.width : -choice_bitmap.width
  152. sprite.change_x = des_x - sprite.start_x
  153. end
  154. @begin_count = true
  155. end
  156. #-------------------------------------------------------------------------
  157. # * new method: easeInOutQuad
  158. #-------------------------------------------------------------------------
  159. def easeInOutQuad(t, b, c, d)
  160. t = t / (d/2.0)
  161. if (t < 1)
  162. return c/2*t*t + b
  163. end
  164. t -= 1
  165. return -c/2.0 * (t*(t-2) - 1) + b
  166. end
  167. #--------------------------------------------------------------------------
  168. # * Call OK Handler
  169. #--------------------------------------------------------------------------
  170. def call_ok_handler
  171. $limit_time = nil
  172. @begin_count = nil
  173. $game_system.choiceWaitTime = nil if AUTOMATIC_CHOICE::RESET_CHOICE_WAIT_TIME
  174. $game_message.choice_proc.call(index)
  175. update_move_choice
  176. close
  177. end
  178. #--------------------------------------------------------------------------
  179. # * Call Cancel Handler
  180. #--------------------------------------------------------------------------
  181. def call_cancel_handler
  182. $limit_time = nil
  183. @begin_count = nil
  184. $game_system.choiceWaitTime = nil if AUTOMATIC_CHOICE::RESET_CHOICE_WAIT_TIME
  185. $game_message.choice_proc.call($game_message.choice_cancel_type - 1)
  186. update_move_choice
  187. close
  188. end
  189. #--------------------------------------------------------------------------
  190. # * new method: dispose_choice_sprites
  191. #--------------------------------------------------------------------------
  192. def dispose_choice_sprites
  193. return if @choice_sprites.size > 0
  194. @choice_sprites.each do |sprite|
  195. sprite.bitmap.dispose
  196. sprite.dispose
  197. end
  198. @timer_sprite.bitmap.dispose
  199. @timer_sprite.dispose
  200. @timer_sprite = nil
  201. @cursor_sprite.bitmap.dispose
  202. @cursor_sprite.dispose
  203. @cursor_sprite = nil
  204. @choice_sprites.clear
  205. @choice_sprites = nil
  206. end
  207. #--------------------------------------------------------------------------
  208. # * new method: update_move_choice
  209. #--------------------------------------------------------------------------
  210. def update_move_choice
  211. return unless AUTOMATIC_CHOICE.automatic?
  212. start_time = Graphics.frame_count
  213. while (current_time = Graphics.frame_count - start_time ) < 45
  214. @choice_sprites.each do |sprite|
  215. sprite.x = easeInOutQuad(current_time, sprite.start_x, sprite.change_x, 45)
  216. @cursor_sprite.opacity = easeInOutQuad(current_time, 255, -255, 45)
  217. @timer_sprite.x = easeInOutQuad(current_time, 0, -50, 45)
  218. @timer_sprite.opacity = easeInOutQuad(current_time, 255, -255, 45)
  219. end
  220. Graphics.update
  221. end
  222. dispose_choice_sprites
  223. end
  224. end # Window_ChoiceList
  225.  
  226. class Game_Interpreter
  227. #--------------------------------------------------------------------------
  228. # * new method: setChoiceWaitTime
  229. #--------------------------------------------------------------------------
  230. def setChoiceWaitTime(wait_time)
  231. $game_system.choiceWaitTime = wait_time
  232. end
  233. end
  234.  
  235. class Game_System
  236. attr_accessor :choiceWaitTime
  237. end # Game_System
  238.  
  239. class Sprite
  240. attr_accessor :start_x
  241. attr_accessor :change_x
  242. end # Sprite
  243. #===============================================================================
  244. # * END OF FILE
  245. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement