Advertisement
AngryPacman

PAC Main Menu 1.7

Jul 29th, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.66 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Pacman Advanced Creative (PAC) Engine - Main Menu 1.7
  4. # 25/7/2011
  5. # Type: Menu
  6. # Installation: Heavy arrays and hashes.
  7. # Level: Simple, Average, Difficult
  8. #
  9. #===============================================================================
  10. #
  11. # Description:
  12. # The PAC Main Menu is focused around simple customization. The layout of
  13. # configuration is similar to that of Main Menu Melody, but the menu itself and
  14. # the code used is much different. Nothing much has been done in terms of
  15. # display to the menu, the focus of the first version, 1.7, is to get the core
  16. # code out of the way so I can focus more on exotic displays in later versions.
  17. #
  18. #===============================================================================
  19. #
  20. # Instructions:
  21. # INSTALLATION
  22. # Paste above main, below materials. It's not very difficult, even an XP
  23. # user could do it.
  24. # CONFIGURATION
  25. # There are detailed instructions for the configuration beginning at line 39.
  26. # Follow them closely, they shall lead you to your dream menu.
  27. #
  28. #===============================================================================
  29. #
  30. # CONFIGURATION BEGINS AT LINE 39
  31. #
  32. #===============================================================================
  33.  
  34. module PAC
  35.   module MM
  36.    
  37. #===============================================================================
  38. #
  39. # BEGIN CONFIGURATION
  40. #
  41. #===============================================================================
  42.  
  43.     # This array holds the commands in the menu, in order. Any command listed
  44.     # here MUST have an iteration in the other hashes. Syntax:
  45.     # ITEMS = [
  46.     #   'Command Name',
  47.     # ]
  48.    
  49.     ITEMS = [
  50.       'Item',
  51.       'Skill',
  52.       'Equip',
  53.       'Status',
  54.       'Party',
  55.       'Save',
  56.       'End Game',
  57.     ]
  58.    
  59.     # This hash determines what to do when the specified command is selected.
  60.     # The syntax:
  61.     # COMMAND = {
  62.     #   'Command Name' => 'command',
  63.     # }
  64.    
  65.     COMMAND = {
  66.       'Item'       => '$scene = Scene_Item.new',
  67.       'Skill'      => '$scene = Scene_Skill.new(@status_window.index)',
  68.       'Equip'      => '$scene = Scene_Equip.new(@status_window.index)',
  69.       'Status'     => '$scene = Scene_Status.new(@status_window.index)',
  70.       'Party'      => '$scene = Scene_Party.new(false, true)',
  71.       'Save'       => '$scene = Scene_File.new(true, false, false)',
  72.       'End Game'   => '$scene = Scene_End.new',
  73.     }
  74.  
  75.     # This hash determines the requirements needed to be met for the item to
  76.     # be disabled. The syntax:
  77.     # DISABLES = {
  78.     #   'Command Name' => 'condition',
  79.     # }
  80.    
  81.     DISABLES = {
  82.       # Disables the save menu if needed.
  83.       'Save'     => '$game_system.save_disabled',
  84.       # Disables the party menu if needed.
  85.       'Party'    => '$game_party.party_menu_disabled or
  86.       $game_party.members.size == 0',
  87.     }
  88.    
  89.     # Use icons in the main menu command window? (true/false)
  90.    
  91.     USE_ICONS = true
  92.    
  93.     # This hash decides which icons are used for each menu option. If you want
  94.     # a command to have no icon, use nil. Syntax:
  95.     # ICONS = {
  96.     #   'Command Name' => Icon_ID',
  97.     # }
  98.    
  99.     ICONS = {
  100.       'Item'     => 144,
  101.       'Skill'    => 137,
  102.       'Equip'    => 1,
  103.       'Status'   => 130,
  104.       'Party'    => 96,
  105.       'Save'     => 200,
  106.       'End Game' => 224,
  107.     }
  108.  
  109. #===============================================================================
  110. #
  111. # END CONFIGURATION
  112. #
  113. #===============================================================================
  114.    
  115.   end
  116. end
  117.  
  118. $imported = {} if $imported == nil
  119. $imported["PAC_Menu 1.7"] = true
  120.  
  121. #==============================================================================
  122. # ** Game_System
  123. #------------------------------------------------------------------------------
  124. #  This class handles system-related data. Also manages vehicles and BGM, etc.
  125. # The instance of this class is referenced by $game_system.
  126. #==============================================================================
  127.  
  128. class Game_System
  129.   #--------------------------------------------------------------------------
  130.   # Public Instance Variables
  131.   #--------------------------------------------------------------------------
  132.   attr_accessor :menu_index
  133.   #--------------------------------------------------------------------------
  134.   # alias listing
  135.   #--------------------------------------------------------------------------
  136.   alias pac_mm_initialize initialize
  137.   #--------------------------------------------------------------------------
  138.   # * Object Initialization
  139.   #--------------------------------------------------------------------------
  140.   def initialize
  141.     pac_mm_initialize
  142.     @menu_index = 0
  143.   end
  144. end
  145.  
  146. #==============================================================================
  147. # ** Window_MenuCommand
  148. #------------------------------------------------------------------------------
  149. #  This window displays selectable commands on the menu screen.
  150. #==============================================================================
  151.  
  152. class Window_MenuCommand < Window_Selectable
  153.   #--------------------------------------------------------------------------
  154.   # * Object Initialization
  155.   #--------------------------------------------------------------------------
  156.   def initialize(width, commands, column_max = 1, row_max = 0, spacing = 32)
  157.     if row_max == 0
  158.       row_max = (commands.size + column_max - 1) / column_max
  159.     end
  160.     super(0, 0, width, row_max * WLH + 32, spacing)
  161.     @commands = commands
  162.     @item_max = commands.size
  163.     @column_max = column_max
  164.     refresh
  165.     self.index = 0
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # * Refresh
  169.   #--------------------------------------------------------------------------
  170.   def refresh
  171.     self.contents.clear
  172.     for i in 0...@item_max
  173.       draw_item(i)
  174.     end
  175.     $game_system.menu_index = self.index
  176.   end
  177.   #--------------------------------------------------------------------------
  178.   # * Draw Item
  179.   #     index : Item number
  180.   #--------------------------------------------------------------------------
  181.   def draw_item(index, enabled = true)
  182.     rect = item_rect(index)
  183.     rect.x += 4
  184.     rect.width -= 8
  185.     self.contents.clear_rect(rect)
  186.     self.contents.font.color = normal_color
  187.     self.contents.font.color.alpha = enabled ? 255 : 128
  188.     if PAC::MM::ICONS[@commands[index]] != nil and PAC::MM::USE_ICONS
  189.       draw_icon(PAC::MM::ICONS[@commands[index]], rect.x, rect.y)
  190.       rect.x += 24
  191.     end
  192.     self.contents.draw_text(rect, @commands[index])
  193.   end
  194. end
  195.  
  196. #==============================================================================
  197. # ** Scene_Menu
  198. #------------------------------------------------------------------------------
  199. #  This class performs the menu screen processing.
  200. #==============================================================================
  201.  
  202. class Scene_Menu < Scene_Base
  203.   #--------------------------------------------------------------------------
  204.   # alias listing
  205.   #--------------------------------------------------------------------------
  206.   alias pac_mm_initialize initialize
  207.   #--------------------------------------------------------------------------
  208.   # * Object Initialization
  209.   #--------------------------------------------------------------------------
  210.   def initialize(menu_index = $game_system.menu_index)
  211.     pac_mm_initialize(menu_index)
  212.   end
  213.   #--------------------------------------------------------------------------
  214.   # * Create Command Window
  215.   #--------------------------------------------------------------------------
  216.   def create_command_window
  217.     commands = PAC::MM::ITEMS
  218.     @command_window = Window_MenuCommand.new(160, commands)
  219.     @command_window.index = @menu_index
  220.     pac_mm_disable_commands
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # * Disable Commands
  224.   #--------------------------------------------------------------------------
  225.   def pac_mm_disable_commands
  226.     if $game_party.members.size == 0
  227.       for i in 0...PAC::MM::ITEMS.size
  228.         command = PAC::MM::ITEMS[i]
  229.         if selection?(command)
  230.           @command_window.draw_item(i, false)
  231.         end
  232.       end
  233.     end
  234.     for i in 0...PAC::MM::ITEMS.size
  235.       command = PAC::MM::ITEMS[i]
  236.       if PAC::MM::DISABLES.key?(command)
  237.         @command_window.draw_item(i, false) if eval(PAC::MM::DISABLES[command])
  238.       end
  239.     end
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # * Require selection?
  243.   #--------------------------------------------------------------------------
  244.   def selection?(command)
  245.     return PAC::MM::COMMAND[command].include?('@status_window.index')
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # * Update Command Selection
  249.   #--------------------------------------------------------------------------
  250.   def update_command_selection
  251.     $game_system.menu_index = @command_window.index
  252.     selection = PAC::MM::ITEMS[@command_window.index]
  253.     if Input.trigger?(Input::B)
  254.       Sound.play_cancel
  255.       $scene = Scene_Map.new
  256.     elsif Input.trigger?(Input::C)
  257.       if $game_party.members.size == 0 and selection?(selection)
  258.         Sound.play_buzzer
  259.         return
  260.       elsif PAC::MM::DISABLES.key?(selection)
  261.         if eval(PAC::MM::DISABLES[selection])
  262.           Sound.play_buzzer
  263.           return
  264.         end
  265.       end
  266.       Sound.play_decision
  267.       if selection?(selection)
  268.         start_actor_selection
  269.       else
  270.         eval(PAC::MM::COMMAND[selection])
  271.       end
  272.     end
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # * Update Actor Selection
  276.   #--------------------------------------------------------------------------
  277.   def update_actor_selection
  278.     if Input.trigger?(Input::B)
  279.       Sound.play_cancel
  280.       end_actor_selection
  281.     elsif Input.trigger?(Input::C)
  282.       selection = PAC::MM::ITEMS[@command_window.index]
  283.       $game_party.last_actor_index = @status_window.index
  284.       Sound.play_decision
  285.       eval(PAC::MM::COMMAND[selection])
  286.     end
  287.   end
  288. end
  289.  
  290. #==============================================================================
  291. # ** Scene_Base
  292. #------------------------------------------------------------------------------
  293. #  This is a superclass of all scenes in the game.
  294. #==============================================================================
  295.  
  296. class Scene_Base
  297.   #--------------------------------------------------------------------------
  298.   # * Dispose of Background for Menu Screen
  299.   #--------------------------------------------------------------------------
  300.   def dispose_menu_background
  301.     @menuback_sprite.dispose if @menuback_sprite != nil
  302.   end
  303. end
  304.  
  305. #==============================================================================
  306. # ** Scene_Item
  307. #------------------------------------------------------------------------------
  308. #  This class performs the item screen processing.
  309. #==============================================================================
  310.  
  311. class Scene_Item < Scene_Base
  312.   #--------------------------------------------------------------------------
  313.   # * Return to Original Screen
  314.   #--------------------------------------------------------------------------
  315.   def return_scene
  316.     $scene = Scene_Menu.new
  317.   end
  318. end
  319.  
  320. #==============================================================================
  321. # ** Scene_Skill
  322. #------------------------------------------------------------------------------
  323. #  This class performs the skill screen processing.
  324. #==============================================================================
  325.  
  326. class Scene_Skill < Scene_Base
  327.   #--------------------------------------------------------------------------
  328.   # * Return to Original Screen
  329.   #--------------------------------------------------------------------------
  330.   def return_scene
  331.     $scene = Scene_Menu.new
  332.   end
  333. end
  334.  
  335. #==============================================================================
  336. # ** Scene_Equip
  337. #------------------------------------------------------------------------------
  338. #  This class performs the equipment screen processing.
  339. #==============================================================================
  340.  
  341. class Scene_Equip < Scene_Base
  342.   #--------------------------------------------------------------------------
  343.   # * Return to Original Screen
  344.   #--------------------------------------------------------------------------
  345.   def return_scene
  346.     $scene = Scene_Menu.new
  347.   end
  348. end
  349.  
  350. #==============================================================================
  351. # ** Scene_Status
  352. #------------------------------------------------------------------------------
  353. #  This class performs the status screen processing.
  354. #==============================================================================
  355.  
  356. class Scene_Status < Scene_Base
  357.   #--------------------------------------------------------------------------
  358.   # * Return to Original Screen
  359.   #--------------------------------------------------------------------------
  360.   def return_scene
  361.     $scene = Scene_Menu.new
  362.   end
  363. end
  364.  
  365. #==============================================================================
  366. # ** Scene_File
  367. #------------------------------------------------------------------------------
  368. #  This class performs the save and load screen processing.
  369. #==============================================================================
  370.  
  371. class Scene_File < Scene_Base
  372.   #--------------------------------------------------------------------------
  373.   # * Return to Original Screen
  374.   #--------------------------------------------------------------------------
  375.   def return_scene
  376.     if @from_title
  377.       $scene = Scene_Title.new
  378.     elsif @from_event
  379.       $scene = Scene_Map.new
  380.     else
  381.     $scene = Scene_Menu.new
  382.     end
  383.   end
  384. end
  385.  
  386. #==============================================================================
  387. # ** Scene_End
  388. #------------------------------------------------------------------------------
  389. #  This class performs game end screen processing.
  390. #==============================================================================
  391.  
  392. class Scene_End < Scene_Base
  393.   #--------------------------------------------------------------------------
  394.   # * Return to Original Screen
  395.   #--------------------------------------------------------------------------
  396.   def return_scene
  397.     $scene = Scene_Menu.new
  398.   end
  399. end
  400.  
  401. #===============================================================================
  402. #
  403. # END OF SCRIPT
  404. #
  405. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement