[
Github Link]
The first thing we want to do is create a data structure to store and
represent what a "command" really is:
Code:
Scene_Command = Struct.new(:symbol, :name, :scene)
Next, we need to define a collection to store the new commands. We will do
this in a namespace I call "Demo".
Code:
module ::Demo New_Commands = []end # ::Demo
Then, you can add commands to the collection:
Code:
Demo::New_Commands << Scene_Command.new(:symbol, "Game Over", ::Scene_Gameover)
This still won't do anything or even have them show up on the menu.
So, we will have to add them to the menu:
Code:
class ::Window_MenuCommand alias :demo_add_main_commands :add_main_commands def add_main_commands demo_add_main_commands ::Demo::New_Commands.each { |x| add_command(x.name, x.symbol, main_commands_enabled) } endend # ::Window_MenuCommand
This should now show the commands, but still won't do anything. To make it
go to the registered scene, we need to handle the command in Scene_Menu:
Code:
class ::Scene_Menu alias :demo_create_command_window :create_command_window def create_command_window demo_create_command_window ::Demo::New_Commands.each { |x| @command_window.set_handler(x.symbol, method(:command_custom)) } end def command_custom commands = Hash[::Demo::New_Commands.collect { |x| [x.symbol, x] }] current_symbol = @command_window.current_symbol if commands.has_key?(current_symbol) scene = commands[current_symbol].scene SceneManager.call(scene) end endend # ::Scene_Menu