Advertisement
Guest User

Simple Menu

a guest
Jan 1st, 2012
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.84 KB | None | 0 0
  1. #==============================================================================
  2. #   Simple Menu
  3. #   Author: Nicke
  4. #   Created: 29/12/2011
  5. #   Edited: 02/01/2012
  6. #   Version: 1.0a
  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 menu script featuring a few functions.
  14. #==============================================================================
  15. ($imported ||= {})["NICKE-SIMPLE-MENU"] = true
  16.  
  17. module NICKE
  18.   module MENU
  19.     #--------------------------------------------------------------------------#
  20.     # * Settings
  21.     #--------------------------------------------------------------------------#
  22.     # Menu font settings.
  23.     # MENU_FONT = [ font, size, bold, shadow ]
  24.     MENU_FONT = [["Rockwell", "Tahoma"], 14, true, true]
  25.    
  26.     # When adding a new item make sure you edit in menu_command method as well.
  27.     # Right now it supports 8 items with the appropriated methods to it.
  28.     # CMDS [ ID ] = [ title ]
  29.     CMDS = [] # Don't remove!
  30.     CMDS[0] = ["Quests"]
  31.     CMDS[1] = ["Items"]
  32.     CMDS[2] = ["Skills"]
  33.     CMDS[3] = ["Status"]
  34.     CMDS[4] = ["Equip"]
  35.     CMDS[5] = ["Save"]
  36.     CMDS[6] = ["Load"]
  37.     CMDS[7] = ["Quit"]
  38.    
  39.     # In here you might want to change the index so that it match up with
  40.     # CMDS items. i.e skills should be 2 if CMDS skills is 2.
  41.     # These are important because of status window related things and
  42.     # save/load disabling option.
  43.     # INDEX_SAVE and INDEX_LOAD can be nil if not in used.
  44.     # Index = index_id
  45.     INDEX_SKILLS = 2
  46.     INDEX_STATUS = 3
  47.     INDEX_EQUIP = 4
  48.     INDEX_SAVE = 5
  49.     INDEX_LOAD = 6
  50.    
  51.     # If you use CMDS.size the items will be pushed horizontal.
  52.     # Bare in mind that if you add too many they will eventually go off screen.
  53.     # WINDOW [ Columns, x, y, z, opacity, center window]
  54.     WINDOW = [CMDS.size, 0, 0, 200, 255, false]
  55.      
  56.     # Transition, nil to use default.
  57.     # TRANSITION [ SPEED, TRANSITION, OPACITY ]
  58.     # TRANSITION = [40, "Graphics/Transitions/1", 50]
  59.     TRANSITION = nil
  60.    
  61.     # Menu background image (System folder)
  62.     # Note: You might want to decrease the opacity as well as arrange
  63.     # the windows so that you can properly see the background.
  64.     # Set to nil to use default.
  65.     BACK = nil
  66.    
  67.     # Note: Not active if menu background is in use.
  68.     # Background type:
  69.     # 0 = radial blur
  70.     # 1 = normal blur
  71.     # 2 = hue change
  72.     # 3 = gradient
  73.     # 4 = default
  74.     # BACK_TYPE = [ type, enabled }
  75.     BACK_TYPE = [0, true]
  76.     BACK_RADIAL_BLUR = [15, 50] # 0-360, 2-100
  77.     BACK_CUSTOM_HUE = 10 # 0-360
  78.     BACK_CUSTOM_GRADIENT = [Color.new(255,200,200,128),
  79.                             Color.new(255,200,25,128),
  80.                             true]
  81.    
  82.     # Gold window.
  83.     # GOLD = [ x, y, z, opacity, enabled ]
  84.     GOLD = [485, 420, 201, 0, false]
  85.    
  86.     # Status window.
  87.     # STATUS = [ x, y, z, opacity, enabled ]
  88.     STATUS = [0, 56, 200, 255, false]
  89.    
  90.   end
  91. end
  92. # *** Don't edit below unless you know what you are doing. ***
  93. #==============================================================================#
  94. # ** Window_MenuStatus
  95. #------------------------------------------------------------------------------
  96. #  New Class :: Window_MenuStatus
  97. #==============================================================================#
  98. class Window_MenuStatus < Window_Selectable
  99.  
  100.   # // Override MenuStatus initialize so that we can specify width and height.
  101.   def initialize(x, y, width = 384, height = 416) # Default values
  102.     super(x, y, width, height)
  103.     refresh
  104.     self.active = false
  105.     self.index = -1
  106.   end
  107.  
  108. end
  109. #==============================================================================#
  110. # ** Window_Command
  111. #------------------------------------------------------------------------------
  112. # New Class :: Window_Command
  113. #
  114. # Method to draw a item in the menu window.
  115. #==============================================================================#
  116. class Window_Command < Window_Selectable
  117.  
  118.   # // draw_item for Window_Command.
  119.   alias nicke_menu_draw_item_win_menu draw_item unless $@
  120.   def draw_item(*args, &block)
  121.     old_size = self.contents.font.size
  122.     self.contents.font.name = NICKE::MENU::MENU_FONT[0]
  123.     self.contents.font.size = NICKE::MENU::MENU_FONT[1]
  124.     self.contents.font.bold = NICKE::MENU::MENU_FONT[2]
  125.     self.contents.font.shadow = NICKE::MENU::MENU_FONT[3]
  126.     self.contents.font.size = old_size
  127.     nicke_menu_draw_item_win_menu(*args, &block)
  128.   end
  129.  
  130.  end
  131. #==============================================================================#
  132. # ** Scene_Menu
  133. #------------------------------------------------------------------------------
  134. #  New Class :: Scene_Menu
  135. #==============================================================================#
  136. class Scene_Menu < Scene_Base
  137.  
  138.   # // Method initialize override.
  139.   def initialize(index = 0)
  140.     @command_index = index
  141.   end
  142.  
  143.   # // Method start override.
  144.   def start
  145.     super
  146.     create_menu_background
  147.     create_command_window
  148.     if NICKE::MENU::GOLD[4]
  149.       @gold_window = Window_Gold.new(NICKE::MENU::GOLD[0], NICKE::MENU::GOLD[1])
  150.       @gold_window.z = NICKE::MENU::GOLD[2]
  151.       @gold_window.opacity = NICKE::MENU::GOLD[3]
  152.     end
  153.     if NICKE::MENU::STATUS[4]
  154.       @status_window = Window_MenuStatus.new(NICKE::MENU::STATUS[0], NICKE::MENU::STATUS[1], Graphics.width, 424)
  155.       @status_window.z = NICKE::MENU::STATUS[2]
  156.       @status_window.opacity = NICKE::MENU::STATUS[3]
  157.     end
  158.   end
  159.  
  160.   # // Method terminate override.
  161.   def terminate
  162.     super
  163.     dispose_menu_background
  164.     dispose_command_window
  165.     dispose_gold_window if NICKE::MENU::GOLD[4]
  166.     dispose_status_window if NICKE::MENU::STATUS[4]
  167.   end
  168.  
  169.   def create_menu_background
  170.     @menuback_sprite = Sprite.new
  171.     if NICKE::MENU::BACK.nil?
  172.       @menuback_sprite.bitmap = $game_temp.background_bitmap
  173.       if NICKE::MENU::BACK_TYPE[1]
  174.         source = $game_temp.background_bitmap
  175.         bitmap = Bitmap.new(Graphics.width, Graphics.height)
  176.         bitmap.stretch_blt(bitmap.rect, source, source.rect)
  177.         case NICKE::MENU::BACK_TYPE[0]
  178.         when 0 ; bitmap.radial_blur(NICKE::MENU::BACK_RADIAL_BLUR[0], NICKE::MENU::BACK_RADIAL_BLUR[0])
  179.         when 1 ; bitmap.blur
  180.         when 2 ; bitmap.hue_change(NICKE::MENU::BACK_CUSTOM_HUE)
  181.         when 3 ; bitmap.gradient_fill_rect(bitmap.rect, NICKE::MENU::BACK_CUSTOM_GRADIENT[0],
  182.                  NICKE::MENU::BACK_CUSTOM_GRADIENT[1], NICKE::MENU::BACK_CUSTOM_GRADIENT[2])
  183.         when 4
  184.           @menuback_sprite.color.set(16, 16, 16, 128)
  185.           return
  186.         end
  187.         @menuback_sprite.dispose
  188.         @menuback_sprite = Sprite.new(@viewport1)
  189.         @menuback_sprite.bitmap = bitmap
  190.       end
  191.     else
  192.       @menuback_sprite.bitmap = Cache.system(NICKE::MENU::BACK)
  193.     end
  194.     update_menu_background
  195.   end
  196.  
  197.   def create_command_window
  198.     @menu = []
  199.     for i in NICKE::MENU::CMDS
  200.       @menu << i[0]
  201.     end
  202.     @command_window = Window_Command.new(Graphics.width, @menu, NICKE::MENU::WINDOW[0])
  203.     @command_window.index = @command_index
  204.     if NICKE::MENU::WINDOW[5]
  205.       @command_window.x = (Graphics.width - @command_window.width) / 2
  206.     else
  207.       @command_window.x = NICKE::MENU::WINDOW[1]
  208.     end
  209.     @command_window.y = NICKE::MENU::WINDOW[2]
  210.     @command_window.z = NICKE::MENU::WINDOW[3]
  211.     @command_window.opacity = NICKE::MENU::WINDOW[4]
  212.     # // Turn off save if save disabled.
  213.     if !NICKE::MENU::INDEX_SAVE.nil?
  214.       if $game_system.save_disabled
  215.         @command_window.draw_item(NICKE::MENU::INDEX_SAVE, false)
  216.       end
  217.     end
  218.     # // Turn off load if no save files found.
  219.     if !NICKE::MENU::INDEX_LOAD.nil?
  220.       if !check_continue
  221.         @command_window.draw_item(NICKE::MENU::INDEX_LOAD, false)
  222.       end
  223.     end
  224.     @command_window.open
  225.   end
  226.  
  227.   def dispose_command_window
  228.     @command_window.dispose unless @command_window.nil?
  229.     @command_window = nil
  230.   end
  231.  
  232.   def dispose_gold_window
  233.     @gold_window.dispose unless @gold_window.nil?
  234.     @gold_window = nil
  235.   end
  236.  
  237.   def dispose_status_window
  238.     @status_window.dispose unless @status_window.nil?
  239.     @status_window = nil
  240.   end
  241.  
  242.   def dispose_menu_background
  243.     @menuback_sprite.dispose unless @menuback_sprite.nil?
  244.     @menuback_sprite = nil
  245.   end
  246.  
  247.   def return_scene
  248.     $scene = Scene_Map.new
  249.   end
  250.  
  251.   def update
  252.     super
  253.     @command_window.update
  254.     @gold_window.update if NICKE::MENU::GOLD[4]
  255.     @status_window.update if NICKE::MENU::STATUS[4]
  256.     if NICKE::MENU::STATUS[4]
  257.       if @command_window.active
  258.         update_command_selection
  259.       elsif @status_window.active
  260.         update_actor_selection
  261.       end
  262.     else
  263.       update_command_selection
  264.     end
  265.   end
  266.  
  267.   def update_command_selection
  268.     if Input.trigger?(Input::B)
  269.       Sound.play_cancel
  270.       return_scene
  271.     end
  272.     if Input.trigger?(Input::C)
  273.       # // Skills, Status, Equip.
  274.       if NICKE::MENU::STATUS[4]
  275.         # // Index should be changed if you switch positioning.
  276.         if @command_window.index == NICKE::MENU::INDEX_SKILLS # // Skills.
  277.           start_actor_selection
  278.           return
  279.         end
  280.         if @command_window.index == NICKE::MENU::INDEX_STATUS # // Status.
  281.           start_actor_selection
  282.           return
  283.         end
  284.         if @command_window.index == NICKE::MENU::INDEX_EQUIP  # // Equip.
  285.           start_actor_selection
  286.           return
  287.         end
  288.       end
  289.       if !NICKE::MENU::INDEX_SAVE.nil?
  290.         if @command_window.index == NICKE::MENU::INDEX_SAVE  # // Save.
  291.           if $game_system.save_disabled
  292.             Sound.play_buzzer
  293.             return
  294.           end
  295.         end
  296.       end
  297.       if !NICKE::MENU::INDEX_LOAD.nil?
  298.         if @command_window.index == NICKE::MENU::INDEX_LOAD  # // Load.
  299.           if !check_continue
  300.             Sound.play_buzzer
  301.             return
  302.           end
  303.         end
  304.       end
  305.       case @command_window.index
  306.       when 0...NICKE::MENU::CMDS.size
  307.         menu_command(@command_window.index)
  308.       end
  309.     end
  310.   end
  311.  
  312.   def update_actor_selection
  313.     if Input.trigger?(Input::B)
  314.       Sound.play_cancel
  315.       end_actor_selection
  316.     end
  317.     if Input.trigger?(Input::C)
  318.       $game_party.last_actor_index = @status_window.index
  319.       Sound.play_decision
  320.       case @command_window.index
  321.       when NICKE::MENU::INDEX_SKILLS # Skill.
  322.         $scene = Scene_Skill.new(@status_window.index)
  323.       when NICKE::MENU::INDEX_STATUS # Status.
  324.         $scene = Scene_Status.new(@status_window.index)
  325.       when NICKE::MENU::INDEX_EQUIP # Equip.
  326.         $scene = Scene_Equip.new(@status_window.index)
  327.       end
  328.     end
  329.   end
  330.  
  331.   def menu_command(index)
  332.     # // Note: Changes should be made here if you wish to add more items to CMDS.
  333.     # // i.e the index numbers should be changed if you switch order of the items.
  334.     case index
  335.     when 0 ; command_journal # // Imported. Can be removed or commented.
  336.     when 1 ; command_items
  337.     when 2 ; command_skills
  338.     when 3 ; command_status
  339.     when 4 ; command_equipment
  340.     when 5 ; command_save
  341.     when 6 ; command_load
  342.     when 7 ; command_system
  343.     end
  344.   end
  345.  
  346.   def check_continue
  347.     # // Check if any save data is available.
  348.     @continue_enabled = (Dir.glob('Save*.rvdata').size > 0)
  349.   end
  350.  
  351.   # // Imported from my game. You can remove it if you want.
  352.   # // Make sure you change in menu_command as well if so.
  353.   def command_journal
  354.     Sound.play_decision
  355.     $scene = Scene_Simple_Journal.new
  356.   end
  357.  
  358.   def command_items
  359.     Sound.play_decision
  360.     $scene = Scene_Item.new
  361.   end
  362.  
  363.   def command_skills
  364.     Sound.play_decision
  365.     $scene = Scene_Skill.new
  366.   end
  367.  
  368.  
  369.   def command_status
  370.     Sound.play_decision
  371.     $scene = Scene_Status.new
  372.   end
  373.  
  374.   def command_equipment
  375.     Sound.play_decision
  376.     $scene = Scene_Equip.new
  377.   end
  378.  
  379.   def command_save
  380.     Sound.play_decision
  381.     $scene = Scene_File.new(true, false, false)
  382.   end
  383.  
  384.   def command_load
  385.     Sound.play_decision
  386.     $scene = Scene_File.new(false, false, false)
  387.   end
  388.  
  389.   def command_system
  390.     Sound.play_decision
  391.     $scene = Scene_End.new
  392.   end
  393.  
  394.   def perform_transition
  395.     if NICKE::MENU::TRANSITION.nil?
  396.       Graphics.transition(30)
  397.     else
  398.       Graphics.transition(NICKE::MENU::TRANSITION[0],NICKE::MENU::TRANSITION[1],NICKE::MENU::TRANSITION[2])
  399.     end
  400.   end
  401.  
  402. end # END OF FILE
  403.  
  404. #=*==========================================================================*=#
  405. # ** END OF FILE
  406. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement