Advertisement
Holy87

Smooth Menu Transition

Feb 27th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.29 KB | None | 0 0
  1. =begin
  2.  ==============================================================================
  3.   ■ Transizioni del menu di Holy87
  4.       versione 1.01
  5.       Difficoltà utente: ★
  6.       Licenza: CC. Chiunque può scaricare, modificare, distribuire e utilizzare
  7.       lo script nei propri progetti, sia amatoriali che commerciali. Vietata
  8.       l'attribuzione impropria.
  9.  ==============================================================================
  10.     Questo script mostra delle animazioni di transizione dei menu, spostando
  11.     le finestre dall'esterno dello schermo alla loro posizione e viceversa. È
  12.     studiato per essere compatibile il più possibile anche con gli script di
  13.     terzi.
  14.  ==============================================================================
  15.   ■ Compatibilità
  16.     * Nessun alias e/o override
  17.  ==============================================================================
  18.   ■ Installazione
  19.     Installare questo script sotto Materials e prima del Main. Configurare le
  20.     opzioni di base in basso se si vuole personalizzare ulteriormente lo script.
  21. =end
  22. #==============================================================================
  23. # ** IMPOSTAZIONI
  24. #------------------------------------------------------------------------------
  25. #  Puoi modificare le preferenze dello script in queste due righe.
  26. #==============================================================================
  27. module TRANSITION_SETTINGS
  28.   #--------------------------------------------------------------------------
  29.   # * Inserisci nell'array le scene in cui non vuoi l'animazione.
  30.   #--------------------------------------------------------------------------
  31.   Excluded_Scenes = [Scene_File, Scene_End]
  32.   #--------------------------------------------------------------------------
  33.   # * Imposta la velocità predefinita di animazione (da 1 a 5)
  34.   #--------------------------------------------------------------------------
  35.   SPEED = 3 #1: lentissimo, 2: lento, 3: medio, 4: veloce, 5: velocissimo
  36. #==============================================================================
  37. # ** FINE CONFIGURAZIONE
  38. #------------------------------------------------------------------------------
  39. #                 - ATTENZIONE: NON MODIFICARE OLTRE! -
  40. #==============================================================================
  41. end
  42.  
  43. $imported = {} if $imported == nil
  44. $imported["H87_SmoothMenuTransition"] = 1.01
  45. #==============================================================================
  46. # ** Classe Window_Base
  47. #------------------------------------------------------------------------------
  48. #  Inclusione del modulo smooth_movement
  49. #==============================================================================
  50. class Window_Base < Window
  51.   #--------------------------------------------------------------------------
  52.   # * Prepara l'oggetto alla transizione in entrata
  53.   #--------------------------------------------------------------------------
  54.   def hide_position(speed = move_speed)
  55.     nx = self.x
  56.     ny = self.y
  57.     if must_move?
  58.       if (xy_movement && moveby_x) || (!xy_movement && attached_lateral?)
  59.         if self.x <= 0
  60.           nx = 0
  61.           self.x = 0 - self.width
  62.           move = true
  63.         elsif self.x >= Graphics.width - self.width
  64.           nx = Graphics.width - self.width
  65.           self.x = Graphics.width
  66.           move = true
  67.         end
  68.       else
  69.         if self.y <= 0
  70.           ny = 0
  71.           self.y = 0 - self.height
  72.           move = true
  73.         elsif self.y >= Graphics.height - self.height
  74.           ny = Graphics.height - self.height
  75.           self.y = Graphics.height
  76.           move = true
  77.         end
  78.       end
  79.       smooth_move(nx, ny, speed) if move
  80.     end
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # * Prepara l'oggetto alla transizione in uscita
  84.   #--------------------------------------------------------------------------
  85.   def exit_from_screen(speed = move_speed)
  86.     move = false
  87.     nx = self.x
  88.     ny = self.y
  89.     if must_move?
  90.       if (xy_movement && moveby_x) || (!xy_movement && attached_lateral?)
  91.         if self.x <= 0
  92.           nx = 0 - self.width
  93.           move = true
  94.         elsif self.x >= Graphics.width - self.width
  95.           nx = Graphics.width
  96.           move = true
  97.         end
  98.       else
  99.         if self.y <= 0
  100.           ny = 0 - self.height
  101.           move = true
  102.         elsif self.y >= Graphics.height - self.height
  103.           ny = Graphics.height
  104.           move = true
  105.         end
  106.       end
  107.       smooth_move(nx, ny, speed) if move
  108.     end
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Restituisce true se l'oggetto è attaccato su un angolo
  112.   #--------------------------------------------------------------------------
  113.   def xy_movement
  114.     return attached_lateral? && attached_up_bott?
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * Restituisce true se l'oggetto è attaccato ad un lato dello schermo
  118.   #--------------------------------------------------------------------------
  119.   def must_move?
  120.     return attached_lateral? || attached_up_bott?
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Restituisce true se l'oggetto è attaccato ai lati dx e sx dello schermo
  124.   #--------------------------------------------------------------------------
  125.   def attached_lateral?
  126.     return self.x <= 0 || self.x >= Graphics.width - self.width
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Restituisce true se l'oggetto è attaccato sopra o sotto lo schermo
  130.   #--------------------------------------------------------------------------
  131.   def attached_up_bott?
  132.     return self.y <= 0 || self.y >= Graphics.height - self.height
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # * Restituisce true se l'oggetto si deve muovere in orizontale, false se
  136.   #   in verticale
  137.   #--------------------------------------------------------------------------
  138.   def moveby_x
  139.     return self.height >= self.width
  140.   end
  141. end
  142.  
  143. #==============================================================================
  144. # ** Classe Scene_MenuBase
  145. #------------------------------------------------------------------------------
  146. #  Imposta le animazioni di entrata ed uscita delle finestre
  147. #==============================================================================
  148. class Scene_MenuBase < Scene_Base
  149.   #--------------------------------------------------------------------------
  150.   # * Metodo post_start
  151.   #--------------------------------------------------------------------------
  152.   def post_start
  153.     alter_window_position unless excluded_scene?
  154.     super
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # * Prepara le finestre alla transizione in entrata
  158.   #--------------------------------------------------------------------------
  159.   def alter_window_position
  160.     instance_variables.each do |varname|
  161.       ivar = instance_variable_get(varname)
  162.       ivar.hide_position(get_transition_speed) if ivar.is_a?(Window)
  163.     end
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # * Prepara le finestre alla transizione in uscita
  167.   #--------------------------------------------------------------------------
  168.   def hide_windows_for_transition
  169.     instance_variables.each do |varname|
  170.       ivar = instance_variable_get(varname)
  171.       ivar.exit_from_screen(get_transition_speed) if ivar.is_a?(Window)
  172.     end
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # * Metodo pre_terminate
  176.   #--------------------------------------------------------------------------
  177.   def pre_terminate
  178.     hide_windows_for_transition unless excluded_scene?
  179.     update_transition
  180.     super
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Aggiorna la transizione
  184.   #--------------------------------------------------------------------------
  185.   def update_transition
  186.     loop {update_basic; break if all_windows_moved}
  187.   end
  188.   #--------------------------------------------------------------------------
  189.   # * Restituisce true se tutte le finestre hanno terminato il movimento
  190.   #--------------------------------------------------------------------------
  191.   def all_windows_moved
  192.     instance_variables.each do |varname|
  193.       ivar = instance_variable_get(varname)
  194.       if ivar.is_a?(Window) && !ivar.move_end?
  195.         return false
  196.       end
  197.     end
  198.     return true
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # * Restituisce true se la schermata è tra quelle eslcuse
  202.   #--------------------------------------------------------------------------
  203.   def excluded_scene?
  204.     for scene in get_excluded_scenes
  205.       return true if self.is_a?(scene)
  206.     end
  207.     return false
  208.   end
  209.   #--------------------------------------------------------------------------
  210.   # * Restituisce le schermate escluse
  211.   #--------------------------------------------------------------------------
  212.   def get_excluded_scenes
  213.     return TRANSITION_SETTINGS::Excluded_Scenes
  214.   end
  215.  
  216.   def get_transition_speed
  217.     return TRANSITION_SETTINGS::SPEED
  218.   end
  219. end #fine dello script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement