Create Your Own Menu (part 1)

Engine : RPG Maker VX Ace

What is this?

Do you want to make your own Menu but don't know how? Follow this tutorial, and I'm sure you can make it.

1. Figure Out the Layout

Before we go to coding action, we have to make the design first. It'll make the coding easier. For this tutorial, I want to make a menu that look like this,
The actor windows is separated so I can animate it later.

2. Creating Menu List Window

 

2a. Setup
Now, create a new project, so we won't be distracted with other script, then open the script editor. Select under ( insert here ), then change the name to "Window_MenuList". 


Q : Why we have to create a new window? Why can't we just use Window_MenuCommand instead?
A : Because I want the menu list to be horizontal, not vertical.

2b. Setup Position and Size
Paste this code below in Window_MenuList,

class Window_MenuList < Window_HorzCommand  
  def initialize  
    #Call superclass method with (x, y)  
    super(16, 16)  
    select_last  
  end    
  
  def window_width  
    512  
  end  
  
  def window_height  
    40  
  end  
  
  def line_height
    #Auto calculate the line height for text
    #Standard padding is a distance between window and it's contents,
    #default value is 12 
    window_height - standard_padding * 2
  end
  
  def select_last
    #Initialize @@last_command_symbol if it's nil
    @@last_command_symbol ||= nil
    #Change cursor index to the last position 
    select_symbol(@@last_command_symbol)  
  end
end

Other explanation:
  • "super" is for calling the superclass method. In this window for example, we call super(16, 16) in initialize, and it's the same thing as Window_HorzCommand.initialize(x, y).

For setting up position and size, you can use Photoshop or other graphics editor to do that. In Photoshop, press Ctrl+T or Edit>Free Transform, then change the anchor point to top-left.


2c. Creating the commands
The commands that we'll make is the same as default one plus new command called Crafting, but without Save. So the list commands is Items, Skills,  Equipment, Status, Formation, Crafting and Game End.

Now, insert this code below, above the very bottom of "end" in Window_MenuList.

#Make Command list
  def make_command_list    
    add_commands_list
  end

  def add_commands_list
    #add_command(Command Name, Command Symbol, Enabled?(true or false))
    add_command(Vocab::item,      :item,      main_commands_enabled)
    add_command(Vocab::skill,     :skill,     main_commands_enabled)
    add_command(Vocab::equip,     :equip,     main_commands_enabled)
    add_command(Vocab::status,    :status,    main_commands_enabled)
    add_command(Vocab::formation, :formation, formation_enabled)
    add_command(Vocab::game_end,  :game_end)
  end

  def main_commands_enabled
    #There's actor in the party?
    $game_party.exists
  end

  def formation_enabled
    #If actors in the party is 2 or more and formation not disabled
    $game_party.members.size >= 2 && !$game_system.formation_disabled
  end

  def process_ok
    #Save command position
    @@last_command_symbol = current_symbol
    super
  end

  def draw_item(index)
    #Change contents font size
    contents.font.size = 16
    super(index)
  end

If you want to add more command, insert add_command in add_command_list. Ouch, I forgot to add the Crafting command. So after we insert the Crafting command, the add_command_list would be like this,

  def add_commands_list
    #add_command(Command Name, Command Symbol, Enabled?(true or false))
    add_command(Vocab::item,      :item,      main_commands_enabled)
    add_command(Vocab::skill,     :skill,     main_commands_enabled)
    add_command(Vocab::equip,     :equip,     main_commands_enabled)
    add_command(Vocab::status,    :status,    main_commands_enabled)
    add_command(Vocab::formation, :formation, formation_enabled)
    add_command("Crafting",       :crafting)
    add_command(Vocab::game_end,  :game_end)
  end
Q : Why is there no true or false after command symbol?
A : If you leave it empty, it will use the default value,  which is true.
Q : What is the symbol for?
A : To distinguish the command with others, it will be used for creating the handler too.

Now, let's see if everything is correct. To test this window, we will create the window with Script Call in Event.
Save, then run the game. Activate the event, and you should see the window popped out.
Click here for part 2


0 komentar: