Advertisement
Guest User

XS - Quit

a guest
Apr 5th, 2012
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.65 KB | None | 0 0
  1. #==============================================================================
  2. #   XaiL System - Quit
  3. #   Author: Nicke
  4. #   Created: 16/01/2012
  5. #   Edited: 17/01/2012
  6. #   Version: 1.0
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  12. #
  13. # Note: This script must be placed below XS - Core and XS - Title.
  14. #
  15. # *** Only for RPG Maker VX Ace. ***
  16. #==============================================================================
  17. ($imported ||= {})["XAIL-XS-QUIT"] = true
  18.  
  19. module XAIL
  20.   module QUIT
  21.   #--------------------------------------------------------------------------#
  22.   # * Settings
  23.   #--------------------------------------------------------------------------#
  24.   # QUIT list, the icon_index (set to nil) and custom_scene is optional.
  25.   # QUIT_LIST:
  26.   # ID = ['Title', :symbol, :command, icon_index, custom_scene (not needed) ]
  27.   QUIT_LIST = []
  28.   QUIT_LIST[0] = ['To Title', :to_title, :command_to_title, 121]
  29.   QUIT_LIST[1] = ['New Game', :new_game, :command_new_game, 125]
  30.   QUIT_LIST[2] = ['Save',     :save,     :command_custom,   229,  Scene_Save]
  31.   QUIT_LIST[3] = ['Load',     :continue, :command_continue, 232]
  32.   QUIT_LIST[4] = ['Quit',     :shutdown, :command_shutdown, 1]
  33.  
  34.   # If center window is true you cannot modify the x value.
  35.   # QUIT_WINDOW [ Width, x, y, z, opacity, center window]
  36.   QUIT_WINDOW = [160, 0, 50, 200, 255, true]
  37.  
  38.   # QUIT_ALIGNMENT = 0 (left), 1 (center), 2 (right)
  39.   QUIT_ALIGNMENT = 0 # Default: 0.
  40.  
  41.   # The windowskin to use for the windows.
  42.   # nil to disable.
  43.   # SKIN = string
  44.   SKIN = nil
  45.  
  46.   # Disable all of the icons if you don't need them.
  47.   # ICON_ENABLE = true/false
  48.   ICON_ENABLE = true
  49.  
  50.   # Transition, nil to use default.
  51.   # TRANSITION [ SPEED, TRANSITION, OPACITY ]
  52.   # TRANSITION = [40, "Graphics/Transitions/1", 50]
  53.   TRANSITION = nil
  54.  
  55.   # Animate options.
  56.   # Set ANIM_WINDOW_TIMER to nil to disable.
  57.   ANIM_WINDOW_TIMER = 5 # Fade in time for window/icons.
  58.   ANIM_SCENE_FADE = 1000 # Fade out time for scene. Default: 1000.
  59.   ANIM_AUDIO_FADE = 1000 # Fade out time for audio. Default: 1000.
  60.  
  61.   end
  62. end
  63. # *** Don't edit below unless you know what you are doing. ***
  64. #==============================================================================
  65. # ** Window_QuitCommand
  66. #==============================================================================
  67. class Window_QuitCommand < Window_Command
  68.  
  69.   def initialize
  70.     super(0, 0)
  71.     self.openness = 0
  72.     open
  73.   end
  74.  
  75.   def window_width
  76.     # // Method to return the width of QUIT_WINDOW.
  77.     return XAIL::QUIT::QUIT_WINDOW[0]
  78.   end
  79.  
  80.   def alignment
  81.     # // Method to return the alignment.
  82.     return XAIL::QUIT::QUIT_ALIGNMENT
  83.   end
  84.  
  85.   def continue_enabled
  86.     # // Method to check if a save file exists.
  87.     DataManager.save_file_exists?
  88.   end
  89.  
  90.   def save_enabled
  91.     # // Method to check if save is enabled.
  92.     !$game_system.save_disabled
  93.   end
  94.  
  95.   def make_command_list
  96.     # // Method to add the commands.
  97.     for i in XAIL::QUIT::QUIT_LIST
  98.       case i[1]
  99.       when :continue # Load
  100.         add_command(i[0], i[1], continue_enabled, i[4])
  101.       when :save
  102.         add_command(i[0], i[1], save_enabled, i[4])
  103.       else
  104.         add_command(i[0], i[1], true, i[4])
  105.       end
  106.     end
  107.   end
  108.  
  109. end
  110. #==============================================================================#
  111. # ** Scene_End
  112. #------------------------------------------------------------------------------
  113. #  New Scene :: Scene_End
  114. #==============================================================================#
  115. class Scene_End < Scene_MenuBase
  116.  
  117.   alias xail_quit_start start
  118.   def start(*args, &block)
  119.     # // Method to start the scene.
  120.     super
  121.     xail_quit_start(*args, &block)
  122.     create_quit_icon_window
  123.     create_quit_command_window
  124.   end
  125.  
  126.   def terminate
  127.     # // Method to terminate.
  128.     super
  129.   end
  130.  
  131.   def create_quit_command_window
  132.     # // Method to create the commands.
  133.     @command_window = Window_QuitCommand.new
  134.     @command_window.windowskin = Cache.system(XAIL::QUIT::SKIN) unless XAIL::QUIT::SKIN.nil?
  135.     if XAIL::QUIT::QUIT_WINDOW[5]
  136.       @command_window.x = (Graphics.width - @command_window.width) / 2
  137.     else
  138.       @command_window.x = XAIL::QUIT::QUIT_WINDOW[1]
  139.     end
  140.     @command_window.y = XAIL::QUIT::QUIT_WINDOW[2]
  141.     @command_window.z = XAIL::QUIT::QUIT_WINDOW[3]
  142.     @command_window.opacity = XAIL::QUIT::QUIT_WINDOW[4]
  143.     for i in XAIL::QUIT::QUIT_LIST
  144.       @command_window.set_handler(i[1], method(i[2]))
  145.     end
  146.     @command_window.set_handler(:cancel, method(:return_scene))
  147.     pre_animate_in(@command_window) unless XAIL::QUIT::ANIM_WINDOW_TIMER.nil?
  148.   end
  149.  
  150.   def create_quit_icon_window
  151.     # // Method to create the menu icon window.
  152.     @command_icon = Window_Icon.new(0, 0, @command_window.width, XAIL::QUIT::QUIT_LIST.size)
  153.     @command_icon.alignment = XAIL::QUIT::QUIT_ALIGNMENT
  154.     @command_icon.enabled = XAIL::QUIT::ICON_ENABLE
  155.     @command_icon.draw_cmd_icons(XAIL::QUIT::QUIT_LIST, 3)
  156.     if XAIL::QUIT::QUIT_WINDOW[5]
  157.       @command_icon.x = (Graphics.width - @command_window.width) / 2
  158.     else
  159.       @command_icon.x = XAIL::QUIT::QUIT_WINDOW[1]
  160.     end
  161.     @command_icon.y = XAIL::QUIT::QUIT_WINDOW[2]
  162.     @command_icon.z = 201
  163.     unless XAIL::QUIT::ANIM_WINDOW_TIMER.nil?
  164.       @command_icon.opacity = 255
  165.       pre_animate_in(@command_icon)
  166.     else
  167.       @command_icon.opacity = 0
  168.     end
  169.   end
  170.  
  171.   def pre_animate_in(command)
  172.     # // Method for pre_animate the window.
  173.     command.opacity -= 255
  174.     command.contents_opacity -= 255
  175.   end
  176.  
  177.   def fade_animate(command, fade)
  178.     # // Method for fading in/out.
  179.     timer = XAIL::QUIT::ANIM_WINDOW_TIMER
  180.     while timer > 0
  181.       Graphics.update
  182.       case fade
  183.       when :fade_in
  184.       command.opacity += 255 / XAIL::QUIT::ANIM_WINDOW_TIMER unless command == @command_icon
  185.       command.contents_opacity += 255 / XAIL::QUIT::ANIM_WINDOW_TIMER
  186.       when :fade_out
  187.       command.opacity -= 255 / XAIL::QUIT::ANIM_WINDOW_TIMER unless command == @command_icon
  188.       command.contents_opacity -= 255 / XAIL::QUIT::ANIM_WINDOW_TIMER  
  189.       end
  190.       command.update
  191.       timer -= 1
  192.     end
  193.   end
  194.  
  195.   def post_start
  196.     # // Method for post_start.
  197.     super
  198.     unless XAIL::QUIT::ANIM_WINDOW_TIMER.nil?
  199.       fade_animate(@command_window, :fade_in)
  200.       fade_animate(@command_icon, :fade_in)
  201.     end
  202.   end
  203.  
  204.   def close_command_window
  205.     # // Method for close_command_window.
  206.     unless XAIL::QUIT::ANIM_WINDOW_TIMER.nil?
  207.       fade_animate(@command_icon, :fade_out)
  208.       fade_animate(@command_window, :fade_out)
  209.     end
  210.   end
  211.  
  212.   def fadeout_scene
  213.     time = XAIL::QUIT::ANIM_AUDIO_FADE
  214.     # // Method to fade out the scene.
  215.     RPG::BGM.fade(time)
  216.     RPG::BGS.fade(time)
  217.     RPG::ME.fade(time)
  218.     Graphics.fadeout(XAIL::QUIT::ANIM_SCENE_FADE * Graphics.frame_rate / 1000)
  219.     RPG::BGM.stop
  220.     RPG::BGS.stop
  221.     RPG::ME.stop
  222.   end
  223.  
  224.   def command_new_game
  225.      # // Method to call new game.
  226.     if $imported["XAIL-XS-TITLE"]
  227.       return command_new_game_xail
  228.     end
  229.     DataManager.setup_new_game
  230.     close_command_window
  231.     fadeout_all
  232.     $game_map.autoplay
  233.     SceneManager.goto(Scene_Map)
  234.   end
  235.  
  236.   def command_new_game_xail
  237.     # // Method to call new game (if XS-Title is imported).
  238.     DataManager.setup_new_game
  239.     close_command_window
  240.     fadeout_scene
  241.     $game_map.autoplay
  242.     if !XAIL::TITLE::SWITCHES.nil?
  243.       for i in XAIL::TITLE::SWITCHES
  244.         $game_switches[i] = true
  245.       end
  246.     end
  247.     if !XAIL::TITLE::COMMON_EVENT.nil?
  248.       $game_temp.reserve_common_event(XAIL::TITLE::COMMON_EVENT)
  249.     end
  250.     SceneManager.goto(Scene_Map)
  251.   end
  252.  
  253.   def command_continue
  254.     # // Method to call load.
  255.     close_command_window
  256.     SceneManager.call(Scene_Load)
  257.   end
  258.  
  259.   def command_custom
  260.     # // Method to call a custom command.
  261.     SceneManager.goto(@command_window.current_ext)
  262.   end
  263.  
  264.   def perform_transition
  265.     # // Method to perform a transition.
  266.     if XAIL::QUIT::TRANSITION.nil?
  267.       Graphics.transition(15)
  268.     else
  269.       Graphics.transition(XAIL::QUIT::TRANSITION[0],XAIL::QUIT::TRANSITION[1],XAIL::QUIT::TRANSITION[2])
  270.     end
  271.   end
  272.  
  273. end # END OF FILE
  274.  
  275. #=*==========================================================================*=#
  276. # ** END OF FILE
  277. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement