Create Your Own Menu (part 3)

Engine : RPG Maker VX Ace

Click here for part 1
Click here for part 2

4. Creating Location and Gold Window

4a. Setup
Insert a new script and name it Window_LocGold.


Then, paste this code below in Window_LocGold.


class Window_LocGold < Window_Base
  def initialize
    #super(x, y, width, height)
    super(16,360,512,40)
    refresh
  end
  
  def line_height
    #Auto calculate the line height for text
    40 - standard_padding * 2
  end
  
  def refresh
    #Change contents font size
    contents.font.size = 16
    #Clear contents
    contents.clear
    draw_location
    draw_gold
  end
  
  def draw_location    
  end
  
  def draw_gold
  end
end
This will create Window_LocGold class, with X 16 and Y 360, and width 512 height 40.

4b. Draw Location Name
To draw the location name, insert this code below in def draw_location.

    #Unless map display name isn't empty
    unless $game_map.display_name.empty?
      draw_text(4, 0, 320, line_height, "Location : #{$game_map.display_name}")
    end

4c. Draw Gold
Now to draw the total amount of gold, insert this code in def draw_gold.

    #change font color to system color
    change_color(system_color)
    draw_text(320, 0, 168, line_height, Vocab::currency_unit, 2)
    #change font color to normal color
    change_color(normal_color)
    #calculate the width for drawing gold amount
    #text_size is for getting the rect of the text when drawed in contents
    #rect has 4 properties : x, y, width, and height
    size = 164 - text_size(Vocab::currency_unit).width
    draw_text(320, 0, size, line_height, $game_party.gold, 2)

Now that everything is ready, test it with script call like before and you should see the window popped out.
Click here for part 4

0 komentar: