neonblack

Menu Commands v1.1 (vx)

Apr 16th, 2012
196
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###--------------------------------------------------------------------------###
  2. #  Menu Commands script                                                        #
  3. #  Version 1.1                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neon Black                                                #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #      Revision information:                                                   #
  21. #  V1.1 - 10.15.2012                                                           #
  22. #   Fixed a crash for when numbers are not properly sorted                     #
  23. #   General script cleanup                                                     #
  24. #  V1.0b - 4.16.2012                                                           #
  25. #   Added submenu support                                                      #
  26. #   Polished code                                                              #
  27. #  V1.0  - 4.15.2012                                                           #
  28. #   Wrote and debugged main script                                             #
  29. ###--------------------------------------------------------------------------###
  30.  
  31. ###--------------------------------------------------------------------------###
  32. #      Compatibility:                                                          #
  33. #  Alias       - Scene_Menu: initialize, terminate, start_actor_selection      #
  34. #  Overwrites  - Scene_Menu: create_command_window, update_command_selection   #
  35. #                            update_actor_selection, update,                   #
  36. #                            end_actor_selection                               #
  37. #  New Methods - Scene_Menu: update_submenu_selection, create_submenu          #
  38. ###--------------------------------------------------------------------------###
  39.  
  40. ###--------------------------------------------------------------------------###
  41. #      Instructions:                                                           #
  42. #  Place this script in the "Materials" section of the scripts above main.     #
  43. #  This script is pretty much plug and play with a few options available to    #
  44. #  change below.                                                               #
  45. #                                                                              #
  46. #      Menu Items:                                                             #
  47. #  The menu items are added and controlled by a hash.  You can edit the menu   #
  48. #  items to your liking using the following guide.                             #
  49. #                                                                              #
  50. #    ID => [ "Name" , Scene_GoTo.new(@args) , party, :save , :no1, :submenu ], #
  51. #                                                                              #
  52. #  ID - This is the item position in the menu.  You can use this to re-order   #
  53. #       options within the menu.  Make sure each one is unique.                #
  54. #  "Name" - The text that will be displayed for the item in the menu.  Make    #
  55. #           sure this is in quotes or it will not work properly.               #
  56. #  Scene_GoTo.new - This is the scene that the option in the menu will call.   #
  57. #                   You do not need the "$scene ="; the script will do that    #
  58. #                   on its own.  You can only define certain arguments at the  #
  59. #                   moment, listed below.                                      #
  60. #           @args - The arguments section for the script.  You can use most    #
  61. #                   arguments normally, however local variables will not       #
  62. #                   work.  If the script requires you to select a character,   #
  63. #                   "@char" can be used in conjuntion with the next option.    #
  64. #  party - Put "true" or "false" here.  Use this spot to tell the script if    #
  65. #          it should start party selection before opening.  Use with the       #
  66. #          "@char" argument to properly select a party member.  This is used   #
  67. #          for menus such as the equip menu.                                   #
  68. #  :save (optional) - Add this tag after all other options and the menu        #
  69. #                     option can be enabled/disabled along with saving.        #
  70. #  :no1 (optional) - Add this tag after all other options and the menu option  #
  71. #                    will still be selectable with an empty party.             #
  72. #  :submenu (opt.) - Places this item into the submenu with this ID tag.       #
  73. #                    Items with this item in them will not appear in the main  #
  74. #                    menu.  A submenu is required.                             #
  75. #                                                                              #
  76. #      Submenus:                                                               #
  77. #  A submenu can be created similar to how normal menu items can be created.   #
  78. #  Submenus will be empty unless there are menu items with a submenu tag in    #
  79. #  them.  A single item can be in several submenu items by having several      #
  80. #  submenu tags in it.  Submenus are never disabled but the items in them can  #
  81. #  be disabled.                                                                #
  82. #                                                                              #
  83. #    ID => [ "Name" , :submenu ],                                              #
  84. #                                                                              #
  85. #  ID - This is the submenu position in the menu.  You can use this to         #
  86. #       re-order option within the menu.  Make sure each is unique.  These     #
  87. #       must also be different from normal menu IDs.                           #
  88. #  "Name" - The text that will be displayed for the submenu in the menu.       #
  89. #           Make sure this is in quotes or it will not work properly.          #
  90. #  :submenu - The submenu tag.  All other items with this tag will appear in   #
  91. #             this submenu.  Make sure each one is unique.                     #
  92. #                                                                              #
  93. #  NOTE - Submenu commands cannot have any other tags in them due to how they  #
  94. #         are identified.  You also cannot nest submenus in other submenus.    #
  95. ###--------------------------------------------------------------------------###
  96.  
  97. ###--------------------------------------------------------------------------###
  98. #      Config:                                                                 #
  99. #  These are the default values used by several of the functions in the        #
  100. #  script.  You may change these values as you find your game requires in      #
  101. #  order to give the player a better playing experience based on your game.    #
  102. #                                                                              #
  103. module CP               #  Do not                                              #
  104. module MENU_COMMANDS    #   alter                                              #
  105. def self.LIST           #    these                                             #
  106. @commands ={            #     4 lines.                                         #
  107. #                                                                              #
  108. # This is where you define the options used in the main menu.  Refer to the    #
  109. # instructions section above to find out what each element does.  Note that    #
  110. # each option will place the cursor on it's option when you back out, so       #
  111. # there is no need to change it in each script.                                #
  112.   0 => ["Status", Scene_Status.new(@char), true],                              #
  113.   1 => ["Item", Scene_Item.new, false],                                        #
  114.   2 => ["Skill", Scene_Skill.new(@char), true],                                #
  115.   3 => ["Equip", Scene_Equip.new(@char), true],                                #
  116.   4 => ["Data", :data],                                                        #
  117.   5 => ["End Game", Scene_End.new, false, :no1],                               #
  118.                                                                                #
  119.   6 => ["Save", Scene_File.new(true, false, false), false, :save, :no1, :data],#
  120.   7 => ["Load", Scene_File.new(false, false, false), false, :no1, :data],      #
  121. ###--------------------------------------------------------------------------###
  122.  
  123.  
  124. ###--------------------------------------------------------------------------###
  125. #  The following lines are the actual core code of the script.  While you are  #
  126. #  certainly invited to look, modifying it may result in undesirable results.  #
  127. #  Modify at your own risk!                                                    #
  128. ###--------------------------------------------------------------------------###
  129.  
  130.  
  131. } ## End of the hash here so people hopefully don't screw with it.
  132. end
  133.  
  134. def self.COMMANDS ## Returns a list of the commands.
  135.   result = []
  136.   @commands.keys.sort.each {|key| result.push(@commands[key])}
  137.   return result
  138. end
  139.  
  140. def self.set_char(char) ## Sets the party character.  Used by actor selection.
  141.   @char = char
  142. end
  143.  
  144. end ## End of the modules.
  145. end
  146.  
  147. $imported = {} if $imported == nil
  148. $imported["CP_MENUCOMMANDS"] = true
  149.  
  150. class Scene_Menu < Scene_Base
  151.  
  152.   ##-----
  153.   ## Alias the initialize method.  A global variable is added that saves the
  154.   ## cursor index when a scene is called.  If the global variable is not nil, it
  155.   ## takes priority for placing the cursor when this scene is called.
  156.   ##-----
  157.   alias cp_nmc_init initialize unless $@
  158.   def initialize(menu_index = 0)
  159.     cp_nmc_init(menu_index)
  160.     @menu_index = $menu_index if $menu_index
  161.     $menu_index = nil
  162.     CP::MENU_COMMANDS.LIST
  163.   end
  164.  
  165.   ##-----
  166.   ## Alias the terminate process for the new window.
  167.   ##-----
  168.   alias cp_nmc_term terminate unless $@
  169.   def terminate
  170.     cp_nmc_term
  171.     @submenu_window.dispose if @submenu_window
  172.   end
  173.  
  174.   ##-----
  175.   ## Overwrite command window drawing.
  176.   ##-----
  177.   def create_command_window
  178.     c_list = []
  179.     @cm_list = []
  180.     CP::MENU_COMMANDS.COMMANDS.each_with_index do |comm, index|
  181.       in_op = comm.size
  182.       if in_op > 3
  183.         in_op -= 1 if comm.include?(:no1)
  184.         in_op -= 1 if comm.include?(:save)
  185.       end
  186.       next if in_op > 3
  187.       c_list.push(comm[0])
  188.       @cm_list.push(index)
  189.     end
  190.     @command_window = Window_Command.new(160, c_list)
  191.     @command_window.index = @menu_index
  192.     save_op = !$game_system.save_disabled
  193.     char_op = $game_party.members.size != 0
  194.     CP::MENU_COMMANDS.COMMANDS.each_with_index do |comm, index|
  195.       i = @cm_list.index(index)
  196.       next unless i
  197.       if comm.include?(:save)
  198.         @command_window.draw_item(i, save_op)
  199.       end
  200.       if comm.include?(:no1)
  201.         @command_window.draw_item(i, char_op)
  202.       end
  203.     end
  204.   end
  205.  
  206.   ##-----
  207.   ## Overwrite the update phase due to the new window.
  208.   ##-----
  209.   def update
  210.     super
  211.     update_menu_background
  212.     @command_window.update
  213.     @gold_window.update
  214.     @status_window.update
  215.     if @submenu_window
  216.       @submenu_window.update
  217.       @submenu_window.dispose if @submenu_window.openness == 0
  218.       @submenu_window = nil if @submenu_window.disposed?
  219.     end
  220.     if @command_window.active
  221.       update_command_selection
  222.     elsif @status_window.active
  223.       update_actor_selection
  224.     elsif @submenu_window.active
  225.       update_submenu_selection
  226.     end
  227.   end
  228.  
  229.   ##-----
  230.   ## Overwrite command selection.  Checks for extra tags.
  231.   ##-----
  232.   def update_command_selection
  233.     if Input.trigger?(Input::B)
  234.       Sound.play_cancel
  235.       $scene = Scene_Map.new
  236.     elsif Input.trigger?(Input::C)
  237.       cwi = @cm_list[@command_window.index]
  238.       if $game_party.members.size == 0 && !CP::MENU_COMMANDS.COMMANDS[cwi].include?(:no1)
  239.         Sound.play_buzzer
  240.         return
  241.       elsif $game_system.save_disabled && CP::MENU_COMMANDS.COMMANDS[cwi].include?(:save)
  242.         Sound.play_buzzer
  243.         return
  244.       end
  245.       Sound.play_decision
  246.       if CP::MENU_COMMANDS.COMMANDS[cwi].size == 2
  247.         $menu_index = @command_window.index
  248.         create_submenu(cwi)
  249.       else
  250.         if CP::MENU_COMMANDS.COMMANDS[cwi][2]
  251.           start_actor_selection
  252.         else
  253.           $menu_index = @command_window.index
  254.           $scene = CP::MENU_COMMANDS.COMMANDS[cwi][1]
  255.         end
  256.       end
  257.     end
  258.   end
  259.  
  260.   ##-----
  261.   ## New method for the submenu.
  262.   ##-----
  263.   def update_submenu_selection
  264.     if Input.trigger?(Input::B)
  265.       Sound.play_cancel
  266.       @submenu_window.active = false
  267.       @command_window.active = true
  268.       $menu_index = nil
  269.       @submenu_window.openness = 0
  270.     elsif Input.trigger?(Input::C)
  271.       cwi = @sw_list[@submenu_window.index]
  272.       if $game_party.members.size == 0 && !CP::MENU_COMMANDS.COMMANDS[cwi].include?(:no1)
  273.         Sound.play_buzzer
  274.         return
  275.       elsif $game_system.save_disabled && CP::MENU_COMMANDS.COMMANDS[cwi].include?(:save)
  276.         Sound.play_buzzer
  277.         return
  278.       end
  279.       Sound.play_decision
  280.       if CP::MENU_COMMANDS.COMMANDS[cwi][2]
  281.         start_actor_selection
  282.       else
  283.         $scene = CP::MENU_COMMANDS.COMMANDS[cwi][1]
  284.       end
  285.     end
  286.   end
  287.  
  288.   ##-----
  289.   ## Alias or overwrite several things for the new window.
  290.   ##-----
  291.   alias cp_nmc_start_a_s start_actor_selection unless $@
  292.   def start_actor_selection
  293.     @submenu_window.active = false if @submenu_window
  294.     cp_nmc_start_a_s
  295.   end
  296.  
  297.   def end_actor_selection
  298.     if @submenu_window
  299.       @submenu_window.active = true
  300.     else
  301.       @command_window.active = true
  302.     end
  303.     @status_window.active = false
  304.     @status_window.index = -1
  305.   end
  306.  
  307.   ##-----
  308.   ## Actor selection.  Makes the "@char" argument work.
  309.   ##-----
  310.   def update_actor_selection
  311.     if Input.trigger?(Input::B)
  312.       Sound.play_cancel
  313.       end_actor_selection
  314.     elsif Input.trigger?(Input::C)
  315.       $game_party.last_actor_index = @status_window.index
  316.       Sound.play_decision
  317.       cwi = @cm_list[@command_window.index]
  318.       cwi = @sw_list[@submenu_window.index] if @submenu_window
  319.       CP::MENU_COMMANDS.set_char(@status_window.index)
  320.       CP::MENU_COMMANDS.LIST
  321.       $menu_index = @command_window.index
  322.       $scene = CP::MENU_COMMANDS.COMMANDS[cwi][1]
  323.     end
  324.   end
  325.  
  326.   ##-----
  327.   ## New method to create the submenu.
  328.   ##-----
  329.   def create_submenu(item)
  330.     submenu = CP::MENU_COMMANDS.COMMANDS[item][1]
  331.     c_list = []
  332.     @sw_list = []
  333.     CP::MENU_COMMANDS.COMMANDS.each_with_index do |comm, index|
  334.       next unless comm.include?(submenu)
  335.       next if index == item
  336.       c_list.push(comm[0])
  337.       @sw_list.push(index)
  338.     end
  339.     @submenu_window = Window_Command.new(120, c_list)
  340.     save_op = !$game_system.save_disabled
  341.     char_op = $game_party.members.size != 0
  342.     CP::MENU_COMMANDS.COMMANDS.each_with_index do |comm, index|
  343.       i = @cm_list.index(index)
  344.       next unless i
  345.       if comm.include?(:save)
  346.         @submenu_window.draw_item(i, save_op)
  347.       end
  348.       if comm.include?(:no1)
  349.         @submenu_window.draw_item(i, char_op)
  350.       end
  351.     end
  352.     @submenu_window.x = @command_window.x + 32
  353.     @submenu_window.y = @command_window.y + 26 + @command_window.index * 24
  354.     @submenu_window.y -= @command_window.oy
  355.     @submenu_window.active = true
  356.     @command_window.active = false
  357.   end
  358. end
  359.  
  360.  
  361. ##----------------------------------------------------------------------------##
  362. ##  END OF SCRIPT                                                             ##
  363. ##----------------------------------------------------------------------------##
RAW Paste Data