Advertisement
Guest User

Simple Quit

a guest
Dec 30th, 2011
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.32 KB | None | 0 0
  1. #==============================================================================
  2. #   Simple Quit
  3. #   Author: Nicke
  4. #   Created: 27/12/2011
  5. #   Edited: 30/12/2011
  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. # A simple end scene with a few features. No need for explaining how it works.
  14. #==============================================================================
  15. ($imported ||= {})["NICKE-SIMPLE-QUIT"] = true
  16.  
  17. module NICKE
  18.   module QUIT
  19.     #--------------------------------------------------------------------------#
  20.     # * Settings
  21.     #--------------------------------------------------------------------------#
  22.     # When adding a new item make sure you edit in quit_command method as well.
  23.     # Right now it supports 5 items with the appropriated methods to it.
  24.     # CMDS ['STRING 1', 'STRING 2'] etc.
  25.     CMDS = ['Quit', 'Save', 'Load', 'Title', 'Back']
  26.    
  27.     # If you use CMDS.size the items will be pushed horizontal.
  28.     # Bare in mind that if you add too many they will eventually go off screen.
  29.     # WINDOW [ columns, x, y, z, opacity, center window]
  30.     WINDOW = [CMDS.size, 0, 0, 200, 255, false]
  31.    
  32.     # CONFIRM_WINDOW [ columns, x, y, z, opacity, center window ]
  33.     CONFIRM_WINDOW = [2, 200, 200, 200, 255, true]
  34.    
  35.     # Transition, nil to use default.
  36.     # TRANSITION [ SPEED, TRANSITION, OPACITY ]
  37.     # TRANSITION = [40, "Graphics/Transitions/1", 50]
  38.     TRANSITION = nil
  39.    
  40.     # BACKGROUND IMAGE (System folder)
  41.     # Set to nil to use default.
  42.     BACK = nil
  43.    
  44.     # Return to map instead?
  45.     RETURN_TO_MAP = false
  46.     RETURN_INDEX = 7
  47.    
  48.     # Font and positioning settings for confirm text.
  49.     # CONFIRM_TEXT = [ name, size, color, bold, shadow, x, y, text ]
  50.     CONFIRM_TEXT = ["Rockwell", 24, Color.new(255,200,200), true, true,
  51.                     0, 156, "Confirm"]
  52.   end
  53. end
  54. # *** Don't edit below unless you know what you are doing. ***
  55. #==============================================================================#
  56. # ** Scene_End
  57. #------------------------------------------------------------------------------
  58. #  New Scene :: Scene_End
  59. #==============================================================================#
  60. class Scene_End < Scene_Base
  61.  
  62.   def initialize(index = 0)
  63.     @command_index = index
  64.   end
  65.  
  66.   alias nicke_end_start start unless $@
  67.   def start(*args, &block)
  68.     super
  69.     nicke_end_start(*args, &block)
  70.   end
  71.  
  72.   alias nicke_end_terminate terminate unless $@
  73.   def terminate(*args, &block)
  74.     super
  75.     nicke_end_terminate(*args, &block)
  76.   end
  77.  
  78.   def create_menu_background
  79.     @menuback_sprite = Sprite.new
  80.     if NICKE::QUIT::BACK.nil?
  81.       @menuback_sprite.bitmap = $game_temp.background_bitmap
  82.       @menuback_sprite.color.set(16, 16, 16, 128)
  83.     else
  84.       @menuback_sprite.bitmap = Cache.system(NICKE::QUIT::BACK)
  85.     end
  86.     update_menu_background
  87.   end
  88.    
  89.   def create_command_window
  90.     @end_menu = []
  91.     for i in NICKE::QUIT::CMDS
  92.       next unless NICKE::QUIT::CMDS.include?(i) ; @end_menu << i
  93.     end
  94.     @command_window = Window_Command.new(Graphics.width, @end_menu, NICKE::QUIT::WINDOW[0])
  95.     @command_window.index = @command_index
  96.     if NICKE::QUIT::WINDOW[5]
  97.       @command_window.x = (Graphics.width - @command_window.width) / 2
  98.     else
  99.       @command_window.x = NICKE::QUIT::WINDOW[1]
  100.     end
  101.     @command_window.y = NICKE::QUIT::WINDOW[2]
  102.     @command_window.z = NICKE::QUIT::WINDOW[3]
  103.     @command_window.opacity = NICKE::QUIT::WINDOW[4]
  104.     # // Turn off save if save disabled.
  105.     if $game_system.save_disabled    
  106.       @command_window.draw_item(1, false)
  107.     end
  108.     # // Turn off load if no save files found.
  109.     if !check_continue
  110.       @command_window.draw_item(2, false)
  111.     end
  112.     @command_window.open
  113.   end
  114.  
  115.   def create_message_window
  116.     @message_window = Window_Text.new
  117.     @message_window.opacity = 0
  118.   end
  119.  
  120.   def create_confirm_window
  121.     @command_window.active = false
  122.     @confirm_window = Window_Command.new(300, ['Yes', 'No'], NICKE::QUIT::CONFIRM_WINDOW[0])
  123.     if NICKE::QUIT::CONFIRM_WINDOW[5]
  124.       @confirm_window.x = (Graphics.width - @confirm_window.width) / 2
  125.     else
  126.       @confirm_window.x = NICKE::QUIT::CONFIRM_WINDOW[1]
  127.     end
  128.     @confirm_window.y = NICKE::QUIT::CONFIRM_WINDOW[2]
  129.     @confirm_window.z = NICKE::QUIT::CONFIRM_WINDOW[3]
  130.     @confirm_window.opacity = NICKE::QUIT::CONFIRM_WINDOW[4]
  131.     @confirm_window.open
  132.   end
  133.  
  134.   def close_confirm_window
  135.     @confirm_window.dispose unless @confirm_window.nil?
  136.     @confirm_window = nil
  137.     @message_window.dispose unless @message_window.nil?
  138.     @message_window = nil
  139.     @command_window.active = true
  140.   end
  141.  
  142.   def return_scene
  143.     if NICKE::QUIT::RETURN_TO_MAP
  144.       $scene = Scene_Map.new
  145.     else
  146.       $scene = Scene_Menu.new(NICKE::QUIT::RETURN_INDEX)
  147.     end
  148.   end
  149.    
  150.   def dispose_command_window
  151.     @command_window.dispose unless @command_window.nil?
  152.     @command_window = nil
  153.   end
  154.  
  155.   def dispose_menu_background
  156.     @menuback_sprite.dispose unless @menuback_sprite.nil?
  157.     @menuback_sprite = nil
  158.   end
  159.  
  160.   def update
  161.     update_input
  162.     update_windows
  163.   end
  164.  
  165.   def update_input
  166.     if !@confirm_window.nil?
  167.       update_confirm_window
  168.       return
  169.     end
  170.     if @command_window.active ; update_command end
  171.   end
  172.  
  173.   def update_windows
  174.     @command_window.update
  175.     if !@message_window.nil?
  176.       @message_window.update
  177.     end
  178.     if !@confirm_window.nil?
  179.       @confirm_window.update
  180.     end
  181.   end
  182.  
  183.   def update_command # Main Command
  184.     if Input.trigger?(Input::B)
  185.       Sound.play_cancel
  186.       return_scene
  187.     end
  188.     if Input.trigger?(Input::C)
  189.       case @command_window.index
  190.       when 0...NICKE::QUIT::CMDS.size
  191.         # // Save (If you change positioning, change this)
  192.         if @command_window.index == 1
  193.           if $game_system.save_disabled
  194.             Sound.play_buzzer
  195.             return
  196.           end
  197.         end
  198.         # // Load (If you change positioning, change this)
  199.         if @command_window.index == 2
  200.           if !check_continue
  201.             Sound.play_buzzer
  202.             return
  203.           end
  204.         end
  205.         # // Back (If you add more, change this)
  206.         if @command_window.index == 4
  207.           Sound.play_cancel
  208.           return_scene
  209.           return
  210.         end
  211.         # // Confirm dialog.
  212.           Sound.play_decision
  213.           create_confirm_window
  214.           create_message_window
  215.       end
  216.     end
  217.   end
  218.  
  219.   def update_confirm_window # Confirm Command
  220.     if Input.trigger?(Input::B)
  221.       close_confirm_window
  222.       Sound.play_cancel
  223.     end
  224.     if Input.trigger?(Input::C)
  225.       case @confirm_window.index
  226.       when 0 # Yes
  227.         Sound.play_decision
  228.         close_confirm_window
  229.         quit_command(@command_window.index)
  230.       when 1 # No
  231.         Sound.play_cancel
  232.         close_confirm_window
  233.       end
  234.     end
  235.   end
  236.  
  237.   def check_continue
  238.     # // Check if any save data is available.
  239.     @continue_enabled = (Dir.glob('Save*.rvdata').size > 0)
  240.   end
  241.  
  242.   def quit_command(index)
  243.     # // Note: Changes should be made here if you wish to add more items to CMDS.
  244.     case index
  245.       when 0 ; command_shutdown # Quit
  246.       when 1
  247.         if !$game_system.save_disabled
  248.           command_save # Save
  249.           @command_window.draw_item(1, false)
  250.         end
  251.       when 2
  252.         if check_continue
  253.           command_load # Load
  254.           @command_window.index = 2
  255.         else
  256.           @command_window.draw_item(2, false)
  257.         end
  258.       when 3 ; command_to_title # Title
  259.       when 4 ; return_scene # Back
  260.     end
  261.   end
  262.  
  263.   def command_save
  264.     # // Save command.
  265.     Sound.play_decision
  266.     close_command_window
  267.     $scene = Scene_File.new(true, false, false)
  268.   end
  269.  
  270.   def command_load
  271.     # // Load command.
  272.     Sound.play_decision
  273.     close_command_window
  274.     $scene = Scene_File.new(false, false, false)
  275.   end
  276.  
  277.   def command_to_title
  278.     # // Title command.
  279.     Sound.play_decision
  280.     close_command_window
  281.     RPG::BGM.fade(800)
  282.     RPG::BGS.fade(800)
  283.     RPG::ME.fade(800)
  284.     $scene = Scene_Title.new
  285.     Graphics.fadeout(60)
  286.   end
  287.  
  288.   def command_shutdown
  289.     # // Quit command.
  290.     Sound.play_decision
  291.     close_command_window
  292.     Graphics.fadeout(60)
  293.     RPG::BGM.fade(800)
  294.     RPG::BGS.fade(800)
  295.     RPG::ME.fade(800)
  296.     $scene = nil
  297.   end
  298.  
  299.   def perform_transition
  300.     if NICKE::QUIT::TRANSITION.nil?
  301.       Graphics.transition(30)
  302.     else
  303.       Graphics.transition(NICKE::QUIT::TRANSITION[0],NICKE::QUIT::TRANSITION[1],NICKE::QUIT::TRANSITION[2])
  304.     end
  305.   end
  306.  
  307. end
  308.  
  309. #==============================================================================#
  310. # ** Window_Text
  311. #------------------------------------------------------------------------------
  312. #  Class for drawing text.
  313. #==============================================================================#
  314. class Window_Text < Window_Base
  315.  
  316.   def initialize
  317.     super(0, 0, Graphics.width, Graphics.height)
  318.     refresh
  319.   end
  320.  
  321.   def refresh
  322.     self.contents.clear
  323.     draw_confirm_text
  324.   end
  325.  
  326.   def self_rect
  327.     # Return the value of contents rect.
  328.     return self.contents.rect
  329.   end
  330.  
  331.   def draw_text(x, y, text, align)
  332.     # Method for drawing the text.
  333.     title = self_rect
  334.     title.x = x
  335.     title.y = y
  336.     title.height = 28
  337.     self.contents.draw_text(title,text,align)
  338.   end
  339.  
  340.   def draw_confirm_text
  341.     contents.font.name = NICKE::QUIT::CONFIRM_TEXT[0]
  342.     contents.font.size = NICKE::QUIT::CONFIRM_TEXT[1]
  343.     contents.font.color = NICKE::QUIT::CONFIRM_TEXT[2]
  344.     contents.font.bold = NICKE::QUIT::CONFIRM_TEXT[3]
  345.     contents.font.shadow = NICKE::QUIT::CONFIRM_TEXT[4]
  346.     self.contents.draw_text(NICKE::QUIT::CONFIRM_TEXT[5], NICKE::QUIT::CONFIRM_TEXT[6], self.contents.width - 16, WLH, NICKE::QUIT::CONFIRM_TEXT[7], 1)
  347.   end
  348.  
  349. end # END OF FILE
  350.  
  351. #=*==========================================================================*=#
  352. # ** END OF FILE
  353. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement