#===============================================================================
# * [ACE] Picture Number Drawing
#===============================================================================
# * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
# * Version: 1.4
# * Updated: 27/11/2017
# * Requires: -------
#-------------------------------------------------------------------------------
# * < Change Log >
#-------------------------------------------------------------------------------
# * Version 1.0 (11/04/2015)
# - Initial release.
# * Version 1.1 (13/06/2015)
# - Added in a safe-check in case an unidentified character is detected.
# - Added a custom folder setting. From now on, all pictures used by this
# script must be in the folder set up for them!
# * Version 1.2 (22/06/2015)
# - Actually added in the safe-check method mentioned in v1.1.
# - Added an optional argument which will clear the previously drawn numbers
# automatically if the number is redrawn at the same place.
# * Version 1.3 (07/10/2016)
# - Just added 2 new methods for getting one number's width and height.
# It is not necessary to update if you don't need that method.
# * Version 1.4 (27/11/2017)
# - From now on, you can setup different number of styles (rows) and number of
# characters (columns) for each of your image sheets.
#-------------------------------------------------------------------------------
# * < Description >
#-------------------------------------------------------------------------------
# * This is a scripter's tool, so it won't do anything by itself!
# * This script adds a new method for Bitmap objects.
# This new method enables the drawing of numbers with pictures.
# * Besides numbers, any other character can be added to the image sheet.
# These extra characters can be drawn with pictures too.
#-------------------------------------------------------------------------------
# * < Usage Information >
#-------------------------------------------------------------------------------
# You can use the new picture drawing method for numbers by calling the
# following on a bitmap object:
#
# draw_numbers(x,y,num,opa,al,clear?)
#
# Arguments:
#
# x = The X position to draw the number on the bitmap.
# y = The Y position to draw the number on the bitmap.
# num = The number to be drawn. It supports negative and float numbers too,
# as long as you define an extra char at the settings below for the
# minus and point signs.
# opa = The opacity level of the drawing. If omitted, 255 will be used
# automatically. Valid values: 0 - 255.
# al = The alignment used for the drawing.
# It works a bit different, not like draw_text's alignment, but it will
# do the alignment just fine.
# You can choose from 3 values here:
# 0 = Left alignment, 1 = Middle alignment, 2 = Right alignment.
# Depending on which alignment mode you choose, the X co-ord used in the
# method call will mean different things:
# 0 - The X co-ord defines the starting point of the drawing.
# 1 - The X co-ord defines the center of the drawing.
# 2 - The X co-ord defines the end of the drawing.
# If this setting is omitted, 0 will be used by default.
# Check the example scene to see the differences in practice!
# clear? = This is either true or false. If true, any previously drawn number
# at the same place will get cleared automatically. If false, there
# will be no automatic clearing, so you will need to do it manually!
# If omitted, this argument defaults to false!
#
# You can change the default drawing style (the default image file and row used)
# too if you want. More info on that can be found below in the next section.
#
# Examples:
#
# contents.draw_numbers(10,30,$game_actors[1].hp)
# Draws the HP of the actor with ID 1, using the default image file from the
# Pictures folder, and will use the default row on the picture.
# This example is executed in a Window class.
#
# @example = Sprite.new
# @example.bitmap = Cache.picture("examplepic")
# @example.bitmap.num_style = ["numpics2",3]
# @example.bitmap.draw_numbers(10,14,$game_party.gold,180,2)
# Draws the party's gold on the @example sprite's bitmap, uses the "numpics2"
# image file from the Pictures folder, uses the third row on the "numpics2"
# picture, and draws the numbers with an opacity level of 180.
# The drawing will use right alignment.
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# You can change the bitmap's picture used for drawing the numbers by setting
# it's "style" directly like this:
#
# bitmap_object.num_style = ["pic",row]
#
# pic = The name of the image used for the drawing.
# It must contain at least all 10 numbers, from 0 to 9.
# The image itself is a sheet of number pictures lined up.
# Each row equals a new style for the number drawing method.
# The numbers on the sheet must start from 0 and they increment from
# the left to the right one by one.
# If you need special characters, such as a - sign for negative numbers,
# or a . for float numbers, you must put them after the number pictures!
# row = The row used from the image. You can create more styles on the same
# image if you want, by simply inserting another sheet below the last
# one. You can than change the styles used dynamically with the
# draw_numbers method easily.
# Useful if you want to pack all of your number drawing styles into
# one single image file.
#
# So, this sets a new "style" for the number drawing method, just like you would
# set a new font type/size/etc for a regular draw_text method before drawing
# your stuffs if needed. Take a look at the example scene to see an example!
#-------------------------------------------------------------------------------
# * < Installation >
#-------------------------------------------------------------------------------
# * Place this script below Materials but above Main!
#-------------------------------------------------------------------------------
# * < Compatibility Info >
#-------------------------------------------------------------------------------
# * No known incompatibilities.
#-------------------------------------------------------------------------------
# * < Known Issues >
#-------------------------------------------------------------------------------
# * No known issues.
#-------------------------------------------------------------------------------
# * < Terms of Use >
#-------------------------------------------------------------------------------
# * Free to use for whatever purposes you want.
# * Credit me (Sixth) in your game, pretty please! :P
# * Posting modified versions of this script is allowed as long as you notice me
# about it with a link to it!
#===============================================================================
$imported = {} if $imported.nil?
$imported["SixthPictureNumbers"] = true
#===============================================================================
# Settings:
#===============================================================================
module PicNumbers # <-- No touchy-touchy!
#-----------------------------------------------------------------------------
# Image Folder Settings:
#-----------------------------------------------------------------------------
# Set up a custom folder where your number pictures will be read from.
# All pictures used must be in this folder!
#-----------------------------------------------------------------------------
ImgFolder = "Graphics/Numbers/"
#-----------------------------------------------------------------------------
# Image Sheet Settings:
#-----------------------------------------------------------------------------
# Set how many rows and columns are on your image files used for the
# number drawing methods.
# From v1.4, you can use different rows and columns for your different
# image-sheets!
# The rows represent the number of available styles on the image,
# while the columns represent the number of characters in one style
# including the extra characters set up in the next section.
#
# Example format:
#
# ---------------------------------------------------------
# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | + | - | . | , | <- Style 1 (row 0)
# ---------------------------------------------------------
# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | + | - | . | , | <- Style 2 (row 1)
# ---------------------------------------------------------
# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | + | - | . | , | <- Style 3 (row 2)
# ---------------------------------------------------------
#
# This example image setup contains 3 styles. Each row is a style.
# Changing the 'row' value in the num_style property of a bitmap will change
# the style used for the drawing.
# The first row's index is 0, the second row's index is 1, and so on.
# The example image got 4 extra characters in it (+/-/./,).
# The width of each section must be the same for all of them!
# The height of each section must be the same for all of them!
# The width and height used can differ for each image, but for optimal
# drawing, keep the characters close to each other horizontally.
#
# And the setting's format here looks like this:
#
# "filename" => [rows,columns],
#
# The "filename" must be the file name of an image-sheet used for this script.
#
# The rows and columns in the arrays must be positive integer numbers, and
# they will setup the number of styles (rows) and characters (columns) for
# the specified image-sheet.
#
# You can add as many as you like!
#
# If an image-sheet got no setting here, it will automatically use the
# "default" settings!
#-----------------------------------------------------------------------------
Formats = {
"default" => [3,17], # <-- Default, do NOT remove!
"numsheet1a" => [5,17],
"numsheet_s24" => [6,17],
"numsheet_big" => [3,17],
"pages1a" => [1,17],
"menu1a" => [3,18],
# <-- Add more settings here if needed!
}
#-----------------------------------------------------------------------------
# Default Drawing Style Settings:
#-----------------------------------------------------------------------------
# If a bitmap got no style settings set up for drawing the numbers, than this
# style will be used by default.
#
# Format:
#
# DefStyle = ["image file name", row]
#-----------------------------------------------------------------------------
DefStyle = ["pacg_nums",0]
#-----------------------------------------------------------------------------
# Extra Character Settings:
#-----------------------------------------------------------------------------
# The extra character setup.
# For negative numbers, you must define the "minus" ( - ) sign!
# For float numbers, you must define the "point" ( . ) sign!
# You can also add any other characters if you want.
#
# Format:
#
# "char name" => column index,
#
# The "char name" is the character itself.
# The column index is the column reserved for the character on the sheet.
# The first column's index is 0, the second column's index is 1, and so on.
# Valid values for the column index start from 10 and goes to infinity.
# The first 10 columns are reserved for the numbers, that is why you
# can NOT use any numbers below 10 here!
#
# If the number drawing method detects an undefined character which is not a
# number, it will draw an empty space instead and jumps to the next one!
#-----------------------------------------------------------------------------
ExtraChars = { # <-- No touchy-touchy!
"+" => 10,
"-" => 11,
"." => 12,
"," => 13,
"/" => 14,
"%" => 15,
":" => 16,
"d" => 17,
# <-- Add more extra characters here!
} # <-- No touchy-touchy!
end # <-- No touchy-touchy!
#===============================================================================
# End of settings! O.o
#===============================================================================
module Cache
def self.picnums(filename)
load_bitmap(PicNumbers::ImgFolder, filename)
end
end
class Bitmap
attr_accessor :num_style
def self_num_style
@num_style.nil? ? PicNumbers::DefStyle : @num_style
end
def num_form
if PicNumbers::Formats[self_num_style[0]]
return PicNumbers::Formats[self_num_style[0]]
else
return PicNumbers::Formats["default"]
end
end
def draw_numbers(x,y,num,opa=255,al=0,clear=false)
img = Cache.picnums(self_num_style[0])
row = self_num_style[1]
form = num_form
wm = img.width/form[1]
hm = img.height/form[0]
numtxt = num.is_a?(String) ? num : num.to_s
case al
when 0
xx = x
when 1
xx = x-(numtxt.size*wm/2)
when 2
xx = x-numtxt.size*wm
end
index = 0
numtxt.each_char do |nm|
if PicNumbers::ExtraChars.include?(nm)
mul = PicNumbers::ExtraChars[nm]
rect = Rect.new(mul*wm, row*hm, wm, hm)
elsif numtxt[index,1].to_i.to_s == nm
rect = Rect.new(nm.to_i*wm, row*hm, wm, hm)
end
self.clear_rect(Rect.new(xx+wm*index,y,wm,hm)) if clear == true
self.blt(xx+wm*index, y, img, rect, opa) if rect
index += 1
rect = nil
end
end
end
#==============================================================================
# !!END OF SCRIPT - OHH, NOES!!
#==============================================================================