Advertisement
Vlue

Special Window Effects

Jul 24th, 2014
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.75 KB | None | 0 0
  1. #Special Window Effects v1.0
  2. #----------#
  3. #Features: Special Window Effects for when a scene (usually a menu) opens and
  4. #            closes
  5. #
  6. #Usage:    Plug and play, customize as needed
  7. #      
  8. #
  9. #----------#
  10. #-- Script by: V.M of D.T
  11. #
  12. #- Questions or comments can be:
  13. #    given by email: sumptuaryspade@live.ca
  14. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  15. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  16. #
  17. #- Free to use in any project with credit given, donations always welcome!
  18.  
  19. #Style options are: :none, :fade, :slide, :book, :book_oat
  20. #Style to be used when scene opens:
  21. WEFF_OPEN_STYLE = :book_oat
  22. #Style to be used when scene closes:
  23. WEFF_CLOSE_STYLE = :book_oat
  24. #Speed of fade and slide styles in frames:
  25. WEFF_SPEED = 15
  26.  
  27. class Scene_Base
  28.   alias menustyle_post_start post_start
  29.   def post_start
  30.     prepare_open_style
  31.     menustyle_post_start
  32.     start_open_style
  33.   end
  34.   def pre_terminate
  35.     prepare_close_style
  36.     start_close_style
  37.   end
  38.   def prepare_open_style
  39.     instance_variables.each do |varname|
  40.       ivar = instance_variable_get(varname)
  41.       if ivar.is_a?(Window)
  42.         ivar.prepare_open if WEFF_OPEN_STYLE == :book
  43.         ivar.prepare_open if WEFF_OPEN_STYLE == :book_oat
  44.         ivar.contents_opacity = 0 if WEFF_OPEN_STYLE == :fade
  45.         ivar.prepare_slide_in if WEFF_OPEN_STYLE == :slide
  46.       end
  47.     end
  48.   end
  49.   def start_open_style
  50.     return open_fade_style if WEFF_OPEN_STYLE == :fade
  51.     return open_slide_style if WEFF_OPEN_STYLE == :slide
  52.     instance_variables.each do |varname|
  53.       ivar = instance_variable_get(varname)
  54.       if ivar.is_a?(Window)
  55.         ivar.set_open if WEFF_OPEN_STYLE == :book
  56.         if WEFF_OPEN_STYLE == :book_oat
  57.           if ivar.set_open
  58.             6.times do |i|
  59.               ivar.update_open
  60.               Graphics.update
  61.             end
  62.           end
  63.         end
  64.       end
  65.     end
  66.   end
  67.   def open_fade_style
  68.     timer = 255/WEFF_SPEED
  69.     windows = instance_variables.select {|varname| instance_variable_get(varname).is_a?(Window) }
  70.     windows = windows.collect {|symbol| instance_variable_get(symbol)}
  71.     timer.times do |i|
  72.       windows.each do |window|
  73.         window.contents_opacity += WEFF_SPEED
  74.       end
  75.       Graphics.update
  76.     end
  77.   end
  78.   def open_slide_style
  79.     windows = instance_variables.select {|varname| instance_variable_get(varname).is_a?(Window) }
  80.     windows = windows.collect {|symbol| instance_variable_get(symbol)}
  81.     (WEFF_SPEED+1).times do |i|
  82.       windows.each do |window|
  83.         window.update_slide
  84.       end
  85.       Graphics.update
  86.     end
  87.     windows.each {|window| window.finish_slide }
  88.   end
  89.   def start_close_style
  90.     return close_fade_style if WEFF_CLOSE_STYLE == :fade
  91.     return open_slide_style if WEFF_CLOSE_STYLE == :slide
  92.     instance_variables.each do |varname|
  93.       ivar = instance_variable_get(varname)
  94.       if ivar.is_a?(Window)
  95.         ivar.close if WEFF_CLOSE_STYLE == :book
  96.         if WEFF_CLOSE_STYLE == :book_oat
  97.           if ivar.set_open
  98.             ivar.close
  99.             6.times do |i|
  100.               ivar.update_close
  101.               Graphics.update
  102.             end
  103.           end
  104.         end
  105.       end
  106.     end
  107.   end
  108.   def prepare_close_style
  109.     if WEFF_OPEN_STYLE == :slide
  110.       instance_variables.each do |varname|
  111.         ivar = instance_variable_get(varname)
  112.         if ivar.is_a?(Window)
  113.           ivar.prepare_slide_out if WEFF_OPEN_STYLE == :slide
  114.         end
  115.       end
  116.     end
  117.   end
  118.   def close_fade_style
  119.     timer = 255/WEFF_SPEED
  120.     windows = instance_variables.select {|varname| instance_variable_get(varname).is_a?(Window) }
  121.     windows = windows.collect {|symbol| instance_variable_get(symbol)}
  122.     timer.times do |i|
  123.       windows.each do |window|
  124.         window.contents_opacity -= WEFF_SPEED
  125.       end
  126.       Graphics.update
  127.     end
  128.   end
  129. end
  130.  
  131. class Window_Base
  132.   def prepare_open
  133.     if self.openness > 0 && self.visible
  134.       self.openness = 0
  135.       @set_to_open = true
  136.     end
  137.   end
  138.   def set_open
  139.     open if @set_to_open
  140.     @set_to_open
  141.   end
  142.   def prepare_slide_in
  143.     @target_x = @target_y = nil
  144.     if self.height > self.width
  145.       @target_x = self.x
  146.       if self.x < Graphics.width / 2
  147.         self.x = 0 - self.width
  148.         @slide_speed = (@target_x - self.x) / WEFF_SPEED
  149.       else
  150.         self.x = Graphics.width
  151.         @slide_speed = (self.x - @target_x) / WEFF_SPEED
  152.       end
  153.     else
  154.       @target_y = self.y
  155.       if self.y < Graphics.height / 2
  156.         self.y = 0 - self.height
  157.         @slide_speed = (@target_y - self.y) / WEFF_SPEED
  158.       else
  159.         self.y = Graphics.height
  160.         @slide_speed = (self.y - @target_y) / WEFF_SPEED
  161.       end
  162.     end
  163.   end
  164.   def prepare_slide_out
  165.     @target_x = @target_y = nil
  166.     if self.height > self.width
  167.       if self.x < Graphics.width / 2
  168.         @target_x = 0 - self.width
  169.         @slide_speed = (self.x - @target_x) / WEFF_SPEED
  170.       else
  171.         @target_x = Graphics.width
  172.         @slide_speed = (@target_x - self.x)  / WEFF_SPEED
  173.       end
  174.     else
  175.       if self.y < Graphics.height / 2
  176.         @target_y = 0 - self.height
  177.         @slide_speed = (self.y - @target_y) / WEFF_SPEED
  178.       else
  179.         @target_y = Graphics.height
  180.         @slide_speed = (@target_y - self.x) / WEFF_SPEED
  181.       end
  182.     end
  183.   end
  184.   def update_slide
  185.     if @target_x
  186.       self.x += @slide_speed if self.x < @target_x
  187.       self.x -= @slide_speed if self.x > @target_x
  188.     elsif @target_y
  189.       self.y += @slide_speed if self.y < @target_y
  190.       self.y -= @slide_speed if self.y > @target_y
  191.     end
  192.   end
  193.   def finish_slide
  194.     self.x = @target_x if @target_x
  195.     self.y = @target_y if @target_y
  196.   end
  197. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement